-
Notifications
You must be signed in to change notification settings - Fork 72
feat: Add sorting options for menu items in MenuSpell #1106
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -132,6 +132,7 @@ public MenuSpell(MagicConfig config, String spellName) { | |
| option.spellSwapName = getConfigString(path + "spell-swap", ""); | ||
| option.power = getConfigFloat(path + "power", 1); | ||
| option.modifierList = getConfigStringList(path + "modifiers", null); | ||
| option.sortMode = SortMode.fromConfigValue(getConfigString(path + "sort-mode", "none")); | ||
| option.stayOpen = getConfigBoolean(path + "stay-open", false); | ||
| options.put(optionName, option); | ||
| } | ||
|
|
@@ -293,9 +294,28 @@ private void applyOptionsToInventory(Player opener, MenuInventory menu) { | |
| } else quantity = (int) Math.round(variable.getValue(opener)); | ||
| item.setAmount(quantity); | ||
|
|
||
| // Set item for all defined slots. | ||
| for (int slot : option.slots) { | ||
| if (inv.getItem(slot) == null) inv.setItem(slot, item); | ||
| // Set item for the defined slots based on the configured fill behavior. | ||
| switch (option.sortMode) { | ||
| case FIRST -> { | ||
| for (int slot : option.slots) { | ||
| if (inv.getItem(slot) != null) continue; | ||
| inv.setItem(slot, item); | ||
| break; | ||
| } | ||
| } | ||
| case LAST -> { | ||
| for (int index = option.slots.size() - 1; index >= 0; index--) { | ||
| int slot = option.slots.get(index); | ||
| if (inv.getItem(slot) != null) continue; | ||
| inv.setItem(slot, item); | ||
| break; | ||
| } | ||
| } | ||
| case NONE -> { | ||
| for (int slot : option.slots) { | ||
| if (inv.getItem(slot) == null) inv.setItem(slot, item); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| // Fill inventory. | ||
|
|
@@ -434,6 +454,22 @@ private enum PostClickState { | |
| IGNORE | ||
| } | ||
|
|
||
| private enum SortMode { | ||
| NONE, | ||
| FIRST, | ||
| LAST; | ||
|
|
||
| private static SortMode fromConfigValue(String value) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd probably get rid of this, and use a normal This is not just to reduce redundancy, and localise the "default/fallback" value, but because it simplifies it too. Ignore the AI suggestion because that's even more of a roundabout way. Even a simple Keep the config default, pass it to |
||
| if (value == null) return NONE; | ||
|
|
||
| return switch (value.toLowerCase()) { | ||
| case "first" -> FIRST; | ||
| case "last" -> LAST; | ||
| default -> NONE; | ||
| }; | ||
| } | ||
| } | ||
|
|
||
| private static class MenuOption { | ||
|
|
||
| private String menuOptionName; | ||
|
|
@@ -456,6 +492,7 @@ private static class MenuOption { | |
| private float power; | ||
| private List<String> modifierList; | ||
| private ModifierSet menuOptionModifiers; | ||
| private SortMode sortMode; | ||
| private boolean stayOpen; | ||
|
|
||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.