Example #1
0
    void Update()
    {
        Player player = Player.localPlayer;

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

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

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

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

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

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

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

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

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

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

                // mana bar alpha
                foreach (Image image in slot.manaSlider.GetComponentsInChildren <Image>())
                {
                    Color color = image.color;
                    color.a     = alpha;
                    image.color = color;
                }
            }
        }
        else
        {
            panel.SetActive(false);
        }
    }
    private void Update()
    {
        // Checks for the local player if we don't have a player yet.
        player = Player.localPlayer;
        if (player == null)
        {
            return;
        }

        // On right mouse click check if on a component that has a dropdown.
        if (Input.GetKeyDown(KeyCode.Mouse1))
        {
            m_PointerEventData          = new PointerEventData(m_EventSystem);
            m_PointerEventData.position = Input.mousePosition;

            List <RaycastResult> results = new List <RaycastResult>();

            m_Raycaster.Raycast(m_PointerEventData, results);

            // Check results of our UI raycast if its a valid target then show the dropdown.
            foreach (RaycastResult result in results)
            {
                if (result.gameObject.name == "SlotPartyHUDMember(Clone)")
                {
                    partySlot = result.gameObject.GetComponent <UIPartyHUDMemberSlot>();
                    partyDropdown.GetComponent <RectTransform>().position = result.screenPosition;
                    partyDropdown.SetActive(true);
                }
            }
        }

        // If the dropdown is shown then check to see what buttons can be used.
        if (partyDropdown.activeSelf)
        {
            // Grab the clicked party member.
            string clickedMember = string.Empty;
            int    clickedIndex  = 0;
            for (int i = 0; i < player.party.members.Length; i++)
            {
                if (player.party.members[i] == partySlot.nameText.text)
                {
                    clickedMember            = player.party.members[i];
                    clickedIndex             = i;
                    player.clickedPartyIndex = clickedIndex;

                    Player member = Player.onlinePlayers[clickedMember];
                    player.CmdSetTarget(member.netIdentity);
                }
            }

            // 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 (player.name == player.party.master)
            {
                // promote button
                activeButtons[1].gameObject.SetActive(true);
                activeButtons[1].onClick.SetListener(() =>
                {
                    player.CmdPartyPromote(clickedIndex);
                    partyDropdown.SetActive(false);
                });

                // kick button
                activeButtons[0].gameObject.SetActive(true);
                activeButtons[0].onClick.SetListener(() =>
                {
                    player.CmdPartyKick(clickedMember);
                    partyDropdown.SetActive(false);
                });
            }
            else
            {
                activeButtons[0].gameObject.SetActive(false);
                activeButtons[1].gameObject.SetActive(false);
            }

            // trade button
            activeButtons[4].gameObject.SetActive(true);
            activeButtons[4].onClick.SetListener(() =>
            {
                player.CmdTradeRequestSend();
                partyDropdown.SetActive(false);
            });

            // guild invite button
            if (target is Player && player.InGuild())
            {
                activeButtons[2].gameObject.SetActive(true);
                activeButtons[2].interactable = !((Player)target).InGuild() &&
                                                player.guild.CanInvite(player.name, target.name) &&
                                                NetworkTime.time >= player.nextRiskyActionTime &&
                                                distance <= player.interactionRange;
                activeButtons[2].onClick.SetListener(() =>
                {
                    player.CmdGuildInviteTarget();
                    partyDropdown.SetActive(false);
                });
            }
            else
            {
                activeButtons[2].gameObject.SetActive(false);
            }

#if _iMMOPVP
            if (player.target && player.target is Player && player.target != player && player.UCE_SameRealm((Player)player.target))
            {
                activeButtons[3].gameObject.SetActive(true);
                activeButtons[3].interactable = player.UCE_Friends.FindIndex(x => x.name == ((Player)(player.target)).name) == -1 ? true : false;
                activeButtons[3].onClick.SetListener(() =>
                {
                    player.Cmd_UCE_AddFriend(((Player)(player.target)).name);
                    partyDropdown.SetActive(false);
                });
            }
            else
            {
                activeButtons[3].gameObject.SetActive(false);
            }
#elif _iMMOFRIENDS
            if (player.target && player.target is Player && player.target != player)
            {
                activeButtons[3].gameObject.SetActive(true);
                activeButtons[3].interactable = player.UCE_Friends.FindIndex(x => x.name == ((Player)(player.target)).name) == -1  ? true : false;
                activeButtons[3].onClick.SetListener(() => {
                    player.Cmd_UCE_AddFriend(((Player)(player.target)).name);
                    partyDropdown.SetActive(false);
                });
            }
            else
            {
                activeButtons[3].gameObject.SetActive(false);
            }
#endif

            m_PointerEventData          = new PointerEventData(m_EventSystem);
            m_PointerEventData.position = Input.mousePosition;

            List <RaycastResult> results = new List <RaycastResult>();

            m_Raycaster.Raycast(m_PointerEventData, results);

            // Check results of our UI raycast if its a valid player then show the dropdown.
            int foundMenu = 0;
            foreach (RaycastResult result in results)
            {
                if (result.gameObject.name == "SlotPartyHUDMember(Clone)" || result.gameObject.name == "PartyDropdown")
                {
                    foundMenu++;
                }
            }

            if (foundMenu == 0)
            {
                partyDropdown.SetActive(false);
            }
        }
    }