mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
boolean setting gui mostly done.
This commit is contained in:
parent
c0a4dd080f
commit
f23d818cf3
2 changed files with 126 additions and 2 deletions
|
|
@ -10,6 +10,7 @@ import org.bukkit.inventory.ItemStack;
|
|||
import xyz.alexcrea.cuanvil.gui.GuiGlobalItems;
|
||||
import xyz.alexcrea.cuanvil.gui.MainConfigGui;
|
||||
import xyz.alexcrea.cuanvil.gui.config.settings.AbstractSettingGui;
|
||||
import xyz.alexcrea.cuanvil.gui.config.settings.BoolSettingsGui;
|
||||
import xyz.alexcrea.cuanvil.gui.config.settings.IntSettingsGui;
|
||||
|
||||
public class BasicConfigGui extends ChestGui {
|
||||
|
|
@ -28,7 +29,7 @@ public class BasicConfigGui extends ChestGui {
|
|||
private void init(){
|
||||
Pattern pattern = new Pattern(
|
||||
"000000000",
|
||||
"010000000",
|
||||
"012000000",
|
||||
"B00000000"
|
||||
);
|
||||
PatternPane pane = new PatternPane(0, 0, 9, 3, pattern);
|
||||
|
|
@ -42,7 +43,10 @@ public class BasicConfigGui extends ChestGui {
|
|||
GuiItem setting1 = GuiGlobalItems.openSettingGuiItem(setting1Item, factory1);
|
||||
pane.bindItem('1', setting1);
|
||||
|
||||
|
||||
ItemStack setting2Item = new ItemStack(Material.STONE);
|
||||
AbstractSettingGui.SettingGuiFactory factory2 = BoolSettingsGui.factory("Test Gui bool",this, "test2", CustomAnvil.instance.getConfig(), false);
|
||||
GuiItem setting2 = GuiGlobalItems.openSettingGuiItem(setting2Item, factory2);
|
||||
pane.bindItem('2', setting2);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,120 @@
|
|||
package xyz.alexcrea.cuanvil.gui.config.settings;
|
||||
|
||||
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
||||
import com.github.stefvanschie.inventoryframework.gui.type.util.Gui;
|
||||
import com.github.stefvanschie.inventoryframework.pane.PatternPane;
|
||||
import com.github.stefvanschie.inventoryframework.pane.util.Pattern;
|
||||
import io.delilaheve.CustomAnvil;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class BoolSettingsGui extends AbstractSettingGui{
|
||||
|
||||
private final BoolSettingFactory holder;
|
||||
private boolean now;
|
||||
|
||||
private BoolSettingsGui(BoolSettingFactory holder, boolean now) {
|
||||
super(3, holder.title, holder.parent);
|
||||
this.holder = holder;
|
||||
this.now = now;
|
||||
|
||||
updateValueDisplay();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Pattern getGuiPattern() {
|
||||
return new Pattern(
|
||||
"000000000",
|
||||
"00-0v0+00",
|
||||
"B0000000S"
|
||||
);
|
||||
}
|
||||
|
||||
protected void updateValueDisplay(){
|
||||
|
||||
PatternPane pane = getPane();
|
||||
|
||||
// Get displayed value for this config.
|
||||
String displayedName;
|
||||
Material displayedMat;
|
||||
if(now){
|
||||
displayedName = "\u00A7aTrue";
|
||||
displayedMat = Material.GREEN_TERRACOTTA;
|
||||
}else{
|
||||
displayedName = "\u00A7cFalse";
|
||||
displayedMat = Material.RED_TERRACOTTA;
|
||||
}
|
||||
|
||||
ItemStack valueItemStack = new ItemStack(displayedMat);
|
||||
ItemMeta valueMeta = valueItemStack.getItemMeta();
|
||||
valueMeta.setDisplayName(displayedName);
|
||||
valueMeta.setLore(Collections.singletonList("\u00A77Click Here to change the value"));
|
||||
valueItemStack.setItemMeta(valueMeta);
|
||||
GuiItem resultItem = new GuiItem(valueItemStack, inverseNowConsumer(), CustomAnvil.instance);
|
||||
|
||||
pane.bindItem('v', resultItem);
|
||||
|
||||
}
|
||||
|
||||
protected Consumer<InventoryClickEvent> inverseNowConsumer(){
|
||||
return event->{
|
||||
event.setCancelled(true);
|
||||
now = !now;
|
||||
updateValueDisplay();
|
||||
update();
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSave() {
|
||||
holder.section.set(holder.configPath, now);
|
||||
// TODO SAVE (also backup before)
|
||||
|
||||
}
|
||||
|
||||
public static SettingGuiFactory factory(@NotNull String title, Gui parent,
|
||||
String configPath, ConfigurationSection section,
|
||||
boolean defaultVal){
|
||||
return new BoolSettingFactory(
|
||||
title,parent,
|
||||
configPath, section,
|
||||
defaultVal);
|
||||
}
|
||||
|
||||
|
||||
public static class BoolSettingFactory extends SettingGuiFactory{
|
||||
@NotNull String title; Gui parent;
|
||||
String configPath; ConfigurationSection section;
|
||||
boolean defaultVal;
|
||||
|
||||
private BoolSettingFactory(@NotNull String title, Gui parent,
|
||||
String configPath, ConfigurationSection section,
|
||||
boolean defaultVal){
|
||||
this.title = title;
|
||||
this.parent = parent;
|
||||
this.configPath = configPath;
|
||||
this.section = section;
|
||||
this.defaultVal = defaultVal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractSettingGui create() {
|
||||
// Get value or default
|
||||
//TODO maybe get section dynamically (and maybe same for save ?)
|
||||
boolean now = section.getBoolean(this.configPath, this.defaultVal);
|
||||
// create new gui
|
||||
return new BoolSettingsGui(this, now);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue