Skip to content

Commit

Permalink
UI: deck: order lists correctly (#287)
Browse files Browse the repository at this point in the history
* UI: deck: order lists correctly

* Address requested changes & fix scrollbar

* Fix chaining OrderBy

* Use .GetItem instead of .First

* Fix own impatience

* Fix ThenBy order & use concise syntax
  • Loading branch information
AcipenserSturio authored Jan 26, 2024
1 parent d20602b commit 4d9050b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
3 changes: 2 additions & 1 deletion zzio/db/ItemRow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ public ItemRow(MappedDB mappedDB, Row row) : base(ModuleType.Item, mappedDB, row

public string Script => row.cells[4].String;

public int Unknown => row.cells[5].Integer;
// Not all itemRows have this value
public int Unknown => row.cells.Length >= 6 ? row.cells[5].Integer : 0;
}
12 changes: 7 additions & 5 deletions zzre/game/systems/ui/ScrDeck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -443,10 +443,12 @@ private void CreateGridList(DefaultEcs.Entity entity, ref components.ui.ScrDeck

private IEnumerable<InventoryCard> AllCardsOfType(in components.ui.ScrDeck deck) => deck.ActiveTab switch
{
Tab.Items => deck.Inventory.Items,
Tab.Fairies => deck.Inventory.Fairies,
Tab.AttackSpells => deck.Inventory.AttackSpells,
Tab.SupportSpells => deck.Inventory.SupportSpells,
Tab.Items => deck.Inventory.Items
.OrderBy(c => mappedDB.GetItem(c.dbUID).Unknown switch { 1 => 0, 0 => 1, _ => 2 })
.ThenBy(c => c.cardId.EntityId),
Tab.Fairies => deck.Inventory.Fairies.OrderByDescending(c => c.level),
Tab.AttackSpells => deck.Inventory.AttackSpells.OrderBy(c => c.cardId.EntityId),
Tab.SupportSpells => deck.Inventory.SupportSpells.OrderBy(c => c.cardId.EntityId),
_ => Enumerable.Empty<InventoryCard>()
};

Expand Down Expand Up @@ -581,7 +583,7 @@ protected override void Update(
{
var slider = deck.ListSlider.Get<components.ui.Slider>();
var allCardsCount = AllCardsOfType(deck).Count();
var newScrollI = (int)MathF.Round(slider.Current.Y * (allCardsCount - 1));
var newScrollI = (int)MathF.Round(slider.Current.Y * (allCardsCount - 1) * (deck.IsGridMode ? ListRows : 1));
if (newScrollI != deck.Scroll)
{
deck.Scroll = newScrollI;
Expand Down

0 comments on commit 4d9050b

Please sign in to comment.