Skip to content

Commit

Permalink
[Feature] Short Construction System / Система Крафтов В Руках (Simple…
Browse files Browse the repository at this point in the history
…-Station#17)

* feat: inhand crafting base

* fix: be gone

* tweak: better naming, menu stays open on item crafting

* feat: recipes
  • Loading branch information
Remuchi committed Sep 5, 2024
1 parent 442f2ea commit 01c397f
Show file tree
Hide file tree
Showing 7 changed files with 192 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<ui:RadialMenu xmlns="https://spacestation14.io"
xmlns:ui="clr-namespace:Content.Client.UserInterface.Controls"
BackButtonStyleClass="RadialMenuBackButton"
CloseButtonStyleClass="RadialMenuCloseButton"
VerticalExpand="True"
HorizontalExpand="True"
MinSize="350 350">

<!-- Main container to hold all crafts-->
<ui:RadialContainer Name="Main" VerticalExpand="True" HorizontalExpand="True" Radius="100"
ReserveSpaceForHiddenChildren="False" />
</ui:RadialMenu>
Original file line number Diff line number Diff line change
@@ -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<ConstructionSystem>();

if (!_entManager.TryGetComponent<ShortConstructionComponent>(owner, out var crafting))
return;

var spriteSystem = _entManager.System<SpriteSystem>();
var main = FindControl<RadialContainer>("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);
}
}

/// <summary>
/// Makes an item or places a schematic based on the type of construction recipe.
/// </summary>
/// <returns>Whatever the menu should be closed or not. By default crafting items does not close the window</returns>
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;
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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<ProtoId<ConstructionPrototype>> Prototypes = new();
}

[NetSerializable, Serializable]
public enum ShortConstructionUiKey : byte
{
Key,
}
18 changes: 18 additions & 0 deletions Resources/Prototypes/Entities/Objects/Materials/Sheets/glass.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions Resources/Prototypes/Entities/Objects/Materials/Sheets/metal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions Resources/Prototypes/Entities/Objects/Materials/parts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 01c397f

Please sign in to comment.