mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
Transform EnchantSelectSettingGui to be displayed as a list.
This commit is contained in:
parent
33fac3eed4
commit
b1ca8bd91c
5 changed files with 71 additions and 50 deletions
|
|
@ -57,7 +57,7 @@ public abstract class ElementListConfigGui< T > extends ChestGui implements Valu
|
||||||
protected ArrayList<OutlinePane> pages;
|
protected ArrayList<OutlinePane> pages;
|
||||||
protected HashMap<UUID, Integer> pageMap;
|
protected HashMap<UUID, Integer> pageMap;
|
||||||
|
|
||||||
public void init() { // Why I'm using an init function ?
|
public void init() { // Why I'm using an init function ? //TODO determine why is it using a init function and not used on constructor.
|
||||||
GuiGlobalItems.addBackgroundItem(this.backgroundPane);
|
GuiGlobalItems.addBackgroundItem(this.backgroundPane);
|
||||||
this.backgroundPane.bindItem('1', GuiSharedConstant.SECONDARY_BACKGROUND_ITEM);
|
this.backgroundPane.bindItem('1', GuiSharedConstant.SECONDARY_BACKGROUND_ITEM);
|
||||||
addPane(this.backgroundPane);
|
addPane(this.backgroundPane);
|
||||||
|
|
|
||||||
|
|
@ -38,16 +38,16 @@ public abstract class SettingGuiListConfigGui< T, S extends SettingGui.SettingGu
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateValueForGeneric(T generic, boolean shouldUpdate) {
|
public void updateValueForGeneric(T generic, boolean shouldUpdate) {
|
||||||
S factory = this.factoryMap.get(generic);
|
if(!this.factoryMap.containsKey(generic)){
|
||||||
if(factory == null){
|
|
||||||
// Create new item & factory
|
// Create new item & factory
|
||||||
factory = createFactory(generic);
|
S factory = createFactory(generic);
|
||||||
GuiItem newItem = itemFromFactory(generic, factory);
|
GuiItem newItem = itemFromFactory(generic, factory);
|
||||||
|
|
||||||
addToPage(newItem);
|
addToPage(newItem);
|
||||||
this.guiItemMap.put(generic, newItem);
|
this.guiItemMap.put(generic, newItem);
|
||||||
this.factoryMap.put(generic, factory);
|
this.factoryMap.put(generic, factory);
|
||||||
}else{
|
}else{
|
||||||
|
S factory = this.factoryMap.get(generic);
|
||||||
// Update old item
|
// Update old item
|
||||||
GuiItem oldItem = this.guiItemMap.get(generic);
|
GuiItem oldItem = this.guiItemMap.get(generic);
|
||||||
|
|
||||||
|
|
@ -73,6 +73,7 @@ public abstract class SettingGuiListConfigGui< T, S extends SettingGui.SettingGu
|
||||||
oldITem.setProperties(newItem.getProperties());
|
oldITem.setProperties(newItem.getProperties());
|
||||||
oldITem.setVisible(newItem.isVisible());
|
oldITem.setVisible(newItem.isVisible());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected GuiItem findGuiItemForRemoval(T generic) {
|
protected GuiItem findGuiItemForRemoval(T generic) {
|
||||||
return this.guiItemMap.get(generic);
|
return this.guiItemMap.get(generic);
|
||||||
|
|
|
||||||
|
|
@ -79,15 +79,15 @@ public class EnchantConflictSubSettingGui extends MappedToListSubSettingGui impl
|
||||||
this.pane.bindItem('D', new GuiItem(deleteItem, GuiGlobalActions.openGuiAction(createDeleteGui()), CustomAnvil.instance));
|
this.pane.bindItem('D', new GuiItem(deleteItem, GuiGlobalActions.openGuiAction(createDeleteGui()), CustomAnvil.instance));
|
||||||
|
|
||||||
// Displayed item will be updated later
|
// Displayed item will be updated later
|
||||||
this.enchantSettingItem = new GuiItem(new ItemStack(Material.ENCHANTED_BOOK), (event) -> {
|
this.enchantSettingItem = new GuiItem(new ItemStack(Material.ENCHANTED_BOOK), event -> {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
EnchantSelectSettingGui enchantGui = new EnchantSelectSettingGui(
|
EnchantSelectSettingGui enchantGui = new EnchantSelectSettingGui(
|
||||||
"\u00A7e" + CasedStringUtil.snakeToUpperSpacedCase(enchantConflict.toString()) + " \u00A75Enchantments",
|
"\u00A7e" + CasedStringUtil.snakeToUpperSpacedCase(enchantConflict.toString()) + "\u00A75",
|
||||||
this, this, 0);
|
this, this);
|
||||||
enchantGui.show(event.getWhoClicked());
|
enchantGui.show(event.getWhoClicked());
|
||||||
}, CustomAnvil.instance);
|
}, CustomAnvil.instance);
|
||||||
|
|
||||||
this.groupSettingItem = new GuiItem(new ItemStack(Material.PAPER), (event) -> {
|
this.groupSettingItem = new GuiItem(new ItemStack(Material.PAPER), event -> {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
GroupSelectSettingGui enchantGui = new GroupSelectSettingGui(
|
GroupSelectSettingGui enchantGui = new GroupSelectSettingGui(
|
||||||
"\u00A7e" + CasedStringUtil.snakeToUpperSpacedCase(this.enchantConflict.toString()) + " \u00A73Groups",
|
"\u00A7e" + CasedStringUtil.snakeToUpperSpacedCase(this.enchantConflict.toString()) + " \u00A73Groups",
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,6 @@ public abstract class AbstractSettingGui extends ChestGui implements SettingGui
|
||||||
}
|
}
|
||||||
|
|
||||||
protected GuiItem saveItem;
|
protected GuiItem saveItem;
|
||||||
protected GuiItem noChangeItem;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialise and prepare value for this gui.
|
* Initialise and prepare value for this gui.
|
||||||
|
|
@ -61,15 +60,14 @@ public abstract class AbstractSettingGui extends ChestGui implements SettingGui
|
||||||
GuiGlobalItems.addBackgroundItem(pane);
|
GuiGlobalItems.addBackgroundItem(pane);
|
||||||
|
|
||||||
saveItem = GuiGlobalItems.saveItem(this, parent);
|
saveItem = GuiGlobalItems.saveItem(this, parent);
|
||||||
noChangeItem = GuiGlobalItems.noChangeItem();
|
|
||||||
|
|
||||||
pane.bindItem('S', noChangeItem);
|
pane.bindItem('S', GuiGlobalItems.noChangeItem());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update() {
|
public void update() {
|
||||||
pane.bindItem('S', hadChange() ? saveItem : noChangeItem);
|
pane.bindItem('S', hadChange() ? saveItem : GuiGlobalItems.noChangeItem());
|
||||||
super.update();
|
super.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -95,6 +93,7 @@ public abstract class AbstractSettingGui extends ChestGui implements SettingGui
|
||||||
*/
|
*/
|
||||||
protected abstract Pattern getGuiPattern();
|
protected abstract Pattern getGuiPattern();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Most of the time a setting gui will be called from a global gui.
|
* Most of the time a setting gui will be called from a global gui.
|
||||||
* <p>
|
* <p>
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,7 @@
|
||||||
package xyz.alexcrea.cuanvil.gui.config.settings;
|
package xyz.alexcrea.cuanvil.gui.config.settings;
|
||||||
|
|
||||||
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
||||||
import com.github.stefvanschie.inventoryframework.pane.Orientable;
|
import com.github.stefvanschie.inventoryframework.gui.type.util.Gui;
|
||||||
import com.github.stefvanschie.inventoryframework.pane.OutlinePane;
|
|
||||||
import com.github.stefvanschie.inventoryframework.pane.Pane;
|
|
||||||
import com.github.stefvanschie.inventoryframework.pane.util.Pattern;
|
import com.github.stefvanschie.inventoryframework.pane.util.Pattern;
|
||||||
import io.delilaheve.CustomAnvil;
|
import io.delilaheve.CustomAnvil;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
|
@ -13,71 +11,67 @@ import org.bukkit.inventory.ItemFlag;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
||||||
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.SelectEnchantmentContainer;
|
import xyz.alexcrea.cuanvil.gui.config.SelectEnchantmentContainer;
|
||||||
|
import xyz.alexcrea.cuanvil.gui.config.list.SettingGuiListConfigGui;
|
||||||
|
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
|
||||||
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
|
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
|
||||||
import xyz.alexcrea.cuanvil.util.CasedStringUtil;
|
import xyz.alexcrea.cuanvil.util.CasedStringUtil;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.*;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class EnchantSelectSettingGui extends AbstractSettingGui {
|
public class EnchantSelectSettingGui extends SettingGuiListConfigGui<WrappedEnchantment, EnchantSelectSettingGui.DummyFactory> implements SettingGui {
|
||||||
|
|
||||||
SelectEnchantmentContainer enchantContainer;
|
private final SelectEnchantmentContainer enchantContainer;
|
||||||
int page;
|
|
||||||
|
|
||||||
Set<WrappedEnchantment> selectedEnchant;
|
private final Set<WrappedEnchantment> selectedEnchant;
|
||||||
|
private final GuiItem saveItem;
|
||||||
|
|
||||||
public EnchantSelectSettingGui(@NotNull String title, ValueUpdatableGui parent, SelectEnchantmentContainer enchantContainer, int page) {
|
public EnchantSelectSettingGui(@NotNull String title, ValueUpdatableGui parent, SelectEnchantmentContainer enchantContainer) {
|
||||||
super(6, title, parent);
|
super(title);
|
||||||
this.enchantContainer = enchantContainer;
|
this.enchantContainer = enchantContainer;
|
||||||
// Not used and not planned rn
|
|
||||||
this.page = page;
|
|
||||||
|
|
||||||
this.selectedEnchant = new HashSet<>(enchantContainer.getSelectedEnchantments());
|
this.selectedEnchant = new HashSet<>(enchantContainer.getSelectedEnchantments());
|
||||||
|
|
||||||
// Add secondary background item
|
this.saveItem = GuiGlobalItems.saveItem(this, parent);
|
||||||
this.getPane().bindItem('1', GuiSharedConstant.SECONDARY_BACKGROUND_ITEM);
|
this.backgroundPane.bindItem('S', GuiGlobalItems.noChangeItem());
|
||||||
|
|
||||||
initGroups();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Pattern getGuiPattern() {
|
protected Pattern getBackgroundPattern() {
|
||||||
return new Pattern(
|
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,
|
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,
|
||||||
"B1111111S"
|
"B11L1R11S"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void initGroups() {
|
@Override
|
||||||
// Add enchantment gui item
|
protected List<WrappedEnchantment> getEveryDisplayableInstanceOfGeneric() {
|
||||||
OutlinePane filledEnchant = new OutlinePane(0, 0, 9, 5);
|
Set<WrappedEnchantment> illegalEnchantments = this.enchantContainer.illegalEnchantments();
|
||||||
filledEnchant.setPriority(Pane.Priority.HIGH);
|
|
||||||
filledEnchant.align(OutlinePane.Alignment.BEGIN);
|
|
||||||
filledEnchant.setOrientation(Orientable.Orientation.HORIZONTAL);
|
|
||||||
|
|
||||||
Set<WrappedEnchantment> illegalEnchant = this.enchantContainer.illegalEnchantments();
|
return Arrays.stream(WrappedEnchantment.values())
|
||||||
for (WrappedEnchantment enchant : GuiSharedConstant.SORTED_ENCHANTMENT_LIST) {
|
.filter(enchantment -> !illegalEnchantments.contains(enchantment))
|
||||||
if (illegalEnchant.contains(enchant)) {
|
.collect(Collectors.toList());
|
||||||
return;
|
|
||||||
}
|
|
||||||
filledEnchant.addItem(getGuiItemFromEnchant(enchant));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
addPane(filledEnchant);
|
@Override
|
||||||
|
public void update() {
|
||||||
|
this.backgroundPane.bindItem('S', hadChange() ? saveItem : GuiGlobalItems.noChangeItem());
|
||||||
|
super.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
private GuiItem getGuiItemFromEnchant(WrappedEnchantment enchantment) {
|
@Override
|
||||||
|
protected GuiItem itemFromFactory(WrappedEnchantment enchantment, DummyFactory factory) {
|
||||||
boolean isIn = this.selectedEnchant.contains(enchantment);
|
boolean isIn = this.selectedEnchant.contains(enchantment);
|
||||||
|
|
||||||
Material usedMaterial;
|
Material usedMaterial;
|
||||||
|
|
@ -95,7 +89,6 @@ public class EnchantSelectSettingGui extends AbstractSettingGui {
|
||||||
return guiItem;
|
return guiItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static final List<String> TRUE_LORE = Collections.singletonList("\u00A77Value: \u00A7aSelected");
|
private static final List<String> TRUE_LORE = Collections.singletonList("\u00A77Value: \u00A7aSelected");
|
||||||
private static final List<String> FALSE_LORE = Collections.singletonList("\u00A77Value: \u00A7cNot Selected");
|
private static final List<String> FALSE_LORE = Collections.singletonList("\u00A77Value: \u00A7cNot Selected");
|
||||||
|
|
||||||
|
|
@ -157,4 +150,32 @@ public class EnchantSelectSettingGui extends AbstractSettingGui {
|
||||||
!baseGroup.containsAll(this.selectedEnchant);
|
!baseGroup.containsAll(this.selectedEnchant);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Unused methods and class
|
||||||
|
public static class DummyFactory extends AbstractSettingGui.SettingGuiFactory{
|
||||||
|
protected DummyFactory(@NotNull String configPath, @NotNull ConfigHolder config) {
|
||||||
|
super(configPath, config);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public Gui create() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
protected List<String> getCreateItemLore() {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
protected Consumer<InventoryClickEvent> getCreateClickConsumer() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
protected String createItemName() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
protected DummyFactory createFactory(WrappedEnchantment generic) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue