Beispiel #1
0
        /// <summary>
        /// Устанавливает необходимые пункты меню для указанного предмета
        /// </summary>
        /// <param name="menu">Контекстное меню, в котором проводится установка</param>
        /// <param name="item">Предмет, относительно которого устанавливаются настройки</param>
        public void SetupPopupMenu(InventoryPopupMenu menu, Item item)
        {
            menu.setSelectedItem(item); // устанавливаем контекстному меню ссылку на выбранный предмет

            menu.useItem.setEnabled(item.toGameObject().GetComponent<DynamicObject>() as IUsedType !=null);
            menu.dropAllItems.setEnabled(item.getMaxCount() > 1 && item.getCount() > 1);
        }
Beispiel #2
0
        /// <summary>
        /// �������� �������� ������� � ���������
        /// </summary>
        /// <param name="item">����������� �������</param>
        /// <returns>���������� ����� �� ������������ �����������, ���� ������� �� ��� ��������� ��������. 0 - ���� ������� ������� ��������</returns>
        public int addItem(List<RectangleSlot> slots, Item item)
        {
            foreach (RectangleSlot slot in slots) { // ���������� ��� �����

                foreach (ItemSlot i in slot.Items) { // �������� ����� ���������� �������� � ����������� ���������� ��
                    if (i.item.Equals(item) && !i.item.isFullCount()) { // ���� ������� ���������, � �� �� ��������� �������������

                        if (item.getCount()!=0) // ���� � ��� ���� ������� �����������, ������� ���� ���������
                            item.setCount(i.item.incCount(item.getCount()));

                        if (item.getCount()==0) // ���������� ���������, ����� ��������
                            return 0;

                    }
                }

                for(int y=1;y<=slot.position.CellsYCount;y++){ // �������� ����� ��������� �������, � �������� ������� ������� (�� ��������)
                    for(int x=1;x<=slot.position.CellsXCount;x++){

                        bool result = true;
                        foreach(ItemSlot i in slot.Items){

                            if(x>=i.getPosition().X &&
                               x<i.getPosition().X+i.item.getSize().getWidth() &&
                               y>=i.getPosition().Y &&
                               y<i.getPosition().Y+i.item.getSize().getHeight()){
                                result=false;
                                break;
                            }

                        }

                        if(result){ // �������� ����� ��������� ��������
                            slot.Items.Add(new ItemSlot(item.Clone(), new ItemPosition(x, y)));
                            return 0;
                        }

                    }

                }

            }

            return item.getCount(); // ���������� ����� ����������� (�� �������) ���������
        }
        /// <summary>
        /// Пытается добавить предмет item в слот slotData
        /// </summary>
        /// <param name="slotData">Сумка, в которую пытаются добавить предмет</param>
        /// <param name="item">Добавляемый предмет</param>
        /// <returns>Возвращает число экземпляров item НЕ ДОБАВЛЕННЫХ в слот</returns>
        public int AddItem(SlotData slotData, Item item)
        {
            foreach (ItemSlot i in slotData.Items) { // пытаемся найти идентичные предметы и попробовать объединить их
                if (i.item.Equals(item) && !i.item.isFullCount()) { // если предмет идентичен, и он не полностью укомплектован

                    if (item.getCount() != 0) // пока у нас есть остаток экземпляров, которые надо раскидать
                        item.setCount(i.item.incCount(item.getCount()));

                    if (item.getCount() == 0) // экземпляры кончились, можно выходить
                        return 0;

                }
            }

            for (int y = 1; y <= slotData.position.CellsYCount; y++) { // пытаемся найти свободную область, и засунуть предмет целиком (не разделяя)
                for (int x = 1; x <= slotData.position.CellsXCount; x++) {

                    bool result = true;
                    foreach (ItemSlot i in slotData.Items) {

                        if (x >= i.getPosition().X &&
                           x < i.getPosition().X + i.item.getSize().getWidth() &&
                           y >= i.getPosition().Y &&
                           y < i.getPosition().Y + i.item.getSize().getHeight()) {
                            result = false;
                            break;
                        }

                    }

                    if (result) { // предметы можно полностью добавить
                        slotData.Items.Add(new ItemSlot(item.Clone(), new ItemPosition(x, y)));
                        return 0;
                    }

                }

            }

            return item.getCount();
        }
Beispiel #4
0
        /// <summary>
        /// Создаёт строку с описанием предмета
        /// </summary>
        /// <param name="item">Описываемй предмет</param>
        /// <returns>Возвращает строку с описанием</returns>
        public string createDescription(Item item)
        {
            ItemDescription description = item.getDescription();
            string result = description.dName;

            if (item.getMaxCount() > 1)
                result += " [" + item.getCount().ToString() + "/" + item.getMaxCount().ToString() + CLang.getInstance().get(Dictionary.K_COUNT) + "]";

            result += "\n" + description.dCaption;

            return result;
        }