Skip to content

Commit 01c397f

Browse files
committed
[Feature] Short Construction System / Система Крафтов В Руках (Simple-Station#17)
* feat: inhand crafting base * fix: be gone * tweak: better naming, menu stays open on item crafting * feat: recipes
1 parent 442f2ea commit 01c397f

7 files changed

Lines changed: 192 additions & 0 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<ui:RadialMenu xmlns="https://spacestation14.io"
2+
xmlns:ui="clr-namespace:Content.Client.UserInterface.Controls"
3+
BackButtonStyleClass="RadialMenuBackButton"
4+
CloseButtonStyleClass="RadialMenuCloseButton"
5+
VerticalExpand="True"
6+
HorizontalExpand="True"
7+
MinSize="350 350">
8+
9+
<!-- Main container to hold all crafts-->
10+
<ui:RadialContainer Name="Main" VerticalExpand="True" HorizontalExpand="True" Radius="100"
11+
ReserveSpaceForHiddenChildren="False" />
12+
</ui:RadialMenu>
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
using System.Numerics;
2+
using Content.Client.Construction;
3+
using Content.Client.UserInterface.Controls;
4+
using Content.Shared._White.ShortConstruction;
5+
using Content.Shared.Construction.Prototypes;
6+
using Robust.Client.AutoGenerated;
7+
using Robust.Client.GameObjects;
8+
using Robust.Client.Placement;
9+
using Robust.Client.UserInterface.Controls;
10+
using Robust.Client.UserInterface.XAML;
11+
using Robust.Shared.Enums;
12+
using Robust.Shared.Prototypes;
13+
14+
namespace Content.Client._White.ShortConstruction.UI;
15+
16+
[GenerateTypedNameReferences]
17+
public sealed partial class ShortConstructionMenu : RadialMenu
18+
{
19+
[Dependency] private readonly EntityManager _entManager = default!;
20+
[Dependency] private readonly IPrototypeManager _protoManager = default!;
21+
[Dependency] private readonly IPlacementManager _placementManager = default!;
22+
23+
private readonly ConstructionSystem _construction;
24+
25+
public ShortConstructionMenu(EntityUid owner)
26+
{
27+
IoCManager.InjectDependencies(this);
28+
RobustXamlLoader.Load(this);
29+
_construction = _entManager.System<ConstructionSystem>();
30+
31+
if (!_entManager.TryGetComponent<ShortConstructionComponent>(owner, out var crafting))
32+
return;
33+
34+
var spriteSystem = _entManager.System<SpriteSystem>();
35+
var main = FindControl<RadialContainer>("Main");
36+
37+
foreach (var protoId in crafting.Prototypes)
38+
{
39+
if (!_protoManager.TryIndex(protoId, out var proto))
40+
continue;
41+
42+
var button = new RadialMenuTextureButton
43+
{
44+
ToolTip = Loc.GetString(proto.Name),
45+
StyleClasses = { "RadialMenuButton" },
46+
SetSize = new Vector2(48f, 48f),
47+
};
48+
49+
var texture = new TextureRect
50+
{
51+
VerticalAlignment = VAlignment.Center,
52+
HorizontalAlignment = HAlignment.Center,
53+
Texture = spriteSystem.Frame0(proto.Icon),
54+
TextureScale = new Vector2(1.5f, 1.5f),
55+
};
56+
57+
button.AddChild(texture);
58+
59+
button.OnButtonUp += _ =>
60+
{
61+
if (ConstructItem(proto))
62+
Close();
63+
};
64+
65+
main.AddChild(button);
66+
}
67+
}
68+
69+
/// <summary>
70+
/// Makes an item or places a schematic based on the type of construction recipe.
71+
/// </summary>
72+
/// <returns>Whatever the menu should be closed or not. By default crafting items does not close the window</returns>
73+
private bool ConstructItem(ConstructionPrototype prototype)
74+
{
75+
if (prototype.Type == ConstructionType.Item)
76+
{
77+
_construction.TryStartItemConstruction(prototype.ID);
78+
return false;
79+
}
80+
81+
_placementManager.BeginPlacing(new PlacementInformation
82+
{
83+
IsTile = false,
84+
PlacementOption = prototype.PlacementMode
85+
}, new ConstructionPlacementHijack(_construction, prototype));
86+
return true;
87+
}
88+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using JetBrains.Annotations;
2+
using Robust.Client.Graphics;
3+
using Robust.Client.Input;
4+
5+
// ReSharper disable InconsistentNaming
6+
7+
namespace Content.Client._White.ShortConstruction.UI;
8+
9+
[UsedImplicitly]
10+
public sealed class ShortConstructionMenuBUI(EntityUid owner, Enum uiKey) : BoundUserInterface(owner, uiKey)
11+
{
12+
[Dependency] private readonly IClyde _displayManager = default!;
13+
[Dependency] private readonly IInputManager _inputManager = default!;
14+
private ShortConstructionMenu? _menu;
15+
16+
protected override void Open()
17+
{
18+
_menu = new ShortConstructionMenu(Owner);
19+
_menu.OnClose += Close;
20+
21+
var vpSize = _displayManager.ScreenSize;
22+
_menu.OpenCenteredAt(_inputManager.MouseScreenPosition.Position / vpSize);
23+
}
24+
25+
protected override void Dispose(bool disposing)
26+
{
27+
base.Dispose(disposing);
28+
if (!disposing)
29+
return;
30+
31+
_menu?.Dispose();
32+
}
33+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using Content.Shared.Construction.Prototypes;
2+
using Robust.Shared.GameStates;
3+
using Robust.Shared.Prototypes;
4+
using Robust.Shared.Serialization;
5+
6+
namespace Content.Shared._White.ShortConstruction;
7+
8+
[RegisterComponent, NetworkedComponent]
9+
public sealed partial class ShortConstructionComponent : Component
10+
{
11+
[DataField(required: true)]
12+
public List<ProtoId<ConstructionPrototype>> Prototypes = new();
13+
}
14+
15+
[NetSerializable, Serializable]
16+
public enum ShortConstructionUiKey : byte
17+
{
18+
Key,
19+
}

‎Resources/Prototypes/Entities/Objects/Materials/Sheets/glass.yml‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,15 @@
9191
reagents:
9292
- ReagentId: Silicon
9393
Quantity: 10
94+
- type: UserInterface # White Dream Start
95+
interfaces:
96+
- key: enum.ShortConstructionUiKey.Key
97+
type: ShortConstructionMenuBUI
98+
- type: ActivatableUI
99+
key: enum.ShortConstructionUiKey.Key
100+
- type: ShortConstruction
101+
prototypes:
102+
- Window # White Dream end
94103

95104
- type: entity
96105
parent: SheetGlass
@@ -177,6 +186,15 @@
177186
max: 1
178187
- !type:DoActsBehavior
179188
acts: [ "Destruction" ]
189+
- type: UserInterface # White Dream Start
190+
interfaces:
191+
- key: enum.ShortConstructionUiKey.Key
192+
type: ShortConstructionMenuBUI
193+
- type: ActivatableUI
194+
key: enum.ShortConstructionUiKey.Key
195+
- type: ShortConstruction
196+
prototypes:
197+
- ReinforcedWindow # White Dream end
180198

181199
- type: entity
182200
parent: SheetRGlass

‎Resources/Prototypes/Entities/Objects/Materials/Sheets/metal.yml‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,19 @@
6969
Quantity: 9
7070
- ReagentId: Carbon
7171
Quantity: 1
72+
- type: UserInterface # White Dream Start
73+
interfaces:
74+
- key: enum.ShortConstructionUiKey.Key
75+
type: ShortConstructionMenuBUI
76+
- type: ActivatableUI
77+
key: enum.ShortConstructionUiKey.Key
78+
- type: ShortConstruction
79+
prototypes:
80+
- Girder
81+
- MetalRod
82+
- TileSteel
83+
- TileWhite
84+
- TileDark # White Dream end
7285

7386
- type: entity
7487
parent: SheetSteel

‎Resources/Prototypes/Entities/Objects/Materials/parts.yml‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,15 @@
6868
Quantity: 4.5
6969
- ReagentId: Carbon
7070
Quantity: 0.5
71+
- type: UserInterface # White Dream Start
72+
interfaces:
73+
- key: enum.ShortConstructionUiKey.Key
74+
type: ShortConstructionMenuBUI
75+
- type: ActivatableUI
76+
key: enum.ShortConstructionUiKey.Key
77+
- type: ShortConstruction
78+
prototypes:
79+
- Grille # White Dream end
7180

7281
- type: entity
7382
parent: PartRodMetal

0 commit comments

Comments
 (0)