Departmental Economy (#36445)

* Cargo Accounts, Request Consoles, and lock boxes

* Funding Allocation Computer

* final changes

* test fix

* remove dumb code

* ScarKy0 review

* first cour

* second cour

* Update machines.yml

* review

---------

Co-authored-by: ScarKy0 <106310278+ScarKy0@users.noreply.github.com>
Co-authored-by: Milon <milonpl.git@proton.me>
This commit is contained in:
Nemanja
2025-04-13 09:22:36 -04:00
committed by GitHub
parent 5f78b72763
commit 12b75beeab
62 changed files with 2106 additions and 331 deletions

View File

@@ -1,6 +1,7 @@
using Content.Shared.Cargo;
using Content.Client.Cargo.UI;
using Content.Shared.Cargo.BUI;
using Content.Shared.Cargo.Components;
using Content.Shared.Cargo.Events;
using Content.Shared.Cargo.Prototypes;
using Content.Shared.IdentityManagement;
@@ -14,6 +15,8 @@ namespace Content.Client.Cargo.BUI
{
public sealed class CargoOrderConsoleBoundUserInterface : BoundUserInterface
{
private readonly SharedCargoSystem _cargoSystem;
[ViewVariables]
private CargoConsoleMenu? _menu;
@@ -43,6 +46,7 @@ namespace Content.Client.Cargo.BUI
public CargoOrderConsoleBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
_cargoSystem = EntMan.System<SharedCargoSystem>();
}
protected override void Open()
@@ -57,7 +61,7 @@ namespace Content.Client.Cargo.BUI
string orderRequester;
if (EntMan.TryGetComponent<MetaDataComponent>(localPlayer, out var metadata))
if (EntMan.EntityExists(localPlayer))
orderRequester = Identity.Name(localPlayer.Value, EntMan);
else
orderRequester = string.Empty;
@@ -96,41 +100,54 @@ namespace Content.Client.Cargo.BUI
}
};
_menu.OnAccountAction += (account, amount) =>
{
SendMessage(new CargoConsoleWithdrawFundsMessage(account, amount));
};
_menu.OnToggleUnboundedLimit += _ =>
{
SendMessage(new CargoConsoleToggleLimitMessage());
};
_menu.OpenCentered();
}
private void Populate(List<CargoOrderData> orders)
{
if (_menu == null) return;
if (_menu == null)
return;
_menu.PopulateProducts();
_menu.PopulateCategories();
_menu.PopulateOrders(orders);
_menu.PopulateAccountActions();
}
protected override void UpdateState(BoundUserInterfaceState state)
{
base.UpdateState(state);
if (state is not CargoConsoleInterfaceState cState)
if (state is not CargoConsoleInterfaceState cState || !EntMan.TryGetComponent<CargoOrderConsoleComponent>(Owner, out var orderConsole))
return;
var station = EntMan.GetEntity(cState.Station);
OrderCapacity = cState.Capacity;
OrderCount = cState.Count;
BankBalance = cState.Balance;
BankBalance = _cargoSystem.GetBalanceFromAccount(station, orderConsole.Account);
AccountName = cState.Name;
_menu?.UpdateStation(station);
Populate(cState.Orders);
_menu?.UpdateCargoCapacity(OrderCount, OrderCapacity);
_menu?.UpdateBankData(AccountName, BankBalance);
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (!disposing) return;
if (!disposing)
return;
_menu?.Dispose();
_orderMenu?.Dispose();
@@ -170,8 +187,6 @@ namespace Content.Client.Cargo.BUI
return;
SendMessage(new CargoConsoleApproveOrderMessage(row.Order.OrderId));
// Most of the UI isn't predicted anyway so.
// _menu?.UpdateCargoCapacity(OrderCount + row.Order.Amount, OrderCapacity);
}
}
}

View File

@@ -0,0 +1,35 @@
using Content.Client.Cargo.UI;
using Content.Shared.Cargo.Components;
using JetBrains.Annotations;
using Robust.Client.UserInterface;
namespace Content.Client.Cargo.BUI;
[UsedImplicitly]
public sealed class FundingAllocationConsoleBoundUserInterface(EntityUid owner, Enum uiKey) : BoundUserInterface(owner, uiKey)
{
[ViewVariables]
private FundingAllocationMenu? _menu;
protected override void Open()
{
base.Open();
_menu = this.CreateWindow<FundingAllocationMenu>();
_menu.OnSavePressed += d =>
{
SendMessage(new SetFundingAllocationBuiMessage(d));
};
}
protected override void UpdateState(BoundUserInterfaceState message)
{
base.UpdateState(message);
if (message is not FundingAllocationConsoleBuiState state)
return;
_menu?.Update(state);
}
}

View File

@@ -3,66 +3,83 @@
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
SetSize="600 600"
MinSize="600 600">
<BoxContainer Orientation="Vertical" Margin="5 0 5 0">
<BoxContainer Orientation="Vertical" Margin="15 5 15 10">
<BoxContainer Orientation="Horizontal">
<Label Text="{Loc 'cargo-console-menu-account-name-label'}"
StyleClasses="LabelKeyText" />
<Label Name="AccountNameLabel"
<RichTextLabel Name="AccountNameLabel"
Text="{Loc 'cargo-console-menu-account-name-none-text'}" />
</BoxContainer>
<BoxContainer Orientation="Horizontal">
<Label Text="{Loc 'cargo-console-menu-points-label'}"
StyleClasses="LabelKeyText" />
<Label Name="PointsLabel"
<RichTextLabel Name="PointsLabel"
Text="$0" />
</BoxContainer>
<BoxContainer Orientation="Horizontal">
<Label Text="{Loc 'cargo-console-menu-order-capacity-label'}"
StyleClasses="LabelKeyText" />
<Label Name="ShuttleCapacityLabel"
Text="0/20" />
</BoxContainer>
<BoxContainer Orientation="Horizontal">
<OptionButton Name="Categories"
Prefix="{Loc 'cargo-console-menu-categories-label'}"
HorizontalExpand="True" />
<LineEdit Name="SearchBar"
PlaceHolder="{Loc 'cargo-console-menu-search-bar-placeholder'}"
HorizontalExpand="True" />
</BoxContainer>
<ScrollContainer HorizontalExpand="True"
VerticalExpand="True"
SizeFlagsStretchRatio="6">
<BoxContainer Name="Products"
Orientation="Vertical"
HorizontalExpand="True"
VerticalExpand="True">
<!-- Products get added here by code -->
</BoxContainer>
</ScrollContainer>
<PanelContainer VerticalExpand="True"
SizeFlagsStretchRatio="6">
<PanelContainer.PanelOverride>
<gfx:StyleBoxFlat BackgroundColor="#000000" />
</PanelContainer.PanelOverride>
<ScrollContainer VerticalExpand="True">
<BoxContainer Orientation="Vertical">
<Label Text="{Loc 'cargo-console-menu-requests-label'}" />
<BoxContainer Name="Requests"
Orientation="Vertical"
VerticalExpand="True">
<!-- Requests are added here by code -->
</BoxContainer>
<Label Text="{Loc 'cargo-console-menu-orders-label'}" />
<BoxContainer Name="Orders"
Orientation="Vertical"
StyleClasses="transparentItemList"
VerticalExpand="True">
<!-- Orders are added here by code -->
</BoxContainer>
<Control MinHeight="10"/>
<TabContainer Name="TabContainer" VerticalExpand="True">
<BoxContainer Orientation="Vertical" VerticalExpand="True">
<BoxContainer Orientation="Horizontal">
<OptionButton Name="Categories"
Prefix="{Loc 'cargo-console-menu-categories-label'}"
HorizontalExpand="True" />
<LineEdit Name="SearchBar"
PlaceHolder="{Loc 'cargo-console-menu-search-bar-placeholder'}"
HorizontalExpand="True" />
</BoxContainer>
</ScrollContainer>
</PanelContainer>
<TextureButton VerticalExpand="True" />
<Control MinHeight="5"/>
<ScrollContainer HorizontalExpand="True"
VerticalExpand="True"
SizeFlagsStretchRatio="2">
<BoxContainer Name="Products"
Orientation="Vertical"
HorizontalExpand="True"
VerticalExpand="True">
<!-- Products get added here by code -->
</BoxContainer>
</ScrollContainer>
<Control MinHeight="5"/>
<PanelContainer VerticalExpand="True"
SizeFlagsStretchRatio="1">
<PanelContainer.PanelOverride>
<gfx:StyleBoxFlat BackgroundColor="#000000" />
</PanelContainer.PanelOverride>
<ScrollContainer VerticalExpand="True">
<BoxContainer Orientation="Vertical" Margin="5">
<Label Text="{Loc 'cargo-console-menu-requests-label'}" />
<BoxContainer Name="Requests"
Orientation="Vertical"
VerticalExpand="True">
<!-- Requests are added here by code -->
</BoxContainer>
</BoxContainer>
</ScrollContainer>
</PanelContainer>
</BoxContainer>
<!-- Funds tab -->
<BoxContainer Orientation="Vertical" Margin="15">
<BoxContainer Orientation="Horizontal">
<RichTextLabel Name="TransferLimitLabel" Margin="0 0 15 0"/>
<RichTextLabel Name="UnlimitedNotifier" Text="{Loc 'cargo-console-menu-account-action-transfer-limit-unlimited-notifier'}"/>
</BoxContainer>
<BoxContainer Orientation="Horizontal">
<RichTextLabel Text="{Loc 'cargo-console-menu-account-action-select'}" Margin="0 0 10 0"/>
<OptionButton Name="ActionOptions"/>
</BoxContainer>
<Control MinHeight="5"/>
<BoxContainer Orientation="Horizontal">
<RichTextLabel Name="AmountText" Text="{ Loc 'cargo-console-menu-account-action-amount'}"/>
<SpinBox Name="TransferSpinBox" MinWidth="100" Value="10"/>
</BoxContainer>
<Control MinHeight="15"/>
<BoxContainer HorizontalAlignment="Center">
<Button Name="AccountActionButton" Text="{ Loc 'cargo-console-menu-account-action-button'}" MinHeight="45" MinWidth="120"/>
</BoxContainer>
<Control VerticalExpand="True"/>
<BoxContainer VerticalAlignment="Bottom" HorizontalAlignment="Center">
<Button Name="AccountLimitToggleButton" Text="{ Loc 'cargo-console-menu-toggle-account-lock-button'}" MinHeight="45" MinWidth="120"/>
</BoxContainer>
</BoxContainer>
</TabContainer>
</BoxContainer>
</controls:FancyWindow>

View File

@@ -1,4 +1,5 @@
using System.Linq;
using Content.Client.Cargo.Systems;
using Content.Client.UserInterface.Controls;
using Content.Shared.Cargo;
using Content.Shared.Cargo.Components;
@@ -8,6 +9,7 @@ using Robust.Client.GameObjects;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Prototypes;
using Robust.Shared.Timing;
using static Robust.Client.UserInterface.Controls.BaseButton;
namespace Content.Client.Cargo.UI
@@ -15,30 +17,83 @@ namespace Content.Client.Cargo.UI
[GenerateTypedNameReferences]
public sealed partial class CargoConsoleMenu : FancyWindow
{
private IEntityManager _entityManager;
private IPrototypeManager _protoManager;
private SpriteSystem _spriteSystem;
[Dependency] private readonly IGameTiming _timing = default!;
private readonly IEntityManager _entityManager;
private readonly IPrototypeManager _protoManager;
private readonly CargoSystem _cargoSystem;
private readonly SpriteSystem _spriteSystem;
private EntityUid _owner;
private EntityUid? _station;
private readonly EntityQuery<CargoOrderConsoleComponent> _orderConsoleQuery;
private readonly EntityQuery<StationBankAccountComponent> _bankQuery;
public event Action<ButtonEventArgs>? OnItemSelected;
public event Action<ButtonEventArgs>? OnOrderApproved;
public event Action<ButtonEventArgs>? OnOrderCanceled;
public event Action<ProtoId<CargoAccountPrototype>?, int>? OnAccountAction;
public event Action<ButtonEventArgs>? OnToggleUnboundedLimit;
private readonly List<string> _categoryStrings = new();
private string? _category;
public CargoConsoleMenu(EntityUid owner, IEntityManager entMan, IPrototypeManager protoManager, SpriteSystem spriteSystem)
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
_entityManager = entMan;
_protoManager = protoManager;
_cargoSystem = entMan.System<CargoSystem>();
_spriteSystem = spriteSystem;
_owner = owner;
Title = Loc.GetString("cargo-console-menu-title");
_orderConsoleQuery = _entityManager.GetEntityQuery<CargoOrderConsoleComponent>();
_bankQuery = _entityManager.GetEntityQuery<StationBankAccountComponent>();
Title = entMan.GetComponent<MetaDataComponent>(owner).EntityName;
SearchBar.OnTextChanged += OnSearchBarTextChanged;
Categories.OnItemSelected += OnCategoryItemSelected;
if (entMan.TryGetComponent<CargoOrderConsoleComponent>(owner, out var orderConsole))
{
var accountProto = _protoManager.Index(orderConsole.Account);
AccountNameLabel.Text = Loc.GetString("cargo-console-menu-account-name-format",
("color", accountProto.Color),
("name", Loc.GetString(accountProto.Name)),
("code", Loc.GetString(accountProto.Code)));
}
TabContainer.SetTabTitle(0, Loc.GetString("cargo-console-menu-tab-title-orders"));
TabContainer.SetTabTitle(1, Loc.GetString("cargo-console-menu-tab-title-funds"));
ActionOptions.OnItemSelected += idx =>
{
ActionOptions.SelectId(idx.Id);
};
TransferSpinBox.IsValid = val =>
{
if (!_entityManager.TryGetComponent<CargoOrderConsoleComponent>(owner, out var console) ||
!_entityManager.TryGetComponent<StationBankAccountComponent>(_station, out var bank))
return true;
return val >= 0 && val <= (int) (console.TransferLimit * bank.Accounts[console.Account]);
};
AccountActionButton.OnPressed += _ =>
{
var account = (ProtoId<CargoAccountPrototype>?) ActionOptions.SelectedMetadata;
OnAccountAction?.Invoke(account, TransferSpinBox.Value);
};
AccountLimitToggleButton.OnPressed += a =>
{
OnToggleUnboundedLimit?.Invoke(a);
};
}
private void OnCategoryItemSelected(OptionButton.ItemSelectedEventArgs args)
@@ -144,11 +199,13 @@ namespace Content.Client.Cargo.UI
/// </summary>
public void PopulateOrders(IEnumerable<CargoOrderData> orders)
{
Orders.DisposeAllChildren();
Requests.DisposeAllChildren();
foreach (var order in orders)
{
if (order.Approved)
continue;
var product = _protoManager.Index<EntityPrototype>(order.ProductId);
var productName = product.Name;
@@ -164,35 +221,67 @@ namespace Content.Client.Cargo.UI
("orderAmount", order.OrderQuantity),
("orderRequester", order.Requester))
},
Description = {Text = Loc.GetString("cargo-console-menu-order-reason-description",
("reason", order.Reason))}
Description =
{
Text = Loc.GetString("cargo-console-menu-order-reason-description",
("reason", order.Reason))
}
};
row.Cancel.OnPressed += (args) => { OnOrderCanceled?.Invoke(args); };
if (order.Approved)
{
row.Approve.Visible = false;
row.Cancel.Visible = false;
Orders.AddChild(row);
}
else
{
// TODO: Disable based on access.
row.Approve.OnPressed += (args) => { OnOrderApproved?.Invoke(args); };
Requests.AddChild(row);
}
// TODO: Disable based on access.
row.Approve.OnPressed += (args) => { OnOrderApproved?.Invoke(args); };
Requests.AddChild(row);
}
}
public void UpdateCargoCapacity(int count, int capacity)
public void PopulateAccountActions()
{
// TODO: Rename + Loc.
ShuttleCapacityLabel.Text = $"{count}/{capacity}";
if (!_entityManager.TryGetComponent<StationBankAccountComponent>(_station, out var bank) ||
!_entityManager.TryGetComponent<CargoOrderConsoleComponent>(_owner, out var console))
return;
var i = 0;
ActionOptions.Clear();
ActionOptions.AddItem(Loc.GetString("cargo-console-menu-account-action-option-withdraw"), i);
i++;
foreach (var account in bank.Accounts.Keys)
{
if (account == console.Account)
continue;
var accountProto = _protoManager.Index(account);
ActionOptions.AddItem(Loc.GetString("cargo-console-menu-account-action-option-transfer",
("code", Loc.GetString(accountProto.Code))),
i);
ActionOptions.SetItemMetadata(i, account);
i++;
}
}
public void UpdateBankData(string name, int points)
public void UpdateStation(EntityUid station)
{
AccountNameLabel.Text = name;
PointsLabel.Text = Loc.GetString("cargo-console-menu-points-amount", ("amount", points.ToString()));
_station = station;
}
protected override void FrameUpdate(FrameEventArgs args)
{
base.FrameUpdate(args);
if (!_bankQuery.TryComp(_station, out var bankAccount) ||
!_orderConsoleQuery.TryComp(_owner, out var orderConsole))
{
return;
}
var balance = _cargoSystem.GetBalanceFromAccount((_station.Value, bankAccount), orderConsole.Account);
PointsLabel.Text = Loc.GetString("cargo-console-menu-points-amount", ("amount", balance));
TransferLimitLabel.Text = Loc.GetString("cargo-console-menu-account-action-transfer-limit",
("limit", (int) (balance * orderConsole.TransferLimit)));
UnlimitedNotifier.Visible = orderConsole.TransferUnbounded;
AccountActionButton.Disabled = TransferSpinBox.Value <= 0 ||
TransferSpinBox.Value > bankAccount.Accounts[orderConsole.Account] * orderConsole.TransferLimit ||
_timing.CurTime < orderConsole.NextAccountActionTime;
}
}
}

View File

@@ -1,11 +1,13 @@
<PanelContainer xmlns="https://spacestation14.io"
HorizontalExpand="True">
HorizontalExpand="True"
Margin="0 1">
<BoxContainer Orientation="Horizontal"
HorizontalExpand="True">
<TextureRect Name="Icon"
Access="Public"
MinSize="32 32"
RectClipContent="True" />
<Control MinWidth="5"/>
<BoxContainer Orientation="Vertical"
HorizontalExpand="True"
VerticalExpand="True">
@@ -23,10 +25,10 @@
<Button Name="Approve"
Access="Public"
Text="{Loc 'cargo-console-menu-cargo-order-row-approve-button'}"
StyleClasses="LabelSubText" />
StyleClasses="OpenRight" />
<Button Name="Cancel"
Access="Public"
Text="{Loc 'cargo-console-menu-cargo-order-row-cancel-button'}"
StyleClasses="LabelSubText" />
StyleClasses="OpenLeft" />
</BoxContainer>
</PanelContainer>

View File

@@ -4,7 +4,8 @@
ToolTip=""
Access="Public"
HorizontalExpand="True"
VerticalExpand="True" />
VerticalExpand="True"
StyleClasses="OpenBoth"/>
<BoxContainer Orientation="Horizontal"
HorizontalExpand="True">
<TextureRect Name="Icon"
@@ -18,7 +19,8 @@
<Label Name="PointCost"
Access="Public"
MinSize="52 32"
Align="Right" />
Align="Right"
Margin="0 0 5 0"/>
</PanelContainer>
</BoxContainer>
</PanelContainer>

View File

@@ -0,0 +1,29 @@
<controls:FancyWindow xmlns="https://spacestation14.io"
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
xmlns:graphics="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client"
Title="{Loc 'cargo-funding-alloc-console-menu-title'}"
SetSize="680 310"
MinSize="680 310">
<BoxContainer Orientation="Vertical"
VerticalExpand="True"
HorizontalExpand="True"
Margin="10 5 10 10">
<Label Name="HelpLabel" HorizontalAlignment="Center" StyleClasses="LabelSubText"/>
<Control MinHeight="10"/>
<PanelContainer VerticalExpand="True" HorizontalExpand="True" VerticalAlignment="Top" MaxHeight="250">
<PanelContainer.PanelOverride>
<graphics:StyleBoxFlat BackgroundColor="#1B1B1E"/>
</PanelContainer.PanelOverride>
<controls:TableContainer Name="EntriesContainer" Columns="4" HorizontalExpand="True" VerticalExpand="True" Margin="5 0">
<RichTextLabel Text="{Loc 'cargo-funding-alloc-console-label-account'}" HorizontalAlignment="Center"/>
<RichTextLabel Text="{Loc 'cargo-funding-alloc-console-label-code'}" HorizontalAlignment="Center"/>
<RichTextLabel Text="{Loc 'cargo-funding-alloc-console-label-balance'}" HorizontalAlignment="Center"/>
<RichTextLabel Text="{Loc 'cargo-funding-alloc-console-label-cut'}" HorizontalAlignment="Center"/>
</controls:TableContainer>
</PanelContainer>
<BoxContainer Orientation="Horizontal" HorizontalExpand="True" Margin="5 0">
<Button Name="SaveButton" Text="{Loc 'cargo-funding-alloc-console-button-save'}" Disabled="True"/>
<RichTextLabel Name="SaveAlertLabel" HorizontalExpand="True" HorizontalAlignment="Right" Visible="False"/>
</BoxContainer>
</BoxContainer>
</controls:FancyWindow>

View File

@@ -0,0 +1,169 @@
using System.Linq;
using Content.Client.Message;
using Content.Client.UserInterface.Controls;
using Content.Shared.Cargo.Components;
using Content.Shared.Cargo.Prototypes;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Prototypes;
using Robust.Shared.Timing;
namespace Content.Client.Cargo.UI;
[GenerateTypedNameReferences]
public sealed partial class FundingAllocationMenu : FancyWindow
{
[Dependency] private readonly IEntityManager _entityManager = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
private readonly EntityQuery<StationBankAccountComponent> _bankQuery;
public event Action<Dictionary<ProtoId<CargoAccountPrototype>, int>>? OnSavePressed;
private EntityUid? _station;
private readonly HashSet<Control> _addedControls = new();
private readonly List<SpinBox> _spinBoxes = new();
private readonly Dictionary<ProtoId<CargoAccountPrototype>, RichTextLabel> _balanceLabels = new();
public FundingAllocationMenu()
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
_bankQuery = _entityManager.GetEntityQuery<StationBankAccountComponent>();
SaveButton.OnPressed += _ =>
{
if (!_entityManager.TryGetComponent<StationBankAccountComponent>(_station, out var bank))
return;
var accounts = bank.Accounts.Keys.OrderBy(p => p.Id).ToList();
var dicts = new Dictionary<ProtoId<CargoAccountPrototype>, int>();
for (var i = 0; i< accounts.Count; i++)
{
dicts.Add(accounts[i], _spinBoxes[i].Value);
}
OnSavePressed?.Invoke(dicts);
SaveButton.Disabled = true;
};
BuildEntries();
}
private void BuildEntries()
{
if (!_entityManager.TryGetComponent<StationBankAccountComponent>(_station, out var bank))
return;
HelpLabel.Text = Loc.GetString("cargo-funding-alloc-console-label-help",
("percent", (int) (bank.PrimaryCut * 100)));
foreach (var ctrl in _addedControls)
{
ctrl.Orphan();
}
_addedControls.Clear();
_spinBoxes.Clear();
_balanceLabels.Clear();
var accounts = bank.Accounts.ToList().OrderBy(p => p.Key);
foreach (var (account, balance) in accounts)
{
var accountProto = _prototypeManager.Index(account);
var accountNameLabel = new RichTextLabel
{
Modulate = accountProto.Color,
Margin = new Thickness(0, 0, 10, 0)
};
accountNameLabel.SetMarkup($"[bold]{Loc.GetString(accountProto.Name)}[/bold]");
EntriesContainer.AddChild(accountNameLabel);
var codeLabel = new RichTextLabel
{
Text = $"[font=\"Monospace\"]{Loc.GetString(accountProto.Code)}[/font]",
HorizontalAlignment = HAlignment.Center,
Margin = new Thickness(5, 0),
};
EntriesContainer.AddChild(codeLabel);
var balanceLabel = new RichTextLabel
{
Text = Loc.GetString("cargo-console-menu-points-amount", ("amount", balance)),
HorizontalExpand = true,
HorizontalAlignment = HAlignment.Center,
Margin = new Thickness(5, 0),
};
EntriesContainer.AddChild(balanceLabel);
var box = new SpinBox
{
HorizontalAlignment = HAlignment.Center,
HorizontalExpand = true,
Value = (int) (bank.RevenueDistribution[account] * 100),
IsValid = val => val is >= 0 and <= 100,
};
box.ValueChanged += _ => UpdateButtonDisabled();
EntriesContainer.AddChild(box);
_spinBoxes.Add(box);
_balanceLabels.Add(account, balanceLabel);
_addedControls.Add(accountNameLabel);
_addedControls.Add(codeLabel);
_addedControls.Add(balanceLabel);
_addedControls.Add(box);
}
}
private void UpdateButtonDisabled()
{
if (!_entityManager.TryGetComponent<StationBankAccountComponent>(_station, out var bank))
return;
var sum = _spinBoxes.Sum(s => s.Value);
var incorrectSum = sum != 100;
var differs = false;
var accounts = bank.Accounts.Keys.OrderBy(p => p.Id).ToList();
for (var i = 0; i < accounts.Count; i++)
{
var percent = _spinBoxes[i].Value;
if (percent != (int) Math.Round(bank.RevenueDistribution[accounts[i]] * 100))
{
differs = true;
break;
}
}
SaveButton.Disabled = !differs || incorrectSum;
var diff = sum - 100;
SaveAlertLabel.Visible = incorrectSum;
SaveAlertLabel.SetMarkup(Loc.GetString("cargo-funding-alloc-console-label-save-fail",
("pos", Math.Sign(diff)),
("val", Math.Abs(diff))));
}
public void Update(FundingAllocationConsoleBuiState state)
{
_station = _entityManager.GetEntity(state.Station);
BuildEntries();
UpdateButtonDisabled();
}
protected override void FrameUpdate(FrameEventArgs args)
{
base.FrameUpdate(args);
if (!_bankQuery.TryComp(_station, out var bank))
return;
foreach (var (account, label) in _balanceLabels)
{
label.Text = Loc.GetString("cargo-console-menu-points-amount", ("amount", bank.Accounts[account]));
}
}
}