Les portraits des aventuriers possédés ne sont plus remplacer par une image blanche lorsque l'on recrute.
This commit is contained in:
parent
2b5a227237
commit
91a53c8417
1 changed files with 57 additions and 6 deletions
|
|
@ -55,19 +55,70 @@ namespace GameUI.Runtime
|
|||
|
||||
void DisplayAdventurers()
|
||||
{
|
||||
// Build a lookup of existing cards by their Adventurer instance
|
||||
Dictionary<AdventurerClass, AdventurerCardUI> existing = new Dictionary<AdventurerClass, AdventurerCardUI>();
|
||||
List<AdventurerCardUI> orphaned = new List<AdventurerCardUI>();
|
||||
foreach (Transform child in _heroesPanel.transform)
|
||||
{
|
||||
Destroy(child.gameObject);
|
||||
AdventurerCardUI card = child.GetComponent<AdventurerCardUI>();
|
||||
if (card != null && card.Adventurer != null)
|
||||
{
|
||||
if (!existing.ContainsKey(card.Adventurer))
|
||||
existing.Add(card.Adventurer, card);
|
||||
else
|
||||
orphaned.Add(card); // duplicate safety
|
||||
}
|
||||
else if (card != null)
|
||||
{
|
||||
orphaned.Add(card);
|
||||
}
|
||||
}
|
||||
|
||||
List<AdventurerClass> filtered = FilterAdventurers(_sort);
|
||||
|
||||
foreach (AdventurerClass adventurer in filtered)
|
||||
// Reuse or create cards to match the filtered list and order
|
||||
HashSet<AdventurerCardUI> used = new HashSet<AdventurerCardUI>();
|
||||
for (int i = 0; i < filtered.Count; i++)
|
||||
{
|
||||
AdventurerClass adv = filtered[i];
|
||||
AdventurerCardUI card;
|
||||
if (existing.TryGetValue(adv, out card))
|
||||
{
|
||||
// Refresh textual data and availability indicators without touching portrait
|
||||
card.setup(adv);
|
||||
card.transform.SetSiblingIndex(i);
|
||||
}
|
||||
else
|
||||
{
|
||||
GameObject cardAdventurerGO = Instantiate(_adventurerPrefab, _heroesPanel.transform);
|
||||
cardAdventurerGO.transform.SetAsLastSibling();
|
||||
AdventurerCardUI card = cardAdventurerGO.GetComponent<AdventurerCardUI>();
|
||||
card.setup(adventurer);
|
||||
cardAdventurerGO.transform.SetSiblingIndex(i);
|
||||
card = cardAdventurerGO.GetComponent<AdventurerCardUI>();
|
||||
if (card != null)
|
||||
{
|
||||
card.setup(adv);
|
||||
}
|
||||
}
|
||||
if (card != null)
|
||||
used.Add(card);
|
||||
}
|
||||
|
||||
// Remove cards that are no longer needed (not part of filtered) or orphaned
|
||||
foreach (Transform child in _heroesPanel.transform)
|
||||
{
|
||||
AdventurerCardUI card = child.GetComponent<AdventurerCardUI>();
|
||||
if (card != null && !used.Contains(card))
|
||||
{
|
||||
Destroy(child.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
// Cleanup any explicit orphaned duplicates detected earlier
|
||||
foreach (var card in orphaned)
|
||||
{
|
||||
if (card != null && !used.Contains(card))
|
||||
{
|
||||
Destroy(card.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue