Files
commander-ai-lab/unity-client/Assets/Scripts/UI/Battleground/StackZoneController.cs
T
KoalaTrapLord 3f5d6d12e8 feat: 4-player Commander Battleground UI (issues #138–#151)
* chore: add battleground UI task tracker (2026-03-28)

* feat(#142): add [NonSerialized] battleground runtime state to CardModel

* feat(#143): add LoadArtCrop and LoadCardRaw (RawImage) to ImageCache

* feat(#148): add GameStateManager singleton and GameState/SeatState POCOs

* feat(#138): add BattlegroundController scene orchestrator

* feat(#139): add LifeTrackerWidget, CommanderDamageRow, PoisonCounter

* feat(#140): add PhaseTrackerWidget and PhaseStepButton

* feat(#141): add TurnOrderBar and TurnOrderPill

* feat(#142): add CardZone and CardView battlefield zone components

* feat(#143): add CommanderZoneWidget with art crop, cast counter, and tax display

* feat(#144): add TokenModel POCO, TokenPanelController, and TokenRowView

* chore: mark issues 1-8 as complete in task tracker

* feat(#146): add StackZoneController, StackItemView, and ManaPoolDisplay

* feat(#147 #150 #151): add LobbySetupModal, ZoneViewerModal, EliminationHandler; add Play Live button to SimulationController

* feat(#151): add Play Live button to SimulationController

* feat(#149): add GameWebSocketClient with reconnect, ping, and main-thread dispatch

* fix: add PostGameAction to ApiClient + update TODO.md all issues complete

- ApiClient.cs: add PostGameAction() wrapper → POST /api/game/action
  (fixes compile error in HumanActionBar.cs)
- TODO.md: mark issues #145, #146, #147, #149, #150, #151 as ✅
  all 14 battleground issues now committed

* feat(game): add routes/game.py + wire lab_api + fix GameWebSocketClient game_id URL

- routes/game.py: POST /api/game/start, POST /api/game/action (new)
- lab_api.py: import + register game_router
- GameWebSocketClient.cs: read game_id from PlayerPrefs, build
  ws://{host}/ws/game/{game_id} — fixes URL mismatch with ws_game.py

* fix(lobby): wire OnConfirm to POST /api/game/start, save game_id to PlayerPrefs

- OnConfirm() now calls ApiClient.PostGameStart() with 4-seat config
- On success: saves BattleSeats + GameId + WsUrl to PlayerPrefs,
  loads Battleground scene
- On failure: shows inline error label (red), re-enables Confirm button
- Added StartGameRequest/Response POCOs matching routes/game.py schema
- Added _errorLabel [SerializeField] for user-facing error feedback
2026-03-29 05:35:29 -04:00

73 lines
2.7 KiB
C#

using System;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using Newtonsoft.Json;
namespace CommanderAILab.UI
{
/// <summary>
/// Displays the active spell/ability stack (LIFO order, top of stack shown first).
/// Hidden when stack is empty. Subscribes to GameStateManager.OnStackUpdated.
/// </summary>
public class StackZoneController : MonoBehaviour
{
[SerializeField] private GameObject stackPanel;
[SerializeField] private Transform stackItemParent; // VerticalLayoutGroup
[SerializeField] private GameObject stackItemPrefab;
[SerializeField] private TMP_Text stackCountLabel;
private readonly List<GameObject> _itemGOs = new();
// ── Lifecycle ───────────────────────────────────────────
private void Start()
{
if (GameStateManager.Instance != null)
GameStateManager.Instance.OnStackUpdated += SetStack;
SetStack(new List<StackItem>());
}
private void OnDestroy()
{
if (GameStateManager.Instance != null)
GameStateManager.Instance.OnStackUpdated -= SetStack;
}
// ── Public API ─────────────────────────────────────────
public void SetStack(List<StackItem> items)
{
// Clear existing rows
foreach (var go in _itemGOs) if (go) Destroy(go);
_itemGOs.Clear();
bool hasItems = items != null && items.Count > 0;
if (stackPanel) stackPanel.SetActive(hasItems);
if (stackCountLabel)
stackCountLabel.text = hasItems ? $"Stack ({items.Count})" : "";
if (!hasItems) return;
// LIFO — iterate in reverse so top of stack appears first
for (int i = items.Count - 1; i >= 0; i--)
{
var go = Instantiate(stackItemPrefab, stackItemParent);
go.SetActive(true);
var view = go.GetComponent<StackItemView>();
view?.Bind(items[i], items.Count - 1 - i);
_itemGOs.Add(go);
}
}
// ── Serializable stack item (shared with GameState) ───────────
[Serializable]
public class StackItem
{
[JsonProperty("card_name")] public string cardName;
[JsonProperty("caster_seat")] public int casterSeat;
[JsonProperty("targets")] public List<string> targets;
[JsonProperty("is_ability")] public bool isAbility;
}
}
}