Skip to content

Commit

Permalink
Migrate to GTNHLib config
Browse files Browse the repository at this point in the history
  • Loading branch information
miozune committed Sep 10, 2024
1 parent 1da3d22 commit 4547d1c
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 193 deletions.
19 changes: 9 additions & 10 deletions src/main/java/com/cleanroommc/modularui/CommonProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
import com.cleanroommc.modularui.network.NetworkHandler;
import com.cleanroommc.modularui.test.ItemEditorGui;
import com.cleanroommc.modularui.test.TestBlock;
import cpw.mods.fml.client.event.ConfigChangedEvent;

import com.gtnewhorizon.gtnhlib.config.ConfigException;
import com.gtnewhorizon.gtnhlib.config.ConfigurationManager;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.event.FMLServerStartingEvent;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.registry.EntityRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
Expand All @@ -20,7 +21,12 @@
public class CommonProxy {

void preInit(FMLPreInitializationEvent event) {
ModularUIConfig.init(event.getSuggestedConfigurationFile());
try {
ConfigurationManager.registerConfig(ModularUIConfig.class);
} catch (ConfigException e) {
throw new RuntimeException(e);
}

FMLCommonHandler.instance().bus().register(new GuiManager());
MinecraftForge.EVENT_BUS.register(new GuiManager());

Expand Down Expand Up @@ -50,11 +56,4 @@ void onServerLoad(FMLServerStartingEvent event) {
public Timer getTimer60Fps() {
throw new UnsupportedOperationException();
}

@SubscribeEvent
public final void onConfigChange(ConfigChangedEvent.OnConfigChangedEvent event) {
if (event.modID.equals(ModularUI.ID)) {
ModularUIConfig.syncConfig();
}
}
}
3 changes: 2 additions & 1 deletion src/main/java/com/cleanroommc/modularui/ModularUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

@Mod(modid = ModularUI.ID, name = "Modular UI 2", version = Tags.VERSION, dependencies = ModularUI.DEPENDENCIES, guiFactory = "com.cleanroommc.modularui.config.GuiFactory")
@Mod(modid = ModularUI.ID, name = ModularUI.NAME, version = Tags.VERSION, dependencies = ModularUI.DEPENDENCIES, guiFactory = "com.cleanroommc.modularui.config.ModularUIGuiConfigFactory")
public class ModularUI {

static final String DEPENDENCIES = "required-after:gtnhmixins@[2.0.1,); "
Expand All @@ -21,6 +21,7 @@ public class ModularUI {
+ "before:gregtech";

public static final String ID = "modularui2";
public static final String NAME = "Modular UI 2";

public static final Logger LOGGER = LogManager.getLogger(ID);

Expand Down
127 changes: 18 additions & 109 deletions src/main/java/com/cleanroommc/modularui/ModularUIConfig.java
Original file line number Diff line number Diff line change
@@ -1,125 +1,34 @@
package com.cleanroommc.modularui;

import com.cleanroommc.modularui.screen.RichTooltip;
import net.minecraftforge.common.config.Configuration;

import java.io.File;
import com.gtnewhorizon.gtnhlib.config.Config;

public class ModularUIConfig {

public static Configuration config;
@Config(modid = ModularUI.ID)
public class ModularUIConfig {

@Config.Comment("Amount of pixels scrolled")
@Config.RangeInt(min = 1, max = 100)
public static int defaultScrollSpeed = 30;

@Config.Comment("If progress bar should step in texture pixels or screen pixels. (Screen pixels are way smaller and therefore smoother)")
public static boolean smoothProgressBar = true;

@Config.Comment("Time in 1/60 sec to open and close panels.")
public static int panelOpenCloseAnimationTime = 0;

// Default direction
@Config.Comment("Default tooltip position around the widget or its panel.")
public static RichTooltip.Pos tooltipPos = RichTooltip.Pos.NEXT_TO_MOUSE;
public static boolean useDarkThemeByDefault = false;

@Config.Comment("If true, widget outlines and widget information will be drawn.")
public static boolean guiDebugMode = ModularUI.isDevEnv;
public static boolean enableTestGuis = ModularUI.isDevEnv;

public static final String CATEGORY_RENDERING = "rendering";
public static final String CATEGORY_DEBUG = "debug";

private static final String LANG_PREFIX = ModularUI.ID + ".config.";

public static final String[] CATEGORIES = new String[] {
CATEGORY_RENDERING,
CATEGORY_DEBUG,
};

public static void init(File configFile) {
config = new Configuration(configFile);
syncConfig();
}

public static void syncConfig() {
config.setCategoryComment(CATEGORY_RENDERING, "Rendering");
config.setCategoryLanguageKey(CATEGORY_RENDERING, LANG_PREFIX + CATEGORY_RENDERING);
config.setCategoryComment(CATEGORY_DEBUG, "Debug");
config.setCategoryLanguageKey(CATEGORY_DEBUG, LANG_PREFIX + CATEGORY_DEBUG);

// === Rendering ===

defaultScrollSpeed = config.get(
CATEGORY_RENDERING,
"defaultScrollSpeed",
30,
"Amount of pixels scrolled.",
1,
100
)
.setLanguageKey(LANG_PREFIX + CATEGORY_RENDERING + ".defaultScrollSpeed")
.getInt();

smoothProgressBar = config.get(
CATEGORY_RENDERING,
"smoothProgressBar",
true,
"If progress bar should step in texture pixels or screen pixels. (Screen pixels are way smaller and therefore smoother)"
)
.setLanguageKey(LANG_PREFIX + CATEGORY_RENDERING + ".smoothProgressBar")
.getBoolean();

panelOpenCloseAnimationTime = config.get(
CATEGORY_RENDERING,
"panelOpenCloseAnimationTime",
0,
"Time in 1/60 sec to open and close panels."
)
.setLanguageKey(LANG_PREFIX + CATEGORY_RENDERING + ".panelOpenCloseAnimationTime")
.getInt();

tooltipPos = RichTooltip.Pos.fromString(
config.get(
CATEGORY_RENDERING,
"tooltipPos",
"NEXT_TO_MOUSE",
"Default tooltip position around the widget or its panel. Select: ABOVE, BELOW, LEFT, RIGHT, VERTICAL, HORIZONTAL, NEXT_TO_MOUSE",
new String[] {
"ABOVE",
"BELOW",
"LEFT",
"RIGHT",
"VERTICAL",
"HORIZONTAL",
"NEXT_TO_MOUSE",
}
)
.setLanguageKey(LANG_PREFIX + CATEGORY_RENDERING + ".tooltipPos")
.getString());

useDarkThemeByDefault = config.get(
CATEGORY_RENDERING,
"useDarkThemeByDefault",
false,
"If true and not specified otherwise, screens will try to use the 'vanilla_dark' theme."
)
.setLanguageKey(LANG_PREFIX + CATEGORY_RENDERING + ".useDarkThemeByDefault")
.getBoolean();

// === Debug ===

guiDebugMode = config.get(
CATEGORY_DEBUG,
"guiDebugMode",
ModularUI.isDevEnv,
"If true, widget outlines and widget information will be drawn."
)
.setLanguageKey(LANG_PREFIX + CATEGORY_DEBUG + ".guiDebugMode")
.getBoolean();

enableTestGuis = config.get(
CATEGORY_DEBUG,
"enableTestGuis",
ModularUI.isDevEnv,
"Enables a test block, test item with a test gui and opening a gui by right clicking a diamond."
)
.setLanguageKey(LANG_PREFIX + CATEGORY_DEBUG + ".enableTestGuis")
.getBoolean();
@Config.Comment("If true and not specified otherwise, screens will try to use the 'vanilla_dark' theme.")
public static boolean useDarkThemeByDefault = false;

if (config.hasChanged()) {
config.save();
}
}
@Config.RequiresMcRestart
@Config.Comment("Enables a test block, test item with a test gui and opening a gui by right clicking a diamond.")
public static boolean enableTestGuis = ModularUI.isDevEnv;
}
29 changes: 0 additions & 29 deletions src/main/java/com/cleanroommc/modularui/config/GuiFactory.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,15 @@

import com.cleanroommc.modularui.ModularUI;
import com.cleanroommc.modularui.ModularUIConfig;
import cpw.mods.fml.client.config.GuiConfig;
import cpw.mods.fml.client.config.IConfigElement;
import net.minecraft.client.gui.GuiScreen;
import net.minecraftforge.common.config.ConfigElement;

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

@SuppressWarnings("rawtypes")
public class ModularUIGuiConfig extends GuiConfig {
import com.gtnewhorizon.gtnhlib.config.ConfigException;
import com.gtnewhorizon.gtnhlib.config.SimpleGuiConfig;

public ModularUIGuiConfig(GuiScreen parentScreen) {
super(
parentScreen,
getConfigElements(),
ModularUI.ID,
false,
false,
GuiConfig.getAbridgedConfigPath(ModularUIConfig.config.toString()));
}

private static List<IConfigElement> getConfigElements() {
List<IConfigElement> list = new ArrayList<>();
import net.minecraft.client.gui.GuiScreen;

for (String category : ModularUIConfig.CATEGORIES) {
list.add(new ConfigElement(ModularUIConfig.config.getCategory(category.toLowerCase(Locale.US))));
}
public class ModularUIGuiConfig extends SimpleGuiConfig {

return list;
public ModularUIGuiConfig(GuiScreen parent) throws ConfigException {
super(parent, ModularUI.ID, ModularUI.NAME, ModularUIConfig.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.cleanroommc.modularui.config;

import com.gtnewhorizon.gtnhlib.config.SimpleGuiFactory;

import net.minecraft.client.gui.GuiScreen;

@SuppressWarnings("unused")
public class ModularUIGuiConfigFactory implements SimpleGuiFactory {

@Override
public Class<? extends GuiScreen> mainConfigGuiClass() {
return ModularUIGuiConfig.class;
}
}
18 changes: 0 additions & 18 deletions src/main/resources/assets/modularui2/lang/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,3 @@ modularui2.item.phantom.control=§7Scroll wheel up increases amount, down decrea
modularui2.fluid.click_to_fill=§bLeft §7Click with a Fluid Container to §bfill §7the tank (Shift-click for a full stack).
modularui2.fluid.click_combined=§cRight §7or §bLeft §7Click with a Fluid Container to §cempty §7or §bfill §7the tank (Shift-click for a full stack).
modularui2.fluid.click_to_empty=§cRight §7Click with a Fluid Container to §cempty §7the tank (Shift-click for a full stack).

modularui2.config.rendering=Rendering
modularui2.config.debug=Debug

modularui2.config.animations.defaultScrollSpeed=Default scroll speed
modularui2.config.animations.defaultScrollSpeed.tooltip=Amount of pixels scrolled.
modularui2.config.animations.smoothProgressBar=Smooth progressbar
modularui2.config.animations.smoothProgressBar.tooltip=If progress bar should step in texture pixels or screen pixels. (Screen pixels are way smaller and therefore smoother)
modularui2.config.animations.panelOpenCloseAnimationTime=Duration of open/close animations
modularui2.config.animations.panelOpenCloseAnimationTime.tooltip=Time in 1/60 sec to open and close panels.
modularui2.config.animations.tooltipPos=Default tooltip position
modularui2.config.animations.tooltipPos.tooltip=Default tooltip position around the widget or its panel. Select: ABOVE, BELOW, LEFT, RIGHT, VERTICAL, HORIZONTAL, NEXT_TO_MOUSE
modularui2.config.animations.useDarkThemeByDefault=Dark theme
modularui2.config.animations.useDarkThemeByDefault.tooltip=If true and not specified otherwise, screens will try to use the 'vanilla_dark' theme.
modularui2.config.debug.guiDebugMode=GUI debug mode
modularui2.config.debug.guiDebugMode.tooltip=If true, widget outlines and widget information will be drawn.
modularui2.config.debug.enableTestGuis=Enable test GUIs
modularui2.config.debug.enableTestGuis.tooltip=Enables a test block, test item with a test gui and opening a gui by right clicking a diamond.

0 comments on commit 4547d1c

Please sign in to comment.