Skip to content

Commit

Permalink
Fix: set translatedName for more complex config types (MiniHUD, etc)
Browse files Browse the repository at this point in the history
  • Loading branch information
sakura-ryoko committed Jul 11, 2024
1 parent a7133ed commit 159eec2
Show file tree
Hide file tree
Showing 14 changed files with 173 additions and 119 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ author = masa
mod_file_name = malilib-fabric

# Current mod version
mod_version = 0.19.999-sakura.6-translations.3
mod_version = 0.19.999-sakura.6-translations.4

# Minecraft, Fabric Loader and API and mappings versions
minecraft_version_out = 1.21
Expand Down
6 changes: 1 addition & 5 deletions src/main/java/fi/dy/masa/malilib/config/IConfigBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,7 @@ default String getTranslatedName()
return this.getName();
}

/**
* Set translatedName
* @param translatedName (Name to set)
*/
default void setTranslatedName(String translatedName) { }
void setTranslatedName(String translatedName);

/**
* Set the value of this config option from a JSON element (is possible)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,17 @@ public ConfigBase(ConfigType type, String name, String comment)
}

public ConfigBase(ConfigType type, String name, String comment, String prettyName)
{
this(type, name, comment, prettyName, name);
}

public ConfigBase(ConfigType type, String name, String comment, String prettyName, String translatedName)
{
this.type = type;
this.name = name;
this.prettyName = prettyName;
this.comment = comment;
this.translatedName = name;
this.prettyName = prettyName;
this.translatedName = translatedName;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ public ConfigBoolean(String name, boolean defaultValue, String comment)

public ConfigBoolean(String name, boolean defaultValue, String comment, String prettyName)
{
super(ConfigType.BOOLEAN, name, comment, prettyName);
this(name, defaultValue, comment, prettyName, name);
}

public ConfigBoolean(String name, boolean defaultValue, String comment, String prettyName, String translatedName)
{
super(ConfigType.BOOLEAN, name, comment, prettyName, translatedName);

this.defaultValue = defaultValue;
this.value = defaultValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ public ConfigBooleanHotkeyed(String name, boolean defaultValue, String defaultHo

public ConfigBooleanHotkeyed(String name, boolean defaultValue, String defaultHotkey, String comment, String prettyName)
{
this(name, defaultValue, defaultHotkey, KeybindSettings.DEFAULT, comment, prettyName);
this(name, defaultValue, defaultHotkey, KeybindSettings.DEFAULT, comment, prettyName, name);
}

public ConfigBooleanHotkeyed(String name, boolean defaultValue, String defaultHotkey, KeybindSettings settings, String comment, String prettyName)
public ConfigBooleanHotkeyed(String name, boolean defaultValue, String defaultHotkey, KeybindSettings settings, String comment, String prettyName, String translatedName)
{
super(name, defaultValue, comment, prettyName);
super(name, defaultValue, comment, prettyName, translatedName);

this.keybind = KeybindMulti.fromStorageString(defaultHotkey, settings);
this.keybind.setCallback(new KeyCallbackToggleBooleanConfigWithMessage(this));
Expand Down
17 changes: 11 additions & 6 deletions src/main/java/fi/dy/masa/malilib/config/options/ConfigColor.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,21 @@ public class ConfigColor extends ConfigInteger
{
private Color4f color;

public ConfigColor(String name, String defaultValue, String comment, String prettyName)
public ConfigColor(String name, String defaultValue, String comment)
{
super(name, StringUtils.getColor(defaultValue, 0), comment, prettyName);
this(name, defaultValue, comment, name);
}

this.color = Color4f.fromColor(this.getIntegerValue());
public ConfigColor(String name, String defaultValue, String comment, String prettyName)
{
this(name, defaultValue, comment, prettyName, name);
}

public ConfigColor(String name, String defaultValue, String comment)
public ConfigColor(String name, String defaultValue, String comment, String prettyName, String translatedName)
{
this(name, defaultValue, comment, name);
super(name, StringUtils.getColor(defaultValue, 0), comment, prettyName, translatedName);

this.color = Color4f.fromColor(this.getIntegerValue());
}

@Override
Expand Down Expand Up @@ -73,7 +78,7 @@ public boolean isModified(String newValue)
{
return StringUtils.getColor(newValue, 0) != this.getDefaultIntegerValue();
}
catch (Exception e)
catch (Exception ignored)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,17 @@ public class ConfigColorList extends ConfigBase<ConfigColorList> implements ICon

public ConfigColorList(String name, ImmutableList<Color4f> defaultValue, String comment)
{
super(ConfigType.COLOR_LIST, name, comment);

this.defaultValue = defaultValue;
this.colors.addAll(defaultValue);
this(name, defaultValue, comment, name);
}

public ConfigColorList(String name, ImmutableList<Color4f> defaultValue, String comment, String prettyName)
{
super(ConfigType.COLOR_LIST, name, comment, prettyName);
this(name, defaultValue, comment, prettyName, name);
}

public ConfigColorList(String name, ImmutableList<Color4f> defaultValue, String comment, String prettyName, String translatedName)
{
super(ConfigType.COLOR_LIST, name, comment, prettyName, translatedName);

this.defaultValue = defaultValue;
this.colors.addAll(defaultValue);
Expand Down
22 changes: 16 additions & 6 deletions src/main/java/fi/dy/masa/malilib/config/options/ConfigDouble.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,32 @@ public ConfigDouble(String name, double defaultValue, String comment)

public ConfigDouble(String name, double defaultValue, String comment, String prettyName)
{
this(name, defaultValue, Double.MIN_VALUE, Double.MAX_VALUE, comment, prettyName);
this(name, defaultValue, Double.MIN_VALUE, Double.MAX_VALUE, comment, prettyName, name);
}

public ConfigDouble(String name, double defaultValue, String comment, String prettyName, String translatedName)
{
this(name, defaultValue, Double.MIN_VALUE, Double.MAX_VALUE, comment, prettyName, translatedName);
}

public ConfigDouble(String name, double defaultValue, double minValue, double maxValue, String comment)
{
this(name, defaultValue, minValue, maxValue, false, comment, name);
this(name, defaultValue, minValue, maxValue, comment, name);
}

public ConfigDouble(String name, double defaultValue, double minValue, double maxValue, String comment, String prettyName)
{
this(name, defaultValue, minValue, maxValue, false, comment, prettyName);
this(name, defaultValue, minValue, maxValue, false, comment, prettyName, name);
}

public ConfigDouble(String name, double defaultValue, double minValue, double maxValue, boolean useSlider, String comment, String prettyName)
public ConfigDouble(String name, double defaultValue, double minValue, double maxValue, String comment, String prettyName, String translatedName)
{
super(ConfigType.DOUBLE, name, comment, prettyName);
this(name, defaultValue, minValue, maxValue, false, comment, prettyName, translatedName);
}

public ConfigDouble(String name, double defaultValue, double minValue, double maxValue, boolean useSlider, String comment, String prettyName, String translatedName)
{
super(ConfigType.DOUBLE, name, comment, prettyName, translatedName);

this.minValue = minValue;
this.maxValue = maxValue;
Expand Down Expand Up @@ -112,7 +122,7 @@ public boolean isModified(String newValue)
{
return Double.parseDouble(newValue) != this.defaultValue;
}
catch (Exception e)
catch (Exception ignored)
{
}

Expand Down
20 changes: 15 additions & 5 deletions src/main/java/fi/dy/masa/malilib/config/options/ConfigHotkey.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,29 @@ public ConfigHotkey(String name, String defaultStorageString, String comment)
this(name, defaultStorageString, comment, name);
}

public ConfigHotkey(String name, String defaultStorageString, KeybindSettings settings, String comment)
public ConfigHotkey(String name, String defaultStorageString, String comment, String prettyName)
{
this(name, defaultStorageString, settings, comment, StringUtils.splitCamelCase(name));
this(name, defaultStorageString, KeybindSettings.DEFAULT, comment, prettyName, name);
}

public ConfigHotkey(String name, String defaultStorageString, String comment, String prettyName)
public ConfigHotkey(String name, String defaultStorageString, String comment, String prettyName, String translatedName)
{
this(name, defaultStorageString, KeybindSettings.DEFAULT, comment, prettyName, translatedName);
}

public ConfigHotkey(String name, String defaultStorageString, KeybindSettings settings, String comment)
{
this(name, defaultStorageString, KeybindSettings.DEFAULT, comment, prettyName);
this(name, defaultStorageString, settings, comment, StringUtils.splitCamelCase(name), name);
}

public ConfigHotkey(String name, String defaultStorageString, KeybindSettings settings, String comment, String prettyName)
{
super(ConfigType.HOTKEY, name, comment, prettyName);
this(name, defaultStorageString, settings, comment, prettyName, name);
}

public ConfigHotkey(String name, String defaultStorageString, KeybindSettings settings, String comment, String prettyName, String translatedName)
{
super(ConfigType.HOTKEY, name, comment, prettyName, translatedName);

this.keybind = KeybindMulti.fromStorageString(defaultStorageString, settings);
}
Expand Down
24 changes: 17 additions & 7 deletions src/main/java/fi/dy/masa/malilib/config/options/ConfigInteger.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,37 @@ public ConfigInteger(String name, int defaultValue, String comment)

public ConfigInteger(String name, int defaultValue, String comment, String prettyName)
{
this(name, defaultValue, Integer.MIN_VALUE, Integer.MAX_VALUE, comment, prettyName);
this(name, defaultValue, Integer.MIN_VALUE, Integer.MAX_VALUE, comment, prettyName, name);
}

public ConfigInteger(String name, int defaultValue, String comment, String prettyName, String translatedName)
{
this(name, defaultValue, Integer.MIN_VALUE, Integer.MAX_VALUE, comment, prettyName, translatedName);
}

public ConfigInteger(String name, int defaultValue, int minValue, int maxValue, String comment)
{
this(name, defaultValue, minValue, maxValue, false, comment, name);
this(name, defaultValue, minValue, maxValue, false, comment, name, name);
}

public ConfigInteger(String name, int defaultValue, int minValue, int maxValue, String comment, String prettyName)
{
this(name, defaultValue, minValue, maxValue, false, comment, prettyName);
this(name, defaultValue, minValue, maxValue, false, comment, prettyName, name);
}

public ConfigInteger(String name, int defaultValue, int minValue, int maxValue, String comment, String prettyName, String translatedName)
{
this(name, defaultValue, minValue, maxValue, false, comment, prettyName, translatedName);
}

public ConfigInteger(String name, int defaultValue, int minValue, int maxValue, boolean useSlider, String comment)
{
this(name, defaultValue, minValue, maxValue, useSlider, comment, name);
this(name, defaultValue, minValue, maxValue, useSlider, comment, name, name);
}

public ConfigInteger(String name, int defaultValue, int minValue, int maxValue, boolean useSlider, String comment, String prettyName)
public ConfigInteger(String name, int defaultValue, int minValue, int maxValue, boolean useSlider, String comment, String prettyName, String translatedName)
{
super(ConfigType.INTEGER, name, comment, prettyName);
super(ConfigType.INTEGER, name, comment, prettyName, translatedName);

this.minValue = minValue;
this.maxValue = maxValue;
Expand Down Expand Up @@ -117,7 +127,7 @@ public boolean isModified(String newValue)
{
return Integer.parseInt(newValue) != this.defaultValue;
}
catch (Exception e)
catch (Exception ignored)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ public ConfigOptionList(String name, IConfigOptionListEntry defaultValue, String

public ConfigOptionList(String name, IConfigOptionListEntry defaultValue, String comment, String prettyName)
{
super(ConfigType.OPTION_LIST, name, comment, prettyName);
this(name, defaultValue, comment, prettyName, name);
}

public ConfigOptionList(String name, IConfigOptionListEntry defaultValue, String comment, String prettyName, String translatedName)
{
super(ConfigType.OPTION_LIST, name, comment, prettyName, translatedName);

this.defaultValue = defaultValue;
this.value = defaultValue;
Expand Down Expand Up @@ -63,7 +68,7 @@ public boolean isModified(String newValue)
{
return this.value.fromString(newValue) != this.defaultValue;
}
catch (Exception e)
catch (Exception ignored)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ public ConfigString(String name, String defaultValue, String comment)

public ConfigString(String name, String defaultValue, String comment, String prettyName)
{
super(ConfigType.STRING, name, comment, prettyName);
this(name, defaultValue, comment, prettyName, name);
}

public ConfigString(String name, String defaultValue, String comment, String prettyName, String translatedName)
{
super(ConfigType.STRING, name, comment, prettyName, translatedName);

this.defaultValue = defaultValue;
this.value = defaultValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ public ConfigStringList(String name, ImmutableList<String> defaultValue, String

public ConfigStringList(String name, ImmutableList<String> defaultValue, String comment, String prettyName)
{
super(ConfigType.STRING_LIST, name, comment, prettyName);
this(name, defaultValue, comment, prettyName, name);
}

public ConfigStringList(String name, ImmutableList<String> defaultValue, String comment, String prettyName, String translatedName)
{
super(ConfigType.STRING_LIST, name, comment, prettyName, translatedName);

this.defaultValue = defaultValue;
this.strings.addAll(defaultValue);
Expand Down
Loading

0 comments on commit 159eec2

Please sign in to comment.