mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
int item display better
This commit is contained in:
parent
26469982b2
commit
f0d2f07703
2 changed files with 45 additions and 28 deletions
|
|
@ -58,9 +58,17 @@ public class EnchantLimitConfigGui extends AbstractEnchantConfigGui<IntSettingsG
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String valueDisplayName(int value) {
|
public String valueDisplayName(IntSettingsGui.ValueDisplayType type, int value) {
|
||||||
if(value == -1) return "Default (" + defaultValue + ")";
|
|
||||||
return super.valueDisplayName(value);
|
if(value < 0) {
|
||||||
|
return switch (type) {
|
||||||
|
case CURRENT -> "Default (" + defaultValue + ")";
|
||||||
|
case RESET -> String.valueOf(defaultValue);
|
||||||
|
default -> "Default";
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
else return super.valueDisplayName(type, value);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,8 @@ public class IntSettingsGui extends AbstractSettingGui {
|
||||||
assert meta != null;
|
assert meta != null;
|
||||||
|
|
||||||
meta.setDisplayName("§eReset to default value");
|
meta.setDisplayName("§eReset to default value");
|
||||||
meta.setLore(Collections.singletonList("§7Default value is §e" + holder.defaultVal));
|
meta.setLore(Collections.singletonList("§7Default value is §e" +
|
||||||
|
holder.valueDisplayName(ValueDisplayType.RESET, holder.defaultVal)));
|
||||||
item.setItemMeta(meta);
|
item.setItemMeta(meta);
|
||||||
returnToDefault = new GuiItem(item, event -> {
|
returnToDefault = new GuiItem(item, event -> {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
|
|
@ -86,42 +87,23 @@ public class IntSettingsGui extends AbstractSettingGui {
|
||||||
* Update item using the setting value to match the new value.
|
* Update item using the setting value to match the new value.
|
||||||
*/
|
*/
|
||||||
protected void updateValueDisplay() {
|
protected void updateValueDisplay() {
|
||||||
|
|
||||||
PatternPane pane = getPane();
|
PatternPane pane = getPane();
|
||||||
var displayNow = holder.valueDisplayName(now);
|
|
||||||
|
|
||||||
// minus item
|
// minus item
|
||||||
GuiItem minusItem;
|
GuiItem minusItem;
|
||||||
if (now > holder.min) {
|
if (now > holder.min) {
|
||||||
int planned = Math.max(holder.min, now - step);
|
int planned = Math.min(holder.max, now + step);
|
||||||
ItemStack item = new ItemStack(Material.RED_TERRACOTTA);
|
minusItem = valueEditItem(Material.RED_TERRACOTTA, ValueDisplayType.REMOVE, planned);
|
||||||
ItemMeta meta = item.getItemMeta();
|
|
||||||
assert meta != null;
|
|
||||||
|
|
||||||
meta.setDisplayName("§e" + displayNow + " §f-> §e" + planned + " §r(§c-" + holder.valueDisplayName(now - planned) + "§r)");
|
|
||||||
meta.setLore(Collections.singletonList(AbstractSettingGui.CLICK_LORE));
|
|
||||||
item.setItemMeta(meta);
|
|
||||||
|
|
||||||
minusItem = new GuiItem(item, updateNowConsumer(planned), CustomAnvil.instance);
|
|
||||||
} else {
|
} else {
|
||||||
minusItem = GuiGlobalItems.backgroundItem(Material.BARRIER);
|
minusItem = GuiGlobalItems.backgroundItem(Material.BARRIER);
|
||||||
}
|
}
|
||||||
pane.bindItem('-', minusItem);
|
pane.bindItem('-', minusItem);
|
||||||
|
|
||||||
//plus item
|
//plus item
|
||||||
// may do a function to generalise ?
|
|
||||||
GuiItem plusItem;
|
GuiItem plusItem;
|
||||||
if (now < holder.max) {
|
if (now < holder.max) {
|
||||||
int planned = Math.min(holder.max, now + step);
|
int planned = Math.min(holder.max, now + step);
|
||||||
ItemStack item = new ItemStack(Material.GREEN_TERRACOTTA);
|
plusItem = valueEditItem(Material.GREEN_TERRACOTTA, ValueDisplayType.ADD, planned);
|
||||||
ItemMeta meta = item.getItemMeta();
|
|
||||||
assert meta != null;
|
|
||||||
|
|
||||||
meta.setDisplayName("§e" + displayNow + " §f-> §e" + planned + " §r(§a+" + holder.valueDisplayName(planned - now) + "§r)");
|
|
||||||
meta.setLore(Collections.singletonList(AbstractSettingGui.CLICK_LORE));
|
|
||||||
item.setItemMeta(meta);
|
|
||||||
|
|
||||||
plusItem = new GuiItem(item, updateNowConsumer(planned), CustomAnvil.instance);
|
|
||||||
} else {
|
} else {
|
||||||
plusItem = GuiGlobalItems.backgroundItem(Material.BARRIER);
|
plusItem = GuiGlobalItems.backgroundItem(Material.BARRIER);
|
||||||
}
|
}
|
||||||
|
|
@ -132,7 +114,7 @@ public class IntSettingsGui extends AbstractSettingGui {
|
||||||
ItemMeta resultMeta = resultPaper.getItemMeta();
|
ItemMeta resultMeta = resultPaper.getItemMeta();
|
||||||
assert resultMeta != null;
|
assert resultMeta != null;
|
||||||
|
|
||||||
resultMeta.setDisplayName("§fValue: §e" + displayNow);
|
resultMeta.setDisplayName("§fValue: §e" + holder.valueDisplayName(ValueDisplayType.CURRENT, now));
|
||||||
resultMeta.setLore(holder.displayLore);
|
resultMeta.setLore(holder.displayLore);
|
||||||
|
|
||||||
resultPaper.setItemMeta(resultMeta);
|
resultPaper.setItemMeta(resultMeta);
|
||||||
|
|
@ -150,7 +132,21 @@ public class IntSettingsGui extends AbstractSettingGui {
|
||||||
}
|
}
|
||||||
pane.bindItem('D', returnToDefault);
|
pane.bindItem('D', returnToDefault);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private GuiItem valueEditItem(Material mat, ValueDisplayType type, int planned) {
|
||||||
|
ItemStack item = new ItemStack(mat);
|
||||||
|
ItemMeta meta = item.getItemMeta();
|
||||||
|
assert meta != null;
|
||||||
|
|
||||||
|
var nowDisplay = holder.valueDisplayName(type, now);
|
||||||
|
var plannedDisplay = holder.valueDisplayName(type, planned);
|
||||||
|
var deltaDisplay = holder.deltaDisplay(type, now, planned);
|
||||||
|
meta.setDisplayName("§e" + nowDisplay + " §f-> §e" + plannedDisplay + " §r(§c" + deltaDisplay + "§r)");
|
||||||
|
|
||||||
|
meta.setLore(Collections.singletonList(AbstractSettingGui.CLICK_LORE));
|
||||||
|
item.setItemMeta(meta);
|
||||||
|
return new GuiItem(item, updateNowConsumer(planned), CustomAnvil.instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -390,10 +386,23 @@ public class IntSettingsGui extends AbstractSettingGui {
|
||||||
return getItem(itemMat, CasedStringUtil.detectToUpperSpacedCase(configPath));
|
return getItem(itemMat, CasedStringUtil.detectToUpperSpacedCase(configPath));
|
||||||
}
|
}
|
||||||
|
|
||||||
public String valueDisplayName(int value) {
|
protected String valueDisplayName(ValueDisplayType type, int value) {
|
||||||
return String.valueOf(value);
|
return String.valueOf(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected String deltaDisplay(ValueDisplayType type, int now, int planned) {
|
||||||
|
var delta = planned - now;
|
||||||
|
if(delta < 0) return "§c" + delta;
|
||||||
|
else return "§a+" + delta;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum ValueDisplayType {
|
||||||
|
ADD,
|
||||||
|
CURRENT,
|
||||||
|
REMOVE,
|
||||||
|
RESET,
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue