-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
382 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
modmenu-bridge/src/main/java/com/terraformersmc/modmenu/config/ModMenuConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
package com.terraformersmc.modmenu.config; | ||
|
||
import com.google.gson.annotations.SerializedName; | ||
import com.terraformersmc.modmenu.config.option.BooleanConfigOption; | ||
import com.terraformersmc.modmenu.config.option.EnumConfigOption; | ||
import com.terraformersmc.modmenu.config.option.OptionConvertable; | ||
import com.terraformersmc.modmenu.config.option.StringSetConfigOption; | ||
import net.minecraft.client.option.SimpleOption; | ||
|
||
import java.lang.reflect.Field; | ||
import java.lang.reflect.Modifier; | ||
import java.util.ArrayList; | ||
import java.util.Comparator; | ||
import java.util.HashSet; | ||
|
||
public class ModMenuConfig { | ||
public static final EnumConfigOption<Sorting> SORTING = new EnumConfigOption<>("sorting", Sorting.ASCENDING); | ||
public static final BooleanConfigOption COUNT_LIBRARIES = new BooleanConfigOption("count_libraries", true); | ||
public static final BooleanConfigOption COMPACT_LIST = new BooleanConfigOption("compact_list", false); | ||
public static final BooleanConfigOption COUNT_CHILDREN = new BooleanConfigOption("count_children", true); | ||
public static final EnumConfigOption<TitleMenuButtonStyle> MODS_BUTTON_STYLE = new EnumConfigOption<>("mods_button_style", TitleMenuButtonStyle.CLASSIC); | ||
public static final EnumConfigOption<GameMenuButtonStyle> GAME_MENU_BUTTON_STYLE = new EnumConfigOption<>("game_menu_button_style", GameMenuButtonStyle.REPLACE_BUGS); | ||
public static final BooleanConfigOption COUNT_HIDDEN_MODS = new BooleanConfigOption("count_hidden_mods", true); | ||
public static final EnumConfigOption<ModCountLocation> MOD_COUNT_LOCATION = new EnumConfigOption<>("mod_count_location", ModCountLocation.TITLE_SCREEN); | ||
public static final BooleanConfigOption HIDE_MOD_LINKS = new BooleanConfigOption("hide_mod_links", false); | ||
public static final BooleanConfigOption SHOW_LIBRARIES = new BooleanConfigOption("show_libraries", false); | ||
public static final BooleanConfigOption HIDE_MOD_LICENSE = new BooleanConfigOption("hide_mod_license", false); | ||
public static final BooleanConfigOption HIDE_BADGES = new BooleanConfigOption("hide_badges", false); | ||
public static final BooleanConfigOption HIDE_MOD_CREDITS = new BooleanConfigOption("hide_mod_credits", false); | ||
public static final BooleanConfigOption EASTER_EGGS = new BooleanConfigOption("easter_eggs", true); | ||
public static final BooleanConfigOption MODIFY_TITLE_SCREEN = new BooleanConfigOption("modify_title_screen", true); | ||
public static final BooleanConfigOption MODIFY_GAME_MENU = new BooleanConfigOption("modify_game_menu", true); | ||
public static final BooleanConfigOption HIDE_CONFIG_BUTTONS = new BooleanConfigOption("hide_config_buttons", false); | ||
public static final BooleanConfigOption RANDOM_JAVA_COLORS = new BooleanConfigOption("random_java_colors", false); | ||
public static final BooleanConfigOption TRANSLATE_NAMES = new BooleanConfigOption("translate_names", true); | ||
public static final BooleanConfigOption TRANSLATE_DESCRIPTIONS = new BooleanConfigOption("translate_descriptions", true); | ||
public static final BooleanConfigOption CONFIG_MODE = new BooleanConfigOption("config_mode", false); | ||
public static final BooleanConfigOption DISABLE_DRAG_AND_DROP = new BooleanConfigOption("disable_drag_and_drop", false); | ||
public static final StringSetConfigOption HIDDEN_MODS = new StringSetConfigOption("hidden_mods", new HashSet<>()); | ||
public static final StringSetConfigOption HIDDEN_CONFIGS = new StringSetConfigOption("hidden_configs", new HashSet<>()); | ||
public static final StringSetConfigOption DISABLE_UPDATE_CHECKER = new StringSetConfigOption("disable_update_checker", new HashSet<>()); | ||
public static final BooleanConfigOption UPDATE_CHECKER = new BooleanConfigOption("update_checker", true); | ||
public static final BooleanConfigOption BUTTON_UPDATE_BADGE = new BooleanConfigOption("button_update_badge", true); | ||
public static final BooleanConfigOption QUICK_CONFIGURE = new BooleanConfigOption("quick_configure", true); | ||
|
||
public static SimpleOption<?>[] asOptions() { | ||
ArrayList<SimpleOption<?>> options = new ArrayList<>(); | ||
for (Field field : ModMenuConfig.class.getDeclaredFields()) { | ||
if (Modifier.isStatic(field.getModifiers()) | ||
&& Modifier.isFinal(field.getModifiers()) | ||
&& OptionConvertable.class.isAssignableFrom(field.getType()) | ||
&& !field.getName().equals("HIDE_CONFIG_BUTTONS") | ||
&& !field.getName().equals("MODIFY_TITLE_SCREEN") | ||
&& !field.getName().equals("MODIFY_GAME_MENU") | ||
&& !field.getName().equals("CONFIG_MODE") | ||
&& !field.getName().equals("DISABLE_DRAG_AND_DROP") | ||
) { | ||
try { | ||
options.add(((OptionConvertable) field.get(null)).asOption()); | ||
} catch (IllegalAccessException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} | ||
return options.stream().toArray(SimpleOption[]::new); | ||
} | ||
|
||
public enum Sorting { | ||
@SerializedName("ascending") | ||
ASCENDING, | ||
@SerializedName("descending") | ||
DESCENDING; | ||
|
||
public Comparator<?> getComparator() { | ||
return Comparator.naturalOrder(); | ||
} | ||
} | ||
|
||
public enum ModCountLocation { | ||
@SerializedName("title_screen") | ||
TITLE_SCREEN(true, false), | ||
@SerializedName("mods_button") | ||
MODS_BUTTON(false, true), | ||
@SerializedName("title_screen_and_mods_button") | ||
TITLE_SCREEN_AND_MODS_BUTTON(true, true), | ||
@SerializedName("none") | ||
NONE(false, false); | ||
|
||
private final boolean titleScreen, modsButton; | ||
|
||
ModCountLocation(boolean titleScreen, boolean modsButton) { | ||
this.titleScreen = titleScreen; | ||
this.modsButton = modsButton; | ||
} | ||
|
||
public boolean isOnTitleScreen() { | ||
return titleScreen; | ||
} | ||
|
||
public boolean isOnModsButton() { | ||
return modsButton; | ||
} | ||
} | ||
|
||
public enum TitleMenuButtonStyle { | ||
@SerializedName("classic") | ||
CLASSIC(), | ||
@SerializedName("replace_realms") | ||
REPLACE_REALMS(), | ||
@SerializedName("shrink") | ||
SHRINK(), | ||
@SerializedName("icon") | ||
ICON(); | ||
} | ||
|
||
public enum GameMenuButtonStyle { | ||
@SerializedName("replace_bugs") | ||
REPLACE_BUGS, | ||
@SerializedName("below_bugs") | ||
BELOW_BUGS, | ||
@SerializedName("icon") | ||
ICON; | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
...nu-bridge/src/main/java/com/terraformersmc/modmenu/config/option/BooleanConfigOption.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.terraformersmc.modmenu.config.option; | ||
|
||
import net.minecraft.client.option.SimpleOption; | ||
import net.minecraft.screen.ScreenTexts; | ||
import net.minecraft.text.Text; | ||
|
||
public class BooleanConfigOption implements OptionConvertable { | ||
private final String key, translationKey; | ||
private final boolean defaultValue; | ||
private final Text enabledText; | ||
private final Text disabledText; | ||
|
||
public BooleanConfigOption(String key, boolean defaultValue, String enabledKey, String disabledKey) { | ||
ConfigOptionStorage.setBoolean(key, defaultValue); | ||
this.key = key; | ||
this.translationKey = ""; | ||
this.defaultValue = defaultValue; | ||
this.enabledText = Text.translatable(translationKey + "." + enabledKey); | ||
this.disabledText = Text.translatable(translationKey + "." + disabledKey); | ||
} | ||
|
||
public BooleanConfigOption(String key, boolean defaultValue) { | ||
this(key, defaultValue, "true", "false"); | ||
} | ||
|
||
public String getKey() { | ||
return key; | ||
} | ||
|
||
public boolean getValue() { | ||
return ConfigOptionStorage.getBoolean(key); | ||
} | ||
|
||
public void setValue(boolean value) { | ||
ConfigOptionStorage.setBoolean(key, value); | ||
} | ||
|
||
public void toggleValue() { | ||
ConfigOptionStorage.toggleBoolean(key); | ||
} | ||
|
||
public boolean getDefaultValue() { | ||
return defaultValue; | ||
} | ||
|
||
public Text getButtonText() { | ||
return ScreenTexts.composeGenericOptionText(Text.translatable(translationKey), getValue() ? enabledText : disabledText); | ||
} | ||
|
||
@Override | ||
public SimpleOption<Boolean> asOption() { | ||
if (enabledText != null && disabledText != null) { | ||
return new SimpleOption<>(translationKey, SimpleOption.emptyTooltip(), | ||
(text, value) -> value ? enabledText : disabledText, SimpleOption.BOOLEAN, getValue(), | ||
newValue -> ConfigOptionStorage.setBoolean(key, newValue)); | ||
} | ||
return SimpleOption.ofBoolean(translationKey, getValue(), (value) -> ConfigOptionStorage.setBoolean(key, value)); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
...nu-bridge/src/main/java/com/terraformersmc/modmenu/config/option/ConfigOptionStorage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.terraformersmc.modmenu.config.option; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
public class ConfigOptionStorage { | ||
private static final Map<String, Boolean> BOOLEAN_OPTIONS = new HashMap<>(); | ||
private static final Map<String, Enum<?>> ENUM_OPTIONS = new HashMap<>(); | ||
private static final Map<String, Set<String>> STRING_SET_OPTIONS = new HashMap<>(); | ||
|
||
public static void setStringSet(String key, Set<String> value) { | ||
STRING_SET_OPTIONS.put(key, value); | ||
} | ||
|
||
public static Set<String> getStringSet(String key) { | ||
return STRING_SET_OPTIONS.get(key); | ||
} | ||
|
||
public static void setBoolean(String key, boolean value) { | ||
BOOLEAN_OPTIONS.put(key, value); | ||
} | ||
|
||
public static void toggleBoolean(String key) { | ||
setBoolean(key, !getBoolean(key)); | ||
} | ||
|
||
public static boolean getBoolean(String key) { | ||
return BOOLEAN_OPTIONS.get(key); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public static <E extends Enum<E>> E getEnum(String key, Class<E> typeClass) { | ||
return (E) ENUM_OPTIONS.get(key); | ||
} | ||
|
||
public static Enum<?> getEnumTypeless(String key, Class<Enum<?>> typeClass) { | ||
return ENUM_OPTIONS.get(key); | ||
} | ||
|
||
public static <E extends Enum<E>> void setEnum(String key, E value) { | ||
ENUM_OPTIONS.put(key, value); | ||
} | ||
|
||
public static void setEnumTypeless(String key, Enum<?> value) { | ||
ENUM_OPTIONS.put(key, value); | ||
} | ||
|
||
public static <E extends Enum<E>> E cycleEnum(String key, Class<E> typeClass) { | ||
return cycleEnum(key, typeClass, 1); | ||
} | ||
|
||
|
||
public static <E extends Enum<E>> E cycleEnum(String key, Class<E> typeClass, int amount) { | ||
E[] values = typeClass.getEnumConstants(); | ||
E currentValue = getEnum(key, typeClass); | ||
E newValue = values[(currentValue.ordinal() + amount) % values.length]; | ||
setEnum(key, newValue); | ||
return newValue; | ||
} | ||
} |
Oops, something went wrong.