From 01c397f0688c007078ec55afdcc943157cb0d02c Mon Sep 17 00:00:00 2001
From: Remuchi <72476615+Remuchi@users.noreply.github.com>
Date: Tue, 3 Sep 2024 12:39:50 +0700
Subject: [PATCH] =?UTF-8?q?[Feature]=20Short=20Construction=20System=20/?=
=?UTF-8?q?=20=D0=A1=D0=B8=D1=81=D1=82=D0=B5=D0=BC=D0=B0=20=D0=9A=D1=80?=
=?UTF-8?q?=D0=B0=D1=84=D1=82=D0=BE=D0=B2=20=D0=92=20=D0=A0=D1=83=D0=BA?=
=?UTF-8?q?=D0=B0=D1=85=20(#17)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* feat: inhand crafting base
* fix: be gone
* tweak: better naming, menu stays open on item crafting
* feat: recipes
---
.../UI/ShortConstructionMenu.xaml | 12 +++
.../UI/ShortConstructionMenu.xaml.cs | 88 +++++++++++++++++++
.../UI/ShortConstructionMenuBUI.cs | 33 +++++++
.../ShortConstructionComponent.cs | 19 ++++
.../Objects/Materials/Sheets/glass.yml | 18 ++++
.../Objects/Materials/Sheets/metal.yml | 13 +++
.../Entities/Objects/Materials/parts.yml | 9 ++
7 files changed, 192 insertions(+)
create mode 100644 Content.Client/_White/ShortConstruction/UI/ShortConstructionMenu.xaml
create mode 100644 Content.Client/_White/ShortConstruction/UI/ShortConstructionMenu.xaml.cs
create mode 100644 Content.Client/_White/ShortConstruction/UI/ShortConstructionMenuBUI.cs
create mode 100644 Content.Shared/_White/ShortConstruction/ShortConstructionComponent.cs
diff --git a/Content.Client/_White/ShortConstruction/UI/ShortConstructionMenu.xaml b/Content.Client/_White/ShortConstruction/UI/ShortConstructionMenu.xaml
new file mode 100644
index 00000000000..ccf3c3fe558
--- /dev/null
+++ b/Content.Client/_White/ShortConstruction/UI/ShortConstructionMenu.xaml
@@ -0,0 +1,12 @@
+
+
+
+
+
diff --git a/Content.Client/_White/ShortConstruction/UI/ShortConstructionMenu.xaml.cs b/Content.Client/_White/ShortConstruction/UI/ShortConstructionMenu.xaml.cs
new file mode 100644
index 00000000000..6142a5b3a59
--- /dev/null
+++ b/Content.Client/_White/ShortConstruction/UI/ShortConstructionMenu.xaml.cs
@@ -0,0 +1,88 @@
+using System.Numerics;
+using Content.Client.Construction;
+using Content.Client.UserInterface.Controls;
+using Content.Shared._White.ShortConstruction;
+using Content.Shared.Construction.Prototypes;
+using Robust.Client.AutoGenerated;
+using Robust.Client.GameObjects;
+using Robust.Client.Placement;
+using Robust.Client.UserInterface.Controls;
+using Robust.Client.UserInterface.XAML;
+using Robust.Shared.Enums;
+using Robust.Shared.Prototypes;
+
+namespace Content.Client._White.ShortConstruction.UI;
+
+[GenerateTypedNameReferences]
+public sealed partial class ShortConstructionMenu : RadialMenu
+{
+ [Dependency] private readonly EntityManager _entManager = default!;
+ [Dependency] private readonly IPrototypeManager _protoManager = default!;
+ [Dependency] private readonly IPlacementManager _placementManager = default!;
+
+ private readonly ConstructionSystem _construction;
+
+ public ShortConstructionMenu(EntityUid owner)
+ {
+ IoCManager.InjectDependencies(this);
+ RobustXamlLoader.Load(this);
+ _construction = _entManager.System();
+
+ if (!_entManager.TryGetComponent(owner, out var crafting))
+ return;
+
+ var spriteSystem = _entManager.System();
+ var main = FindControl("Main");
+
+ foreach (var protoId in crafting.Prototypes)
+ {
+ if (!_protoManager.TryIndex(protoId, out var proto))
+ continue;
+
+ var button = new RadialMenuTextureButton
+ {
+ ToolTip = Loc.GetString(proto.Name),
+ StyleClasses = { "RadialMenuButton" },
+ SetSize = new Vector2(48f, 48f),
+ };
+
+ var texture = new TextureRect
+ {
+ VerticalAlignment = VAlignment.Center,
+ HorizontalAlignment = HAlignment.Center,
+ Texture = spriteSystem.Frame0(proto.Icon),
+ TextureScale = new Vector2(1.5f, 1.5f),
+ };
+
+ button.AddChild(texture);
+
+ button.OnButtonUp += _ =>
+ {
+ if (ConstructItem(proto))
+ Close();
+ };
+
+ main.AddChild(button);
+ }
+ }
+
+ ///
+ /// Makes an item or places a schematic based on the type of construction recipe.
+ ///
+ /// Whatever the menu should be closed or not. By default crafting items does not close the window
+ private bool ConstructItem(ConstructionPrototype prototype)
+ {
+ if (prototype.Type == ConstructionType.Item)
+ {
+ _construction.TryStartItemConstruction(prototype.ID);
+ return false;
+ }
+
+ _placementManager.BeginPlacing(new PlacementInformation
+ {
+ IsTile = false,
+ PlacementOption = prototype.PlacementMode
+ }, new ConstructionPlacementHijack(_construction, prototype));
+ return true;
+ }
+}
diff --git a/Content.Client/_White/ShortConstruction/UI/ShortConstructionMenuBUI.cs b/Content.Client/_White/ShortConstruction/UI/ShortConstructionMenuBUI.cs
new file mode 100644
index 00000000000..af19c1088f4
--- /dev/null
+++ b/Content.Client/_White/ShortConstruction/UI/ShortConstructionMenuBUI.cs
@@ -0,0 +1,33 @@
+using JetBrains.Annotations;
+using Robust.Client.Graphics;
+using Robust.Client.Input;
+
+// ReSharper disable InconsistentNaming
+
+namespace Content.Client._White.ShortConstruction.UI;
+
+[UsedImplicitly]
+public sealed class ShortConstructionMenuBUI(EntityUid owner, Enum uiKey) : BoundUserInterface(owner, uiKey)
+{
+ [Dependency] private readonly IClyde _displayManager = default!;
+ [Dependency] private readonly IInputManager _inputManager = default!;
+ private ShortConstructionMenu? _menu;
+
+ protected override void Open()
+ {
+ _menu = new ShortConstructionMenu(Owner);
+ _menu.OnClose += Close;
+
+ var vpSize = _displayManager.ScreenSize;
+ _menu.OpenCenteredAt(_inputManager.MouseScreenPosition.Position / vpSize);
+ }
+
+ protected override void Dispose(bool disposing)
+ {
+ base.Dispose(disposing);
+ if (!disposing)
+ return;
+
+ _menu?.Dispose();
+ }
+}
diff --git a/Content.Shared/_White/ShortConstruction/ShortConstructionComponent.cs b/Content.Shared/_White/ShortConstruction/ShortConstructionComponent.cs
new file mode 100644
index 00000000000..cdfa90b0010
--- /dev/null
+++ b/Content.Shared/_White/ShortConstruction/ShortConstructionComponent.cs
@@ -0,0 +1,19 @@
+using Content.Shared.Construction.Prototypes;
+using Robust.Shared.GameStates;
+using Robust.Shared.Prototypes;
+using Robust.Shared.Serialization;
+
+namespace Content.Shared._White.ShortConstruction;
+
+[RegisterComponent, NetworkedComponent]
+public sealed partial class ShortConstructionComponent : Component
+{
+ [DataField(required: true)]
+ public List> Prototypes = new();
+}
+
+[NetSerializable, Serializable]
+public enum ShortConstructionUiKey : byte
+{
+ Key,
+}
diff --git a/Resources/Prototypes/Entities/Objects/Materials/Sheets/glass.yml b/Resources/Prototypes/Entities/Objects/Materials/Sheets/glass.yml
index 0a957eeb7aa..cccbb7cf6f1 100644
--- a/Resources/Prototypes/Entities/Objects/Materials/Sheets/glass.yml
+++ b/Resources/Prototypes/Entities/Objects/Materials/Sheets/glass.yml
@@ -91,6 +91,15 @@
reagents:
- ReagentId: Silicon
Quantity: 10
+ - type: UserInterface # White Dream Start
+ interfaces:
+ - key: enum.ShortConstructionUiKey.Key
+ type: ShortConstructionMenuBUI
+ - type: ActivatableUI
+ key: enum.ShortConstructionUiKey.Key
+ - type: ShortConstruction
+ prototypes:
+ - Window # White Dream end
- type: entity
parent: SheetGlass
@@ -177,6 +186,15 @@
max: 1
- !type:DoActsBehavior
acts: [ "Destruction" ]
+ - type: UserInterface # White Dream Start
+ interfaces:
+ - key: enum.ShortConstructionUiKey.Key
+ type: ShortConstructionMenuBUI
+ - type: ActivatableUI
+ key: enum.ShortConstructionUiKey.Key
+ - type: ShortConstruction
+ prototypes:
+ - ReinforcedWindow # White Dream end
- type: entity
parent: SheetRGlass
diff --git a/Resources/Prototypes/Entities/Objects/Materials/Sheets/metal.yml b/Resources/Prototypes/Entities/Objects/Materials/Sheets/metal.yml
index 82b9f62837a..92d379bd72a 100644
--- a/Resources/Prototypes/Entities/Objects/Materials/Sheets/metal.yml
+++ b/Resources/Prototypes/Entities/Objects/Materials/Sheets/metal.yml
@@ -69,6 +69,19 @@
Quantity: 9
- ReagentId: Carbon
Quantity: 1
+ - type: UserInterface # White Dream Start
+ interfaces:
+ - key: enum.ShortConstructionUiKey.Key
+ type: ShortConstructionMenuBUI
+ - type: ActivatableUI
+ key: enum.ShortConstructionUiKey.Key
+ - type: ShortConstruction
+ prototypes:
+ - Girder
+ - MetalRod
+ - TileSteel
+ - TileWhite
+ - TileDark # White Dream end
- type: entity
parent: SheetSteel
diff --git a/Resources/Prototypes/Entities/Objects/Materials/parts.yml b/Resources/Prototypes/Entities/Objects/Materials/parts.yml
index 71adedab0ed..ee506c75722 100644
--- a/Resources/Prototypes/Entities/Objects/Materials/parts.yml
+++ b/Resources/Prototypes/Entities/Objects/Materials/parts.yml
@@ -68,6 +68,15 @@
Quantity: 4.5
- ReagentId: Carbon
Quantity: 0.5
+ - type: UserInterface # White Dream Start
+ interfaces:
+ - key: enum.ShortConstructionUiKey.Key
+ type: ShortConstructionMenuBUI
+ - type: ActivatableUI
+ key: enum.ShortConstructionUiKey.Key
+ - type: ShortConstruction
+ prototypes:
+ - Grille # White Dream end
- type: entity
parent: PartRodMetal