forked from SteamWar/SteamWar
Size particle choice menus by their options
Lists that fit on one page get one row per nine options plus the bottom bar, so a condition with three options opens a two row menu. Longer lists keep the paged 6 row menu.
This commit is contained in:
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
package de.steamwar.lobby.particle.gui;
|
package de.steamwar.lobby.particle.gui;
|
||||||
|
|
||||||
|
import de.steamwar.inventory.SWInventory;
|
||||||
import de.steamwar.inventory.SWItem;
|
import de.steamwar.inventory.SWItem;
|
||||||
import de.steamwar.inventory.SWListInv;
|
import de.steamwar.inventory.SWListInv;
|
||||||
import de.steamwar.lobby.particle.UnlockContext;
|
import de.steamwar.lobby.particle.UnlockContext;
|
||||||
@@ -100,7 +101,24 @@ class Pickers {
|
|||||||
open(player, msg("PARTICLE_SLOT_ICON_TITLE", player), list, onPick, onBack);
|
open(player, msg("PARTICLE_SLOT_ICON_TITLE", player), list, onPick, onBack);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Lists that fit on one page get just enough rows for their options plus the bottom bar
|
||||||
private <T> void open(Player player, String title, List<SWListInv.SWListEntry<T>> list, Consumer<T> onPick, Runnable onBack) {
|
private <T> void open(Player player, String title, List<SWListInv.SWListEntry<T>> list, Consumer<T> onPick, Runnable onBack) {
|
||||||
|
if (list.size() <= SIZE - 9) {
|
||||||
|
int size = (Math.max(1, (list.size() + 8) / 9) + 1) * 9;
|
||||||
|
SWInventory inventory = new SWInventory(player, size, title);
|
||||||
|
for (int i = 0; i < list.size(); i++) {
|
||||||
|
T value = list.get(i).getObject();
|
||||||
|
inventory.setItem(i, list.get(i).getItem().getItemStack(), clickType -> {
|
||||||
|
if (value != null) onPick.accept(value);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
inventory.setItem(BottomBar.position(size, BottomBar.BACK), new SWItem(Material.ARROW, msg("PARTICLE_BACK", player), clickType -> onBack.run()));
|
||||||
|
BottomBar.fillUnused(inventory, size, false);
|
||||||
|
SlotEditor.fill(inventory, 0, size);
|
||||||
|
inventory.open();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
SWListInv<T> inventory = new SWListInv<>(player, title, false, list, (clickType, value) -> {
|
SWListInv<T> inventory = new SWListInv<>(player, title, false, list, (clickType, value) -> {
|
||||||
if (value != null) onPick.accept(value);
|
if (value != null) onPick.accept(value);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user