From 1b0bf2ad18112f1c611411092c9977ee6c668925 Mon Sep 17 00:00:00 2001 From: Tornado Tech <54727692+Tornado-Technology@users.noreply.github.com> Date: Tue, 6 Aug 2024 21:25:59 +1000 Subject: [PATCH] Added base workbench window (#372) * Added base workbench window * Fixed serialization errors * Created base UI layout * Updated ui * Updated UI after crafting --- .../CP14WorkbenchBoundUserInterface.cs | 34 +++++++ .../Workbench/CP14WorkbenchRecipeControl.xaml | 10 ++ .../CP14WorkbenchRecipeControl.xaml.cs | 45 +++++++++ .../CP14WorkbenchRequirementControl.xaml | 12 +++ .../CP14WorkbenchRequirementControl.xaml.cs | 59 ++++++++++++ .../_CP14/Workbench/CP14WorkbenchWindow.xaml | 60 ++++++++++++ .../Workbench/CP14WorkbenchWindow.xaml.cs | 92 +++++++++++++++++++ .../_CP14/Workbench/CP14WorkbenchSystem.UI.cs | 33 +++++++ .../_CP14/Workbench/CP14WorkbenchSystem.cs | 37 ++++++-- .../_CP14/Workbench/CP14WorkbenchUI.cs | 63 +++++++++++++ .../CP14WorkbenchRecipePrototype.cs | 8 +- .../Structures/Furniture/workbenchs.yml | 10 +- 12 files changed, 446 insertions(+), 17 deletions(-) create mode 100644 Content.Client/_CP14/Workbench/CP14WorkbenchBoundUserInterface.cs create mode 100644 Content.Client/_CP14/Workbench/CP14WorkbenchRecipeControl.xaml create mode 100644 Content.Client/_CP14/Workbench/CP14WorkbenchRecipeControl.xaml.cs create mode 100644 Content.Client/_CP14/Workbench/CP14WorkbenchRequirementControl.xaml create mode 100644 Content.Client/_CP14/Workbench/CP14WorkbenchRequirementControl.xaml.cs create mode 100644 Content.Client/_CP14/Workbench/CP14WorkbenchWindow.xaml create mode 100644 Content.Client/_CP14/Workbench/CP14WorkbenchWindow.xaml.cs create mode 100644 Content.Server/_CP14/Workbench/CP14WorkbenchSystem.UI.cs create mode 100644 Content.Shared/_CP14/Workbench/CP14WorkbenchUI.cs diff --git a/Content.Client/_CP14/Workbench/CP14WorkbenchBoundUserInterface.cs b/Content.Client/_CP14/Workbench/CP14WorkbenchBoundUserInterface.cs new file mode 100644 index 0000000000..1e17cbaa1a --- /dev/null +++ b/Content.Client/_CP14/Workbench/CP14WorkbenchBoundUserInterface.cs @@ -0,0 +1,34 @@ +using Content.Shared._CP14.Workbench; +using Robust.Client.UserInterface; + +namespace Content.Client._CP14.Workbench; + +public sealed class CP14WorkbenchBoundUserInterface : BoundUserInterface +{ + private CP14WorkbenchWindow? _window; + + public CP14WorkbenchBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) + { + } + + protected override void Open() + { + base.Open(); + + _window = this.CreateWindow(); + + _window.OnCraft += entry => SendMessage(new CP14WorkbenchUiCraftMessage(entry.ProtoId)); + } + + protected override void UpdateState(BoundUserInterfaceState state) + { + base.UpdateState(state); + + switch (state) + { + case CP14WorkbenchUiRecipesState recipesState: + _window?.UpdateRecipes(recipesState); + break; + } + } +} diff --git a/Content.Client/_CP14/Workbench/CP14WorkbenchRecipeControl.xaml b/Content.Client/_CP14/Workbench/CP14WorkbenchRecipeControl.xaml new file mode 100644 index 0000000000..fab7715ae6 --- /dev/null +++ b/Content.Client/_CP14/Workbench/CP14WorkbenchRecipeControl.xaml @@ -0,0 +1,10 @@ + + + + + diff --git a/Content.Client/_CP14/Workbench/CP14WorkbenchRecipeControl.xaml.cs b/Content.Client/_CP14/Workbench/CP14WorkbenchRecipeControl.xaml.cs new file mode 100644 index 0000000000..0cbcc35c78 --- /dev/null +++ b/Content.Client/_CP14/Workbench/CP14WorkbenchRecipeControl.xaml.cs @@ -0,0 +1,45 @@ +using Content.Shared._CP14.Workbench; +using Content.Shared._CP14.Workbench.Prototypes; +using Content.Shared.Stacks; +using Robust.Client.AutoGenerated; +using Robust.Client.GameObjects; +using Robust.Client.UserInterface; +using Robust.Client.UserInterface.XAML; +using Robust.Shared.Prototypes; + +namespace Content.Client._CP14.Workbench; + +[GenerateTypedNameReferences] +public sealed partial class CP14WorkbenchRecipeControl : Control +{ + [Dependency] private readonly IEntityManager _entity = default!; + + private readonly SpriteSystem _sprite; + + public CP14WorkbenchRecipeControl() + { + RobustXamlLoader.Load(this); + IoCManager.InjectDependencies(this); + + _sprite = _entity.System(); + } + + public CP14WorkbenchRecipeControl(EntityPrototype prototype, int count) : this() + { + var entityName = Loc.GetString(prototype.Name); + Name.Text = count <= 1 ? entityName : $"{entityName} x{count}"; + View.Texture = _sprite.GetPrototypeIcon(prototype).Default; + } + + public CP14WorkbenchRecipeControl(StackPrototype prototype, int count) : this() + { + var entityName = Loc.GetString(prototype.Name); + Name.Text = count <= 1 ? entityName : $"{entityName} x{count}"; + + var icon = prototype.Icon; + if (icon is null) + return; + + View.Texture = _sprite.Frame0(icon); + } +} diff --git a/Content.Client/_CP14/Workbench/CP14WorkbenchRequirementControl.xaml b/Content.Client/_CP14/Workbench/CP14WorkbenchRequirementControl.xaml new file mode 100644 index 0000000000..3efee3eace --- /dev/null +++ b/Content.Client/_CP14/Workbench/CP14WorkbenchRequirementControl.xaml @@ -0,0 +1,12 @@ + + + diff --git a/Content.Client/_CP14/Workbench/CP14WorkbenchRequirementControl.xaml.cs b/Content.Client/_CP14/Workbench/CP14WorkbenchRequirementControl.xaml.cs new file mode 100644 index 0000000000..b89a61afc3 --- /dev/null +++ b/Content.Client/_CP14/Workbench/CP14WorkbenchRequirementControl.xaml.cs @@ -0,0 +1,59 @@ +using Content.Shared._CP14.Workbench; +using Content.Shared._CP14.Workbench.Prototypes; +using Robust.Client.AutoGenerated; +using Robust.Client.GameObjects; +using Robust.Client.UserInterface; +using Robust.Client.UserInterface.XAML; +using Robust.Shared.Prototypes; + +namespace Content.Client._CP14.Workbench; + +[GenerateTypedNameReferences] +public sealed partial class CP14WorkbenchRequirementControl : Control +{ + [Dependency] private readonly IEntityManager _entity = default!; + [Dependency] private readonly IPrototypeManager _prototype = default!; + + public event Action? OnSelect; + + private readonly SpriteSystem _sprite; + + private readonly CP14WorkbenchRecipePrototype _recipePrototype; + private readonly bool _craftable; + + public CP14WorkbenchRequirementControl(CP14WorkbenchUiRecipesEntry entry) + { + RobustXamlLoader.Load(this); + IoCManager.InjectDependencies(this); + + _sprite = _entity.System(); + + _recipePrototype = _prototype.Index(entry.ProtoId); + _craftable = entry.Craftable; + + Button.OnPressed += _ => OnSelect?.Invoke(entry, _recipePrototype); + + UpdateColor(); + UpdateName(); + UpdateView(); + } + + private void UpdateColor() + { + if (_craftable) + return; + + Button.ModulateSelfOverride = Color.FromHex("#302622"); + } + + private void UpdateName() + { + var result = _prototype.Index(_recipePrototype.Result); + Name.Text = Loc.GetString(result.Name); + } + + private void UpdateView() + { + View.Texture = _sprite.GetPrototypeIcon(_recipePrototype.Result).Default; + } +} diff --git a/Content.Client/_CP14/Workbench/CP14WorkbenchWindow.xaml b/Content.Client/_CP14/Workbench/CP14WorkbenchWindow.xaml new file mode 100644 index 0000000000..76f7bcde4b --- /dev/null +++ b/Content.Client/_CP14/Workbench/CP14WorkbenchWindow.xaml @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +