From d566771b9fdba45c56b272b28e5fc0dbf2508958 Mon Sep 17 00:00:00 2001 From: syeyoung Date: Tue, 7 Feb 2023 15:11:13 +0900 Subject: - config gui and going back Signed-off-by: syeyoung --- .../syeyoung/dungeonsguide/mod/DungeonsGuide.java | 7 ++++-- .../guiconfig/configv3/ConfigGuiScreenAdapter.java | 29 ++++++++++++++++++++++ .../mod/config/guiconfig/configv3/FeatureItem.java | 2 +- .../mod/config/guiconfig/configv3/GUIOpenItem.java | 2 +- .../mod/features/AbstractHUDFeature.java | 2 +- .../dungeonsguide/mod/guiv2/GuiScreenAdapter.java | 14 +++++++++++ 6 files changed, 51 insertions(+), 5 deletions(-) create mode 100644 mod/src/main/java/kr/syeyoung/dungeonsguide/mod/config/guiconfig/configv3/ConfigGuiScreenAdapter.java (limited to 'mod') diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/DungeonsGuide.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/DungeonsGuide.java index b0d67ab0..f3622b22 100755 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/DungeonsGuide.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/DungeonsGuide.java @@ -27,6 +27,7 @@ import kr.syeyoung.dungeonsguide.mod.commands.CommandDgDebug; import kr.syeyoung.dungeonsguide.mod.commands.CommandDungeonsGuide; import kr.syeyoung.dungeonsguide.mod.commands.CommandReparty; import kr.syeyoung.dungeonsguide.mod.config.Config; +import kr.syeyoung.dungeonsguide.mod.config.guiconfig.configv3.ConfigGuiScreenAdapter; import kr.syeyoung.dungeonsguide.mod.cosmetics.CosmeticsManager; import kr.syeyoung.dungeonsguide.mod.cosmetics.CustomNetworkPlayerInfo; import kr.syeyoung.dungeonsguide.mod.discord.DiscordIntegrationManager; @@ -488,6 +489,8 @@ public class DungeonsGuide implements DGInterface { } - - + @Override + public Class getModConfigGUI() { + return ConfigGuiScreenAdapter.class; + } } diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/config/guiconfig/configv3/ConfigGuiScreenAdapter.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/config/guiconfig/configv3/ConfigGuiScreenAdapter.java new file mode 100644 index 00000000..77717c74 --- /dev/null +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/config/guiconfig/configv3/ConfigGuiScreenAdapter.java @@ -0,0 +1,29 @@ +/* + * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod + * Copyright (C) 2023 cyoung06 (syeyoung) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package kr.syeyoung.dungeonsguide.mod.config.guiconfig.configv3; + +import kr.syeyoung.dungeonsguide.mod.guiv2.GuiScreenAdapter; +import kr.syeyoung.dungeonsguide.mod.guiv2.elements.GlobalHUDScale; +import net.minecraft.client.gui.GuiScreen; + +public class ConfigGuiScreenAdapter extends GuiScreenAdapter { + public ConfigGuiScreenAdapter(GuiScreen parent) { + super(new GlobalHUDScale(new MainConfigWidget()), parent); + } +} diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/config/guiconfig/configv3/FeatureItem.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/config/guiconfig/configv3/FeatureItem.java index 525d5e97..c082eb2a 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/config/guiconfig/configv3/FeatureItem.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/config/guiconfig/configv3/FeatureItem.java @@ -93,7 +93,7 @@ public class FeatureItem extends AnnotatedImportOnlyWidget { @On(functionName = "relocate") public void onRelocate() { Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.create(new ResourceLocation("gui.button.press"), 1.0F)); - Minecraft.getMinecraft().displayGuiScreen(new GuiScreenAdapter(new GlobalHUDScale(new HUDLocationConfig((AbstractHUDFeature) feature)))); + Minecraft.getMinecraft().displayGuiScreen(new GuiScreenAdapter(new GlobalHUDScale(new HUDLocationConfig((AbstractHUDFeature) feature)), Minecraft.getMinecraft().currentScreen)); // do stuff } } diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/config/guiconfig/configv3/GUIOpenItem.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/config/guiconfig/configv3/GUIOpenItem.java index 0f3d9cda..da65f8c6 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/config/guiconfig/configv3/GUIOpenItem.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/config/guiconfig/configv3/GUIOpenItem.java @@ -52,6 +52,6 @@ public class GUIOpenItem extends AnnotatedImportOnlyWidget { @On(functionName = "click") public void openPage() { Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.create(new ResourceLocation("gui.button.press"), 1.0F)); - Minecraft.getMinecraft().displayGuiScreen(new GuiScreenAdapter(new GlobalHUDScale(pageCreator.get()))); + Minecraft.getMinecraft().displayGuiScreen(new GuiScreenAdapter(new GlobalHUDScale(pageCreator.get()), Minecraft.getMinecraft().currentScreen)); } } diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/AbstractHUDFeature.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/AbstractHUDFeature.java index b5b1fafb..94bec8fd 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/AbstractHUDFeature.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/features/AbstractHUDFeature.java @@ -181,7 +181,7 @@ public abstract class AbstractHUDFeature extends AbstractGuiFeature { public void configure() { Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.create(new ResourceLocation("gui.button.press"), 1.0F)); MainConfigWidget mainConfigWidget = new MainConfigWidget(); - GuiScreenAdapter adapter = new GuiScreenAdapter(new GlobalHUDScale(mainConfigWidget)); + GuiScreenAdapter adapter = new GuiScreenAdapter(new GlobalHUDScale(mainConfigWidget), Minecraft.getMinecraft().currentScreen); Minecraft.getMinecraft().displayGuiScreen(adapter); Navigator.getNavigator(mainConfigWidget.getDomElement()).openPage( diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/GuiScreenAdapter.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/GuiScreenAdapter.java index 6bcad794..34d755cb 100644 --- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/GuiScreenAdapter.java +++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/guiv2/GuiScreenAdapter.java @@ -26,6 +26,7 @@ import kr.syeyoung.dungeonsguide.mod.utils.cursor.EnumCursor; import kr.syeyoung.dungeonsguide.mod.utils.cursor.GLCursors; import lombok.Getter; import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.renderer.GlStateManager; @@ -47,7 +48,12 @@ public class GuiScreenAdapter extends GuiScreen { private Stack domStack = new Stack<>(); + private GuiScreen parent; public GuiScreenAdapter(Widget widget) { + this(widget, null); + } + public GuiScreenAdapter(Widget widget, GuiScreen parent) { + this.parent = parent; view = new RootDom(widget); view.getContext().CONTEXT.put("screenAdapter", this); @@ -134,6 +140,14 @@ public class GuiScreenAdapter extends GuiScreen { @Override public void keyTyped(char typedChar, int keyCode) throws IOException { + if (keyCode == 1) { + this.mc.displayGuiScreen((GuiScreen)parent); + if (this.mc.currentScreen == null) { + this.mc.setIngameFocus(); + } + return; + } + try { view.keyPressed0(typedChar, keyCode); super.keyTyped(typedChar, keyCode); -- cgit