Construction UI MVP Experiment (#3107)

* Refactors the ConstructionSystem into the MVP pattern.

* Refactors the ConstructionMenu into the MVP pattern.

* Moved the ConstructionMenuPresenter to the GameScreen where it belongs.

* Rebase updates.
This commit is contained in:
Acruid
2021-02-20 12:05:59 -08:00
committed by GitHub
parent 1b8c07b76f
commit 008fee4eaf
4 changed files with 689 additions and 443 deletions

View File

@@ -1,5 +1,7 @@
#nullable enable
using Content.Client.Administration;
using Content.Client.Chat;
using Content.Client.Construction;
using Content.Client.Interfaces.Chat;
using Content.Client.UserInterface;
using Content.Client.Voting;
@@ -26,7 +28,8 @@ namespace Content.Client.State
[Dependency] private readonly IConfigurationManager _configurationManager = default!;
[Dependency] private readonly IClientAdminManager _adminManager = default!;
[ViewVariables] private ChatBox _gameChat;
[ViewVariables] private ChatBox? _gameChat;
private ConstructionMenuPresenter? _constructionMenu;
private bool _oocEnabled;
private bool _adminOocEnabled;
@@ -61,16 +64,38 @@ namespace Content.Client.State
_configurationManager.OnValueChanged(CCVars.OocEnabled, OnOocEnabledChanged, true);
_configurationManager.OnValueChanged(CCVars.AdminOocEnabled, OnAdminOocEnabledChanged, true);
_adminManager.AdminStatusUpdated += OnAdminStatusUpdated;
SetupPresenters();
}
public override void Shutdown()
{
DisposePresenters();
base.Shutdown();
_gameChat.Dispose();
_gameChat?.Dispose();
_gameHud.RootControl.Orphan();
}
/// <summary>
/// All UI Presenters should be constructed in here.
/// </summary>
private void SetupPresenters()
{
_constructionMenu = new ConstructionMenuPresenter(_gameHud);
}
/// <summary>
/// All UI Presenters should be disposed in here.
/// </summary>
private void DisposePresenters()
{
_constructionMenu?.Dispose();
}
private void OnOocEnabledChanged(bool val)
{
_oocEnabled = val;
@@ -80,6 +105,9 @@ namespace Content.Client.State
return;
}
if(_gameChat is null)
return;
_gameChat.Input.PlaceHolder = Loc.GetString(_oocEnabled ? "Say something! [ for OOC" : "Say something!");
}
@@ -92,11 +120,17 @@ namespace Content.Client.State
return;
}
if (_gameChat is null)
return;
_gameChat.Input.PlaceHolder = Loc.GetString(_adminOocEnabled ? "Say something! [ for OOC" : "Say something!");
}
private void OnAdminStatusUpdated()
{
if (_gameChat is null)
return;
_gameChat.Input.PlaceHolder = _adminManager.IsActive()
? Loc.GetString(_adminOocEnabled ? "Say something! [ for OOC" : "Say something!")
: Loc.GetString(_oocEnabled ? "Say something! [ for OOC" : "Say something!");