Skip to content

Commit

Permalink
zzre: Prevent deck from closing and close deck on button
Browse files Browse the repository at this point in the history
  • Loading branch information
Helco committed Jan 23, 2024
1 parent 6e84fa2 commit 86e9d50
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
14 changes: 8 additions & 6 deletions zzre/game/systems/ui/InGameScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ public static class InGameScreen
public static readonly components.ui.ElementId IDOpenMap = new(1004);
public static readonly components.ui.ElementId IDSaveGame = new(1005);

private record struct TabInfo(components.ui.ElementId Id, int PosX, int TileI, UID TooltipUID);
private record struct TabInfo(components.ui.ElementId Id, int PosX, int TileI, UID TooltipUID, StdItemId Item);
private static readonly TabInfo[] Tabs = new TabInfo[]
{
new(IDOpenDeck, PosX: 553, TileI: 21, TooltipUID: new(0xdeadbeef)),
new(IDOpenRunes, PosX: 427, TileI: 12, TooltipUID: new(0x6636B4A1)),
new(IDOpenFairybook, PosX: 469, TileI: 15, TooltipUID: new(0x8D1BBCA1)),
new(IDOpenMap, PosX: 511, TileI: 18, TooltipUID: new(0xC51E6991))
new(IDOpenDeck, PosX: 553, TileI: 21, TooltipUID: new(0xdeadbeef), StdItemId.FairyBag),
new(IDOpenRunes, PosX: 427, TileI: 12, TooltipUID: new(0x6636B4A1), StdItemId.RuneFairyGarden),
new(IDOpenFairybook, PosX: 469, TileI: 15, TooltipUID: new(0x8D1BBCA1), StdItemId.FairyBook),
new(IDOpenMap, PosX: 511, TileI: 18, TooltipUID: new(0xC51E6991), StdItemId.MapFairyGarden)
};

public static void CreateTopButtons(UIPreloader preload, in DefaultEcs.Entity parent, components.ui.ElementId curTab)
public static void CreateTopButtons(UIPreloader preload, in DefaultEcs.Entity parent, Inventory inventory, components.ui.ElementId curTab)
{
preload.CreateButton(parent)
.With(IDClose)
Expand All @@ -45,6 +45,8 @@ public static void CreateTopButtons(UIPreloader preload, in DefaultEcs.Entity pa

foreach (var tab in Tabs)
{
if (!inventory.Contains(tab.Item))
continue;
var tabButton = preload.CreateButton(parent)
.With(tab.Id)
.With(Mid + new Vector2(tab.PosX, 3))
Expand Down
7 changes: 4 additions & 3 deletions zzre/game/systems/ui/ScrDeck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ protected override void HandleOpen(in messages.ui.OpenDeck message)
{
var inventory = zanzarah.CurrentGame!.PlayerEntity.Get<Inventory>();
if (!inventory.Contains(StdItemId.FairyBag))
inventory.AddItem((int)StdItemId.FairyBag);
//return;
return;

var entity = World.CreateEntity();
entity.Set<components.ui.ScrDeck>();
Expand All @@ -70,7 +69,7 @@ protected override void HandleOpen(in messages.ui.OpenDeck message)

CreateBackgrounds(entity, ref deck);
CreateListControls(entity, ref deck);
CreateTopButtons(preload, entity, IDOpenDeck);
CreateTopButtons(preload, entity, inventory, IDOpenDeck);
CreateFairySlots(entity, ref deck);

if (deck.ActiveTab == Tab.None)
Expand Down Expand Up @@ -549,6 +548,8 @@ private void HandleElementDown(DefaultEcs.Entity clickedEntity, components.ui.El
UpdateSliderPosition(deck);
FillList(ref deck);
}
else if (id == IDClose)
deckEntity.Dispose();
}

private void UpdateSliderPosition(in components.ui.ScrDeck deck)
Expand Down

0 comments on commit 86e9d50

Please sign in to comment.