diff options
author | makamys <makamys@outlook.com> | 2022-06-30 16:15:25 +0200 |
---|---|---|
committer | makamys <makamys@outlook.com> | 2022-06-30 16:58:14 +0200 |
commit | 33162cb3ecbd8ad26cd6b363854d92c63a5e5f91 (patch) | |
tree | 8af69de2dcd6c7e2d44dc3f39eae12320c0366c2 | |
parent | e599b420e4ac09a68c19c2e083facdd44ca9b3ae (diff) | |
download | Neodymium-33162cb3ecbd8ad26cd6b363854d92c63a5e5f91.tar.gz Neodymium-33162cb3ecbd8ad26cd6b363854d92c63a5e5f91.tar.bz2 Neodymium-33162cb3ecbd8ad26cd6b363854d92c63a5e5f91.zip |
Make names in config GUI more human readable
-rw-r--r-- | src/main/java/makamys/neodymium/Config.java | 3 | ||||
-rw-r--r-- | src/main/java/makamys/neodymium/config/HumanReadableConfigElement.java | 39 |
2 files changed, 41 insertions, 1 deletions
diff --git a/src/main/java/makamys/neodymium/Config.java b/src/main/java/makamys/neodymium/Config.java index 54a7017..33539d0 100644 --- a/src/main/java/makamys/neodymium/Config.java +++ b/src/main/java/makamys/neodymium/Config.java @@ -27,6 +27,7 @@ import java.util.List; import org.lwjgl.input.Keyboard; import cpw.mods.fml.client.config.IConfigElement; +import makamys.neodymium.config.HumanReadableConfigElement; import net.minecraft.launchwrapper.Launch; import net.minecraftforge.common.config.ConfigElement; import net.minecraftforge.common.config.Configuration; @@ -195,7 +196,7 @@ public class Config { public static List<IConfigElement> getElements() { List<IConfigElement> list = new ArrayList<IConfigElement>(); for(Property prop : config.getCategory("render").values()) { - list.add(new ConfigElement(prop)); + list.add(new HumanReadableConfigElement(prop)); } return list; } diff --git a/src/main/java/makamys/neodymium/config/HumanReadableConfigElement.java b/src/main/java/makamys/neodymium/config/HumanReadableConfigElement.java new file mode 100644 index 0000000..761f114 --- /dev/null +++ b/src/main/java/makamys/neodymium/config/HumanReadableConfigElement.java @@ -0,0 +1,39 @@ +package makamys.neodymium.config; + +import net.minecraftforge.common.config.ConfigElement; +import net.minecraftforge.common.config.Property; + +public class HumanReadableConfigElement extends ConfigElement { + + public HumanReadableConfigElement(Property prop) { + super(prop); + } + + @Override + public String getName() { + return decamelize(super.getName()); + } + + private static String decamelize(String s) { + boolean[] spaceField = new boolean[s.length()]; + + for(int i = 0; i < s.length(); i++) { + if(i > 0 && i < s.length() && !Character.isUpperCase(s.charAt(i - 1)) && Character.isUpperCase(s.charAt(i))) { + spaceField[i] = true; + } else if(i > 2 && Character.isUpperCase(s.charAt(i - 2)) && Character.isUpperCase(s.charAt(i - 1)) && !Character.isUpperCase(s.charAt(i))) { + spaceField[i - 1] = true; + } + } + + String out = ""; + for(int i = 0; i < s.length(); i++) { + if(spaceField[i]) { + out += " "; + } + out += i == 0 ? Character.toUpperCase(s.charAt(i)) : s.charAt(i); + } + + return out; + } + +} |