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:
@@ -1,6 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Content.Server.Mind.Components;
|
||||
using Content.Server.Stack;
|
||||
using Content.Shared.Stacks;
|
||||
using Content.Shared.Traitor.Uplink;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
@@ -13,8 +16,12 @@ namespace Content.Server.Traitor.Uplink.Account
|
||||
/// </summary>
|
||||
public class UplinkAccountsSystem : EntitySystem
|
||||
{
|
||||
public const string TelecrystalProtoId = "Telecrystal";
|
||||
|
||||
[Dependency]
|
||||
private readonly UplinkListingSytem _listingSystem = default!;
|
||||
[Dependency]
|
||||
private readonly SharedStackSystem _stackSystem = default!;
|
||||
|
||||
private readonly HashSet<UplinkAccount> _accounts = new();
|
||||
|
||||
@@ -86,5 +93,25 @@ namespace Content.Server.Traitor.Uplink.Account
|
||||
purchasedItem = EntityManager.SpawnEntity(listing.ItemId, spawnCoords);
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool TryWithdrawTC(UplinkAccount acc, int tc, EntityCoordinates spawnCoords, [NotNullWhen(true)] out EntityUid? stackUid)
|
||||
{
|
||||
stackUid = null;
|
||||
|
||||
// try to charge TC from players account
|
||||
var actTC = Math.Min(tc, acc.Balance);
|
||||
if (actTC <= 0)
|
||||
return false;
|
||||
if (!RemoveFromBalance(acc, actTC))
|
||||
return false;
|
||||
|
||||
// create a stack of TCs near player
|
||||
var stackEntity = EntityManager.SpawnEntity(TelecrystalProtoId, spawnCoords);
|
||||
stackUid = stackEntity.Uid;
|
||||
|
||||
// set right amount in stack
|
||||
_stackSystem.SetCount(stackUid.Value, actTC);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace Content.Server.Traitor.Uplink
|
||||
foreach (var item in _prototypeManager.EnumeratePrototypes<UplinkStoreListingPrototype>())
|
||||
{
|
||||
var newListing = new UplinkListingData(item.ListingName, item.ItemId,
|
||||
item.Price, item.Category, item.Description);
|
||||
item.Price, item.Category, item.Description, item.Icon);
|
||||
|
||||
RegisterUplinkListing(newListing);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ using Content.Server.PDA;
|
||||
using Content.Server.Traitor.Uplink.Account;
|
||||
using Content.Server.Traitor.Uplink.Components;
|
||||
using Content.Server.UserInterface;
|
||||
using Content.Shared.Hands.Components;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Traitor.Uplink;
|
||||
using Robust.Server.GameObjects;
|
||||
@@ -34,8 +35,11 @@ namespace Content.Server.Traitor.Uplink
|
||||
SubscribeLocalEvent<UplinkComponent, ComponentInit>(OnInit);
|
||||
SubscribeLocalEvent<UplinkComponent, ComponentRemove>(OnRemove);
|
||||
SubscribeLocalEvent<UplinkComponent, UseInHandEvent>(OnUseHand);
|
||||
|
||||
// UI events
|
||||
SubscribeLocalEvent<UplinkComponent, UplinkBuyListingMessage>(OnBuy);
|
||||
SubscribeLocalEvent<UplinkComponent, UplinkRequestUpdateInterfaceMessage>(OnRequestUpdateUI);
|
||||
SubscribeLocalEvent<UplinkComponent, UplinkTryWithdrawTC>(OnWithdrawTC);
|
||||
|
||||
SubscribeLocalEvent<UplinkAccountBalanceChanged>(OnBalanceChangedBroadcast);
|
||||
}
|
||||
@@ -131,6 +135,31 @@ namespace Content.Server.Traitor.Uplink
|
||||
RaiseNetworkEvent(new UplinkBuySuccessMessage(), message.Session.ConnectedClient);
|
||||
}
|
||||
|
||||
private void OnWithdrawTC(EntityUid uid, UplinkComponent uplink, UplinkTryWithdrawTC args)
|
||||
{
|
||||
var acc = uplink.UplinkAccount;
|
||||
if (acc == null)
|
||||
return;
|
||||
|
||||
var player = args.Session.AttachedEntity;
|
||||
if (player == null) return;
|
||||
var cords = player.Transform.Coordinates;
|
||||
|
||||
// try to withdraw TCs from account
|
||||
if (!_accounts.TryWithdrawTC(acc, args.TC, cords, out var tcUid))
|
||||
return;
|
||||
|
||||
// try to put it into players hands
|
||||
if (player.TryGetComponent(out SharedHandsComponent? hands))
|
||||
hands.TryPutInAnyHand(EntityManager.GetEntity(tcUid.Value));
|
||||
|
||||
// play buying sound
|
||||
SoundSystem.Play(Filter.SinglePlayer(args.Session), uplink.BuySuccessSound.GetSound(),
|
||||
uplink.Owner, AudioParams.Default.WithVolume(-2f));
|
||||
|
||||
UpdateUserInterface(uplink);
|
||||
}
|
||||
|
||||
public void ToggleUplinkUI(UplinkComponent component, IPlayerSession session)
|
||||
{
|
||||
var ui = component.Owner.GetUIOrNull(UplinkUiKey.Key);
|
||||
|
||||
Reference in New Issue
Block a user