revenant cleanup (#10662)

This commit is contained in:
Nemanja
2022-08-18 20:04:23 -04:00
committed by GitHub
parent b8ce23f666
commit d7e0b70e2c
18 changed files with 92 additions and 388 deletions

View File

@@ -1,54 +0,0 @@
using Content.Shared.Revenant;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
namespace Content.Client.Revenant.Ui;
[UsedImplicitly]
public sealed class RevenantBoundUserInterface : BoundUserInterface
{
private RevenantMenu? _menu;
public RevenantBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey)
{
}
protected override void Open()
{
_menu = new();
_menu.OpenCentered();
_menu.OnClose += Close;
_menu.OnListingButtonPressed += (_, listing) =>
{
SendMessage(new RevenantBuyListingMessage(listing));
};
}
protected override void UpdateState(BoundUserInterfaceState state)
{
base.UpdateState(state);
if (_menu == null)
return;
switch (state)
{
case RevenantUpdateState msg:
_menu.UpdateEssence(msg.Essence);
_menu.UpdateListing(msg.Listings);
break;
}
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (!disposing)
return;
_menu?.Close();
_menu?.Dispose();
}
}

View File

@@ -1,21 +0,0 @@
<Control xmlns="https://spacestation14.io">
<BoxContainer Margin="8,8,8,8" Orientation="Vertical">
<BoxContainer Orientation="Horizontal">
<Label Name="RevenantItemName" HorizontalExpand="True" />
<Button
Name="RevenantItemBuyButton"
MinWidth="64"
HorizontalAlignment="Right"
Access="Public" />
</BoxContainer>
<PanelContainer StyleClasses="HighDivider" />
<BoxContainer HorizontalExpand="True" Orientation="Horizontal">
<TextureRect
Name="RevenantItemTexture"
Margin="0,0,4,0"
MinSize="48 48"
Stretch="KeepAspectCentered" />
<RichTextLabel Name="RevenantItemDescription" />
</BoxContainer>
</BoxContainer>
</Control>

View File

@@ -1,26 +0,0 @@
using Robust.Client.AutoGenerated;
using Robust.Client.Graphics;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Maths;
namespace Content.Client.Revenant.Ui;
[GenerateTypedNameReferences]
public sealed partial class RevenantListingControl : Control
{
public RevenantListingControl(string itemName, string itemDescription,
int itemPrice, bool canBuy, Texture? texture = null)
{
RobustXamlLoader.Load(this);
RevenantItemName.Text = itemName;
RevenantItemDescription.SetMessage(itemDescription);
RevenantItemBuyButton.Text = Loc.GetString("revenant-user-interface-cost", ("price", itemPrice));
RevenantItemBuyButton.Disabled = !canBuy;
RevenantItemTexture.Texture = texture;
}
}

View File

@@ -1,41 +0,0 @@
<DefaultWindow
xmlns="https://spacestation14.io"
xmlns:gfx="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client"
Title="{Loc 'revenant-user-interface-title'}"
MinSize="512 512"
SetSize="512 512">
<BoxContainer Orientation="Vertical">
<BoxContainer Orientation="Vertical" VerticalExpand="True">
<BoxContainer Margin="4,4,4,4" Orientation="Horizontal">
<RichTextLabel
Name="BalanceInfo"
HorizontalAlignment="Left"
Access="Public"
HorizontalExpand="True" />
</BoxContainer>
<PanelContainer VerticalExpand="True">
<PanelContainer.PanelOverride>
<gfx:StyleBoxFlat BackgroundColor="#000000FF" />
</PanelContainer.PanelOverride>
<BoxContainer Orientation="Horizontal" VerticalExpand="True">
<ScrollContainer
Name="RevenantListingsScroll"
HScrollEnabled="False"
HorizontalExpand="True"
MinSize="100 256"
SizeFlagsStretchRatio="2"
VerticalExpand="True">
<BoxContainer
Name="RevenantListingsContainer"
MinSize="100 256"
Orientation="Vertical"
SizeFlagsStretchRatio="2"
VerticalExpand="True">
<!-- Listings are added here by code -->
</BoxContainer>
</ScrollContainer>
</BoxContainer>
</PanelContainer>
</BoxContainer>
</BoxContainer>
</DefaultWindow>

View File

@@ -1,62 +0,0 @@
using Content.Client.Message;
using Content.Shared.FixedPoint;
using Content.Shared.Revenant;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML;
using Robust.Client.Utility;
namespace Content.Client.Revenant.Ui;
[GenerateTypedNameReferences]
public sealed partial class RevenantMenu : DefaultWindow
{
private FixedPoint2 _essence = 0f;
public event Action<BaseButton.ButtonEventArgs, RevenantStoreListingPrototype>? OnListingButtonPressed;
public RevenantMenu()
{
RobustXamlLoader.Load(this);
}
public void UpdateEssence(float essence)
{
// update balance label
_essence = essence;
var balanceStr = Loc.GetString("revenant-user-interface-essence-amount", ("amount", Math.Round(_essence.Float())));
BalanceInfo.SetMarkup(balanceStr);
}
public void UpdateListing(List<RevenantStoreListingPrototype> 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);
}
}
private void AddListingGui(RevenantStoreListingPrototype listing)
{
var listingName = listing.ListingName;
var listingDesc = listing.Description;
var listingPrice = listing.Price;
var canBuy = _essence > listing.Price;
var texture = listing.Icon?.Frame0();
var newListing = new RevenantListingControl(listingName, listingDesc, listingPrice, canBuy, texture);
newListing.RevenantItemBuyButton.OnButtonDown += args
=> OnListingButtonPressed?.Invoke(args, listing);
RevenantListingsContainer.AddChild(newListing);
}
private void ClearListings()
{
RevenantListingsContainer.Children.Clear();
}
}