Revs (the spooky ones) (#9842)

This commit is contained in:
Nemanja
2022-08-13 09:49:41 -04:00
committed by GitHub
parent ab4e2ef74f
commit 3e1cf73469
68 changed files with 1976 additions and 34 deletions

View File

@@ -19,7 +19,7 @@ namespace Content.Client.Ghost
// No good way to get an event into the UI.
public int AvailableGhostRoleCount { get; private set; } = 0;
private bool _ghostVisibility;
private bool _ghostVisibility = true;
private bool GhostVisibility
{
@@ -33,12 +33,9 @@ namespace Content.Client.Ghost
_ghostVisibility = value;
foreach (var ghost in EntityManager.GetAllComponents(typeof(GhostComponent), true))
foreach (var ghost in EntityQuery<GhostComponent, SpriteComponent>(true))
{
if (EntityManager.TryGetComponent(ghost.Owner, out SpriteComponent? sprite))
{
sprite.Visible = value;
}
ghost.Item2.Visible = true;
}
}
}
@@ -69,12 +66,6 @@ namespace Content.Client.Ghost
{
component.Gui?.Dispose();
component.Gui = null;
// PlayerDetachedMsg might not fire due to deletion order so...
if (component.IsAttached)
{
GhostVisibility = false;
}
}
private void OnGhostPlayerAttach(EntityUid uid, GhostComponent component, PlayerAttachedEvent playerAttachedEvent)

View File

@@ -0,0 +1,16 @@
using Content.Shared.Revenant;
namespace Content.Client.Revenant;
[RegisterComponent]
public sealed class RevenantComponent : SharedRevenantComponent
{
[DataField("state")]
public string State = "idle";
[DataField("corporealState")]
public string CorporealState = "active";
[DataField("stunnedState")]
public string StunnedState = "stunned";
[DataField("harvestingState")]
public string HarvestingState = "harvesting";
}

View File

@@ -0,0 +1,36 @@
using Content.Shared.Revenant;
using Robust.Client.GameObjects;
namespace Content.Client.Revenant;
public sealed class RevenantSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<RevenantComponent, AppearanceChangeEvent>(OnAppearanceChange);
}
private void OnAppearanceChange(EntityUid uid, RevenantComponent component, ref AppearanceChangeEvent args)
{
if (args.Sprite == null)
return;
if (args.Component.TryGetData(RevenantVisuals.Harvesting, out bool harvesting) && harvesting)
{
args.Sprite.LayerSetState(0, component.HarvestingState);
}
else if (args.Component.TryGetData(RevenantVisuals.Stunned, out bool stunned) && stunned)
{
args.Sprite.LayerSetState(0, component.StunnedState);
}
else if (args.Component.TryGetData(RevenantVisuals.Corporeal, out bool corporeal))
{
if (corporeal)
args.Sprite.LayerSetState(0, component.CorporealState);
else
args.Sprite.LayerSetState(0, component.State);
}
}
}

View File

@@ -0,0 +1,56 @@
using Content.Client.Traitor.Uplink;
using Content.Shared.Revenant;
using Content.Shared.Traitor.Uplink;
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

@@ -0,0 +1,21 @@
<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

@@ -0,0 +1,26 @@
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

@@ -0,0 +1,41 @@
<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

@@ -0,0 +1,62 @@
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();
}
}

View File

@@ -119,7 +119,6 @@ namespace Content.Client.Traitor.Uplink
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);