Enchant cost and Enchant limit config gui now are multi page list.

This commit is contained in:
alexcrea 2024-06-17 19:57:10 +02:00
parent 502aa64f50
commit db1dfdf144
No known key found for this signature in database
GPG key ID: 43FD265DB0DBF91F
6 changed files with 51 additions and 71 deletions

View file

@ -1,25 +1,24 @@
package xyz.alexcrea.cuanvil.gui.config.global;
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
import com.github.stefvanschie.inventoryframework.gui.type.ChestGui;
import com.github.stefvanschie.inventoryframework.gui.type.util.Gui;
import com.github.stefvanschie.inventoryframework.pane.Orientable;
import com.github.stefvanschie.inventoryframework.pane.OutlinePane;
import io.delilaheve.CustomAnvil;
import com.github.stefvanschie.inventoryframework.pane.util.Pattern;
import org.bukkit.event.inventory.InventoryClickEvent;
import xyz.alexcrea.cuanvil.enchant.WrappedEnchantment;
import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
import xyz.alexcrea.cuanvil.gui.config.list.SettingGuiListConfigGui;
import xyz.alexcrea.cuanvil.gui.config.settings.AbstractSettingGui;
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.function.Consumer;
/**
* Abstract Global Config gui for enchantment setting configuration.
*
* @param <T> Type of the factory of the type of setting the gui should edit.
*/
public abstract class AbstractEnchantConfigGui<T extends AbstractSettingGui.SettingGuiFactory> extends ChestGui implements ValueUpdatableGui {
public abstract class AbstractEnchantConfigGui<T extends AbstractSettingGui.SettingGuiFactory> extends SettingGuiListConfigGui<WrappedEnchantment, T> implements ValueUpdatableGui {
/**
* Constructor for a gui displaying available enchantment to edit a enchantment setting.
@ -27,66 +26,50 @@ public abstract class AbstractEnchantConfigGui<T extends AbstractSettingGui.Sett
* @param title Title of the gui.
*/
protected AbstractEnchantConfigGui(String title) {
super(6, title, CustomAnvil.instance);
}
private OutlinePane filledEnchant;
/**
* Initialise value updatable gui pattern
*/
protected void init() {
// Back item panel
addPane(GuiSharedConstant.BACK_TO_MAIN_MENU_BIG_LIST_DISPLAY_BACKGROUND_PANE);
// enchant item panel
this.filledEnchant = new OutlinePane(0, 0, 9, 5);
this.filledEnchant.align(OutlinePane.Alignment.BEGIN);
this.filledEnchant.setOrientation(Orientable.Orientation.HORIZONTAL);
addPane(this.filledEnchant);
prepareValues();
updateGuiValues();
}
private List<T> bookItemFactoryList;
/**
* Prepare enchantment config gui displayed items factory.
*/
protected void prepareValues() {
bookItemFactoryList = new ArrayList<>();
for (WrappedEnchantment enchant : GuiSharedConstant.SORTED_ENCHANTMENT_LIST) {
T factory = getFactoryFromEnchant(enchant);
bookItemFactoryList.add(factory);
}
super(title);
}
@Override
public void updateGuiValues() {
// probably not the most efficient but hey ! it do the work
// TODO optimise one day.. maybe
this.filledEnchant.clear();
for (T inventoryFactory : this.bookItemFactoryList) {
GuiItem item = getItemFromFactory(inventoryFactory);
this.filledEnchant.addItem(item);
public void updateGuiValues() { //TODO maybe optimise it.
reloadValues();
}
update();
@Override
protected List<WrappedEnchantment> getEveryDisplayableInstanceOfGeneric() {
return GuiSharedConstant.SORTED_ENCHANTMENT_LIST;
}
@Override
protected Pattern getBackgroundPattern(){
return new Pattern(
GuiSharedConstant.EMPTY_GUI_FULL_LINE,
GuiSharedConstant.EMPTY_GUI_FULL_LINE,
GuiSharedConstant.EMPTY_GUI_FULL_LINE,
GuiSharedConstant.EMPTY_GUI_FULL_LINE,
GuiSharedConstant.EMPTY_GUI_FULL_LINE,
"B11L1R111"
);
}
// Unused methods
@Override
protected GuiItem prepareCreateNewItem() {
return null;
}
@Override
protected List<String> getCreateItemLore() {
return Collections.emptyList();
}
@Override
public Gui getConnectedGui() {
return this;
protected Consumer<InventoryClickEvent> getCreateClickConsumer() {
return null;
}
public abstract T getFactoryFromEnchant(WrappedEnchantment enchant);
public abstract GuiItem getItemFromFactory(T inventoryFactory);
@Override
protected String createItemName() {
return null;
}
}

View file

@ -12,10 +12,7 @@ import xyz.alexcrea.cuanvil.gui.config.settings.EnchantCostSettingsGui;
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
import xyz.alexcrea.cuanvil.util.CasedStringUtil;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.*;
/**
* Global Config gui for enchantment cost settings.
@ -39,7 +36,7 @@ public class EnchantCostConfigGui extends AbstractEnchantConfigGui<EnchantCostSe
}
@Override
public EnchantCostSettingsGui.EnchantCostSettingFactory getFactoryFromEnchant(WrappedEnchantment enchant) {
public EnchantCostSettingsGui.EnchantCostSettingFactory createFactory(WrappedEnchantment enchant) {
String key = enchant.getKey().getKey().toLowerCase(Locale.ENGLISH);
String prettyKey = CasedStringUtil.snakeToUpperSpacedCase(key);
@ -62,7 +59,7 @@ public class EnchantCostConfigGui extends AbstractEnchantConfigGui<EnchantCostSe
}
@Override
public GuiItem getItemFromFactory(EnchantCostSettingsGui.EnchantCostSettingFactory factory) {
public GuiItem itemFromFactory(WrappedEnchantment enchantment, EnchantCostSettingsGui.EnchantCostSettingFactory factory) {
// Get item properties
int itemCost = factory.getConfiguredValue();
int bookCost = factory.getConfiguredBookValue();

View file

@ -15,9 +15,9 @@ import java.util.Locale;
*/
public class EnchantLimitConfigGui extends AbstractEnchantConfigGui<IntSettingsGui.IntSettingFactory> {
private final static String SECTION_NAME = "enchant_limits";
private static final String SECTION_NAME = "enchant_limits";
public final static EnchantLimitConfigGui INSTANCE = new EnchantLimitConfigGui();
public static final EnchantLimitConfigGui INSTANCE = new EnchantLimitConfigGui();
static {
INSTANCE.init();
@ -32,7 +32,7 @@ public class EnchantLimitConfigGui extends AbstractEnchantConfigGui<IntSettingsG
}
@Override
public IntSettingsGui.IntSettingFactory getFactoryFromEnchant(WrappedEnchantment enchant) {
public IntSettingsGui.IntSettingFactory createFactory(WrappedEnchantment enchant) {
String key = enchant.getKey().getKey().toLowerCase(Locale.ROOT);
String prettyKey = CasedStringUtil.snakeToUpperSpacedCase(key);
@ -47,7 +47,7 @@ public class EnchantLimitConfigGui extends AbstractEnchantConfigGui<IntSettingsG
}
@Override
public GuiItem getItemFromFactory(IntSettingsGui.IntSettingFactory inventoryFactory) {
public GuiItem itemFromFactory(WrappedEnchantment enchantment, IntSettingsGui.IntSettingFactory inventoryFactory) {
return inventoryFactory.getItem(
Material.ENCHANTED_BOOK,
inventoryFactory.getTitle());

View file

@ -18,7 +18,7 @@ import java.util.List;
public class UnitRepairConfigGui extends MappedGuiListConfigGui<Material, UnitRepairElementListGui> {
public final static UnitRepairConfigGui INSTANCE = new UnitRepairConfigGui();
public static final UnitRepairConfigGui INSTANCE = new UnitRepairConfigGui();
static {
INSTANCE.init();
@ -89,7 +89,7 @@ public class UnitRepairConfigGui extends MappedGuiListConfigGui<Material, UnitRe
createItem.setItemMeta(createMeta);
return new GuiItem(createItem, (clickEvent) -> {
return new GuiItem(createItem, clickEvent -> {
clickEvent.setCancelled(true);
new SelectItemTypeGui(

View file

@ -16,7 +16,7 @@ import java.util.function.Consumer;
public abstract class MappedElementListConfigGui< T, S > extends ElementListConfigGui< T > {
protected final HashMap<T, S> elementGuiMap;
public MappedElementListConfigGui(@NotNull String title) {
protected MappedElementListConfigGui(@NotNull String title) {
super(title);
this.elementGuiMap = new HashMap<>();
@ -38,7 +38,7 @@ public abstract class MappedElementListConfigGui< T, S > extends ElementListConf
createItem.setItemMeta(createMeta);
return new GuiItem(createItem, (clickEvent) -> {
return new GuiItem(createItem, clickEvent -> {
clickEvent.setCancelled(true);
HumanEntity player = clickEvent.getWhoClicked();

View file

@ -17,7 +17,7 @@ public abstract class SettingGuiListConfigGui< T, S extends AbstractSettingGui.S
protected HashMap<T, GuiItem> guiItemMap;
protected HashMap<T, S> factoryMap;
public SettingGuiListConfigGui(@NotNull String title) {
protected SettingGuiListConfigGui(@NotNull String title) {
super(title);
this.guiItemMap = new HashMap<>();
this.factoryMap = new HashMap<>();