aboutsummaryrefslogtreecommitdiff
path: root/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/gui
diff options
context:
space:
mode:
Diffstat (limited to 'loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/gui')
-rw-r--r--loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/gui/screen/GuiDisplayer.java19
-rw-r--r--loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/gui/screen/GuiPrivacyPolicy.java83
-rw-r--r--loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/gui/screen/SpecialGuiScreen.java3
-rw-r--r--loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/gui/screen/WidgetPrivacyPolicy.java101
4 files changed, 112 insertions, 94 deletions
diff --git a/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/gui/screen/GuiDisplayer.java b/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/gui/screen/GuiDisplayer.java
index 35d9a9ea..ad942ffb 100644
--- a/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/gui/screen/GuiDisplayer.java
+++ b/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/gui/screen/GuiDisplayer.java
@@ -20,6 +20,7 @@ package kr.syeyoung.dungeonsguide.launcher.gui.screen;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiMainMenu;
+import net.minecraft.client.gui.GuiScreen;
import net.minecraftforge.client.event.GuiOpenEvent;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
@@ -31,7 +32,7 @@ public class GuiDisplayer {
public static GuiDisplayer INSTANCE = new GuiDisplayer();
private GuiDisplayer() {}
- private Queue<SpecialGuiScreen> guiScreensToShow = new LinkedList<>();
+ private Queue<GuiScreen> guiScreensToShow = new LinkedList<>();
private boolean isMcLoaded;
@@ -40,23 +41,21 @@ public class GuiDisplayer {
if (guiOpenEvent.gui instanceof GuiMainMenu) {
isMcLoaded = true;
}
- if (guiScreensToShow.size() > 0 && guiOpenEvent.gui != guiScreensToShow.peek()) {
- SpecialGuiScreen gui = guiScreensToShow.peek();
+ if (isMcLoaded && !guiScreensToShow.isEmpty()) {
+ GuiScreen gui = guiScreensToShow.poll();
if (gui == null) return;
- gui.setOnDismiss(guiScreensToShow::poll);
guiOpenEvent.gui = gui;
}
}
- public void displayGui(SpecialGuiScreen specialGuiScreen) {
+ public void displayGui(GuiScreen specialGuiScreen) {
if (specialGuiScreen == null) return;
if (!guiScreensToShow.contains(specialGuiScreen))
guiScreensToShow.add(specialGuiScreen);
- if (isMcLoaded) {
- SpecialGuiScreen gui = guiScreensToShow.peek();
- if (gui == null) return;
- gui.setOnDismiss(guiScreensToShow::poll);
- Minecraft.getMinecraft().displayGuiScreen(gui);
+ if (isMcLoaded && Minecraft.getMinecraft().isCallingFromMinecraftThread()) {
+ Minecraft.getMinecraft().displayGuiScreen(null);
+ } else if (isMcLoaded) {
+ Minecraft.getMinecraft().addScheduledTask(() -> Minecraft.getMinecraft().displayGuiScreen(null));
}
}
}
diff --git a/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/gui/screen/GuiPrivacyPolicy.java b/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/gui/screen/GuiPrivacyPolicy.java
deleted file mode 100644
index 66b26111..00000000
--- a/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/gui/screen/GuiPrivacyPolicy.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Dungeons Guide - The most intelligent Hypixel Skyblock Dungeons Mod
- * Copyright (C) 2022 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 <https://www.gnu.org/licenses/>.
- */
-
-package kr.syeyoung.dungeonsguide.launcher.gui.screen;
-
-import kr.syeyoung.dungeonsguide.launcher.auth.AuthManager;
-import net.minecraft.client.Minecraft;
-import net.minecraft.client.gui.FontRenderer;
-import net.minecraft.client.gui.GuiButton;
-import net.minecraft.client.gui.ScaledResolution;
-import org.lwjgl.opengl.GL11;
-
-import java.io.IOException;
-
-public class GuiPrivacyPolicy extends SpecialGuiScreen {
- @Override
- public void initGui() {
- super.initGui();
- ScaledResolution sr = new ScaledResolution(Minecraft.getMinecraft());
-
- int width = Math.min(300, sr.getScaledWidth() / 2 - 20);
-
- this.buttonList.add(new GuiButton(0, sr.getScaledWidth()/2 + 10,sr.getScaledHeight()-40, width, 20,"Accept Privacy Policy"));
- this.buttonList.add(new GuiButton(1, sr.getScaledWidth() / 2 - 10 - width,sr.getScaledHeight()-40, width, 20,"Deny and Play Without DG"));
- }
-
-
- @Override
- protected void actionPerformed(GuiButton button) throws IOException {
- super.actionPerformed(button);
- if (button.id == 0) {
- // accept
- try {
- AuthManager.getInstance().acceptPrivacyPolicy(1);
- } catch (Exception e) {
- e.printStackTrace();
-// GuiDisplayer.INSTANCE.displayGui(new GuiLoadingError(e));
- // display tooltip.
- }
- dismiss();
- } else if (button.id == 1) {
- dismiss();
- }
- }
-
-
- @Override
- public void drawScreen(int mouseX, int mouseY, float partialTicks) {
- super.drawBackground(0);
-
- ScaledResolution sr = new ScaledResolution(Minecraft.getMinecraft());
- FontRenderer fontRenderer = Minecraft.getMinecraft().fontRendererObj;
-
- final String ACCEPT_POLICY_MSG = "Please accept or deny the Dungeons Guide Privacy Policy to continue";
-
- fontRenderer.drawString(ACCEPT_POLICY_MSG, (sr.getScaledWidth()-fontRenderer.getStringWidth(ACCEPT_POLICY_MSG))/2,40,0xFFFF0000);
- fontRenderer.drawString("Blah blah legal stuff", (sr.getScaledWidth()-fontRenderer.getStringWidth(ACCEPT_POLICY_MSG))/2,sr.getScaledHeight() / 2, 0xFFFFFFFF);
-
- super.drawScreen(mouseX, mouseY, partialTicks);
- }
-
- public static void clip(ScaledResolution resolution, int x, int y, int width, int height) {
- if (width < 0 || height < 0) return;
-
- int scale = resolution.getScaleFactor();
- GL11.glScissor((x ) * scale, Minecraft.getMinecraft().displayHeight - (y + height) * scale, (width) * scale, height * scale);
- }
-}
diff --git a/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/gui/screen/SpecialGuiScreen.java b/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/gui/screen/SpecialGuiScreen.java
index efe5c36a..280b5b3e 100644
--- a/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/gui/screen/SpecialGuiScreen.java
+++ b/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/gui/screen/SpecialGuiScreen.java
@@ -29,7 +29,8 @@ public abstract class SpecialGuiScreen extends GuiScreen {
}
protected void dismiss() {
- onDismiss.run();
+ if (onDismiss != null)
+ onDismiss.run();
Minecraft.getMinecraft().displayGuiScreen(null);
}
}
diff --git a/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/gui/screen/WidgetPrivacyPolicy.java b/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/gui/screen/WidgetPrivacyPolicy.java
new file mode 100644
index 00000000..0ee99c92
--- /dev/null
+++ b/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/gui/screen/WidgetPrivacyPolicy.java
@@ -0,0 +1,101 @@
+/*
+ * 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 <https://www.gnu.org/licenses/>.
+ */
+
+package kr.syeyoung.dungeonsguide.launcher.gui.screen;
+
+import kr.syeyoung.dungeonsguide.launcher.LetsEncrypt;
+import kr.syeyoung.dungeonsguide.launcher.Main;
+import kr.syeyoung.dungeonsguide.launcher.auth.AuthManager;
+import kr.syeyoung.dungeonsguide.launcher.guiv2.BindableAttribute;
+import kr.syeyoung.dungeonsguide.launcher.guiv2.Widget;
+import kr.syeyoung.dungeonsguide.launcher.guiv2.xml.AnnotatedImportOnlyWidget;
+import kr.syeyoung.dungeonsguide.launcher.guiv2.xml.DomElementRegistry;
+import kr.syeyoung.dungeonsguide.launcher.guiv2.xml.ParsedWidgetConverter;
+import kr.syeyoung.dungeonsguide.launcher.guiv2.xml.annotations.Bind;
+import kr.syeyoung.dungeonsguide.launcher.guiv2.xml.annotations.On;
+import kr.syeyoung.dungeonsguide.launcher.guiv2.xml.data.Parser;
+import kr.syeyoung.dungeonsguide.launcher.guiv2.xml.data.ParserElement;
+import kr.syeyoung.dungeonsguide.launcher.guiv2.xml.data.W3CBackedParser;
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.audio.PositionedSoundRecord;
+import net.minecraft.util.ResourceLocation;
+import org.apache.commons.io.IOUtils;
+
+import javax.net.ssl.HttpsURLConnection;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Collections;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+public class WidgetPrivacyPolicy extends AnnotatedImportOnlyWidget {
+ private static final ExecutorService executor = Executors.newSingleThreadExecutor();
+ @Bind(variableName = "policy")
+ public final BindableAttribute<Widget> policy = new BindableAttribute<>(Widget.class);
+ @Bind(variableName = "policyVisibility")
+ public final BindableAttribute<String> policyVisibility = new BindableAttribute<>(String.class, "loading");
+
+ @Bind(variableName = "policyVersion")
+ public final BindableAttribute<Integer> version = new BindableAttribute<>(Integer.class, 0);
+
+ public WidgetPrivacyPolicy() {
+ super(new ResourceLocation("dungeons_guide_loader:gui/privacyPolicy/privacyPolicy.gui"));
+ reload();
+ }
+
+ @On(functionName = "accept")
+ public void accept() {
+ Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.create(new ResourceLocation("gui.button.press"), 1.0F));
+ AuthManager.getInstance().acceptPrivacyPolicy(version.getValue());
+ Minecraft.getMinecraft().displayGuiScreen(null);
+ }
+ @On(functionName = "deny")
+ public void deny() {
+ Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.create(new ResourceLocation("gui.button.press"), 1.0F));
+ Minecraft.getMinecraft().displayGuiScreen(null);
+ }
+
+ @On(functionName = "reload")
+ public void reload() {
+ Minecraft.getMinecraft().getSoundHandler().playSound(PositionedSoundRecord.create(new ResourceLocation("gui.button.press"), 1.0F));
+ policyVisibility.setValue("loading");
+ executor.submit(() -> {
+ try {
+ HttpsURLConnection urlConnection = (HttpsURLConnection) new URL(Main.POLICY).openConnection();
+ urlConnection.setSSLSocketFactory(LetsEncrypt.LETS_ENCRYPT);
+ urlConnection.setRequestProperty("User-Agent", "DungeonsGuide/4.0");
+ urlConnection.setConnectTimeout(1000);
+ urlConnection.setReadTimeout(3000);
+ urlConnection.setRequestMethod("GET");
+ urlConnection.setDoInput(true);
+
+ try (W3CBackedParser parser = new W3CBackedParser(urlConnection.getInputStream())) {
+ ParserElement element = parser.getRootNode();
+ ParsedWidgetConverter converter = DomElementRegistry.obtainConverter(element.getNodeName());
+ Widget w = converter.convert(this, element);
+ policy.setValue(w);
+ policyVisibility.setValue("loaded");
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ policyVisibility.setValue("failed");
+ }
+ });
+ }
+}