From 3e7e44df29585ce2a9060c0f06b16e7888db9edd Mon Sep 17 00:00:00 2001 From: Acruid Date: Fri, 26 Mar 2021 17:10:31 -0700 Subject: [PATCH] Removed Control.Update, moved all update code to Control.FrameUpdate. UI controls have no business running code inside simulation Ticks. Because of how the update loop is ordered, this will actually make the UI elements more responsive to simulation changes. Fixed multiple bugs in the action UI where the Control.Update method was calling the base Control.FrameUpdate. --- .../Components/Atmos/GasAnalyzerComponent.cs | 14 +++++++------- .../Components/Chemistry/HyposprayComponent.cs | 7 ++++--- .../Components/Chemistry/InjectorComponent.cs | 6 +++--- .../Components/Crayon/CrayonComponent.cs | 6 +++--- .../Components/HandheldLightComponent.cs | 6 +++--- .../Components/Interactable/MultiToolComponent.cs | 6 +++--- .../Components/Interactable/WelderComponent.cs | 5 +++-- .../GameObjects/Components/StackComponent.cs | 6 +++--- .../HealthOverlay/HealthOverlayGui.cs | 8 ++++---- Content.Client/Instruments/InstrumentMenu.xaml.cs | 4 ++-- Content.Client/UserInterface/ActionMenu.cs | 4 ++-- Content.Client/UserInterface/ActionsUI.cs | 4 ++-- Resources/Locale/en-US/atmos.ftl | 3 ++- 13 files changed, 41 insertions(+), 38 deletions(-) diff --git a/Content.Client/GameObjects/Components/Atmos/GasAnalyzerComponent.cs b/Content.Client/GameObjects/Components/Atmos/GasAnalyzerComponent.cs index 1a74adb679..4f35a487d2 100644 --- a/Content.Client/GameObjects/Components/Atmos/GasAnalyzerComponent.cs +++ b/Content.Client/GameObjects/Components/Atmos/GasAnalyzerComponent.cs @@ -1,4 +1,4 @@ -using Content.Client.UserInterface.Stylesheets; +using Content.Client.UserInterface.Stylesheets; using Content.Client.Utility; using Content.Shared.GameObjects.Components; using Robust.Client.UserInterface; @@ -14,13 +14,14 @@ namespace Content.Client.GameObjects.Components.Atmos internal class GasAnalyzerComponent : SharedGasAnalyzerComponent, IItemStatus { [ViewVariables(VVAccess.ReadWrite)] private bool _uiUpdateNeeded; - [ViewVariables] public GasAnalyzerDanger Danger { get; private set; } + [ViewVariables] private GasAnalyzerDanger Danger { get; set; } Control IItemStatus.MakeControl() { return new StatusControl(this); } + /// public override void HandleComponentState(ComponentState? curState, ComponentState? nextState) { if (curState is not GasAnalyzerComponentState state) @@ -44,9 +45,10 @@ namespace Content.Client.GameObjects.Components.Atmos parent._uiUpdateNeeded = true; } - protected override void Update(FrameEventArgs args) + /// + protected override void FrameUpdate(FrameEventArgs args) { - base.Update(args); + base.FrameUpdate(args); if (!_parent._uiUpdateNeeded) { @@ -62,9 +64,7 @@ namespace Content.Client.GameObjects.Components.Atmos _ => "green", }; - _label.SetMarkup(Loc.GetString("Pressure: [color={0}]{1}[/color]", - color, - _parent.Danger)); + _label.SetMarkup(Loc.GetString("itemstatus-pressure-warn", ("color", color), ("danger", _parent.Danger))); } } } diff --git a/Content.Client/GameObjects/Components/Chemistry/HyposprayComponent.cs b/Content.Client/GameObjects/Components/Chemistry/HyposprayComponent.cs index 2d1ff9cdb5..c9a9aeb984 100644 --- a/Content.Client/GameObjects/Components/Chemistry/HyposprayComponent.cs +++ b/Content.Client/GameObjects/Components/Chemistry/HyposprayComponent.cs @@ -1,4 +1,4 @@ -using Content.Client.UserInterface.Stylesheets; +using Content.Client.UserInterface.Stylesheets; using Content.Client.Utility; using Content.Shared.Chemistry; using Content.Shared.GameObjects.Components.Chemistry; @@ -47,9 +47,10 @@ namespace Content.Client.GameObjects.Components.Chemistry parent._uiUpdateNeeded = true; } - protected override void Update(FrameEventArgs args) + /// + protected override void FrameUpdate(FrameEventArgs args) { - base.Update(args); + base.FrameUpdate(args); if (!_parent._uiUpdateNeeded) { return; diff --git a/Content.Client/GameObjects/Components/Chemistry/InjectorComponent.cs b/Content.Client/GameObjects/Components/Chemistry/InjectorComponent.cs index ca9f99dbaf..c3e037f167 100644 --- a/Content.Client/GameObjects/Components/Chemistry/InjectorComponent.cs +++ b/Content.Client/GameObjects/Components/Chemistry/InjectorComponent.cs @@ -1,4 +1,4 @@ -using Content.Client.UserInterface.Stylesheets; +using Content.Client.UserInterface.Stylesheets; using Content.Client.Utility; using Content.Shared.Chemistry; using Content.Shared.GameObjects.Components.Chemistry; @@ -57,9 +57,9 @@ namespace Content.Client.GameObjects.Components.Chemistry parent._uiUpdateNeeded = true; } - protected override void Update(FrameEventArgs args) + protected override void FrameUpdate(FrameEventArgs args) { - base.Update(args); + base.FrameUpdate(args); if (!_parent._uiUpdateNeeded) { return; diff --git a/Content.Client/GameObjects/Components/Crayon/CrayonComponent.cs b/Content.Client/GameObjects/Components/Crayon/CrayonComponent.cs index 5559b22633..dbc091e0e9 100644 --- a/Content.Client/GameObjects/Components/Crayon/CrayonComponent.cs +++ b/Content.Client/GameObjects/Components/Crayon/CrayonComponent.cs @@ -1,4 +1,4 @@ -using Content.Client.UserInterface.Stylesheets; +using Content.Client.UserInterface.Stylesheets; using Content.Client.Utility; using Content.Shared.GameObjects.Components; using Robust.Client.UserInterface; @@ -51,9 +51,9 @@ namespace Content.Client.GameObjects.Components.Crayon parent._uiUpdateNeeded = true; } - protected override void Update(FrameEventArgs args) + protected override void FrameUpdate(FrameEventArgs args) { - base.Update(args); + base.FrameUpdate(args); if (!_parent._uiUpdateNeeded) { diff --git a/Content.Client/GameObjects/Components/HandheldLightComponent.cs b/Content.Client/GameObjects/Components/HandheldLightComponent.cs index cf2af86113..b001a37430 100644 --- a/Content.Client/GameObjects/Components/HandheldLightComponent.cs +++ b/Content.Client/GameObjects/Components/HandheldLightComponent.cs @@ -1,4 +1,4 @@ -using Content.Shared.GameObjects.Components; +using Content.Shared.GameObjects.Components; using Robust.Client.Graphics; using Robust.Client.UserInterface; using Robust.Client.UserInterface.Controls; @@ -70,9 +70,9 @@ namespace Content.Client.GameObjects.Components } } - protected override void Update(FrameEventArgs args) + protected override void FrameUpdate(FrameEventArgs args) { - base.Update(args); + base.FrameUpdate(args); if (!_parent.HasCell) return; diff --git a/Content.Client/GameObjects/Components/Interactable/MultiToolComponent.cs b/Content.Client/GameObjects/Components/Interactable/MultiToolComponent.cs index 354cc053db..33a9954ae5 100644 --- a/Content.Client/GameObjects/Components/Interactable/MultiToolComponent.cs +++ b/Content.Client/GameObjects/Components/Interactable/MultiToolComponent.cs @@ -1,4 +1,4 @@ -using Content.Client.UserInterface.Stylesheets; +using Content.Client.UserInterface.Stylesheets; using Content.Client.Utility; using Content.Shared.GameObjects; using Content.Shared.GameObjects.Components.Interactable; @@ -52,9 +52,9 @@ namespace Content.Client.GameObjects.Components.Interactable parent._uiUpdateNeeded = true; } - protected override void Update(FrameEventArgs args) + protected override void FrameUpdate(FrameEventArgs args) { - base.Update(args); + base.FrameUpdate(args); if (!_parent._uiUpdateNeeded) { diff --git a/Content.Client/GameObjects/Components/Interactable/WelderComponent.cs b/Content.Client/GameObjects/Components/Interactable/WelderComponent.cs index df4043dbcf..feb17bf20e 100644 --- a/Content.Client/GameObjects/Components/Interactable/WelderComponent.cs +++ b/Content.Client/GameObjects/Components/Interactable/WelderComponent.cs @@ -55,9 +55,10 @@ namespace Content.Client.GameObjects.Components.Interactable parent._uiUpdateNeeded = true; } - protected override void Update(FrameEventArgs args) + /// + protected override void FrameUpdate(FrameEventArgs args) { - base.Update(args); + base.FrameUpdate(args); if (!_parent._uiUpdateNeeded) { diff --git a/Content.Client/GameObjects/Components/StackComponent.cs b/Content.Client/GameObjects/Components/StackComponent.cs index ab82d64059..fb132614ba 100644 --- a/Content.Client/GameObjects/Components/StackComponent.cs +++ b/Content.Client/GameObjects/Components/StackComponent.cs @@ -1,4 +1,4 @@ -#nullable enable +#nullable enable using Content.Client.UserInterface.Stylesheets; using Content.Client.Utility; @@ -65,9 +65,9 @@ namespace Content.Client.GameObjects.Components parent._uiUpdateNeeded = true; } - protected override void Update(FrameEventArgs args) + protected override void FrameUpdate(FrameEventArgs args) { - base.Update(args); + base.FrameUpdate(args); if (!_parent._uiUpdateNeeded) { diff --git a/Content.Client/GameObjects/EntitySystems/HealthOverlay/HealthOverlayGui.cs b/Content.Client/GameObjects/EntitySystems/HealthOverlay/HealthOverlayGui.cs index c38c390633..3480d32381 100644 --- a/Content.Client/GameObjects/EntitySystems/HealthOverlay/HealthOverlayGui.cs +++ b/Content.Client/GameObjects/EntitySystems/HealthOverlay/HealthOverlayGui.cs @@ -1,4 +1,4 @@ -#nullable enable +#nullable enable using Content.Client.Utility; using Content.Shared.GameObjects.Components.Damage; using Content.Shared.GameObjects.Components.Mobs.State; @@ -69,10 +69,8 @@ namespace Content.Client.GameObjects.EntitySystems.HealthOverlay Panel.Visible = val; } - protected override void Update(FrameEventArgs args) + private void MoreFrameUpdate(FrameEventArgs args) { - base.Update(args); - if (Entity.Deleted) { return; @@ -137,6 +135,8 @@ namespace Content.Client.GameObjects.EntitySystems.HealthOverlay { base.FrameUpdate(args); + MoreFrameUpdate(args); + if (Entity.Deleted || _eyeManager.CurrentMap != Entity.Transform.MapID) { diff --git a/Content.Client/Instruments/InstrumentMenu.xaml.cs b/Content.Client/Instruments/InstrumentMenu.xaml.cs index 6dac2cdbce..8ddcdeacd1 100644 --- a/Content.Client/Instruments/InstrumentMenu.xaml.cs +++ b/Content.Client/Instruments/InstrumentMenu.xaml.cs @@ -179,9 +179,9 @@ namespace Content.Client.Instruments _owner.Instrument.PlayerTick = (int)Math.Ceiling(PlaybackSlider.Value); } - protected override void Update(FrameEventArgs args) + protected override void FrameUpdate(FrameEventArgs args) { - base.Update(args); + base.FrameUpdate(args); if (_owner.Instrument == null) return; diff --git a/Content.Client/UserInterface/ActionMenu.cs b/Content.Client/UserInterface/ActionMenu.cs index 30d4413a70..fda8e7ad9d 100644 --- a/Content.Client/UserInterface/ActionMenu.cs +++ b/Content.Client/UserInterface/ActionMenu.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Globalization; using System.Linq; @@ -510,7 +510,7 @@ namespace Content.Client.UserInterface protected override void FrameUpdate(FrameEventArgs args) { - base.Update(args); + base.FrameUpdate(args); _dragDropHelper.Update(args.DeltaSeconds); } } diff --git a/Content.Client/UserInterface/ActionsUI.cs b/Content.Client/UserInterface/ActionsUI.cs index 9f7768b878..322b4fc894 100644 --- a/Content.Client/UserInterface/ActionsUI.cs +++ b/Content.Client/UserInterface/ActionsUI.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using Content.Client.GameObjects.Components.Mobs; using Content.Client.GameObjects.Components.Mobs.Actions; using Content.Client.UserInterface.Controls; @@ -576,7 +576,7 @@ namespace Content.Client.UserInterface protected override void FrameUpdate(FrameEventArgs args) { - base.Update(args); + base.FrameUpdate(args); DragDropHelper.Update(args.DeltaSeconds); } } diff --git a/Resources/Locale/en-US/atmos.ftl b/Resources/Locale/en-US/atmos.ftl index 73e1dfe70a..d63239b896 100644 --- a/Resources/Locale/en-US/atmos.ftl +++ b/Resources/Locale/en-US/atmos.ftl @@ -2,4 +2,5 @@ ### UI # Used for GasEntry.ToString() -gas-entry-info = {$gasName}: {$gasAmount} mol \ No newline at end of file +gas-entry-info = {$gasName}: {$gasAmount} mol +itemstatus-pressure-warn = Pressure: [color={$color}]{$danger}[/color] \ No newline at end of file