Skip to content

Commit 3a2cd95

Browse files
authored
Fix solution editor UI (space-wizards#24004)
Fixes space-wizards#23645 The problem is that the solution editor UI is an EUI, so the UI updates before the game states are applied. A correct fix would be to move it to a BUI in some way, but that's a little involved as we don't really have pre-existing code that uses BUIs in a manner good for this. I decided against this because I realized we'd want to have more tools similar to this and tbh I kinda figured integrating it with VV would be a better fix instead, so... This is a bad workaround to manually synchronize the UI updates against game timing. It's not pretty but it works.
1 parent 2375a6c commit 3a2cd95

File tree

4 files changed

+35
-5
lines changed

4 files changed

+35
-5
lines changed

‎Content.Client/Administration/UI/ManageSolutions/EditSolutionsEui.cs‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ public override void Closed()
3434
public override void HandleState(EuiStateBase baseState)
3535
{
3636
var state = (EditSolutionsEuiState) baseState;
37-
_window.SetTargetEntity(state.Target);
38-
_window.UpdateSolutions(state.Solutions);
39-
_window.UpdateReagents();
37+
_window.SetState(state);
4038
}
4139
}
4240
}

‎Content.Client/Administration/UI/ManageSolutions/EditSolutionsWindow.xaml.cs‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
using Content.Shared.Administration;
12
using Content.Shared.Chemistry.Components;
23
using Content.Shared.Chemistry.Reagent;
34
using Robust.Client.AutoGenerated;
45
using Robust.Client.Console;
6+
using Robust.Client.Timing;
57
using Robust.Client.UserInterface.Controls;
68
using Robust.Client.UserInterface.CustomControls;
79
using Robust.Client.UserInterface.XAML;
10+
using Robust.Shared.Timing;
811

912
namespace Content.Client.Administration.UI.ManageSolutions
1013
{
@@ -16,11 +19,13 @@ public sealed partial class EditSolutionsWindow : DefaultWindow
1619
{
1720
[Dependency] private readonly IClientConsoleHost _consoleHost = default!;
1821
[Dependency] private readonly IEntityManager _entityManager = default!;
22+
[Dependency] private readonly IClientGameTiming _timing = default!;
1923

2024
private NetEntity _target = NetEntity.Invalid;
2125
private string? _selectedSolution;
2226
private AddReagentWindow? _addReagentWindow;
2327
private Dictionary<string, EntityUid>? _solutions;
28+
private EditSolutionsEuiState? _nextState;
2429

2530
public EditSolutionsWindow()
2631
{
@@ -327,5 +332,27 @@ public void UpdateSolutions(List<(string, NetEntity)>? solutions)
327332
SolutionOption.Select(selectedIndex);
328333
_selectedSolution = (string?) SolutionOption.SelectedMetadata;
329334
}
335+
336+
protected override void FrameUpdate(FrameEventArgs args)
337+
{
338+
// TODO: THIS IS FUCKING TERRIBLE.
339+
// Ok so the problem is that this shouldn't be via an EUI at all. Why?
340+
// The EUI update notification comes in *before* the game state it updates from.
341+
// So the UI doesn't update properly. Heck.
342+
// I didn't wanna completely rewrite this thing to work properly so instead you get terrible hacks.
343+
344+
if (_nextState != null && _timing.LastRealTick >= _nextState.Tick)
345+
{
346+
SetTargetEntity(_nextState.Target);
347+
UpdateSolutions(_nextState.Solutions);
348+
UpdateReagents();
349+
_nextState = null;
350+
}
351+
}
352+
353+
public void SetState(EditSolutionsEuiState state)
354+
{
355+
_nextState = state;
356+
}
330357
}
331358
}

‎Content.Server/Administration/UI/EditSolutionsEui.cs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Content.Shared.Chemistry.Components.SolutionManager;
66
using Content.Shared.Eui;
77
using JetBrains.Annotations;
8+
using Robust.Shared.Timing;
89

910
namespace Content.Server.Administration.UI
1011
{
@@ -15,6 +16,7 @@ namespace Content.Server.Administration.UI
1516
public sealed class EditSolutionsEui : BaseEui
1617
{
1718
[Dependency] private readonly IEntityManager _entityManager = default!;
19+
[Dependency] private readonly IGameTiming _gameTiming = default!;
1820
private readonly SolutionContainerSystem _solutionContainerSystem = default!;
1921
public readonly EntityUid Target;
2022

@@ -55,7 +57,7 @@ public override EuiStateBase GetNewState()
5557
else
5658
netSolutions = null;
5759

58-
return new EditSolutionsEuiState(_entityManager.GetNetEntity(Target), netSolutions);
60+
return new EditSolutionsEuiState(_entityManager.GetNetEntity(Target), netSolutions, _gameTiming.CurTick);
5961
}
6062
}
6163
}
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Content.Shared.Eui;
22
using Robust.Shared.Serialization;
3+
using Robust.Shared.Timing;
34

45
namespace Content.Shared.Administration
56
{
@@ -8,11 +9,13 @@ public sealed class EditSolutionsEuiState : EuiStateBase
89
{
910
public readonly NetEntity Target;
1011
public readonly List<(string, NetEntity)>? Solutions;
12+
public readonly GameTick Tick;
1113

12-
public EditSolutionsEuiState(NetEntity target, List<(string, NetEntity)>? solutions)
14+
public EditSolutionsEuiState(NetEntity target, List<(string, NetEntity)>? solutions, GameTick tick)
1315
{
1416
Target = target;
1517
Solutions = solutions;
18+
Tick = tick;
1619
}
1720
}
1821
}

0 commit comments

Comments
 (0)