From 7cf35168284de8cf5fd3af50b4a6a00cf4e28999 Mon Sep 17 00:00:00 2001 From: ThisIsALegitUsername Date: Tue, 21 Feb 2023 14:18:39 +0000 Subject: [PATCH] begin work on cape chooser --- .../java/dev/resent/cape/CapeManager.java | 39 +++++++++++++++++++ src/main/java/dev/resent/cape/CapeUi.java | 32 +++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 src/main/java/dev/resent/cape/CapeManager.java create mode 100644 src/main/java/dev/resent/cape/CapeUi.java diff --git a/src/main/java/dev/resent/cape/CapeManager.java b/src/main/java/dev/resent/cape/CapeManager.java new file mode 100644 index 00000000..0a2a2f7d --- /dev/null +++ b/src/main/java/dev/resent/cape/CapeManager.java @@ -0,0 +1,39 @@ +package dev.resent.cape; + +import net.lax1dude.eaglercraft.v1_8.EagRuntime; +import net.lax1dude.eaglercraft.v1_8.internal.FileChooserResult; +import net.lax1dude.eaglercraft.v1_8.opengl.ImageData; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.texture.DynamicTexture; +import net.minecraft.util.ResourceLocation; + +public class CapeManager { + + public static void displayChooser(){ + EagRuntime.displayFileChooser("image/png", "png"); + } + + public static ResourceLocation capeLocation; + + public static void loadCape(){ + CapeManager.free(); + if (EagRuntime.fileChooserHasResult()) { + FileChooserResult result = EagRuntime.getFileChooserResult(); + if (result != null) { + ImageData loadedCape = ImageData.loadImageFile(result.fileData); + if(loadedCape != null){ + capeLocation = Minecraft.getMinecraft().getTextureManager().getDynamicTextureLocation("uploadedcape", new DynamicTexture(loadedCape)); + Minecraft.getMinecraft().getTextureManager().bindTexture(capeLocation); + } else { + EagRuntime.showPopup("The selected file '" + result.fileName + "' is not a PNG file!"); + } + } + } + } + + public static void free(){ + Minecraft.getMinecraft().getTextureManager().deleteTexture(capeLocation); + capeLocation = null; + } + +} diff --git a/src/main/java/dev/resent/cape/CapeUi.java b/src/main/java/dev/resent/cape/CapeUi.java new file mode 100644 index 00000000..354d4d68 --- /dev/null +++ b/src/main/java/dev/resent/cape/CapeUi.java @@ -0,0 +1,32 @@ +package dev.resent.cape; + +import dev.resent.client.Resent; +import dev.resent.module.base.RenderMod; +import dev.resent.ui.ClickGUI; +import net.lax1dude.eaglercraft.v1_8.Keyboard; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.GuiScreen; + +public class CapeUi extends GuiScreen { + + public void initGui() { + this.buttonList.add(new GuiButton(200, this.width / 2 - 100, this.height / 6 + 148, "Back")); + } + + public void onGuiClosed() { + Keyboard.enableRepeatEvents(false); + mc.gameSettings.saveOptions(); + } + + public void drawScreen(int mx, int my, float par3) { + this.drawDefaultBackground(); + Resent.INSTANCE.modManager.modules.stream().filter(m -> m.isEnabled() && m instanceof RenderMod).forEach(rm -> ((RenderMod)rm).renderLayout(mx, my)); + super.drawScreen(mx, my, par3); + } + + protected void actionPerformed(GuiButton par1GuiButton) { + if (par1GuiButton.id == 200) { + this.mc.displayGuiScreen(new ClickGUI()); + } + } +}