From 9dee987e66d1880943489dd9227b54770988279b Mon Sep 17 00:00:00 2001 From: AcipenserSturio Date: Thu, 25 Jan 2024 19:10:16 +0300 Subject: [PATCH 1/2] UI: book: add fairy buttons --- zzre/game/systems/ui/ScrBookMenu.cs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/zzre/game/systems/ui/ScrBookMenu.cs b/zzre/game/systems/ui/ScrBookMenu.cs index 27b9081f..2b9884ad 100644 --- a/zzre/game/systems/ui/ScrBookMenu.cs +++ b/zzre/game/systems/ui/ScrBookMenu.cs @@ -42,6 +42,30 @@ protected override void HandleOpen(in messages.ui.OpenBookMenu message) .Build(); CreateTopButtons(preload, entity, inventory, IDOpenFairybook); + CreateFairyButtons(preload, entity, inventory); + } + + private void CreateFairyButtons(UIPreloader preload, in DefaultEcs.Entity entity, Inventory inventory) + { + var fairies = db.Fairies.OrderBy(fairyRow => fairyRow.CardId.EntityId).ToArray(); + for (int i = 0; i < fairies.Length; i++) + { + var fairyRow = fairies[i]; + foreach (var ownedFairy in inventory.Fairies) + { + if (ownedFairy.cardId == fairyRow.CardId) + { + var element = new components.ui.ElementId(1 + i); + preload.CreateButton(entity) + .With(element) + .With(Mid + new Vector2(226 + 45 * (i % 9), 66 + 45 * (i / 9))) + .With(new components.ui.ButtonTiles(ownedFairy.cardId.EntityId)) + .With(preload.Wiz000) + .Build(); + break; + } + } + } } protected override void Update(float timeElapsed, in DefaultEcs.Entity entity, ref components.ui.ScrBookMenu bookMenu) From 2cf20a3928f4ecb27a9297f4d66d07eae2255503 Mon Sep 17 00:00:00 2001 From: AcipenserSturio Date: Thu, 25 Jan 2024 19:27:51 +0300 Subject: [PATCH 2/2] Use .Contains() instead of loop --- zzre/game/systems/ui/ScrBookMenu.cs | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/zzre/game/systems/ui/ScrBookMenu.cs b/zzre/game/systems/ui/ScrBookMenu.cs index 2b9884ad..1ddcb3dc 100644 --- a/zzre/game/systems/ui/ScrBookMenu.cs +++ b/zzre/game/systems/ui/ScrBookMenu.cs @@ -50,20 +50,15 @@ private void CreateFairyButtons(UIPreloader preload, in DefaultEcs.Entity entity var fairies = db.Fairies.OrderBy(fairyRow => fairyRow.CardId.EntityId).ToArray(); for (int i = 0; i < fairies.Length; i++) { - var fairyRow = fairies[i]; - foreach (var ownedFairy in inventory.Fairies) + if (inventory.Contains(fairies[i].CardId)) { - if (ownedFairy.cardId == fairyRow.CardId) - { - var element = new components.ui.ElementId(1 + i); - preload.CreateButton(entity) - .With(element) - .With(Mid + new Vector2(226 + 45 * (i % 9), 66 + 45 * (i / 9))) - .With(new components.ui.ButtonTiles(ownedFairy.cardId.EntityId)) - .With(preload.Wiz000) - .Build(); - break; - } + var element = new components.ui.ElementId(1 + i); + preload.CreateButton(entity) + .With(element) + .With(Mid + new Vector2(226 + 45 * (i % 9), 66 + 45 * (i / 9))) + .With(new components.ui.ButtonTiles(fairies[i].CardId.EntityId)) + .With(preload.Wiz000) + .Build(); } } }