From 005dede866b5c8790d4cdc6f053fe617d748e31f Mon Sep 17 00:00:00 2001 From: desuwatch Date: Tue, 7 May 2024 00:47:52 +0300 Subject: [PATCH 1/2] Added balance column in admin panel --- .../UI/Tabs/PlayerTab/PlayerTab.xaml.cs | 3 ++- .../UI/Tabs/PlayerTab/PlayerTabEntry.xaml | 6 +++++- .../UI/Tabs/PlayerTab/PlayerTabEntry.xaml.cs | 5 +++-- .../UI/Tabs/PlayerTab/PlayerTabHeader.xaml | 9 ++++++++- .../UI/Tabs/PlayerTab/PlayerTabHeader.xaml.cs | 13 +++++++++++-- .../Administration/Systems/AdminSystem.cs | 18 +++++++++++++++++- Content.Server/_NF/Bank/BankSystem.cs | 5 +++++ Content.Shared/Administration/PlayerInfo.cs | 3 ++- .../_NF/Bank/Events/BalanceChangedMessage.cs | 4 ++++ 9 files changed, 57 insertions(+), 9 deletions(-) create mode 100644 Content.Shared/_NF/Bank/Events/BalanceChangedMessage.cs diff --git a/Content.Client/Administration/UI/Tabs/PlayerTab/PlayerTab.xaml.cs b/Content.Client/Administration/UI/Tabs/PlayerTab/PlayerTab.xaml.cs index 33a1d2361f2..acad192c225 100644 --- a/Content.Client/Administration/UI/Tabs/PlayerTab/PlayerTab.xaml.cs +++ b/Content.Client/Administration/UI/Tabs/PlayerTab/PlayerTab.xaml.cs @@ -121,7 +121,8 @@ private void RefreshPlayerList(IReadOnlyList players) player.Antag ? "YES" : "NO", new StyleBoxFlat(useAltColor ? _altColor : _defaultColor), player.Connected, - player.PlaytimeString); + player.PlaytimeString, + player.Balance); entry.PlayerEntity = player.NetEntity; entry.OnKeyBindDown += args => OnEntryKeyBindDown?.Invoke(entry, args); entry.ToolTip = Loc.GetString("player-tab-entry-tooltip"); diff --git a/Content.Client/Administration/UI/Tabs/PlayerTab/PlayerTabEntry.xaml b/Content.Client/Administration/UI/Tabs/PlayerTab/PlayerTabEntry.xaml index 8ac90305ca9..8edeb7a8b3f 100644 --- a/Content.Client/Administration/UI/Tabs/PlayerTab/PlayerTabEntry.xaml +++ b/Content.Client/Administration/UI/Tabs/PlayerTab/PlayerTabEntry.xaml @@ -1,4 +1,4 @@ - + diff --git a/Content.Client/Administration/UI/Tabs/PlayerTab/PlayerTabEntry.xaml.cs b/Content.Client/Administration/UI/Tabs/PlayerTab/PlayerTabEntry.xaml.cs index 80a68f4cd2d..3f8d6453575 100644 --- a/Content.Client/Administration/UI/Tabs/PlayerTab/PlayerTabEntry.xaml.cs +++ b/Content.Client/Administration/UI/Tabs/PlayerTab/PlayerTabEntry.xaml.cs @@ -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; @@ -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, int balance) { RobustXamlLoader.Load(this); @@ -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(); } } diff --git a/Content.Client/Administration/UI/Tabs/PlayerTab/PlayerTabHeader.xaml b/Content.Client/Administration/UI/Tabs/PlayerTab/PlayerTabHeader.xaml index 2fd3f31b903..cd8f1801773 100644 --- a/Content.Client/Administration/UI/Tabs/PlayerTab/PlayerTabHeader.xaml +++ b/Content.Client/Administration/UI/Tabs/PlayerTab/PlayerTabHeader.xaml @@ -1,4 +1,4 @@ - + diff --git a/Content.Client/Administration/UI/Tabs/PlayerTab/PlayerTabHeader.xaml.cs b/Content.Client/Administration/UI/Tabs/PlayerTab/PlayerTabHeader.xaml.cs index cf7ceff23c4..6ac326cfa09 100644 --- a/Content.Client/Administration/UI/Tabs/PlayerTab/PlayerTabHeader.xaml.cs +++ b/Content.Client/Administration/UI/Tabs/PlayerTab/PlayerTabHeader.xaml.cs @@ -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; @@ -20,6 +20,7 @@ public PlayerTabHeader() JobLabel.OnKeyBindDown += JobClicked; AntagonistLabel.OnKeyBindDown += AntagonistClicked; PlaytimeLabel.OnKeyBindDown += PlaytimeClicked; + BalanceLabel.OnKeyBindDown += BalanceClicked; } public Label GetHeader(Header header) @@ -31,6 +32,7 @@ public Label GetHeader(Header header) Header.Job => JobLabel, Header.Antagonist => AntagonistLabel, Header.Playtime => PlaytimeLabel, + Header.Balance => BalanceLabel, _ => throw new ArgumentOutOfRangeException(nameof(header), header, null) }; } @@ -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"); } private void HeaderClicked(GUIBoundKeyEventArgs args, Header header) @@ -79,6 +82,10 @@ private void PlaytimeClicked(GUIBoundKeyEventArgs args) { HeaderClicked(args, Header.Playtime); } + private void BalanceClicked(GUIBoundKeyEventArgs args) + { + HeaderClicked(args, Header.Balance); + } protected override void Dispose(bool disposing) { @@ -91,6 +98,7 @@ protected override void Dispose(bool disposing) JobLabel.OnKeyBindDown -= JobClicked; AntagonistLabel.OnKeyBindDown -= AntagonistClicked; PlaytimeLabel.OnKeyBindDown -= PlaytimeClicked; + BalanceLabel.OnKeyBindDown -= BalanceClicked; } } @@ -100,6 +108,7 @@ public enum Header Character, Job, Antagonist, - Playtime + Playtime, + Balance } } diff --git a/Content.Server/Administration/Systems/AdminSystem.cs b/Content.Server/Administration/Systems/AdminSystem.cs index b7ca4e915b5..cbe22482c18 100644 --- a/Content.Server/Administration/Systems/AdminSystem.cs +++ b/Content.Server/Administration/Systems/AdminSystem.cs @@ -9,8 +9,11 @@ using Content.Server.Players.PlayTimeTracking; using Content.Server.Popups; using Content.Server.StationRecords.Systems; +using Content.Shared._NF.Bank.Events; using Content.Shared.Administration; using Content.Shared.Administration.Events; +using Content.Shared.Bank.Components; +using Content.Shared.Bank.Events; using Content.Shared.CCVar; using Content.Shared.GameTicking; using Content.Shared.Hands.Components; @@ -84,6 +87,8 @@ public override void Initialize() SubscribeLocalEvent(OnRoleEvent); SubscribeLocalEvent(OnRoleEvent); SubscribeLocalEvent(OnRoundRestartCleanup); + SubscribeLocalEvent(OnBalanceChanged); + } private void OnRoundRestartCleanup(RoundRestartCleanupEvent ev) @@ -182,6 +187,12 @@ private void OnPlayerAttached(PlayerAttachedEvent ev) _roundActivePlayers.Add(ev.Player.UserId); UpdatePlayerList(ev.Player); } + private void OnBalanceChanged(BalanceChangedEvent ev) + { + if (ev.Amount == 0) + return; + UpdatePlayerList(ev.Session); + } public override void Shutdown() { @@ -210,11 +221,16 @@ private PlayerInfo GetPlayerInfo(SessionData data, ICommonSession? session) var name = data.UserName; var entityName = string.Empty; var identityName = string.Empty; + var balance = 0; if (session?.AttachedEntity != null) { entityName = EntityManager.GetComponent(session.AttachedEntity.Value).EntityName; identityName = Identity.Name(session.AttachedEntity.Value, EntityManager); + if(EntityManager.TryGetComponent(session.AttachedEntity.Value, out var comp)) + { + balance = comp.Balance; + } } var antag = false; @@ -235,7 +251,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); } private void OnPanicBunkerChanged(bool enabled) diff --git a/Content.Server/_NF/Bank/BankSystem.cs b/Content.Server/_NF/Bank/BankSystem.cs index 1b1ea96fa66..0abf030b328 100644 --- a/Content.Server/_NF/Bank/BankSystem.cs +++ b/Content.Server/_NF/Bank/BankSystem.cs @@ -7,6 +7,8 @@ using Robust.Shared.GameStates; using Robust.Shared.Network; using Content.Server.Cargo.Components; +using Content.Shared._NF.Bank.Events; +using Robust.Server.Player; namespace Content.Server.Bank; @@ -14,6 +16,7 @@ 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!; @@ -84,6 +87,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)); } /// diff --git a/Content.Shared/Administration/PlayerInfo.cs b/Content.Shared/Administration/PlayerInfo.cs index 93f1aa0b393..14809e72ca4 100644 --- a/Content.Shared/Administration/PlayerInfo.cs +++ b/Content.Shared/Administration/PlayerInfo.cs @@ -14,7 +14,8 @@ public sealed record PlayerInfo( NetUserId SessionId, bool Connected, bool ActiveThisRound, - TimeSpan? OverallPlaytime) + TimeSpan? OverallPlaytime, + int Balance) { private string? _playtimeString; diff --git a/Content.Shared/_NF/Bank/Events/BalanceChangedMessage.cs b/Content.Shared/_NF/Bank/Events/BalanceChangedMessage.cs new file mode 100644 index 00000000000..1fa3546c395 --- /dev/null +++ b/Content.Shared/_NF/Bank/Events/BalanceChangedMessage.cs @@ -0,0 +1,4 @@ +using Robust.Shared.Player; + +namespace Content.Shared._NF.Bank.Events; +public sealed record BalanceChangedEvent(ICommonSession Session, int Amount); From 0018ec2c450469034778300dcf878c2ab05b2936 Mon Sep 17 00:00:00 2001 From: desuwatch Date: Tue, 7 May 2024 01:52:17 +0300 Subject: [PATCH 2/2] Added balance monitoring for admins --- Content.Client/Administration/AdminNameOverlay.cs | 3 ++- .../Administration/Systems/AdminSystem.cs | 2 +- Content.Server/_NF/Bank/BankSystem.cs | 14 ++++++++++++-- .../_NF/Bank/Events/BalanceChangedMessage.cs | 12 +++++++++++- .../en-US/administration/ui/tabs/player-tab.ftl | 1 + .../ru-RU/administration/ui/tabs/player-tab.ftl | 1 + 6 files changed, 28 insertions(+), 5 deletions(-) diff --git a/Content.Client/Administration/AdminNameOverlay.cs b/Content.Client/Administration/AdminNameOverlay.cs index c21ba2e32ca..e10b800cc3c 100644 --- a/Content.Client/Administration/AdminNameOverlay.cs +++ b/Content.Client/Administration/AdminNameOverlay.cs @@ -65,8 +65,9 @@ protected override void Draw(in OverlayDrawArgs args) { 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 + 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: {playerInfo.Balance}", playerInfo.Connected ? Color.Aquamarine : Color.White); } } } diff --git a/Content.Server/Administration/Systems/AdminSystem.cs b/Content.Server/Administration/Systems/AdminSystem.cs index cbe22482c18..9291e3136ae 100644 --- a/Content.Server/Administration/Systems/AdminSystem.cs +++ b/Content.Server/Administration/Systems/AdminSystem.cs @@ -191,7 +191,7 @@ private void OnBalanceChanged(BalanceChangedEvent ev) { if (ev.Amount == 0) return; - UpdatePlayerList(ev.Session); + UpdatePlayerList(ev.Player); } public override void Shutdown() diff --git a/Content.Server/_NF/Bank/BankSystem.cs b/Content.Server/_NF/Bank/BankSystem.cs index 0abf030b328..1304f5fac3d 100644 --- a/Content.Server/_NF/Bank/BankSystem.cs +++ b/Content.Server/_NF/Bank/BankSystem.cs @@ -39,6 +39,10 @@ private void OnPlayerSpawn (PlayerSpawnCompleteEvent args) var mobUid = args.Mob; var bank = EnsureComp(mobUid); bank.Balance = args.Profile.BankBalance; + if (_playerManager.TryGetSessionByEntity(mobUid, out var player)) + { + RaiseLocalEvent(new BalanceChangedEvent(bank.Balance, player)); + } Dirty(bank); } @@ -87,8 +91,6 @@ 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)); } /// @@ -119,6 +121,10 @@ public bool TryBankWithdraw(EntityUid mobUid, int amount) bank.Balance -= amount; _log.Info($"{mobUid} withdrew {amount}"); + if (_playerManager.TryGetSessionByEntity(mobUid, out var player)) + { + RaiseLocalEvent(new BalanceChangedEvent(bank.Balance, player)); + } Dirty(bank); return true; } @@ -145,6 +151,10 @@ public bool TryBankDeposit(EntityUid mobUid, int amount) bank.Balance += amount; _log.Info($"{mobUid} deposited {amount}"); + if (_playerManager.TryGetSessionByEntity(mobUid, out var player)) + { + RaiseLocalEvent(new BalanceChangedEvent(bank.Balance, player)); + } Dirty(bank); return true; } diff --git a/Content.Shared/_NF/Bank/Events/BalanceChangedMessage.cs b/Content.Shared/_NF/Bank/Events/BalanceChangedMessage.cs index 1fa3546c395..36a1718d070 100644 --- a/Content.Shared/_NF/Bank/Events/BalanceChangedMessage.cs +++ b/Content.Shared/_NF/Bank/Events/BalanceChangedMessage.cs @@ -1,4 +1,14 @@ using Robust.Shared.Player; namespace Content.Shared._NF.Bank.Events; -public sealed record BalanceChangedEvent(ICommonSession Session, int Amount); +public sealed class BalanceChangedEvent : EntityEventArgs +{ + public readonly int Amount; + public readonly ICommonSession Player; + + public BalanceChangedEvent(int amount, ICommonSession player) + { + Amount = amount; + Player = player; + } +} diff --git a/Resources/Locale/en-US/administration/ui/tabs/player-tab.ftl b/Resources/Locale/en-US/administration/ui/tabs/player-tab.ftl index e0dd7a03b15..105b70b6621 100644 --- a/Resources/Locale/en-US/administration/ui/tabs/player-tab.ftl +++ b/Resources/Locale/en-US/administration/ui/tabs/player-tab.ftl @@ -6,3 +6,4 @@ player-tab-playtime = Playtime player-tab-show-disconnected = Show Disconnected player-tab-overlay = Overlay player-tab-entry-tooltip = Playtime is displayed in days:hours:minutes. +player-tab-balance = Balance diff --git a/Resources/Locale/ru-RU/administration/ui/tabs/player-tab.ftl b/Resources/Locale/ru-RU/administration/ui/tabs/player-tab.ftl index 5cd723ea1a2..fe17bedf322 100644 --- a/Resources/Locale/ru-RU/administration/ui/tabs/player-tab.ftl +++ b/Resources/Locale/ru-RU/administration/ui/tabs/player-tab.ftl @@ -3,6 +3,7 @@ player-tab-character = Персонаж player-tab-job = Должность player-tab-antagonist = Антагонист player-tab-playtime = Игровое время +player-tab-balance = Баланс player-tab-show-disconnected = Показать отключившихся player-tab-overlay = Оверлей player-tab-entry-tooltip = Игровое время отображается как дни:часы:минуты.