-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature] Short Construction System / Система Крафтов В Руках (#17)
* feat: inhand crafting base * fix: be gone * tweak: better naming, menu stays open on item crafting * feat: recipes
- Loading branch information
Showing
7 changed files
with
192 additions
and
0 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
Content.Client/_White/ShortConstruction/UI/ShortConstructionMenu.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
88 changes: 88 additions & 0 deletions
88
Content.Client/_White/ShortConstruction/UI/ShortConstructionMenu.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
Content.Client/_White/ShortConstruction/UI/ShortConstructionMenuBUI.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
Content.Shared/_White/ShortConstruction/ShortConstructionComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters