Skip to content

Commit

Permalink
Merge branch 'master' into Pirate-PDA-GPS
Browse files Browse the repository at this point in the history
  • Loading branch information
dvir001 authored Dec 26, 2024
2 parents 8a56355 + f354739 commit ef89eab
Show file tree
Hide file tree
Showing 13 changed files with 224 additions and 14 deletions.
41 changes: 41 additions & 0 deletions Content.Client/Stack/StackCustomSplitBoundUserInterface.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Cherry-picked from space-station-14#32938 courtesy of Ilya246
using JetBrains.Annotations;
using Content.Shared.Stacks;
using Robust.Client.GameObjects;
using Robust.Client.UserInterface;

namespace Content.Client.Stack
{
[UsedImplicitly]
public sealed class StackCustomSplitBoundUserInterface : BoundUserInterface
{
private IEntityManager _entManager;
private EntityUid _owner;
[ViewVariables]
private StackCustomSplitWindow? _window;

public StackCustomSplitBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
_owner = owner;
_entManager = IoCManager.Resolve<IEntityManager>();
}

protected override void Open()
{
base.Open();
_window = this.CreateWindow<StackCustomSplitWindow>();

if (_entManager.TryGetComponent<StackComponent>(_owner, out var comp))
_window.SetMax(comp.Count);

_window.ApplyButton.OnPressed += _ =>
{
if (int.TryParse(_window.AmountLineEdit.Text, out var i))
{
SendMessage(new StackCustomSplitAmountMessage(i));
_window.Close();
}
};
}
}
}
15 changes: 15 additions & 0 deletions Content.Client/Stack/StackCustomSplitWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<DefaultWindow xmlns="https://spacestation14.io"
Title="{Loc 'ui-custom-stack-split-title'}"
Resizable="False">
<!--Cherry-picked from space-station-14#32938 courtesy of Ilya246-->

<BoxContainer Orientation="Vertical" SeparationOverride="4" MinSize="240 80">
<BoxContainer Orientation="Horizontal">
<LineEdit Name="AmountLineEdit" Access="Public" HorizontalExpand="True" PlaceHolder="{Loc 'ui-custom-stack-split-line-edit-placeholder'}"/>
</BoxContainer>
<BoxContainer Orientation="Horizontal">
<Label Name="MaximumAmount" Access="Public" />
</BoxContainer>
<Button Name="ApplyButton" Access="Public" Text="{Loc 'ui-custom-stack-split-apply'}"/>
</BoxContainer>
</DefaultWindow>
35 changes: 35 additions & 0 deletions Content.Client/Stack/StackCustomSplitWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Cherry-picked from space-station-14#32938 courtesy of Ilya246
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML;

namespace Content.Client.Stack
{
[GenerateTypedNameReferences]
public sealed partial class StackCustomSplitWindow : DefaultWindow
{
private int _max = Int32.MaxValue;
private int _min = 1;

public StackCustomSplitWindow()
{
RobustXamlLoader.Load(this);
AmountLineEdit.OnTextChanged += OnValueChanged;
}

public void SetMax(int max)
{
_max = max;
MaximumAmount.Text = Loc.GetString("comp-stack-split-size", ("size", _max));
}

private void OnValueChanged(LineEdit.LineEditEventArgs args)
{
if (!int.TryParse(AmountLineEdit.Text, out var amount) || amount > _max || amount < _min)
ApplyButton.Disabled = true;
else
ApplyButton.Disabled = false;
}
}
}
36 changes: 34 additions & 2 deletions Content.Server/Stack/StackSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace Content.Server.Stack
public sealed class StackSystem : SharedStackSystem
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly SharedUserInterfaceSystem _ui = default!; // Cherry-picked from space-station-14#32938 courtesy of Ilya246

public static readonly int[] DefaultSplitAmounts = { 1, 5, 10, 20, 50, 100, 500, 1000, 5000, 10000 };

Expand Down Expand Up @@ -170,16 +171,33 @@ private void OnStackAlternativeInteract(EntityUid uid, StackComponent stack, Get
if (!args.CanAccess || !args.CanInteract || args.Hands == null || stack.Count == 1)
return;

// Frontier: cherry-picked from ss14#32938, moved up top
var priority = 1;
if (_ui.HasUi(uid, StackCustomSplitUiKey.Key)) // Frontier: check for interface
{
AlternativeVerb custom = new()
{
Text = Loc.GetString("comp-stack-split-custom"),
Category = VerbCategory.Split,
Act = () =>
{
_ui.OpenUi(uid, StackCustomSplitUiKey.Key, args.User);
},
Priority = priority--
};
args.Verbs.Add(custom);
}
// End Frontier: cherry-picked from ss14#32938, moved up top

AlternativeVerb halve = new()
{
Text = Loc.GetString("comp-stack-split-halve"),
Category = VerbCategory.Split,
Act = () => UserSplit(uid, args.User, stack.Count / 2, stack),
Priority = 1
Priority = priority-- // Frontier: 1<priority--
};
args.Verbs.Add(halve);

var priority = 0;
foreach (var amount in DefaultSplitAmounts)
{
if (amount >= stack.Count)
Expand All @@ -200,6 +218,20 @@ private void OnStackAlternativeInteract(EntityUid uid, StackComponent stack, Get
}
}

// Cherry-picked from ss14#32938 courtesy of Ilya246
protected override void OnCustomSplitMessage(Entity<StackComponent> ent, ref StackCustomSplitAmountMessage message)
{
var (uid, comp) = ent;

// digital ghosts shouldn't be allowed to split stacks
if (!(message.Actor is { Valid: true } user))
return;

var amount = message.Amount;
UserSplit(uid, user, amount, comp);
}
// End cherry-pick from ss14#32938 courtesy of Ilya246

private void UserSplit(EntityUid uid, EntityUid userUid, int amount,
StackComponent? stack = null,
TransformComponent? userTransform = null)
Expand Down
26 changes: 26 additions & 0 deletions Content.Server/_NF/Chemistry/RandomPillSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Content.Shared.Chemistry.Components;
using Robust.Shared.Random;

namespace Content.Server._NF.Chemistry;

public sealed class RandomPillSystem : EntitySystem
{
[Dependency] private readonly IRobustRandom _random = default!;

public const int MaxPillType = 21;

public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<PillComponent, MapInitEvent>(OnMapInit);
}

private void OnMapInit(Entity<PillComponent> ent, ref MapInitEvent componentInit)
{
if (ent.Comp.Random)
{
ent.Comp.PillType = (uint)_random.Next(MaxPillType);
Dirty(ent);
}
}
}
6 changes: 6 additions & 0 deletions Content.Shared/Chemistry/Components/PillComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,10 @@ public sealed partial class PillComponent : Component
[DataField("pillType")]
[ViewVariables(VVAccess.ReadWrite)]
public uint PillType;

/// <summary>
/// Frontier: if true, pill appearance will be randomly generated on init.
/// </summary>
[DataField(serverOnly: true)]
public bool Random;
}
6 changes: 6 additions & 0 deletions Content.Shared/Stacks/SharedStackSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,17 @@ public override void Initialize()
SubscribeLocalEvent<StackComponent, ComponentStartup>(OnStackStarted);
SubscribeLocalEvent<StackComponent, ExaminedEvent>(OnStackExamined);
SubscribeLocalEvent<StackComponent, InteractUsingEvent>(OnStackInteractUsing);
SubscribeLocalEvent<StackComponent, StackCustomSplitAmountMessage>(OnCustomSplitMessage); // cherry-pick #32938

_vvm.GetTypeHandler<StackComponent>()
.AddPath(nameof(StackComponent.Count), (_, comp) => comp.Count, SetCount);
}

// Cherry-pick #32938 courtesy of Ilya246
// client shouldn't try to split stacks so do nothing on client
protected virtual void OnCustomSplitMessage(Entity<StackComponent> ent, ref StackCustomSplitAmountMessage message) {}
// End cherry-pick #32938 courtesy of Ilya246

public override void Shutdown()
{
base.Shutdown();
Expand Down
22 changes: 22 additions & 0 deletions Content.Shared/Stacks/StackCustomSplit.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Cherry-pick space-station-14#32938 courtesy of Ilya246
using Robust.Shared.Serialization;

namespace Content.Shared.Stacks
{
[Serializable, NetSerializable]
public sealed class StackCustomSplitAmountMessage : BoundUserInterfaceMessage
{
public int Amount;

public StackCustomSplitAmountMessage(int amount)
{
Amount = amount;
}
}

[Serializable, NetSerializable]
public enum StackCustomSplitUiKey
{
Key,
}
}
6 changes: 6 additions & 0 deletions Resources/Changelog/Frontier.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6110,3 +6110,9 @@ Entries:
message: Cargo Depots should be spawning normally now.
id: 5612
time: '2024-12-26T15:21:56.0000000+00:00'
- author: Ilya246 and whatston3
changes:
- type: Add
message: Spesos and spessos now support custom split amounts.
id: 5613
time: '2024-12-26T20:21:42.0000000+00:00'
9 changes: 9 additions & 0 deletions Resources/Locale/en-US/stack/stack-component.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,13 @@ comp-stack-becomes-full = Stack is now full.
# Text related to splitting a stack
comp-stack-split = You split the stack.
comp-stack-split-halve = Halve
comp-stack-split-custom = Split amount...
comp-stack-split-too-small = Stack is too small to split.
# Cherry-picked from space-station-14#32938 courtesy of Ilya246
comp-stack-split-size = Max: {$size}
ui-custom-stack-split-title = Split Amount
ui-custom-stack-split-line-edit-placeholder = Amount
ui-custom-stack-split-apply = Split
# End cherry-pick from ss14#32938
6 changes: 6 additions & 0 deletions Resources/Prototypes/Entities/Objects/Misc/space_cash.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@
- cash_100000 # Frontier: larger denominations
- cash_250000 # Frontier: larger denominations (cash_1000000<cash_250000)
layerFunction: Threshold # Frontier: multicolour cash
# cherry-pick from space-station#32938 courtesy of Ilya246
- type: UserInterface
interfaces:
enum.StackCustomSplitUiKey.Key:
type: StackCustomSplitBoundUserInterface
# end cherry-pick from ss#32938
- type: StackLayerThreshold # Frontier
thresholds: [10, 100, 500, 1000, 5000, 10000, 25000, 50000, 100000, 250000] # Frontier
- type: Sprite
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@
- type: RandomFillSolution
solution: food
weightedRandomId: RandomFillStrangePill
- type: Pill # Frontier
random: true # Frontier
# RandomSprite does not work with pill component
# - type: Sprite
# sprite: Objects/Specific/Chemistry/pills.rsi
Expand Down
28 changes: 16 additions & 12 deletions Resources/Prototypes/_NF/Entities/Objects/Misc/space_cash.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,21 @@
- cash_100
- cash_500
- cash_1000
- cash_5000 # Frontier: larger denominations
- cash_10000 # Frontier: larger denominations
- cash_25000 # Frontier: larger denominations
- cash_50000 # Frontier: larger denominations
- cash_100000 # Frontier: larger denominations
- cash_250000 # Frontier: larger denominations (cash_1000000<cash_250000)
layerFunction: Threshold # Frontier: multicolour cash
- type: StackLayerThreshold # Frontier
thresholds: [10, 100, 500, 1000, 5000, 10000, 25000, 50000, 100000, 250000] # Frontier
- cash_5000
- cash_10000
- cash_25000
- cash_50000
- cash_100000
- cash_250000
layerFunction: Threshold
- type: UserInterface
interfaces:
enum.StackCustomSplitUiKey.Key:
type: StackCustomSplitBoundUserInterface
- type: StackLayerThreshold
thresholds: [10, 100, 500, 1000, 5000, 10000, 25000, 50000, 100000, 250000]
- type: Sprite
sprite: _NF/Objects/Economy/counterfeit_cash.rsi # Frontier: larger denominations
sprite: _NF/Objects/Economy/counterfeit_cash.rsi
state: cash
layers:
- state: cash
Expand All @@ -95,13 +99,13 @@
name: spesso
unit: materials-unit-bill
stackEntity: SpaceCashCounterfeit
icon: { sprite: _NF/Objects/Economy/counterfeit_cash.rsi, state: cash } # Frontier: use Frontier sprite set
icon: { sprite: _NF/Objects/Economy/counterfeit_cash.rsi, state: cash }
price: 0

- type: stack
id: CreditCounterfeit
name: spesso
icon: { sprite: _NF/Objects/Economy/counterfeit_cash.rsi, state: cash } # Frontier: use Frontier sprite set
icon: { sprite: _NF/Objects/Economy/counterfeit_cash.rsi, state: cash }
spawn: SpaceCashCounterfeit

- type: currency
Expand Down

0 comments on commit ef89eab

Please sign in to comment.