Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More Quick Construction Recipes And Upgrades #945

Merged
merged 8 commits into from
Sep 24, 2024
97 changes: 55 additions & 42 deletions Content.Client/ShortConstruction/UI/ShortConstructionMenuBUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Robust.Client.UserInterface.Controls;
using Robust.Shared.Enums;
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;

// ReSharper disable InconsistentNaming

Expand All @@ -30,7 +31,6 @@ public sealed class ShortConstructionMenuBUI : BoundUserInterface
private readonly SpriteSystem _spriteSystem;

private RadialMenu? _menu;

public ShortConstructionMenuBUI(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
_construction = _entManager.System<ConstructionSystem>();
Expand All @@ -39,8 +39,19 @@ public ShortConstructionMenuBUI(EntityUid owner, Enum uiKey) : base(owner, uiKey

protected override void Open()
{
_menu = FormMenu();
_menu.OnClose += Close;
_menu = new RadialMenu
{
HorizontalExpand = true,
VerticalExpand = true,
BackButtonStyleClass = "RadialMenuBackButton",
CloseButtonStyleClass = "RadialMenuCloseButton"
};

if (_entManager.TryGetComponent<ShortConstructionComponent>(Owner, out var crafting))
{
CreateMenu(crafting.Entries);
}
gluesniffler marked this conversation as resolved.
Show resolved Hide resolved

_menu.OpenCenteredAt(_inputManager.MouseScreenPosition.Position / _displayManager.ScreenSize);
}

Expand All @@ -51,56 +62,58 @@ protected override void Dispose(bool disposing)
_menu?.Dispose();
}

private RadialMenu FormMenu()
private void CreateMenu(List<ShortConstructionEntry> entries, string? parentCategory = null)
{
var menu = new RadialMenu
{
HorizontalExpand = true,
VerticalExpand = true,
BackButtonStyleClass = "RadialMenuBackButton",
CloseButtonStyleClass = "RadialMenuCloseButton"
};

if (!_entManager.TryGetComponent<ShortConstructionComponent>(Owner, out var crafting))
return menu;
if (_menu == null)
return;

var mainContainer = new RadialContainer
var container = new RadialContainer
{
Radius = 36f / MathF.Sin(MathF.PI / 2f / crafting.Prototypes.Count)
Name = parentCategory ?? "Main",
Radius = 48f + 24f * MathF.Log(entries.Count),
};

foreach (var protoId in crafting.Prototypes)
{
if (!_protoManager.TryIndex(protoId, out var proto))
continue;
_menu.AddChild(container);

var button = new RadialMenuTextureButton
foreach (var entry in entries)
{
if (entry.Category != null)
{
ToolTip = Loc.GetString(proto.Name),
StyleClasses = { "RadialMenuButton" },
SetSize = new Vector2(48f, 48f)
};

var texture = new TextureRect
var button = CreateButton(entry.Category.Name, entry.Category.Icon);
button.TargetLayer = entry.Category.Name;
CreateMenu(entry.Category.Entries, entry.Category.Name);
container.AddChild(button);
}
else if (entry.Prototype != null
&& _protoManager.TryIndex(entry.Prototype, out var proto))
{
VerticalAlignment = Control.VAlignment.Center,
HorizontalAlignment = Control.HAlignment.Center,
Texture = _spriteSystem.Frame0(proto.Icon),
TextureScale = new Vector2(1.5f, 1.5f)
};
var button = CreateButton(proto.Name, proto.Icon);
button.OnButtonUp += _ => ConstructItem(proto);
container.AddChild(button);
}
}

button.AddChild(texture);
}

button.OnButtonUp += _ =>
{
ConstructItem(proto);
};
private RadialMenuTextureButton CreateButton(string name, SpriteSpecifier icon)
{
var button = new RadialMenuTextureButton
{
ToolTip = Loc.GetString(name),
StyleClasses = { "RadialMenuButton" },
SetSize = new Vector2(64f, 64f),
};

mainContainer.AddChild(button);
}
var texture = new TextureRect
{
VerticalAlignment = Control.VAlignment.Center,
HorizontalAlignment = Control.HAlignment.Center,
Texture = _spriteSystem.Frame0(icon),
TextureScale = new Vector2(2f, 2f)
};

menu.AddChild(mainContainer);
return menu;
button.AddChild(texture);
return button;
}

/// <summary>
Expand All @@ -121,6 +134,6 @@ private void ConstructItem(ConstructionPrototype prototype)
}, new ConstructionPlacementHijack(_construction, prototype));

// Should only close the menu if we're placing a construction hijack.
_menu!.Close();
// Theres not much point to closing it though. _menu!.Close();
}
}
26 changes: 25 additions & 1 deletion Content.Shared/ShortConstruction/ShortConstructionComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,38 @@
using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
using Robust.Shared.Utility;

namespace Content.Shared.ShortConstruction;

[RegisterComponent, NetworkedComponent]
public sealed partial class ShortConstructionComponent : Component
{
[DataField(required: true)]
public List<ProtoId<ConstructionPrototype>> Prototypes = new();
public List<ShortConstructionEntry> Entries = new();
}

[DataDefinition]
public sealed partial class ShortConstructionEntry
{
[DataField("prototype")]
public ProtoId<ConstructionPrototype>? Prototype { get; set; }

[DataField("category")]
public ShortConstructionCategory? Category { get; set; }
gluesniffler marked this conversation as resolved.
Show resolved Hide resolved
}

[DataDefinition]
public sealed partial class ShortConstructionCategory
{
[DataField("name")]
public string Name { get; set; } = string.Empty;

[DataField("icon")]
public SpriteSpecifier Icon { get; set; } = default!;

[DataField("entries")]
public List<ShortConstructionEntry> Entries { get; set; } = new();
gluesniffler marked this conversation as resolved.
Show resolved Hide resolved
}

[NetSerializable, Serializable]
Expand Down
63 changes: 59 additions & 4 deletions Resources/Prototypes/Entities/Objects/Materials/Sheets/glass.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,13 @@
- type: ActivatableUI
key: enum.ShortConstructionUiKey.Key
- type: ShortConstruction
prototypes:
- Window
entries:
- prototype: Window
- prototype: WindowDirectional
- prototype: WindowDiagonal
- prototype: SheetRGlass
- prototype: SheetPGlass
- prototype: SheetUGlass

- type: entity
parent: SheetGlass
Expand Down Expand Up @@ -193,8 +198,12 @@
- type: ActivatableUI
key: enum.ShortConstructionUiKey.Key
- type: ShortConstruction
prototypes:
- ReinforcedWindow
entries:
- prototype: SheetRPGlass1
- prototype: SheetRUGlass1
- prototype: ReinforcedWindow
- prototype: ReinforcedWindowDiagonal
- prototype: WindowReinforcedDirectional

- type: entity
parent: SheetRGlass
Expand Down Expand Up @@ -272,6 +281,18 @@
max: 1
- !type:DoActsBehavior
acts: [ "Destruction" ]
- type: UserInterface
interfaces:
- key: enum.ShortConstructionUiKey.Key
type: ShortConstructionMenuBUI
- type: ActivatableUI
key: enum.ShortConstructionUiKey.Key
- type: ShortConstruction
entries:
- prototype: SheetRPGlass0
- prototype: PlasmaWindow
- prototype: PlasmaWindowDiagonal
- prototype: PlasmaWindowDirectional

- type: entity
parent: SheetPGlass
Expand Down Expand Up @@ -338,6 +359,17 @@
- ReagentId: Carbon
Quantity: 0.5
canReact: false
- type: UserInterface
interfaces:
- key: enum.ShortConstructionUiKey.Key
type: ShortConstructionMenuBUI
- type: ActivatableUI
key: enum.ShortConstructionUiKey.Key
- type: ShortConstruction
entries:
- prototype: ReinforcedPlasmaWindow
- prototype: ReinforcedPlasmaWindowDiagonal
- prototype: PlasmaReinforcedWindowDirectional

- type: entity
parent: SheetRPGlass
Expand Down Expand Up @@ -413,6 +445,18 @@
- ReagentId: Uranium
Quantity: 10
canReact: false
- type: UserInterface
interfaces:
- key: enum.ShortConstructionUiKey.Key
type: ShortConstructionMenuBUI
- type: ActivatableUI
key: enum.ShortConstructionUiKey.Key
- type: ShortConstruction
entries:
- prototype: SheetRUGlass0
- prototype: UraniumWindow
- prototype: UraniumWindowDiagonal
- prototype: UraniumWindowDirectional

- type: entity
parent: SheetUGlass
Expand Down Expand Up @@ -467,6 +511,17 @@
- ReagentId: Carbon
Quantity: 0.5
canReact: false
- type: UserInterface
interfaces:
- key: enum.ShortConstructionUiKey.Key
type: ShortConstructionMenuBUI
- type: ActivatableUI
key: enum.ShortConstructionUiKey.Key
- type: ShortConstruction
entries:
- prototype: ReinforcedUraniumWindow
- prototype: ReinforcedUraniumWindowDiagonal
- prototype: UraniumReinforcedWindowDirectional

- type: entity
parent: SheetRUGlass
Expand Down
84 changes: 78 additions & 6 deletions Resources/Prototypes/Entities/Objects/Materials/Sheets/metal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,75 @@
- type: ActivatableUI
key: enum.ShortConstructionUiKey.Key
- type: ShortConstruction
prototypes:
- Girder
- MetalRod
- TileSteel
- TileWhite
- TileDark
entries:
- prototype: Girder
- prototype: MetalRod
- category:
name: Tiles
icon:
sprite: Objects/Tiles/tile.rsi
state: steel
entries:
- prototype: TileSteel
- prototype: TileWhite
- prototype: TileDark
- category:
name: Electronics
icon:
sprite: Structures/Machines/computers.rsi
state: computer-datatheory
entries:
- prototype: MachineFrame
- prototype: Computer
- prototype: Windoor
- prototype: LightTubeFixture
- prototype: APC
- prototype: AirAlarmFixture
- prototype: AirSensor
- prototype: FireAlarm
- category:
name: Atmospherics
icon:
sprite: Structures/Piping/Atmospherics/vent.rsi
state: vent_out
entries:
- prototype: GasPort
- prototype: GasOutletInjector
- prototype: GasVentScrubber
- prototype: GasPassiveVent
- prototype: GasVentPump
- prototype: GasMixer
- prototype: GasFilter
- prototype: GasVolumePump
- prototype: GasPressurePump
- prototype: GasValve
- category:
name: Piping
icon:
sprite: Structures/Piping/Atmospherics/pipe.rsi
state: pipeFourway
entries:
- prototype: HeatExchanger
- prototype: GasPipeBend
- prototype: GasPipeFourway
- prototype: GasPipeHalf
- prototype: GasPipeStraight
- prototype: GasPipeTJunction
- category:
name: Disposals
icon:
sprite: Structures/Piping/disposal.rsi
state: disposal
entries:
- prototype: DisposalPipe
- prototype: DisposalBend
- prototype: DisposalJunction
- prototype: DisposalYJunction
- prototype: DisposalRouter
- prototype: DisposalTagger
- prototype: DisposalTrunk
- prototype: DisposalUnit
- prototype: CrateGenericSteel

- type: entity
parent: SheetSteel
Expand Down Expand Up @@ -218,6 +281,15 @@
- ReagentId: Carbon
Quantity: 1
canReact: false
- type: UserInterface
interfaces:
- key: enum.ShortConstructionUiKey.Key
type: ShortConstructionMenuBUI
- type: ActivatableUI
key: enum.ShortConstructionUiKey.Key
- type: ShortConstruction
entries:
- prototype: SecureWindoor

- type: entity
parent: SheetPlasteel
Expand Down
Loading
Loading