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

Cargo orders computer update #728

Closed
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
using Content.Shared.Cargo;
using Content.Client.Cargo.UI;
using Content.Client.SS220.Cargo.UI;
using Content.Shared.Cargo.BUI;
using Content.Shared.Cargo.Events;
using Content.Shared.Cargo.Prototypes;
using Content.Shared.IdentityManagement;
using Robust.Client.GameObjects;
using Robust.Client.Player;
using Robust.Shared.Utility;
using Robust.Shared.Prototypes;
using static Robust.Client.UserInterface.Controls.BaseButton;
using Content.Shared.SS220.Cargo.Events;

namespace Content.Client.SS220.Cargo.BUI
{
public sealed class UpdatedCargoOrderConsoleBoundUserInterface : BoundUserInterface
{
[ViewVariables]
private UpdatedCargoConsoleMenu? _menu;

/// <summary>
/// This is the separate popup window for individual orders.
/// </summary>
[ViewVariables]
private UpdatedCargoConsoleOrderMenu? _orderMenu;

[ViewVariables]
public string? AccountName { get; private set; }

[ViewVariables]
public int BankBalance { get; private set; }

[ViewVariables]
public int OrderCapacity { get; private set; }

[ViewVariables]
public int OrderCount { get; private set; }

/// <summary>
/// Currently selected product
/// </summary>
[ViewVariables]
private CargoProductPrototype? _product;

public UpdatedCargoOrderConsoleBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
}

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

var spriteSystem = EntMan.System<SpriteSystem>();
var dependencies = IoCManager.Instance!;
_menu = new UpdatedCargoConsoleMenu(Owner, EntMan, dependencies.Resolve<IPrototypeManager>(), spriteSystem);
var localPlayer = dependencies.Resolve<IPlayerManager>().LocalEntity;
var description = new FormattedMessage();

string orderRequester;

if (EntMan.TryGetComponent<MetaDataComponent>(localPlayer, out var metadata))
orderRequester = Identity.Name(localPlayer.Value, EntMan);
else
orderRequester = string.Empty;

_orderMenu = new UpdatedCargoConsoleOrderMenu();

_menu.OnClose += Close;

_menu.OnItemSelected += (args) =>
{
if (args.Button.Parent is not CargoProductRow row)
return;

description.Clear();
description.PushColor(Color.White); // Rich text default color is grey
if (row.MainButton.ToolTip != null)
description.AddText(row.MainButton.ToolTip);

_orderMenu.Description.SetMessage(description);
_product = row.Product;
_orderMenu.ProductName.Text = row.ProductName.Text;
_orderMenu.PointCost.Text = row.PointCost.Text;
_orderMenu.Requester.Text = orderRequester;
_orderMenu.Reason.Text = "";
_orderMenu.Amount.Value = 1;

_orderMenu.OpenCentered();
};
_menu.OnOrderApproved += ApproveOrder;
_menu.OnOrderCanceled += RemoveOrder;

_menu.CashOutButtonPressed += CashOut;
_menu.CashOutAllButtonPressed += CashOutAll;

_orderMenu.SubmitButton.OnPressed += (_) =>
{
if (AddOrder())
{
_orderMenu.Close();
}
};

_menu.OpenCentered();
}

private void Populate(List<CargoOrderData> orders)
{
if (_menu == null) return;

_menu.PopulateProducts();
_menu.PopulateCategories();
_menu.PopulateOrders(orders);
}

protected override void UpdateState(BoundUserInterfaceState state)
{
base.UpdateState(state);

if (state is not CargoConsoleInterfaceState cState)
return;

OrderCapacity = cState.Capacity;
OrderCount = cState.Count;
BankBalance = cState.Balance;

AccountName = cState.Name;

Populate(cState.Orders);
_menu?.UpdateCargoCapacity(OrderCount, OrderCapacity);
_menu?.UpdateBankData(AccountName, BankBalance);
}

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

if (!disposing) return;

_menu?.Dispose();
_orderMenu?.Dispose();
}

private bool AddOrder()
{
var orderAmt = _orderMenu?.Amount.Value ?? 0;
if (orderAmt < 1 || orderAmt > OrderCapacity)
{
return false;
}

SendMessage(new CargoConsoleAddOrderMessage(
_orderMenu?.Requester.Text ?? "",
_orderMenu?.Reason.Text ?? "",
_product?.ID ?? "",
orderAmt));

return true;
}

private void RemoveOrder(ButtonEventArgs args)
{
if (args.Button.Parent?.Parent is not CargoOrderRow row || row.Order == null)
return;

SendMessage(new CargoConsoleRemoveOrderMessage(row.Order.OrderId));
}

private void ApproveOrder(ButtonEventArgs args)
{
if (args.Button.Parent?.Parent is not CargoOrderRow row || row.Order == null)
return;

if (OrderCount >= OrderCapacity)
return;

SendMessage(new CargoConsoleApproveOrderMessage(row.Order.OrderId));
// Most of the UI isn't predicted anyway so.
// _menu?.UpdateCargoCapacity(OrderCount + row.Order.Amount, OrderCapacity);
}
private void CashOut(ButtonEventArgs args)
{
if (!int.TryParse(_menu?.GetAmountOfCashOut(), out var cashOut))
return;

SendMessage(new CargoConsoleCashOutMessage(cashOut));
_menu?.ClearAmountOfCashOutLineEdit();
}
private void CashOutAll(ButtonEventArgs args)
{
SendMessage(new CargoConsoleCashOutMessage(BankBalance));
}
}
}
76 changes: 76 additions & 0 deletions Content.Client/SS220/Cargo/UI/UpdatedCargoConsoleMenu.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<controls:FancyWindow xmlns="https://spacestation14.io"
xmlns:gfx="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client"
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
SetSize="600 600"
MinSize="600 600">
<BoxContainer Orientation="Vertical" Margin="5 0 5 0">
<BoxContainer Orientation="Horizontal">
<BoxContainer Orientation="Vertical" >
<BoxContainer Orientation="Horizontal">
<Label Text="{Loc 'cargo-console-menu-account-name-label'}" StyleClasses="LabelKeyText" />
<Label 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" 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>
<BoxContainer Orientation="Vertical" HorizontalExpand="True" VerticalAlignment="Center" HorizontalAlignment="Right">
<BoxContainer Orientation="Horizontal">
<LineEdit Name="AmountOfCashOut" MinWidth="64"/>
<Label Text="{Loc 'updated-cargo-console-currency-label'}"/>
<Button Name="CashOutButton" Access="Public" Text="{Loc 'updated-cargo-console-cash-out-button'}" StyleClasses="OpenLeft"/>
</BoxContainer>
<BoxContainer Orientation="Horizontal">
<Button Name="CashOutAllButton" Access="Public" Text="{Loc 'updated-cargo-console-cash-out-all-button'}" StyleClasses="OpenLeft"/>
</BoxContainer>
</BoxContainer>
</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>
</BoxContainer>
</ScrollContainer>
</PanelContainer>
<TextureButton VerticalExpand="True" />
</BoxContainer>
</controls:FancyWindow>
Loading
Loading