2022-06-28 22:54:08 +10:00
|
|
|
using Content.Shared.Research.Components;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Research.Prototypes;
|
2022-12-20 17:39:57 -05:00
|
|
|
using Content.Shared.Research.Systems;
|
2021-03-10 14:48:29 +01:00
|
|
|
using JetBrains.Annotations;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Client.GameObjects;
|
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;
|
2022-12-20 17:39:57 -05:00
|
|
|
private readonly IEntityManager _entityManager;
|
|
|
|
|
private readonly SharedResearchSystem _research;
|
2019-09-03 22:51:19 +02:00
|
|
|
|
2022-08-21 05:38:30 +12:00
|
|
|
public ResearchConsoleBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey)
|
2019-09-03 22:51:19 +02:00
|
|
|
{
|
2021-03-10 14:48:29 +01:00
|
|
|
SendMessage(new ConsoleServerSyncMessage());
|
2022-12-20 17:39:57 -05:00
|
|
|
_entityManager = IoCManager.Resolve<IEntityManager>();
|
|
|
|
|
_research = _entityManager.System<SharedResearchSystem>();
|
2019-09-03 22:51:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Open()
|
|
|
|
|
{
|
|
|
|
|
base.Open();
|
|
|
|
|
|
2022-12-20 17:39:57 -05:00
|
|
|
if (!_entityManager.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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsTechnologyUnlocked(TechnologyPrototype technology)
|
|
|
|
|
{
|
2022-12-20 17:39:57 -05:00
|
|
|
if (_technologyDatabase == null)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return _research.IsTechnologyUnlocked(_technologyDatabase.Owner, technology, _technologyDatabase);
|
2019-09-03 22:51:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool CanUnlockTechnology(TechnologyPrototype technology)
|
|
|
|
|
{
|
2022-12-20 17:39:57 -05:00
|
|
|
if (_technologyDatabase == null)
|
|
|
|
|
return false;
|
|
|
|
|
|
2022-12-25 16:22:23 -05:00
|
|
|
return _research.ArePrerequesitesUnlocked(_technologyDatabase.Owner, technology, _technologyDatabase);
|
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();
|
2022-12-20 17:39:57 -05:00
|
|
|
_consoleMenu?.Populate();
|
2019-09-03 22:51:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Dispose(bool disposing)
|
|
|
|
|
{
|
|
|
|
|
base.Dispose(disposing);
|
2022-12-20 17:39:57 -05:00
|
|
|
if (!disposing)
|
|
|
|
|
return;
|
2019-09-03 22:51:19 +02:00
|
|
|
_consoleMenu?.Dispose();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|