mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 08:14:00 +02:00
save buton now only display when change happen.
This commit is contained in:
parent
6e0d1037bc
commit
75e75d92e6
5 changed files with 50 additions and 8 deletions
|
|
@ -1,2 +1,2 @@
|
||||||
rootProject.name = "UnsafeEnchants"
|
rootProject.name = "CustomAnvil"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package xyz.alexcrea.cuanvil.gui.config.settings;
|
||||||
|
|
||||||
import com.github.stefvanschie.inventoryframework.adventuresupport.StringHolder;
|
import com.github.stefvanschie.inventoryframework.adventuresupport.StringHolder;
|
||||||
import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder;
|
import com.github.stefvanschie.inventoryframework.adventuresupport.TextHolder;
|
||||||
|
import com.github.stefvanschie.inventoryframework.gui.GuiItem;
|
||||||
import com.github.stefvanschie.inventoryframework.gui.type.ChestGui;
|
import com.github.stefvanschie.inventoryframework.gui.type.ChestGui;
|
||||||
import com.github.stefvanschie.inventoryframework.pane.PatternPane;
|
import com.github.stefvanschie.inventoryframework.pane.PatternPane;
|
||||||
import com.github.stefvanschie.inventoryframework.pane.util.Pattern;
|
import com.github.stefvanschie.inventoryframework.pane.util.Pattern;
|
||||||
|
|
@ -33,6 +34,8 @@ public abstract class AbstractSettingGui extends ChestGui {
|
||||||
this(rows, StringHolder.of(title), parent);
|
this(rows, StringHolder.of(title), parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected GuiItem saveItem;
|
||||||
|
protected GuiItem noChangeItem;
|
||||||
private void initBase(ValueUpdatableGui parent){
|
private void initBase(ValueUpdatableGui parent){
|
||||||
Pattern pattern = getGuiPattern();
|
Pattern pattern = getGuiPattern();
|
||||||
pane = new PatternPane(0, 0, pattern.getLength(), pattern.getHeight(), pattern);
|
pane = new PatternPane(0, 0, pattern.getLength(), pattern.getHeight(), pattern);
|
||||||
|
|
@ -41,8 +44,17 @@ public abstract class AbstractSettingGui extends ChestGui {
|
||||||
GuiGlobalItems.addBackItem(pane, parent);
|
GuiGlobalItems.addBackItem(pane, parent);
|
||||||
GuiGlobalItems.addBackgroundItem(pane);
|
GuiGlobalItems.addBackgroundItem(pane);
|
||||||
|
|
||||||
pane.bindItem('S', GuiGlobalItems.saveItem(this, parent));
|
saveItem = GuiGlobalItems.saveItem(this, parent);
|
||||||
|
noChangeItem = GuiGlobalItems.noChangeItem();
|
||||||
|
|
||||||
|
pane.bindItem('S', noChangeItem);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update() {
|
||||||
|
pane.bindItem('S', hadChange() ? saveItem : noChangeItem);
|
||||||
|
super.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected PatternPane getPane() {
|
protected PatternPane getPane() {
|
||||||
|
|
@ -54,6 +66,8 @@ public abstract class AbstractSettingGui extends ChestGui {
|
||||||
|
|
||||||
public abstract boolean onSave();
|
public abstract boolean onSave();
|
||||||
|
|
||||||
|
public abstract boolean hadChange();
|
||||||
|
|
||||||
|
|
||||||
public abstract static class SettingGuiFactory{
|
public abstract static class SettingGuiFactory{
|
||||||
protected String configPath;
|
protected String configPath;
|
||||||
|
|
|
||||||
|
|
@ -17,11 +17,13 @@ import java.util.function.Consumer;
|
||||||
public class BoolSettingsGui extends AbstractSettingGui{
|
public class BoolSettingsGui extends AbstractSettingGui{
|
||||||
|
|
||||||
private final BoolSettingFactory holder;
|
private final BoolSettingFactory holder;
|
||||||
|
private final boolean before;
|
||||||
private boolean now;
|
private boolean now;
|
||||||
|
|
||||||
private BoolSettingsGui(BoolSettingFactory holder, boolean now) {
|
private BoolSettingsGui(BoolSettingFactory holder, boolean now) {
|
||||||
super(3, holder.title, holder.parent);
|
super(3, holder.title, holder.parent);
|
||||||
this.holder = holder;
|
this.holder = holder;
|
||||||
|
this.before = now;
|
||||||
this.now = now;
|
this.now = now;
|
||||||
|
|
||||||
updateValueDisplay();
|
updateValueDisplay();
|
||||||
|
|
@ -33,7 +35,7 @@ public class BoolSettingsGui extends AbstractSettingGui{
|
||||||
return new Pattern(
|
return new Pattern(
|
||||||
"000000000",
|
"000000000",
|
||||||
"00-0v0+00",
|
"00-0v0+00",
|
||||||
"B0000000S"
|
"BD000000S"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -81,6 +83,11 @@ public class BoolSettingsGui extends AbstractSettingGui{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hadChange() {
|
||||||
|
return now != before;
|
||||||
|
}
|
||||||
|
|
||||||
public static BoolSettingFactory factory(@NotNull String title, ValueUpdatableGui parent,
|
public static BoolSettingFactory factory(@NotNull String title, ValueUpdatableGui parent,
|
||||||
String configPath, ConfigHolder config,
|
String configPath, ConfigHolder config,
|
||||||
boolean defaultVal){
|
boolean defaultVal){
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ import java.util.function.Consumer;
|
||||||
public class IntSettingsGui extends AbstractSettingGui{
|
public class IntSettingsGui extends AbstractSettingGui{
|
||||||
|
|
||||||
private final IntSettingFactory holder;
|
private final IntSettingFactory holder;
|
||||||
|
private final int before;
|
||||||
private int now;
|
private int now;
|
||||||
private int step;
|
private int step;
|
||||||
|
|
||||||
|
|
@ -28,6 +29,7 @@ public class IntSettingsGui extends AbstractSettingGui{
|
||||||
super(3, holder.title, holder.parent);
|
super(3, holder.title, holder.parent);
|
||||||
assert holder.steps.length > 0 && holder.steps.length <= 9;
|
assert holder.steps.length > 0 && holder.steps.length <= 9;
|
||||||
this.holder = holder;
|
this.holder = holder;
|
||||||
|
this.before =now;
|
||||||
this.now = now;
|
this.now = now;
|
||||||
this.step = holder.steps[0];
|
this.step = holder.steps[0];
|
||||||
|
|
||||||
|
|
@ -41,7 +43,7 @@ public class IntSettingsGui extends AbstractSettingGui{
|
||||||
return new Pattern(
|
return new Pattern(
|
||||||
"abcdefghi",
|
"abcdefghi",
|
||||||
"00-0v0+00",
|
"00-0v0+00",
|
||||||
"B0000000S"
|
"BD000000S"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -55,7 +57,7 @@ public class IntSettingsGui extends AbstractSettingGui{
|
||||||
int planned = Math.max(holder.min, now - step);
|
int planned = Math.max(holder.min, now - step);
|
||||||
ItemStack item = new ItemStack(Material.RED_TERRACOTTA);
|
ItemStack item = new ItemStack(Material.RED_TERRACOTTA);
|
||||||
ItemMeta meta = item.getItemMeta();
|
ItemMeta meta = item.getItemMeta();
|
||||||
meta.setDisplayName("\u00A7e"+planned + " \u00A7r(\u00A7c-"+(now-planned)+"\u00A7r)");
|
meta.setDisplayName("\u00A7e"+now+" -> "+planned + " \u00A7r(\u00A7c-"+(now-planned)+"\u00A7r)");
|
||||||
meta.setLore(AbstractSettingGui.CLICK_LORE);
|
meta.setLore(AbstractSettingGui.CLICK_LORE);
|
||||||
item.setItemMeta(meta);
|
item.setItemMeta(meta);
|
||||||
|
|
||||||
|
|
@ -72,7 +74,7 @@ public class IntSettingsGui extends AbstractSettingGui{
|
||||||
int planned = Math.min(holder.max, now + step);
|
int planned = Math.min(holder.max, now + step);
|
||||||
ItemStack item = new ItemStack(Material.GREEN_TERRACOTTA);
|
ItemStack item = new ItemStack(Material.GREEN_TERRACOTTA);
|
||||||
ItemMeta meta = item.getItemMeta();
|
ItemMeta meta = item.getItemMeta();
|
||||||
meta.setDisplayName("\u00A7e"+planned + " \u00A7r(\u00A7a+"+(planned-now)+"\u00A7r)");
|
meta.setDisplayName("\u00A7e"+now+" -> "+planned + " \u00A7r(\u00A7a+"+(planned-now)+"\u00A7r)");
|
||||||
meta.setLore(AbstractSettingGui.CLICK_LORE);
|
meta.setLore(AbstractSettingGui.CLICK_LORE);
|
||||||
item.setItemMeta(meta);
|
item.setItemMeta(meta);
|
||||||
|
|
||||||
|
|
@ -85,7 +87,7 @@ public class IntSettingsGui extends AbstractSettingGui{
|
||||||
// "result" display
|
// "result" display
|
||||||
ItemStack resultPaper = new ItemStack(Material.PAPER);
|
ItemStack resultPaper = new ItemStack(Material.PAPER);
|
||||||
ItemMeta resultMeta = resultPaper.getItemMeta();
|
ItemMeta resultMeta = resultPaper.getItemMeta();
|
||||||
resultMeta.setDisplayName("\u00A7e"+now);
|
resultMeta.setDisplayName("\u00A7eValue: "+now);
|
||||||
resultPaper.setItemMeta(resultMeta);
|
resultPaper.setItemMeta(resultMeta);
|
||||||
GuiItem resultItem = new GuiItem(resultPaper, GuiGlobalActions.stayInPlace, CustomAnvil.instance);
|
GuiItem resultItem = new GuiItem(resultPaper, GuiGlobalActions.stayInPlace, CustomAnvil.instance);
|
||||||
|
|
||||||
|
|
@ -179,6 +181,11 @@ public class IntSettingsGui extends AbstractSettingGui{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hadChange() {
|
||||||
|
return now != before;
|
||||||
|
}
|
||||||
|
|
||||||
public static IntSettingFactory factory(@NotNull String title, ValueUpdatableGui parent,
|
public static IntSettingFactory factory(@NotNull String title, ValueUpdatableGui parent,
|
||||||
String configPath, ConfigHolder config,
|
String configPath, ConfigHolder config,
|
||||||
int min, int max, int defaultVal, int... steps){
|
int min, int max, int defaultVal, int... steps){
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,8 @@ public class GuiGlobalItems {
|
||||||
addBackgroundItem(target, DEFAULT_BACKGROUND_MAT);
|
addBackgroundItem(target, DEFAULT_BACKGROUND_MAT);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Material DEFAULT_SAVE_ITEM = Material.LIME_TERRACOTTA;
|
private static final Material DEFAULT_SAVE_ITEM = Material.LIME_DYE;
|
||||||
|
private static final Material DEFAULT_NO_CHANGE_ITEM = Material.GRAY_DYE;
|
||||||
public static GuiItem saveItem(
|
public static GuiItem saveItem(
|
||||||
@NotNull AbstractSettingGui setting,
|
@NotNull AbstractSettingGui setting,
|
||||||
@NotNull ValueUpdatableGui goal){
|
@NotNull ValueUpdatableGui goal){
|
||||||
|
|
@ -73,6 +74,19 @@ public class GuiGlobalItems {
|
||||||
CustomAnvil.instance);
|
CustomAnvil.instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final GuiItem NO_CHANGE_ITEM;
|
||||||
|
static {
|
||||||
|
ItemStack item = new ItemStack(DEFAULT_NO_CHANGE_ITEM);
|
||||||
|
ItemMeta meta = item.getItemMeta();
|
||||||
|
meta.setDisplayName("\u00A77No change. can't save.");
|
||||||
|
item.setItemMeta(meta);
|
||||||
|
NO_CHANGE_ITEM = new GuiItem(item,GuiGlobalActions.stayInPlace, CustomAnvil.instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static GuiItem noChangeItem(){
|
||||||
|
return NO_CHANGE_ITEM;
|
||||||
|
}
|
||||||
|
|
||||||
public static GuiItem openSettingGuiItem(
|
public static GuiItem openSettingGuiItem(
|
||||||
@NotNull ItemStack item,
|
@NotNull ItemStack item,
|
||||||
@NotNull AbstractSettingGui.SettingGuiFactory factory
|
@NotNull AbstractSettingGui.SettingGuiFactory factory
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue