Fix do-after flicker (#10020)
This commit is contained in:
@@ -6,6 +6,7 @@ using JetBrains.Annotations;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.Player;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
@@ -72,6 +72,7 @@ namespace Content.Client.DoAfter.UI
|
||||
{
|
||||
IoCManager.InjectDependencies(this);
|
||||
_shader = IoCManager.Resolve<IPrototypeManager>().Index<ShaderPrototype>("unshaded").Instance();
|
||||
VerticalAlignment = VAlignment.Center;
|
||||
}
|
||||
|
||||
protected override void FrameUpdate(FrameEventArgs args)
|
||||
|
||||
45
Content.Client/DoAfter/UI/DoAfterControl.cs
Normal file
45
Content.Client/DoAfter/UI/DoAfterControl.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using Content.Client.Resources;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.ResourceManagement;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Client.DoAfter.UI;
|
||||
|
||||
public sealed class DoAfterControl : PanelContainer
|
||||
{
|
||||
public float Ratio
|
||||
{
|
||||
get => _bar.Ratio;
|
||||
set => _bar.Ratio = value;
|
||||
}
|
||||
|
||||
public bool Cancelled
|
||||
{
|
||||
get => _bar.Cancelled;
|
||||
set => _bar.Cancelled = value;
|
||||
}
|
||||
|
||||
private DoAfterBar _bar;
|
||||
|
||||
public DoAfterControl()
|
||||
{
|
||||
IoCManager.InjectDependencies(this);
|
||||
|
||||
var cache = IoCManager.Resolve<IResourceCache>();
|
||||
|
||||
AddChild(new TextureRect
|
||||
{
|
||||
Texture = cache.GetTexture("/Textures/Interface/Misc/progress_bar.rsi/icon.png"),
|
||||
TextureScale = Vector2.One * DoAfterBar.DoAfterBarScale,
|
||||
VerticalAlignment = VAlignment.Center,
|
||||
});
|
||||
|
||||
_bar = new DoAfterBar();
|
||||
AddChild(_bar);
|
||||
VerticalAlignment = VAlignment.Bottom;
|
||||
_bar.Measure(Vector2.Infinity);
|
||||
Measure(Vector2.Infinity);
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Content.Client.IoC;
|
||||
using Content.Client.Resources;
|
||||
using Content.Shared.DoAfter;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Client.DoAfter.UI
|
||||
{
|
||||
@@ -21,14 +12,12 @@ namespace Content.Client.DoAfter.UI
|
||||
[Dependency] private readonly IEyeManager _eyeManager = default!;
|
||||
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||
|
||||
private readonly Dictionary<byte, PanelContainer> _doAfterControls = new();
|
||||
private readonly Dictionary<byte, DoAfterBar> _doAfterBars = new();
|
||||
private readonly Dictionary<byte, DoAfterControl> _doAfterControls = new();
|
||||
|
||||
// We'll store cancellations for a little bit just so we can flash the graphic to indicate it's cancelled
|
||||
private readonly Dictionary<byte, TimeSpan> _cancelledDoAfters = new();
|
||||
|
||||
public EntityUid AttachedEntity { get; set; }
|
||||
private ScreenCoordinates _playerPosition;
|
||||
public EntityUid? AttachedEntity { get; set; }
|
||||
|
||||
public DoAfterGui()
|
||||
{
|
||||
@@ -37,8 +26,6 @@ namespace Content.Client.DoAfter.UI
|
||||
IoCManager.InjectDependencies(this);
|
||||
IoCManager.Resolve<IUserInterfaceManager>().StateRoot.AddChild(this);
|
||||
SeparationOverride = 0;
|
||||
|
||||
LayoutContainer.SetGrowVertical(this, LayoutContainer.GrowDirection.Begin);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
@@ -53,43 +40,21 @@ namespace Content.Client.DoAfter.UI
|
||||
}
|
||||
|
||||
_doAfterControls.Clear();
|
||||
_doAfterBars.Clear();
|
||||
_cancelledDoAfters.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add the necessary control for a DoAfter progress bar.
|
||||
/// </summary>
|
||||
/// <param name="message"></param>
|
||||
public void AddDoAfter(ClientDoAfter message)
|
||||
{
|
||||
if (_doAfterControls.ContainsKey(message.ID))
|
||||
return;
|
||||
|
||||
var doAfterBar = new DoAfterBar
|
||||
{
|
||||
VerticalAlignment = VAlignment.Center
|
||||
};
|
||||
|
||||
_doAfterBars[message.ID] = doAfterBar;
|
||||
|
||||
var control = new PanelContainer
|
||||
{
|
||||
Children =
|
||||
{
|
||||
new TextureRect
|
||||
{
|
||||
Texture = StaticIoC.ResC.GetTexture("/Textures/Interface/Misc/progress_bar.rsi/icon.png"),
|
||||
TextureScale = Vector2.One * DoAfterBar.DoAfterBarScale,
|
||||
VerticalAlignment = VAlignment.Center,
|
||||
},
|
||||
|
||||
doAfterBar
|
||||
}
|
||||
};
|
||||
|
||||
AddChild(control);
|
||||
_doAfterControls.Add(message.ID, control);
|
||||
var doAfterBar = new DoAfterControl();
|
||||
AddChild(doAfterBar);
|
||||
_doAfterControls.Add(message.ID, doAfterBar);
|
||||
Measure(Vector2.Infinity);
|
||||
}
|
||||
|
||||
// NOTE THAT THE BELOW ONLY HANDLES THE UI SIDE
|
||||
@@ -107,8 +72,6 @@ namespace Content.Client.DoAfter.UI
|
||||
RemoveChild(control);
|
||||
control.DisposeAllChildren();
|
||||
_doAfterControls.Remove(id);
|
||||
_doAfterBars.Remove(id);
|
||||
|
||||
_cancelledDoAfters.Remove(id);
|
||||
}
|
||||
|
||||
@@ -122,23 +85,13 @@ namespace Content.Client.DoAfter.UI
|
||||
if (_cancelledDoAfters.ContainsKey(id))
|
||||
return;
|
||||
|
||||
DoAfterBar doAfterBar;
|
||||
|
||||
if (!_doAfterControls.TryGetValue(id, out var doAfterControl))
|
||||
{
|
||||
doAfterControl = new PanelContainer();
|
||||
doAfterControl = new DoAfterControl();
|
||||
AddChild(doAfterControl);
|
||||
DebugTools.Assert(!_doAfterBars.ContainsKey(id));
|
||||
doAfterBar = new DoAfterBar();
|
||||
doAfterControl.AddChild(doAfterBar);
|
||||
_doAfterBars[id] = doAfterBar;
|
||||
}
|
||||
else
|
||||
{
|
||||
doAfterBar = _doAfterBars[id];
|
||||
}
|
||||
|
||||
doAfterBar.Cancelled = true;
|
||||
doAfterControl.Cancelled = true;
|
||||
_cancelledDoAfters.Add(id, _gameTiming.CurTime);
|
||||
}
|
||||
|
||||
@@ -146,32 +99,29 @@ namespace Content.Client.DoAfter.UI
|
||||
{
|
||||
base.FrameUpdate(args);
|
||||
|
||||
if (!AttachedEntity.IsValid() ||
|
||||
!_entityManager.TryGetComponent(AttachedEntity, out DoAfterComponent? doAfterComponent))
|
||||
if (!_entityManager.TryGetComponent(AttachedEntity, out DoAfterComponent? doAfterComponent))
|
||||
{
|
||||
Visible = false;
|
||||
return;
|
||||
}
|
||||
|
||||
var doAfters = doAfterComponent.DoAfters;
|
||||
|
||||
if (doAfters.Count == 0)
|
||||
{
|
||||
Visible = false;
|
||||
return;
|
||||
}
|
||||
|
||||
var transform = _entityManager.GetComponent<TransformComponent>(AttachedEntity);
|
||||
var transform = _entityManager.GetComponent<TransformComponent>(AttachedEntity.Value);
|
||||
|
||||
if (_eyeManager.CurrentMap != transform.MapID || !transform.Coordinates.IsValid(_entityManager))
|
||||
{
|
||||
Visible = false;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
Visible = true;
|
||||
}
|
||||
|
||||
Visible = true;
|
||||
var currentTime = _gameTiming.CurTime;
|
||||
var toRemove = new List<byte>();
|
||||
|
||||
@@ -195,15 +145,16 @@ namespace Content.Client.DoAfter.UI
|
||||
if (_cancelledDoAfters.ContainsKey(id) || !_doAfterControls.ContainsKey(id))
|
||||
continue;
|
||||
|
||||
var doAfterBar = _doAfterBars[id];
|
||||
var control = _doAfterControls[id];
|
||||
var ratio = (currentTime - message.StartTime).TotalSeconds;
|
||||
doAfterBar.Ratio = MathF.Min(1.0f,
|
||||
control.Ratio = MathF.Min(1.0f,
|
||||
(float) ratio / message.Delay);
|
||||
|
||||
// Just in case it doesn't get cleaned up by the system for whatever reason.
|
||||
if (ratio > message.Delay + DoAfterSystem.ExcessTime)
|
||||
{
|
||||
toRemove.Add(id);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -212,9 +163,14 @@ namespace Content.Client.DoAfter.UI
|
||||
RemoveDoAfter(id);
|
||||
}
|
||||
|
||||
var screenCoordinates = _eyeManager.CoordinatesToScreen(transform.Coordinates);
|
||||
_playerPosition = new ScreenCoordinates(screenCoordinates.Position / UIScale, screenCoordinates.Window);
|
||||
LayoutContainer.SetPosition(this, new Vector2(_playerPosition.X - Width / 2, _playerPosition.Y - Height - 30.0f));
|
||||
UpdatePosition(transform);
|
||||
}
|
||||
|
||||
public void UpdatePosition(TransformComponent xform)
|
||||
{
|
||||
var screenCoordinates = _eyeManager.CoordinatesToScreen(xform.Coordinates);
|
||||
var position = screenCoordinates.Position / UIScale - DesiredSize / 2f;
|
||||
LayoutContainer.SetPosition(this, position - new Vector2(0, 40f));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user