Handbuch Scroll-Listen entfernt. Handbuch offen und tabs eingefügt. Upgrades eingefügt. "Garage" eingefügt. Anbindung eines echten Gameplaymanager möglich (theoretisch)

This commit is contained in:
2026-10-15 03:24:48 +02:00
parent dadd1fcad0
commit 5486444dde
132 changed files with 55540 additions and 4807 deletions
@@ -1,103 +1,48 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace DepthsOfGreed.HandbookUI
{
public sealed class BuildMenuController : MonoBehaviour
{
[SerializeField] private Button[] categoryButtons;
[SerializeField] private TowerCardView[] cardSlots;
public TestPlacementController Placement { get; set; }
private readonly List<TowerCardView> cards = new List<TowerCardView>();
private Button[] categories;
private int selectedCategory = -1;
private readonly List<HandbookTowerEntry>[] groups = { new List<HandbookTowerEntry>(), new List<HandbookTowerEntry>(), new List<HandbookTowerEntry>(), new List<HandbookTowerEntry>() };
private int selected = -1;
private TowerCardView revealed;
private HandbookTowerEntry[][] entries;
public int SelectedCategory => selected;
public void Initialize(HandbookTowerCatalog catalog)
{
categories = new[] {
transform.Find("LeftPage/CategoryBar/Category_Ammo").GetComponent<Button>(),
transform.Find("LeftPage/CategoryBar/Category_Energy").GetComponent<Button>(),
transform.Find("LeftPage/CategoryBar/Category_Special").GetComponent<Button>()
};
var left = transform.Find("LeftPage/Cards_Left");
var right = transform.Find("RightPage/Cards_Right");
int count = Mathf.Max(left.childCount, right.childCount);
for (int i = 0; i < count; i++)
{
if (i < left.childCount) AddCard(left.GetChild(i));
if (i < right.childCount) AddCard(right.GetChild(i));
}
var groups = new[] { new List<HandbookTowerEntry>(), new List<HandbookTowerEntry>(), new List<HandbookTowerEntry>() };
if (catalog && catalog.towers != null)
foreach (var entry in catalog.towers)
if (entry) groups[(int)entry.category].Add(entry);
entries = new[] { groups[0].ToArray(), groups[1].ToArray(), groups[2].ToArray() };
foreach (var group in groups)
if (group.Count > cards.Count)
Debug.LogWarning("Handbuch: Mehr Turmtypen als Kartenplätze in einer Kategorie.", this);
for (int i = 0; i < categories.Length; i++)
{
int index = i;
categories[i].onClick.AddListener(() => SelectCategory(index));
}
foreach (var card in cardSlots) card.Initialize(this);
foreach (var group in groups) group.Clear();
if (catalog.towers != null) foreach (var entry in catalog.towers) if (entry) groups[(int)entry.menuGroup].Add(entry);
for (int i = 0; i < categoryButtons.Length; i++) { int n = i; categoryButtons[i].onClick.AddListener(() => SelectCategory(n)); }
SelectCategory(0);
}
private void AddCard(Transform card)
{
var view = card.gameObject.AddComponent<TowerCardView>();
view.Initialize(this);
cards.Add(view);
}
public void SelectCategory(int index)
{
if (index == selectedCategory) return;
selectedCategory = index;
revealed = null;
for (int i = 0; i < cards.Count; i++)
if (index < 0 || index >= groups.Length || index == selected) return;
selected = index; ResetCards(); Bind();
for (int i = 0; i < categoryButtons.Length; i++)
{
cards[i].SetBack(false, true);
bool visible = i < entries[index].Length;
cards[i].gameObject.SetActive(visible);
if (visible) cards[i].Bind(entries[index][i]);
}
for (int i = 0; i < categories.Length; i++)
{
var colors = categories[i].colors;
colors.normalColor = i == index ? new Color(1f, 0.72f, 0.2f) : new Color(0.82f, 0.82f, 0.82f);
colors.highlightedColor = i == index ? new Color(1f, 0.82f, 0.4f) : Color.white;
colors.selectedColor = colors.normalColor;
colors.pressedColor = new Color(0.7f, 0.7f, 0.7f);
categories[i].colors = colors;
categories[i].image.color = Color.white;
categoryButtons[i].image.color = Color.white; var colors = categoryButtons[i].colors;
colors.normalColor = i == index ? new Color(1, 0.76f, 0.35f) : new Color(0.87f, 0.84f, 0.75f);
colors.highlightedColor = i == index ? new Color(1, 0.86f, 0.55f) : new Color(0.97f, 0.94f, 0.85f);
colors.selectedColor = colors.normalColor; categoryButtons[i].colors = colors;
}
}
private void Bind()
{
if (groups[selected].Count > cardSlots.Length) Debug.LogError("Handbuch: Mehr Einträge als vorbereitete Baukarten; weitere Slots im Inspector ergänzen.", this);
for (int i = 0; i < cardSlots.Length; i++) { bool visible = i < groups[selected].Count; cardSlots[i].gameObject.SetActive(visible); if (visible) cardSlots[i].Bind(groups[selected][i]); }
}
public void ToggleCard(TowerCardView card)
{
if (revealed == card)
{
card.SetBack(false);
revealed = null;
return;
}
if (revealed) revealed.SetBack(false);
revealed = card;
card.SetBack(true);
}
public void ResetCards()
{
revealed = null;
foreach (var card in cards) card.SetBack(false, true);
}
public void ResetForClose()
{
ResetCards();
SelectCategory(0);
if (revealed == card) { card.SetBack(false); revealed = null; return; }
if (revealed) revealed.SetBack(false); revealed = card; card.SetBack(true);
}
public void ResetCards() { revealed = null; foreach (var card in cardSlots) card.SetBack(false, true); }
public void ResetForClose() { ResetCards(); selected = -1; SelectCategory(0); }
}
}