Guidebook can POP OUT YAYYYY (#20268)

* Let them eat cake

* Reviews

* Change amoled theme to gray

* Ok nevermind im big smart
This commit is contained in:
Vasilis
2023-09-22 21:52:30 +02:00
committed by GitHub
parent 413ba8cc9a
commit e5162d4151
6 changed files with 282 additions and 202 deletions

View File

@@ -5,6 +5,7 @@ using Content.Client.Guidebook.Controls;
using Content.Client.Lobby;
using Content.Client.UserInterface.Controls;
using Content.Shared.Input;
using Robust.Client.Graphics;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controllers;
using static Robust.Client.UserInterface.Controls.BaseButton;
@@ -17,7 +18,11 @@ namespace Content.Client.UserInterface.Systems.Guidebook;
public sealed class GuidebookUIController : UIController, IOnStateEntered<LobbyState>, IOnStateEntered<GameplayState>, IOnStateExited<LobbyState>, IOnStateExited<GameplayState>, IOnSystemChanged<GuidebookSystem>
{
[UISystemDependency] private readonly GuidebookSystem _guidebookSystem = default!;
[Dependency] private readonly IClyde _clyde = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IUserInterfaceManager _uiManager = default!;
private IClydeWindow? ClydeWindow { get; set; }
private GuidebookWindow? _guideWindow;
private MenuButton? GuidebookButton => UIManager.GetActiveUIWidgetOrNull<MenuBar.Widgets.GameTopMenuBar>()?.GuidebookButton;
@@ -40,6 +45,7 @@ public sealed class GuidebookUIController : UIController, IOnStateEntered<LobbyS
_guideWindow = UIManager.CreateWindow<GuidebookWindow>();
_guideWindow.OnClose += OnWindowClosed;
_guideWindow.OnOpen += OnWindowOpen;
_guideWindow.Guidebook.PopOutButton.OnPressed += _ => PopOut();
// setup keybinding
CommandBinds.Builder
@@ -135,7 +141,12 @@ public sealed class GuidebookUIController : UIController, IOnStateEntered<LobbyS
string? selected = null)
{
if (_guideWindow == null)
return;
{
_guideWindow = UIManager.CreateWindow<GuidebookWindow>();
_guideWindow.OnClose += OnWindowClosed;
_guideWindow.OnOpen += OnWindowOpen;
_guideWindow.Guidebook.PopOutButton.OnPressed += _ => PopOut();
}
if (_guideWindow.IsOpen)
{
@@ -161,11 +172,11 @@ public sealed class GuidebookUIController : UIController, IOnStateEntered<LobbyS
}
}
_guideWindow.UpdateGuides(guides, rootEntries, forceRoot, selected);
_guideWindow.Guidebook.UpdateGuides(guides, rootEntries, forceRoot, selected);
// Expand up to depth-2.
_guideWindow.Tree.SetAllExpanded(false);
_guideWindow.Tree.SetAllExpanded(true, 1);
_guideWindow.Guidebook.Tree.SetAllExpanded(false);
_guideWindow.Guidebook.Tree.SetAllExpanded(true, 1);
_guideWindow.OpenCenteredRight();
}
@@ -208,4 +219,43 @@ public sealed class GuidebookUIController : UIController, IOnStateEntered<LobbyS
RecursivelyAddChildren(child, guides);
}
}
private void PopOut()
{
if (_guideWindow == null)
{
return;
}
var monitor = _clyde.EnumerateMonitors().First();
ClydeWindow = _clyde.CreateWindow(new WindowCreateParameters
{
Maximized = false,
Title = "Guidebook",
Monitor = monitor,
Width = 750,
Height = 700
});
var control = _guideWindow.Guidebook;
control.Orphan();
_guideWindow.Dispose();
_guideWindow = null;
ClydeWindow.RequestClosed += OnRequestClosed;
ClydeWindow.DisposeOnClose = true;
var Root = _uiManager.CreateWindowRoot(ClydeWindow);
Root.AddChild(control);
control.PopOutButton.Disabled = true;
control.PopOutButton.Visible = false;
}
private void OnRequestClosed(WindowRequestClosedEventArgs obj)
{
ClydeWindow = null;
_guideWindow = null;
if (GuidebookButton != null)
GuidebookButton.Pressed = false;
}
}