* 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
87 lines
3.4 KiB
C#
87 lines
3.4 KiB
C#
using UnityEngine;
|
|
using TMPro;
|
|
|
|
namespace CommanderAILab.UI
|
|
{
|
|
/// <summary>
|
|
/// Horizontal strip of 4 TurnOrderPills at the top of BattlefieldCenter.
|
|
/// Animates an active border sliding to the current seat's pill on turn change.
|
|
/// Subscribes to GameStateManager.OnTurnChanged.
|
|
/// </summary>
|
|
public class TurnOrderBar : MonoBehaviour
|
|
{
|
|
[SerializeField] private TurnOrderPill[] pills; // length 4
|
|
[SerializeField] private RectTransform activeBorder; // sliding highlight rect
|
|
[SerializeField] private float slideDuration = 0.25f;
|
|
|
|
private int _activeSeat = 0;
|
|
|
|
// ── Lifecycle ───────────────────────────────────────────
|
|
private void Start()
|
|
{
|
|
if (GameStateManager.Instance != null)
|
|
{
|
|
GameStateManager.Instance.OnTurnChanged += SetActiveSeat;
|
|
GameStateManager.Instance.OnLifeChanged += OnLifeChanged;
|
|
GameStateManager.Instance.OnPlayerEliminated += OnPlayerEliminated;
|
|
}
|
|
SetActiveSeat(0);
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
if (GameStateManager.Instance == null) return;
|
|
GameStateManager.Instance.OnTurnChanged -= SetActiveSeat;
|
|
GameStateManager.Instance.OnLifeChanged -= OnLifeChanged;
|
|
GameStateManager.Instance.OnPlayerEliminated -= OnPlayerEliminated;
|
|
}
|
|
|
|
// ── Public API ─────────────────────────────────────────
|
|
public void SetActiveSeat(int seatIndex)
|
|
{
|
|
_activeSeat = seatIndex;
|
|
for (int i = 0; i < pills.Length; i++)
|
|
pills[i]?.SetActive(i == seatIndex);
|
|
|
|
AnimateBorderToPill(seatIndex);
|
|
}
|
|
|
|
// ── Internal ──────────────────────────────────────────
|
|
private void AnimateBorderToPill(int seatIndex)
|
|
{
|
|
if (activeBorder == null || pills == null || seatIndex >= pills.Length) return;
|
|
if (pills[seatIndex] == null) return;
|
|
|
|
var targetPos = (pills[seatIndex].transform as RectTransform)?.anchoredPosition
|
|
?? pills[seatIndex].transform.localPosition;
|
|
|
|
StopAllCoroutines();
|
|
StartCoroutine(SlideBorder(targetPos));
|
|
}
|
|
|
|
private System.Collections.IEnumerator SlideBorder(Vector2 targetPos)
|
|
{
|
|
var start = activeBorder.anchoredPosition;
|
|
float elapsed = 0f;
|
|
while (elapsed < slideDuration)
|
|
{
|
|
elapsed += Time.deltaTime;
|
|
float t = Mathf.SmoothStep(0f, 1f, elapsed / slideDuration);
|
|
activeBorder.anchoredPosition = Vector2.Lerp(start, targetPos, t);
|
|
yield return null;
|
|
}
|
|
activeBorder.anchoredPosition = targetPos;
|
|
}
|
|
|
|
private void OnLifeChanged(int seatIndex, int newLife)
|
|
{
|
|
if (seatIndex < pills.Length) pills[seatIndex]?.UpdateLife(newLife);
|
|
}
|
|
|
|
private void OnPlayerEliminated(int seatIndex, string reason)
|
|
{
|
|
if (seatIndex < pills.Length) pills[seatIndex]?.SetEliminated();
|
|
}
|
|
}
|
|
}
|