Fix DoAfter flicker (#3643)

Co-authored-by: Metal Gear Sloth <metalgearsloth@gmail.com>
This commit is contained in:
metalgearsloth
2021-03-16 19:16:55 +11:00
committed by GitHub
parent 7193a6fed2
commit d4dede2755
2 changed files with 11 additions and 18 deletions

View File

@@ -2,6 +2,8 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using Content.Client.GameObjects.EntitySystems.DoAfter; using Content.Client.GameObjects.EntitySystems.DoAfter;
using Content.Shared.GameObjects.Components; using Content.Shared.GameObjects.Components;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.IoC; using Robust.Shared.IoC;
using Robust.Shared.Network; using Robust.Shared.Network;
@@ -53,7 +55,7 @@ namespace Content.Client.GameObjects.Components
if (Gui?.Disposed == false) if (Gui?.Disposed == false)
return; return;
Gui = new DoAfterGui {AttachedEntity = Owner, FirstDraw = true}; Gui = new DoAfterGui {AttachedEntity = Owner};
foreach (var (_, doAfter) in _doAfters) foreach (var (_, doAfter) in _doAfters)
{ {

View File

@@ -30,10 +30,6 @@ namespace Content.Client.GameObjects.EntitySystems.DoAfter
public IEntity? AttachedEntity { get; set; } public IEntity? AttachedEntity { get; set; }
private ScreenCoordinates _playerPosition; private ScreenCoordinates _playerPosition;
// This behavior probably shouldn't be happening; so for whatever reason the control position is set the frame after
// I got NFI why because I don't know the UI internals
public bool FirstDraw { get; set; }
public DoAfterGui() public DoAfterGui()
{ {
IoCManager.InjectDependencies(this); IoCManager.InjectDependencies(this);
@@ -151,12 +147,16 @@ namespace Content.Client.GameObjects.EntitySystems.DoAfter
if (AttachedEntity?.IsValid() != true || if (AttachedEntity?.IsValid() != true ||
!AttachedEntity.TryGetComponent(out DoAfterComponent? doAfterComponent)) !AttachedEntity.TryGetComponent(out DoAfterComponent? doAfterComponent))
{ {
Visible = false;
return; return;
} }
var doAfters = doAfterComponent.DoAfters; var doAfters = doAfterComponent.DoAfters;
if (doAfters.Count == 0) if (doAfters.Count == 0)
{
Visible = false;
return; return;
}
if (_eyeManager.CurrentMap != AttachedEntity.Transform.MapID || if (_eyeManager.CurrentMap != AttachedEntity.Transform.MapID ||
!AttachedEntity.Transform.Coordinates.IsValid(_entityManager)) !AttachedEntity.Transform.Coordinates.IsValid(_entityManager))
@@ -169,19 +169,6 @@ namespace Content.Client.GameObjects.EntitySystems.DoAfter
Visible = true; Visible = true;
} }
// Set position ready for 2nd+ frames.
var screenCoordinates = _eyeManager.CoordinatesToScreen(AttachedEntity.Transform.Coordinates);
_playerPosition = new ScreenCoordinates(screenCoordinates.X / UIScale, screenCoordinates.Y / UIScale);
LayoutContainer.SetPosition(this, new Vector2(_playerPosition.X - Width / 2, _playerPosition.Y - Height - 30.0f));
if (FirstDraw)
{
Visible = false;
FirstDraw = false;
return;
}
Visible = true;
var currentTime = _gameTiming.CurTime; var currentTime = _gameTiming.CurTime;
var toRemove = new List<byte>(); var toRemove = new List<byte>();
@@ -221,6 +208,10 @@ namespace Content.Client.GameObjects.EntitySystems.DoAfter
{ {
RemoveDoAfter(id); RemoveDoAfter(id);
} }
var screenCoordinates = _eyeManager.CoordinatesToScreen(AttachedEntity.Transform.Coordinates);
_playerPosition = new ScreenCoordinates(screenCoordinates.X / UIScale, screenCoordinates.Y / UIScale);
LayoutContainer.SetPosition(this, new Vector2(_playerPosition.X - Width / 2, _playerPosition.Y - Height - 30.0f));
} }
} }
} }