Moving PDA to ECS (#4538)
* Moved pen slot to separate component * Moved it all to more generic item slot class * Add sounds * Item slots now supports many slots * Some clean-up * Refactored slots a bit * Moving ID card out * Moving pda to system * Moving PDA owner to ECS * Moved PDA flashlight to separate component * Toggle lights work through events * Fixing UI * Moving uplink to separate component * Continue moving uplink to separate component * More cleaning * Removing pda shared * Nuked shared pda component * Fixed flashlight * Pen slot now showed in UI * Light toggle now shows correctly in UI * Small refactoring of item slots * Added contained entity * Fixed tests * Finished with PDA * Moving PDA uplink to separate window * Adding-removing uplink should show new button * Working on a better debug * Debug command to add uplink * Uplink send state to UI * Almost working UI * Uplink correcty updates when you buy-sell items * Ups * Moved localization to separate file * Minor fixes * Removed item slots methods events * Removed PDA owner name * Removed one uplink event * Deleted all uplink events * Removed flashlight events * Update Content.Shared/Traitor/Uplink/UplinkVisuals.cs Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> * Update Content.Server/Containers/ItemSlot/ItemSlotsSystem.cs Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> * Update Content.Server/Containers/ItemSlot/ItemSlotsSystem.cs Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> * Update Content.Server/GameTicking/Presets/PresetTraitorDeathMatch.cs Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> * Item slots system review * Flashlight review * PDA to XAML * Move UplinkMenu to seperate class, fix WeightedColors methods * Move UI to XAML * Moved events to entity id * Address review * Removed uplink extensions * Minor fix * Moved item slots to shared * My bad Robust... * Fixed pda sound * Fixed pda tests * Fixed pda test again Co-authored-by: Alexander Evgrashin <evgrashin.adl@gmail.com> Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Co-authored-by: Visne <vincefvanwijk@gmail.com>
This commit is contained in:
112
Content.Client/Traitor/Uplink/UplinkBoundUserInterface.cs
Normal file
112
Content.Client/Traitor/Uplink/UplinkBoundUserInterface.cs
Normal file
@@ -0,0 +1,112 @@
|
||||
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)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void Open()
|
||||
{
|
||||
_menu = new UplinkMenu(_prototypeManager);
|
||||
_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));
|
||||
};
|
||||
|
||||
_menu.OnCategoryButtonPressed += (_, category) =>
|
||||
{
|
||||
_menu.CurrentFilterCategory = category;
|
||||
SendMessage(new UplinkRequestUpdateInterfaceMessage());
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class UplinkMenuPopup : Popup
|
||||
{
|
||||
public UplinkMenuPopup(string text)
|
||||
{
|
||||
var label = new RichTextLabel();
|
||||
label.SetMessage(text);
|
||||
AddChild(new PanelContainer
|
||||
{
|
||||
StyleClasses = { ExamineSystem.StyleClassEntityTooltip },
|
||||
Children = { label }
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
43
Content.Client/Traitor/Uplink/UplinkMenu.xaml
Normal file
43
Content.Client/Traitor/Uplink/UplinkMenu.xaml
Normal file
@@ -0,0 +1,43 @@
|
||||
<SS14Window xmlns="https://spacestation14.io"
|
||||
xmlns:gfx="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client"
|
||||
Title="{Loc 'pda-bound-user-interface-uplink-tab-title'}"
|
||||
MinSize="512 512"
|
||||
SetSize="512 512">
|
||||
<BoxContainer Orientation="Vertical">
|
||||
<BoxContainer Orientation="Vertical"
|
||||
VerticalExpand="True">
|
||||
<RichTextLabel Name="BalanceInfoProtected"
|
||||
HorizontalAlignment="Center" />
|
||||
<PanelContainer VerticalExpand="True">
|
||||
<PanelContainer.PanelOverride>
|
||||
<gfx:StyleBoxFlat BackgroundColor="#000000FF" />
|
||||
</PanelContainer.PanelOverride>
|
||||
<SplitContainer Orientation="Horizontal"
|
||||
VerticalExpand="True">
|
||||
<PanelContainer VerticalExpand="True">
|
||||
<PanelContainer.PanelOverride>
|
||||
<gfx:StyleBoxFlat BackgroundColor="#80808005" />
|
||||
</PanelContainer.PanelOverride>
|
||||
<BoxContainer Name="CategoryListContainer"
|
||||
Orientation="Vertical">
|
||||
<!-- Category buttons are added here by code -->
|
||||
</BoxContainer>
|
||||
</PanelContainer>
|
||||
<ScrollContainer HorizontalExpand="True"
|
||||
VerticalExpand="True"
|
||||
SizeFlagsStretchRatio="2"
|
||||
MinSize="100 256">
|
||||
<BoxContainer Name="UplinkListingsContainer"
|
||||
Orientation="Vertical"
|
||||
HorizontalExpand="True"
|
||||
VerticalExpand="True"
|
||||
SizeFlagsStretchRatio="2"
|
||||
MinSize="100 256">
|
||||
<!-- Listings are added here by code -->
|
||||
</BoxContainer>
|
||||
</ScrollContainer>
|
||||
</SplitContainer>
|
||||
</PanelContainer>
|
||||
</BoxContainer>
|
||||
</BoxContainer>
|
||||
</SS14Window>
|
||||
166
Content.Client/Traitor/Uplink/UplinkMenu.xaml.cs
Normal file
166
Content.Client/Traitor/Uplink/UplinkMenu.xaml.cs
Normal file
@@ -0,0 +1,166 @@
|
||||
using System;
|
||||
using Content.Shared.PDA;
|
||||
using Content.Shared.Traitor.Uplink;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Client.Traitor.Uplink
|
||||
{
|
||||
[GenerateTypedNameReferences]
|
||||
public partial class UplinkMenu : SS14Window
|
||||
{
|
||||
private readonly IPrototypeManager _prototypeManager;
|
||||
|
||||
public RichTextLabel BalanceInfo => BalanceInfoProtected;
|
||||
public event Action<BaseButton.ButtonEventArgs, UplinkListingData>? OnListingButtonPressed;
|
||||
public event Action<BaseButton.ButtonEventArgs, UplinkCategory>? OnCategoryButtonPressed;
|
||||
|
||||
public UplinkMenu(IPrototypeManager prototypeManager)
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
|
||||
_prototypeManager = prototypeManager;
|
||||
|
||||
PopulateUplinkCategoryButtons();
|
||||
}
|
||||
|
||||
public UplinkCategory CurrentFilterCategory
|
||||
{
|
||||
get => _currentFilter;
|
||||
set
|
||||
{
|
||||
if (value.GetType() != typeof(UplinkCategory))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_currentFilter = value;
|
||||
}
|
||||
}
|
||||
|
||||
public UplinkAccountData? CurrentLoggedInAccount
|
||||
{
|
||||
get => _loggedInUplinkAccount;
|
||||
set => _loggedInUplinkAccount = value;
|
||||
}
|
||||
|
||||
private UplinkCategory _currentFilter;
|
||||
private UplinkAccountData? _loggedInUplinkAccount;
|
||||
|
||||
public void AddListingGui(UplinkListingData listing)
|
||||
{
|
||||
if (!_prototypeManager.TryIndex(listing.ItemId, out EntityPrototype? prototype) || listing.Category != CurrentFilterCategory)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var weightedColor = listing.Price switch
|
||||
{
|
||||
<= 0 => Color.Gray,
|
||||
<= 5 => Color.Green,
|
||||
<= 10 => Color.Yellow,
|
||||
<= 20 => Color.Orange,
|
||||
<= 50 => Color.Purple,
|
||||
_ => Color.Gray
|
||||
};
|
||||
var itemLabel = new Label
|
||||
{
|
||||
Text = listing.ListingName == string.Empty ? prototype.Name : listing.ListingName,
|
||||
ToolTip = listing.Description == string.Empty ? prototype.Description : listing.Description,
|
||||
HorizontalExpand = true,
|
||||
Modulate = _loggedInUplinkAccount?.DataBalance >= listing.Price
|
||||
? Color.White
|
||||
: Color.Gray.WithAlpha(0.30f)
|
||||
};
|
||||
|
||||
var priceLabel = new Label
|
||||
{
|
||||
Text = $"{listing.Price} TC",
|
||||
HorizontalAlignment = HAlignment.Right,
|
||||
Modulate = _loggedInUplinkAccount?.DataBalance >= listing.Price
|
||||
? weightedColor
|
||||
: Color.Gray.WithAlpha(0.30f)
|
||||
};
|
||||
|
||||
//Padding for the price lable.
|
||||
var pricePadding = new BoxContainer
|
||||
{
|
||||
Orientation = BoxContainer.LayoutOrientation.Horizontal,
|
||||
MinSize = (32, 1),
|
||||
};
|
||||
|
||||
//Contains the name of the item and its price. Used for spacing item name and price.
|
||||
var listingButtonHbox = new BoxContainer
|
||||
{
|
||||
Orientation = BoxContainer.LayoutOrientation.Horizontal,
|
||||
Children =
|
||||
{
|
||||
itemLabel,
|
||||
priceLabel,
|
||||
pricePadding
|
||||
}
|
||||
};
|
||||
|
||||
var listingButtonPanelContainer = new PanelContainer
|
||||
{
|
||||
Children =
|
||||
{
|
||||
listingButtonHbox
|
||||
}
|
||||
};
|
||||
|
||||
var pdaUplinkListingButton = new PDAUplinkItemButton(listing)
|
||||
{
|
||||
Children =
|
||||
{
|
||||
listingButtonPanelContainer
|
||||
}
|
||||
};
|
||||
pdaUplinkListingButton.OnPressed += args
|
||||
=> OnListingButtonPressed?.Invoke(args, pdaUplinkListingButton.ButtonListing);
|
||||
UplinkListingsContainer.AddChild(pdaUplinkListingButton);
|
||||
}
|
||||
|
||||
public void ClearListings()
|
||||
{
|
||||
UplinkListingsContainer.Children.Clear();
|
||||
}
|
||||
|
||||
private void PopulateUplinkCategoryButtons()
|
||||
{
|
||||
foreach (UplinkCategory cat in Enum.GetValues(typeof(UplinkCategory)))
|
||||
{
|
||||
var catButton = new PDAUplinkCategoryButton
|
||||
{
|
||||
Text = Loc.GetString(cat.ToString()),
|
||||
ButtonCategory = cat
|
||||
};
|
||||
//It'd be neat if it could play a cool tech ping sound when you switch categories,
|
||||
//but right now there doesn't seem to be an easy way to do client-side audio without still having to round trip to the server and
|
||||
//send to a specific client INetChannel.
|
||||
catButton.OnPressed += args => OnCategoryButtonPressed?.Invoke(args, catButton.ButtonCategory);
|
||||
|
||||
CategoryListContainer.AddChild(catButton);
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class PDAUplinkItemButton : ContainerButton
|
||||
{
|
||||
public PDAUplinkItemButton(UplinkListingData data)
|
||||
{
|
||||
ButtonListing = data;
|
||||
}
|
||||
|
||||
public UplinkListingData ButtonListing { get; }
|
||||
}
|
||||
|
||||
private sealed class PDAUplinkCategoryButton : Button
|
||||
{
|
||||
public UplinkCategory ButtonCategory;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user