Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: late joiners would be displayed as selected [MTTB-4] #899

Merged
merged 6 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 29 additions & 30 deletions Assets/Scripts/Gameplay/UI/PartyHUD.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,33 @@ public class PartyHUD : MonoBehaviour
ClientPlayerAvatarRuntimeCollection m_PlayerAvatars;

[SerializeField]
private Image m_HeroPortrait;
Image m_HeroPortrait;

[SerializeField]
private GameObject[] m_AllyPanel;
GameObject[] m_AllyPanel;

[SerializeField]
private TextMeshProUGUI[] m_PartyNames;
TextMeshProUGUI[] m_PartyNames;

[SerializeField]
private Image[] m_PartyClassSymbols;
Image[] m_PartyClassSymbols;

[SerializeField]
private Slider[] m_PartyHealthSliders;
Slider[] m_PartyHealthSliders;

[SerializeField]
private Image[] m_PartyHealthGodModeImages;
Image[] m_PartyHealthGodModeImages;

// track a list of hero (slot 0) + allies
private ulong[] m_PartyIds;

// track Hero's target to show when it is the Hero or an ally
private ulong m_CurrentTarget;
ulong[] m_PartyIds;

ServerCharacter m_OwnedServerCharacter;

ClientPlayerAvatar m_OwnedPlayerAvatar;

private Dictionary<ulong, ServerCharacter> m_TrackedAllies = new Dictionary<ulong, ServerCharacter>();
Dictionary<ulong, ServerCharacter> m_TrackedAllies = new Dictionary<ulong, ServerCharacter>();

private ClientInputSender m_ClientSender;
ClientInputSender m_ClientSender;

void Awake()
{
Expand Down Expand Up @@ -189,7 +186,7 @@ void SetUIFromSlotData(int slot, ServerCharacter serverCharacter)
#if UNITY_EDITOR || DEVELOPMENT_BUILD
void SetAllyGodModeStatus(ulong id, bool newValue)
{
int slot = FindOrAddAlly(id);
int slot = FindOrAddAlly(id, true);
// do nothing if not in a slot
if (slot == -1)
{
Expand All @@ -201,7 +198,7 @@ void SetAllyGodModeStatus(ulong id, bool newValue)

void SetAllyHealth(ulong id, int hp)
{
int slot = FindOrAddAlly(id);
int slot = FindOrAddAlly(id, true);
// do nothing if not in a slot
if (slot == -1)
{
Expand All @@ -211,29 +208,20 @@ void SetAllyHealth(ulong id, int hp)
m_PartyHealthSliders[slot].value = hp;
}

private void OnHeroSelectionChanged(ulong prevTarget, ulong newTarget)
void OnHeroSelectionChanged(ulong prevTarget, ulong newTarget)
{
SetHeroSelectFX(m_CurrentTarget, false);
SetHeroSelectFX(prevTarget, false);
SetHeroSelectFX(newTarget, true);
}

// Helper to change name appearance for selected or unselected party members
// also updates m_CurrentTarget
private void SetHeroSelectFX(ulong target, bool selected)
void SetHeroSelectFX(ulong target, bool selected)
{
// check id against all party slots
int slot = FindOrAddAlly(target, true);
if (slot >= 0)
{
m_PartyNames[slot].color = selected ? Color.green : Color.white;
if (selected)
{
m_CurrentTarget = target;
}
else
{
m_CurrentTarget = 0;
}
}
}

Expand All @@ -244,7 +232,7 @@ public void SelectPartyMember(int slot)
}

// helper to initialize the Allies array - safe to call multiple times
private void InitPartyArrays()
void InitPartyArrays()
{
if (m_PartyIds == null)
{
Expand All @@ -262,16 +250,25 @@ private void InitPartyArrays()

// Helper to find ally slots, returns -1 if no slot is found for the id
// If a slot is available one will be added for this id unless dontAdd=true
private int FindOrAddAlly(ulong id, bool dontAdd = false)
int FindOrAddAlly(ulong id, bool dontAdd = false)
{
// make sure allies array is ready
InitPartyArrays();

if (id == 0)
{
// special case: id of 0 is uninitialized party id
return -1;
}

int openslot = -1;
for (int i = 0; i < m_PartyIds.Length; i++)
{
// if this ID is in the list, return the slot index
if (m_PartyIds[i] == id) { return i; }
if (m_PartyIds[i] == id)
{
return i;
}
// otherwise, record the first open slot (not slot 0 thats for the Hero)
if (openslot == -1 && i > 0 && m_PartyIds[i] == 0)
{
Expand Down Expand Up @@ -315,6 +312,9 @@ void RemoveHero()
/// <param name="id"> NetworkObjectID of the ally. </param>
void RemoveAlly(ulong id)
{
// remove potential selected state of party member UI
SetHeroSelectFX(id, false);

for (int i = 0; i < m_PartyIds.Length; i++)
{
// if this ID is in the list, return the slot index
Expand All @@ -323,7 +323,6 @@ void RemoveAlly(ulong id)
m_AllyPanel[i - 1].SetActive(false);
// and save ally ID to party array
m_PartyIds[i] = 0;
return;
}
}

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Additional documentation and release notes are available at [Multiplayer Documen
* Changed the way characters are oriented when using skills.
* Added the GetTotalDamage API to the IDamageable interface. This number is your maximum health minus your current health.
* Changed the way MeleeAction selects a target when there are multiple targets to collide with. The target with the highest GetTotalDamage value (mentioned above) will be selected.
* Fixed a visual issue where a selected party member's party HUD slot would be displayed as selected (green) when the same or new party member joins the session in-game (#899)

## [2.5.0] - 2024-04-18

Expand Down
Loading