Skip to content

Commit

Permalink
Merge pull request #1552 from space-syndicate/upstream-sync
Browse files Browse the repository at this point in the history
Upstream sync
  • Loading branch information
Morb0 authored Nov 4, 2023
2 parents 5469489 + a64291b commit 8b85567
Show file tree
Hide file tree
Showing 764 changed files with 19,220 additions and 13,326 deletions.
1 change: 1 addition & 0 deletions Content.Client/Actions/ActionsSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ private void BaseHandleState<T>(EntityUid uid, BaseActionComponent component, Ba
component.ClientExclusive = state.ClientExclusive;
component.Priority = state.Priority;
component.AttachedEntity = EnsureEntity<T>(state.AttachedEntity, uid);
component.RaiseOnUser = state.RaiseOnUser;
component.AutoPopulate = state.AutoPopulate;
component.Temporary = state.Temporary;
component.ItemIconStyle = state.ItemIconStyle;
Expand Down
31 changes: 23 additions & 8 deletions Content.Client/DoAfter/DoAfterOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Robust.Client.Graphics;
using Robust.Shared.Enums;
using Robust.Shared.Graphics;
using Robust.Client.Player;
using Robust.Shared.Prototypes;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
Expand All @@ -14,6 +15,7 @@ public sealed class DoAfterOverlay : Overlay
{
private readonly IEntityManager _entManager;
private readonly IGameTiming _timing;
private readonly IPlayerManager _player;
private readonly SharedTransformSystem _transform;
private readonly MetaDataSystem _meta;

Expand All @@ -31,13 +33,14 @@ public sealed class DoAfterOverlay : Overlay

public override OverlaySpace Space => OverlaySpace.WorldSpaceBelowFOV;

public DoAfterOverlay(IEntityManager entManager, IPrototypeManager protoManager, IGameTiming timing)
public DoAfterOverlay(IEntityManager entManager, IPrototypeManager protoManager, IGameTiming timing, IPlayerManager player)
{
_entManager = entManager;
_timing = timing;
_player = player;
_transform = _entManager.EntitySysManager.GetEntitySystem<SharedTransformSystem>();
_meta = _entManager.EntitySysManager.GetEntitySystem<MetaDataSystem>();
var sprite = new SpriteSpecifier.Rsi(new ("/Textures/Interface/Misc/progress_bar.rsi"), "icon");
var sprite = new SpriteSpecifier.Rsi(new("/Textures/Interface/Misc/progress_bar.rsi"), "icon");
_barTexture = _entManager.EntitySysManager.GetEntitySystem<SpriteSystem>().Frame0(sprite);

_shader = protoManager.Index<ShaderPrototype>("unshaded").Instance();
Expand All @@ -58,6 +61,7 @@ protected override void Draw(in OverlayDrawArgs args)
var curTime = _timing.CurTime;

var bounds = args.WorldAABB.Enlarged(5f);
var localEnt = _player.LocalSession?.AttachedEntity;

var metaQuery = _entManager.GetEntityQuery<MetaDataComponent>();
var enumerator = _entManager.AllEntityQueryEnumerator<ActiveDoAfterComponent, DoAfterComponent, SpriteComponent, TransformComponent>();
Expand Down Expand Up @@ -88,6 +92,17 @@ protected override void Draw(in OverlayDrawArgs args)

foreach (var doAfter in comp.DoAfters.Values)
{
// Hide some DoAfters from other players for stealthy actions (ie: thieving gloves)
var alpha = 1f;
if (doAfter.Args.Hidden)
{
if (uid != localEnt)
continue;

// Hints to the local player that this do-after is not visible to other players.
alpha = 0.5f;
}

// Use the sprite itself if we know its bounds. This means short or tall sprites don't get overlapped
// by the bar.
float yOffset = sprite.Bounds.Height / 2f + 0.05f;
Expand All @@ -108,15 +123,15 @@ protected override void Draw(in OverlayDrawArgs args)
{
var elapsed = doAfter.CancelledTime.Value - doAfter.StartTime;
elapsedRatio = (float) Math.Min(1, elapsed.TotalSeconds / doAfter.Args.Delay.TotalSeconds);
var cancelElapsed = (time - doAfter.CancelledTime.Value).TotalSeconds;
var cancelElapsed = (time - doAfter.CancelledTime.Value).TotalSeconds;
var flash = Math.Floor(cancelElapsed / FlashTime) % 2 == 0;
color = new Color(1f, 0f, 0f, flash ? 1f : 0f);
color = new Color(1f, 0f, 0f, flash ? alpha : 0f);
}
else
{
var elapsed = time - doAfter.StartTime;
elapsedRatio = (float) Math.Min(1, elapsed.TotalSeconds / doAfter.Args.Delay.TotalSeconds);
color = GetProgressColor(elapsedRatio);
color = GetProgressColor(elapsedRatio, alpha);
}

var xProgress = (EndX - StartX) * elapsedRatio + StartX;
Expand All @@ -131,14 +146,14 @@ protected override void Draw(in OverlayDrawArgs args)
handle.SetTransform(Matrix3.Identity);
}

public static Color GetProgressColor(float progress)
public static Color GetProgressColor(float progress, float alpha = 1f)
{
if (progress >= 1.0f)
{
return new Color(0f, 1f, 0f);
return new Color(0f, 1f, 0f, alpha);
}
// lerp
var hue = (5f / 18f) * progress;
return Color.FromHsv((hue, 1f, 0.75f, 1f));
return Color.FromHsv((hue, 1f, 0.75f, alpha));
}
}
2 changes: 1 addition & 1 deletion Content.Client/DoAfter/DoAfterSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public sealed class DoAfterSystem : SharedDoAfterSystem
public override void Initialize()
{
base.Initialize();
_overlay.AddOverlay(new DoAfterOverlay(EntityManager, _prototype, GameTiming));
_overlay.AddOverlay(new DoAfterOverlay(EntityManager, _prototype, GameTiming, _player));
}

public override void Shutdown()
Expand Down
39 changes: 39 additions & 0 deletions Content.Client/Info/PlaytimeStats/PlaytimeStatsEntry.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using Robust.Client.AutoGenerated;
using Robust.Client.Graphics;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;

namespace Content.Client.Info.PlaytimeStats;

[GenerateTypedNameReferences]
public sealed partial class PlaytimeStatsEntry : ContainerButton
{
public TimeSpan Playtime { get; private set; } // new TimeSpan property

public PlaytimeStatsEntry(string role, TimeSpan playtime, StyleBox styleBox)
{
RobustXamlLoader.Load(this);

RoleLabel.Text = role;
Playtime = playtime; // store the TimeSpan value directly
PlaytimeLabel.Text = ConvertTimeSpanToHoursMinutes(playtime); // convert to string for display
BackgroundColorPanel.PanelOverride = styleBox;
}

private static string ConvertTimeSpanToHoursMinutes(TimeSpan timeSpan)
{
var hours = (int)timeSpan.TotalHours;
var minutes = timeSpan.Minutes;

var formattedTimeLoc = Loc.GetString("ui-playtime-time-format", ("hours", hours), ("minutes", minutes));
return formattedTimeLoc;
}

public void UpdateShading(StyleBoxFlat styleBox)
{
BackgroundColorPanel.PanelOverride = styleBox;
}
public string? PlaytimeText => PlaytimeLabel.Text;

public string? RoleText => RoleLabel.Text;
}
20 changes: 20 additions & 0 deletions Content.Client/Info/PlaytimeStats/PlaytimeStatsEntry.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<ContainerButton xmlns="https://spacestation14.io"
xmlns:customControls1="clr-namespace:Content.Client.Administration.UI.CustomControls"
EnableAllKeybinds="True">
<PanelContainer Name="BackgroundColorPanel"/>
<BoxContainer Orientation="Horizontal"
HorizontalExpand="True"
SeparationOverride="4">
<Label Name="RoleLabel"
SizeFlagsStretchRatio="3"
HorizontalExpand="True"
ClipText="True"
Margin="5,5,5,5"/>
<customControls1:VSeparator/>
<Label Name="PlaytimeLabel"
SizeFlagsStretchRatio="3"
HorizontalExpand="True"
ClipText="True"
Margin="5,5,5,5"/>
</BoxContainer>
</ContainerButton>
86 changes: 86 additions & 0 deletions Content.Client/Info/PlaytimeStats/PlaytimeStatsHeader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Input;

namespace Content.Client.Info.PlaytimeStats;

[GenerateTypedNameReferences]
public sealed partial class PlaytimeStatsHeader : ContainerButton
{
public event Action<Header, SortDirection>? OnHeaderClicked;
private SortDirection _roleDirection = SortDirection.Ascending;
private SortDirection _playtimeDirection = SortDirection.Descending;

public PlaytimeStatsHeader()
{
RobustXamlLoader.Load(this);

RoleLabel.OnKeyBindDown += RoleClicked;
PlaytimeLabel.OnKeyBindDown += PlaytimeClicked;

UpdateLabels();
}

public enum Header : byte
{
Role,
Playtime
}
public enum SortDirection : byte
{
Ascending,
Descending
}

private void HeaderClicked(GUIBoundKeyEventArgs args, Header header)
{
if (args.Function != EngineKeyFunctions.UIClick)
{
return;
}

switch (header)
{
case Header.Role:
_roleDirection = _roleDirection == SortDirection.Ascending ? SortDirection.Descending : SortDirection.Ascending;
break;
case Header.Playtime:
_playtimeDirection = _playtimeDirection == SortDirection.Ascending ? SortDirection.Descending : SortDirection.Ascending;
break;
}

UpdateLabels();
OnHeaderClicked?.Invoke(header, header == Header.Role ? _roleDirection : _playtimeDirection);
args.Handle();
}
private void UpdateLabels()
{
RoleLabel.Text = Loc.GetString("ui-playtime-header-role-type") +
(_roleDirection == SortDirection.Ascending ? " ↓" : " ↑");
PlaytimeLabel.Text = Loc.GetString("ui-playtime-header-role-time") +
(_playtimeDirection == SortDirection.Ascending ? " ↓" : " ↑");
}

private void RoleClicked(GUIBoundKeyEventArgs args)
{
HeaderClicked(args, Header.Role);
}

private void PlaytimeClicked(GUIBoundKeyEventArgs args)
{
HeaderClicked(args, Header.Playtime);
}

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

if (disposing)
{
RoleLabel.OnKeyBindDown -= RoleClicked;
PlaytimeLabel.OnKeyBindDown -= PlaytimeClicked;
}
}
}
29 changes: 29 additions & 0 deletions Content.Client/Info/PlaytimeStats/PlaytimeStatsHeader.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<ContainerButton xmlns="https://spacestation14.io"
xmlns:customControls="clr-namespace:Content.Client.Administration.UI.CustomControls"
EnableAllKeybinds="True">
<PanelContainer Name="BackgroundColorPlaytimePanel" Access="Public"/>
<BoxContainer Orientation="Vertical"
HorizontalExpand="True">
<BoxContainer Orientation="Horizontal"
HorizontalExpand="True"
SeparationOverride="4">
<Label Name="RoleLabel"
SizeFlagsStretchRatio="3"
HorizontalExpand="True"
ClipText="True"
Text="{Loc ui-playtime-header-role-type}"
MouseFilter="Pass"
Margin="5,5,5,5"/>
<customControls:VSeparator/>
<Label Name="PlaytimeLabel"
SizeFlagsStretchRatio="3"
HorizontalExpand="True"
ClipText="True"
Text="{Loc ui-playtime-header-role-time}"
MouseFilter="Pass"
Margin="5,5,5,5"/>
</BoxContainer>
<!-- Horizontal Separator -->
<customControls:HSeparator/>
</BoxContainer>
</ContainerButton>
Loading

0 comments on commit 8b85567

Please sign in to comment.