Skip to content

Commit

Permalink
Load InterfaceData into a prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
whatston3 committed Dec 26, 2024
1 parent 234e9ea commit e6c9ca7
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Content.Server/Stack/StackSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ private void OnStackAlternativeInteract(EntityUid uid, StackComponent stack, Get
args.Verbs.Add(verb);
}

if (stack.CustomSplit)
if (_ui.HasUi(uid, StackCustomSplitUiKey.Key))
{
AlternativeVerb custom = new()
{
Expand Down
20 changes: 20 additions & 0 deletions Content.Shared/Stacks/CustomStackSplitPrototype.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
using Robust.Shared.GameObjects;
using Robust.Shared.Utility;

namespace Content.Shared.Stacks;

[Prototype]
public sealed partial class CustomStackSplitPrototype : IPrototype
{
[ViewVariables]
[IdDataField]
public string ID { get; private set; } = default!;

/// <summary>
/// UI parameters for custom stack splitting.
/// </summary>
[DataField(required: true)]
public InterfaceData Interface { get; private set; } = default!;
}
4 changes: 2 additions & 2 deletions Content.Shared/Stacks/SharedStackSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public override void Initialize()

private void OnStackInit(EntityUid uid, StackComponent stack, ref ComponentInit args)
{
if (stack.CustomSplit)
_ui.SetUi(uid, StackCustomSplitUiKey.Key, new InterfaceData("StackCustomSplitBoundUserInterface"));
if (!string.IsNullOrEmpty(stack.CustomSplit) && _prototype.TryIndex<CustomStackSplitPrototype>(stack.CustomSplit, out var customStackSplit))
_ui.SetUi(uid, StackCustomSplitUiKey.Key, customStackSplit.Interface);
}

// client shouldn't try to split stacks so do nothing on client
Expand Down
4 changes: 2 additions & 2 deletions Content.Shared/Stacks/StackComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ public sealed partial class StackComponent : Component
public List<string> LayerStates = new();

/// <summary>
/// If true, interacting with object will show a custom split dialog.
/// The CustomStackSplit prototype to use for the stack interface
/// </summary>
[DataField("customSplit")]
[ViewVariables(VVAccess.ReadWrite)]
public bool CustomSplit;
public string? CustomSplit;
}

[Serializable, NetSerializable]
Expand Down
4 changes: 4 additions & 0 deletions Resources/Prototypes/custom_stack_split.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- type: customStackSplit
id: Default
interface:
type: StackCustomSplitBoundUserInterface

0 comments on commit e6c9ca7

Please sign in to comment.