Made Config gui prettier and with description lore.

This commit is contained in:
alexcrea 2024-04-30 20:31:04 +02:00
parent 4b50499442
commit 24ebb19e11
No known key found for this signature in database
GPG key ID: 43FD265DB0DBF91F
11 changed files with 88 additions and 51 deletions

View file

@ -76,7 +76,6 @@ public class BasicConfigGui extends ValueUpdatableGui {
// limit repair item
this.limitRepairFactory = BoolSettingsGui.boolFactory("\u00A78Limit Repair Cost ?", this,
ConfigOptions.LIMIT_REPAIR_COST, ConfigHolder.DEFAULT_CONFIG, ConfigOptions.DEFAULT_LIMIT_REPAIR,
"",
"\u00A77Whether all anvil actions cost should be capped.",
"\u00A77If true, all anvil repairs will max out at the value of \u00A7aLimit Repair Value\u00A77.");
@ -85,7 +84,6 @@ public class BasicConfigGui extends ValueUpdatableGui {
this.repairCostFactory = IntSettingsGui.intFactory("\u00A78Repair Cost Limit", this,
ConfigOptions.LIMIT_REPAIR_VALUE, ConfigHolder.DEFAULT_CONFIG,
Arrays.asList(
"",
"\u00A77Value to limit repair costs to when \u00A7aLimit Repair Value\u00A77 is true.",
"\u00A77Valid values include \u00A7e1 \u00A77to \u00A7e39\u00A77: " +
"vanilla would display \u00A7e40+\u00A77 as \u00A7ctoo expensive\u00A77."
@ -107,7 +105,6 @@ public class BasicConfigGui extends ValueUpdatableGui {
// remove repair limit item
this.removeRepairLimit = BoolSettingsGui.boolFactory("\u00A78Remove Repair Limit ?", this,
ConfigOptions.REMOVE_REPAIR_LIMIT, ConfigHolder.DEFAULT_CONFIG, ConfigOptions.DEFAULT_REMOVE_LIMIT,
"",
"\u00A77Whether the anvil's repair limit should be removed entirely.",
"\u00A77The anvil will still visually display \u00A7ctoo expensive\u00A77.",
"\u00A77However the action will be completable.");
@ -117,7 +114,6 @@ public class BasicConfigGui extends ValueUpdatableGui {
this.itemRepairCost = IntSettingsGui.intFactory("\u00A78Item Repair Cost", this,
ConfigOptions.ITEM_REPAIR_COST, ConfigHolder.DEFAULT_CONFIG,
Arrays.asList(
"",
"\u00A77XP Level amount added to the anvil when the item",
"\u00A77is repaired by another item of the same type."
),
@ -129,7 +125,6 @@ public class BasicConfigGui extends ValueUpdatableGui {
this.unitRepairCost = IntSettingsGui.intFactory("\u00A78Unit Repair Cost", this,
ConfigOptions.UNIT_REPAIR_COST, ConfigHolder.DEFAULT_CONFIG,
Arrays.asList(
"",
"\u00A77XP Level amount added to the anvil when the item is repaired by an \u00A7eunit\u00A77.",
"\u00A77For example: a Diamond on a Diamond Sword.",
"\u00A77What's considered unit for what can be edited on the unit repair configuration."
@ -143,7 +138,6 @@ public class BasicConfigGui extends ValueUpdatableGui {
this.itemRenameCost = IntSettingsGui.intFactory("\u00A78Rename Cost", this,
ConfigOptions.ITEM_RENAME_COST, ConfigHolder.DEFAULT_CONFIG,
Arrays.asList(
"",
"\u00A77XP Level amount added to the anvil when the item is renamed."
),
range.getFirst(), range.getLast(),
@ -155,7 +149,6 @@ public class BasicConfigGui extends ValueUpdatableGui {
this.sacrificeIllegalEnchantCost = IntSettingsGui.intFactory("\u00A78Sacrifice Illegal Enchant Cost", this,
ConfigOptions.SACRIFICE_ILLEGAL_COST, ConfigHolder.DEFAULT_CONFIG,
Arrays.asList(
"",
"\u00A77XP Level amount added to the anvil when a sacrifice enchantment",
"\u00A77conflict With one of the left item enchantment"
),

View file

@ -32,7 +32,7 @@ public class EnchantCostConfigGui extends AbstractEnchantConfigGui<EnchantCostSe
* Constructor of this Global gui for enchantment cost settings.
*/
private EnchantCostConfigGui() {
super("\u00A78Enchantment Level Limit");
super("\u00A78Enchantment Level Cost");
}
@ -70,8 +70,8 @@ public class EnchantCostConfigGui extends AbstractEnchantConfigGui<EnchantCostSe
// Edit name and lore
itemMeta.setDisplayName(itemName);
itemMeta.setLore(Arrays.asList(
"\u00A77Item Cost: " + itemCost,
"\u00A77Book Cost: " + bookCost));
"\u00A77Item Cost: \u00A7e" + itemCost,
"\u00A77Book Cost: \u00A7e" + bookCost));
item.setItemMeta(itemMeta);

View file

@ -40,7 +40,7 @@ public class GroupConfigGui extends MappedGuiListConfigGui<IncludeGroup, GroupCo
meta.setDisplayName("\u00A7e" + CasedStringUtil.snakeToUpperSpacedCase(group.getName())+ " \u00A7fGroup");
meta.setLore(Arrays.asList(
"\u00A77Number of selected groups : " + group.getGroups().size(),
"\u00A77Number of included material: " + group.getNonGroupInheritedMaterials().size(),
"\u00A77Number of included material : " + group.getNonGroupInheritedMaterials().size(),
"",
"\u00A77Total number of included material "+group.getMaterials().size()));

View file

@ -12,15 +12,12 @@ import xyz.alexcrea.cuanvil.config.ConfigHolder;
import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
import java.util.Collections;
import java.util.List;
/**
* An instance gui used to edit a setting.
*/
public abstract class AbstractSettingGui extends ChestGui {
protected final static List<String> CLICK_LORE = Collections.singletonList("\u00A77Click Here to change the value");
protected final static String CLICK_LORE = "\u00A77Click Here to change the value";
private PatternPane pane;

View file

@ -16,6 +16,7 @@ import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
import xyz.alexcrea.cuanvil.util.CasedStringUtil;
import xyz.alexcrea.cuanvil.util.MetricsUtil;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@ -62,12 +63,21 @@ public class BoolSettingsGui extends AbstractSettingGui {
* Prepare "return to default value" gui item.
*/
protected void prepareReturnToDefault() {
// Prepare default Value text
String defaultValueLore;
if(holder.defaultVal){
defaultValueLore = "\u00A7aYes \u00A77Is the default value";
}else{
defaultValueLore = "\u00A7cNo \u00A77Is the default value";
}
// Create reset to default item
ItemStack item = new ItemStack(Material.COMMAND_BLOCK);
ItemMeta meta = item.getItemMeta();
assert meta != null;
meta.setDisplayName("\u00A7eReset to default value");
meta.setLore(Collections.singletonList("\u00A77Default value is: " + holder.defaultVal));
meta.setLore(Collections.singletonList(defaultValueLore));
item.setItemMeta(meta);
returnToDefault = new GuiItem(item, event -> {
event.setCancelled(true);
@ -87,19 +97,27 @@ public class BoolSettingsGui extends AbstractSettingGui {
String displayedName;
Material displayedMat;
if (now) {
displayedName = "\u00A7aTrue";
displayedName = "\u00A7aYes";
displayedMat = Material.GREEN_TERRACOTTA;
} else {
displayedName = "\u00A7cFalse";
displayedName = "\u00A7cNo";
displayedMat = Material.RED_TERRACOTTA;
}
// create & set Value item
ArrayList<String> valueLore = new ArrayList<>();
if(!holder.displayLore.isEmpty()){
valueLore.addAll(holder.displayLore);
valueLore.add("");
}
valueLore.add(AbstractSettingGui.CLICK_LORE);
ItemStack valueItemStack = new ItemStack(displayedMat);
ItemMeta valueMeta = valueItemStack.getItemMeta();
assert valueMeta != null;
valueMeta.setDisplayName(displayedName);
valueMeta.setLore(AbstractSettingGui.CLICK_LORE);
valueMeta.setLore(valueLore);
valueItemStack.setItemMeta(valueMeta);
GuiItem resultItem = new GuiItem(valueItemStack, inverseNowConsumer(), CustomAnvil.instance);
@ -236,17 +254,18 @@ public class BoolSettingsGui extends AbstractSettingGui {
boolean value = getConfiguredValue();
Material itemMat;
StringBuilder itemName = new StringBuilder("\u00A7");
StringBuilder itemName = new StringBuilder("\u00A7e");
String finalValue;
if (value) {
itemMat = Material.GREEN_TERRACOTTA;
itemName.append("a");
finalValue = "\u00A7aYes";
} else {
itemMat = Material.RED_TERRACOTTA;
itemName.append("c");
finalValue = "\u00A7cNo";
}
itemName.append(name);
return GuiGlobalItems.createGuiItemFromProperties(this, itemMat, itemName, value, this.displayLore);
return GuiGlobalItems.createGuiItemFromProperties(this, itemMat, itemName, finalValue, this.displayLore, false);
}
/**

View file

@ -21,6 +21,7 @@ import xyz.alexcrea.cuanvil.util.MetricsUtil;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@ -165,7 +166,7 @@ public class DoubleSettingGui extends AbstractSettingGui {
ItemMeta resultMeta = resultPaper.getItemMeta();
assert resultMeta != null;
resultMeta.setDisplayName("\u00A7eValue: " + displayValue(now));
resultMeta.setDisplayName("\u00A7fValue: \u00A7e" + displayValue(now));
resultPaper.setItemMeta(resultMeta);
GuiItem resultItem = new GuiItem(resultPaper, GuiGlobalActions.stayInPlace, CustomAnvil.instance);
@ -183,13 +184,22 @@ public class DoubleSettingGui extends AbstractSettingGui {
}
private GuiItem getSetValueItem(Material mat, BigDecimal planned, String numberPrefix){
// Create set item lore
ArrayList<String> setLoreItem = new ArrayList<>();
if(!holder.displayLore.isEmpty()){
setLoreItem.addAll(holder.displayLore);
setLoreItem.add("");
}
setLoreItem.add(AbstractSettingGui.CLICK_LORE);
// Create & return set value item
ItemStack item = new ItemStack(mat);
ItemMeta meta = item.getItemMeta();
assert meta != null;
meta.setDisplayName("\u00A7e" + displayValue(now) + " -> " + displayValue(planned)
meta.setDisplayName("\u00A7e" + displayValue(now) + " \u00A7f-> \u00A7e" + displayValue(planned)
+ " \u00A7r(" + numberPrefix + (displayValue(planned.subtract(now).abs()) + "\u00A7r)"));
meta.setLore(AbstractSettingGui.CLICK_LORE);
meta.setLore(setLoreItem);
item.setItemMeta(meta);
return new GuiItem(item, updateNowConsumer(planned), CustomAnvil.instance);
@ -275,7 +285,7 @@ public class DoubleSettingGui extends AbstractSettingGui {
stepLore = Collections.singletonList("\u00A77Click here to change the value by " + displayValue(stepValue));
clickEvent = updateStepValue(stepValue);
}
stepName.append("Step of ").append(displayValue(stepValue));
stepName.append("Step of \u00A7e").append(displayValue(stepValue));
// Create item stack then gui item
ItemStack item = new ItemStack(stepMat);
@ -473,7 +483,9 @@ public class DoubleSettingGui extends AbstractSettingGui {
BigDecimal value = getConfiguredValue();
StringBuilder itemName = new StringBuilder("\u00A7a").append(name);
return GuiGlobalItems.createGuiItemFromProperties(this, itemMat, itemName, displayValue(value, this.asPercentage), this.displayLore);
return GuiGlobalItems.createGuiItemFromProperties(this, itemMat, itemName,
"\u00A7e" + displayValue(value, this.asPercentage),
this.displayLore, true);
}
public GuiItem getItem(Material itemMat){

View file

@ -19,6 +19,7 @@ import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant;
import xyz.alexcrea.cuanvil.util.MetricsUtil;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.function.Consumer;
@ -146,8 +147,8 @@ public class EnchantCostSettingsGui extends IntSettingsGui {
ItemMeta meta = item.getItemMeta();
assert meta != null;
meta.setDisplayName("\u00A7e" + nowBook + " -> " + planned + " \u00A7r(\u00A7c-" + (nowBook - planned) + "\u00A7r)");
meta.setLore(AbstractSettingGui.CLICK_LORE);
meta.setDisplayName("\u00A7e" + nowBook + " \u00A7f-> \u00A7e" + planned + " \u00A7r(\u00A7c-" + (nowBook - planned) + "\u00A7r)");
meta.setLore(Collections.singletonList(AbstractSettingGui.CLICK_LORE));
item.setItemMeta(meta);
minusItem = new GuiItem(item, updateNowBookConsumer(planned), CustomAnvil.instance);
@ -164,8 +165,8 @@ public class EnchantCostSettingsGui extends IntSettingsGui {
ItemMeta meta = item.getItemMeta();
assert meta != null;
meta.setDisplayName("\u00A7e" + nowBook + " -> " + planned + " \u00A7r(\u00A7a+" + (planned - nowBook) + "\u00A7r)");
meta.setLore(AbstractSettingGui.CLICK_LORE);
meta.setDisplayName("\u00A7e" + nowBook + " \u00A7f-> \u00A7e" + planned + " \u00A7r(\u00A7a+" + (planned - nowBook) + "\u00A7r)");
meta.setLore(Collections.singletonList(AbstractSettingGui.CLICK_LORE));
item.setItemMeta(meta);
plusItem = new GuiItem(item, updateNowBookConsumer(planned), CustomAnvil.instance);
@ -174,15 +175,19 @@ public class EnchantCostSettingsGui extends IntSettingsGui {
}
pane.bindItem('P', plusItem);
// "result" display
ItemStack resultPaper = new ItemStack(Material.PAPER);
ItemMeta resultMeta = resultPaper.getItemMeta();
assert resultMeta != null;
// now value display
ItemStack nowPaper = new ItemStack(Material.PAPER);
ItemMeta nowMeta = nowPaper.getItemMeta();
assert nowMeta != null;
resultMeta.setDisplayName("\u00A7eValue: " + nowBook);
resultPaper.setItemMeta(resultMeta);
nowMeta.setDisplayName("\u00A7fValue: \u00A7e" + nowBook);
if(!holder.displayLore.isEmpty()){
nowMeta.setLore(holder.displayLore);
}
GuiItem resultItem = new GuiItem(resultPaper, GuiGlobalActions.stayInPlace, CustomAnvil.instance);
nowPaper.setItemMeta(nowMeta);
GuiItem resultItem = new GuiItem(nowPaper, GuiGlobalActions.stayInPlace, CustomAnvil.instance);
pane.bindItem('V', resultItem);

View file

@ -97,8 +97,8 @@ public class IntSettingsGui extends AbstractSettingGui {
ItemMeta meta = item.getItemMeta();
assert meta != null;
meta.setDisplayName("\u00A7e" + now + " -> " + planned + " \u00A7r(\u00A7c-" + (now - planned) + "\u00A7r)");
meta.setLore(AbstractSettingGui.CLICK_LORE);
meta.setDisplayName("\u00A7e" + now + " \u00A7f-> \u00A7e" + planned + " \u00A7r(\u00A7c-" + (now - planned) + "\u00A7r)");
meta.setLore(Collections.singletonList(AbstractSettingGui.CLICK_LORE));
item.setItemMeta(meta);
minusItem = new GuiItem(item, updateNowConsumer(planned), CustomAnvil.instance);
@ -116,8 +116,8 @@ public class IntSettingsGui extends AbstractSettingGui {
ItemMeta meta = item.getItemMeta();
assert meta != null;
meta.setDisplayName("\u00A7e" + now + " -> " + planned + " \u00A7r(\u00A7a+" + (planned - now) + "\u00A7r)");
meta.setLore(AbstractSettingGui.CLICK_LORE);
meta.setDisplayName("\u00A7e" + now + " \u00A7f-> \u00A7e" + planned + " \u00A7r(\u00A7a+" + (planned - now) + "\u00A7r)");
meta.setLore(Collections.singletonList(AbstractSettingGui.CLICK_LORE));
item.setItemMeta(meta);
plusItem = new GuiItem(item, updateNowConsumer(planned), CustomAnvil.instance);
@ -131,8 +131,11 @@ public class IntSettingsGui extends AbstractSettingGui {
ItemMeta resultMeta = resultPaper.getItemMeta();
assert resultMeta != null;
resultMeta.setDisplayName("\u00A7eValue: " + now);
resultMeta.setDisplayName("\u00A7fValue: \u00A7e" + now);
resultMeta.setLore(holder.displayLore);
resultPaper.setItemMeta(resultMeta);
GuiItem resultItem = new GuiItem(resultPaper, GuiGlobalActions.stayInPlace, CustomAnvil.instance);
pane.bindItem('v', resultItem);
@ -229,7 +232,7 @@ public class IntSettingsGui extends AbstractSettingGui {
stepLore = Collections.singletonList("\u00A77Click here to change the value by " + stepValue);
clickEvent = updateStepValue(stepValue);
}
stepName.append("Step of: ").append(stepValue);
stepName.append("Step of: \u00A7e").append(stepValue);
// Create item stack then gui item
ItemStack item = new ItemStack(stepMat);
@ -393,7 +396,9 @@ public class IntSettingsGui extends AbstractSettingGui {
int value = getConfiguredValue();
StringBuilder itemName = new StringBuilder("\u00A7a").append(name);
return GuiGlobalItems.createGuiItemFromProperties(this, itemMat, itemName, value, this.displayLore);
return GuiGlobalItems.createGuiItemFromProperties(this, itemMat, itemName,
"\u00A7e" + value,
this.displayLore, true);
}
/**

View file

@ -7,6 +7,7 @@ import io.delilaheve.CustomAnvil;
import org.bukkit.Material;
import org.bukkit.entity.HumanEntity;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.NotNull;
@ -268,6 +269,7 @@ public class ItemSettingGui extends AbstractSettingGui {
meta.setDisplayName("\u00A7a" + name);
meta.setLore(getDisplayLore());
meta.addItemFlags(ItemFlag.values());
item.setItemMeta(meta);

View file

@ -203,12 +203,16 @@ public class GuiGlobalItems {
@NotNull Material itemMat,
@NotNull StringBuilder itemName,
@NotNull Object value,
@NotNull List<String> displayLore
@NotNull List<String> displayLore,
boolean displayValuePrefix
) {
// Prepare lore
ArrayList<String> lore = new ArrayList<>();
lore.add(SETTING_ITEM_LORE_PREFIX + value);
lore.add((displayValuePrefix ? SETTING_ITEM_LORE_PREFIX : "") + value);
if(!displayLore.isEmpty()){
lore.add("");
lore.addAll(displayLore);
}
// Create & initialise item
ItemStack item = new ItemStack(itemMat);