diff options
author | nextdaydelivery <12willettsh@gmail.com> | 2022-02-12 16:29:20 +0000 |
---|---|---|
committer | nextdaydelivery <12willettsh@gmail.com> | 2022-02-12 16:29:20 +0000 |
commit | 56b75c981609a89639dfd3860ca890af64d2bfbe (patch) | |
tree | 1d401c3e2a3d857df79e35bbf9e024a1eba3f10a /src/main | |
parent | 8ad9f2d1e21f57aa43ad2be59796ab0a26b3c099 (diff) | |
download | OneConfig-56b75c981609a89639dfd3860ca890af64d2bfbe.tar.gz OneConfig-56b75c981609a89639dfd3860ca890af64d2bfbe.tar.bz2 OneConfig-56b75c981609a89639dfd3860ca890af64d2bfbe.zip |
finish theme stuff (takes 9ms btw)
Diffstat (limited to 'src/main')
4 files changed, 127 insertions, 27 deletions
diff --git a/src/main/java/io/polyfrost/oneconfig/OneConfig.java b/src/main/java/io/polyfrost/oneconfig/OneConfig.java index a025984..a07176e 100644 --- a/src/main/java/io/polyfrost/oneconfig/OneConfig.java +++ b/src/main/java/io/polyfrost/oneconfig/OneConfig.java @@ -2,6 +2,7 @@ package io.polyfrost.oneconfig; import io.polyfrost.oneconfig.command.OneConfigCommand; import io.polyfrost.oneconfig.test.TestConfig; +import io.polyfrost.oneconfig.themes.Themes; import net.minecraft.client.Minecraft; import net.minecraftforge.client.ClientCommandHandler; import net.minecraftforge.common.MinecraftForge; @@ -30,5 +31,6 @@ public class OneConfig { public void onFMLInitialization(FMLInitializationEvent event) { ClientCommandHandler.instance.registerCommand(new OneConfigCommand()); MinecraftForge.EVENT_BUS.register(this); + Themes.openTheme(new File("C:\\Users\\Harry\\Documents\\Coding\\Minecraft\\Forge1.8.9\\OneConfig\\run\\OneConfig\\Themes\\one.zip")); } } diff --git a/src/main/java/io/polyfrost/oneconfig/command/OneConfigCommand.java b/src/main/java/io/polyfrost/oneconfig/command/OneConfigCommand.java index d462c5e..0b42795 100644 --- a/src/main/java/io/polyfrost/oneconfig/command/OneConfigCommand.java +++ b/src/main/java/io/polyfrost/oneconfig/command/OneConfigCommand.java @@ -44,8 +44,8 @@ public class OneConfigCommand implements ICommand { @Override public void processCommand(ICommandSender sender, String[] args) throws CommandException { new TickDelay(() -> mc.displayGuiScreen(new Window()), 1); - if(args != null) { - mc.thePlayer.addChatMessage(new ChatComponentText("hi")); + if(args.length != 0) { + mc.thePlayer.addChatMessage(new ChatComponentText("reloading theme!")); Themes.openTheme(new File("C:\\Users\\Harry\\Documents\\Coding\\Minecraft\\Forge1.8.9\\OneConfig\\run\\OneConfig\\Themes\\one.zip")); } } diff --git a/src/main/java/io/polyfrost/oneconfig/gui/Window.java b/src/main/java/io/polyfrost/oneconfig/gui/Window.java index c15356c..5ef880b 100644 --- a/src/main/java/io/polyfrost/oneconfig/gui/Window.java +++ b/src/main/java/io/polyfrost/oneconfig/gui/Window.java @@ -50,7 +50,7 @@ public class Window extends GuiScreen { Gui.drawRect(left, top + 100, right, top + 101, testingColor.getRGB()); //ResourceLocation location = mc.getRenderManager().renderEngine.getDynamicTextureLocation("oneconfig",new DynamicTexture(ImageIO.read(t.getResource("assets/textures/icons/hudsettings128.png")))); - Renderer.drawScaledImage(t.getIcons(), left + 10, top + 10, 128, 1152); + Renderer.drawScaledImage(t.getLargeIconAtlas(), left + 10, top + 10, 128, 1152); } public static Window getWindow() { diff --git a/src/main/java/io/polyfrost/oneconfig/themes/Theme.java b/src/main/java/io/polyfrost/oneconfig/themes/Theme.java index a9b31a9..cc88e4a 100644 --- a/src/main/java/io/polyfrost/oneconfig/themes/Theme.java +++ b/src/main/java/io/polyfrost/oneconfig/themes/Theme.java @@ -7,6 +7,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.texture.DynamicTexture; import net.minecraft.client.resources.FileResourcePack; import net.minecraft.util.ResourceLocation; +import org.jetbrains.annotations.NotNull; import javax.imageio.ImageIO; import java.awt.*; @@ -36,6 +37,12 @@ public class Theme extends FileResourcePack { private final String title; private final int version; private final ResourceLocation iconsLoc; + private final ResourceLocation modIconsLoc; + private final ResourceLocation smallIconsLoc; + private final ResourceLocation logoLoc; + private final ResourceLocation logoLocSmall; + + /** * Create a new theme instance for the window. @@ -44,6 +51,7 @@ public class Theme extends FileResourcePack { */ protected Theme(File themePack) throws IOException { super(themePack); + long start = System.nanoTime(); themeFile = themePack; themeConfigFile = new File(themeFile.getPath() + ".json"); packMetadata = new JsonParser().parse(new InputStreamReader(getInputStreamByName("pack.json"))).getAsJsonObject(); @@ -81,7 +89,13 @@ public class Theme extends FileResourcePack { this.description = description; this.version = version; - iconsLoc = createIconAtlas(); + iconsLoc = createLargeIconAtlas(); + smallIconsLoc = createSmallIconAtlas(); + modIconsLoc = createModIconsAtlas(); + logoLoc = getLocationFromName("textures/logos/logo.png"); + logoLocSmall = getLocationFromName("textures/logos/logo_small.png"); + Themes.themeLog.info("Successfully loaded theme and created atlases in " + ((float) (System.nanoTime() - start)) / 1000000f + "ms"); + } /** @@ -102,19 +116,12 @@ public class Theme extends FileResourcePack { } - // TIME CALC - // long start = System.nanoTime(); - // System.out.println(((float) (System.nanoTime() - start)) / 1000000f + "ms"); - /** * Create the large icon atlas from this theme. */ - private ResourceLocation createIconAtlas() { // TODO finish for all atlases + private ResourceLocation createLargeIconAtlas() { try { List<BufferedImage> icons = new ArrayList<>(); - BufferedImage out = new BufferedImage(128, 1152, BufferedImage.TYPE_INT_ARGB); - Graphics2D graphics2D = out.createGraphics(); - int i = 0; icons.add(ImageIO.read(getResource("textures/icons/discord.png"))); icons.add(ImageIO.read(getResource("textures/icons/docs.png"))); icons.add(ImageIO.read(getResource("textures/icons/feedback.png"))); @@ -124,18 +131,83 @@ public class Theme extends FileResourcePack { icons.add(ImageIO.read(getResource("textures/icons/store.png"))); icons.add(ImageIO.read(getResource("textures/icons/themes.png"))); icons.add(ImageIO.read(getResource("textures/icons/update.png"))); - for (BufferedImage img : icons) { - graphics2D.drawImage(img, null, 0, i); - i += 128; - } - graphics2D.dispose(); - return mc.getTextureManager().getDynamicTextureLocation("OneConfigIconAtlas", new DynamicTexture(out)); + return createAtlasFromList(icons, 128); } catch (Exception e) { - Themes.themeLog.error("Failed to create large icon atlas", e); + Themes.themeLog.error("Failed to create large icon atlas, is pack invalid?", e); return null; } } + /** + * Create the small icon atlas for this theme. + */ + private ResourceLocation createSmallIconAtlas() { + try { + List<BufferedImage> icons = new ArrayList<>(); + icons.add(ImageIO.read(getResource("textures/smallicons/backarrow.png"))); + icons.add(ImageIO.read(getResource("textures/smallicons/close.png"))); + icons.add(ImageIO.read(getResource("textures/smallicons/forward.png"))); + icons.add(ImageIO.read(getResource("textures/smallicons/home.png"))); + icons.add(ImageIO.read(getResource("textures/smallicons/magnify.png"))); + icons.add(ImageIO.read(getResource("textures/smallicons/minimize.png"))); + icons.add(ImageIO.read(getResource("textures/smallicons/search.png"))); + return createAtlasFromList(icons, 32); + } catch (Exception e) { + Themes.themeLog.error("Failed to create small icon atlas, is pack invalid?", e); + return null; + } + } + + /** + * Create mod icon atlas for this theme. + */ + private ResourceLocation createModIconsAtlas() { + try { + List<BufferedImage> icons = new ArrayList<>(); + icons.add(ImageIO.read(getResource("textures/mod/allmods.png"))); + icons.add(ImageIO.read(getResource("textures/mod/hudmods.png"))); + icons.add(ImageIO.read(getResource("textures/mod/hypixel.png"))); + icons.add(ImageIO.read(getResource("textures/mod/performance.png"))); + icons.add(ImageIO.read(getResource("textures/mod/pvp.png"))); + icons.add(ImageIO.read(getResource("textures/mod/qolmods.png"))); + icons.add(ImageIO.read(getResource("textures/mod/skyblock.png"))); + icons.add(ImageIO.read(getResource("textures/mod/utilities.png"))); + return createAtlasFromList(icons, 32); + } catch (Exception e) { + Themes.themeLog.error("Failed to create mod icon atlas, is pack invalid?", e); + return null; + } + } + + + /** + * Create a texture atlas from the given list of images, vertically stacked. + * @param images List of BufferedImages to use + * @param imageSize image size in pixels (note: images must be square) + * @return ResourceLocation of the atlas + */ + public static ResourceLocation createAtlasFromList(@NotNull List<BufferedImage> images, int imageSize) { + BufferedImage out = new BufferedImage(imageSize, (images.size() * imageSize), BufferedImage.TYPE_INT_ARGB); + Graphics2D graphics2D = out.createGraphics(); + int i = 0; + for (BufferedImage img : images) { + graphics2D.drawImage(img, null, 0, i); + i += imageSize; + } + graphics2D.dispose(); + return mc.getTextureManager().getDynamicTextureLocation(String.valueOf(i), new DynamicTexture(out)); + } + + + /** + * get a ResourceLocation of an image in the current theme. + * @param name path of the resource (e.g. textures/logos/logo.png) + * @throws IOException if the item cannot be located or pack is corrupt. + */ + public ResourceLocation getLocationFromName(String name) throws IOException { + return mc.getTextureManager().getDynamicTextureLocation(name, new DynamicTexture(ImageIO.read(getInputStreamByName(name)))); + } + /** @@ -235,7 +307,6 @@ public class Theme extends FileResourcePack { */ public String getName() { return title; - } /** @@ -252,13 +323,6 @@ public class Theme extends FileResourcePack { } /** - * Get the large icon atlas. - */ - public ResourceLocation getIcons() { - return iconsLoc; - } - - /** * Get the pack's version. Not used yet, but will be when more features are added for theme compatability. */ public int getVersion() { @@ -272,5 +336,39 @@ public class Theme extends FileResourcePack { return themeFile; } + /** + * Get the large icon atlas. + */ + public ResourceLocation getLargeIconAtlas() { + return iconsLoc; + } + + /** + * Get the small icon atlas. + */ + public ResourceLocation getSmallIconAtlas() { + return smallIconsLoc; + } + + /** + * Get the mod icon atlas. + */ + public ResourceLocation getModIconsAtlas() { + return modIconsLoc; + } + + /** + * Get the logo for OneConfig as specified by this theme. + */ + public ResourceLocation getOneConfigLogo() { + return logoLoc; + } + + /** + * Get the small logo for OneConfig as specified by this theme. + */ + public ResourceLocation getSmallOneConfigLogo() { + return logoLocSmall; + } } |