| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- using Content.Client.Gameplay;
- using Content.Client.Ghost;
- using Content.Client.UserInterface.Systems.Gameplay;
- using Content.Client.UserInterface.Systems.Ghost.Widgets;
- using Content.Shared.Ghost;
- using Robust.Client.UserInterface;
- using Robust.Client.UserInterface.Controllers;
- namespace Content.Client.UserInterface.Systems.Ghost;
- // TODO hud refactor BEFORE MERGE fix ghost gui being too far up
- public sealed class GhostUIController : UIController, IOnSystemChanged<GhostSystem>
- {
- [Dependency] private readonly IEntityNetworkManager _net = default!;
- [UISystemDependency] private readonly GhostSystem? _system = default;
- private GhostGui? Gui => UIManager.GetActiveUIWidgetOrNull<GhostGui>();
- public override void Initialize()
- {
- base.Initialize();
- var gameplayStateLoad = UIManager.GetUIController<GameplayStateLoadController>();
- gameplayStateLoad.OnScreenLoad += OnScreenLoad;
- gameplayStateLoad.OnScreenUnload += OnScreenUnload;
- }
- private void OnScreenLoad()
- {
- LoadGui();
- }
- private void OnScreenUnload()
- {
- UnloadGui();
- }
- public void OnSystemLoaded(GhostSystem system)
- {
- system.PlayerRemoved += OnPlayerRemoved;
- system.PlayerUpdated += OnPlayerUpdated;
- system.PlayerAttached += OnPlayerAttached;
- system.PlayerDetached += OnPlayerDetached;
- system.GhostWarpsResponse += OnWarpsResponse;
- system.GhostRoleCountUpdated += OnRoleCountUpdated;
- }
- public void OnSystemUnloaded(GhostSystem system)
- {
- system.PlayerRemoved -= OnPlayerRemoved;
- system.PlayerUpdated -= OnPlayerUpdated;
- system.PlayerAttached -= OnPlayerAttached;
- system.PlayerDetached -= OnPlayerDetached;
- system.GhostWarpsResponse -= OnWarpsResponse;
- system.GhostRoleCountUpdated -= OnRoleCountUpdated;
- }
- public void UpdateGui()
- {
- if (Gui == null)
- {
- return;
- }
- Gui.Visible = _system?.IsGhost ?? false;
- Gui.Update(_system?.AvailableGhostRoleCount, _system?.Player?.CanReturnToBody);
- }
- private void OnPlayerRemoved(GhostComponent component)
- {
- Gui?.Hide();
- }
- private void OnPlayerUpdated(GhostComponent component)
- {
- UpdateGui();
- }
- private void OnPlayerAttached(GhostComponent component)
- {
- if (Gui == null)
- return;
- Gui.Visible = true;
- UpdateGui();
- }
- private void OnPlayerDetached()
- {
- Gui?.Hide();
- }
- private void OnWarpsResponse(GhostWarpsResponseEvent msg)
- {
- if (Gui?.TargetWindow is not { } window)
- return;
- window.UpdateWarps(msg.Warps);
- window.Populate();
- }
- private void OnRoleCountUpdated(GhostUpdateGhostRoleCountEvent msg)
- {
- UpdateGui();
- }
- private void OnWarpClicked(NetEntity player)
- {
- var msg = new GhostWarpToTargetRequestEvent(player);
- _net.SendSystemNetworkMessage(msg);
- }
- private void OnGhostnadoClicked()
- {
- var msg = new GhostnadoRequestEvent();
- _net.SendSystemNetworkMessage(msg);
- }
- public void LoadGui()
- {
- if (Gui == null)
- return;
- Gui.RequestWarpsPressed += RequestWarps;
- Gui.ReturnToBodyPressed += ReturnToBody;
- Gui.ReturnToLobbyPressed += ReturnToLobby;
- Gui.GhostRolesPressed += GhostRolesPressed;
- Gui.TargetWindow.WarpClicked += OnWarpClicked;
- Gui.TargetWindow.OnGhostnadoClicked += OnGhostnadoClicked;
- UpdateGui();
- }
- public void UnloadGui()
- {
- if (Gui == null)
- return;
- Gui.RequestWarpsPressed -= RequestWarps;
- Gui.ReturnToBodyPressed -= ReturnToBody;
- Gui.ReturnToLobbyPressed -= ReturnToLobby;
- Gui.GhostRolesPressed -= GhostRolesPressed;
- Gui.TargetWindow.WarpClicked -= OnWarpClicked;
- Gui.Hide();
- }
- private void ReturnToBody()
- {
- _system?.ReturnToBody();
- }
- private void ReturnToLobby()
- {
- _system?.ReturnToLobby();
- }
- private void RequestWarps()
- {
- _system?.RequestWarps();
- Gui?.TargetWindow.Populate();
- Gui?.TargetWindow.OpenCentered();
- }
- private void GhostRolesPressed()
- {
- _system?.OpenGhostRoles();
- }
- }
|