Files
tbd-station-14/Content.Client/UserInterface/Systems/EscapeMenu/EscapeUIController.cs
Leon Friedrich 22d72f56b5 Guidebook Revival (#13320)
* Fix some bugs in stations and do a little cleanup.

* Begin backporting the guidebook.

* wow that's a lot of work.

* More work, gives the monkey some more interactions.

* disco monkye.

* monky

* jobs entry.

* more writing.

* disco

* im being harassed

* fix spacing.

* i hate writing.

* Update Resources/Prototypes/Entities/Mobs/NPCs/animals.yml

Co-authored-by: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com>

* builds again

* a

* pilfer changes from AL

* fix and remove unused code

* pilfer actual guide changes from AL

* localization

* more error logs & safety checks

* replace controls button with command

* add test

* todos

* pidgin parsing

* remove old parser

* Move files and change tree sorting

* add localization and public methods.

* Add help component/verb

* rename ITag to IDocumentTag

* Fix yml and tweak tooltips

* autoclose tooltip

* Split container

* Fancier-tree

* Hover color

* txt to xml

* oops

* Curse you hidden merge conflicts

* Rename parsing manager

* Stricter arg parsing

tag args must now be of the form key="value"

* Change default args

* Moar tests

* nullable enable

* Even fancier tree

* extremely fancy trees

* better indent icons

* stricter xml and subheadings

* tweak embed margin

* Fix parsing bugs

* quick fixes.

* spain.

* ogh

* hn bmvdsyc

Co-authored-by: moonheart08 <moonheart08@users.noreply.github.com>
2023-01-16 02:42:22 -06:00

155 lines
4.3 KiB
C#

using Content.Client.Gameplay;
using Content.Client.Guidebook;
using Content.Client.Info;
using Content.Client.UserInterface.Controls;
using Content.Client.UserInterface.Systems.Info;
using Content.Shared.CCVar;
using JetBrains.Annotations;
using Robust.Client.Console;
using Robust.Client.Input;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controllers;
using Robust.Shared.Configuration;
using Robust.Shared.Input;
using Robust.Shared.Input.Binding;
using Robust.Shared.Utility;
using static Robust.Client.UserInterface.Controls.BaseButton;
namespace Content.Client.UserInterface.Systems.EscapeMenu;
[UsedImplicitly]
public sealed class EscapeUIController : UIController, IOnStateEntered<GameplayState>, IOnStateExited<GameplayState>
{
[Dependency] private readonly IClientConsoleHost _console = default!;
[Dependency] private readonly IUriOpener _uri = default!;
[Dependency] private readonly IConfigurationManager _cfg = default!;
[Dependency] private readonly ChangelogUIController _changelog = default!;
[Dependency] private readonly InfoUIController _info = default!;
[Dependency] private readonly OptionsUIController _options = default!;
[UISystemDependency] private readonly GuidebookSystem? _guidebook = default!;
private Options.UI.EscapeMenu? _escapeWindow;
private MenuButton? EscapeButton => UIManager.GetActiveUIWidgetOrNull<MenuBar.Widgets.GameTopMenuBar>()?.EscapeButton;
public void UnloadButton()
{
if (EscapeButton == null)
{
return;
}
EscapeButton.Pressed = false;
EscapeButton.OnPressed -= EscapeButtonOnOnPressed;
}
public void LoadButton()
{
if (EscapeButton == null)
{
return;
}
EscapeButton.OnPressed += EscapeButtonOnOnPressed;
}
private void ActivateButton() => EscapeButton!.Pressed = true;
private void DeactivateButton() => EscapeButton!.Pressed = false;
public void OnStateEntered(GameplayState state)
{
DebugTools.Assert(_escapeWindow == null);
_escapeWindow = UIManager.CreateWindow<Options.UI.EscapeMenu>();
_escapeWindow.OnClose += DeactivateButton;
_escapeWindow.OnOpen += ActivateButton;
_escapeWindow.ChangelogButton.OnPressed += _ =>
{
CloseEscapeWindow();
_changelog.ToggleWindow();
};
_escapeWindow.RulesButton.OnPressed += _ =>
{
CloseEscapeWindow();
_info.OpenWindow();
};
_escapeWindow.DisconnectButton.OnPressed += _ =>
{
CloseEscapeWindow();
_console.ExecuteCommand("disconnect");
};
_escapeWindow.OptionsButton.OnPressed += _ =>
{
CloseEscapeWindow();
_options.OpenWindow();
};
_escapeWindow.QuitButton.OnPressed += _ =>
{
CloseEscapeWindow();
_console.ExecuteCommand("quit");
};
_escapeWindow.WikiButton.OnPressed += _ =>
{
_uri.OpenUri(_cfg.GetCVar(CCVars.InfoLinksWiki));
};
_escapeWindow.GuidebookButton.OnPressed += _ =>
{
_guidebook?.OpenGuidebook();
};
// Hide wiki button if we don't have a link for it.
_escapeWindow.WikiButton.Visible = _cfg.GetCVar(CCVars.InfoLinksWiki) != "";
CommandBinds.Builder
.Bind(EngineKeyFunctions.EscapeMenu,
InputCmdHandler.FromDelegate(_ => ToggleWindow()))
.Register<EscapeUIController>();
}
public void OnStateExited(GameplayState state)
{
if (_escapeWindow != null)
{
_escapeWindow.Dispose();
_escapeWindow = null;
}
CommandBinds.Unregister<EscapeUIController>();
}
private void EscapeButtonOnOnPressed(ButtonEventArgs obj)
{
ToggleWindow();
}
private void CloseEscapeWindow()
{
_escapeWindow?.Close();
}
private void ToggleWindow()
{
if (_escapeWindow == null)
return;
if (_escapeWindow.IsOpen)
{
CloseEscapeWindow();
EscapeButton!.Pressed = false;
}
else
{
_escapeWindow.OpenCentered();
EscapeButton!.Pressed = true;
}
}
}