Skip to content

Commit

Permalink
BankLable Corvax (#1379)
Browse files Browse the repository at this point in the history
  • Loading branch information
dvir001 authored May 17, 2024
1 parent fbc9a08 commit d23d0dc
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 9 deletions.
2 changes: 2 additions & 0 deletions Content.Client/Administration/AdminNameOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,14 @@ protected override void Draw(in OverlayDrawArgs args)
var screenCoordinates = _eyeManager.WorldToScreen(aabb.Center +
new Angle(-_eyeManager.CurrentEye.Rotation).RotateVec(
aabb.TopRight - aabb.Center)) + new Vector2(1f, 7f);
var balance_str = playerInfo.Balance == int.MinValue ? "NO BALANCE" : playerInfo.Balance.ToString(); // Frontier
if (playerInfo.Antag)
{
args.ScreenHandle.DrawString(_font, screenCoordinates + (lineoffset * 2), "ANTAG", Color.OrangeRed);
}
args.ScreenHandle.DrawString(_font, screenCoordinates+lineoffset, playerInfo.Username, playerInfo.Connected ? Color.Yellow : Color.White);
args.ScreenHandle.DrawString(_font, screenCoordinates, playerInfo.CharacterName, playerInfo.Connected ? Color.Aquamarine : Color.White);
args.ScreenHandle.DrawString(_font, screenCoordinates + 3 * lineoffset, $"balance: {balance_str}", playerInfo.Connected ? Color.Aquamarine : Color.White);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ private void RefreshPlayerList(IReadOnlyList<PlayerInfo> players)
player.Antag ? "YES" : "NO",
new StyleBoxFlat(useAltColor ? _altColor : _defaultColor),
player.Connected,
player.PlaytimeString);
player.PlaytimeString, // Frontier
player.Balance == int.MinValue ? "NO BALANCE" : player.Balance.ToString()); // Frontier
entry.PlayerEntity = player.NetEntity;
entry.OnKeyBindDown += args => OnEntryKeyBindDown?.Invoke(entry, args);
entry.ToolTip = Loc.GetString("player-tab-entry-tooltip");
Expand Down Expand Up @@ -151,8 +152,9 @@ private int Compare(PlayerInfo x, PlayerInfo y)
Header.Job => Compare(x.StartingJob, y.StartingJob),
Header.Antagonist => x.Antag.CompareTo(y.Antag),
Header.Playtime => TimeSpan.Compare(x.OverallPlaytime ?? default, y.OverallPlaytime ?? default),
Header.Balance => x.Balance.CompareTo(y.Balance), // Frontier
_ => 1
};
}; ;
}

private int Compare(string x, string y)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,9 @@
SizeFlagsStretchRatio="2"
HorizontalExpand="True"
ClipText="True"/>
<Label Name="BalanceLabel"
SizeFlagsStretchRatio="2"
HorizontalExpand="True"
ClipText="True"/>
</BoxContainer>
</ContainerButton>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Robust.Client.AutoGenerated;
using Robust.Client.AutoGenerated;
using Robust.Client.Graphics;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;
Expand All @@ -10,7 +10,7 @@ public sealed partial class PlayerTabEntry : ContainerButton
{
public NetEntity? PlayerEntity;

public PlayerTabEntry(string username, string character, string identity, string job, string antagonist, StyleBox styleBox, bool connected, string overallPlaytime)
public PlayerTabEntry(string username, string character, string identity, string job, string antagonist, StyleBox styleBox, bool connected, string overallPlaytime, string balance) // Frontier - Add int balance
{
RobustXamlLoader.Load(this);

Expand All @@ -24,5 +24,6 @@ public PlayerTabEntry(string username, string character, string identity, string
AntagonistLabel.Text = antagonist;
BackgroundColorPanel.PanelOverride = styleBox;
OverallPlaytimeLabel.Text = overallPlaytime;
BalanceLabel.Text = balance.ToString(); // Frontier
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Control xmlns="https://spacestation14.io"
<Control xmlns="https://spacestation14.io"
xmlns:cc="clr-namespace:Content.Client.Administration.UI.CustomControls">
<PanelContainer Name="BackgroundColorPanel" Access="Public"/>
<BoxContainer Orientation="Horizontal"
Expand Down Expand Up @@ -31,11 +31,18 @@
ClipText="True"
Text="{Loc player-tab-antagonist}"
MouseFilter="Pass"/>
<cc:VSeparator/>
<Label Name="PlaytimeLabel"
SizeFlagsStretchRatio="2"
HorizontalExpand="True"
ClipText="True"
Text="{Loc player-tab-playtime}"
MouseFilter="Pass"/>
<Label Name="BalanceLabel"
SizeFlagsStretchRatio="2"
HorizontalExpand="True"
ClipText="True"
Text="{Loc player-tab-balance}"
MouseFilter="Pass"/>
</BoxContainer>
</Control>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Robust.Client.AutoGenerated;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;
Expand All @@ -20,6 +20,7 @@ public PlayerTabHeader()
JobLabel.OnKeyBindDown += JobClicked;
AntagonistLabel.OnKeyBindDown += AntagonistClicked;
PlaytimeLabel.OnKeyBindDown += PlaytimeClicked;
BalanceLabel.OnKeyBindDown += BalanceClicked; // Frontier
}

public Label GetHeader(Header header)
Expand All @@ -31,6 +32,7 @@ public Label GetHeader(Header header)
Header.Job => JobLabel,
Header.Antagonist => AntagonistLabel,
Header.Playtime => PlaytimeLabel,
Header.Balance => BalanceLabel, // Frontier
_ => throw new ArgumentOutOfRangeException(nameof(header), header, null)
};
}
Expand All @@ -42,6 +44,7 @@ public void ResetHeaderText()
JobLabel.Text = Loc.GetString("player-tab-job");
AntagonistLabel.Text = Loc.GetString("player-tab-antagonist");
PlaytimeLabel.Text = Loc.GetString("player-tab-playtime");
BalanceLabel.Text = Loc.GetString("player-tab-balance"); // Frontier
}

private void HeaderClicked(GUIBoundKeyEventArgs args, Header header)
Expand Down Expand Up @@ -80,6 +83,11 @@ private void PlaytimeClicked(GUIBoundKeyEventArgs args)
HeaderClicked(args, Header.Playtime);
}

private void BalanceClicked(GUIBoundKeyEventArgs args) // Frontier
{
HeaderClicked(args, Header.Balance);
}

protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
Expand All @@ -91,6 +99,7 @@ protected override void Dispose(bool disposing)
JobLabel.OnKeyBindDown -= JobClicked;
AntagonistLabel.OnKeyBindDown -= AntagonistClicked;
PlaytimeLabel.OnKeyBindDown -= PlaytimeClicked;
BalanceLabel.OnKeyBindDown -= BalanceClicked; // Frontier
}
}

Expand All @@ -100,6 +109,7 @@ public enum Header
Character,
Job,
Antagonist,
Playtime
Playtime,
Balance // Frontier
}
}
25 changes: 24 additions & 1 deletion Content.Server/Administration/Systems/AdminSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
using Robust.Shared.Enums;
using Robust.Shared.Network;
using Robust.Shared.Player;
using Content.Shared._NF.Bank.Events; // Frontier
using Content.Shared.Bank.Components; // Frontier
using Content.Shared.Bank.Events; // Frontier

namespace Content.Server.Administration.Systems
{
Expand Down Expand Up @@ -84,6 +87,8 @@ public override void Initialize()
SubscribeLocalEvent<RoleAddedEvent>(OnRoleEvent);
SubscribeLocalEvent<RoleRemovedEvent>(OnRoleEvent);
SubscribeLocalEvent<RoundRestartCleanupEvent>(OnRoundRestartCleanup);

SubscribeLocalEvent<BalanceChangedEvent>(OnBalanceChanged); // Frontier
}

private void OnRoundRestartCleanup(RoundRestartCleanupEvent ev)
Expand Down Expand Up @@ -183,6 +188,12 @@ private void OnPlayerAttached(PlayerAttachedEvent ev)
UpdatePlayerList(ev.Player);
}

private void OnBalanceChanged(BalanceChangedEvent ev) // Frontier
{
if (ev.Amount == 0)
return;
UpdatePlayerList(ev.Session);
}
public override void Shutdown()
{
base.Shutdown();
Expand Down Expand Up @@ -210,11 +221,23 @@ private PlayerInfo GetPlayerInfo(SessionData data, ICommonSession? session)
var name = data.UserName;
var entityName = string.Empty;
var identityName = string.Empty;
int balance = 0; // Frontier

if (session?.AttachedEntity != null)
{
entityName = EntityManager.GetComponent<MetaDataComponent>(session.AttachedEntity.Value).EntityName;
identityName = Identity.Name(session.AttachedEntity.Value, EntityManager);

// Frontier
if (EntityManager.TryGetComponent<BankAccountComponent>(session.AttachedEntity.Value, out var comp))
{
balance = comp.Balance;
}
else
{
balance = int.MinValue; // Ok
}
// Frontier
}

var antag = false;
Expand All @@ -235,7 +258,7 @@ private PlayerInfo GetPlayerInfo(SessionData data, ICommonSession? session)
}

return new PlayerInfo(name, entityName, identityName, startingRole, antag, GetNetEntity(session?.AttachedEntity), data.UserId,
connected, _roundActivePlayers.Contains(data.UserId), overallPlaytime);
connected, _roundActivePlayers.Contains(data.UserId), overallPlaytime, balance); // Frontier - Added balance
}

private void OnPanicBunkerChanged(bool enabled)
Expand Down
5 changes: 5 additions & 0 deletions Content.Server/_NF/Bank/BankSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@
using Robust.Shared.Network;
using Content.Server.Cargo.Components;
using Content.Shared.Preferences.Loadouts;
using Content.Shared._NF.Bank.Events;
using Robust.Server.Player;

namespace Content.Server.Bank;

public sealed partial class BankSystem : EntitySystem
{
[Dependency] private readonly IServerPreferencesManager _prefsManager = default!;
[Dependency] private readonly IServerDbManager _dbManager = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;

private ISawmill _log = default!;

Expand Down Expand Up @@ -72,6 +75,8 @@ private void OnBankAccountChanged(EntityUid mobUid, BankAccountComponent bank, r

_dbManager.SaveCharacterSlotAsync((NetUserId) user, newProfile, index);
_log.Info($"Character {profile.Name} saved");
var session = _playerManager.GetSessionById((NetUserId) user);
RaiseLocalEvent(new BalanceChangedEvent(session, bank.Balance));
}

/// <summary>
Expand Down
3 changes: 2 additions & 1 deletion Content.Shared/Administration/PlayerInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public sealed record PlayerInfo(
NetUserId SessionId,
bool Connected,
bool ActiveThisRound,
TimeSpan? OverallPlaytime)
TimeSpan? OverallPlaytime,
int Balance) // Frontier
{
private string? _playtimeString;

Expand Down
4 changes: 4 additions & 0 deletions Content.Shared/_NF/Bank/Events/BalanceChangedMessage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
using Robust.Shared.Player;

namespace Content.Shared._NF.Bank.Events;
public sealed record BalanceChangedEvent(ICommonSession Session, int Amount);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
player-tab-balance = Balance

0 comments on commit d23d0dc

Please sign in to comment.