Skip to content

Commit

Permalink
feat: inhand crafting base
Browse files Browse the repository at this point in the history
  • Loading branch information
Remuchi committed Aug 24, 2024
1 parent a625d9e commit 3e5335a
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Content.Client/_White/InhandCrafting/UI/InhandCraftMenu.xaml
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>
73 changes: 73 additions & 0 deletions Content.Client/_White/InhandCrafting/UI/InhandCraftMenu.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using System.Numerics;
using Content.Client.Construction;
using Content.Client.UserInterface.Controls;
using Content.Shared._White.InhandCrafting;
using Content.Shared.Construction.Prototypes;
using Robust.Client.AutoGenerated;
using Robust.Client.GameObjects;
using Robust.Client.Placement;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Enums;
using Robust.Shared.Prototypes;

namespace Content.Client._White.InhandCrafting.UI;

[GenerateTypedNameReferences]
public sealed partial class InhandCraftMenu : RadialMenu
{
[Dependency] private readonly EntityManager _entManager = default!;
[Dependency] private readonly IPrototypeManager _protoManager = default!;
[Dependency] private readonly IPlacementManager _placementManager = default!;

private readonly ConstructionSystem _construction;

public InhandCraftMenu(EntityUid owner)
{
IoCManager.InjectDependencies(this);
RobustXamlLoader.Load(this);
_construction = _entManager.System<ConstructionSystem>();

if (!_entManager.TryGetComponent<InhandCraftingComponent>(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),
TextureNormal = spriteSystem.Frame0(proto.Icon),
StyleClasses = { "RadialMenuButton" },
SetSize = new Vector2(48f, 48f),
};

button.OnButtonUp += _ =>
{
BuildItem(proto);
Close();
};

main.AddChild(button);
}
}

private void BuildItem(ConstructionPrototype prototype)
{
if (prototype.Type == ConstructionType.Item)
{
_construction.TryStartItemConstruction(prototype.ID);
return;
}

_placementManager.BeginPlacing(new PlacementInformation
{
IsTile = false,
PlacementOption = prototype.PlacementMode
}, new ConstructionPlacementHijack(_construction, prototype));
}
}
33 changes: 33 additions & 0 deletions Content.Client/_White/InhandCrafting/UI/InhandCraftMenuBUI.cs
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.InhandCrafting.UI;

[UsedImplicitly]
public sealed class InhandCraftMenuBUI(EntityUid owner, Enum uiKey) : BoundUserInterface(owner, uiKey)
{
[Dependency] private readonly IClyde _displayManager = default!;
[Dependency] private readonly IInputManager _inputManager = default!;
private InhandCraftMenu? _menu;

protected override void Open()
{
_menu = new InhandCraftMenu(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();
}
}
1 change: 1 addition & 0 deletions Content.Shared/Content.Shared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<ProjectReference Include="..\RobustToolbox\Lidgren.Network\Lidgren.Network.csproj">
<Private>false</Private>
</ProjectReference>
<ProjectReference Include="..\RobustToolbox\Robust.Client\Robust.Client.csproj" />
<ProjectReference Include="..\RobustToolbox\Robust.Shared.Maths\Robust.Shared.Maths.csproj">
<Private>false</Private>
</ProjectReference>
Expand Down
13 changes: 13 additions & 0 deletions Content.Shared/_White/InhandCrafting/InhandCraftingComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Content.Shared.Construction.Prototypes;
using Robust.Client.Placement;
using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;

namespace Content.Shared._White.InhandCrafting;

[RegisterComponent, NetworkedComponent]
public sealed partial class InhandCraftingComponent : Component
{
[DataField(required: true)]
public List<ProtoId<ConstructionPrototype>> Prototypes;
}
9 changes: 9 additions & 0 deletions Content.Shared/_White/InhandCrafting/InhandCraftingUiKey.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Robust.Shared.Serialization;

namespace Content.Shared._White.InhandCrafting;

[NetSerializable, Serializable]
public enum InhandCraftingUiKey : byte
{
Key,
}
10 changes: 10 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,16 @@
Quantity: 9
- ReagentId: Carbon
Quantity: 1
- type: UserInterface # White Dream Start
interfaces:
- key: enum.InhandCraftingUiKey.Key
type: InhandCraftMenuBUI
- type: ActivatableUI
key: enum.InhandCraftingUiKey.Key
- type: InhandCrafting
prototypes:
- Girder
- TileDark # White Dream end

- type: entity
parent: SheetSteel
Expand Down

0 comments on commit 3e5335a

Please sign in to comment.