diff --git a/src/main/java/at/feldim2425/moreoverlays/MoreOverlays.java b/src/main/java/at/feldim2425/moreoverlays/MoreOverlays.java index 258eb1d..53612df 100644 --- a/src/main/java/at/feldim2425/moreoverlays/MoreOverlays.java +++ b/src/main/java/at/feldim2425/moreoverlays/MoreOverlays.java @@ -43,6 +43,6 @@ public void onClientInit(FMLClientSetupEvent event){ } public Screen openSettings(Minecraft mc, Screen modlist){ - return new ConfigScreen(Config.config_client, MOD_ID); + return new ConfigScreen(modlist, Config.config_client, MOD_ID); } } diff --git a/src/main/java/at/feldim2425/moreoverlays/gui/ConfigScreen.java b/src/main/java/at/feldim2425/moreoverlays/gui/ConfigScreen.java index 810fcd3..410e97e 100644 --- a/src/main/java/at/feldim2425/moreoverlays/gui/ConfigScreen.java +++ b/src/main/java/at/feldim2425/moreoverlays/gui/ConfigScreen.java @@ -5,6 +5,7 @@ import at.feldim2425.moreoverlays.MoreOverlays; import at.feldim2425.moreoverlays.gui.config.ConfigOptionList; +import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.widget.button.Button; import net.minecraft.client.resources.I18n; @@ -26,11 +27,13 @@ public class ConfigScreen extends Screen { private String txtUndo = ""; private String txtReset = ""; + private Screen modListScreen; - public ConfigScreen(ForgeConfigSpec spec, String modId) { + public ConfigScreen(Screen modListScreen, ForgeConfigSpec spec, String modId) { super(new TranslationTextComponent("gui.config."+modId+".tile")); + this.modListScreen = modListScreen; this.configSpec = spec; - this.modId = modId; + this.modId = modId; this.txtReset = I18n.format("gui.config." + MoreOverlays.MOD_ID + ".reset_config"); this.txtUndo = I18n.format("gui.config." + MoreOverlays.MOD_ID + ".undo"); @@ -38,8 +41,16 @@ public ConfigScreen(ForgeConfigSpec spec, String modId) { @Override protected void init() { - this.optionList = new ConfigOptionList(this.minecraft, this.modId, this); - + if (this.optionList == null) { + this.optionList = new ConfigOptionList(this.minecraft, this.modId, this); + + if(pathCache.isEmpty()){ + this.optionList.setConfiguration(configSpec); + } + else { + this.optionList.setConfiguration(configSpec, this.pathCache); + } + } final int buttonY = this.height - 32 + (32-20)/2; this.btnReset = new Button(this.width-40, buttonY, 20, 20, ConfigOptionList.RESET_CHAR, @@ -58,16 +69,19 @@ protected void init() { this.btnUndo.active = false; this.btnSave.active = false; - - if(pathCache.isEmpty()){ - this.optionList.setConfiguration(configSpec); + this.optionList.updateGui(); + } + + private void back() { + if(!this.optionList.getCurrentPath().isEmpty()){ + this.optionList.pop(); } else { - this.optionList.setConfiguration(configSpec, this.pathCache); + Minecraft.getInstance().displayGuiScreen(modListScreen); } - } - - @Override + } + + @Override public void render(int mouseX, int mouseY, float partialTick) { this.renderBackground(); this.optionList.render(mouseX, mouseY, partialTick); @@ -117,12 +131,12 @@ public void updatePath(final List newPath){ @Override public boolean keyPressed(int key, int p_keyPressed_2_, int p_keyPressed_3_) { - if(key == 256 && !this.optionList.getCurrentPath().isEmpty()){ - this.optionList.pop(); - return true; + if (key == 256) { + this.back(); + return true; } else { return super.keyPressed(key, p_keyPressed_2_, p_keyPressed_3_); } } -} \ No newline at end of file +} diff --git a/src/main/java/at/feldim2425/moreoverlays/gui/config/ConfigOptionList.java b/src/main/java/at/feldim2425/moreoverlays/gui/config/ConfigOptionList.java index e3aadc9..42b8b56 100644 --- a/src/main/java/at/feldim2425/moreoverlays/gui/config/ConfigOptionList.java +++ b/src/main/java/at/feldim2425/moreoverlays/gui/config/ConfigOptionList.java @@ -65,6 +65,11 @@ protected int getScrollbarPosition() { public int getRowWidth() { return super.getRowWidth() + 64; } + + public void updateGui() { + this.updateSize(this.parent.width, this.parent.height, 43, this.parent.height - 32); + } + @Override protected void renderDecorations(int p_renderDecorations_1_, int p_renderDecorations_2_) { @@ -186,6 +191,7 @@ else if(cEntry.getValue() instanceof ForgeConfigSpec.BooleanValue){ this.addEntry(new OptionGeneric<>(this, (ForgeConfigSpec.ConfigValue)cEntry.getValue(), (ForgeConfigSpec.ValueSpec)rootConfig.getSpec().get(fullPath))); } } + this.setFocused(null); } public List getCurrentPath() {