Skip to content

Commit

Permalink
Predict dumping
Browse files Browse the repository at this point in the history
- This got soaped really fucking hard.
- Dumping is predicted, this required disposals to be predicte.d
- Disposals required mailing (because it's tightly coupled), and a smidge of other content systems.
- I also had to fix a compnetworkgenerator issue at the same time so it wouldn't mispredict.
  • Loading branch information
metalgearsloth committed Sep 23, 2024
1 parent 8ed779b commit 77877aa
Show file tree
Hide file tree
Showing 133 changed files with 1,541 additions and 1,643 deletions.
25 changes: 25 additions & 0 deletions Content.Client/Configurable/ConfigurationSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Content.Client.Configurable.UI;
using Content.Shared.Configurable;

namespace Content.Client.Configurable;

public sealed class ConfigurationSystem : SharedConfigurationSystem
{
[Dependency] private readonly SharedUserInterfaceSystem _uiSystem = default!;

public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<ConfigurationComponent, AfterAutoHandleStateEvent>(OnConfigurationState);
}

private void OnConfigurationState(Entity<ConfigurationComponent> ent, ref AfterAutoHandleStateEvent args)
{
if (_uiSystem.TryGetOpenUi<ConfigurationBoundUserInterface>(ent.Owner,
ConfigurationComponent.ConfigurationUiKey.Key,
out var bui))
{
bui.Refresh(ent);
}
}
}
53 changes: 46 additions & 7 deletions Content.Client/Configurable/UI/ConfigurationBoundUserInterface.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System.Text.RegularExpressions;
using Robust.Client.GameObjects;
using System.Numerics;
using System.Text.RegularExpressions;
using Content.Shared.Configurable;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using static Content.Shared.Configurable.ConfigurationComponent;

namespace Content.Client.Configurable.UI
Expand All @@ -19,16 +21,53 @@ protected override void Open()
base.Open();
_menu = this.CreateWindow<ConfigurationMenu>();
_menu.OnConfiguration += SendConfiguration;
if (EntMan.TryGetComponent(Owner, out ConfigurationComponent? component))
Refresh((Owner, component));
}

protected override void UpdateState(BoundUserInterfaceState state)
public void Refresh(Entity<ConfigurationComponent> entity)
{
base.UpdateState(state);

if (state is not ConfigurationBoundUserInterfaceState configurationState)
if (_menu == null)
return;

_menu?.Populate(configurationState);
_menu.Column.Children.Clear();
_menu.Inputs.Clear();

foreach (var field in entity.Comp.Config)
{
var label = new Label
{
Margin = new Thickness(0, 0, 8, 0),
Name = field.Key,
Text = field.Key + ":",
VerticalAlignment = Control.VAlignment.Center,
HorizontalExpand = true,
SizeFlagsStretchRatio = .2f,
MinSize = new Vector2(60, 0)
};

var input = new LineEdit
{
Name = field.Key + "-input",
Text = field.Value ?? "",
IsValid = _menu.Validate,
HorizontalExpand = true,
SizeFlagsStretchRatio = .8f
};

_menu.Inputs.Add((field.Key, input));

var row = new BoxContainer
{
Orientation = BoxContainer.LayoutOrientation.Horizontal
};

ConfigurationMenu.CopyProperties(_menu.Row, row);

row.AddChild(label);
row.AddChild(input);
_menu.Column.AddChild(row);
}
}

protected override void ReceiveMessage(BoundUserInterfaceMessage message)
Expand Down
67 changes: 11 additions & 56 deletions Content.Client/Configurable/UI/ConfigurationMenu.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
using System.Collections.Generic;
using System.Numerics;
using System.Numerics;
using System.Text.RegularExpressions;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Shared.Localization;
using Robust.Shared.Maths;
using static Content.Shared.Configurable.ConfigurationComponent;
using static Robust.Client.UserInterface.Controls.BaseButton;
using static Robust.Client.UserInterface.Controls.BoxContainer;

namespace Content.Client.Configurable.UI
{
public sealed class ConfigurationMenu : DefaultWindow
{
private readonly BoxContainer _column;
private readonly BoxContainer _row;
public readonly BoxContainer Column;
public readonly BoxContainer Row;

private readonly List<(string name, LineEdit input)> _inputs;
public readonly List<(string name, LineEdit input)> Inputs;

[ViewVariables]
public Regex? Validation { get; internal set; }
Expand All @@ -28,7 +24,7 @@ public ConfigurationMenu()
{
MinSize = SetSize = new Vector2(300, 250);

_inputs = new List<(string name, LineEdit input)>();
Inputs = new List<(string name, LineEdit input)>();

Title = Loc.GetString("configuration-menu-device-title");

Expand All @@ -39,14 +35,14 @@ public ConfigurationMenu()
HorizontalExpand = true
};

_column = new BoxContainer
Column = new BoxContainer
{
Orientation = LayoutOrientation.Vertical,
Margin = new Thickness(8),
SeparationOverride = 16,
};

_row = new BoxContainer
Row = new BoxContainer
{
Orientation = LayoutOrientation.Horizontal,
SeparationOverride = 16,
Expand All @@ -69,61 +65,20 @@ public ConfigurationMenu()
ModulateSelfOverride = Color.FromHex("#202025")
};

outerColumn.AddChild(_column);
outerColumn.AddChild(Column);
baseContainer.AddChild(outerColumn);
baseContainer.AddChild(confirmButton);
Contents.AddChild(baseContainer);
}

public void Populate(ConfigurationBoundUserInterfaceState state)
{
_column.Children.Clear();
_inputs.Clear();

foreach (var field in state.Config)
{
var label = new Label
{
Margin = new Thickness(0, 0, 8, 0),
Name = field.Key,
Text = field.Key + ":",
VerticalAlignment = VAlignment.Center,
HorizontalExpand = true,
SizeFlagsStretchRatio = .2f,
MinSize = new Vector2(60, 0)
};

var input = new LineEdit
{
Name = field.Key + "-input",
Text = field.Value ?? "",
IsValid = Validate,
HorizontalExpand = true,
SizeFlagsStretchRatio = .8f
};

_inputs.Add((field.Key, input));

var row = new BoxContainer
{
Orientation = LayoutOrientation.Horizontal
};
CopyProperties(_row, row);

row.AddChild(label);
row.AddChild(input);
_column.AddChild(row);
}
}

private void OnConfirm(ButtonEventArgs args)
{
var config = GenerateDictionary(_inputs, "Text");
var config = GenerateDictionary(Inputs, "Text");
OnConfiguration?.Invoke(config);
Close();
}

private bool Validate(string value)
public bool Validate(string value)
{
return Validation?.IsMatch(value) != false;
}
Expand All @@ -140,7 +95,7 @@ private Dictionary<string, string> GenerateDictionary(IEnumerable<(string name,
return dictionary;
}

private static void CopyProperties<T>(T from, T to) where T : Control
public static void CopyProperties<T>(T from, T to) where T : Control
{
foreach (var property in from.AllAttachedProperties)
{
Expand Down
9 changes: 8 additions & 1 deletion Content.Client/Decals/DecalSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public sealed class DecalSystem : SharedDecalSystem
[Dependency] private readonly IOverlayManager _overlayManager = default!;
[Dependency] private readonly SpriteSystem _sprites = default!;

private DecalOverlay _overlay = default!;
private DecalOverlay? _overlay;

private HashSet<uint> _removedUids = new();
private readonly List<Vector2i> _removedChunks = new();
Expand All @@ -31,6 +31,9 @@ public override void Initialize()

public void ToggleOverlay()
{
if (_overlay == null)
return;

if (_overlayManager.HasOverlay<DecalOverlay>())
{
_overlayManager.RemoveOverlay(_overlay);
Expand All @@ -44,6 +47,10 @@ public void ToggleOverlay()
public override void Shutdown()
{
base.Shutdown();

if (_overlay == null)
return;

_overlayManager.RemoveOverlay(_overlay);
}

Expand Down
8 changes: 8 additions & 0 deletions Content.Client/DeviceNetwork/Systems/DeviceNetworkSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using Content.Shared.DeviceNetwork.Systems;

namespace Content.Client.DeviceNetwork.Systems;

public sealed class DeviceNetworkSystem : SharedDeviceNetworkSystem
{

}
9 changes: 0 additions & 9 deletions Content.Client/Disposal/DisposalUnitComponent.cs

This file was deleted.

90 changes: 90 additions & 0 deletions Content.Client/Disposal/Mailing/MailingUnitBoundUserInterface.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
using Content.Client.Disposal.Unit;
using Content.Client.Power.EntitySystems;
using Content.Shared.Disposal;
using Content.Shared.Disposal.Components;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using MailingUnitComponent = Content.Shared.Disposal.Components.MailingUnitComponent;

namespace Content.Client.Disposal.Mailing;

public sealed class MailingUnitBoundUserInterface : BoundUserInterface
{
[ViewVariables]
public MailingUnitWindow? MailingUnitWindow;

public MailingUnitBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
}

private void ButtonPressed(DisposalUnitComponent.UiButton button)
{
SendMessage(new DisposalUnitComponent.UiButtonPressedMessage(button));
// If we get client-side power stuff then we can predict the button presses but for now we won't as it stuffs
// the pressure lerp up.
}

private void TargetSelected(ItemList.ItemListSelectedEventArgs args)
{
var item = args.ItemList[args.ItemIndex];
SendMessage(new TargetSelectedMessage(item.Text));
}

protected override void Open()
{
base.Open();

MailingUnitWindow = this.CreateWindow<MailingUnitWindow>();
MailingUnitWindow.OpenCenteredRight();

MailingUnitWindow.Eject.OnPressed += _ => ButtonPressed(DisposalUnitComponent.UiButton.Eject);
MailingUnitWindow.Engage.OnPressed += _ => ButtonPressed(DisposalUnitComponent.UiButton.Engage);
MailingUnitWindow.Power.OnPressed += _ => ButtonPressed(DisposalUnitComponent.UiButton.Power);

MailingUnitWindow.TargetListContainer.OnItemSelected += TargetSelected;

if (EntMan.TryGetComponent(Owner, out MailingUnitComponent? component))
Refresh((Owner, component));
}

public void Refresh(Entity<MailingUnitComponent> entity)
{
if (MailingUnitWindow == null)
return;

// TODO: This should be decoupled from disposals
if (EntMan.TryGetComponent(entity.Owner, out DisposalUnitComponent? disposals))
{
var disposalSystem = EntMan.System<DisposalUnitSystem>();

var disposalState = disposalSystem.GetState(Owner, disposals);
var fullPressure = disposalSystem.EstimatedFullPressure(Owner, disposals);

MailingUnitWindow.UnitState.Text = Loc.GetString($"disposal-unit-state-{disposalState}");
MailingUnitWindow.FullPressure = fullPressure;
MailingUnitWindow.PressureBar.UpdatePressure(fullPressure);
MailingUnitWindow.Power.Pressed = EntMan.System<PowerReceiverSystem>().IsPowered(Owner);
MailingUnitWindow.Engage.Pressed = disposals.Engaged;
}

MailingUnitWindow.Title = Loc.GetString("ui-mailing-unit-window-title", ("tag", entity.Comp.Tag ?? " "));
//UnitTag.Text = state.Tag;
MailingUnitWindow.Target.Text = entity.Comp.Target;

MailingUnitWindow.TargetListContainer.Clear();
foreach (var target in entity.Comp.TargetList)
{
MailingUnitWindow.TargetListContainer.AddItem(target);
}
}

protected override void Dispose(bool disposing)
{
base.Dispose(disposing);

if (!disposing)
return;

MailingUnitWindow?.Dispose();
}
}
22 changes: 22 additions & 0 deletions Content.Client/Disposal/Mailing/MailingUnitSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Content.Shared.Disposal;
using Content.Shared.Disposal.Components;
using Content.Shared.Disposal.Mailing;

namespace Content.Client.Disposal.Mailing;

public sealed class MailingUnitSystem : SharedMailingUnitSystem
{
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<MailingUnitComponent, AfterAutoHandleStateEvent>(OnMailingState);
}

private void OnMailingState(Entity<MailingUnitComponent> ent, ref AfterAutoHandleStateEvent args)
{
if (UserInterfaceSystem.TryGetOpenUi<MailingUnitBoundUserInterface>(ent.Owner, MailingUnitUiKey.Key, out var bui))
{
bui.Refresh(ent);
}
}
}
Loading

0 comments on commit 77877aa

Please sign in to comment.