Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport Goob/EE playing card fixes (Goob#1215 and #1311 via EE#1451) #2861

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion Content.Client/Inventory/StrippableBoundUserInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
using Robust.Shared.Map;
using static Content.Client.Inventory.ClientInventorySystem;
using static Robust.Client.UserInterface.Control;
using Content.Shared._EE.Strip.Components; // EE

namespace Content.Client.Inventory
{
Expand Down Expand Up @@ -172,7 +173,9 @@ private void AddHandButton(Hand hand)
button.BlockedRect.MouseFilter = MouseFilterMode.Ignore;
}

UpdateEntityIcon(button, hand.HeldEntity);
// Goobstation: use virtual entity if hidden
UpdateEntityIcon(button, EntMan.HasComponent<StripMenuHiddenComponent>(hand.HeldEntity) ? _virtualHiddenEntity : hand.HeldEntity);
// End Goobstation
_strippingMenu!.HandsContainer.AddChild(button);
}

Expand Down Expand Up @@ -214,6 +217,11 @@ private void AddInventoryButton(EntityUid invUid, string slotId, InventoryCompon
if (entity != null && _strippable.IsStripHidden(slotDef, _player.LocalEntity))
entity = _virtualHiddenEntity;

// Goobstation/EE: hide strip menu items
if (entity != null && EntMan.HasComponent<StripMenuHiddenComponent>(entity))
entity = _virtualHiddenEntity;
// End Goobstation/EE

var button = new SlotButton(new SlotData(slotDef, container));
button.Pressed += SlotPressed;

Expand Down
14 changes: 1 addition & 13 deletions Content.Client/_EstacaoPirata/Cards/Card/CardSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ namespace Content.Client._EstacaoPirata.Cards.Card;
/// </summary>
public sealed class CardSystem : EntitySystem
{
[Dependency] private readonly SpriteSystem _spriteSystem = default!;
/// <inheritdoc/>
public override void Initialize()
{
Expand Down Expand Up @@ -38,7 +37,7 @@ private void OnComponentStartupEvent(EntityUid uid, CardComponent comp, Componen
}

comp.BackSprite ??= comp.FrontSprite;
Dirty(uid, comp);
DirtyEntity(uid);
UpdateSprite(uid, comp);
}

Expand All @@ -52,30 +51,19 @@ private void OnFlip(CardFlipUpdatedEvent args)
private void UpdateSprite(EntityUid uid, CardComponent comp)
{
var newSprite = comp.Flipped ? comp.BackSprite : comp.FrontSprite;
if (newSprite == null)
return;

if (!TryComp(uid, out SpriteComponent? spriteComponent))
return;

var layerCount = newSprite.Count();

//inserts Missing Layers
if (spriteComponent.AllLayers.Count() < layerCount)
{
for (var i = spriteComponent.AllLayers.Count(); i < layerCount; i++)
{
spriteComponent.AddBlankLayer(i);
}
}
//Removes extra layers
else if (spriteComponent.AllLayers.Count() > layerCount)
{
for (var i = spriteComponent.AllLayers.Count() - 1; i >= layerCount; i--)
{
spriteComponent.RemoveLayer(i);
}
}

for (var i = 0; i < newSprite.Count(); i++)
{
Expand Down
21 changes: 6 additions & 15 deletions Content.Client/_EstacaoPirata/Cards/CardSpriteSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ namespace Content.Client._EstacaoPirata.Cards;
public sealed class CardSpriteSystem : EntitySystem
{
/// <inheritdoc/>
public override void Initialize()
{

}
public override void Initialize() { }

public bool TryAdjustLayerQuantity(Entity<SpriteComponent, CardStackComponent> uid, int? cardLimit = null)
{
Expand All @@ -23,7 +20,8 @@ public bool TryAdjustLayerQuantity(Entity<SpriteComponent, CardStackComponent> u

var layerCount = 0;
//Gets the quantity of layers
foreach (var card in stack.Cards.TakeLast(cardCount))
var relevantCards = stack.Cards.TakeLast(cardCount).ToList();
foreach (var card in relevantCards)
{
if (!TryComp(card, out SpriteComponent? cardSprite))
return false;
Expand All @@ -33,21 +31,13 @@ public bool TryAdjustLayerQuantity(Entity<SpriteComponent, CardStackComponent> u
layerCount = int.Max(1, layerCount); // Frontier: you need one layer.
//inserts Missing Layers
if (sprite.AllLayers.Count() < layerCount)
{
for (var i = sprite.AllLayers.Count(); i < layerCount; i++)
{
sprite.AddBlankLayer(i);
}
}

//Removes extra layers
else if (sprite.AllLayers.Count() > layerCount)
{
for (var i = sprite.AllLayers.Count() - 1; i >= layerCount; i--)
{
sprite.RemoveLayer(i);
}
}


return true;
}
Expand All @@ -61,7 +51,8 @@ public bool TryHandleLayerConfiguration(Entity<SpriteComponent, CardStackCompone
List<(int, ISpriteLayer)> layers = [];

var i = 0;
foreach (var card in stack.Cards.TakeLast(cardCount))
var cards = stack.Cards.TakeLast(cardCount).ToList();
foreach (var card in cards)
{
if (!TryComp(card, out SpriteComponent? cardSprite))
return false;
Expand Down
20 changes: 11 additions & 9 deletions Content.Client/_EstacaoPirata/Cards/Deck/CardDeckSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,8 @@ public override void Update(float frameTime)
private bool TryGetCardLayer(EntityUid card, out SpriteComponent.Layer? layer)
{
layer = null;
if (!TryComp(card, out SpriteComponent? cardSprite))
return false;

if (!cardSprite.TryGetLayer(0, out var l))
if (!TryComp(card, out SpriteComponent? cardSprite)
|| !cardSprite.TryGetLayer(0, out var l))
return false;

layer = l;
Expand All @@ -75,13 +73,10 @@ private bool TryGetCardLayer(EntityUid card, out SpriteComponent.Layer? layer)

private void UpdateSprite(EntityUid uid, CardDeckComponent comp)
{
if (!TryComp(uid, out SpriteComponent? sprite))
if (!TryComp(uid, out SpriteComponent? sprite)
|| !TryComp(uid, out CardStackComponent? cardStack))
return;

if (!TryComp(uid, out CardStackComponent? cardStack))
return;


// Prevents error appearing at spawnMenu
if (cardStack.Cards.Count <= 0 || !TryGetCardLayer(cardStack.Cards.Last(), out var cardlayer) ||
cardlayer == null)
Expand Down Expand Up @@ -132,7 +127,14 @@ private void OnAppearanceChanged(EntityUid uid, CardDeckComponent comp, Appearan
}
private void OnComponentStartupEvent(EntityUid uid, CardDeckComponent comp, ComponentStartup args)
{
if (!TryComp(uid, out CardStackComponent? stack))
{
_notInitialized[(uid, comp)] = 0;
return;
}

if (stack.Cards.Count <= 0)
_notInitialized[(uid, comp)] = 0;
UpdateSprite(uid, comp);
}

Expand Down
55 changes: 50 additions & 5 deletions Content.Client/_EstacaoPirata/Cards/Hand/CardHandSystem.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Linq;
using System.Numerics;
using Content.Shared._EstacaoPirata.Cards.Hand;
using Content.Shared._EstacaoPirata.Cards.Stack;
Expand All @@ -10,6 +11,7 @@ namespace Content.Client._EstacaoPirata.Cards.Hand;
/// </summary>
public sealed class CardHandSystem : EntitySystem
{
private readonly Dictionary<Entity<CardHandComponent>, int> _notInit = [];
[Dependency] private readonly CardSpriteSystem _cardSpriteSystem = default!;


Expand All @@ -23,13 +25,50 @@ public override void Initialize()
SubscribeNetworkEvent<CardStackFlippedEvent>(OnStackFlip);
}

public override void Update(float frameTime)
{
base.Update(frameTime);
foreach (var (ent, value) in _notInit)
{
if (value >= 5)
{
_notInit.Remove(ent);
continue;
}
_notInit[ent] = value + 1;
if (!TryComp(ent.Owner, out CardStackComponent? stack) || stack.Cards.Count <= 0)
continue;

// If cards were correctly initialized, we update the sprite
UpdateSprite(ent.Owner, ent.Comp);
_notInit.Remove(ent);
}
}

private bool TryGetCardLayer(EntityUid card, out SpriteComponent.Layer? layer)
{
layer = null;
if (!TryComp(card, out SpriteComponent? cardSprite)
|| !cardSprite.TryGetLayer(0, out var l))
return false;

layer = l;
return true;
}

private void UpdateSprite(EntityUid uid, CardHandComponent comp)
{
if (!TryComp(uid, out SpriteComponent? sprite))
if (!TryComp(uid, out SpriteComponent? sprite)
|| !TryComp(uid, out CardStackComponent? cardStack))
return;

if (!TryComp(uid, out CardStackComponent? cardStack))
// Prevents error appearing at spawnMenu
if (cardStack.Cards.Count <= 0 || !TryGetCardLayer(cardStack.Cards.Last(), out var cardlayer) ||
cardlayer == null)
{
_notInit[(uid, comp)] = 0;
return;
}

_cardSpriteSystem.TryAdjustLayerQuantity((uid, sprite, cardStack), comp.CardLimit);

Expand Down Expand Up @@ -60,15 +99,15 @@ private void UpdateSprite(EntityUid uid, CardHandComponent comp)
}
else
{
var intervalAngle = comp.Angle / (cardCount-1);
var intervalAngle = comp.Angle / (cardCount - 1);
var intervalSize = comp.XOffset / (cardCount - 1);

_cardSpriteSystem.TryHandleLayerConfiguration(
(uid, sprite, cardStack),
cardCount,
(sprt, cardIndex, layerIndex) =>
{
var angle = (-(comp.Angle/2)) + cardIndex * intervalAngle;
var angle = (-(comp.Angle / 2)) + cardIndex * intervalAngle;
var x = (-(comp.XOffset / 2)) + cardIndex * intervalSize;
var y = -(x * x) + 0.10f;

Expand Down Expand Up @@ -99,7 +138,13 @@ private void OnStackStart(CardStackInitiatedEvent args)
}
private void OnComponentStartupEvent(EntityUid uid, CardHandComponent comp, ComponentStartup args)
{

if (!TryComp(uid, out CardStackComponent? stack))
{
_notInit[(uid, comp)] = 0;
return;
}
if (stack.Cards.Count <= 0)
_notInit[(uid, comp)] = 0;
UpdateSprite(uid, comp);
}

Expand Down
20 changes: 3 additions & 17 deletions Content.Client/_EstacaoPirata/Cards/Hand/UI/CardHandMenu.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,13 @@ public sealed partial class CardHandMenu : RadialMenu
[Dependency] private readonly EntityManager _entManager = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;

private readonly SpriteSystem _spriteSystem;
private readonly SharedPopupSystem _popup;

public event Action<NetEntity>? CardHandDrawMessageAction;

private EntityUid _owner;

public CardHandMenu(EntityUid owner, CardHandMenuBoundUserInterface bui)
{
IoCManager.InjectDependencies(this);
RobustXamlLoader.Load(this);

_spriteSystem = _entManager.System<SpriteSystem>();
_popup = _entManager.System<SharedPopupSystem>();

_owner = owner;

// Find the main radial container
var main = FindControl<RadialContainer>("Main");

Expand All @@ -42,19 +32,15 @@ public CardHandMenu(EntityUid owner, CardHandMenuBoundUserInterface bui)

foreach (var card in stack.Cards)
{
if (_playerManager.LocalSession == null)
return;
if (!_entManager.TryGetComponent<CardComponent>(card, out var cardComp))
if (_playerManager.LocalSession == null
|| !_entManager.TryGetComponent<CardComponent>(card, out var cardComp))
return;

string cardName;
if (cardComp.Flipped && _entManager.TryGetComponent<MetaDataComponent>(card, out var metadata))
{
cardName = metadata.EntityName;
}
else
{
cardName = Loc.GetString(cardComp.Name);
}

var button = new CardMenuButton()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using Content.Shared._EstacaoPirata.Cards.Hand;
using Content.Shared.RCD;
using JetBrains.Annotations;
using Robust.Client.Graphics;
using Robust.Client.Input;
using Robust.Shared.Prototypes;

namespace Content.Client._EstacaoPirata.Cards.Hand.UI;

Expand Down Expand Up @@ -32,10 +30,7 @@ protected override void Open()
_menu.OpenCenteredAt(_inputManager.MouseScreenPosition.Position / vpSize);
}

public void SendCardHandDrawMessage(NetEntity e)
{
SendMessage(new CardHandDrawMessage(e));
}
public void SendCardHandDrawMessage(NetEntity e) => SendMessage(new CardHandDrawMessage(e));

protected override void Dispose(bool disposing)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Content.Shared.Storage;
using Robust.Shared.Prototypes;

namespace Content.Server._EstacaoPirata.OpenTriggeredStorageFill;

Expand All @@ -9,5 +8,6 @@ namespace Content.Server._EstacaoPirata.OpenTriggeredStorageFill;
[RegisterComponent]
public sealed partial class OpenTriggeredStorageFillComponent : Component
{
[DataField("contents")] public List<EntitySpawnEntry> Contents = new();
[DataField]
public List<EntitySpawnEntry> Contents = new();
}
Loading
Loading