diff options
author | syeyoung <cyoung06@naver.com> | 2022-12-15 16:05:54 +0900 |
---|---|---|
committer | syeyoung <cyoung06@naver.com> | 2022-12-15 16:05:54 +0900 |
commit | ecc627800828857a1e617d1135ca37b08b4dc24c (patch) | |
tree | b7c67ff2540102dd497326df0e29d7f01959b9bd /loader/src/main/java/kr | |
parent | bf56c97637e14df058ac52f270af530b85574be0 (diff) | |
download | Skyblock-Dungeons-Guide-ecc627800828857a1e617d1135ca37b08b4dc24c.tar.gz Skyblock-Dungeons-Guide-ecc627800828857a1e617d1135ca37b08b4dc24c.tar.bz2 Skyblock-Dungeons-Guide-ecc627800828857a1e617d1135ca37b08b4dc24c.zip |
- call super
- loading splash
Signed-off-by: syeyoung <cyoung06@naver.com>
Diffstat (limited to 'loader/src/main/java/kr')
5 files changed, 217 insertions, 58 deletions
diff --git a/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/Main.java b/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/Main.java index 4cb4d1a2..8041f82c 100755 --- a/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/Main.java +++ b/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/Main.java @@ -24,6 +24,7 @@ import kr.syeyoung.dungeonsguide.launcher.exceptions.DungeonsGuideLoadingExcepti import kr.syeyoung.dungeonsguide.launcher.exceptions.NoSuitableLoaderFoundException; import kr.syeyoung.dungeonsguide.launcher.exceptions.NoVersionFoundException; import kr.syeyoung.dungeonsguide.launcher.exceptions.DungeonsGuideUnloadingException; +import kr.syeyoung.dungeonsguide.launcher.gui.screen.GuiChooseVersion; import kr.syeyoung.dungeonsguide.launcher.gui.screen.GuiDisplayer; import kr.syeyoung.dungeonsguide.launcher.gui.screen.GuiLoadingError; import kr.syeyoung.dungeonsguide.launcher.gui.screen.GuiUnloadingError; @@ -35,6 +36,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.resources.IReloadableResourceManager; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.config.Configuration; +import net.minecraftforge.fml.client.SplashProgress; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod.EventHandler; import net.minecraftforge.fml.common.ProgressManager; @@ -91,21 +93,7 @@ public class Main .titleColor(0xFFFF0000) .description("Click to try reloading....") .onClick(() -> { - try { - File f = new File(configDir, "loader.cfg"); - Configuration configuration = new Configuration(f); - IDGLoader idgLoader = obtainLoader(configuration); - load(idgLoader); - } catch (NoSuitableLoaderFoundException e) { - e.printStackTrace(); - GuiDisplayer.INSTANCE.displayGui(new GuiLoadingError(e)); - } catch (NoVersionFoundException e) { - e.printStackTrace(); - GuiDisplayer.INSTANCE.displayGui(new GuiLoadingError(e)); - } catch (DungeonsGuideLoadingException e) { - e.printStackTrace(); - GuiDisplayer.INSTANCE.displayGui(new GuiLoadingError(e)); - } + GuiDisplayer.INSTANCE.displayGui(new GuiChooseVersion(new RuntimeException("just unloaded"))); }) .unremovable(true) .build()); @@ -114,16 +102,19 @@ public class Main File f = new File(configDir, "loader.cfg"); Configuration configuration = new Configuration(f); IDGLoader idgLoader = obtainLoader(configuration); - load(idgLoader); - } catch (NoSuitableLoaderFoundException e) { + tryReloading(idgLoader); + } catch (NoSuitableLoaderFoundException | NoVersionFoundException e) { e.printStackTrace(); - GuiDisplayer.INSTANCE.displayGui(new GuiLoadingError(e)); - } catch (NoVersionFoundException e) { - e.printStackTrace(); - GuiDisplayer.INSTANCE.displayGui(new GuiLoadingError(e)); + GuiDisplayer.INSTANCE.displayGui(new GuiChooseVersion(e)); + } + } + + public void tryReloading(IDGLoader loader) { + SplashProgress.start(); + try { + reload(loader); } catch (DungeonsGuideLoadingException e) { e.printStackTrace(); - try { unload(); } catch (Exception e2) { @@ -131,7 +122,10 @@ public class Main GuiDisplayer.INSTANCE.displayGui(new GuiUnloadingError(e2)); } GuiDisplayer.INSTANCE.displayGui(new GuiLoadingError(e)); - + } catch (DungeonsGuideUnloadingException e) { + GuiDisplayer.INSTANCE.displayGui(new GuiUnloadingError(e)); + } finally { + SplashProgress.finish(); } } @@ -149,29 +143,7 @@ public class Main .titleColor(0xFFFF0000) .description("Click to try reloading....") .onClick(() -> { - try { - File f = new File(configDir, "loader.cfg"); - Configuration configuration = new Configuration(f); - IDGLoader idgLoader = obtainLoader(configuration); - reload(idgLoader); - } catch (NoSuitableLoaderFoundException e) { - e.printStackTrace(); - GuiDisplayer.INSTANCE.displayGui(new GuiLoadingError(e)); - } catch (NoVersionFoundException e) { - e.printStackTrace(); - GuiDisplayer.INSTANCE.displayGui(new GuiLoadingError(e)); - } catch (DungeonsGuideLoadingException e) { - e.printStackTrace(); - try { - unload(); - } catch (Exception e2) { - e2.printStackTrace(); - GuiDisplayer.INSTANCE.displayGui(new GuiUnloadingError(e2)); - } - GuiDisplayer.INSTANCE.displayGui(new GuiLoadingError(e)); - } catch (DungeonsGuideUnloadingException e) { - GuiDisplayer.INSTANCE.displayGui(new GuiUnloadingError(e)); - } + GuiDisplayer.INSTANCE.displayGui(new GuiChooseVersion(new RuntimeException("just unloaded"))); }) .unremovable(true) .build()); @@ -216,18 +188,7 @@ public class Main IDGLoader loader = reqLoader; reqLoader = null; - try { - reload(loader); - } catch (DungeonsGuideLoadingException e) { - try { - unload(); - } catch (Exception e2) { - GuiDisplayer.INSTANCE.displayGui(new GuiUnloadingError(e2)); - } - GuiDisplayer.INSTANCE.displayGui(new GuiLoadingError(e)); - } catch (DungeonsGuideUnloadingException e) { - GuiDisplayer.INSTANCE.displayGui(new GuiUnloadingError(e)); - } + tryReloading(loader); } } diff --git a/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/gui/screen/GuiChooseVersion.java b/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/gui/screen/GuiChooseVersion.java new file mode 100644 index 00000000..e4e315a0 --- /dev/null +++ b/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/gui/screen/GuiChooseVersion.java @@ -0,0 +1,195 @@ +package kr.syeyoung.dungeonsguide.launcher.gui.screen; + +import kr.syeyoung.dungeonsguide.launcher.Main; +import kr.syeyoung.dungeonsguide.launcher.branch.Update; +import kr.syeyoung.dungeonsguide.launcher.branch.UpdateBranch; +import kr.syeyoung.dungeonsguide.launcher.branch.UpdateRetrieverUtil; +import kr.syeyoung.dungeonsguide.launcher.gui.tooltip.Notification; +import kr.syeyoung.dungeonsguide.launcher.gui.tooltip.NotificationManager; +import kr.syeyoung.dungeonsguide.launcher.loader.JarLoader; +import kr.syeyoung.dungeonsguide.launcher.loader.LocalLoader; +import kr.syeyoung.dungeonsguide.launcher.loader.RemoteLoader; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.*; +import net.minecraftforge.fml.client.config.GuiCheckBox; +import net.minecraftforge.fml.common.FMLCommonHandler; + +import java.awt.*; +import java.awt.datatransfer.StringSelection; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintStream; +import java.util.Collections; +import java.util.List; +import java.util.Optional; +import java.util.UUID; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.stream.Collectors; + +public class GuiChooseVersion extends SpecialGuiScreen { + private static final ExecutorService executor = Executors.newSingleThreadExecutor(); + private Throwable cause; + + public GuiChooseVersion(Throwable cause) { + this.cause = cause; + + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + PrintStream printStream = new PrintStream(byteArrayOutputStream); + cause.printStackTrace(printStream); + this.stacktrace = byteArrayOutputStream.toString(); + + try { + fetchList(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + private void fetchList () throws IOException { + loading++; + executor.submit(() -> { + try { + branchList = UpdateRetrieverUtil.getUpdateBranches().stream() + .filter(updateBranch -> + Optional.ofNullable(updateBranch.getMetadata()) + .filter(a -> a.has("additionalMeta")) + .map(a -> a.getJSONObject("additionalMeta")) + .filter(a -> a.has("type")) + .map(a -> a.getString("type")).orElse("").equals("mod")) + .collect(Collectors.toList()); + } catch (IOException e) { + e.printStackTrace(); + } + smthUpdated = true; + loading--; + }); + } + + private void fetchUpdates(UpdateBranch branch) throws IOException { + loading++; + executor.submit(() -> { + try { + updates = UpdateRetrieverUtil.getLatestUpdates(branch.getId(), 0); + } catch (IOException e) { + e.printStackTrace(); + } + smthUpdated = true; + loading--; + }); + } + private final String stacktrace; + + private List<UpdateBranch> branchList = Collections.emptyList(); + private List<Update> updates = Collections.emptyList(); + private UpdateBranch current; + private boolean smthUpdated = false; + private int loading = 0; + + @Override + public void initGui() { + super.initGui(); + // Local version + // Jar embedded version + // Remote version + // dg gui lib....? + + ScaledResolution sr = new ScaledResolution(Minecraft.getMinecraft()); + this.buttonList.add(new GuiButton(2, 0,sr.getScaledHeight()-20 ,"Copy Error into Clipboard")); + + this.buttonList.add(new GuiButton(3, sr.getScaledWidth()/2-100,sr.getScaledHeight()-40 ,"Play Without DG")); + GuiButton button; + int tenth = sr.getScaledWidth()/10; + this.buttonList.add(button = new GuiButton(0, tenth,90 ,"Try loading Locally (classes)")); + button.enabled = this.getClass().getResourceAsStream("/kr/syeyoung/dungeonsguide/mod/DungeonsGuide.class") != null; + this.buttonList.add(button = new GuiButton(1, tenth,110 ,"Try loading Local Jar (embedded jar)")); + button.enabled = this.getClass().getResourceAsStream("/mod.jar") != null; + this.buttonList.add(button = new GuiButton(4, tenth,sr.getScaledHeight()-100 ,"Refresh Options")); + + this.buttonList.add(new GuiCheckBox(5, sr.getScaledWidth() - tenth,sr.getScaledHeight()-100 ,"Save This Loader", false)); + + int k = 0; + for (UpdateBranch updateBranch : branchList) { + this.buttonList.add(new GuiButton(10 + k++, tenth, 110 + 20 * k,"Remote Branch: "+ updateBranch.getName())); + } + + k = 0; + for (Update update : updates) { + this.buttonList.add(new GuiButton(branchList.size() + 10 + k++, tenth+210, 70+ 20 * k, update.getName())); + } + } + + @Override + protected void actionPerformed(GuiButton button) throws IOException { + super.actionPerformed(button); + if (button.id == 2) { + Toolkit.getDefaultToolkit() + .getSystemClipboard() + .setContents( + new StringSelection(stacktrace), + null + ); + + NotificationManager.INSTANCE.updateNotification(UUID.randomUUID(), Notification.builder() + .title("Successfully Copied!") + .description("") + .titleColor(0xFF00FF00) + .build()); + } else if (button.id == 0) { + dismiss(); + Main.getMain().tryReloading(new LocalLoader()); + } else if (button.id == 1) { + dismiss(); + Main.getMain().tryReloading(new JarLoader()); + } else if (button.id == 3) { + dismiss(); + } else if (button.id == 4) { + branchList = Collections.emptyList(); + updates = Collections.emptyList(); + current = null; + smthUpdated = true; + fetchList(); + } else if (button.id == 5) { + // do smt + } else if (button.id < branchList.size() + 10) { + int idx = button.id - 10; + current = branchList.get(idx); + fetchUpdates(branchList.get(idx)); + } else { + int idx = button.id - branchList.size() - 10; + Update update = updates.get(idx); + + dismiss(); + Main.getMain().tryReloading(new RemoteLoader(current.getName(),current.getId(),update.getId())); + } + } + + @Override + public void updateScreen() { + super.updateScreen(); + if (smthUpdated) { + this.buttonList.clear(); + initGui(); + smthUpdated = false; + } + } + + @Override + public void drawScreen(int mouseX, int mouseY, float partialTicks) { + super.drawBackground(1); + + ScaledResolution sr = new ScaledResolution(Minecraft.getMinecraft()); + FontRenderer fontRenderer = Minecraft.getMinecraft().fontRendererObj; + fontRenderer.drawString("Please choose a new version to load", (sr.getScaledWidth()-fontRenderer.getStringWidth("Please choose a new version to load"))/2,(int) (40),0xFFFF0000); + fontRenderer.drawString("Problem: "+cause.getMessage(), (sr.getScaledWidth()-fontRenderer.getStringWidth("Problem: "+cause.getMessage()))/2, (int) (40+fontRenderer.FONT_HEIGHT*1.5),0xFFFF0000); + + int tenth = sr.getScaledWidth() / 10; + Gui.drawRect(tenth, 90,sr.getScaledWidth()-tenth, sr.getScaledHeight()-80, 0xFF5B5B5B); + + if (loading > 0) { + fontRenderer.drawString("Loading", sr.getScaledWidth()/2, sr.getScaledHeight()/2, 0xFF000000); + } + + super.drawScreen(mouseX, mouseY, partialTicks); + } +} diff --git a/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/gui/screen/GuiLoadingError.java b/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/gui/screen/GuiLoadingError.java index b61484f1..1f3c3875 100644 --- a/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/gui/screen/GuiLoadingError.java +++ b/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/gui/screen/GuiLoadingError.java @@ -44,6 +44,7 @@ public class GuiLoadingError extends SpecialGuiScreen { @Override public void initGui() { + super.initGui(); ScaledResolution sr = new ScaledResolution(Minecraft.getMinecraft()); this.buttonList.add(new GuiButton(0, sr.getScaledWidth()/2-100,sr.getScaledHeight()-70 ,"Close Minecraft")); this.buttonList.add(new GuiButton(1, sr.getScaledWidth()/2-100,sr.getScaledHeight()-40 ,"Play Without DG")); 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 index d276b4b9..2894214c 100644 --- 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 @@ -12,6 +12,7 @@ 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); diff --git a/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/gui/screen/GuiUnloadingError.java b/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/gui/screen/GuiUnloadingError.java index dd05dec4..eb714129 100644 --- a/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/gui/screen/GuiUnloadingError.java +++ b/loader/src/main/java/kr/syeyoung/dungeonsguide/launcher/gui/screen/GuiUnloadingError.java @@ -42,6 +42,7 @@ public class GuiUnloadingError extends SpecialGuiScreen { @Override public void initGui() { + super.initGui(); ScaledResolution sr = new ScaledResolution(Minecraft.getMinecraft()); this.buttonList.add(new GuiButton(0, sr.getScaledWidth()/2-100,sr.getScaledHeight()-70 ,"Close Minecraft")); this.buttonList.add(new GuiButton(1, sr.getScaledWidth()/2-100,sr.getScaledHeight()-40 ,"Play With DG in Inconsistent State")); |