Files
tbd-station-14/Content.Client/GameObjects/Components/Research/ResearchConsoleBoundUserInterface.cs
DrSmugleaf 902aa128c2 Enable nullability in Content.Client (#3257)
* Enable nullability in Content.Client

* Remove #nullable enable

* Merge fixes

* Remove Debug.Assert

* Merge fixes

* Fix build

* Fix build
2021-03-10 14:48:29 +01:00

85 lines
2.7 KiB
C#

using Content.Client.Research;
using Content.Shared.Research;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
using Robust.Shared.GameObjects;
using static Content.Shared.GameObjects.Components.Research.SharedResearchConsoleComponent;
namespace Content.Client.GameObjects.Components.Research
{
[UsedImplicitly]
public class ResearchConsoleBoundUserInterface : BoundUserInterface
{
public int Points { get; private set; }
public int PointsPerSecond { get; private set; }
private ResearchConsoleMenu? _consoleMenu;
private TechnologyDatabaseComponent? _technologyDatabase;
public ResearchConsoleBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey)
{
SendMessage(new ConsoleServerSyncMessage());
}
protected override void Open()
{
base.Open();
if (!Owner.Owner.TryGetComponent(out _technologyDatabase)) return;
_consoleMenu = new ResearchConsoleMenu(this);
_consoleMenu.OnClose += Close;
_consoleMenu.ServerSyncButton.OnPressed += (_) =>
{
SendMessage(new ConsoleServerSyncMessage());
};
_consoleMenu.ServerSelectionButton.OnPressed += (_) =>
{
SendMessage(new ConsoleServerSelectionMessage());
};
_consoleMenu.UnlockButton.OnPressed += (_) =>
{
if (_consoleMenu.TechnologySelected != null)
{
SendMessage(new ConsoleUnlockTechnologyMessage(_consoleMenu.TechnologySelected.ID));
}
};
_consoleMenu.OpenCentered();
_technologyDatabase.OnDatabaseUpdated += _consoleMenu.Populate;
}
public bool IsTechnologyUnlocked(TechnologyPrototype technology)
{
return _technologyDatabase?.IsTechnologyUnlocked(technology) ?? false;
}
public bool CanUnlockTechnology(TechnologyPrototype technology)
{
return _technologyDatabase?.CanUnlockTechnology(technology) ?? false;
}
protected override void UpdateState(BoundUserInterfaceState state)
{
base.UpdateState(state);
var castState = (ResearchConsoleBoundInterfaceState)state;
Points = castState.Points;
PointsPerSecond = castState.PointsPerSecond;
// We update the user interface here.
_consoleMenu?.PopulatePoints();
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (!disposing) return;
_consoleMenu?.Dispose();
}
}
}