FightPanelUI.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using UnityEngine;
  4. namespace MazeGen
  5. {
  6. /// <summary>
  7. /// Displays live fights: join-window countdown timer, participant list, and controls
  8. /// to watch or simulate each fight. Drawn centre-top so a paused fight is impossible to miss.
  9. /// </summary>
  10. public class FightPanelUI
  11. {
  12. private Vector2 scrollPosition;
  13. private CombatDirector director;
  14. private MazeCameraController cameraController;
  15. public FightPanelUI(CombatDirector combatDirector, MazeCameraController camera)
  16. {
  17. director = combatDirector;
  18. cameraController = camera;
  19. }
  20. public void Draw()
  21. {
  22. var fights = director.ActiveFights;
  23. if (fights.Count == 0) return;
  24. float width = Mathf.Min(460f, Mathf.Max(280f, Screen.width - 720f));
  25. GUILayout.BeginArea(new Rect(300f, 10f, width, Screen.height - 20f), GUI.skin.box);
  26. GUILayout.Label($"FIGHTS BREAKING OUT ({fights.Count})", GUI.skin.box);
  27. // The "resume" button stays outside the scroll view so it's always reachable even
  28. // when there are more fights than fit on screen at once.
  29. scrollPosition = GUILayout.BeginScrollView(scrollPosition);
  30. // Snapshot: resuming from this panel can resolve/cancel a fight, mutating the live list.
  31. foreach (var fight in fights.ToArray())
  32. {
  33. GUILayout.BeginVertical(GUI.skin.box);
  34. GUILayout.Label($"#{fight.Id} in room {fight.Room.Id} - {fight.Agents.Count} agent(s) vs {fight.Encounter.AliveMonsterCount} monster(s)");
  35. GUILayout.Label($"Starts in {Mathf.Max(0f, fight.JoinTimeRemaining):0.0}s - {(SimulationClock.IsPaused ? "frozen; resume to let the timer run out" : "others can still join")}");
  36. GUILayout.Label($"In: {string.Join(", ", fight.Agents.Select(a => a.DisplayName))}");
  37. // These only set a preference for when the join window naturally expires - they
  38. // never skip the timer, so late arrivals always get their full chance to join.
  39. CombatViewMode preferred = fight.PreferredResolution ?? director.TimeoutResolution;
  40. GUILayout.Label($"When it starts: {(preferred == CombatViewMode.Watch ? "watch it" : "log only")}");
  41. GUILayout.BeginHorizontal();
  42. GUI.enabled = preferred != CombatViewMode.Watch;
  43. if (GUILayout.Button("Watch it"))
  44. director.PreferWatch(fight);
  45. GUI.enabled = preferred != CombatViewMode.Simulate;
  46. if (GUILayout.Button("Log only"))
  47. director.PreferSimulate(fight);
  48. GUI.enabled = true;
  49. if (GUILayout.Button("Go to"))
  50. cameraController?.FocusOn(fight.Room.Position);
  51. GUILayout.EndHorizontal();
  52. GUILayout.EndVertical();
  53. }
  54. GUILayout.EndScrollView();
  55. if (SimulationClock.IsPaused && GUILayout.Button("Resume - let the join window run"))
  56. {
  57. director.ResumeAllMusters();
  58. SimulationClock.UserPaused = false;
  59. }
  60. GUILayout.EndArea();
  61. }
  62. }
  63. }