mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
Enchant cost and Enchant limit config gui now are multi page list.
This commit is contained in:
parent
502aa64f50
commit
db1dfdf144
6 changed files with 51 additions and 71 deletions
|
|
@ -1,25 +1,24 @@
|
||||||
package xyz.alexcrea.cuanvil.gui.config.global;
|
package xyz.alexcrea.cuanvil.gui.config.global;
|
||||||
|
|
||||||
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
||||||
import com.github.stefvanschie.inventoryframework.gui.type.ChestGui;
|
import com.github.stefvanschie.inventoryframework.pane.util.Pattern;
|
||||||
import com.github.stefvanschie.inventoryframework.gui.type.util.Gui;
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
import com.github.stefvanschie.inventoryframework.pane.Orientable;
|
|
||||||
import com.github.stefvanschie.inventoryframework.pane.OutlinePane;
|
|
||||||
import io.delilaheve.CustomAnvil;
|
|
||||||
import xyz.alexcrea.cuanvil.enchant.WrappedEnchantment;
|
import xyz.alexcrea.cuanvil.enchant.WrappedEnchantment;
|
||||||
import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
|
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.config.settings.AbstractSettingGui;
|
||||||
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
|
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract Global Config gui for enchantment setting configuration.
|
* Abstract Global Config gui for enchantment setting configuration.
|
||||||
*
|
*
|
||||||
* @param <T> Type of the factory of the type of setting the gui should edit.
|
* @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.
|
* 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.
|
* @param title Title of the gui.
|
||||||
*/
|
*/
|
||||||
protected AbstractEnchantConfigGui(String title) {
|
protected AbstractEnchantConfigGui(String title) {
|
||||||
super(6, title, CustomAnvil.instance);
|
super(title);
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateGuiValues() {
|
public void updateGuiValues() { //TODO maybe optimise it.
|
||||||
|
reloadValues();
|
||||||
|
}
|
||||||
|
|
||||||
// probably not the most efficient but hey ! it do the work
|
@Override
|
||||||
// TODO optimise one day.. maybe
|
protected List<WrappedEnchantment> getEveryDisplayableInstanceOfGeneric() {
|
||||||
|
return GuiSharedConstant.SORTED_ENCHANTMENT_LIST;
|
||||||
|
}
|
||||||
|
|
||||||
this.filledEnchant.clear();
|
@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"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
for (T inventoryFactory : this.bookItemFactoryList) {
|
|
||||||
GuiItem item = getItemFromFactory(inventoryFactory);
|
|
||||||
|
|
||||||
this.filledEnchant.addItem(item);
|
// Unused methods
|
||||||
}
|
@Override
|
||||||
|
protected GuiItem prepareCreateNewItem() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
update();
|
@Override
|
||||||
|
protected List<String> getCreateItemLore() {
|
||||||
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public Gui getConnectedGui() {
|
protected Consumer<InventoryClickEvent> getCreateClickConsumer() {
|
||||||
return this;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract T getFactoryFromEnchant(WrappedEnchantment enchant);
|
@Override
|
||||||
|
protected String createItemName() {
|
||||||
public abstract GuiItem getItemFromFactory(T inventoryFactory);
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,10 +12,7 @@ import xyz.alexcrea.cuanvil.gui.config.settings.EnchantCostSettingsGui;
|
||||||
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
|
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
|
||||||
import xyz.alexcrea.cuanvil.util.CasedStringUtil;
|
import xyz.alexcrea.cuanvil.util.CasedStringUtil;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Global Config gui for enchantment cost settings.
|
* Global Config gui for enchantment cost settings.
|
||||||
|
|
@ -39,7 +36,7 @@ public class EnchantCostConfigGui extends AbstractEnchantConfigGui<EnchantCostSe
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EnchantCostSettingsGui.EnchantCostSettingFactory getFactoryFromEnchant(WrappedEnchantment enchant) {
|
public EnchantCostSettingsGui.EnchantCostSettingFactory createFactory(WrappedEnchantment enchant) {
|
||||||
String key = enchant.getKey().getKey().toLowerCase(Locale.ENGLISH);
|
String key = enchant.getKey().getKey().toLowerCase(Locale.ENGLISH);
|
||||||
String prettyKey = CasedStringUtil.snakeToUpperSpacedCase(key);
|
String prettyKey = CasedStringUtil.snakeToUpperSpacedCase(key);
|
||||||
|
|
||||||
|
|
@ -62,7 +59,7 @@ public class EnchantCostConfigGui extends AbstractEnchantConfigGui<EnchantCostSe
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GuiItem getItemFromFactory(EnchantCostSettingsGui.EnchantCostSettingFactory factory) {
|
public GuiItem itemFromFactory(WrappedEnchantment enchantment, EnchantCostSettingsGui.EnchantCostSettingFactory factory) {
|
||||||
// Get item properties
|
// Get item properties
|
||||||
int itemCost = factory.getConfiguredValue();
|
int itemCost = factory.getConfiguredValue();
|
||||||
int bookCost = factory.getConfiguredBookValue();
|
int bookCost = factory.getConfiguredBookValue();
|
||||||
|
|
|
||||||
|
|
@ -15,9 +15,9 @@ import java.util.Locale;
|
||||||
*/
|
*/
|
||||||
public class EnchantLimitConfigGui extends AbstractEnchantConfigGui<IntSettingsGui.IntSettingFactory> {
|
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 {
|
static {
|
||||||
INSTANCE.init();
|
INSTANCE.init();
|
||||||
|
|
@ -32,7 +32,7 @@ public class EnchantLimitConfigGui extends AbstractEnchantConfigGui<IntSettingsG
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IntSettingsGui.IntSettingFactory getFactoryFromEnchant(WrappedEnchantment enchant) {
|
public IntSettingsGui.IntSettingFactory createFactory(WrappedEnchantment enchant) {
|
||||||
String key = enchant.getKey().getKey().toLowerCase(Locale.ROOT);
|
String key = enchant.getKey().getKey().toLowerCase(Locale.ROOT);
|
||||||
String prettyKey = CasedStringUtil.snakeToUpperSpacedCase(key);
|
String prettyKey = CasedStringUtil.snakeToUpperSpacedCase(key);
|
||||||
|
|
||||||
|
|
@ -47,7 +47,7 @@ public class EnchantLimitConfigGui extends AbstractEnchantConfigGui<IntSettingsG
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GuiItem getItemFromFactory(IntSettingsGui.IntSettingFactory inventoryFactory) {
|
public GuiItem itemFromFactory(WrappedEnchantment enchantment, IntSettingsGui.IntSettingFactory inventoryFactory) {
|
||||||
return inventoryFactory.getItem(
|
return inventoryFactory.getItem(
|
||||||
Material.ENCHANTED_BOOK,
|
Material.ENCHANTED_BOOK,
|
||||||
inventoryFactory.getTitle());
|
inventoryFactory.getTitle());
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ import java.util.List;
|
||||||
|
|
||||||
public class UnitRepairConfigGui extends MappedGuiListConfigGui<Material, UnitRepairElementListGui> {
|
public class UnitRepairConfigGui extends MappedGuiListConfigGui<Material, UnitRepairElementListGui> {
|
||||||
|
|
||||||
public final static UnitRepairConfigGui INSTANCE = new UnitRepairConfigGui();
|
public static final UnitRepairConfigGui INSTANCE = new UnitRepairConfigGui();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
INSTANCE.init();
|
INSTANCE.init();
|
||||||
|
|
@ -89,7 +89,7 @@ public class UnitRepairConfigGui extends MappedGuiListConfigGui<Material, UnitRe
|
||||||
|
|
||||||
createItem.setItemMeta(createMeta);
|
createItem.setItemMeta(createMeta);
|
||||||
|
|
||||||
return new GuiItem(createItem, (clickEvent) -> {
|
return new GuiItem(createItem, clickEvent -> {
|
||||||
clickEvent.setCancelled(true);
|
clickEvent.setCancelled(true);
|
||||||
|
|
||||||
new SelectItemTypeGui(
|
new SelectItemTypeGui(
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ import java.util.function.Consumer;
|
||||||
public abstract class MappedElementListConfigGui< T, S > extends ElementListConfigGui< T > {
|
public abstract class MappedElementListConfigGui< T, S > extends ElementListConfigGui< T > {
|
||||||
|
|
||||||
protected final HashMap<T, S> elementGuiMap;
|
protected final HashMap<T, S> elementGuiMap;
|
||||||
public MappedElementListConfigGui(@NotNull String title) {
|
protected MappedElementListConfigGui(@NotNull String title) {
|
||||||
super(title);
|
super(title);
|
||||||
this.elementGuiMap = new HashMap<>();
|
this.elementGuiMap = new HashMap<>();
|
||||||
|
|
||||||
|
|
@ -38,7 +38,7 @@ public abstract class MappedElementListConfigGui< T, S > extends ElementListConf
|
||||||
|
|
||||||
createItem.setItemMeta(createMeta);
|
createItem.setItemMeta(createMeta);
|
||||||
|
|
||||||
return new GuiItem(createItem, (clickEvent) -> {
|
return new GuiItem(createItem, clickEvent -> {
|
||||||
clickEvent.setCancelled(true);
|
clickEvent.setCancelled(true);
|
||||||
HumanEntity player = clickEvent.getWhoClicked();
|
HumanEntity player = clickEvent.getWhoClicked();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ public abstract class SettingGuiListConfigGui< T, S extends AbstractSettingGui.S
|
||||||
|
|
||||||
protected HashMap<T, GuiItem> guiItemMap;
|
protected HashMap<T, GuiItem> guiItemMap;
|
||||||
protected HashMap<T, S> factoryMap;
|
protected HashMap<T, S> factoryMap;
|
||||||
public SettingGuiListConfigGui(@NotNull String title) {
|
protected SettingGuiListConfigGui(@NotNull String title) {
|
||||||
super(title);
|
super(title);
|
||||||
this.guiItemMap = new HashMap<>();
|
this.guiItemMap = new HashMap<>();
|
||||||
this.factoryMap = new HashMap<>();
|
this.factoryMap = new HashMap<>();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue