// Controls all functionality for buffs on target.
    private void BuffControl(Entity target)
    {
        // target buffs
        UIUtils.BalancePrefabs(buffSlotPrefab.gameObject, target.buffs.Count, buffsPanel);
        for (int i = 0; i < target.buffs.Count; ++i)
        {
            UIBuffSlot slot = buffsPanel.GetChild(i).GetComponent <UIBuffSlot>();

            // refresh
            slot.image.color     = Color.white;
            slot.image.sprite    = target.buffs[i].image;
            slot.tooltip.text    = target.buffs[i].ToolTip();
            slot.slider.maxValue = target.buffs[i].buffTime;
            slot.slider.value    = target.buffs[i].BuffTimeRemaining();
        }
    }
Example #2
0
    // -----------------------------------------------------------------------------------
    // Prepare
    // -----------------------------------------------------------------------------------
    public void Prepare()
    {
        Player player = Player.localPlayer;

        if (!player)
        {
            return;
        }

        UIUtils.BalancePrefabs(friendRow.gameObject, player.UCE_Friends.Count, content);

        for (int i = 0; i < player.UCE_Friends.Count; i++)
        {
            UCE_UI_FriendRow friendRow = content.GetChild(i).GetComponent <UCE_UI_FriendRow>();
            friendRow.SetData(i);
        }
    }
    void Update()
    {
        Player player = Utils.ClientLocalPlayer();

        if (!player)
        {
            return;
        }

        // hotkey (not while typing in chat, etc.)
        if (Input.GetKeyDown(hotKey) && !UIUtils.AnyInputActive())
        {
            panel.SetActive(!panel.activeSelf);
        }

        // only update the panel if it's active
        if (panel.activeSelf)
        {
            // only show active quests, no completed ones
            List <Quest> activeQuests = player.quests.Where(q => !q.completed).ToList();

            // instantiate/destroy enough slots
            UIUtils.BalancePrefabs(slotPrefab.gameObject, activeQuests.Count, content);

            // refresh all
            for (int i = 0; i < activeQuests.Count; ++i)
            {
                UIQuestSlot slot  = content.GetChild(i).GetComponent <UIQuestSlot>();
                Quest       quest = activeQuests[i];

                // name button
                GameObject descriptionPanel = slot.descriptionText.gameObject;
                string     prefix           = descriptionPanel.activeSelf ? hidePrefix : expandPrefix;
                slot.nameButton.GetComponentInChildren <Text>().text = prefix + quest.name;
                slot.nameButton.onClick.SetListener(() => {
                    descriptionPanel.SetActive(!descriptionPanel.activeSelf);
                });

                // description
                int gathered = quest.gatherItem != null?player.InventoryCount(new Item(quest.gatherItem)) : 0;

                slot.descriptionText.text = quest.ToolTip(gathered);
            }
        }
    }
    // -----------------------------------------------------------------------------------
    // Update
    // @Client
    // -----------------------------------------------------------------------------------
    public void Update()
    {
        Player player = Player.localPlayer;

        if (!player)
        {
            return;
        }

        if (panel.activeSelf &&
            player.target != null &&
            player.target is Npc &&
            Utils.ClosestDistance(player.collider, player.target.collider) <= player.interactionRange
            )
        {
            Npc npc = (Npc)player.target;

            UIUtils.BalancePrefabs(slotPrefab.gameObject, npc.teleportationDestinations.Length, content);

            for (int i = 0; i < npc.teleportationDestinations.Length; ++i)
            {
                int index = i;

                UCE_Slot_Teleportation slot = content.GetChild(index).GetComponent <UCE_Slot_Teleportation>();

                slot.actionButton.interactable = npc.teleportationDestinations[index].teleportationRequirement.checkRequirements(player);

                slot.actionButton.GetComponentInChildren <Text>().text = labelTeleport + npc.teleportationDestinations[index].teleportationTarget.name;

                slot.actionButton.onClick.SetListener(() =>
                {
                    player.Cmd_NpcWarp(index);
                    panel.SetActive(false);
                });
            }

            panel.SetActive(true);
        }
        else
        {
            panel.SetActive(false);
        }
    }
Example #5
0
    void Update()
    {
        Player player = Player.localPlayer;

        // use collider point(s) to also work with big entities
        if (player != null &&
            panel.activeSelf &&
            player.target != null &&
            player.target is Npc npc &&
            Utils.ClosestDistance(player, player.target) <= player.interactionRange)
        {
            // welcome text
            welcomeText.text = npc.welcome;

            // count amount of valid offers
            int validOffers = 0;
            foreach (NpcOffer offer in npc.offers)
            {
                if (offer.HasOffer(player))
                {
                    ++validOffers;
                }
            }

            // instantiate enough buttons
            UIUtils.BalancePrefabs(offerButtonPrefab, validOffers, offerPanel);

            // show a button for each valid offer
            int index = 0;
            foreach (NpcOffer offer in npc.offers)
            {
                if (offer.HasOffer(player))
                {
                    Button button = offerPanel.GetChild(index).GetComponent <Button>();
                    button.GetComponentInChildren <Text>().text = offer.GetOfferName();
                    button.onClick.SetListener(() => {
                        offer.OnSelect(player);
                    });
                    ++index;
                }
            }
        }
    // -----------------------------------------------------------------------------------
    //
    // -----------------------------------------------------------------------------------
    public void UpdateSearchResults(List <MailSearch> results)
    {
        UIUtils.BalancePrefabs(searchSlot.gameObject, results.Count, searchContent);

        for (int i = 0; i < results.Count; ++i)
        {
            UIMailSearchSlot slot = searchContent.GetChild(i).GetComponent <UIMailSearchSlot>();
            slot.nameText.text  = results[i].name;
            slot.levelText.text = results[i].level.ToString();
            slot.guildText.text = results[i].guild == null ? "" : results[i].guild;
            slot.actionButton.onClick.SetListener(() =>
            {
                recipient = slot.nameText.text;
            });
        }

        searchButton.interactable = true;
        search.interactable       = true;
        sending = false;
        dialog.SetActive(false);
    }
Example #7
0
    void Update()
    {
        Player player = Utils.ClientLocalPlayer();

        if (!player)
        {
            return;
        }

        // hotkey (not while typing in chat, etc.)
        if (Input.GetKeyDown(hotKey) && !UIUtils.AnyInputActive())
        {
            panel.SetActive(!panel.activeSelf);
        }

        // only update the panel if it's active
        if (panel.activeSelf)
        {
            // only show active quests, no completed ones
            List <Quest> activeQuests = player.quests.Where(q => !q.completed).ToList();

            // instantiate/destroy enough slots
            UIUtils.BalancePrefabs(slotPrefab.gameObject, activeQuests.Count, content);

            // refresh all
            for (int i = 0; i < activeQuests.Count; ++i)
            {
                UIQuestSlot slot     = content.GetChild(i).GetComponent <UIQuestSlot>();
                Quest       quest    = activeQuests[i];
                int         gathered = quest.gatherItem != null?player.InventoryCount(new Item(quest.gatherItem)) : 0;

                slot.descriptionText.text = quest.ToolTip(gathered);
            }
        }

        // addon system hooks
        Utils.InvokeMany(typeof(UIQuests), this, "Update_");
    }
    // -----------------------------------------------------------------------------------
    // Update
    // -----------------------------------------------------------------------------------
    private void Update()
    {
        Player player = Player.localPlayer;

        if (!player)
        {
            return;
        }

        if (Input.GetKeyDown(hotKey) && !UIUtils.AnyInputActive())
        {
            panel.SetActive(!panel.activeSelf);
        }

        if (panel.activeSelf && player.UCE_Professions.Count > 0)
        {
            UIUtils.BalancePrefabs(slotPrefab.gameObject, player.UCE_Professions.Count, content);

            for (int i = 0; i < content.childCount; i++)
            {
                content.GetChild(i).GetComponent <UCE_UI_HarvestingSlot>().Show(player.UCE_Professions[i]);
            }
        }
    }
Example #9
0
    public void Show(ScriptableDialogue dialogue, GameObject player)
    {
        panel.SetActive(true);

        // show text
        welcomeText.text = dialogue.GetText(player);

        // show choices
        List <DialogueChoice> choices = dialogue.GetChoices(player);

        // instantiate/destroy enough slots
        UIUtils.BalancePrefabs(slotPrefab.gameObject, choices.Count, content);

        // refresh all choices
        for (int i = 0; i < choices.Count; ++i)
        {
            UIDialogueChoice slot = content.GetChild(i).GetComponent <UIDialogueChoice>();

            DialogueChoice choice = choices[i];
            slot.button.interactable = choice.interactable;
            slot.button.GetComponentInChildren <Text>().text = choice.text;
            slot.button.onClick.SetListener(choice.action);
        }
    }
Example #10
0
    // -----------------------------------------------------------------------------------
    // Update
    // -----------------------------------------------------------------------------------
    private void Update()
    {
        Player player = Player.localPlayer;

        if (!player)
        {
            return;
        }

        if (gameObject.activeSelf)
        {
            // instantiate/destroy enough category slots
            UIUtils.BalancePrefabs(currencySlotPrefab.gameObject, player.UCE_currencies.Count, currencyContent);

            // -- Currencies
            for (int i = 0; i < player.UCE_currencies.Count; ++i)
            {
                UCE_UI_HonorCurrencySlot slot = currencyContent.GetChild(i).GetComponent <UCE_UI_HonorCurrencySlot>();
                slot.currencyImage.sprite = player.UCE_currencies[i].honorCurrency.image;
                slot.nameText.text        = player.UCE_currencies[i].honorCurrency.name;
                slot.valueText.text       = player.UCE_currencies[i].amount.ToString();
            }
        }
    }
    // -----------------------------------------------------------------------------------
    // UpdateElements
    // -----------------------------------------------------------------------------------
#if _iMMOELEMENTS
    protected void UpdateElements()
    {
        Player player = Player.localPlayer;

        if (!player)
        {
            return;
        }

        UIUtils.BalancePrefabs(slotElementPrefab.gameObject, UCE_ElementTemplate.dict.Count, elementsContent);

        for (int i = 0; i < UCE_ElementTemplate.dict.Count; ++i)
        {
            UCE_UI_ElementSlot  slot2 = elementsContent.GetChild(i).GetComponent <UCE_UI_ElementSlot>();
            UCE_ElementTemplate ele   = UCE_ElementTemplate.dict.Values.ElementAt(i);
            float points = 1.0f - player.UCE_CalculateElementalResistance(ele);

            slot2.tooltip.enabled = true;
            slot2.tooltip.text    = ele.toolTip;
            slot2.image.sprite    = ele.image;
            slot2.label.text      = ele.name + ":";
            slot2.points.text     = (points * 100).ToString("F0") + "%";
        }
    }
Example #12
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
        }
    }
Example #13
0
    void Update()
    {
        var player = Utils.ClientLocalPlayer();

        if (!player)
        {
            return;
        }

        // instantiate/destroy enough slots (except normal attack)
        UIUtils.BalancePrefabs(slotPrefab.gameObject, player.skills.Count - 1, content);

        // refresh all (except normal attack)
        for (int i = 1; i < player.skills.Count; ++i)
        {
            var slot  = content.GetChild(i - 1).GetComponent <UISkillSlot>();
            var skill = player.skills[i];

            // overlay hotkey (without 'Alpha' etc.)
            slot.hotKeyText.text = player.skillHotkeys[i].ToString().Replace("Alpha", "");

            // click event (done more than once but w/e)
            int icopy = i;
            slot.button.interactable = skill.learned;
            slot.button.onClick.SetListener(() => {
                OnSkillClicked(player, icopy);
            });

            // hotkey pressed and not typing in any input right now?
            if (Input.GetKeyDown(player.skillHotkeys[i]) && !UIUtils.AnyInputActive())
            {
                OnSkillClicked(player, i);
            }

            // set state
            slot.dragAndDropable.dragable = skill.learned;
            // note: entries should be dropable at all times

            // tooltip
            slot.tooltip.text = skill.ToolTip();

            // image
            slot.image.sprite = skill.image;
            slot.image.color  = skill.learned ? Color.white : Color.gray;

            // -> learnable?
            if (!skill.learned &&
                player.level >= skill.requiredLevel &&
                player.SkillpointsSpendable() > 0)
            {
                slot.learnButton.gameObject.SetActive(true);
                slot.learnButton.onClick.SetListener(() => { player.CmdLearnSkill(icopy); });
                // -> upgradeable?
            }
            else if (skill.learned &&
                     skill.level < skill.maxLevel &&
                     player.level >= skill.upgradeRequiredLevel &&
                     player.SkillpointsSpendable() > 0)
            {
                slot.learnButton.gameObject.SetActive(true);
                slot.learnButton.onClick.SetListener(() => { player.CmdUpgradeSkill(icopy); });
                // -> otherwise no button needed
            }
            else
            {
                slot.learnButton.gameObject.SetActive(false);
            }

            // cooldown overlay
            float cd = skill.CooldownRemaining();
            slot.cooldownOverlay.SetActive(skill.learned && cd > 0);
            slot.cooldownText.text = cd.ToString("F0");
        }
    }
Example #14
0
    void Update()
    {
        var player = Utils.ClientLocalPlayer();

        if (!player)
        {
            return;
        }

        // hotkey (not while typing in chat, etc.)
        if (Input.GetKeyDown(hotKey) && !UIUtils.AnyInputActive())
        {
            panel.SetActive(!panel.activeSelf);
        }

        // only update the panel if it's active
        if (panel.activeSelf)
        {
            // instantiate/destroy enough slots
            UIUtils.BalancePrefabs(ingredientSlotPrefab, player.craftingIndices.Count, ingredientContent);

            // refresh all
            for (int i = 0; i < player.craftingIndices.Count; ++i)
            {
                var entry = ingredientContent.GetChild(i).GetChild(0); // slot entry
                entry.name = i.ToString();                             // for drag and drop
                int itemIdx = player.craftingIndices[i];

                if (0 <= itemIdx && itemIdx < player.inventory.Count &&
                    player.inventory[itemIdx].valid)
                {
                    var item = player.inventory[itemIdx];

                    // set state
                    entry.GetComponent <UIShowToolTip>().enabled      = true;
                    entry.GetComponent <UIDragAndDropable>().dragable = true;
                    // note: entries should be dropable at all times

                    // image
                    entry.GetComponent <Image>().color        = Color.white;
                    entry.GetComponent <Image>().sprite       = item.image;
                    entry.GetComponent <UIShowToolTip>().text = item.Tooltip();

                    // amount overlay: not needed while it's always one item
                    //entry.GetChild(0).gameObject.SetActive(item.amount > 1);
                    //if (item.amount > 1) entry.GetComponentInChildren<Text>().text = item.amount.ToString();
                }
                else
                {
                    // reset the index if it's not valid anymore
                    player.craftingIndices[i] = -1;

                    // remove listeners
                    entry.GetComponent <Button>().onClick.RemoveAllListeners();

                    // set state
                    entry.GetComponent <UIShowToolTip>().enabled      = false;
                    entry.GetComponent <UIDragAndDropable>().dragable = false;

                    // image
                    entry.GetComponent <Image>().color  = Color.clear;
                    entry.GetComponent <Image>().sprite = null;

                    // amount overlay: not needed while it's always one item
                    //entry.GetChild(0).gameObject.SetActive(false);
                }
            }

            // result slot: find a matching recipe (if any)
            // -> build list of item templates
            var validIndices = player.craftingIndices.Where(
                idx => 0 <= idx && idx < player.inventory.Count &&
                player.inventory[idx].valid
                );

            var items  = validIndices.Select(idx => player.inventory[idx].template).ToList();
            var recipe = RecipeTemplate.dict.Values.ToList().Find(r => r.CanCraftWith(items)); // good enough for now
            if (recipe != null)
            {
                // set state
                result.GetComponent <UIShowToolTip>().enabled = true;

                // image
                result.GetComponent <Image>().color        = Color.white;
                result.GetComponent <Image>().sprite       = recipe.result.image;
                result.GetComponent <UIShowToolTip>().text = new Item(recipe.result).Tooltip();
            }
            else
            {
                // remove listeners
                result.GetComponent <Button>().onClick.RemoveAllListeners();

                // set state
                result.GetComponent <UIShowToolTip>().enabled = false;

                // image
                result.GetComponent <Image>().color  = Color.clear;
                result.GetComponent <Image>().sprite = null;
            }

            // craft button
            buttonCraft.interactable = recipe != null && player.InventoryCanAddAmount(recipe.result, 1);
            buttonCraft.onClick.SetListener(() => {
                player.CmdCraft(validIndices.ToArray());
            });
        }
    }
Example #15
0
    void Update()
    {
        Player player = Player.localPlayer;

        if (player)
        {
            // hotkey (not while typing in chat, etc.)
            if (Input.GetKeyDown(hotKey) && !UIUtils.AnyInputActive())
            {
                panel.SetActive(!panel.activeSelf);
            }

            // only update the panel if it's active
            if (panel.activeSelf)
            {
                // instantiate/destroy enough slots
                // (we only care about non status skills)
                UIUtils.BalancePrefabs(slotPrefab.gameObject, player.skills.skills.Count, content);

                // refresh all
                for (int i = 0; i < player.skills.skills.Count; ++i)
                {
                    UISkillSlot slot  = content.GetChild(i).GetComponent <UISkillSlot>();
                    Skill       skill = player.skills.skills[i];

                    bool isPassive = skill.data is PassiveSkill;

                    // set state
                    slot.dragAndDropable.name     = i.ToString();
                    slot.dragAndDropable.dragable = skill.level > 0 && !isPassive;

                    // can we cast it? checks mana, cooldown etc.
                    bool canCast = player.skills.CastCheckSelf(skill);

                    // if movement does NOT support navigation then we need to
                    // check distance too. otherwise distance doesn't matter
                    // because we can navigate anywhere.
                    if (!player.movement.CanNavigate())
                    {
                        canCast &= player.skills.CastCheckDistance(skill, out Vector3 _);
                    }

                    // click event
                    slot.button.interactable = skill.level > 0 &&
                                               !isPassive &&
                                               canCast;

                    int icopy = i;
                    slot.button.onClick.SetListener(() => {
                        // try use the skill or walk closer if needed
                        ((PlayerSkills)player.skills).TryUse(icopy);
                    });

                    // image
                    if (skill.level > 0)
                    {
                        slot.image.color  = Color.white;
                        slot.image.sprite = skill.image;
                    }

                    // description
                    slot.descriptionText.text = skill.ToolTip(showRequirements: skill.level == 0);

                    // learn / upgrade
                    if (skill.level < skill.maxLevel && ((PlayerSkills)player.skills).CanUpgrade(skill))
                    {
                        slot.upgradeButton.gameObject.SetActive(true);
                        slot.upgradeButton.GetComponentInChildren <Text>().text = skill.level == 0 ? "Learn" : "Upgrade";
                        slot.upgradeButton.onClick.SetListener(() => { ((PlayerSkills)player.skills).CmdUpgrade(icopy); });
                    }
                    else
                    {
                        slot.upgradeButton.gameObject.SetActive(false);
                    }

                    // cooldown overlay
                    float cooldown = skill.CooldownRemaining();
                    slot.cooldownOverlay.SetActive(skill.level > 0 && cooldown > 0);
                    slot.cooldownText.text         = cooldown.ToString("F0");
                    slot.cooldownCircle.fillAmount = skill.cooldown > 0 ? cooldown / skill.cooldown : 0;
                }

                // skill experience
                skillExperienceText.text = ((PlayerSkills)player.skills).skillExperience.ToString();
            }
        }
        else
        {
            panel.SetActive(false);
        }
    }
Example #16
0
    // -----------------------------------------------------------------------------------
    //
    // -----------------------------------------------------------------------------------
    private void Update()
    {
        Player player = Player.localPlayer;

        if (!player)
        {
            return;
        }

        // use collider point(s) to also work with big entities
        if (player.target != null && player.target is Npc &&
            Utils.ClosestDistance(player.collider, player.target.collider) <= player.interactionRange &&
            panel.activeSelf)
        {
            Npc npc = (Npc)player.target;

            long amount = player.UCE_GetHonorCurrency(npc.itemShopCategories[currentCategory].honorCurrency);
            if (amount == -1)
            {
                amount = 0;
            }

            // instantiate/destroy enough category slots
            UIUtils.BalancePrefabs(categorySlotPrefab.gameObject, npc.itemShopCategories.Length, categoryContent);

            // -- Categories
            for (int i = 0; i < npc.itemShopCategories.Length; ++i)
            {
                Button button = categoryContent.GetChild(i).GetComponent <Button>();
                button.interactable = i != currentCategory;
                button.GetComponentInChildren <Text>().text = npc.itemShopCategories[i].categoryName;
                int icopy = i; // needed for lambdas, otherwise i is Count
                button.onClick.SetListener(() =>
                {
                    // set new category and then scroll to the top again
                    currentCategory = icopy;
                    ScrollToBeginning();
                });
            }

            // -- Items
            if (npc.itemShopCategories.Length > 0)
            {
                // instantiate/destroy enough item slots for that category
                ScriptableItem[] items = npc.itemShopCategories[currentCategory].items;
                UIUtils.BalancePrefabs(itemSlotPrefab.gameObject, items.Length, itemContent);

                // refresh all items in that category
                for (int i = 0; i < items.Length; ++i)
                {
                    UCE_UI_HonorShopSlot slot     = itemContent.GetChild(i).GetComponent <UCE_UI_HonorShopSlot>();
                    ScriptableItem       itemData = items[i];
                    Item itm = new Item(itemData);

                    // refresh item
                    slot.tooltip.text           = itm.ToolTip();
                    slot.image.color            = Color.white;
                    slot.image.sprite           = itemData.image;
                    slot.nameText.text          = itemData.name;
                    slot.priceText.text         = itm.UCE_GetHonorCurrency(npc.itemShopCategories[currentCategory].honorCurrency).ToString();
                    slot.currencyText.text      = npc.itemShopCategories[currentCategory].honorCurrency.name;
                    slot.buyButton.interactable = player.isAlive && amount >= itm.UCE_GetHonorCurrency(npc.itemShopCategories[currentCategory].honorCurrency);
                    int icopy = i; // needed for lambdas, otherwise i is Count
                    slot.buyButton.onClick.SetListener(() =>
                    {
                        player.Cmd_UCE_HonorShop(currentCategory, icopy);
                        inventoryPanel.SetActive(true); // better feedback
                    });
                }
            }

            // Currency
            currencyNameText.text   = npc.itemShopCategories[currentCategory].honorCurrency.name;
            currencyAmountText.text = amount.ToString();
        }
    }
    // -----------------------------------------------------------------------------------
    // Update
    // -----------------------------------------------------------------------------------
    private void Update()
    {
        Player player = Player.localPlayer;

        if (!player)
        {
            return;
        }

        if (manager == null)
        {
            manager = FindObjectOfType <NetworkManagerMMO>();
        }

        if (auth == null)
        {
            auth = manager.GetComponent <NetworkAuthenticatorMMO>();
        }

        if (manager != null && panel.activeSelf)
        {
            // item slot
            if (itemIndex != -1)
            {
                ScriptableItem item = player.inventory.slots[itemIndex].item.data;
                itemSlot.GetComponent <Image>().color           = Color.white;
                itemSlot.GetComponent <Image>().sprite          = item.image;
                itemSlot.GetComponent <UIShowToolTip>().enabled = true;
                itemSlot.GetComponent <UIShowToolTip>().text    = item.ToolTip();
            }
            else
            {
                itemSlot.GetComponent <Image>().color           = Color.clear;
                itemSlot.GetComponent <Image>().sprite          = null;
                itemSlot.GetComponent <UIShowToolTip>().enabled = false;
            }

            // no one selected yet, show search box
            if (string.IsNullOrEmpty(recipient))
            {
                searchPanel.gameObject.SetActive(true);
                messagePanel.gameObject.SetActive(false);
                itemIndex = -1;

                if (search.text.Length > 0 &&
                    search.text.Length <= auth.accountMaxLength &&
                    Regex.IsMatch(search.text, @"^[a-zA-Z0-9_]+$"))
                {
                    searchButton.interactable = true;
                }
                else
                {
                    searchButton.interactable = false;
                }
                searchButton.onClick.SetListener(() =>
                {
                    if (NetworkTime.time >= player.nextRiskyActionTime)
                    {
                        //prepare and send search request, get response
                        sending                   = true;
                        search.interactable       = false;
                        searchButton.interactable = false;
                        player.CmdMail_Search(search.text);
                        dialogMessage.text = "Searching...";
                        dialog.SetActive(true);
                    }
                });
            }
            else
            {
                searchPanel.gameObject.SetActive(false);
                messagePanel.gameObject.SetActive(true);
                recipientText.text = recipient;

                acceptButton.interactable = !string.IsNullOrEmpty(subject.text) && player.mailSettings.costPerMail.checkCost(player);
                acceptButton.onClick.SetListener(() =>
                {
                    if (NetworkTime.time >= player.nextRiskyActionTime)
                    {
                        sending            = true;
                        dialogMessage.text = "Sending Mail...";
                        dialog.SetActive(true);
                        player.CmdMail_Send(recipient, subject.text, body.text, itemIndex);
                        itemIndex = -1;
                    }
                });

                dialogButton.onClick.SetListener(() =>
                {
                    cancelButton.onClick.Invoke();
                });
            }

            //show the dialog button if we are not sending
            dialogButton.gameObject.SetActive(!sending);

            // cancel
            cancelButton.interactable = !sending;
            cancelButton.onClick.SetListener(() =>
            {
                recipient    = "";
                search.text  = "";
                subject.text = "";
                body.text    = "";
                sending      = false;
                itemIndex    = -1;
                UIUtils.BalancePrefabs(searchSlot.gameObject, 0, searchContent);
                dialog.SetActive(false);
                panel.SetActive(false);
            });
        }
    }
Example #18
0
    void Update()
    {
        var player = Utils.ClientLocalPlayer();

        if (!player)
        {
            return;
        }

        // use collider point(s) to also work with big entities
        if (panel.activeSelf &&
            player.target != null &&
            player.target.health == 0 &&
            Utils.ClosestDistance(player.collider, player.target.collider) <= player.interactionRange &&
            player.target is Monster &&
            ((Monster)player.target).HasLoot())
        {
            // gold slot
            if (player.target.gold > 0)
            {
                goldSlot.SetActive(true);
                goldSlot.GetComponentInChildren <Button>().onClick.SetListener(() => {
                    player.CmdTakeLootGold();
                });
                goldText.text = player.target.gold.ToString();
            }
            else
            {
                goldSlot.SetActive(false);
            }

            // instantiate/destroy enough slots
            // (we only want to show the non-empty slots)
            var items = player.target.inventory.Where(item => item.valid).ToList();
            UIUtils.BalancePrefabs(itemSlotPrefab.gameObject, items.Count, content);

            // refresh all valid items
            for (int i = 0; i < items.Count; ++i)
            {
                var slot = content.GetChild(i).GetComponent <UILootSlot>();
                slot.dragAndDropable.name = i.ToString(); // drag and drop index
                int itemIndex = player.target.inventory.FindIndex(
                    item => item.valid && item.name == items[i].name
                    );

                // refresh
                slot.button.interactable = player.InventoryCanAddAmount(items[i].template, items[i].amount);
                slot.button.onClick.SetListener(() => {
                    player.CmdTakeLootItem(itemIndex);
                });
                slot.tooltip.text  = items[i].ToolTip();
                slot.image.color   = Color.white;
                slot.image.sprite  = items[i].image;
                slot.nameText.text = items[i].name;
                slot.amountOverlay.SetActive(items[i].amount > 1);
                slot.amountText.text = items[i].amount.ToString();
            }
        }
        else
        {
            panel.SetActive(false);    // hide
        }
        // addon system hooks
        Utils.InvokeMany(typeof(UILoot), this, "Update_");
    }
Example #19
0
    void Update()
    {
        Player player = Player.localPlayer;

        // only show and update while there are party members
        if (player != null && player.InParty())
        {
            panel.SetActive(true);
            Party party = player.party;

            // get party members without self. no need to show self in HUD too.
            List <string> members = player.InParty() ? party.members.Where(m => m != player.name).ToList() : new List <string>();

            // instantiate/destroy enough slots
            UIUtils.BalancePrefabs(slotPrefab.gameObject, members.Count, memberContent);

            // refresh all members
            for (int i = 0; i < members.Count; ++i)
            {
                UIPartyHUDMemberSlot slot = memberContent.GetChild(i).GetComponent <UIPartyHUDMemberSlot>();
                string memberName         = members[i];
                float  distance           = Mathf.Infinity;
                float  visRange           = player.VisRange();

                slot.nameText.text = memberName;
                slot.masterIndicatorText.gameObject.SetActive(party.master == memberName);

                // pull health, mana, etc. from observers so that party struct
                // doesn't have to send all that data around. people will only
                // see health of party members that are near them, which is the
                // only time that it's important anyway.
                if (Player.onlinePlayers.ContainsKey(memberName))
                {
                    Player member = Player.onlinePlayers[memberName];
                    slot.icon.sprite        = member.classIcon;
                    slot.healthSlider.value = member.HealthPercent();
                    slot.manaSlider.value   = member.ManaPercent();
                    slot.backgroundButton.onClick.SetListener(() => {
                        player.CmdSetTarget(member.netIdentity);
                    });

                    // distance color based on visRange ratio
                    distance = Vector3.Distance(player.transform.position, member.transform.position);
                    visRange = member.VisRange(); // visRange is always based on the other guy
                }

                // distance overlay alpha based on visRange ratio
                // (because values are only up to date for members in observer
                //  range)
                float ratio = visRange > 0 ? distance / visRange : 1f;
                float alpha = alphaCurve.Evaluate(ratio);

                // icon alpha
                Color iconColor = slot.icon.color;
                iconColor.a     = alpha;
                slot.icon.color = iconColor;

                // health bar alpha
                foreach (Image image in slot.healthSlider.GetComponentsInChildren <Image>())
                {
                    Color color = image.color;
                    color.a     = alpha;
                    image.color = color;
                }

                // mana bar alpha
                foreach (Image image in slot.manaSlider.GetComponentsInChildren <Image>())
                {
                    Color color = image.color;
                    color.a     = alpha;
                    image.color = color;
                }
            }
        }
        else
        {
            panel.SetActive(false);
        }
    }
Example #20
0
    void Update()
    {
        Player player = Player.localPlayer;

        if (player)
        {
            // hotkey (not while typing in chat, etc.)
            if (Input.GetKeyDown(hotKey) && !UIUtils.AnyInputActive())
            {
                panel.SetActive(!panel.activeSelf);
            }

            // only update the panel if it's active
            if (panel.activeSelf)
            {
                // instantiate/destroy enough slots
                UIUtils.BalancePrefabs(ingredientSlotPrefab.gameObject, player.crafting.indices.Count, ingredientContent);

                // refresh all
                for (int i = 0; i < player.crafting.indices.Count; ++i)
                {
                    UICraftingIngredientSlot slot = ingredientContent.GetChild(i).GetComponent <UICraftingIngredientSlot>();
                    slot.dragAndDropable.name = i.ToString(); // drag and drop index
                    int itemIndex = player.crafting.indices[i];

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

                        // 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 = true;

                        // 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
                    {
                        // reset the index because it's invalid
                        player.crafting.indices[i] = -1;

                        // refresh invalid item
                        slot.tooltip.enabled          = false;
                        slot.dragAndDropable.dragable = false;
                        slot.image.color  = Color.clear;
                        slot.image.sprite = null;
                        slot.amountOverlay.SetActive(false);
                    }
                }

                // find valid indices => item templates => matching recipe
                List <int> validIndices = player.crafting.indices.Where(
                    index => 0 <= index && index < player.inventory.slots.Count &&
                    player.inventory.slots[index].amount > 0
                    ).ToList();
                List <ItemSlot>  items  = validIndices.Select(index => player.inventory.slots[index]).ToList();
                ScriptableRecipe recipe = ScriptableRecipe.Find(items);
                if (recipe != null)
                {
                    // refresh valid recipe
                    Item item = new Item(recipe.result);
                    // only build tooltip while it's actually shown. this
                    // avoids MASSIVE amounts of StringBuilder allocations.
                    resultSlotToolTip.enabled = true;
                    if (resultSlotToolTip.IsVisible())
                    {
                        resultSlotToolTip.text = new ItemSlot(item).ToolTip(); // ItemSlot so that {AMOUNT} is replaced too
                    }
                    resultSlotImage.color  = Color.white;
                    resultSlotImage.sprite = recipe.result.image;

                    // show progress bar while crafting
                    // (show 100% if craft time = 0 because it's just better feedback)
                    progressSlider.gameObject.SetActive(player.state == "CRAFTING");
                    double startTime   = player.crafting.endTime - recipe.craftingTime;
                    double elapsedTime = NetworkTime.time - startTime;
                    progressSlider.value = recipe.craftingTime > 0 ? (float)elapsedTime / recipe.craftingTime : 1;
                }
                else
                {
                    // refresh invalid recipe
                    resultSlotToolTip.enabled = false;
                    resultSlotImage.color     = Color.clear;
                    resultSlotImage.sprite    = null;
                    progressSlider.gameObject.SetActive(false);
                }

                // craft result
                // (no recipe != null check because it will be null if those were
                //  the last two ingredients in our inventory)
                if (player.crafting.state == CraftingState.Success)
                {
                    resultText.color = successColor;
                    resultText.text  = "Success!";
                }
                else if (player.crafting.state == CraftingState.Failed)
                {
                    resultText.color = failedColor;
                    resultText.text  = "Failed :(";
                }
                else
                {
                    resultText.text = "";
                }

                // craft button with 'Try' prefix to let people know that it might fail
                // (disabled while in progress)
                craftButton.GetComponentInChildren <Text>().text = recipe != null &&
                                                                   recipe.probability < 1 ? "Try Craft" : "Craft";
                craftButton.interactable = recipe != null &&
                                           player.state != "CRAFTING" &&
                                           player.crafting.state != CraftingState.InProgress &&
                                           player.inventory.CanAdd(new Item(recipe.result), 1);
                craftButton.onClick.SetListener(() => {
                    player.crafting.state = CraftingState.InProgress; // wait for result

                    // pass original array so server can copy it to it's own
                    // craftingIndices. we pass original one and not only the valid
                    // indicies because then in host mode we would make the crafting
                    // indices array smaller by only copying the valid indices,
                    // hence losing crafting slots
                    player.crafting.CmdCraft(recipe.name, player.crafting.indices.ToArray());
                });
            }
        }
        else
        {
            panel.SetActive(false);
        }
    }
    // -----------------------------------------------------------------------------------
    // Update
    // -----------------------------------------------------------------------------------
    private void Update()
    {
        Player player = Player.localPlayer;

        if (!player)
        {
            return;
        }

        // hotkey (not while typing in chat, etc.)
        if (Input.GetKeyDown(hotKey) && !UIUtils.AnyInputActive())
        {
            panel.SetActive(!panel.activeSelf);
        }

        if (panel.activeSelf)
        {
            List <UCE_Quest> activeQuests = new List <UCE_Quest>();

            if (showActiveQuests)
            {
                activeQuests = player.UCE_quests.Where(q => !q.completed || (q.repeatable > 0 && !q.completedAgain)).ToList();
            }
            else
            {
                activeQuests = player.UCE_quests.Where(q => q.completed).ToList();
            }

            if (cacheTimer == null || cacheTimer.Length != activeQuests.Count)
            {
                cacheTooltip = new string[player.UCE_quests.Count];
                cacheTimer   = new float[player.UCE_quests.Count];
            }

            UIUtils.BalancePrefabs(slotPrefab.gameObject, activeQuests.Count, content);

            // -- refresh all
            for (int i = 0; i < activeQuests.Count; ++i)
            {
                int index              = i;
                UCE_UI_QuestSlot slot  = content.GetChild(index).GetComponent <UCE_UI_QuestSlot>();
                UCE_Quest        quest = activeQuests[index];

                // -- check cache
                if (Time.time > cacheTimer[index])
                {
                    // =======================================================================

                    // -- check gathered items
                    int[] gathered = player.checkGatheredItems(quest);

                    // -- check explored areas
                    int explored = 0;
#if _iMMOEXPLORATION
                    foreach (UCE_Area_Exploration area in quest.exploreTarget)
                    {
                        if (player.UCE_HasExploredArea(area))
                        {
                            explored++;
                        }
                    }
#endif

                    // -- check faction requirement
                    bool factionRequirementsMet = true;
#if _iMMOFACTIONS
                    factionRequirementsMet = player.UCE_CheckFactionRating(quest.factionRequirement);
#endif

                    // =======================================================================

                    // name button
                    GameObject descriptionPanel = slot.descriptionText.gameObject;
                    string     prefix           = descriptionPanel.activeSelf ? hidePrefix : expandPrefix;
                    slot.nameButton.GetComponentInChildren <Text>().text = prefix + quest.name;

                    if (showActiveQuests)
                    {
                        if (quest.IsFulfilled(gathered, explored, factionRequirementsMet))
                        {
                            slot.nameButton.GetComponent <Image>().color = fulfilledQuestColor;
                        }
                        else
                        {
                            slot.nameButton.GetComponent <Image>().color = inprogressQuestColor;
                        }
                    }
                    else
                    {
                        slot.nameButton.GetComponent <Image>().color = fulfilledQuestColor;
                    }

                    slot.nameButton.onClick.SetListener(() =>
                    {
                        descriptionPanel.SetActive(!descriptionPanel.activeSelf);
                    });

                    // -- cancel button
                    if (showActiveQuests)
                    {
                        slot.cancelButton.gameObject.SetActive(true);
                        slot.cancelButton.onClick.SetListener(() =>
                        {
                            cancelQuestPanel.Show(quest.name);
                        });
                    }
                    else
                    {
                        slot.cancelButton.gameObject.SetActive(false);
                    }

                    // -- update cache
                    cacheTooltip[index] = quest.ToolTip(gathered, explored, factionRequirementsMet);
                    cacheTimer[index]   = Time.time + cacheInterval;

                    // -- update description
                    slot.descriptionText.text = cacheTooltip[index];
                }
            }
        }
    }
    // 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;
            }
        }
    }
Example #23
0
    void Update()
    {
        GameObject player = Player.player;

        panel.SetActive(player != null); // hide while not in the game world
        if (!player)
        {
            return;
        }

        // get components
        Skillbar        skillbar  = player.GetComponent <Skillbar>();
        PlayerSkills    skills    = player.GetComponent <PlayerSkills>();
        PlayerInventory inventory = player.GetComponent <PlayerInventory>();
        PlayerEquipment equipment = player.GetComponent <PlayerEquipment>();
        PlayerLook      look      = player.GetComponent <PlayerLook>();

        // instantiate/destroy enough slots
        UIUtils.BalancePrefabs(slotPrefab.gameObject, skillbar.slots.Length, content);

        // refresh all
        for (int i = 0; i < skillbar.slots.Length; ++i)
        {
            UISkillbarSlot slot = content.GetChild(i).GetComponent <UISkillbarSlot>();
            slot.dragAndDropable.name = i.ToString(); // drag and drop index

            // hotkey overlay (without 'Alpha' etc.)
            string pretty = skillbar.slots[i].hotKey.ToString().Replace("Alpha", "");
            slot.hotkeyText.text = pretty;

            // skill, inventory item or equipment item?
            int skillIndex     = skills.GetSkillIndexByName(skillbar.slots[i].reference);
            int inventoryIndex = inventory.GetItemIndexByName(skillbar.slots[i].reference);
            int equipmentIndex = equipment.GetItemIndexByName(skillbar.slots[i].reference);
            if (skillIndex != -1)
            {
                Skill skill = skills.skills[skillIndex];

                bool canUse = skill.CanCast(player) && !look.IsFreeLooking();

                // hotkey pressed and not typing in any input right now?
                if (Input.GetKeyDown(skillbar.slots[i].hotKey) &&
                    !UIUtils.AnyInputActive() &&
                    canUse)
                {
                    skills.StartCast(skillIndex);
                }

                // refresh skill slot
                slot.button.interactable = canUse;
                slot.button.onClick.SetListener(() => {
                    skills.StartCast(skillIndex);
                });
                slot.tooltip.enabled          = true;
                slot.tooltip.text             = skill.ToolTip();
                slot.dragAndDropable.dragable = true;
                slot.image.color  = Color.white;
                slot.image.sprite = skill.image;
                float cooldown = skill.CooldownRemaining();
                slot.cooldownOverlay.SetActive(cooldown > 0);
                slot.cooldownText.text         = cooldown.ToString("F0");
                slot.cooldownCircle.fillAmount = skill.cooldown > 0 ? cooldown / skill.cooldown : 0;
                slot.amountOverlay.SetActive(false);
            }
            else if (inventoryIndex != -1)
            {
                ItemSlot itemSlot = inventory.slots[inventoryIndex];

                // hotkey pressed and not typing in any input right now?
                if (Input.GetKeyDown(skillbar.slots[i].hotKey) && !UIUtils.AnyInputActive())
                {
                    inventory.UseItem(inventoryIndex);
                }

                // refresh inventory slot
                slot.button.onClick.SetListener(() => {
                    inventory.UseItem(inventoryIndex);
                });
                slot.tooltip.enabled          = true;
                slot.tooltip.text             = itemSlot.ToolTip();
                slot.dragAndDropable.dragable = true;
                slot.image.color  = Color.white;
                slot.image.sprite = itemSlot.item.image;
                slot.cooldownOverlay.SetActive(false);
                slot.cooldownCircle.fillAmount = 0;
                slot.amountOverlay.SetActive(itemSlot.amount > 1);
                slot.amountText.text = itemSlot.amount.ToString();
            }
            else if (equipmentIndex != -1)
            {
                ItemSlot itemSlot = equipment.slots[equipmentIndex];

                // refresh equipment slot
                slot.button.onClick.RemoveAllListeners();
                slot.tooltip.enabled          = true;
                slot.tooltip.text             = itemSlot.ToolTip();
                slot.dragAndDropable.dragable = true;
                slot.image.color  = Color.white;
                slot.image.sprite = itemSlot.item.image;
                slot.cooldownOverlay.SetActive(false);
                slot.cooldownCircle.fillAmount = 0;
                slot.amountOverlay.SetActive(itemSlot.amount > 1);
                slot.amountText.text = itemSlot.amount.ToString();
            }
            else
            {
                // clear the outdated reference
                skillbar.slots[i].reference = "";

                // refresh empty slot
                slot.button.onClick.RemoveAllListeners();
                slot.tooltip.enabled          = false;
                slot.dragAndDropable.dragable = false;
                slot.image.color  = Color.clear;
                slot.image.sprite = null;
                slot.cooldownOverlay.SetActive(false);
                slot.cooldownCircle.fillAmount = 0;
                slot.amountOverlay.SetActive(false);
            }
        }
    }
Example #24
0
    void Update()
    {
        Player player = Player.localPlayer;

        if (player)
        {
            // hotkey (not while typing in chat, etc.)
            if (Input.GetKeyDown(hotKey) && !UIUtils.AnyInputActive())
            {
                panel.SetActive(!panel.activeSelf);
            }

            // only update the panel if it's active
            if (panel.activeSelf)
            {
                Party party       = player.party;
                int   memberCount = party.members != null ? party.members.Length : 0;

                // properties
                currentCapacityText.text = memberCount.ToString();
                maximumCapacityText.text = Party.Capacity.ToString();

                // instantiate/destroy enough slots
                UIUtils.BalancePrefabs(slotPrefab.gameObject, memberCount, memberContent);

                // refresh all members
                for (int i = 0; i < memberCount; ++i)
                {
                    UIPartyMemberSlot slot       = memberContent.GetChild(i).GetComponent <UIPartyMemberSlot>();
                    string            memberName = party.members[i];

                    slot.nameText.text = memberName;
                    slot.masterIndicatorText.gameObject.SetActive(i == 0);

                    // party struct doesn't sync health, mana, level, etc. We find
                    // those from observers instead. Saves bandwidth and is good
                    // enough since another member's health is only really important
                    // to use when we are fighting the same monsters.
                    // => null if member not in observer range, in which case health
                    //    bars etc. should be grayed out!

                    // update some data only if around. otherwise keep previous data.
                    // update icon only if around. otherwise keep previous one.
                    if (Player.onlinePlayers.ContainsKey(memberName))
                    {
                        Player member = Player.onlinePlayers[memberName];
                        slot.icon.sprite        = member.classIcon;
                        slot.levelText.text     = member.level.ToString();
                        slot.guildText.text     = member.guildName;
                        slot.healthSlider.value = member.HealthPercent();
                        slot.manaSlider.value   = member.ManaPercent();
                    }

                    // action button:
                    // dismiss: if i=0 and member=self and master
                    // kick: if i > 0 and player=master
                    // leave: if member=self and not master
                    if (memberName == player.name && i == 0)
                    {
                        slot.actionButton.gameObject.SetActive(true);
                        slot.actionButton.GetComponentInChildren <Text>().text = "Dismiss";
                        slot.actionButton.onClick.SetListener(() => {
                            player.CmdPartyDismiss();
                        });
                    }
                    else if (memberName == player.name && i > 0)
                    {
                        slot.actionButton.gameObject.SetActive(true);
                        slot.actionButton.GetComponentInChildren <Text>().text = "Leave";
                        slot.actionButton.onClick.SetListener(() => {
                            player.CmdPartyLeave();
                        });
                    }
                    else if (party.members[0] == player.name && i > 0)
                    {
                        slot.actionButton.gameObject.SetActive(true);
                        slot.actionButton.GetComponentInChildren <Text>().text = "Kick";
                        int icopy = i;
                        slot.actionButton.onClick.SetListener(() => {
                            player.CmdPartyKick(icopy);
                        });
                    }
                    else
                    {
                        slot.actionButton.gameObject.SetActive(false);
                    }
                }

                // exp share toggle
                experienceShareToggle.interactable = player.InParty() && party.members[0] == player.name;
                experienceShareToggle.onValueChanged.SetListener((val) => {}); // avoid callback while setting .isOn via code
                experienceShareToggle.isOn = party.shareExperience;
                experienceShareToggle.onValueChanged.SetListener((val) => {
                    player.CmdPartySetExperienceShare(val);
                });

                // gold share toggle
                goldShareToggle.interactable = player.InParty() && party.members[0] == player.name;
                goldShareToggle.onValueChanged.SetListener((val) => {}); // avoid callback while setting .isOn via code
                goldShareToggle.isOn = party.shareGold;
                goldShareToggle.onValueChanged.SetListener((val) => {
                    player.CmdPartySetGoldShare(val);
                });
            }
        }
        else
        {
            panel.SetActive(false);
        }
    }
Example #25
0
    void Update()
    {
        Player player = Player.localPlayer;

        if (player)
        {
            // hotkey (not while typing in chat, etc.)
            if (Input.GetKeyDown(hotKey) && !UIUtils.AnyInputActive())
            {
                panel.SetActive(!panel.activeSelf);
            }

            // only update the panel if it's active
            if (panel.activeSelf)
            {
                Guild guild       = player.guild;
                int   memberCount = guild.members != null ? guild.members.Length : 0;

                // guild properties
                nameText.text            = player.guild.name;
                masterText.text          = guild.master;
                currentCapacityText.text = memberCount.ToString();
                maximumCapacityText.text = GuildSystem.Capacity.ToString();

                // notice edit button
                noticeEditButton.interactable = guild.CanNotify(player.name) &&
                                                !noticeInput.interactable;
                noticeEditButton.onClick.SetListener(() => {
                    noticeInput.interactable = true;
                });

                // notice set button
                noticeSetButton.interactable = guild.CanNotify(player.name) &&
                                               noticeInput.interactable &&
                                               NetworkTime.time >= player.nextRiskyActionTime;
                noticeSetButton.onClick.SetListener(() => {
                    noticeInput.interactable = false;
                    if (noticeInput.text.Length > 0 &&
                        !string.IsNullOrWhiteSpace(noticeInput.text) &&
                        noticeInput.text != guild.notice)
                    {
                        player.CmdSetGuildNotice(noticeInput.text);
                    }
                });

                // notice input: copies notice while not editing it
                if (!noticeInput.interactable)
                {
                    noticeInput.text = guild.notice ?? "";
                }
                noticeInput.characterLimit = GuildSystem.NoticeMaxLength;

                // leave
                leaveButton.interactable = guild.CanLeave(player.name);
                leaveButton.onClick.SetListener(() => {
                    player.CmdLeaveGuild();
                });

                // instantiate/destroy enough slots
                UIUtils.BalancePrefabs(slotPrefab.gameObject, memberCount, memberContent);

                // refresh all members
                for (int i = 0; i < memberCount; ++i)
                {
                    UIGuildMemberSlot slot   = memberContent.GetChild(i).GetComponent <UIGuildMemberSlot>();
                    GuildMember       member = guild.members[i];

                    slot.onlineStatusImage.color    = member.online ? onlineColor : offlineColor;
                    slot.nameText.text              = member.name;
                    slot.levelText.text             = member.level.ToString();
                    slot.rankText.text              = member.rank.ToString();
                    slot.promoteButton.interactable = guild.CanPromote(player.name, member.name);
                    slot.promoteButton.onClick.SetListener(() => {
                        player.CmdGuildPromote(member.name);
                    });
                    slot.demoteButton.interactable = guild.CanDemote(player.name, member.name);
                    slot.demoteButton.onClick.SetListener(() => {
                        player.CmdGuildDemote(member.name);
                    });
                    slot.kickButton.interactable = guild.CanKick(player.name, member.name);
                    slot.kickButton.onClick.SetListener(() => {
                        player.CmdGuildKick(member.name);
                    });
                }
            }
        }
        else
        {
            panel.SetActive(false);
        }
    }
Example #26
0
    void Update()
    {
        var player = Utils.ClientLocalPlayer();

        if (!player)
        {
            return;
        }

        // hotkey (not while typing in chat, etc.)
        if (Input.GetKeyDown(hotKey) && !UIUtils.AnyInputActive())
        {
            panel.SetActive(!panel.activeSelf);
        }

        // only update the panel if it's active
        if (panel.activeSelf)
        {
            // instantiate/destroy enough slots
            UIUtils.BalancePrefabs(slotPrefab.gameObject, player.inventory.Count, content);

            // refresh all items
            for (int i = 0; i < player.inventory.Count; ++i)
            {
                var slot = content.GetChild(i).GetComponent <UIInventorySlot>();
                slot.dragAndDropable.name = i.ToString(); // drag and drop index
                var item = player.inventory[i];

                if (item.valid)
                {
                    // refresh valid item
                    int icopy = i; // needed for lambdas, otherwise i is Count
                    slot.button.onClick.SetListener(() => {
                        if (player.level >= item.minLevel)
                        {
                            player.CmdUseInventoryItem(icopy);
                        }
                    });
                    slot.tooltip.enabled          = true;
                    slot.tooltip.text             = item.ToolTip();
                    slot.dragAndDropable.dragable = true;
                    slot.image.color  = Color.white;
                    slot.image.sprite = item.image;
                    slot.amountOverlay.SetActive(item.amount > 1);
                    slot.amountText.text = item.amount.ToString();
                }
                else
                {
                    // refresh invalid item
                    slot.button.onClick.RemoveAllListeners();
                    slot.tooltip.enabled          = false;
                    slot.dragAndDropable.dragable = false;
                    slot.image.color  = Color.clear;
                    slot.image.sprite = null;
                    slot.amountOverlay.SetActive(false);
                }
            }

            // gold
            goldText.text = player.gold.ToString();

            // trash (tooltip always enabled, dropable always true)
            trash.dragable = player.trash.valid;
            if (player.trash.valid)
            {
                // refresh valid item
                trashImage.color  = Color.white;
                trashImage.sprite = player.trash.image;
                trashOverlay.SetActive(player.trash.amount > 1);
                trashAmountText.text = player.trash.amount.ToString();
            }
            else
            {
                // refresh invalid item
                trashImage.color  = Color.clear;
                trashImage.sprite = null;
                trashOverlay.SetActive(false);
            }
        }
    }
    // -----------------------------------------------------------------------------------
    // Update
    // -----------------------------------------------------------------------------------
    private void Update()
    {
        Player player = Player.localPlayer;

        if (!player)
        {
            return;
        }

        if (panel.activeSelf)
        {
            List <UCE_Quest> activeQuests = player.UCE_quests.Where(q => !q.completed || (q.repeatable > 0 && !q.completedAgain)).ToList();

            int maxQuests = Mathf.Min(activeQuests.Count, maxActiveQuestsToShow);

            UIUtils.BalancePrefabs(slotPrefab.gameObject, maxQuests, content);

            // -- refresh all
            for (int i = 0; i < maxQuests; ++i)
            {
                int index              = i;
                UCE_UI_QuestSlot slot  = content.GetChild(index).GetComponent <UCE_UI_QuestSlot>();
                UCE_Quest        quest = activeQuests[index];

                // -- check cache
                if (Time.time > cacheTimer[index])
                {
                    // =======================================================================

                    // -- check gathered items
                    int[] gathered = player.checkGatheredItems(quest);

                    // -- check explored areas
                    int explored = 0;
#if _iMMOEXPLORATION
                    foreach (UCE_Area_Exploration area in quest.exploreTarget)
                    {
                        if (player.UCE_HasExploredArea(area))
                        {
                            explored++;
                        }
                    }
#endif

                    // -- check faction requirement
                    bool factionRequirementsMet = true;
#if _iMMOFACTIONS
                    factionRequirementsMet = player.UCE_CheckFactionRating(quest.factionRequirement);
#endif

                    // =======================================================================

                    // name button
                    GameObject descriptionPanel = slot.descriptionText.gameObject;
                    string     prefix           = descriptionPanel.activeSelf ? hidePrefix : expandPrefix;
                    slot.nameButton.GetComponentInChildren <Text>().text = prefix + quest.name;
                    slot.nameButton.onClick.SetListener(() =>
                    {
                        descriptionPanel.SetActive(!descriptionPanel.activeSelf);
                    });

                    if (quest.IsFulfilled(gathered, explored, factionRequirementsMet))
                    {
                        slot.nameButton.GetComponent <Image>().color = fulfilledQuestColor;
                    }
                    else
                    {
                        slot.nameButton.GetComponent <Image>().color = inprogressQuestColor;
                    }

                    // -- cancel button
                    slot.cancelButton.gameObject.SetActive(false);

                    // -- update cache
                    cacheTooltip[index] = quest.TrackerTip(gathered, explored, factionRequirementsMet, player.level);
                    cacheTimer[index]   = Time.time + cacheInterval;

                    // -- update description
                    slot.descriptionText.text = cacheTooltip[index];
                }
            }
        }
    }
    void Update()
    {
        Player player = Utils.ClientLocalPlayer();

        panel.SetActive(player != null); // hide while not in the game world
        if (!player)
        {
            return;
        }

        // instantiate/destroy enough slots
        UIUtils.BalancePrefabs(slotPrefab.gameObject, player.skillbar.Length, content);

        // refresh all
        for (int i = 0; i < player.skillbar.Length; ++i)
        {
            UISkillbarSlot slot = content.GetChild(i).GetComponent <UISkillbarSlot>();
            slot.dragAndDropable.name = i.ToString(); // drag and drop index

            // hotkey overlay (without 'Alpha' etc.)
            string pretty = player.skillbar[i].hotKey.ToString().Replace("Alpha", "");
            slot.hotkeyText.text = pretty;

            // skill, inventory item or equipment item?
            int skillIndex     = player.GetSkillIndexByName(player.skillbar[i].reference);
            int inventoryIndex = player.GetInventoryIndexByName(player.skillbar[i].reference);
            int equipmentIndex = player.GetEquipmentIndexByName(player.skillbar[i].reference);
            if (skillIndex != -1)
            {
                Skill skill = player.skills[skillIndex];

                // hotkey pressed and not typing in any input right now?
                if (Input.GetKeyDown(player.skillbar[i].hotKey) &&
                    !UIUtils.AnyInputActive() &&
                    player.CastCheckSelf(skill)) // checks mana, cooldowns, etc.)
                {
                    player.CmdUseSkill(skillIndex);
                }

                // refresh skill slot
                slot.button.interactable = player.CastCheckSelf(skill); // check mana, cooldowns, etc.
                slot.button.onClick.SetListener(() => {
                    player.CmdUseSkill(skillIndex);
                });
                slot.tooltip.enabled          = true;
                slot.tooltip.text             = skill.ToolTip();
                slot.dragAndDropable.dragable = true;
                slot.image.color  = Color.white;
                slot.image.sprite = skill.image;
                float cooldown = skill.CooldownRemaining();
                slot.cooldownOverlay.SetActive(cooldown > 0);
                slot.cooldownText.text         = cooldown.ToString("F0");
                slot.cooldownCircle.fillAmount = skill.cooldown > 0 ? cooldown / skill.cooldown : 0;
                slot.amountOverlay.SetActive(false);
            }
            else if (inventoryIndex != -1)
            {
                ItemSlot itemSlot = player.inventory[inventoryIndex];

                // hotkey pressed and not typing in any input right now?
                if (Input.GetKeyDown(player.skillbar[i].hotKey) && !UIUtils.AnyInputActive())
                {
                    player.CmdUseInventoryItem(inventoryIndex);
                }

                // refresh inventory slot
                slot.button.onClick.SetListener(() => {
                    player.CmdUseInventoryItem(inventoryIndex);
                });
                slot.tooltip.enabled          = true;
                slot.tooltip.text             = itemSlot.ToolTip();
                slot.dragAndDropable.dragable = true;
                slot.image.color  = Color.white;
                slot.image.sprite = itemSlot.item.image;
                slot.cooldownOverlay.SetActive(false);
                slot.cooldownCircle.fillAmount = 0;
                slot.amountOverlay.SetActive(itemSlot.amount > 1);
                slot.amountText.text = itemSlot.amount.ToString();
            }
            else if (equipmentIndex != -1)
            {
                ItemSlot itemSlot = player.equipment[equipmentIndex];

                // refresh equipment slot
                slot.button.onClick.RemoveAllListeners();
                slot.tooltip.enabled          = true;
                slot.tooltip.text             = itemSlot.ToolTip();
                slot.dragAndDropable.dragable = true;
                slot.image.color  = Color.white;
                slot.image.sprite = itemSlot.item.image;
                slot.cooldownOverlay.SetActive(false);
                slot.cooldownCircle.fillAmount = 0;
                slot.amountOverlay.SetActive(itemSlot.amount > 1);
                slot.amountText.text = itemSlot.amount.ToString();
            }
            else
            {
                // clear the outdated reference
                player.skillbar[i].reference = "";

                // refresh empty slot
                slot.button.onClick.RemoveAllListeners();
                slot.tooltip.enabled          = false;
                slot.dragAndDropable.dragable = false;
                slot.image.color  = Color.clear;
                slot.image.sprite = null;
                slot.cooldownOverlay.SetActive(false);
                slot.cooldownCircle.fillAmount = 0;
                slot.amountOverlay.SetActive(false);
            }
        }
    }
    void Update()
    {
        Player player = Utils.ClientLocalPlayer();

        if (!player)
        {
            return;
        }

        // hotkey (not while typing in chat, etc.)
        if (Input.GetKeyDown(hotKey) && !UIUtils.AnyInputActive())
        {
            panel.SetActive(!panel.activeSelf);
        }

        // only update the panel if it's active
        if (panel.activeSelf)
        {
            // instantiate/destroy enough category slots
            UIUtils.BalancePrefabs(categorySlotPrefab.gameObject, player.itemMallCategories.Length, categoryContent);

            // refresh all category buttons
            for (int i = 0; i < player.itemMallCategories.Length; ++i)
            {
                Button button = categoryContent.GetChild(i).GetComponent <Button>();
                button.interactable = i != currentCategory;
                button.GetComponentInChildren <Text>().text = player.itemMallCategories[i].category;
                int icopy = i; // needed for lambdas, otherwise i is Count
                button.onClick.SetListener(() => {
                    // set new category and then scroll to the top again
                    currentCategory = icopy;
                    ScrollToBeginning();
                });
            }

            if (player.itemMallCategories.Length > 0)
            {
                // instantiate/destroy enough item slots for that category
                ScriptableItem[] items = player.itemMallCategories[currentCategory].items;
                UIUtils.BalancePrefabs(itemSlotPrefab.gameObject, items.Length, itemContent);

                // refresh all items in that category
                for (int i = 0; i < items.Length; ++i)
                {
                    UIItemMallSlot slot = itemContent.GetChild(i).GetComponent <UIItemMallSlot>();
                    ScriptableItem item = items[i];

                    // refresh item
                    slot.tooltip.text              = new Item(item).ToolTip();
                    slot.image.color               = Color.white;
                    slot.image.sprite              = item.image;
                    slot.nameText.text             = item.name;
                    slot.priceText.text            = item.itemMallPrice.ToString();
                    slot.unlockButton.interactable = player.health > 0 && player.coins >= item.itemMallPrice;
                    int icopy = i; // needed for lambdas, otherwise i is Count
                    slot.unlockButton.onClick.SetListener(() => {
                        player.CmdUnlockItem(currentCategory, icopy);
                        inventoryPanel.SetActive(true); // better feedback
                    });
                }
            }

            // overview
            nameText.text           = player.name;
            levelText.text          = "Lv. " + player.level;
            currencyAmountText.text = player.coins.ToString();
            buyButton.onClick.SetListener(() => { Application.OpenURL(buyUrl); });
            couponInput.interactable  = NetworkTime.time >= player.nextRiskyActionTime;
            couponButton.interactable = NetworkTime.time >= player.nextRiskyActionTime;
            couponButton.onClick.SetListener(() => {
                if (!Utils.IsNullOrWhiteSpace(couponInput.text))
                {
                    player.CmdEnterCoupon(couponInput.text);
                }
                couponInput.text = "";
            });
        }
    }
Example #30
0
    void Update()
    {
        var player = Utils.ClientLocalPlayer();

        if (!player)
        {
            return;
        }

        // instantiate/destroy enough slots
        UIUtils.BalancePrefabs(slotPrefab, player.inventory.Count, content);

        // refresh all
        for (int i = 0; i < player.inventory.Count; ++i)
        {
            var entry = content.GetChild(i).GetChild(0); // slot entry
            entry.name = i.ToString();                   // for drag and drop
            var item = player.inventory[i];

            // overlay hotkey (without 'Alpha' etc.)
            var pretty = player.inventoryHotkeys[i].ToString().Replace("Alpha", "");
            entry.GetChild(1).GetComponentInChildren <Text>().text = pretty;

            if (item.valid)
            {
                // click event
                int icopy = i; // needed for lambdas, otherwise i is Count
                entry.GetComponent <Button>().onClick.SetListener(() => {
                    player.CmdUseInventoryItem(icopy);
                });

                // hotkey pressed and not typing in any input right now?
                if (Input.GetKeyDown(player.inventoryHotkeys[i]) && !UIUtils.AnyInputActive())
                {
                    player.CmdUseInventoryItem(i);
                }

                // set state
                entry.GetComponent <UIShowToolTip>().enabled      = true;
                entry.GetComponent <UIDragAndDropable>().dragable = true;
                // note: entries should be dropable at all times

                // image
                entry.GetComponent <Image>().color        = Color.white;
                entry.GetComponent <Image>().sprite       = item.image;
                entry.GetComponent <UIShowToolTip>().text = item.Tooltip();

                // amount overlay
                entry.GetChild(0).gameObject.SetActive(item.amount > 1);
                if (item.amount > 1)
                {
                    entry.GetComponentInChildren <Text>().text = item.amount.ToString();
                }
            }
            else
            {
                // remove listeners
                entry.GetComponent <Button>().onClick.RemoveAllListeners();

                // set state
                entry.GetComponent <UIShowToolTip>().enabled      = false;
                entry.GetComponent <UIDragAndDropable>().dragable = false;

                // image
                entry.GetComponent <Image>().color  = Color.clear;
                entry.GetComponent <Image>().sprite = null;

                // amount overlay
                entry.GetChild(0).gameObject.SetActive(false);
            }
        }

        // gold
        goldText.text = player.gold.ToString();
    }