Skip to content

Commit

Permalink
Merge branch 'master' into 2024-12-26-Kegs
Browse files Browse the repository at this point in the history
  • Loading branch information
dvir001 authored Dec 26, 2024
2 parents 0aa1fa8 + ecd0e54 commit b3839f8
Show file tree
Hide file tree
Showing 23 changed files with 340 additions and 100 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;
}
2 changes: 2 additions & 0 deletions Content.Shared/Construction/SharedFlatpackSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ private void OnFlatpackInteractUsing(Entity<FlatpackComponent> ent, ref Interact
if (_net.IsServer)
{
var spawn = Spawn(comp.Entity, _map.GridTileToLocal(grid, gridComp, buildPos));
if (TryComp(spawn, out TransformComponent? spawnXform)) // Frontier: rotatable flatpacks
spawnXform.LocalRotation = xform.LocalRotation.GetCardinalDir().ToAngle(); // Frontier: rotatable flatpacks
_adminLogger.Add(LogType.Construction,
LogImpact.Low,
$"{ToPrettyString(args.User):player} unpacked {ToPrettyString(spawn):entity} at {xform.Coordinates} from {ToPrettyString(uid):entity}");
Expand Down
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,
}
}
127 changes: 62 additions & 65 deletions Content.Shared/_EE/CCVar/EECCVars.cs
Original file line number Diff line number Diff line change
@@ -1,81 +1,78 @@
using Robust.Shared;
using Robust.Shared.Configuration;

namespace Content.Shared._EE.CCVar
namespace Content.Shared._EE.CCVar;

[CVarDefs] // ReSharper disable once InconsistentNaming
public sealed class EECCVars
{
// ReSharper disable once InconsistentNaming
[CVarDefs]
public sealed class EECCVars : CVars
{
#region Jetpack System
#region Jetpack System

/// <summary>
/// When true, Jetpacks can be enabled anywhere, even in gravity.
/// </summary>
public static readonly CVarDef<bool> JetpackEnableAnywhere =
CVarDef.Create("ee.jetpack.enable_anywhere", false, CVar.REPLICATED);
/// <summary>
/// When true, Jetpacks can be enabled anywhere, even in gravity.
/// </summary>
public static readonly CVarDef<bool> JetpackEnableAnywhere =
CVarDef.Create("ee.jetpack.enable_anywhere", false, CVar.REPLICATED);

/// <summary>
/// When true, jetpacks can be enabled on grids that have zero gravity.
/// </summary>
public static readonly CVarDef<bool> JetpackEnableInNoGravity =
CVarDef.Create("ee.jetpack.enable_in_no_gravity", true, CVar.REPLICATED);
/// <summary>
/// When true, jetpacks can be enabled on grids that have zero gravity.
/// </summary>
public static readonly CVarDef<bool> JetpackEnableInNoGravity =
CVarDef.Create("ee.jetpack.enable_in_no_gravity", true, CVar.REPLICATED);

#endregion
#endregion

#region Contests System
#region Contests System

/// <summary>
/// The MASTER TOGGLE for the entire Contests System.
/// ALL CONTESTS BELOW, regardless of type or setting will output 1f when false.
/// </summary>
public static readonly CVarDef<bool> DoContestsSystem =
CVarDef.Create("contests.do_contests_system", true, CVar.REPLICATED | CVar.SERVER);
/// <summary>
/// The MASTER TOGGLE for the entire Contests System.
/// ALL CONTESTS BELOW, regardless of type or setting will output 1f when false.
/// </summary>
public static readonly CVarDef<bool> DoContestsSystem =
CVarDef.Create("ee.contests.do_contests_system", true, CVar.REPLICATED | CVar.SERVER);

/// <summary>
/// Contest functions normally include an optional override to bypass the clamp set by max_percentage.
/// This CVar disables the bypass when false, forcing all implementations to comply with max_percentage.
/// </summary>
public static readonly CVarDef<bool> AllowClampOverride =
CVarDef.Create("contests.allow_clamp_override", true, CVar.REPLICATED | CVar.SERVER);
/// <summary>
/// Toggles all MassContest functions. All mass contests output 1f when false
/// </summary>
public static readonly CVarDef<bool> DoMassContests =
CVarDef.Create("contests.do_mass_contests", true, CVar.REPLICATED | CVar.SERVER);
/// <summary>
/// Contest functions normally include an optional override to bypass the clamp set by max_percentage.
/// This CVar disables the bypass when false, forcing all implementations to comply with max_percentage.
/// </summary>
public static readonly CVarDef<bool> AllowClampOverride =
CVarDef.Create("ee.contests.allow_clamp_override", true, CVar.REPLICATED | CVar.SERVER);
/// <summary>
/// Toggles all MassContest functions. All mass contests output 1f when false
/// </summary>
public static readonly CVarDef<bool> DoMassContests =
CVarDef.Create("ee.contests.do_mass_contests", true, CVar.REPLICATED | CVar.SERVER);

/// <summary>
/// Toggles all StaminaContest functions. All stamina contests output 1f when false
/// </summary>
public static readonly CVarDef<bool> DoStaminaContests =
CVarDef.Create("contests.do_stamina_contests", true, CVar.REPLICATED | CVar.SERVER);
/// <summary>
/// Toggles all StaminaContest functions. All stamina contests output 1f when false
/// </summary>
public static readonly CVarDef<bool> DoStaminaContests =
CVarDef.Create("ee.contests.do_stamina_contests", true, CVar.REPLICATED | CVar.SERVER);

/// <summary>
/// Toggles all HealthContest functions. All health contests output 1f when false
/// </summary>
public static readonly CVarDef<bool> DoHealthContests =
CVarDef.Create("contests.do_health_contests", true, CVar.REPLICATED | CVar.SERVER);
/// <summary>
/// Toggles all HealthContest functions. All health contests output 1f when false
/// </summary>
public static readonly CVarDef<bool> DoHealthContests =
CVarDef.Create("ee.contests.do_health_contests", true, CVar.REPLICATED | CVar.SERVER);

/// <summary>
/// Toggles all MindContest functions. All mind contests output 1f when false.
/// MindContests are not currently implemented, and are awaiting completion of the Psionic Refactor
/// </summary>
public static readonly CVarDef<bool> DoMindContests =
CVarDef.Create("contests.do_mind_contests", true, CVar.REPLICATED | CVar.SERVER);
/// <summary>
/// Toggles all MindContest functions. All mind contests output 1f when false.
/// MindContests are not currently implemented, and are awaiting completion of the Psionic Refactor
/// </summary>
public static readonly CVarDef<bool> DoMindContests =
CVarDef.Create("ee.contests.do_mind_contests", true, CVar.REPLICATED | CVar.SERVER);

/// <summary>
/// Toggles all MoodContest functions. All mood contests output 1f when false.
/// </summary>
public static readonly CVarDef<bool> DoMoodContests =
CVarDef.Create("contests.do_mood_contests", true, CVar.REPLICATED | CVar.SERVER);
/// <summary>
/// Toggles all MoodContest functions. All mood contests output 1f when false.
/// </summary>
public static readonly CVarDef<bool> DoMoodContests =
CVarDef.Create("ee.contests.do_mood_contests", true, CVar.REPLICATED | CVar.SERVER);

/// <summary>
/// The maximum amount that Mass Contests can modify a physics multiplier, given as a +/- percentage
/// Default of 0.25f outputs between * 0.75f and 1.25f
/// </summary>
public static readonly CVarDef<float> MassContestsMaxPercentage =
CVarDef.Create("contests.max_percentage", 0.25f, CVar.REPLICATED | CVar.SERVER);
/// <summary>
/// The maximum amount that Mass Contests can modify a physics multiplier, given as a +/- percentage
/// Default of 0.25f outputs between * 0.75f and 1.25f
/// </summary>
public static readonly CVarDef<float> MassContestsMaxPercentage =
CVarDef.Create("ee.contests.max_percentage", 0.25f, CVar.REPLICATED | CVar.SERVER);

#endregion
}
#endregion
}
Loading

0 comments on commit b3839f8

Please sign in to comment.