Technology Disks (#13077)

* clean up a bunch of R&D code

* don't store components

* brug

* speedrun some sloth review

* technology disks

* expand functionality, begin work on printer

* disk printer ui

* file

* fix the rebase

* disk console is finito

* Update DiskConsoleSystem.cs
This commit is contained in:
Nemanja
2022-12-20 17:39:57 -05:00
committed by GitHub
parent 88ed188b42
commit 050e157005
34 changed files with 659 additions and 151 deletions

View File

@@ -0,0 +1,8 @@
using Content.Shared.Research.Systems;
namespace Content.Client.Research;
public sealed class ResearchSystem : SharedResearchSystem
{
}

View File

@@ -1,34 +0,0 @@
using Content.Shared.Research.Components;
using Content.Shared.Research.Prototypes;
using Robust.Shared.Prototypes;
namespace Content.Client.Research
{
[RegisterComponent]
public sealed class TechnologyDatabaseComponent : SharedTechnologyDatabaseComponent
{
/// <summary>
/// Event called when the database is updated.
/// </summary>
public event Action? OnDatabaseUpdated;
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
{
base.HandleComponentState(curState, nextState);
if (curState is not TechnologyDatabaseState state) return;
TechnologyIds.Clear();
var protoManager = IoCManager.Resolve<IPrototypeManager>();
foreach (var techID in state.Technologies)
{
if (!protoManager.HasIndex<TechnologyPrototype>(techID)) continue;
TechnologyIds.Add(techID);
}
OnDatabaseUpdated?.Invoke();
}
}
}

View File

@@ -0,0 +1,53 @@
using Content.Shared.Lathe;
using Content.Shared.Research;
using Robust.Client.GameObjects;
namespace Content.Client.Research.UI
{
public sealed class DiskConsoleBoundUserInterface : BoundUserInterface
{
private DiskConsoleMenu? _menu;
public DiskConsoleBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey)
{
}
protected override void Open()
{
base.Open();
_menu = new();
_menu.OnClose += Close;
_menu.OpenCentered();
_menu.OnServerButtonPressed += () =>
{
SendMessage(new LatheServerSelectionMessage());
};
_menu.OnPrintButtonPressed += () =>
{
SendMessage(new DiskConsolePrintDiskMessage());
};
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (!disposing)
return;
_menu?.Close();
}
protected override void UpdateState(BoundUserInterfaceState state)
{
base.UpdateState(state);
if (state is not DiskConsoleBoundUserInterfaceState msg)
return;
_menu?.Update(msg);
}
}
}

View File

@@ -0,0 +1,36 @@
<controls:FancyWindow xmlns="https://spacestation14.io"
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
xmlns:graphics="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client"
Title="{Loc 'tech-disk-ui-name'}"
MinSize="400 260"
SetSize="400 260">
<BoxContainer Orientation="Vertical"
HorizontalExpand="True"
VerticalExpand="True"
Margin="10 10 10 10">
<Button Name="ServerButton"
Text="{Loc 'lathe-menu-server-list'}"
HorizontalAlignment="Left"></Button>
<PanelContainer Margin="0 10 0 0" VerticalExpand="True">
<PanelContainer.PanelOverride>
<graphics:StyleBoxFlat BackgroundColor="#000000FF"/>
</PanelContainer.PanelOverride>
<BoxContainer Orientation="Vertical" VerticalExpand="True" HorizontalExpand="True" VerticalAlignment="Center">
<Label Name="TotalLabel"
HorizontalAlignment="Center">
</Label>
<Label Name="CostLabel"
HorizontalAlignment="Center">
</Label>
<BoxContainer MinHeight="20"></BoxContainer>
<Button
Name="PrintButton"
Text="{Loc 'tech-disk-ui-print-button'}"
MaxWidth="120"
HorizontalAlignment="Center"
VerticalExpand="False">
</Button>
</BoxContainer>
</PanelContainer>
</BoxContainer>
</controls:FancyWindow>

View File

@@ -0,0 +1,29 @@
using Content.Client.UserInterface.Controls;
using Content.Shared.Research;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.XAML;
namespace Content.Client.Research.UI;
[GenerateTypedNameReferences]
public sealed partial class DiskConsoleMenu : FancyWindow
{
public event Action? OnServerButtonPressed;
public event Action? OnPrintButtonPressed;
public DiskConsoleMenu()
{
RobustXamlLoader.Load(this);
ServerButton.OnPressed += _ => OnServerButtonPressed?.Invoke();
PrintButton.OnPressed += _ => OnPrintButtonPressed?.Invoke();
}
public void Update(DiskConsoleBoundUserInterfaceState state)
{
PrintButton.Disabled = !state.CanPrint;
TotalLabel.Text = Loc.GetString("tech-disk-ui-total-label", ("amount", state.ServerPoints));
CostLabel.Text = Loc.GetString("tech-disk-ui-cost-label", ("amount", state.PointCost));
}
}

View File

@@ -1,5 +1,6 @@
using Content.Shared.Research.Components;
using Content.Shared.Research.Prototypes;
using Content.Shared.Research.Systems;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
@@ -12,17 +13,22 @@ namespace Content.Client.Research.UI
public int PointsPerSecond { get; private set; }
private ResearchConsoleMenu? _consoleMenu;
private TechnologyDatabaseComponent? _technologyDatabase;
private readonly IEntityManager _entityManager;
private readonly SharedResearchSystem _research;
public ResearchConsoleBoundUserInterface(ClientUserInterfaceComponent owner, Enum uiKey) : base(owner, uiKey)
{
SendMessage(new ConsoleServerSyncMessage());
_entityManager = IoCManager.Resolve<IEntityManager>();
_research = _entityManager.System<SharedResearchSystem>();
}
protected override void Open()
{
base.Open();
if (!IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner.Owner, out _technologyDatabase)) return;
if (!_entityManager.TryGetComponent(Owner.Owner, out _technologyDatabase))
return;
_consoleMenu = new ResearchConsoleMenu(this);
@@ -47,18 +53,22 @@ namespace Content.Client.Research.UI
};
_consoleMenu.OpenCentered();
_technologyDatabase.OnDatabaseUpdated += _consoleMenu.Populate;
}
public bool IsTechnologyUnlocked(TechnologyPrototype technology)
{
return _technologyDatabase?.IsTechnologyUnlocked(technology.ID) ?? false;
if (_technologyDatabase == null)
return false;
return _research.IsTechnologyUnlocked(_technologyDatabase.Owner, technology, _technologyDatabase);
}
public bool CanUnlockTechnology(TechnologyPrototype technology)
{
return _technologyDatabase?.CanUnlockTechnology(technology) ?? false;
if (_technologyDatabase == null)
return false;
return _research.CanUnlockTechnology(_technologyDatabase.Owner, technology, _technologyDatabase);
}
protected override void UpdateState(BoundUserInterfaceState state)
@@ -70,12 +80,14 @@ namespace Content.Client.Research.UI
PointsPerSecond = castState.PointsPerSecond;
// We update the user interface here.
_consoleMenu?.PopulatePoints();
_consoleMenu?.Populate();
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (!disposing) return;
if (!disposing)
return;
_consoleMenu?.Dispose();
}
}