diff options
Diffstat (limited to 'src/main/java/io')
10 files changed, 223 insertions, 52 deletions
diff --git a/src/main/java/io/polyfrost/oneconfig/gui/Window.java b/src/main/java/io/polyfrost/oneconfig/gui/Window.java index 7671578..62576a9 100644 --- a/src/main/java/io/polyfrost/oneconfig/gui/Window.java +++ b/src/main/java/io/polyfrost/oneconfig/gui/Window.java @@ -1,6 +1,7 @@ package io.polyfrost.oneconfig.gui; import io.polyfrost.oneconfig.gui.elements.OCBlock; +import io.polyfrost.oneconfig.gui.elements.OCButton; import io.polyfrost.oneconfig.gui.elements.OCStoreBlock; import io.polyfrost.oneconfig.themes.Theme; import io.polyfrost.oneconfig.themes.textures.ThemeElement; @@ -8,13 +9,9 @@ import io.polyfrost.oneconfig.themes.Themes; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.ScaledResolution; -import net.minecraft.client.renderer.texture.DynamicTexture; import net.minecraft.util.ResourceLocation; -import javax.imageio.ImageIO; import java.awt.*; -import java.io.IOException; -import java.net.URL; import static io.polyfrost.oneconfig.renderer.Renderer.clamp; import static io.polyfrost.oneconfig.renderer.Renderer.easeOut; @@ -24,9 +21,13 @@ public class Window extends GuiScreen { public static Window currentWindow; private final Theme t = Themes.getActiveTheme(); private final int guiScaleToRestore; + long secondCounter = System.currentTimeMillis(); + long prevTime = System.currentTimeMillis(); + int frames = 0; OCBlock block = new OCBlock(-1, 100, 200); ResourceLocation example = new ResourceLocation("oneconfig", "textures/hudsettings.png"); OCStoreBlock storeBlock = new OCStoreBlock("OneConfig Theme", "OneConfig default theme with the default look you love.", example, new Color(27,27,27,255).getRGB()); + OCButton button = new OCButton("Mod Settings","Configure all supported mods",ThemeElement.MOD_SETTINGS,false,758, 144); public static ScaledResolution resolution = new ScaledResolution(Minecraft.getMinecraft()); public Window() { @@ -46,6 +47,19 @@ public class Window extends GuiScreen { currentProgress = clamp(easeOut(currentProgress, 1f)); int alphaVal = (int) (50 * currentProgress); drawGradientRect(0, 0, super.width, super.height, new Color(80, 80, 80, alphaVal).getRGB(), new Color(80, 80, 80, alphaVal + 10).getRGB()); + long secondDelta = System.currentTimeMillis() - secondCounter; + long deltaTime = System.currentTimeMillis() - prevTime; + //if(deltaTime >= 15) { + // prevTime = System.currentTimeMillis(); + // frames++; + // drawWindow(); + //} + if(secondDelta >= 1000) { + secondCounter = System.currentTimeMillis(); + //System.out.println(frames + "FPS"); + //Minecraft.getMinecraft().thePlayer.sendChatMessage(frames + "FPS"); + frames = 0; + } drawWindow(); } @@ -61,14 +75,14 @@ public class Window extends GuiScreen { //Gui.drawRect(left - 1, top - 1, right + 1, bottom + 1, testingColor.getRGB()); //new Color(16, 17, 19, 255).getRGB() t.getTextureManager().draw(ThemeElement.BACKGROUND, left, top, right, bottom); - t.getTextureManager().draw(ThemeElement.BUTTON_OFF, left + 480, top + 40, 640, 48); + //t.getTextureManager().draw(ThemeElement.BUTTON_OFF, left + 480, top + 40, 640, 48); t.getTextureManager().draw(ThemeElement.SEARCH, left + 504, top + 48, 32, 32); t.getFont().drawString("Search all of OneConfig", left + 548, top + 48, 1.1f, 1f, new Color(242,242,242,255).getRGB()); - t.getTextureManager().draw(ThemeElement.BUTTON_OFF, left + 1504, top + 32, 64, 64); - t.getTextureManager().draw(ThemeElement.BUTTON_OFF, left + 1424, top + 32, 64, 64); - t.getTextureManager().draw(ThemeElement.BUTTON_OFF, left + 1344, top + 32, 64, 64); - block.draw(200, 300); - storeBlock.draw(500,300); + //t.getTextureManager().draw(ThemeElement.BUTTON_OFF, left + 1504, top + 32, 64, 64); + //t.getTextureManager().draw(ThemeElement.BUTTON_OFF, left + 1424, top + 32, 64, 64); + //t.getTextureManager().draw(ThemeElement.BUTTON_OFF, left + 1344, top + 32, 64, 64); + //block.draw(200, 300); + button.draw(500,300); //t.getTextureManager().draw(ThemeElement.CLOSE, left + 1504, top + 32, 64, 64); //t.getTextureManager().draw(ThemeElement.BUTTON_OFF, left + 100, top + 100, 296, 64); //t.getTextureManager().draw(ThemeElement.CLOSE); diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/OCBlock.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/OCBlock.java index fcce48b..180215c 100644 --- a/src/main/java/io/polyfrost/oneconfig/gui/elements/OCBlock.java +++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/OCBlock.java @@ -2,11 +2,10 @@ package io.polyfrost.oneconfig.gui.elements; import io.polyfrost.oneconfig.renderer.Renderer; import io.polyfrost.oneconfig.themes.Theme; -import io.polyfrost.oneconfig.themes.textures.ThemeElement; import io.polyfrost.oneconfig.themes.Themes; +import io.polyfrost.oneconfig.themes.textures.ThemeElement; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; -import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.renderer.GlStateManager; import org.jetbrains.annotations.NotNull; import org.lwjgl.input.Keyboard; @@ -16,6 +15,9 @@ import java.awt.*; import static io.polyfrost.oneconfig.gui.Window.resolution; +/** + * Default simple block for all the GUI elements. If you are making custom ones, your class should extend this one. + */ @SuppressWarnings("unused") public class OCBlock { public static final Theme theme = Themes.getActiveTheme(); @@ -23,13 +25,26 @@ public class OCBlock { private Color color; private String text; private final boolean bold; - protected int width, height; + /** + * Width of the element in pixels. + */ + public int width; + /** + * Height of the element in pixels. + */ + public int height; private ThemeElement element; private boolean clicked = false; private boolean rightClicked = false; private int mouseX, mouseY; private boolean hovered; - private int x, y; + + /** + * Create a basic element with nothing. Used for extended classes. + */ + public OCBlock(int width, int height) { + this(null, false, -1, width, height); + } /** * Create a new basic element. @@ -82,8 +97,7 @@ public class OCBlock { * Draw the element at the specified coordinates. */ public void draw(int x, int y) { - this.x = x; - this.y = y; + update(x, y); if(element != null) { Gui.drawRect(x, y, x + width, y + height, color.getRGB()); GlStateManager.color(color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f, color.getAlpha() / 255f); @@ -106,8 +120,7 @@ public class OCBlock { /** * Update this elements click, key and hover status. Call this method at the end of your 'draw' function, if overridden. */ - public void update() { - resolution = new ScaledResolution(mc); + public void update(int x, int y) { int mouseX = Mouse.getX() / resolution.getScaleFactor(); int mouseY = Math.abs((Mouse.getY() / resolution.getScaleFactor()) - resolution.getScaledHeight()); hovered = mouseX > x && mouseY > y && mouseX < x + width && mouseY < y + height; @@ -124,6 +137,7 @@ public class OCBlock { rightClicked = Mouse.isButtonDown(1); onKeyPress(Keyboard.getEventKey()); } + if(!hovered && clicked) clicked = false; } /** diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/OCButton.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/OCButton.java new file mode 100644 index 0000000..2ffeaf7 --- /dev/null +++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/OCButton.java @@ -0,0 +1,105 @@ +package io.polyfrost.oneconfig.gui.elements; + +import io.polyfrost.oneconfig.renderer.Renderer; +import io.polyfrost.oneconfig.themes.textures.ThemeElement; +import net.minecraft.client.renderer.GlStateManager; +import org.jetbrains.annotations.NotNull; + +import java.awt.*; + +public class OCButton extends OCBlock { + private float percentHoveredRed = 0f; + private float percentHoveredGreen = 0f; + private float percentHoveredBlue = 0f; + private float percentHoveredAlpha = 0f; + private float percentDescription = 0f; + private final Color elementColor = theme.getElementColor(); + private final Color hoverColor = theme.getHoverColor(); + private ThemeElement element; + private boolean alwaysShowDesc = true; + private String title, description; + + /** + * Create an empty button. + */ + public OCButton(int width, int height) { + super(width, height); + } + + /** + * Create a new button with the specified texture. + */ + public OCButton(ThemeElement element) { + super(element.size + 2, element.size + 2); + this.element = element; + } + + public OCButton(@NotNull String title, @NotNull String description, ThemeElement icon, boolean alwaysShowDesc) { + super(icon.size + theme.getBoldFont().getWidth(title) + 20, icon.size + 10); + this.element = icon; + this.title = title; + this.description = description; + this.alwaysShowDesc = alwaysShowDesc; + } + + + public OCButton(@NotNull String title, @NotNull String description, ThemeElement icon, boolean alwaysShowDesc, int width, int height) { + super(width, height); + this.element = icon; + this.title = title; + this.description = description; + this.alwaysShowDesc = alwaysShowDesc; + } + + public void draw(int x, int y) { + super.update(x, y); + + percentHoveredRed = smooth(percentHoveredRed, elementColor.getRed() / 255f, hoverColor.getRed() / 255f); + percentHoveredGreen = smooth(percentHoveredGreen, elementColor.getGreen() / 255f, hoverColor.getGreen() / 255f); + percentHoveredBlue = smooth(percentHoveredBlue, elementColor.getBlue() / 255f, hoverColor.getBlue() / 255f); + percentHoveredAlpha = smooth(percentHoveredAlpha, elementColor.getAlpha() / 255f, hoverColor.getAlpha() / 255f); + if(!alwaysShowDesc) { + percentDescription = Renderer.clamp(Renderer.easeOut(percentDescription, isHovered() ? 1f : 0f)); + } + GlStateManager.color(percentHoveredRed, percentHoveredGreen, percentHoveredBlue, percentHoveredAlpha); + if(isClicked()) { + Renderer.setGlColor(theme.getClickColor()); + } + + theme.getTextureManager().draw(ThemeElement.BUTTON, x, y, width, height); + if(element != null) { + GlStateManager.color(1f,1f,1f, isClicked() ? 0.6f : 1f); + theme.getTextureManager().draw(element, x + 19, y + 8, element.size, element.size); + if(title != null) { + if(alwaysShowDesc) { + theme.getBoldFont().drawString(title, x + element.size + 25, y + 30, 1.2f, 1.2f, isClicked() ? theme.getTextColor().darker().getRGB() : theme.getTextColor().getRGB()); + theme.getFont().drawString(description, x + element.size + 25, y + theme.getBoldFont().getHeight() + 37, 1.2f, 1.2f, isClicked() ? theme.getAccentTextColor().darker().getRGB() : theme.getAccentTextColor().getRGB()); + } else { + int titleY = y + 48; + titleY -= (int) (percentDescription * 18); + Color targetColor = theme.getAccentTextColor(); + Color currentColor = isClicked() ? targetColor.darker() : new Color(targetColor.getRed(), targetColor.getGreen(), targetColor.getBlue(), (int) (targetColor.getAlpha() * percentDescription)); + theme.getFont().drawString(description, x + element.size + 25, y + theme.getBoldFont().getHeight() + 37, 1.2f, 1.2f, currentColor.getRGB()); + theme.getBoldFont().drawString(title, x + element.size + 25, titleY, 1.2f, 1.2f, isClicked() ? theme.getTextColor().darker().getRGB() : theme.getTextColor().getRGB()); + } + } + } + } + + + private float smooth(float current, float min, float max) { + current = Renderer.easeOut(current, isHovered() ? 1f : 0f); + if(current <= min) { + current = min; + } + + if(current >= max) { + current = max; + } + return current; + } + + public void onHover() { + + } +} diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/OCStoreBlock.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/OCStoreBlock.java index 7a87f77..3d23b2f 100644 --- a/src/main/java/io/polyfrost/oneconfig/gui/elements/OCStoreBlock.java +++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/OCStoreBlock.java @@ -1,6 +1,8 @@ package io.polyfrost.oneconfig.gui.elements; import io.polyfrost.oneconfig.renderer.Renderer; +import io.polyfrost.oneconfig.themes.textures.ThemeElement; +import net.minecraft.client.gui.Gui; import net.minecraft.util.ResourceLocation; import java.awt.*; @@ -11,7 +13,7 @@ public class OCStoreBlock extends OCBlock { private Color color; public OCStoreBlock(String title, String description, ResourceLocation image, int color) { - super(color, 200, 400); + super(color, 300, 400); this.color = Renderer.getColorFromInt(color); this.description = description; this.title = title; @@ -19,12 +21,13 @@ public class OCStoreBlock extends OCBlock { } public void draw(int x, int y) { - super.draw(x, y); - Renderer.drawScaledImage(image, x, y, 200, 100); - super.theme.getFont().drawSplitString("i like fish", x + 2, y + 102, 200, -1); + //super.draw(x, y); + Renderer.drawScaledImage(image, x, y, 300, 150); + //Gui.drawRect(x,y,x + 300, y + 150, -1); + theme.getBoldFont().drawSplitString(title, x + 2, y + 152, 200, -1); - super.update(); + //super.update(); } public void draw(int x, int y, int width, int height) { diff --git a/src/main/java/io/polyfrost/oneconfig/renderer/Renderer.java b/src/main/java/io/polyfrost/oneconfig/renderer/Renderer.java index 03aafdd..012fdc8 100644 --- a/src/main/java/io/polyfrost/oneconfig/renderer/Renderer.java +++ b/src/main/java/io/polyfrost/oneconfig/renderer/Renderer.java @@ -41,13 +41,8 @@ public class Renderer extends Gui { } public static void drawRegularPolygon(double x, double y, int radius, int sides, int color, double lowerAngle, double upperAngle) { - float f3 = (float) (color >> 24 & 255) / 255.0F; - float f = (float) (color >> 16 & 255) / 255.0F; - float f1 = (float) (color >> 8 & 255) / 255.0F; - float f2 = (float) (color & 255) / 255.0F; - GL11.glDisable(GL11.GL_TEXTURE_2D); - GlStateManager.color(f, f1, f2, f3); + setGlColor(color); GlStateManager.enableBlend(); GlStateManager.disableAlpha(); worldRenderer.begin(GL11.GL_POLYGON, DefaultVertexFormats.POSITION); @@ -121,4 +116,22 @@ public class Renderer extends Gui { return new Color(f, f1, f2, f3); } + /** + * Set GL color from the given Color variable. + */ + public static void setGlColor(Color color) { + GlStateManager.color(color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f, color.getAlpha() / 255f); + } + + /** + * Set GL color from the given color as an Integer. + */ + public static void setGlColor(int color) { + float f1 = (float) (color >> 8 & 255) / 255.0F; + float f = (float) (color >> 16 & 255) / 255.0F; + float f2 = (float) (color & 255) / 255.0F; + float f3 = (float) (color >> 24 & 255) / 255.0F; + GlStateManager.color(f,f1,f2,f3); + } + } diff --git a/src/main/java/io/polyfrost/oneconfig/renderer/TrueTypeFont.java b/src/main/java/io/polyfrost/oneconfig/renderer/TrueTypeFont.java index 01901eb..9a51e68 100644 --- a/src/main/java/io/polyfrost/oneconfig/renderer/TrueTypeFont.java +++ b/src/main/java/io/polyfrost/oneconfig/renderer/TrueTypeFont.java @@ -310,10 +310,6 @@ public class TrueTypeFont { public void drawString(String text, float x, float y, float scaleX, float scaleY, int format, int color) { - float f = (float) (color >> 16 & 255) / 255.0F; - float f1 = (float) (color >> 8 & 255) / 255.0F; - float f3 = (float) (color >> 24 & 255) / 255.0F; - float f2 = (float) (color & 255) / 255.0F; int startIndex = 0; int endIndex = text.length() - 1; IntObject intObject; @@ -360,7 +356,7 @@ public class TrueTypeFont { GlStateManager.enableAlpha(); GlStateManager.enableBlend(); - GlStateManager.color(f, f1, f2, f3); + Renderer.setGlColor(color); while (i >= startIndex && i <= endIndex) { charCurrent = text.charAt(i); if (charCurrent < 256) { diff --git a/src/main/java/io/polyfrost/oneconfig/themes/Theme.java b/src/main/java/io/polyfrost/oneconfig/themes/Theme.java index 63450da..5f2bfac 100644 --- a/src/main/java/io/polyfrost/oneconfig/themes/Theme.java +++ b/src/main/java/io/polyfrost/oneconfig/themes/Theme.java @@ -22,6 +22,7 @@ public class Theme extends FileResourcePack { private final File themeFile; private final File themeConfigFile; private static final Minecraft mc = Minecraft.getMinecraft(); + private final long loadedTime = System.currentTimeMillis(); private final JsonObject packMetadata; private final JsonObject packConfig; private final Color accentColor; @@ -40,6 +41,7 @@ public class Theme extends FileResourcePack { private final TextureManager manager; private final TrueTypeFont boldFont; private final TrueTypeFont normalFont; + private boolean ready; @@ -50,6 +52,7 @@ public class Theme extends FileResourcePack { */ protected Theme(File themePack) throws IOException { super(themePack); + ready = false; long start = System.nanoTime(); themeFile = themePack; themeConfigFile = new File(themeFile.getPath() + ".json"); @@ -110,6 +113,7 @@ public class Theme extends FileResourcePack { Themes.themeLog.warn("Theme was made for a different version of OneConfig! This may cause issues in the GUI."); } Themes.themeLog.info("Successfully loaded theme in " + ((float) (System.nanoTime() - start)) / 1000000f + "ms"); + ready = true; } @@ -290,4 +294,17 @@ public class Theme extends FileResourcePack { return boldFont; } + /** + * Get the time this theme was loaded. (used for debugging) + */ + public long getLoadedTime() { + return loadedTime; + } + + /** + * Check if the theme is fully loaded or not. + */ + public boolean isReady() { + return ready; + } } diff --git a/src/main/java/io/polyfrost/oneconfig/themes/Themes.java b/src/main/java/io/polyfrost/oneconfig/themes/Themes.java index 38e5df7..240c97d 100644 --- a/src/main/java/io/polyfrost/oneconfig/themes/Themes.java +++ b/src/main/java/io/polyfrost/oneconfig/themes/Themes.java @@ -45,4 +45,9 @@ public class Themes { // TODO restart gui } + + public String toString() { + return "OneConfig Theme {loaded=" + activeTheme.getLoadedTime() + ", name=" + activeTheme.getName() + ", desc=" + activeTheme.getDescription() + ", ready=" + activeTheme.isReady() + "}"; + } + } diff --git a/src/main/java/io/polyfrost/oneconfig/themes/textures/TextureManager.java b/src/main/java/io/polyfrost/oneconfig/themes/textures/TextureManager.java index 5825fb1..9b583ef 100644 --- a/src/main/java/io/polyfrost/oneconfig/themes/textures/TextureManager.java +++ b/src/main/java/io/polyfrost/oneconfig/themes/textures/TextureManager.java @@ -8,6 +8,7 @@ import net.minecraft.client.renderer.texture.DynamicTexture; import net.minecraft.crash.CrashReport; import net.minecraft.util.ReportedException; import net.minecraft.util.ResourceLocation; +import org.jetbrains.annotations.NotNull; import javax.imageio.ImageIO; import java.awt.image.BufferedImage; @@ -15,6 +16,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; +import static io.polyfrost.oneconfig.themes.Themes.activeTheme; import static io.polyfrost.oneconfig.themes.Themes.themeLog; public class TextureManager { @@ -73,26 +75,28 @@ public class TextureManager { * @param width width of the image * @param height height of the image */ - public void draw(ThemeElement element, int x, int y, int width, int height) { - GlStateManager.enableBlend(); - GlStateManager.color(1f, 1f, 1f, 1f); - ResourceLocation location = resources.get(element.ordinal()); - mc.getTextureManager().bindTexture(location); - try { - if(!tickableTextures.isEmpty()) { - for (TickableTexture texture : tickableTextures) { - if (texture.getElement().equals(element)) { - texture.draw(x, y); - } else { - Gui.drawScaledCustomSizeModalRect(x, y, 0, 0, width, height, width, height, width, height); + public void draw(@NotNull ThemeElement element, int x, int y, int width, int height) { + if (activeTheme.isReady()) { + ResourceLocation location = resources.get(element.ordinal()); + mc.getTextureManager().bindTexture(location); + GlStateManager.enableBlend(); + try { + if (!tickableTextures.isEmpty()) { + for (TickableTexture texture : tickableTextures) { + if (texture.getElement().equals(element)) { + texture.draw(x, y); + } else { + Gui.drawScaledCustomSizeModalRect(x, y, 0, 0, width, height, width, height, width, height); + } } + } else { + Gui.drawScaledCustomSizeModalRect(x, y, 0, 0, width, height, width, height, width, height); } - } else { - Gui.drawScaledCustomSizeModalRect(x, y, 0, 0, width, height, width, height, width, height); + GlStateManager.disableBlend(); + GlStateManager.color(1f, 1f, 1f, 1f); + } catch (Exception e) { + themeLog.error("Error occurred drawing texture " + element.name() + ", is theme invalid?", e); } - GlStateManager.disableBlend(); - } catch (Exception e) { - themeLog.error("Error occurred drawing texture " + element.name() + ", is theme invalid?", e); } } } diff --git a/src/main/java/io/polyfrost/oneconfig/themes/textures/ThemeElement.java b/src/main/java/io/polyfrost/oneconfig/themes/textures/ThemeElement.java index 096b2aa..2ab3bc9 100644 --- a/src/main/java/io/polyfrost/oneconfig/themes/textures/ThemeElement.java +++ b/src/main/java/io/polyfrost/oneconfig/themes/textures/ThemeElement.java @@ -31,7 +31,7 @@ public enum ThemeElement { LOGO("textures/logos/logo.png", 128), SMALL_LOGO("textures/logos/logo_small.png", 64), - BUTTON_OFF("textures/window/button_off.png", 758), + BUTTON("textures/window/button.png", 758), BUTTON_HOVER("textures/window/button_hover.png", 758), BUTTON_CLICK("textures/window/button_click.png", 758), |