Les portraits des aventuriers possédés ne sont plus remplacer par une image blanche lorsque l'on recrute.

This commit is contained in:
mrtoine 2025-10-17 12:43:38 +02:00
parent 2b5a227237
commit 91a53c8417

View file

@ -55,19 +55,70 @@ namespace GameUI.Runtime
void DisplayAdventurers() 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) 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); 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++)
{ {
GameObject cardAdventurerGO = Instantiate(_adventurerPrefab, _heroesPanel.transform); AdventurerClass adv = filtered[i];
cardAdventurerGO.transform.SetAsLastSibling(); AdventurerCardUI card;
AdventurerCardUI card = cardAdventurerGO.GetComponent<AdventurerCardUI>(); if (existing.TryGetValue(adv, out card))
card.setup(adventurer); {
// 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.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);
}
} }
} }