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,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;