AgentPanelUI.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace MazeGen
  5. {
  6. /// <summary>
  7. /// Displays a clickable list of all agents with their status. Allows the player to follow
  8. /// an agent's perspective. Narrates status as dead, reached exit, fighting, or exploring with HP.
  9. /// </summary>
  10. public class AgentPanelUI
  11. {
  12. private Vector2 scrollPosition;
  13. public AgentPanelUI()
  14. {
  15. }
  16. /// <summary>
  17. /// Draw the agent list panel. Returns the clicked agent (if any) or null.
  18. /// </summary>
  19. public MazeAgent Draw(List<MazeAgent> agents, MazeAgent currentlyFollowed, bool hasFollowedAgent, Action onStopFollowing)
  20. {
  21. GUILayout.BeginArea(new Rect(10, 360, 280, Screen.height - 380), GUI.skin.box);
  22. if (hasFollowedAgent && GUILayout.Button("Stop following"))
  23. onStopFollowing?.Invoke();
  24. GUILayout.Space(6);
  25. GUILayout.Label("Agents (click to follow):");
  26. scrollPosition = GUILayout.BeginScrollView(scrollPosition);
  27. MazeAgent clickedAgent = null;
  28. foreach (var agent in agents)
  29. {
  30. bool isFollowed = agent == currentlyFollowed;
  31. string status = DescribeStatus(agent);
  32. GUI.color = agent.IsDead ? new Color(0.55f, 0.55f, 0.55f) : Color.white;
  33. if (GUILayout.Button($"{(isFollowed ? "> " : "")}{agent.DisplayName} - {status}"))
  34. clickedAgent = agent;
  35. }
  36. GUI.color = Color.white;
  37. GUILayout.EndScrollView();
  38. GUILayout.EndArea();
  39. return clickedAgent;
  40. }
  41. private string DescribeStatus(MazeAgent agent)
  42. {
  43. if (agent.IsDead) return "dead";
  44. if (agent.IsFinished) return "reached exit";
  45. if (agent.IsEngaged) return "fighting";
  46. return $"exploring ({agent.CharacterSheet.Stats.CurrentHealth:0}hp)";
  47. }
  48. }
  49. }