// -----------------------------------------------------------------------------------
    // 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)
        {
            Refresh();
        }
    }
Example #2
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 refresh the panel while it's active
            if (panel.activeSelf)
            {
                damageText.text            = player.damage.ToString();
                defenseText.text           = player.defense.ToString();
                healthText.text            = player.healthMax.ToString();
                manaText.text              = player.manaMax.ToString();
                criticalChanceText.text    = (player.criticalChance * 100).ToString("F0") + "%";
                blockChanceText.text       = (player.blockChance * 100).ToString("F0") + "%";
                speedText.text             = player.speed.ToString();
                levelText.text             = player.level.ToString();
                currentExperienceText.text = player.experience.ToString();
                maximumExperienceText.text = player.experienceMax.ToString();
                skillExperienceText.text   = player.skillExperience.ToString();

                strengthText.text           = player.strength.ToString();
                strengthButton.interactable = player.AttributesSpendable() > 0;
                strengthButton.onClick.SetListener(() => { player.CmdIncreaseStrength(); });

                intelligenceText.text           = player.intelligence.ToString();
                intelligenceButton.interactable = player.AttributesSpendable() > 0;
                intelligenceButton.onClick.SetListener(() => { player.CmdIncreaseIntelligence(); });
            }
        }
        else
        {
            panel.SetActive(false);
        }
    }
Example #3
0
    ////////////////////////////////////////////////////////////////////////////
    void Update()
    {
        // only while alive and  while cursor is locked, otherwise we are in a UI
        if (health.current > 0 && Cursor.lockState == CursorLockMode.Locked)
        {
            // calculate horizontal and vertical rotation steps
            float xExtra = Input.GetAxis("Mouse X") * XSensitivity;
            float yExtra = Input.GetAxis("Mouse Y") * YSensitivity;

            // use mouse to rotate character
            // (but use camera freelook parent while climbing so player isn't rotated
            //  while climbing)
            // (no free look in first person)
            if (movement.state == MoveState.CLIMBING ||
                (Input.GetKey(freeLookKey) && !UIUtils.AnyInputActive() && distance > 0))
            {
                // set to freelook parent already?
                if (camera.transform.parent != freeLookParent)
                {
                    InitializeFreeLook();
                }

                // rotate freelooktarget for horizontal, rotate camera for vertical
                freeLookParent.Rotate(new Vector3(0, xExtra, 0));
                camera.transform.Rotate(new Vector3(-yExtra, 0, 0));
            }
            else
            {
                // set to player parent already?
                if (camera.transform.parent != transform)
                {
                    InitializeForcedLook();
                }

                // rotate character for horizontal, rotate camera for vertical
                transform.Rotate(new Vector3(0, xExtra, 0));
                camera.transform.Rotate(new Vector3(-yExtra, 0, 0));
            }
        }
    }
    // Assign our movement hotkeys then check our skillbar hotkeys.
    private void UpdateClient_DSM()
    {
        if (settingsVariables != null)
        {
            if (!UIUtils.AnyInputActive())
            {
                if (Input.GetKey(settingsVariables.keybindings[0]))
                {
                    vertical = 1;
                }
                else if (Input.GetKey(settingsVariables.keybindings[1]))
                {
                    vertical = -1;
                }
                else
                {
                    vertical = 0;
                }

                if (Input.GetKey(settingsVariables.keybindings[2]))
                {
                    horizontal = -1;
                }
                else if (Input.GetKey(settingsVariables.keybindings[3]))
                {
                    horizontal = 1;
                }
                else
                {
                    horizontal = 0;
                }
            }
        }

        if (settingsVariables != null)
        {
            UpdateHotkeys();
        }
    }
Example #5
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_");
    }
Example #6
0
    // -----------------------------------------------------------------------------------
    // Update
    // @Client
    // -----------------------------------------------------------------------------------
    void Update()
    {
        Player player = Player.localPlayer;

        if (!player && displayTime > 0)
        {
            panel.SetActive(false);
        }

        if (!player)
        {
            return;
        }
        else if (displayTime == 0)
        {
            panel.SetActive(true);
        }

        if (Input.GetKeyDown(hotKey) && !UIUtils.AnyInputActive())
        {
            panel.SetActive(!panel.activeSelf);
        }
    }
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];

                // 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
                slot.descriptionText.text = quest.ToolTip(player);
            }
        }
    }
Example #8
0
    //Initiates every frame.
    private void Update()
    {
        Player player = Player.localPlayer;                         //Grab the player from utils.

        if (player == null)
        {
            return;                                                 //Don't continue if there is no player found.
        }
        if (Input.GetKeyDown(hotKey) && !UIUtils.AnyInputActive())  //If the hotkey is pressed and chat is not active then progress.
        {
            CanvasGroup cg = panel.GetComponent <CanvasGroup>();

            if (cg.alpha == 0)
            {
                cg.alpha          = 1;                              //Set the options menu as active.
                cg.blocksRaycasts = true;                           //Set the options menu to catch mouse clicks.
            }
            else
            {
                cg.alpha          = 0;                              //Set the options menu as active.
                cg.blocksRaycasts = false;                          //Set the options menu to catch mouse clicks.
            }
        }
    }
Example #9
0
    void Update()
    {
        Player player = Player.localPlayer;

        if (player)
        {
            if (Input.GetKeyDown(hotKey) && !UIUtils.AnyInputActive())
            {
                panel.SetActive(!panel.activeSelf);
            }
            string quitPrefix = "";
            if (player.remainingLogoutTime > 0)
            {
                quitPrefix = "(" + Mathf.CeilToInt((float)player.remainingLogoutTime) + ") ";
            }
            quitButton.GetComponent <UIShowToolTip>().text = quitPrefix + "Quit";
            quitButton.interactable = player.remainingLogoutTime == 0;
            quitButton.onClick.SetListener(NetworkManagerSurvival.Quit);
        }
        else
        {
            panel.SetActive(false);
        }
    }
    // -----------------------------------------------------------------------------------
    // 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 #11
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 #12
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);
            }
        }
    }
    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);
            }
        }
    }
Example #14
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);
            }
        }
    }
    // -----------------------------------------------------------------------------------
    // 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];
                }
            }
        }
    }
Example #16
0
    protected override void UpdateClient()
    {
        // pressing/holding space bar makes camera focus on the player
        // (not while typing in chat etc.)
        if (isLocalPlayer)
        {
            if (Input.GetKey(focusKey) && !UIUtils.AnyInputActive())
            {
                // focus on it once, then disable scrolling while holding the
                // button, otherwise camera gets shaky when moving cursor to the
                // edge of the screen
                Camera.main.GetComponent <CameraScrolling>().FocusOn(transform.position);
                Camera.main.GetComponent <CameraScrolling>().enabled = false;
            }
            else
            {
                Camera.main.GetComponent <CameraScrolling>().enabled = true;
            }
        }

        if (state == "IDLE" || state == "MOVING")
        {
            if (isLocalPlayer)
            {
                // simply accept input
                SelectionHandling();

                // canel action if escape key was pressed, clear skillWanted
                if (Input.GetKeyDown(KeyCode.Escape))
                {
                    skillWanted = -1;
                    CmdCancelAction();
                }
            }
        }
        else if (state == "CASTING")
        {
            // keep looking at the target for server & clients (only Y rotation)
            if (target)
            {
                LookAtY(target.transform.position);
            }

            if (isLocalPlayer)
            {
                // simply accept input
                SelectionHandling();

                // canel action if escape key was pressed, clear skillWanted
                if (Input.GetKeyDown(KeyCode.Escape))
                {
                    skillWanted = -1;
                    CmdCancelAction();
                }
            }
        }
        else if (state == "DEAD")
        {
        }
        else
        {
            Debug.LogError("invalid state:" + state);
        }
    }
Example #17
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 #18
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);
        }
    }
Example #19
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();
    }
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
                // (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 #21
0
    void Update()
    {
        Player player = Player.localPlayer;

        if (player != null)
        {
            // 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.slots.Count, content);

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

                    if (itemSlot.amount > 0)
                    {
                        // refresh valid item
                        int icopy = i; // needed for lambdas, otherwise i is Count
                        slot.button.onClick.SetListener(() => {
                            if (itemSlot.item.data is UsableItem usable &&
                                usable.CanUse(player, icopy))
                            {
                                player.inventory.CmdUseItem(icopy);
                            }
                        });
                        // 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;

                        // cooldown if usable item
                        if (itemSlot.item.data is UsableItem usable2)
                        {
                            float cooldown = player.GetItemCooldown(usable2.cooldownCategory);
                            slot.cooldownCircle.fillAmount = usable2.cooldown > 0 ? cooldown / usable2.cooldown : 0;
                        }
                        else
                        {
                            slot.cooldownCircle.fillAmount = 0;
                        }
                        slot.amountOverlay.SetActive(itemSlot.amount > 1);
                        slot.amountText.text = itemSlot.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.cooldownCircle.fillAmount = 0;
                        slot.amountOverlay.SetActive(false);
                    }
                }

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

                // trash (tooltip always enabled, dropable always true)
                trash.dragable = player.inventory.trash.amount > 0;
                if (player.inventory.trash.amount > 0)
                {
                    // refresh valid item
                    if (player.inventory.trash.item.maxDurability > 0)
                    {
                        if (player.inventory.trash.item.durability == 0)
                        {
                            trashImage.color = brokenDurabilityColor;
                        }
                        else if (player.inventory.trash.item.DurabilityPercent() < lowDurabilityThreshold)
                        {
                            trashImage.color = lowDurabilityColor;
                        }
                        else
                        {
                            trashImage.color = Color.white;
                        }
                    }
                    else
                    {
                        trashImage.color = Color.white;  // reset for no-durability items
                    }
                    trashImage.sprite = player.inventory.trash.item.image;

                    trashOverlay.SetActive(player.inventory.trash.amount > 1);
                    trashAmountText.text = player.inventory.trash.amount.ToString();
                }
                else
                {
                    // refresh invalid item
                    trashImage.color  = Color.clear;
                    trashImage.sprite = null;
                    trashOverlay.SetActive(false);
                }
            }
        }
        else
        {
            panel.SetActive(false);
        }
    }
Example #22
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 #23
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
            // (we only care about non status skills)
            var skills = player.skills.Where(s => !s.category.StartsWith("Status")).ToList();
            UIUtils.BalancePrefabs(slotPrefab.gameObject, skills.Count, content);

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

                // drag and drop name has to be the index in the real skill list,
                // not in the filtered list, otherwise drag and drop may fail
                int skillIndex = player.skills.FindIndex(s => s.name == skill.name);
                slot.dragAndDropable.name = skillIndex.ToString();

                // click event
                slot.button.interactable = skill.learned;
                slot.button.onClick.SetListener(() => {
                    if (skill.learned && skill.IsReady())
                    {
                        player.CmdUseSkill(skillIndex);
                    }
                });

                // set state
                slot.dragAndDropable.dragable = skill.learned;

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

                // description
                slot.descriptionText.text = skill.ToolTip(showRequirements: !skill.learned);

                // learnable?
                if (!skill.learned)
                {
                    slot.learnButton.gameObject.SetActive(true);
                    slot.learnButton.GetComponentInChildren <Text>().text = "Learn";
                    slot.learnButton.interactable = player.level >= skill.requiredLevel &&
                                                    player.skillExperience >= skill.requiredSkillExperience;
                    slot.learnButton.onClick.SetListener(() => { player.CmdLearnSkill(skillIndex); });
                    // upgradeable?
                }
                else if (skill.level < skill.maxLevel)
                {
                    slot.learnButton.gameObject.SetActive(true);
                    slot.learnButton.GetComponentInChildren <Text>().text = "Upgrade";
                    slot.learnButton.interactable = player.level >= skill.upgradeRequiredLevel &&
                                                    player.skillExperience >= skill.upgradeRequiredSkillExperience;
                    slot.learnButton.onClick.SetListener(() => { player.CmdUpgradeSkill(skillIndex); });
                    // otherwise no button needed
                }
                else
                {
                    slot.learnButton.gameObject.SetActive(false);
                }

                // cooldown overlay
                float cooldown = skill.CooldownRemaining();
                slot.cooldownOverlay.SetActive(skill.learned && cooldown > 0);
                slot.cooldownText.text = cooldown.ToString("F0");
            }

            // skill experience
            skillExperienceText.text = player.skillExperience.ToString();
        }

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

        if (player == null || player.UCE_skillbarIndex == 0)
        {
            panel.SetActive(false);
            return;
        }
        else
        {
            panel.SetActive(true);
        }

        if (Time.time > fInterval)
        {
            UCE_SlowUpdate();
            fInterval = Time.time + updateInterval;
        }

        if (player != null && panel.activeSelf)
        {
            if (content.childCount <= 0)
            {
                return;
            }

            for (int i = 0; i < player.UCE_skillbar.Length; ++i)
            {
                UCEUISkillbarSlot slot = content.GetChild(i).GetComponent <UCEUISkillbarSlot>();

                // skill, inventory item or equipment item?
                int skillIndex     = player.GetSkillIndexByName(player.UCE_skillbar[i].reference);
                int inventoryIndex = player.GetInventoryIndexByName(player.UCE_skillbar[i].reference);

                if (skillIndex != -1)
                {
                    Skill skill   = player.skills[skillIndex];
                    bool  canCast = player.CastCheckSelf(skill);

                    // hotkey pressed and not typing in any input right now?
                    if (Input.GetKeyDown(player.UCE_skillbar[i].hotKey) &&
                        !UIUtils.AnyInputActive() &&
                        canCast) // checks mana, cooldowns, etc.) {
                    {
                        // try use the skill or walk closer if needed
                        player.TryUseSkill(skillIndex);
                    }
                }
                else if (inventoryIndex != -1)
                {
                    ItemSlot itemSlot = player.inventory[inventoryIndex];

                    // hotkey pressed and not typing in any input right now?
                    if (Input.GetKeyDown(player.UCE_skillbar[i].hotKey) && !UIUtils.AnyInputActive())
                    {
                        player.CmdUseInventoryItem(inventoryIndex);
                    }
                }
            }
        }
        else
        {
            panel.SetActive(false);
        }
    }
Example #25
0
    void Update()
    {
        var player = Utils.ClientLocalPlayer();

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

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

        // refresh all
        for (int i = 0; i < player.skillbar.Length; ++i)
        {
            var entry = content.GetChild(i).GetChild(0); // slot entry
            entry.name = i.ToString();                   // for drag and drop

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

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

                // click event (done more than once but w/e)
                entry.GetComponent <Button>().onClick.SetListener(() => {
                    player.CmdUseSkill(skillIndex);
                });

                // 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       = player.skills[skillIndex].image;
                entry.GetComponent <UIShowToolTip>().text = player.skills[skillIndex].Tooltip();

                // overlay cooldown
                float cd = player.skills[skillIndex].CooldownRemaining();
                entry.GetChild(0).gameObject.SetActive(cd > 0);
                if (cd > 1)
                {
                    entry.GetChild(0).GetComponentInChildren <Text>().text = cd.ToString("F0");
                }

                // hotkey pressed and not typing in any input right now?
                if (skill.learned && skill.IsReady() &&
                    Input.GetKeyDown(player.skillbarHotkeys[i]) &&
                    !UIUtils.AnyInputActive())
                {
                    player.CmdUseSkill(skillIndex);
                }
            }
            else if (invIndex != -1)
            {
                // click event (done more than once but w/e)
                entry.GetComponent <Button>().onClick.SetListener(() => {
                    player.CmdUseInventoryItem(invIndex);
                });

                // 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       = player.inventory[invIndex].image;
                entry.GetComponent <UIShowToolTip>().text = player.inventory[invIndex].Tooltip();

                // overlay amount
                int amount = player.inventory[invIndex].amount;
                entry.GetChild(0).gameObject.SetActive(amount > 1);
                if (amount > 1)
                {
                    entry.GetChild(0).GetComponentInChildren <Text>().text = amount.ToString();
                }

                // hotkey pressed and not typing in any input right now?
                if (Input.GetKeyDown(player.skillbarHotkeys[i]) && !UIUtils.AnyInputActive())
                {
                    player.CmdUseInventoryItem(invIndex);
                }
            }
            else if (equipIndex != -1)
            {
                // click event (done more than once but w/e)
                entry.GetComponent <Button>().onClick.RemoveAllListeners();

                // 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       = player.equipment[equipIndex].image;
                entry.GetComponent <UIShowToolTip>().text = player.equipment[equipIndex].Tooltip();

                // overlay
                entry.GetChild(0).gameObject.SetActive(false);
            }
            else
            {
                // outdated reference. clear it.
                player.skillbar[i] = "";

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

                // overlay
                entry.GetChild(0).gameObject.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)
        {
            // find all the items that should be sold in the item mall
            var items = (from kvp in ItemTemplate.dict
                         where kvp.Value.itemMallPrice > 0
                         select kvp.Value).ToList();

            // find the needed categories
            var categories = items.Select(item => Utils.ParseFirstNoun(item.category)).Distinct().ToList();

            // instantiate/destroy enough category slots
            UIUtils.BalancePrefabs(categorySlotPrefab.gameObject, categories.Count, categoryContent);

            // refresh all category buttons
            for (int i = 0; i < categories.Count; ++i)
            {
                var button = categoryContent.GetChild(i).GetComponent <Button>();
                button.interactable = i != currentCategory;
                button.GetComponentInChildren <Text>().text = categories[i];
                int icopy = i;
                button.onClick.SetListener(() => { currentCategory = icopy; });
            }

            if (categories.Count > 0)
            {
                // instantiate/destroy enough item slots for that category
                var categoryItems = items.Where(
                    item => Utils.ParseFirstNoun(item.category) == categories[currentCategory]
                    ).ToList();
                UIUtils.BalancePrefabs(itemSlotPrefab.gameObject, categoryItems.Count, itemContent);

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

                    // refresh item
                    slot.tooltip.text              = new Item(item).ToolTip();
                    slot.image.color               = Color.white;
                    slot.image.sprite              = item.image;
                    slot.descriptionText.text      = item.name + "\n\n<b><color=#" + ColorUtility.ToHtmlStringRGBA(priceColor) + ">" + item.itemMallPrice + "</color></b> " + currencyName;
                    slot.unlockButton.interactable = player.health > 0 && player.coins >= item.itemMallPrice;
                    slot.unlockButton.onClick.SetListener(() => {
                        inventoryPanel.SetActive(true); // better feedback
                        player.CmdUnlockItem(item.name);
                    });
                }
            }

            // overview
            nameText.text           = player.name;
            levelText.text          = "Lv. " + player.level;
            currencyNameText.text   = currencyName;
            currencyAmountText.text = player.coins.ToString();
            buyButton.GetComponentInChildren <Text>().text = "Buy " + currencyName;
            buyButton.onClick.SetListener(() => { Application.OpenURL(buyUrl); });
            couponInput.interactable  = NetworkTime.time >= player.nextCouponTime;
            couponButton.interactable = NetworkTime.time >= player.nextCouponTime;
            couponButton.onClick.SetListener(() => {
                if (!Utils.IsNullOrWhiteSpace(couponInput.text))
                {
                    player.CmdEnterCoupon(couponInput.text);
                }
                couponInput.text = "";
            });
        }
    }
Example #27
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 #28
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.gameObject, player.craftingIndices.Count, ingredientContent);

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

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

                    // refresh valid item
                    slot.tooltip.enabled          = true;
                    slot.tooltip.text             = item.ToolTip();
                    slot.dragAndDropable.dragable = true;
                    slot.image.color  = Color.white;
                    slot.image.sprite = item.image;
                }
                else
                {
                    // reset the index because it's invalid
                    player.craftingIndices[i] = -1;

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

            // find valid indices => item templates => matching recipe
            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)
            {
                // refresh valid recipe
                resultSlotToolTip.enabled = true;
                resultSlotToolTip.text    = new Item(recipe.result).ToolTip();
                resultSlotImage.color     = Color.white;
                resultSlotImage.sprite    = recipe.result.image;
            }
            else
            {
                // refresh invalid recipe
                resultSlotToolTip.enabled = false;
                resultSlotImage.color     = Color.clear;
                resultSlotImage.sprite    = null;
            }

            // craft button
            craftButton.interactable = recipe != null && player.InventoryCanAddAmount(recipe.result, 1);
            craftButton.onClick.SetListener(() => {
                player.CmdCraft(validIndices.ToArray());
            });
        }
    }
    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;
        }

        // 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, player.equipment.Count, content);

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

                // set category overlay in any case. we use the last noun in the
                // category string, for example:
                //   EquipmentWeaponBow => Bow
                //   EquipmentShield => Shield
                // (disable overlay if no category, e.g. for archer shield slot)
                if (player.equipmentTypes[i] != "")
                {
                    entry.GetChild(0).gameObject.SetActive(true);
                    string overlay = Utils.ParseLastNoun(player.equipmentTypes[i]);
                    entry.GetComponentInChildren <Text>().text = overlay != "" ? overlay : "?";
                }
                else
                {
                    entry.GetChild(0).gameObject.SetActive(false);
                }

                if (item.valid)
                {
                    // click event (done more than once but w/e)
                    entry.GetComponent <Button>().onClick.RemoveAllListeners();

                    // set state
                    entry.GetComponent <UIShowToolTip>().enabled      = item.valid;
                    entry.GetComponent <UIDragAndDropable>().dragable = item.valid;
                    // 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();
                }
                else
                {
                    // remove listeners
                    entry.GetComponent <Button>().onClick.RemoveAllListeners();

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

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