| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- using System.Collections.Generic;
- using System.Linq;
- using UnityEngine;
- namespace MazeGen
- {
- /// <summary>
- /// Displays live fights: join-window countdown timer, participant list, and controls
- /// to watch or simulate each fight. Drawn centre-top so a paused fight is impossible to miss.
- /// </summary>
- public class FightPanelUI
- {
- private Vector2 scrollPosition;
- private CombatDirector director;
- private MazeCameraController cameraController;
- public FightPanelUI(CombatDirector combatDirector, MazeCameraController camera)
- {
- director = combatDirector;
- cameraController = camera;
- }
- public void Draw()
- {
- var fights = director.ActiveFights;
- if (fights.Count == 0) return;
- float width = Mathf.Min(460f, Mathf.Max(280f, Screen.width - 720f));
- GUILayout.BeginArea(new Rect(300f, 10f, width, Screen.height - 20f), GUI.skin.box);
- GUILayout.Label($"FIGHTS BREAKING OUT ({fights.Count})", GUI.skin.box);
- // The "resume" button stays outside the scroll view so it's always reachable even
- // when there are more fights than fit on screen at once.
- scrollPosition = GUILayout.BeginScrollView(scrollPosition);
- // Snapshot: resuming from this panel can resolve/cancel a fight, mutating the live list.
- foreach (var fight in fights.ToArray())
- {
- GUILayout.BeginVertical(GUI.skin.box);
- GUILayout.Label($"#{fight.Id} in room {fight.Room.Id} - {fight.Agents.Count} agent(s) vs {fight.Encounter.AliveMonsterCount} monster(s)");
- 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")}");
- GUILayout.Label($"In: {string.Join(", ", fight.Agents.Select(a => a.DisplayName))}");
- // These only set a preference for when the join window naturally expires - they
- // never skip the timer, so late arrivals always get their full chance to join.
- CombatViewMode preferred = fight.PreferredResolution ?? director.TimeoutResolution;
- GUILayout.Label($"When it starts: {(preferred == CombatViewMode.Watch ? "watch it" : "log only")}");
- GUILayout.BeginHorizontal();
- GUI.enabled = preferred != CombatViewMode.Watch;
- if (GUILayout.Button("Watch it"))
- director.PreferWatch(fight);
- GUI.enabled = preferred != CombatViewMode.Simulate;
- if (GUILayout.Button("Log only"))
- director.PreferSimulate(fight);
- GUI.enabled = true;
- if (GUILayout.Button("Go to"))
- cameraController?.FocusOn(fight.Room.Position);
- GUILayout.EndHorizontal();
- GUILayout.EndVertical();
- }
- GUILayout.EndScrollView();
- if (SimulationClock.IsPaused && GUILayout.Button("Resume - let the join window run"))
- {
- director.ResumeAllMusters();
- SimulationClock.UserPaused = false;
- }
- GUILayout.EndArea();
- }
- }
- }
|