Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Economy system refactor #2

Draft
wants to merge 5 commits into
base: economy
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions Content.Client/AWS/Economy/ClientEconomyManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using System.Collections.Frozen;
using System.Diagnostics.CodeAnalysis;
using Content.Shared.AWS.Economy;
using Robust.Shared.Network;

namespace Content.Client.AWS.Economy;

public sealed class ClientEconomyManager : IClientEconomyManager
{
[Dependency] private readonly IClientNetManager _netManager = default!;

public event EventHandler? AccountUpdateReceived;

/// <summary>
/// List of all cached accounts on this client.
/// </summary>
private FrozenDictionary<string, EconomyBankAccount> _cachedAccounts = default!;

public void Initialize()
{
_netManager.RegisterNetMessage<MsgEconomyAccountListRequest>();

_netManager.RegisterNetMessage<MsgEconomyAccountList>(AccountsUpdateMessage);
}

public bool IsValidAccount(string accountID)
{
AccountUpdateRequest();
return _cachedAccounts.ContainsKey(accountID);
}

public bool TryGetAccount(string accountID, [NotNullWhen(true)] out EconomyBankAccount? account)
{
AccountUpdateRequest();
return _cachedAccounts.TryGetValue(accountID, out account);
}

/// <summary>
/// Returns list of all cached accounts on this client. Use <see cref="AccountUpdateRequest"/> before using for fresh data.
/// </summary>
public IReadOnlyDictionary<string, EconomyBankAccount> GetAccounts(EconomyBankAccountMask flag = EconomyBankAccountMask.NotBlocked)
{
if (flag == EconomyBankAccountMask.All)
return _cachedAccounts;

Dictionary<string, EconomyBankAccount> list = new();
var accountsEnum = _cachedAccounts.GetEnumerator();
while (accountsEnum.MoveNext())
{
var account = accountsEnum.Current.Value;
switch (flag)
{
case EconomyBankAccountMask.NotBlocked:
if (!account.Blocked)
list.Add(account.AccountID, account);
break;
case EconomyBankAccountMask.Blocked:
if (account.Blocked)
list.Add(account.AccountID, account);
break;
}
}

return list;
}

public void AccountUpdateRequest()
{
var msg = new MsgEconomyAccountListRequest();
_netManager.ClientSendMessage(msg);
}

private void AccountsUpdateMessage(MsgEconomyAccountList message)
{
_cachedAccounts = message.Accounts.ToFrozenDictionary();
AccountUpdateReceived?.Invoke(this, EventArgs.Empty);
}
}
16 changes: 16 additions & 0 deletions Content.Client/AWS/Economy/IClientEconomyManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Content.Shared.AWS.Economy;

namespace Content.Client.AWS.Economy;

public interface IClientEconomyManager : ISharedEconomyManager
{
/// <summary>
/// Raised when the account list is received from the server.
/// </summary>
event EventHandler AccountUpdateReceived;

/// <summary>
/// Requests the server to send the account list.
/// </summary>
void AccountUpdateRequest();
}
Original file line number Diff line number Diff line change
@@ -1,33 +1,41 @@
using Content.Shared.AWS.Economy;
using Content.Client.AWS.Economy.UI;

namespace Content.Client.AWS.Economy.UI;

public sealed class EconomyLogConsoleBoundUserInterface : BoundUserInterface
{
[Dependency] private readonly IClientEconomyManager _economyManager = default!;

[ViewVariables]
private EconomyLogConsoleMenu? _menu;

public EconomyLogConsoleBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{

IoCManager.InjectDependencies(this);
}

protected override void Open()
{
base.Open();

// Requset accounts from the server, and when we receive them, open the menu.
_economyManager.AccountUpdateRequest();
_economyManager.AccountUpdateReceived += OnAccountUpdate;
}

private void OnAccountUpdate(object? sender, EventArgs e)
{
_menu = new EconomyLogConsoleMenu(this);
_menu.OnClose += Close;

_menu.OpenCentered();
_menu?.OpenCentered();
}

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

_economyManager.AccountUpdateReceived -= OnAccountUpdate;
_menu?.Dispose();
}
}
30 changes: 16 additions & 14 deletions Content.Client/AWS/Economy/UI/EconomyLogConsoleMenu.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
using Content.Client.UserInterface.Controls;
using Content.Shared.AWS.Economy;
using Content.Client.AWS.Economy.UI;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.XAML;
using Robust.Client.UserInterface.Controls;
using System.Linq;
using System.Collections.Frozen;

namespace Content.Client.AWS.Economy.UI;

[GenerateTypedNameReferences]
public sealed partial class EconomyLogConsoleMenu : FancyWindow
{
[Dependency] private readonly IEntitySystemManager _entitySystem = default!;
[Dependency] private readonly IClientEconomyManager _economyManager = default!;

private EconomyLogConsoleBoundUserInterface Owner { get; set; }
private Dictionary<string, EconomyBankAccountComponent> _accounts;
private FrozenDictionary<string, EconomyBankAccount> _accounts = default!;

public EconomyLogConsoleMenu(EconomyLogConsoleBoundUserInterface owner)
{
IoCManager.InjectDependencies(this);
RobustXamlLoader.Load(this);
var economyBankAccount = _entitySystem.GetEntitySystem<EconomyBankAccountSystemShared>();

LogDetails.SelectMode = ItemList.ItemListSelectMode.None;

Owner = owner;
_accounts = economyBankAccount.GetAccounts();

_accounts = _economyManager.GetAccounts().ToFrozenDictionary();

FillList();

Expand All @@ -36,16 +38,16 @@ private void OnSelectAccount(ItemList.Item accountId)
{
LogDetails.Clear();

var accountComponent = (accountId.Metadata! as EconomyBankAccountComponent)!;
var account = (accountId.Metadata! as EconomyBankAccount)!;

if (accountComponent.Logs.Count == 0)
if (account.Logs.Count == 0)
{
LogDetails.AddItem("No logs detected");
return;
}
for (int i = accountComponent.Logs.Count - 1; i != -1; i--)
for (int i = account.Logs.Count - 1; i != -1; i--)
{
var item = accountComponent.Logs[i];
var item = account.Logs[i];
LogDetails.AddItem("[" + item.Date.ToString("hh\\:mm\\:ss") + "] — " + item.Text);
}
}
Expand Down Expand Up @@ -84,11 +86,11 @@ private void OnTextEnteredLog(LineEdit.LineEditEventArgs eventArgs)
LogDetails.Clear();
var upText = eventArgs.Text.ToUpper();

var accountComponent = (accountId.Metadata! as EconomyBankAccountComponent)!;
var account = (accountId.Metadata! as EconomyBankAccount)!;

for (int i = accountComponent.Logs.Count - 1; i != -1; i--)
for (int i = account.Logs.Count - 1; i != -1; i--)
{
var item = accountComponent.Logs[i];
var item = account.Logs[i];
if (item.Text.Contains(upText))
LogDetails.AddItem("[" + item.Date.ToString("hh\\:mm\\:ss") + "] — " + item.Text);
}
Expand All @@ -105,8 +107,8 @@ private void FillList()
AccountList.SortItemsByText();
}

private string FormFieldName(EconomyBankAccountComponent comp)
private string FormFieldName(EconomyBankAccount account)
{
return comp.AccountId + " — " + comp.AccountName;
return account.AccountID + " — " + account.AccountName;
}
}
3 changes: 3 additions & 0 deletions Content.Client/Entry/EntryPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
using Robust.Shared.Prototypes;
using Robust.Shared.Replays;
using Robust.Shared.Timing;
using Content.Shared.AWS.Economy;

namespace Content.Client.Entry
{
Expand Down Expand Up @@ -73,6 +74,7 @@ public sealed class EntryPoint : GameClient
[Dependency] private readonly ILogManager _logManager = default!;
[Dependency] private readonly ContentReplayPlaybackManager _replayMan = default!;
[Dependency] private readonly DebugMonitorManager _debugMonitorManager = default!;
[Dependency] private readonly ISharedEconomyManager _economyManager = default!;

public override void Init()
{
Expand Down Expand Up @@ -134,6 +136,7 @@ public override void Init()
_extendedDisconnectInformation.Initialize();
_jobRequirements.Initialize();
_playbackMan.Initialize();
_economyManager.Initialize(); //AWS-economy

//AUTOSCALING default Setup!
_configManager.SetCVar("interface.resolutionAutoScaleUpperCutoffX", 1080);
Expand Down
4 changes: 4 additions & 0 deletions Content.Client/IoC/ClientContentIoC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
using Content.Client.Lobby;
using Content.Shared.Administration.Managers;
using Content.Shared.Players.PlayTimeTracking;
using Content.Shared.AWS.Economy;
using Content.Client.AWS.Economy;

namespace Content.Client.IoC
{
Expand Down Expand Up @@ -52,6 +54,8 @@ public static void Register()
collection.Register<ISharedPlaytimeManager, JobRequirementsManager>();
collection.Register<MappingManager>();
collection.Register<DebugMonitorManager>();
collection.Register<ISharedEconomyManager, ClientEconomyManager>(); //AWS-economy
collection.Register<IClientEconomyManager, ClientEconomyManager>(); //AWS-economy
}
}
}
Loading
Loading