Uplink UI icons and withdraw button (#4929)

* Uplink menu has icons now

* Add item icons

* Add few descriptions

* Better withdraw window

* Finished with withdraw window

* Refactored withdraw ui and fix some bugs

* Basic withdraw

* Quick fixes

* Removed uplink listing for TCs

* Move slider to separate control

* Final touches

* A bit more

* Not again...

* Fixed names

* Address review

* Fixed robust

* Non necessary check
This commit is contained in:
Alex Evgrashin
2021-10-29 12:40:47 +03:00
committed by GitHub
parent c7c651e3de
commit 4002aa5852
16 changed files with 263 additions and 108 deletions

View File

@@ -1,26 +1,14 @@
using Content.Client.Examine;
using Content.Client.Message;
using Content.Shared.Traitor.Uplink;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Maths;
using Robust.Shared.Prototypes;
namespace Content.Client.Traitor.Uplink
{
[UsedImplicitly]
public class UplinkBoundUserInterface : BoundUserInterface
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IUserInterfaceManager _userInterfaceManager = default!;
private UplinkMenu? _menu;
private UplinkMenuPopup? _failPopup;
public UplinkBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey)
{
@@ -28,23 +16,12 @@ namespace Content.Client.Traitor.Uplink
protected override void Open()
{
_menu = new UplinkMenu(_prototypeManager);
_menu = new UplinkMenu();
_menu.OpenCentered();
_menu.OnClose += Close;
_menu.OnListingButtonPressed += (_, listing) =>
{
if (_menu.CurrentLoggedInAccount?.DataBalance < listing.Price)
{
_failPopup = new UplinkMenuPopup(Loc.GetString("uplink-bound-user-interface-insufficient-funds-popup"));
_userInterfaceManager.ModalRoot.AddChild(_failPopup);
_failPopup.Open(UIBox2.FromDimensions(_menu.Position.X + 150, _menu.Position.Y + 60, 156, 24));
_menu.OnClose += () =>
{
_failPopup.Dispose();
};
}
SendMessage(new UplinkBuyListingMessage(listing.ItemId));
};
@@ -54,59 +31,36 @@ namespace Content.Client.Traitor.Uplink
SendMessage(new UplinkRequestUpdateInterfaceMessage());
};
}
_menu.OnWithdrawAttempt += (tc) =>
{
SendMessage(new UplinkTryWithdrawTC(tc));
};
}
protected override void UpdateState(BoundUserInterfaceState state)
{
base.UpdateState(state);
if (_menu == null)
{
return;
}
switch (state)
{
case UplinkUpdateState msg:
{
_menu.CurrentLoggedInAccount = msg.Account;
var balance = msg.Account.DataBalance;
string weightedColor = balance switch
{
<= 0 => "gray",
<= 5 => "green",
<= 20 => "yellow",
<= 50 => "purple",
_ => "gray"
};
_menu.BalanceInfo.SetMarkup(Loc.GetString("uplink-bound-user-interface-tc-balance-popup",
("weightedColor", weightedColor),
("balance", balance)));
_menu.ClearListings();
foreach (var item in
msg.Listings) //Should probably chunk these out instead. to-do if this clogs the internet tubes.
{
_menu.AddListingGui(item);
}
_menu.UpdateAccount(msg.Account);
_menu.UpdateListing(msg.Listings);
break;
}
}
}
private sealed class UplinkMenuPopup : Popup
protected override void Dispose(bool disposing)
{
public UplinkMenuPopup(string text)
{
var label = new RichTextLabel();
label.SetMessage(text);
AddChild(new PanelContainer
{
StyleClasses = { ExamineSystem.StyleClassEntityTooltip },
Children = { label }
});
}
base.Dispose(disposing);
if (!disposing)
return;
_menu?.Close();
_menu?.Dispose();
}
}
}

View File

@@ -10,6 +10,13 @@
MinWidth="64"/>
</BoxContainer>
<PanelContainer StyleClasses="HighDivider" />
<RichTextLabel Name="UplinkItemDescription" />
<BoxContainer Orientation="Horizontal"
HorizontalExpand="True">
<TextureRect Name="UplinkItemTexture"
MinSize="48 48"
Margin="0 0 4 0"
Stretch="KeepAspectCentered"/>
<RichTextLabel Name="UplinkItemDescription" />
</BoxContainer>
</BoxContainer>
</Control>

View File

@@ -1,4 +1,5 @@
using Robust.Client.AutoGenerated;
using Robust.Client.Graphics;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;
@@ -9,7 +10,9 @@ namespace Content.Client.Traitor.Uplink
[GenerateTypedNameReferences]
public partial class UplinkListingControl : Control
{
public UplinkListingControl(string itemName, string itemDescription, int itemPrice, bool canBuy)
public UplinkListingControl(string itemName, string itemDescription,
int itemPrice, bool canBuy, Texture? texture = null)
{
RobustXamlLoader.Load(this);
@@ -18,6 +21,8 @@ namespace Content.Client.Traitor.Uplink
UplinkItemBuyButton.Text = $"{itemPrice} TC";
UplinkItemBuyButton.Disabled = !canBuy;
UplinkItemTexture.Texture = texture;
}
}
}

View File

@@ -12,6 +12,10 @@
Access="Public"
HorizontalExpand="True"
HorizontalAlignment="Left" />
<Button Name="WithdrawButton"
Text="Withdraw"
HorizontalAlignment="Right"
MinWidth="64"/>
</BoxContainer>
<PanelContainer VerticalExpand="True">
<PanelContainer.PanelOverride>

View File

@@ -1,12 +1,16 @@
using System;
using Content.Client.Message;
using Content.Shared.PDA;
using Content.Shared.Traitor.Uplink;
using Robust.Client.AutoGenerated;
using Robust.Client.GameObjects;
using Robust.Client.ResourceManagement;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML;
using Robust.Client.Utility;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Maths;
using Robust.Shared.Prototypes;
namespace Content.Client.Traitor.Uplink
@@ -14,18 +18,25 @@ namespace Content.Client.Traitor.Uplink
[GenerateTypedNameReferences]
public partial class UplinkMenu : SS14Window
{
private readonly IPrototypeManager _prototypeManager;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IResourceCache _resourceCache = default!;
private UplinkWithdrawWindow? _withdrawWindow;
public event Action<BaseButton.ButtonEventArgs, UplinkListingData>? OnListingButtonPressed;
public event Action<BaseButton.ButtonEventArgs, UplinkCategory>? OnCategoryButtonPressed;
public event Action<int>? OnWithdrawAttempt;
public UplinkMenu(IPrototypeManager prototypeManager)
private UplinkCategory _currentFilter;
private UplinkAccountData? _loggedInUplinkAccount;
public UplinkMenu()
{
RobustXamlLoader.Load(this);
_prototypeManager = prototypeManager;
IoCManager.InjectDependencies(this);
PopulateUplinkCategoryButtons();
WithdrawButton.OnButtonDown += OnWithdrawButtonDown;
}
public UplinkCategory CurrentFilterCategory
@@ -42,16 +53,60 @@ namespace Content.Client.Traitor.Uplink
}
}
public UplinkAccountData? CurrentLoggedInAccount
public void UpdateAccount(UplinkAccountData account)
{
get => _loggedInUplinkAccount;
set => _loggedInUplinkAccount = value;
_loggedInUplinkAccount = account;
// update balance label
var balance = account.DataBalance;
var weightedColor = balance switch
{
<= 0 => "gray",
<= 5 => "green",
<= 20 => "yellow",
<= 50 => "purple",
_ => "gray"
};
var balanceStr = Loc.GetString("uplink-bound-user-interface-tc-balance-popup",
("weightedColor", weightedColor),
("balance", balance));
BalanceInfo.SetMarkup(balanceStr);
// you can't withdraw if you don't have TC
WithdrawButton.Disabled = balance <= 0;
}
private UplinkCategory _currentFilter;
private UplinkAccountData? _loggedInUplinkAccount;
public void UpdateListing(UplinkListingData[] listings)
{
// should probably chunk these out instead. to-do if this clogs the internet tubes.
// maybe read clients prototypes instead?
ClearListings();
foreach (var item in listings)
{
AddListingGui(item);
}
}
public void AddListingGui(UplinkListingData listing)
private void OnWithdrawButtonDown(BaseButton.ButtonEventArgs args)
{
if (_loggedInUplinkAccount == null)
return;
// check if window is already open
if (_withdrawWindow != null && _withdrawWindow.IsOpen)
{
_withdrawWindow.MoveToFront();
return;
}
// open a new one
_withdrawWindow = new UplinkWithdrawWindow(_loggedInUplinkAccount.DataBalance);
_withdrawWindow.OpenCentered();
_withdrawWindow.OnWithdrawAttempt += OnWithdrawAttempt;
}
private void AddListingGui(UplinkListingData listing)
{
if (!_prototypeManager.TryIndex(listing.ItemId, out EntityPrototype? prototype) || listing.Category != CurrentFilterCategory)
{
@@ -63,14 +118,19 @@ namespace Content.Client.Traitor.Uplink
var listingPrice = listing.Price;
var canBuy = _loggedInUplinkAccount?.DataBalance >= listing.Price;
var newListing = new UplinkListingControl(listingName, listingDesc, listingPrice, canBuy);
var texture = listing.Icon?.Frame0();
if (texture == null)
texture = SpriteComponent.GetPrototypeIcon(prototype, _resourceCache).Default;
var newListing = new UplinkListingControl(listingName, listingDesc, listingPrice, canBuy, texture);
newListing.UplinkItemBuyButton.OnButtonDown += args
=> OnListingButtonPressed?.Invoke(args, listing);
UplinkListingsContainer.AddChild(newListing);
}
public void ClearListings()
private void ClearListings()
{
UplinkListingsContainer.Children.Clear();
}
@@ -93,6 +153,12 @@ namespace Content.Client.Traitor.Uplink
}
}
public override void Close()
{
base.Close();
_withdrawWindow?.Close();
}
private sealed class PDAUplinkCategoryButton : Button
{
public UplinkCategory ButtonCategory;

View File

@@ -0,0 +1,22 @@
<SS14Window xmlns="https://spacestation14.io"
Title="{Loc 'uplink-user-interface-withdraw-title'}"
MinSize="256 128">
<BoxContainer Orientation="Vertical"
HorizontalExpand="True"
VerticalExpand="True">
<SliderIntInput Name="WithdrawSlider"
HorizontalExpand="True"/>
<BoxContainer Orientation="Horizontal"
VerticalExpand="True"
VerticalAlignment="Bottom">
<Button Name="ApplyButton"
Text="{Loc 'uplink-user-interface-withdraw-withdraw-button'}"
HorizontalAlignment="Left"
HorizontalExpand="True"/>
<Button Name="CancelButton"
Text="{Loc 'uplink-user-interface-withdraw-cancel-button'}"
HorizontalAlignment="Right"
HorizontalExpand="True"/>
</BoxContainer>
</BoxContainer>
</SS14Window>

View File

@@ -0,0 +1,34 @@
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Localization;
namespace Content.Client.Traitor.Uplink
{
/// <summary>
/// Window to select amount TC to withdraw from Uplink account
/// Used as sub-window in Uplink UI
/// </summary>
[GenerateTypedNameReferences]
public partial class UplinkWithdrawWindow : SS14Window
{
public event System.Action<int>? OnWithdrawAttempt;
public UplinkWithdrawWindow(int tcCount)
{
RobustXamlLoader.Load(this);
// setup withdraw slider
WithdrawSlider.MinValue = 1;
WithdrawSlider.MaxValue = tcCount;
// and buttons
ApplyButton.OnButtonDown += _ =>
{
OnWithdrawAttempt?.Invoke(WithdrawSlider.Value);
Close();
};
CancelButton.OnButtonDown += _ => Close();
}
}
}