| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- using System;
- using System.Collections.Generic;
- using UnityEngine;
- namespace MazeGen
- {
- /// <summary>
- /// Displays a clickable list of all agents with their status. Allows the player to follow
- /// an agent's perspective. Narrates status as dead, reached exit, fighting, or exploring with HP.
- /// </summary>
- public class AgentPanelUI
- {
- private Vector2 scrollPosition;
- public AgentPanelUI()
- {
- }
- /// <summary>
- /// Draw the agent list panel. Returns the clicked agent (if any) or null.
- /// </summary>
- public MazeAgent Draw(List<MazeAgent> agents, MazeAgent currentlyFollowed, bool hasFollowedAgent, Action onStopFollowing)
- {
- GUILayout.BeginArea(new Rect(10, 360, 280, Screen.height - 380), GUI.skin.box);
- if (hasFollowedAgent && GUILayout.Button("Stop following"))
- onStopFollowing?.Invoke();
- GUILayout.Space(6);
- GUILayout.Label("Agents (click to follow):");
- scrollPosition = GUILayout.BeginScrollView(scrollPosition);
- MazeAgent clickedAgent = null;
- foreach (var agent in agents)
- {
- bool isFollowed = agent == currentlyFollowed;
- string status = DescribeStatus(agent);
- GUI.color = agent.IsDead ? new Color(0.55f, 0.55f, 0.55f) : Color.white;
- if (GUILayout.Button($"{(isFollowed ? "> " : "")}{agent.DisplayName} - {status}"))
- clickedAgent = agent;
- }
- GUI.color = Color.white;
- GUILayout.EndScrollView();
- GUILayout.EndArea();
- return clickedAgent;
- }
- private string DescribeStatus(MazeAgent agent)
- {
- if (agent.IsDead) return "dead";
- if (agent.IsFinished) return "reached exit";
- if (agent.IsEngaged) return "fighting";
- return $"exploring ({agent.CharacterSheet.Stats.CurrentHealth:0}hp)";
- }
- }
- }
|