Beispiel #1
0
 /// <summary>
 /// Makes tooltip visible, should be called from mouse hovering over item
 /// </summary>
 /// <param name="uiSlot">inventory slot being hovered over</param>
 private void ShowTooltip(UISlot uiSlot)
 {
     if (uiSlot.slot.isOccupied)
     {
         tooltip.ShowTooltip(uiSlot);
     }
 }
 internal void GetInventory(string name, List <Item> items)
 {
     this.name = name;
     _playerName.SetText($"{name} 的背包");
     if (slots.Count != items.Count)
     {
         slots.Clear();
         for (int i = 0; i < items.Count; i++)
         {
             var uislot = new UISlot();
             uislot.Width.Set(60, 0f);
             uislot.Height.Set(60, 0f);
             uislot.ContainedItem     = items[i];
             uislot.Index             = i;
             uislot.PostExchangeItem += Uislot_PostExchangeItem;
             slots.Add(uislot);
             _itemGrid.Add(uislot);
         }
     }
     else
     {
         for (int i = 0; i < items.Count; i++)
         {
             slots[i].ContainedItem = items[i];
         }
     }
 }
Beispiel #3
0
    private void OnEnable()
    {
        while (0 < content.childCount)
        {
            Transform child = content.GetChild(0);
            child.SetParent(null);
            GameObject.Destroy(child.gameObject);
        }

        foreach (var itr in AchieveManager.Instance.achieves)
        {
            GameObject obj  = GameObject.Instantiate <GameObject>(slot_prefab);
            UISlot     slot = obj.AddComponent <UISlot>();

            slot.Init(itr.Value);
            slot.transform.SetParent(content, false);
        }
        scrollbar.value = 1.0f;

        /*
         * for (int i = 0; i < 10; i++)
         * {
         *      GameObject obj = GameObject.Instantiate<GameObject>(slot_prefab);
         *      UISlot slot = obj.AddComponent<UISlot>();
         *      slot.Init(null);
         *      slot.transform.SetParent(content, false);
         * }
         */
    }
Beispiel #4
0
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
            Player target = Main.player[_targetID];

            _playerName.SetText($"{target.name} 的背包");
            if (slots.Count == 0)
            {
                for (int i = 0; i < target.inventory.Length + target.armor.Length + target.bank.item.Length; i++)
                {
                    var uislot = new UISlot(useTexture(target, i));
                    uislot.Width.Set(60, 0f);
                    uislot.Height.Set(60, 0f);
                    uislot.ContainedItem     = GetItem(target, i);
                    uislot.Index             = i;
                    uislot.PostExchangeItem += Uislot_PostExchangeItem;
                    slots.Add(uislot);
                    _itemGrid.Add(uislot);
                }
            }
            else
            {
                for (int i = 0; i < slots.Count; i++)
                {
                    slots[i].ContainedItem = GetItem(target, i);
                }
            }
        }
    // this function will be called by slot of other storage, when the slot be dropped on this storage
    // 负责处理和UISolt的交互
    public override void Income_Slot(UISlot slot)
    {
        //Debug.Log("Slot income: " + slot.slot_id);
        // 如果UISlot不是属于本面板
        if (slot.storage != this)
        {
            // buy from UI Shopping
            // 如果面板属于商店,执行买操作,
            if (slot.storage.GetType() == typeof(UIShopping))
            {
                Buy(slot);
            }

            // unequip
            // 如果面板属于装备,执行卸载操作
            if (slot.storage.backpackSys == this .backpackSys && slot.storage.GetType() == typeof(UIEquipment))
            {

                Unequip(slot);
            }
        }
        // 如果UISlot是属于本面板
        else
        {
            // do exchange
            // 交换/合并分栏
            Exchange(slot);
        }
    }
Beispiel #6
0
 private IEnumerator <ICoroutineInstruction> _lotteryTask(List <Item> items)
 {
     listItems.Clear();
     for (int i = 0; i < 3; i++)
     {
         chestImage.Frame = i;
         yield return(new WaitForFrames(20));
     }
     for (int i = 0; i < items.Count; i++)
     {
         var    dim  = chestImage.GetDimensions().Center();
         UISlot slot = new UISlot();
         slot.Width.Set(50, 0f);
         slot.Height.Set(50, 0f);
         slot.Top.Pixels    = dim.Y - 25f;
         slot.Left.Pixels   = dim.X - 25f;
         slot.ContainedItem = items[i].Clone();
         unionsPanel.Append(slot);
         listItems.Add(slot);
         Vector2 targetpos = new Vector2(5 + 55 * i, 5);
         Vector2 startPos  = new Vector2(dim.X - 25f - unionsPanel.GetDimensions().X, dim.Y - 25f - unionsPanel.GetDimensions().Y);
         for (int j = 0; j <= 30; j++)
         {
             float   factor = j / 30f;
             Vector2 pos    = Vector2.Lerp(startPos, targetpos, factor);
             slot.Top.Pixels  = pos.Y;
             slot.Left.Pixels = pos.X;
             slot.Opacity     = factor;
             slot.Recalculate();
             yield return(new SkipFrame());
         }
     }
 }
 private void BeginDrag(UISlot uiSlot)
 {
     if (uiSlot is BaseItemSlot)
     {
         BaseItemSlot itemSlot = uiSlot as BaseItemSlot;
         if (itemSlot.Item != null)
         {
             dragItemSlot                     = itemSlot;
             draggableIcon.sprite             = itemSlot.Item.Icon;
             draggableIcon.transform.position = Input.mousePosition;
             draggableIcon.gameObject.SetActive(true);
         }
     }
     else if (uiSlot is BaseSkillSlot)
     {
         BaseSkillSlot skillSlot = uiSlot as BaseSkillSlot;
         if (skillSlot.Skill != null)
         {
             dragSkillSlot                    = skillSlot;
             draggableIcon.sprite             = skillSlot.Skill.Icon;
             draggableIcon.transform.position = Input.mousePosition;
             draggableIcon.gameObject.SetActive(true);
         }
     }
 }
Beispiel #8
0
 public void Init()
 {
     for (int i = 0; i < size; i++)
     {
         UISlot slot = Instantiate(slotPrefab, mainSection.transform).GetComponent <UISlot>();
         slots.Add(slot);
     }
 }
Beispiel #9
0
        private void Uislot_PostExchangeItem(UIElement target)
        {
            if (Main.netMode != 1)
            {
                return;
            }
            UISlot slot = (UISlot)target;

            MessageSender.SyncSingleEquip(_targetID, slot.Index, slot.ContainedItem);
        }
Beispiel #10
0
    // this is called, after drop for this dragger has been called (i think)
    public void OnEndDrag()
    {
        if (dragging == true)
        {
            Destroy(draggerGraphic);
            dragging = false;

            SpecialOnEndDrag();
        }
        dragOrigin = null;
    }
Beispiel #11
0
 // this function will be called by slot of other storage, when the slot be dropped on this storage
 // 负责处理和UISolt的交互
 public override void Income_Slot(UISlot slot)
 {
     // 如果UISlot不是属于本面板
     if (slot.storage != this)
     {
         // sell from UIBackpack
         // 如果UISlot属于背包面板的,这里的背包面板UIBackpack是玩家的背包面板
         if (slot.storage.GetType() == typeof(UIBackpack))
         {
             // 出售道具
             Sell(slot);
         }
     }
 }
Beispiel #12
0
 public void updateInventory()
 {
     if (inv != null)
     {
         for (int i = 0; i < inv.getSize(); i++)
         {
             GameObject o      = Instantiate <GameObject>(GameManager.UIHandler.UISlotPrefab);
             UISlot     UISlot = o.GetComponent <UISlot>();
             UISlot.setParentSlot(inv.getSlot(i));
             UISlot.setInventoryType(inv.getInventoryType());
             o.transform.SetParent(gridParent);
         }
     }
 }
Beispiel #13
0
    public void OnBeginDrag(UISlot origin)
    {
        if (origin.IsEmpty() == false)
        {
            dragOrigin = origin;

            // create dragger graphic
            draggerGraphic = Instantiate(draggerGraphicPrefab, InGameMenu.instance.transform);
            Image draggerImage = draggerGraphic.GetComponent <Image>();
            draggerImage.sprite = dragOrigin.image.sprite;             // <--------------------------------------------------------------------------- how the image is accesd will prob change
            draggerImage.color  = new Color(draggerImage.color.r, draggerImage.color.g, draggerImage.color.b, draggerAlphaValue);
            draggerGraphic.transform.localScale = new Vector3(draggerScale, draggerScale, draggerScale);


            dragging = true;
        }
    }
        /// <summary>
        /// Sets a unit to the new slot position from the first UI Slot.
        /// </summary>
        /// <param name="_slot">Hands over the new slot for the unit.</param>
        private void NewUISlot(UISlot _slot)
        {
            if (_slot == UISlotFirst || _slot == null || UISlotFirst == null)
            {
                return;
            }

            if (_slot.GetID >= 0)
            {
            }
            else
            {
                _slot.Init(UISlotFirst.GetSprite, UISlotFirst.GetID);
                UISlotFirst.RemoveUnit();
                UISlotFirst.SetDefaultSprite();
                OnUnitChanged?.Invoke(UISlotFirst.GetSlotId, _slot.GetSlotId);
            }
        }
    private void BeginDrag(UICharacter uiCharacter)
    {
        if (TransformService.ContainPos(uiCharacterArea.transform as RectTransform, uiCharacter.transform.position))
        {
            isMoveFromBattleArea = true;
        }
        else if (TransformService.ContainPos(uiPrepareArea.transform as RectTransform, uiCharacter.transform.position))
        {
            isMoveFromBattleArea = false;
        }

        parentWhenBeginDrag = uiCharacter.GetComponentInParent <UISlot>();
        SwapCharacters(invisibleCharacter, uiCharacter);
        uiCharacter.SetDefaultImage();
        originalSize = uiCharacter.character.GetSize();
        uiSellArea.UpdatePrice(uiCharacter.characterInfo);
        uiSellArea.OnShow();
    }
Beispiel #16
0
    void GrabItem(UISlot grabbable)
    {
        if (grabbable.Item == null)
        {
            return;
        }

        if (grabbable is InventorySlot inventoryGrabbable)
        {
            grabbedSlot = inventoryGrabbable.MainSlot;
            inventoryGrabbable.MainSlot.GrabItem(true);
        }
        else
        {
            grabbedSlot = grabbable;
            grabbable.GrabItem(true);
        }
    }
        internal void SetContent(string content, List <ItemInfo> items)
        {
            _mailContent.SetText(content);
            int id = 0;

            foreach (var info in items)
            {
                var    item = info.ToItem();
                UISlot slot = new UISlot(ServerSideCharacter2.ModTexturesTable["Box"]);
                slot.Width.Set(60, 0f);
                slot.Height.Set(60, 0f);
                slot.CanPutInSlot += (i) => false;
                slot.DrawColor     = Drawing.DefaultBoxColor * 0.75f;
                slot.OnPickItem   += Slot_OnPickItem;
                slot.ContainedItem = item;
                slot.Index         = id++;
                _uiItemGrid.Add(slot);
            }
        }
Beispiel #18
0
    private void Drop(UISlot dropUISlot)
    {
        if (dropUISlot is BaseItemSlot)
        {
            BaseItemSlot dropItemSlot = dropUISlot as BaseItemSlot;
            if (dragItemSlot == null)
            {
                return;
            }

            if (dropItemSlot.CanAddStack(dragItemSlot.Item))
            {
                AddStacks(dropItemSlot);
            }
            else if (dropItemSlot.CanReceiveItem(dragItemSlot.Item) && dragItemSlot.CanReceiveItem(dropItemSlot.Item))
            {
                SwapItems(dropItemSlot);
            }
        }
        else if (dropUISlot is BaseSkillSlot)
        {
            BaseSkillSlot dropSkillSlot = dropUISlot as BaseSkillSlot;
            if (dragSkillSlot == null)
            {
                return;
            }

            if (dropSkillSlot is UsableSkillSlot)
            {
                ActiveSkill holdSkill = dragSkillSlot.Skill as ActiveSkill;
                if (dragSkillSlot is UsableSkillSlot)
                {
                    SkillWindow.RemoveSkill(holdSkill);
                    if (dropSkillSlot.Skill)
                    {
                        SkillWindow.EquipSkill(dropSkillSlot.Skill as ActiveSkill, 0, dragSkillSlot as UsableSkillSlot);
                    }
                }
                SkillWindow.EquipSkill(holdSkill, 0, dropUISlot as UsableSkillSlot);
            }
        }
    }
Beispiel #19
0
    void CreateSlotGrid()
    {
        RectTransform rectTransform = GetComponent <RectTransform>();

        float slotSize = rectTransform.sizeDelta.x / numColumns;                     // figure out the size of each slot by using the panel width as base

        GetComponent <GridLayoutGroup>().cellSize = new Vector2(slotSize, slotSize); // set the size of each slot
        // Create the actual grid
        int numSlots = numRows * numColumns;

        for (int i = 0; i < numSlots; ++i)
        {
            GameObject tmp     = Instantiate(uiSlotPrefab, transform) as GameObject;
            UISlot     newSlot = tmp.GetComponent <UISlot>();
            slots.Add(newSlot);
        }

        // Resize Height of the Grid to fit with the width;
        rectTransform.sizeDelta = new Vector2(rectTransform.sizeDelta.x, slotSize * numRows);
    }
    public void OnEndDrag(PointerEventData eventData)
    {
        var results = new List <RaycastResult>();

        transform.parent          = current.transform;
        transform.localPosition   = Vector3.zero;
        pointerEventData.position = Input.mousePosition;
        EventSystem.current.RaycastAll(pointerEventData, results);



        for (int i = 0; i < results.Count; i++)
        {
            Debug.Log(results[i].gameObject.name + " " + i);
        }

        foreach (var hit in results)
        {
            // If we found slot.
            //Debug.Log(hit.gameObject.tag);
            var slot = hit.gameObject.GetComponent <UISlot>();
            if (hit.gameObject.tag == "ItemSlot")
            {
                // We should check if we can place ourselves​ there.
                if (!slot.filled)
                {
                    current.filled = false;
                    Debug.Log("OK");
                    // Swapping references.
                    slot.item          = current.item;
                    current.item       = null;
                    current            = slot;
                    transform.parent   = hit.gameObject.transform;
                    transform.position = transform.parent.position;
                    slot.filled        = true;
                }
            }
        }
    }
    // this function will be called by slot of other storage, when the slot be dropped on this storage
    public override void Income_Slot(UISlot slot)
    {
        // Debug.Log("Slot income: " + slot.slot_id);

        // *********** this code for test ***********
        // put the income item to this storage, and empty the imcome slot
        for(int i=0;i<slots.Count;i++)
        {
            if (slots[i].isEmpty)
            {
                slots[i].SetItemID(slot.item_id);
                slots[i].SetAtt1(slot.att1.texture);
                slots[i].SetIcon(slot.icon.texture);
                slots[i].SetInfo(slot.info.text);
                slots[i].SetDragbale(true);

                slot.SetIconEmpty();

                break;
            }
        }
    }
Beispiel #22
0
    /// <summary>
    /// Positions and makes tooltip visible showing items information
    /// </summary>
    /// <param name="uiSlot">slot being hovered</param>
    public void ShowTooltip(UISlot uiSlot)
    {
        //activate
        gameObject.SetActive(true);

        //setup position
        Vector3[] corners = new Vector3[4];
        uiSlot.transform.GetWorldCorners(corners);
        _myTransform.anchoredPosition = new Vector2(corners[1].x, corners[1].y) * (1 / _mainCanvas.scaleFactor);
        if (uiSlot.slot is InventorySlot)
        {
            int rowOffset = ((InventorySlot)uiSlot.slot).RowOffset;
            int colOffset = ((InventorySlot)uiSlot.slot).ColOffset;
            _myTransform.anchoredPosition -= new Vector2((int)uiSlot.transform.sizeDelta.x * colOffset, -(int)uiSlot.transform.sizeDelta.y * rowOffset);
        }

        Item item = uiSlot.slot.item;

        //set tooltip info
        nameText.text = item.itemName;
        descText.text = item.description;
        //properties
        for (int i = 0; i < propertiesPanel.childCount; i++)
        {
            if (i >= item.statModifiers.Count)
            {
                //hide this property
                propertiesPanel.GetChild(i).GetChild(0).gameObject.SetActive(false);
                propertiesPanel.GetChild(i).GetChild(1).gameObject.SetActive(false);
            }
            else
            {
                propertiesPanel.GetChild(i).GetChild(0).gameObject.SetActive(true);
                propertiesPanel.GetChild(i).GetChild(1).gameObject.SetActive(true);
                Text propertyText = propertiesPanel.GetChild(i).GetChild(1).GetComponent <Text>();
                propertyText.text = item.statModifiers[i].Value + " to " + _characterStats.Stats[(int)item.statModifiers[i].Type].Label();
            }
        }
    }
Beispiel #23
0
        /// <summary>
        /// Update ui inventory slots
        /// </summary>
        public void UpdateStorageUI()
        {
            foreach (var UISlot in UISlots)
            {
                var slotUI = UISlot.GetComponent <PlayerExaminationWindowSlot>();

                // reset inventory slot
                slotUI.RefreshImage();

                // if slot is obscured - enable overlay
                if (currentEquipment.IsSlotObscured(slotUI.UI_ItemSlot.ItemSlot.NamedSlot.GetValueOrDefault()))
                {
                    slotUI.SetObscuredOverlayActive(true);
                }
                // else link slot
                else
                {
                    if (slotUI.IsPocket)
                    {
                        continue;
                    }
                }
            }
        }
        internal void GetMailList()
        {
            lock (this)
            {
                SelectedMailItem = null;
                ClearContent();
                _mailList.Clear();
                if (Main.netMode == 0)
                {
                    for (int i = 0; i < 5; i++)
                    {
                        UISlot slot = new UISlot(ServerSideCharacter2.ModTexturesTable["Box"]);
                        slot.Width.Set(60, 0f);
                        slot.Height.Set(60, 0f);
                        slot.CanPutInSlot += (item) => false;
                        slot.DrawColor     = Drawing.DefaultBoxColor * 0.75f;
                        _uiItemGrid.Add(slot);
                    }

                    for (int i = 0; i < 5; i++)
                    {
                        var testinfo = new MailHead(ServerUtils.RandomGenString(40))
                        {
                            IsRead = Main.rand.NextBool(),
                            Sender = "<系统>"
                        };
                        var bar = new UIMailHead(testinfo);
                        _mailList.Add(bar);
                    }
                }
                else
                {
                    MessageSender.SendGetMailsHead();
                }
            }
        }
Beispiel #25
0
 public void OnEndDrag(PointerEventData eventData)
 {
     if (UISlot.getSlot().getItem() != null)
     {
         this.transform.SetParent(originalParent);
         transform.localPosition = originalPos;
         RaycastResult ray = eventData.pointerCurrentRaycast;
         if (ray.gameObject != null && ray.gameObject.name.Equals("ItemIcon"))
         {
             UISlot otherUISlot = ray.gameObject.GetComponent <Dragable>().UISlot;
             UIHandler.onDragAndDropEvent(this.UISlot.getSlot(), otherUISlot.getSlot());
         }
         else if (ray.gameObject.name.Equals("Slot"))
         {
         }
         else
         {
             ItemStack item = this.UISlot.parentSlot.getItem();
             this.UISlot.parentSlot.setItem(null);
             GameManager.getLocalPlayer().dropItem(item);
         }
         image.raycastTarget = true;
     }
 }
Beispiel #26
0
 private void EndDrag(UISlot itemSlot)
 {
     dragItemSlot  = null;
     dragSkillSlot = null;
     draggableIcon.gameObject.SetActive(false);
 }
Beispiel #27
0
 private void Drag(UISlot itemSlot)
 {
     draggableIcon.transform.position = Input.mousePosition;
 }
Beispiel #28
0
    public void OnSlotClicked(UISlot slot)
    {
        switch (slot.type)
        {
        case UISlot.Type.WEAPON:
        {
            if (selectedShopSlot == -1)
            {
                shopTutorial.text = "Please choose an item to purchase first";
            }
            else
            {
                selectedWeaponSlot = slot.id;
            }
            break;
        }

        case UISlot.Type.MAGIC:
        {
            if (selectedShopSlot == -1)
            {
                shopTutorial.text = "Please choose an item to purchase first";
            }
            else
            {
                selectedMagicSlot = slot.id;
            }
            break;
        }

        case UISlot.Type.ARMOUR:
        {
            if (selectedShopSlot == -1)
            {
                shopTutorial.text = "Please choose an item to purchase first";
            }
            else
            {
                selectedArmourSlot = slot.id;
            }
            break;
        }

        case UISlot.Type.SHOP:
        {
            if (slot.item == null)
            {
                shopTutorial.text = "Already purchased";
            }
            else
            {
                shopTutorial.text = "Select a slot to replace";
                selectedShopSlot  = slot.id;
                slot.SetSelected(true);
            }
            break;
        }
        }

        // Now compare selections
        if (selectedShopSlot != -1)
        {
            UISlot shopSlot = shopSlots[selectedShopSlot];
            // We ready to purchase a weapon
            if (shopSlot.item is Weapon && selectedWeaponSlot != -1)
            {
                if (shopSlot.item.cost <= Game.inst.currency)
                {
                    // Purchase the item
                    Game.inst.SpendCurrency(shopSlot.item.cost);
                    Player.inst.inventory.Purchase(shopSlot.item, selectedWeaponSlot);
                    // Update visual slots
                    weaponSlots[selectedWeaponSlot].SetItem(shopSlot.item, UISlot.Type.WEAPON, selectedWeaponSlot);
                    shopSlot.SetItem(null, UISlot.Type.SHOP, selectedShopSlot);
                }
                else
                {
                    shopTutorial.text = "You can't afford that";
                }

                // Reset selections
                shopSlot.SetSelected(false);
                weaponSlots[selectedWeaponSlot].SetSelected(false);
                selectedShopSlot   = -1;
                selectedWeaponSlot = -1;
            }

            // We ready to purchase a spell
            if (shopSlot.item is Spell && selectedMagicSlot != -1)
            {
                if (shopSlot.item.cost <= Game.inst.currency)
                {
                    // Purchase the item
                    Game.inst.SpendCurrency(shopSlot.item.cost);
                    Player.inst.inventory.Purchase(shopSlot.item, selectedMagicSlot);
                    // Update visual slots
                    magicSlots[selectedMagicSlot].SetItem(shopSlot.item, UISlot.Type.MAGIC, selectedMagicSlot);
                    shopSlot.SetItem(null, UISlot.Type.SHOP, selectedShopSlot);
                }
                else
                {
                    shopTutorial.text = "You can't afford that";
                }

                // Reset selections
                magicSlots[selectedMagicSlot].SetSelected(false);
                shopSlot.SetSelected(false);
                selectedShopSlot   = -1;
                selectedWeaponSlot = -1;
            }

            // We ready to purchase an armour
            if (shopSlot.item is Armour && selectedArmourSlot != -1)
            {
                if (shopSlot.item.cost <= Game.inst.currency)
                {
                    // Purchase the item
                    Game.inst.SpendCurrency(shopSlot.item.cost);
                    Player.inst.inventory.Purchase(shopSlot.item, selectedArmourSlot);
                    // Update visual slots
                    armourSlots[selectedArmourSlot].SetItem(shopSlot.item, UISlot.Type.ARMOUR, selectedArmourSlot);
                    shopSlot.SetItem(null, UISlot.Type.SHOP, selectedShopSlot);
                }
                else
                {
                    shopTutorial.text = "You can't afford that";
                }

                // Reset selections
                armourSlots[selectedArmourSlot].SetSelected(false);
                shopSlot.SetSelected(false);
                selectedShopSlot   = -1;
                selectedArmourSlot = -1;
            }
        }
    }
 private void UpdateQuantity(UISlot slot)
 {
     slot.quantity.text  = $"{inventory.GetAmountOf(slot.Set.item)}/{slot.Set.quantity}";
     slot.quantity.color = (inventory.GetAmountOf(slot.Set.item) < slot.Set.quantity) ? Color.red : Color.white;
 }
Beispiel #30
0
 void Start()
 {
     UISlot         = transform.parent.GetComponent <UISlot>();
     image          = GetComponent <Image>();
     originalParent = this.transform.parent;
 }
 // this function will be called by slot of other storage, when the slot be dropped on this storage
 public virtual void Income_Slot(UISlot slot)
 {
     Debug.Log("Slot income: " + slot.slot_id);
 }
Beispiel #32
0
 // Start is called before the first frame update
 void Start()
 {
     m_ParentSlotScript = ParentObject?.GetComponent <UISlot>();
 }
 /// <summary>
 /// Sets the first UISlot.
 /// </summary>
 /// <param name="_slot"></param>
 private void SetFirstUISlot(UISlot _slot)
 {
     UISlotFirst = _slot;
     Icon.SetActive(true);
     Icon.GetComponent <Image>().sprite = _slot.GetSprite;
 }
        private void Slot_OnPickItem(UIElement target)
        {
            UISlot slot = (UISlot)target;

            MessageSender.SendPickMailItem(SelectedMailItem.MailID, (byte)slot.Index);
        }
Beispiel #35
0
    // 交换/合并分栏
    void Exchange(UISlot slot)
    {
        ItemBase item = ItemDatabase.GetItem(slot.item_id);
        UISlot us = Get_UISlot_On_End_Drag();
        if (us != null)
        {
            if (us.slot_id != slot.slot_id)
            {
                backpackSys.backpack.ExChange(us.slot_id, slot.slot_id);

                Sync();
            }

        }
    }
Beispiel #36
0
    // 出售道具
    void Sell(UISlot slot)
    {
        // 通过数据库查询道具,因为空的UISlot不能被拖放,所以这里就不判断空道具了
        ItemBase item = ItemDatabase.GetItem(slot.item_id);

        // reject
        // 该道具是否属于被拒绝的类型
        foreach(ItemBase.Type t in rejectType)
        {
            if (t == item.type)
                return;
        }

        // 获取作为通货的道具
        ItemBase money = ItemDatabase.GetItem(moneyID);
        // 获取当前UISlot中的道具数量
        int sellStatk = slot.storage.backpackSys.backpack.Get_Stack(slot.slot_id);
        // add money and remove the item to/from slot.storage
        // 为那个传进来的UISlot所属的面板的背包系统中的背包添加适当的通货,同时移除道具。
        // 说人话就是,为玩家背包添加金钱,移除出售了的道具。
        slot.storage.backpackSys.backpack.Add(money.item_id, item.sell*sellStatk);
        slot.storage.backpackSys.backpack.Remove(slot.slot_id,item.item_id,sellStatk);
        // sync
        // 同步双方的面板和数据
        slot.storage.Sync();
        Sync();
    }
Beispiel #37
0
    // 买操作
    void Buy(UISlot slot)
    {
        // 通过数据库查询道具,因为空的UISlot不能被拖放,所以这里就不判断空道具了
        ItemBase item = ItemDatabase.GetItem(slot.item_id);

        // 获取本面板中的被交互的UISlot
        UISlot uis = Get_UISlot_On_End_Drag();
        if (uis != null)
        {
            // enougth money
            // 是否有足够的通货买道具,
            // 每次买卖一组道具,通过for循环来购买,每次购买一个,直到钱不足或满足购买数量。
            for(int i=0;i<item.maxStack; i++)
            {
                // 判断是否有足够的钱购买一个道具
                if (backpackSys.backpack.Get_Stack(slot.storage.moneyID) >= item.buy)
                {
                    // 是否有足够的空间购买道具
                    if (backpackSys.backpack.Add(uis.slot_id,item.item_id,1) == 1)
                    {
                        // 勾除响应的通货
                        backpackSys.backpack.Remove(slot.storage.moneyID,item.buy);
                    }
                    else
                    {
                        break;
                    }
                }
                else
                {
                    break;
                }
            }
            // 同步双方的面板
            slot.storage.Sync();
            Sync();
        }
    }
Beispiel #38
0
 // 卸载
 void Unequip(UISlot slot)
 {
     // 获取本面板中的被交互的UISlot
     UISlot uis = Get_UISlot_On_End_Drag();
     if (uis != null)
     {
         // 是否有足够的空位放卸载的道具
         if (backpackSys.backpack.Add(uis.slot_id,slot.item_id,1) == 1)
         {
             // 移除装备栏中的道具
             backpackSys.equipment.Remove(slot.slot_id,slot.item_id,1);
         }
         // 同步双方的面板
         Sync();
         slot.storage.Sync();
     }
 }