Cargo Console Limit (#1095)
Co-authored-by: Pieter-Jan Briers <pieterjan.briers+git@gmail.com>
This commit is contained in:
@@ -27,6 +27,8 @@ namespace Content.Client.GameObjects.Components.Cargo
|
||||
public string BankName { get; private set; }
|
||||
[ViewVariables]
|
||||
public int BankBalance { get; private set; }
|
||||
[ViewVariables]
|
||||
public (int CurrentCapacity, int MaxCapacity) ShuttleCapacity { get; private set; }
|
||||
|
||||
private CargoProductPrototype _product;
|
||||
|
||||
@@ -95,6 +97,8 @@ namespace Content.Client.GameObjects.Components.Cargo
|
||||
BankId = cstate.BankId;
|
||||
BankName = cstate.BankName;
|
||||
BankBalance = cstate.BankBalance;
|
||||
ShuttleCapacity = cstate.ShuttleCapacity;
|
||||
_menu.UpdateCargoCapacity();
|
||||
_menu.UpdateBankData();
|
||||
}
|
||||
|
||||
@@ -126,7 +130,10 @@ namespace Content.Client.GameObjects.Components.Cargo
|
||||
{
|
||||
if (!(args.Button.Parent.Parent is CargoOrderRow row))
|
||||
return;
|
||||
if (ShuttleCapacity.CurrentCapacity == ShuttleCapacity.MaxCapacity)
|
||||
return;
|
||||
SendMessage(new SharedCargoConsoleComponent.CargoConsoleApproveOrderMessage(row.Order.OrderNumber));
|
||||
_menu?.UpdateCargoCapacity();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ namespace Content.Client.UserInterface.Cargo
|
||||
private Label _accountNameLabel { get; set; }
|
||||
private Label _pointsLabel { get; set; }
|
||||
private Label _shuttleStatusLabel { get; set; }
|
||||
private Label _shuttleCapacityLabel { get; set; }
|
||||
private VBoxContainer _requests { get; set; }
|
||||
private VBoxContainer _orders { get; set; }
|
||||
private OptionButton _categories { get; set; }
|
||||
@@ -95,6 +96,20 @@ namespace Content.Client.UserInterface.Cargo
|
||||
shuttleStatus.AddChild(_shuttleStatusLabel);
|
||||
rows.AddChild(shuttleStatus);
|
||||
|
||||
var shuttleCapacity = new HBoxContainer();
|
||||
var shuttleCapacityLabel = new Label
|
||||
{
|
||||
Text = _loc.GetString("Order Capacity: "),
|
||||
StyleClasses = { StyleNano.StyleClassLabelKeyText }
|
||||
};
|
||||
_shuttleCapacityLabel = new Label
|
||||
{
|
||||
Text = "0/20"
|
||||
};
|
||||
shuttleCapacity.AddChild(shuttleCapacityLabel);
|
||||
shuttleCapacity.AddChild(_shuttleCapacityLabel);
|
||||
rows.AddChild(shuttleCapacity);
|
||||
|
||||
var buttons = new HBoxContainer();
|
||||
CallShuttleButton = new Button()
|
||||
{
|
||||
@@ -272,8 +287,7 @@ namespace Content.Client.UserInterface.Cargo
|
||||
public void PopulateOrders()
|
||||
{
|
||||
_orders.RemoveAllChildren();
|
||||
_requests.RemoveAllChildren();
|
||||
|
||||
_requests.RemoveAllChildren();
|
||||
foreach (var order in Owner.Orders.Orders)
|
||||
{
|
||||
var row = new CargoOrderRow();
|
||||
@@ -306,6 +320,11 @@ namespace Content.Client.UserInterface.Cargo
|
||||
PopulateOrders();
|
||||
}
|
||||
|
||||
public void UpdateCargoCapacity()
|
||||
{
|
||||
_shuttleCapacityLabel.Text = $"{Owner.ShuttleCapacity.CurrentCapacity}/{Owner.ShuttleCapacity.MaxCapacity}";
|
||||
}
|
||||
|
||||
public void UpdateBankData()
|
||||
{
|
||||
_accountNameLabel.Text = Owner.BankName;
|
||||
|
||||
@@ -95,5 +95,11 @@ namespace Content.Server.Cargo
|
||||
return null;
|
||||
return account.GetOrders();
|
||||
}
|
||||
|
||||
public (int CurrentCapacity, int MaxCapacity) GetCapacity(int id)
|
||||
{
|
||||
TryGetAccount(id, out var account);
|
||||
return (account.CurrentOrderSize, account.MaxOrderSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Content.Shared.Prototypes.Cargo;
|
||||
using Robust.Shared.Localization;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
@@ -12,9 +13,13 @@ namespace Content.Server.Cargo
|
||||
public CargoOrderDatabase(int id)
|
||||
{
|
||||
Id = id;
|
||||
CurrentOrderSize = 0;
|
||||
MaxOrderSize = 20;
|
||||
}
|
||||
|
||||
public int Id { get; private set; }
|
||||
public int CurrentOrderSize { get; private set; }
|
||||
public int MaxOrderSize { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Removes all orders from the database.
|
||||
@@ -86,9 +91,18 @@ namespace Content.Server.Cargo
|
||||
/// <param name="order">The order to be approved.</param>
|
||||
public void ApproveOrder(int orderNumber)
|
||||
{
|
||||
if (CurrentOrderSize == MaxOrderSize)
|
||||
return;
|
||||
if (!_orders.TryGetValue(orderNumber, out var order))
|
||||
return;
|
||||
else if (CurrentOrderSize + order.Amount > MaxOrderSize)
|
||||
{
|
||||
AddOrder(order.Requester, Loc.GetString("{0} (Overflow)", order.Reason.Replace(" (Overflow)","")), order.ProductId,
|
||||
order.Amount - MaxOrderSize - CurrentOrderSize, order.PayingAccountId);
|
||||
order.Amount = MaxOrderSize - CurrentOrderSize;
|
||||
}
|
||||
order.Approved = true;
|
||||
CurrentOrderSize += order.Amount;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -100,5 +114,13 @@ namespace Content.Server.Cargo
|
||||
{
|
||||
return _orders.ContainsValue(order);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clears the current order capacity. This allows more orders to be processed and is invoked after an order is dispatched.
|
||||
/// </summary>
|
||||
public void ClearOrderCapacity()
|
||||
{
|
||||
CurrentOrderSize = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Content.Server.GameObjects.Components.Cargo;
|
||||
using Content.Shared.Prototypes.Cargo;
|
||||
|
||||
@@ -13,5 +14,6 @@ namespace Content.Server.Cargo
|
||||
void AddComponent(CargoOrderDatabaseComponent component);
|
||||
List<CargoOrderData> GetOrdersFromAccount(int accountId);
|
||||
List<CargoOrderData> RemoveAndGetApprovedFrom(CargoOrderDatabase database);
|
||||
(int CurrentCapacity, int MaxCapacity) GetCapacity(int id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using Content.Server.Cargo;
|
||||
using Content.Server.GameObjects.Components.Power;
|
||||
using Content.Server.GameObjects.Components.Power.ApcNetComponents;
|
||||
using Content.Server.GameObjects.EntitySystems;
|
||||
using Content.Shared.GameObjects.Components.Cargo;
|
||||
@@ -46,24 +45,19 @@ namespace Content.Server.GameObjects.Components.Cargo
|
||||
return;
|
||||
if (_bankAccount != null)
|
||||
{
|
||||
_bankAccount.OnBalanceChange -= OnBankAccountChange;
|
||||
_bankAccount.OnBalanceChange -= UpdateUIState;
|
||||
}
|
||||
|
||||
_bankAccount = value;
|
||||
if (value != null)
|
||||
{
|
||||
_bankAccount.OnBalanceChange += OnBankAccountChange;
|
||||
_bankAccount.OnBalanceChange += UpdateUIState;
|
||||
}
|
||||
|
||||
OnBankAccountChange();
|
||||
UpdateUIState();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnBankAccountChange()
|
||||
{
|
||||
SetState(_bankAccount.Id, _bankAccount.Name, _bankAccount.Balance);
|
||||
}
|
||||
|
||||
private bool _requestOnly = false;
|
||||
|
||||
private PowerReceiverComponent _powerReceiver;
|
||||
@@ -121,14 +115,19 @@ namespace Content.Server.GameObjects.Components.Cargo
|
||||
_prototypeManager.TryIndex(order.ProductId, out CargoProductPrototype product);
|
||||
if (product == null)
|
||||
break;
|
||||
var capacity = _cargoOrderDataManager.GetCapacity(Orders.Database.Id);
|
||||
if (capacity.CurrentCapacity == capacity.MaxCapacity)
|
||||
break;
|
||||
if (!_cargoConsoleSystem.ChangeBalance(_bankAccount.Id, (-product.PointCost) * order.Amount))
|
||||
break;
|
||||
_cargoOrderDataManager.ApproveOrder(Orders.Database.Id, msg.OrderNumber);
|
||||
UpdateUIState();
|
||||
break;
|
||||
}
|
||||
case CargoConsoleShuttleMessage _:
|
||||
{
|
||||
var approvedOrders = _cargoOrderDataManager.RemoveAndGetApprovedFrom(Orders.Database);
|
||||
Orders.Database.ClearOrderCapacity();
|
||||
// TODO replace with shuttle code
|
||||
|
||||
// TEMPORARY loop for spawning stuff on top of console
|
||||
@@ -158,12 +157,18 @@ namespace Content.Server.GameObjects.Components.Cargo
|
||||
_userInterface.Open(actor.playerSession);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sync bank account information
|
||||
/// </summary>
|
||||
public void SetState(int id, string name, int balance)
|
||||
private void UpdateUIState()
|
||||
{
|
||||
_userInterface.SetState(new CargoConsoleInterfaceState(_requestOnly, id, name, balance));
|
||||
if (_bankAccount == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var id = _bankAccount.Id;
|
||||
var name = _bankAccount.Name;
|
||||
var balance = _bankAccount.Balance;
|
||||
var capacity = _cargoOrderDataManager.GetCapacity(id);
|
||||
_userInterface.SetState(new CargoConsoleInterfaceState(_requestOnly, id, name, balance, capacity));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,13 +94,15 @@ namespace Content.Shared.GameObjects.Components.Cargo
|
||||
public readonly int BankId;
|
||||
public readonly string BankName;
|
||||
public readonly int BankBalance;
|
||||
public readonly (int CurrentCapacity, int MaxCapacity) ShuttleCapacity;
|
||||
|
||||
public CargoConsoleInterfaceState(bool requestOnly, int bankId, string bankName, int bankBalance)
|
||||
public CargoConsoleInterfaceState(bool requestOnly, int bankId, string bankName, int bankBalance, (int CurrentCapacity, int MaxCapacity) shuttleCapacity)
|
||||
{
|
||||
RequestOnly = requestOnly;
|
||||
BankId = bankId;
|
||||
BankName = bankName;
|
||||
BankBalance = bankBalance;
|
||||
ShuttleCapacity = shuttleCapacity;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user