2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Research.Prototypes;
|
2021-03-10 14:48:29 +01:00
|
|
|
using JetBrains.Annotations;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Client.GameObjects;
|
|
|
|
|
using Robust.Shared.GameObjects;
|
2021-12-03 14:17:01 +01:00
|
|
|
using Robust.Shared.IoC;
|
2021-06-09 22:19:39 +02:00
|
|
|
using static Content.Shared.Research.Components.SharedResearchConsoleComponent;
|
2019-09-03 22:51:19 +02:00
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Client.Research.UI
|
2019-09-03 22:51:19 +02:00
|
|
|
{
|
2021-03-10 14:48:29 +01:00
|
|
|
[UsedImplicitly]
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class ResearchConsoleBoundUserInterface : BoundUserInterface
|
2019-09-03 22:51:19 +02:00
|
|
|
{
|
2021-03-10 14:48:29 +01:00
|
|
|
public int Points { get; private set; }
|
|
|
|
|
public int PointsPerSecond { get; private set; }
|
|
|
|
|
private ResearchConsoleMenu? _consoleMenu;
|
|
|
|
|
private TechnologyDatabaseComponent? _technologyDatabase;
|
2019-09-03 22:51:19 +02:00
|
|
|
|
|
|
|
|
public ResearchConsoleBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey)
|
|
|
|
|
{
|
2021-03-10 14:48:29 +01:00
|
|
|
SendMessage(new ConsoleServerSyncMessage());
|
2019-09-03 22:51:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Open()
|
|
|
|
|
{
|
|
|
|
|
base.Open();
|
|
|
|
|
|
2021-12-03 15:53:09 +01:00
|
|
|
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner.Owner, out _technologyDatabase)) return;
|
2019-09-03 22:51:19 +02:00
|
|
|
|
|
|
|
|
_consoleMenu = new ResearchConsoleMenu(this);
|
|
|
|
|
|
2019-09-06 08:13:17 +02:00
|
|
|
_consoleMenu.OnClose += Close;
|
|
|
|
|
|
2021-03-10 14:48:29 +01:00
|
|
|
_consoleMenu.ServerSyncButton.OnPressed += (_) =>
|
|
|
|
|
{
|
|
|
|
|
SendMessage(new ConsoleServerSyncMessage());
|
|
|
|
|
};
|
2019-09-03 22:51:19 +02:00
|
|
|
|
2021-03-10 14:48:29 +01:00
|
|
|
_consoleMenu.ServerSelectionButton.OnPressed += (_) =>
|
2019-09-03 22:51:19 +02:00
|
|
|
{
|
2021-03-10 14:48:29 +01:00
|
|
|
SendMessage(new ConsoleServerSelectionMessage());
|
2019-09-03 22:51:19 +02:00
|
|
|
};
|
|
|
|
|
|
2021-03-10 14:48:29 +01:00
|
|
|
_consoleMenu.UnlockButton.OnPressed += (_) =>
|
2019-09-03 22:51:19 +02:00
|
|
|
{
|
2021-03-10 14:48:29 +01:00
|
|
|
if (_consoleMenu.TechnologySelected != null)
|
|
|
|
|
{
|
|
|
|
|
SendMessage(new ConsoleUnlockTechnologyMessage(_consoleMenu.TechnologySelected.ID));
|
|
|
|
|
}
|
2019-09-03 22:51:19 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
_consoleMenu.OpenCentered();
|
|
|
|
|
|
2021-03-10 14:48:29 +01:00
|
|
|
_technologyDatabase.OnDatabaseUpdated += _consoleMenu.Populate;
|
2019-09-03 22:51:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsTechnologyUnlocked(TechnologyPrototype technology)
|
|
|
|
|
{
|
2021-03-10 14:48:29 +01:00
|
|
|
return _technologyDatabase?.IsTechnologyUnlocked(technology) ?? false;
|
2019-09-03 22:51:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool CanUnlockTechnology(TechnologyPrototype technology)
|
|
|
|
|
{
|
2021-03-10 14:48:29 +01:00
|
|
|
return _technologyDatabase?.CanUnlockTechnology(technology) ?? false;
|
2019-09-03 22:51:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void UpdateState(BoundUserInterfaceState state)
|
|
|
|
|
{
|
|
|
|
|
base.UpdateState(state);
|
|
|
|
|
|
2021-03-10 14:48:29 +01:00
|
|
|
var castState = (ResearchConsoleBoundInterfaceState)state;
|
2019-09-03 22:51:19 +02:00
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|