Files
commander-ai-lab/unity-client/Assets/Scripts/UI/Battleground/CommanderDamageRow.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

70 lines
2.4 KiB
C#

using UnityEngine;
using TMPro;
namespace CommanderAILab.UI
{
/// <summary>
/// Displays cumulative commander damage received from each opposing seat.
/// Triggers elimination when any source reaches 21.
/// Attach one to each seat panel; set SeatIndex in inspector.
/// </summary>
public class CommanderDamageRow : MonoBehaviour
{
/// <summary>The seat this row belongs to (receives damage).</summary>
[SerializeField] private int seatIndex;
/// <summary>
/// Labels for damage received from each seat.
/// fromSeatLabels[i] corresponds to global seat i.
/// The label for this seat's own index will be hidden (can't deal commander damage to yourself).
/// </summary>
[SerializeField] private TMP_Text[] fromSeatLabels; // length 4
private readonly int[] _damage = new int[4];
private void Start()
{
// Hide this seat's own label
if (fromSeatLabels != null && seatIndex < fromSeatLabels.Length
&& fromSeatLabels[seatIndex] != null)
fromSeatLabels[seatIndex].gameObject.SetActive(false);
RefreshAllLabels();
}
public void AddDamage(int fromSeat, int amount)
{
if (fromSeat < 0 || fromSeat >= 4 || fromSeat == seatIndex) return;
_damage[fromSeat] = Mathf.Max(0, _damage[fromSeat] + amount);
RefreshLabel(fromSeat);
if (_damage[fromSeat] >= 21)
GameStateManager.Instance?.EliminatePlayer(seatIndex, "commander_damage");
}
public void SetDamage(int fromSeat, int value)
{
if (fromSeat < 0 || fromSeat >= 4 || fromSeat == seatIndex) return;
_damage[fromSeat] = Mathf.Max(0, value);
RefreshLabel(fromSeat);
}
public int GetDamage(int fromSeat) =>
(fromSeat >= 0 && fromSeat < 4) ? _damage[fromSeat] : 0;
private void RefreshLabel(int fromSeat)
{
if (fromSeatLabels == null || fromSeat >= fromSeatLabels.Length) return;
var lbl = fromSeatLabels[fromSeat];
if (lbl == null) return;
lbl.text = _damage[fromSeat] > 0 ? _damage[fromSeat].ToString() : "0";
lbl.color = _damage[fromSeat] >= 21 ? Color.red : Color.white;
}
private void RefreshAllLabels()
{
for (int i = 0; i < 4; i++) RefreshLabel(i);
}
}
}