Handbuch Tabs: Bauen und Index (fertig)
UI_Prefabs HandbuchDataAssets
This commit is contained in:
@@ -0,0 +1,103 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace DepthsOfGreed.HandbookUI
|
||||
{
|
||||
public sealed class BuildMenuController : MonoBehaviour
|
||||
{
|
||||
public TestPlacementController Placement { get; set; }
|
||||
private readonly List<TowerCardView> cards = new List<TowerCardView>();
|
||||
private Button[] categories;
|
||||
private int selectedCategory = -1;
|
||||
private TowerCardView revealed;
|
||||
private HandbookTowerEntry[][] entries;
|
||||
|
||||
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));
|
||||
}
|
||||
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++)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user