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;
|
||||
|
||||
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() {
|
||||
public void updateGuiValues() { //TODO maybe optimise it.
|
||||
reloadValues();
|
||||
}
|
||||
|
||||
// probably not the most efficient but hey ! it do the work
|
||||
// TODO optimise one day.. maybe
|
||||
@Override
|
||||
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
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
|
|
@ -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<>();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue