// Assign our componenet based on the slot type.
    private void LateUpdate()
    {
        player = Player.localPlayer;

        if (player != null)
        {
            switch (slotType)
            {
            case SlotType.Equipment:
                // refresh all
                int lastECount = 0;
                if (lastECount != player.equipment.Count)
                {
                    for (int i = 0; i < player.equipment.Count; ++i)
                    {
                        lastECount = player.equipment.Count;
                        if (player.equipment[i].amount > 0)
                        {
                            UIEquipment equipmentContents = gameObject.GetComponent <UIEquipment>();
                            UIUtils.BalancePrefabs(equipmentContents.slotPrefab.gameObject, player.equipment.Count, equipmentContents.content);
                            if (equipmentContents.panel.activeSelf)
                            {
                                UIEquipmentSlot slot = equipmentContents.content.transform.GetChild(i).GetComponent <UIEquipmentSlot>();
                                raritySlot = slot.GetComponent <UCE_RaritySlot>();
                                tooltip    = slot.tooltip;
                                slot.dragAndDropable.name = i.ToString();     // drag and drop slot
                                itemSlot = player.equipment[i];
                                SetRarityColor(itemSlot.item.data);
                            }
                        }
                        else
                        {
                            UIEquipment equipmentContents = gameObject.GetComponent <UIEquipment>();
                            if (equipmentContents.panel.activeSelf)
                            {
                                UIEquipmentSlot slot = equipmentContents.content.transform.GetChild(i).GetComponent <UIEquipmentSlot>();
                                raritySlot = slot.GetComponent <UCE_RaritySlot>();
                                raritySlot.rarityOutline.color = Color.clear;
                            }
                        }
                    }
                }
                break;

            case SlotType.Inventory:
                // refresh all
                int lastICount = 0;
                if (lastICount != player.inventory.Count)
                {
                    for (int i = 0; i < player.inventory.Count; ++i)
                    {
                        lastICount = player.inventory.Count;
                        if (player.inventory[i].amount > 0)
                        {
                            UIInventory inventoryContents = GetComponent <UIInventory>();
                            UIUtils.BalancePrefabs(inventoryContents.slotPrefab.gameObject, player.inventory.Count, inventoryContents.content);
                            if (inventoryContents.panel.activeSelf)
                            {
                                UIInventorySlot slot = inventoryContents.content.transform.GetChild(i).GetComponent <UIInventorySlot>();
                                raritySlot = slot.GetComponent <UCE_RaritySlot>();
                                tooltip    = slot.tooltip;
                                slot.dragAndDropable.name = i.ToString();     // drag and drop slot
                                itemSlot = player.inventory[i];
                                SetRarityColor(itemSlot.item.data);
                            }
                        }
                        else
                        {
                            UIInventory inventoryContents = gameObject.GetComponent <UIInventory>();
                            if (inventoryContents.panel.activeSelf)
                            {
                                UIInventorySlot slot = inventoryContents.content.transform.GetChild(i).GetComponent <UIInventorySlot>();
                                raritySlot = slot.GetComponent <UCE_RaritySlot>();
                                raritySlot.rarityOutline.color = Color.clear;
                            }
                        }
                    }
                }
                break;

            case SlotType.Loot:
                if (player.target != null && player.target.health <= 0)
                {
                    UILoot          lootContent = GetComponent <UILoot>();
                    List <ItemSlot> items       = player.target.inventory.Where(slot => slot.amount > 0).ToList();
                    UIUtils.BalancePrefabs(lootContent.itemSlotPrefab.gameObject, items.Count, lootContent.content);

                    // refresh all valid items
                    for (int i = 0; i < items.Count; ++i)
                    {
                        UILootSlot slot = lootContent.content.GetChild(i).GetComponent <UILootSlot>();
                        slot.dragAndDropable.name = i.ToString();     // drag and drop index
                        int itemIndex = player.target.inventory.FindIndex(
                            // note: .Equals because name AND dynamic variables matter (petLevel etc.)
                            itemSlot => itemSlot.amount > 0 && itemSlot.item.Equals(items[i].item)
                            );

                        // refresh
                        raritySlot = slot.GetComponent <UCE_RaritySlot>();
                        tooltip    = slot.tooltip;
                        slot.dragAndDropable.name = i.ToString();     // drag and drop slot
                        itemSlot = items[i];
                        SetRarityColor(itemSlot.item.data);
                    }
                }
                break;

            case SlotType.PlayerTrade:
                if (player.state == "TRADING")
                {
                    Player other        = (Player)player.target;
                    int    lastPTYCount = 0;
                    if (lastPTYCount != player.tradeOfferItems.Count)
                    {
                        for (int i = 0; i < player.tradeOfferItems.Count; ++i)
                        {
                            lastPTYCount = player.tradeOfferItems.Count;
                            UIPlayerTrading tradeContents = GetComponent <UIPlayerTrading>();
                            UIUtils.BalancePrefabs(tradeContents.slotPrefab.gameObject, player.tradeOfferItems.Count, tradeContents.myContent);
                            if (tradeContents.panel.activeSelf)
                            {
                                UIPlayerTradingSlot slot = tradeContents.myContent.transform.GetChild(i).GetComponent <UIPlayerTradingSlot>();
                                if (slot.amountText.text != "0")
                                {
                                    raritySlot = slot.GetComponent <UCE_RaritySlot>();
                                    tooltip    = slot.tooltip;
                                    slot.dragAndDropable.name = i.ToString();     // drag and drop slot
                                    int inventoryIndex = player.tradeOfferItems[i];
                                    itemSlot = player.inventory[inventoryIndex];
                                    SetRarityColor(itemSlot.item.data);
                                }
                                else
                                {
                                    raritySlot = slot.GetComponent <UCE_RaritySlot>();
                                    raritySlot.rarityOutline.color = Color.clear;
                                }
                            }
                        }
                    }

                    int lastPTOCount = 0;
                    if (lastPTOCount != other.tradeOfferItems.Count)
                    {
                        for (int i = 0; i < other.tradeOfferItems.Count; ++i)
                        {
                            lastPTOCount = other.tradeOfferItems.Count;
                            UIPlayerTrading tradeContents = GetComponent <UIPlayerTrading>();
                            UIUtils.BalancePrefabs(tradeContents.slotPrefab.gameObject, other.tradeOfferItems.Count, tradeContents.otherContent);
                            if (tradeContents.panel.activeSelf)
                            {
                                UIPlayerTradingSlot slot = tradeContents.otherContent.transform.GetChild(i).GetComponent <UIPlayerTradingSlot>();
                                if (slot.amountText.text != "0")
                                {
                                    raritySlot = slot.GetComponent <UCE_RaritySlot>();
                                    tooltip    = slot.tooltip;
                                    slot.dragAndDropable.name = i.ToString();     // drag and drop slot
                                    int inventoryIndex = other.tradeOfferItems[i];
                                    itemSlot = other.inventory[inventoryIndex];
                                    SetRarityColor(itemSlot.item.data);
                                }
                                else
                                {
                                    raritySlot = slot.GetComponent <UCE_RaritySlot>();
                                    raritySlot.rarityOutline.color = Color.clear;
                                }
                            }
                        }
                    }
                }
                break;

            case SlotType.NpcTrade:
                if (player.target is Npc)
                {
                    Npc npc = (Npc)player.target;
#if _iMMONPCSHOP
                    UCE_UI_NpcShop shopContents = GetComponent <UCE_UI_NpcShop>();
                    if (shopContents.panel.activeSelf)
                    {
                        ScriptableItem[] items = npc.saleItems.Where(x => x.itemCategory == shopContents.currentCategory || shopContents.currentCategory == "").ToArray();
                        UIUtils.BalancePrefabs(shopContents.itemSlotPrefab.gameObject, items.Length, shopContents.itemContent);

                        int    lastIMCount = 0;
                        string currentPage = "";
                        if (lastIMCount != items.Length || currentPage != shopContents.currentCategory)
                        {
                            for (int i = 0; i < items.Length; ++i)
                            {
                                lastIMCount = items.Length;
                                currentPage = shopContents.currentCategory;

                                UCE_UI_NpcShopSlot slot = shopContents.itemContent.GetChild(i).GetComponent <UCE_UI_NpcShopSlot>();
                                raritySlot = slot.GetComponent <UCE_RaritySlot>();
                                tooltip    = slot.tooltip;
                                scriptItem = items[i];
                                SetRarityColor(scriptItem);
                            }
                        }
                    }
#else
                    int lastNTCount = 0;
                    if (lastNTCount != npc.saleItems.Length)
                    {
                        for (int i = 0; i < npc.saleItems.Length; ++i)
                        {
                            lastNTCount = npc.saleItems.Length;
                            UINpcTrading npcContents = GetComponent <UINpcTrading>();
                            UIUtils.BalancePrefabs(npcContents.slotPrefab.gameObject, npc.saleItems.Length, npcContents.content);
                            if (npcContents.panel.activeSelf)
                            {
                                UINpcTradingSlot slot = npcContents.content.transform.GetChild(i).GetComponent <UINpcTradingSlot>();
                                raritySlot = slot.GetComponent <UCE_RaritySlot>();
                                tooltip    = slot.tooltip;
                                scriptItem = npc.saleItems[i];
                                SetRarityColor(scriptItem);
                            }
                        }
                    }
#endif
                }
                break;

            case SlotType.ItemMall:
                UIItemMall mallContents = GetComponent <UIItemMall>();
                if (mallContents.panel.activeSelf)
                {
                    ScriptableItem[] items = player.itemMallCategories[mallContents.currentCategory].items;
                    UIUtils.BalancePrefabs(mallContents.itemSlotPrefab.gameObject, items.Length, mallContents.itemContent);

                    int lastIMCount = 0;
                    int currentPage = 0;
                    if (lastIMCount != items.Length || currentPage != mallContents.currentCategory)
                    {
                        for (int i = 0; i < items.Length; ++i)
                        {
                            lastIMCount = items.Length;
                            currentPage = mallContents.currentCategory;
                            UIItemMallSlot slot = mallContents.itemContent.GetChild(i).GetComponent <UIItemMallSlot>();
                            raritySlot = slot.GetComponent <UCE_RaritySlot>();
                            tooltip    = slot.tooltip;
                            scriptItem = items[i];
                            SetRarityColor(scriptItem);
                        }
                    }
                }
                break;

            case SlotType.Crafting:
                UICrafting craftContents = GetComponent <UICrafting>();
                UIUtils.BalancePrefabs(craftContents.ingredientSlotPrefab.gameObject, player.craftingIndices.Count, craftContents.ingredientContent);
                if (craftContents.panel.activeSelf)
                {
                    int lastCCount = 0;
                    if (lastCCount != player.craftingIndices.Count)
                    {
                        for (int i = 0; i < player.craftingIndices.Count; ++i)
                        {
                            lastCCount = player.craftingIndices.Count;
                            UICraftingIngredientSlot slot = craftContents.ingredientContent.GetChild(i).GetComponent <UICraftingIngredientSlot>();
                            if (player.craftingIndices[i] != -1)
                            {
                                int itemIndex = player.craftingIndices[i];
                                raritySlot = slot.GetComponent <UCE_RaritySlot>();
                                tooltip    = slot.tooltip;
                                itemSlot   = player.inventory[itemIndex];
                                SetRarityColor(itemSlot.item.data);
                            }
                            else
                            {
                                raritySlot = slot.GetComponent <UCE_RaritySlot>();
                                raritySlot.rarityOutline.color = Color.clear;
                            }
                        }
                    }
                }
                break;
            }
        }
    }
예제 #2
0
    void Update()
    {
        Player player = Player.localPlayer;

        // only if trading, otherwise set inactive
        if (player != null &&
            player.state == "TRADING" && player.target != null && player.target is Player)
        {
            panel.SetActive(true);
            Player other = (Player)player.target;

            // OTHER ///////////////////////////////////////////////////////////
            // status text
            if (other.tradeStatus == TradeStatus.Accepted)
            {
                otherStatusText.text = "[ACCEPTED]";
            }
            else if (other.tradeStatus == TradeStatus.Locked)
            {
                otherStatusText.text = "[LOCKED]";
            }
            else
            {
                otherStatusText.text = "";
            }

            // gold input
            otherGoldInput.text = other.tradeOfferGold.ToString();

            // items
            UIUtils.BalancePrefabs(slotPrefab.gameObject, other.tradeOfferItems.Count, otherContent);
            for (int i = 0; i < other.tradeOfferItems.Count; ++i)
            {
                UIPlayerTradingSlot slot = otherContent.GetChild(i).GetComponent <UIPlayerTradingSlot>();
                int inventoryIndex       = other.tradeOfferItems[i];

                slot.dragAndDropable.dragable = false;
                slot.dragAndDropable.dropable = false;

                if (0 <= inventoryIndex && inventoryIndex < other.inventory.Count &&
                    other.inventory[inventoryIndex].amount > 0)
                {
                    ItemSlot itemSlot = other.inventory[inventoryIndex];

                    // refresh valid item
                    slot.tooltip.enabled = true;
                    slot.tooltip.text    = itemSlot.ToolTip();
                    slot.image.color     = Color.white;
                    slot.image.sprite    = itemSlot.item.image;
                    slot.amountOverlay.SetActive(itemSlot.amount > 1);
                    slot.amountText.text = itemSlot.amount.ToString();
                }
                else
                {
                    // refresh invalid item
                    slot.tooltip.enabled = false;
                    slot.image.color     = Color.clear;
                    slot.image.sprite    = null;
                    slot.amountOverlay.SetActive(false);
                }
            }

            // SELF ////////////////////////////////////////////////////////////
            // status text
            if (player.tradeStatus == TradeStatus.Accepted)
            {
                myStatusText.text = "[ACCEPTED]";
            }
            else if (player.tradeStatus == TradeStatus.Locked)
            {
                myStatusText.text = "[LOCKED]";
            }
            else
            {
                myStatusText.text = "";
            }

            // gold input
            if (player.tradeStatus == TradeStatus.Free)
            {
                myGoldInput.interactable = true;
                myGoldInput.onValueChanged.SetListener(val => {
                    long goldOffer   = Utils.Clamp(val.ToLong(), 0, player.gold);
                    myGoldInput.text = goldOffer.ToString();
                    player.CmdTradeOfferGold(goldOffer);
                });
            }
            else
            {
                myGoldInput.interactable = false;
                myGoldInput.text         = player.tradeOfferGold.ToString();
            }

            // items
            UIUtils.BalancePrefabs(slotPrefab.gameObject, player.tradeOfferItems.Count, myContent);
            for (int i = 0; i < player.tradeOfferItems.Count; ++i)
            {
                UIPlayerTradingSlot slot = myContent.GetChild(i).GetComponent <UIPlayerTradingSlot>();
                slot.dragAndDropable.name = i.ToString(); // drag and drop index
                int inventoryIndex = player.tradeOfferItems[i];

                if (0 <= inventoryIndex && inventoryIndex < player.inventory.Count &&
                    player.inventory[inventoryIndex].amount > 0)
                {
                    ItemSlot itemSlot = player.inventory[inventoryIndex];

                    // refresh valid item
                    slot.tooltip.enabled          = true;
                    slot.tooltip.text             = itemSlot.ToolTip();
                    slot.dragAndDropable.dragable = player.tradeStatus == TradeStatus.Free;
                    slot.image.color  = Color.white;
                    slot.image.sprite = itemSlot.item.image;
                    slot.amountOverlay.SetActive(itemSlot.amount > 1);
                    slot.amountText.text = itemSlot.amount.ToString();
                }
                else
                {
                    // refresh invalid item
                    slot.tooltip.enabled          = false;
                    slot.dragAndDropable.dragable = false;
                    slot.image.color  = Color.clear;
                    slot.image.sprite = null;
                    slot.amountOverlay.SetActive(false);
                }
            }

            // buttons /////////////////////////////////////////////////////////
            // lock
            lockButton.interactable = player.tradeStatus == TradeStatus.Free;
            lockButton.onClick.SetListener(() => {
                player.CmdTradeOfferLock();
            });

            // accept (only if both have locked the trade & if not accepted yet)
            // accept (if not accepted yet & other has locked or accepted)
            acceptButton.interactable = player.tradeStatus == TradeStatus.Locked &&
                                        other.tradeStatus != TradeStatus.Free;
            acceptButton.onClick.SetListener(() => {
                player.CmdTradeOfferAccept();
            });

            // cancel
            cancelButton.onClick.SetListener(() => {
                player.CmdTradeCancel();
            });
        }
        else
        {
            panel.SetActive(false);
            myGoldInput.text = "0"; // reset
        }
    }
예제 #3
0
    void Update()
    {
        Player player = Player.localPlayer;

        // only if trading, otherwise set inactive
        if (player != null &&
            player.state == "TRADING" &&
            player.target != null &&
            player.target is Player other)
        {
            panel.SetActive(true);

            // OTHER ///////////////////////////////////////////////////////////
            // status text
            if (other.trading.state == TradingState.Accepted)
            {
                otherStatusText.text = "[ACCEPTED]";
            }
            else if (other.trading.state == TradingState.Locked)
            {
                otherStatusText.text = "[LOCKED]";
            }
            else
            {
                otherStatusText.text = "";
            }

            // gold input
            otherGoldInput.text = other.trading.offerGold.ToString();

            // items
            UIUtils.BalancePrefabs(slotPrefab.gameObject, other.trading.offerItems.Count, otherContent);
            for (int i = 0; i < other.trading.offerItems.Count; ++i)
            {
                UIPlayerTradingSlot slot = otherContent.GetChild(i).GetComponent <UIPlayerTradingSlot>();
                int inventoryIndex       = other.trading.offerItems[i];

                slot.dragAndDropable.dragable = false;
                slot.dragAndDropable.dropable = false;

                if (0 <= inventoryIndex && inventoryIndex < other.inventory.slots.Count &&
                    other.inventory.slots[inventoryIndex].amount > 0)
                {
                    ItemSlot itemSlot = other.inventory.slots[inventoryIndex];

                    // refresh valid item

                    // only build tooltip while it's actually shown. this
                    // avoids MASSIVE amounts of StringBuilder allocations.
                    slot.tooltip.enabled = true;
                    if (slot.tooltip.IsVisible())
                    {
                        slot.tooltip.text = itemSlot.ToolTip();
                    }

                    // use durability colors?
                    if (itemSlot.item.maxDurability > 0)
                    {
                        if (itemSlot.item.durability == 0)
                        {
                            slot.image.color = brokenDurabilityColor;
                        }
                        else if (itemSlot.item.DurabilityPercent() < lowDurabilityThreshold)
                        {
                            slot.image.color = lowDurabilityColor;
                        }
                        else
                        {
                            slot.image.color = Color.white;
                        }
                    }
                    else
                    {
                        slot.image.color = Color.white;  // reset for no-durability items
                    }
                    slot.image.sprite = itemSlot.item.image;

                    slot.amountOverlay.SetActive(itemSlot.amount > 1);
                    slot.amountText.text = itemSlot.amount.ToString();
                }
                else
                {
                    // refresh invalid item
                    slot.tooltip.enabled = false;
                    slot.image.color     = Color.clear;
                    slot.image.sprite    = null;
                    slot.amountOverlay.SetActive(false);
                }
            }

            // SELF ////////////////////////////////////////////////////////////
            // status text
            if (player.trading.state == TradingState.Accepted)
            {
                myStatusText.text = "[ACCEPTED]";
            }
            else if (player.trading.state == TradingState.Locked)
            {
                myStatusText.text = "[LOCKED]";
            }
            else
            {
                myStatusText.text = "";
            }

            // gold input
            if (player.trading.state == TradingState.Free)
            {
                myGoldInput.interactable = true;
                myGoldInput.onValueChanged.SetListener(val => {
                    long goldOffer   = Utils.Clamp(val.ToLong(), 0, player.gold);
                    myGoldInput.text = goldOffer.ToString();
                    player.trading.CmdOfferGold(goldOffer);
                });
            }
            else
            {
                myGoldInput.interactable = false;
                myGoldInput.text         = player.trading.offerGold.ToString();
            }

            // items
            UIUtils.BalancePrefabs(slotPrefab.gameObject, player.trading.offerItems.Count, myContent);
            for (int i = 0; i < player.trading.offerItems.Count; ++i)
            {
                UIPlayerTradingSlot slot = myContent.GetChild(i).GetComponent <UIPlayerTradingSlot>();
                slot.dragAndDropable.name = i.ToString(); // drag and drop index
                int inventoryIndex = player.trading.offerItems[i];

                if (0 <= inventoryIndex && inventoryIndex < player.inventory.slots.Count &&
                    player.inventory.slots[inventoryIndex].amount > 0)
                {
                    ItemSlot itemSlot = player.inventory.slots[inventoryIndex];

                    // refresh valid item

                    // only build tooltip while it's actually shown. this
                    // avoids MASSIVE amounts of StringBuilder allocations.
                    slot.tooltip.enabled = true;
                    if (slot.tooltip.IsVisible())
                    {
                        slot.tooltip.text = itemSlot.ToolTip();
                    }
                    slot.dragAndDropable.dragable = player.trading.state == TradingState.Free;

                    // use durability colors?
                    if (itemSlot.item.maxDurability > 0)
                    {
                        if (itemSlot.item.durability == 0)
                        {
                            slot.image.color = brokenDurabilityColor;
                        }
                        else if (itemSlot.item.DurabilityPercent() < lowDurabilityThreshold)
                        {
                            slot.image.color = lowDurabilityColor;
                        }
                        else
                        {
                            slot.image.color = Color.white;
                        }
                    }
                    else
                    {
                        slot.image.color = Color.white;  // reset for no-durability items
                    }
                    slot.image.sprite = itemSlot.item.image;

                    slot.amountOverlay.SetActive(itemSlot.amount > 1);
                    slot.amountText.text = itemSlot.amount.ToString();
                }
                else
                {
                    // refresh invalid item
                    slot.tooltip.enabled          = false;
                    slot.dragAndDropable.dragable = false;
                    slot.image.color  = Color.clear;
                    slot.image.sprite = null;
                    slot.amountOverlay.SetActive(false);
                }
            }

            // buttons /////////////////////////////////////////////////////////
            // lock
            lockButton.interactable = player.trading.state == TradingState.Free;
            lockButton.onClick.SetListener(() => {
                player.trading.CmdLockOffer();
            });

            // accept (only if both have locked the trade & if not accepted yet)
            // accept (if not accepted yet & other has locked or accepted)
            acceptButton.interactable = player.trading.state == TradingState.Locked &&
                                        other.trading.state != TradingState.Free;
            acceptButton.onClick.SetListener(() => {
                player.trading.CmdAcceptOffer();
            });

            // cancel
            cancelButton.onClick.SetListener(() => {
                player.trading.CmdCancel();
            });
        }
        else
        {
            panel.SetActive(false);
            myGoldInput.text = "0"; // reset
        }
    }