aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/io/polyfrost/oneconfig/OneConfig.java2
-rw-r--r--src/main/java/io/polyfrost/oneconfig/command/OneConfigCommand.java3
-rw-r--r--src/main/java/io/polyfrost/oneconfig/config/OneConfigConfig.java10
-rw-r--r--src/main/java/io/polyfrost/oneconfig/config/core/ConfigCore.java4
-rw-r--r--src/main/java/io/polyfrost/oneconfig/config/interfaces/Config.java12
-rw-r--r--src/main/java/io/polyfrost/oneconfig/config/interfaces/Option.java3
-rw-r--r--src/main/java/io/polyfrost/oneconfig/config/profiles/Profiles.java8
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/Window.java16
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/elements/OCBlock.java126
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/elements/OCButton.java24
-rw-r--r--src/main/java/io/polyfrost/oneconfig/gui/elements/OCStoreBlock.java11
-rw-r--r--src/main/java/io/polyfrost/oneconfig/hud/gui/HudGui.java33
-rw-r--r--src/main/java/io/polyfrost/oneconfig/hud/interfaces/BasicHud.java4
-rw-r--r--src/main/java/io/polyfrost/oneconfig/hud/interfaces/TextHud.java16
-rw-r--r--src/main/java/io/polyfrost/oneconfig/renderer/Renderer.java35
-rw-r--r--src/main/java/io/polyfrost/oneconfig/renderer/TrueTypeFont.java269
-rw-r--r--src/main/java/io/polyfrost/oneconfig/test/TestHud.java2
-rw-r--r--src/main/java/io/polyfrost/oneconfig/themes/textures/TextureManager.java19
-rw-r--r--src/main/java/io/polyfrost/oneconfig/themes/textures/TickableTexture.java9
19 files changed, 311 insertions, 295 deletions
diff --git a/src/main/java/io/polyfrost/oneconfig/OneConfig.java b/src/main/java/io/polyfrost/oneconfig/OneConfig.java
index da4a604..7f29c39 100644
--- a/src/main/java/io/polyfrost/oneconfig/OneConfig.java
+++ b/src/main/java/io/polyfrost/oneconfig/OneConfig.java
@@ -14,7 +14,7 @@ import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import java.io.File;
-@Mod(modid = "oneconfig", name = "OneConfig", version = "${version}")
+@Mod(modid = "@ID@", name = "@NAME@", version = "@VER@")
public class OneConfig {
private static final Minecraft mc = Minecraft.getMinecraft();
public static File jarFile;
diff --git a/src/main/java/io/polyfrost/oneconfig/command/OneConfigCommand.java b/src/main/java/io/polyfrost/oneconfig/command/OneConfigCommand.java
index 575fc3f..df727a0 100644
--- a/src/main/java/io/polyfrost/oneconfig/command/OneConfigCommand.java
+++ b/src/main/java/io/polyfrost/oneconfig/command/OneConfigCommand.java
@@ -39,8 +39,7 @@ public class OneConfigCommand implements ICommand {
@Override
public void processCommand(ICommandSender sender, String[] args) {
- if (args.length == 0)
- new TickDelay(() -> mc.displayGuiScreen(new Window()), 1);
+ if (args.length == 0) new TickDelay(() -> mc.displayGuiScreen(new Window()), 1);
else {
switch (args[0]) {
case "hud":
diff --git a/src/main/java/io/polyfrost/oneconfig/config/OneConfigConfig.java b/src/main/java/io/polyfrost/oneconfig/config/OneConfigConfig.java
index a518633..b46c65d 100644
--- a/src/main/java/io/polyfrost/oneconfig/config/OneConfigConfig.java
+++ b/src/main/java/io/polyfrost/oneconfig/config/OneConfigConfig.java
@@ -8,16 +8,16 @@ import java.io.*;
import java.nio.charset.StandardCharsets;
public class OneConfigConfig extends Config {
+ public static String currentProfile = "Default Profile";
+
public OneConfigConfig() {
super(null, "OneConfig.json");
}
@Override
public void init(ModData modData) {
- if (new File("OneConfig/" + configFile).exists())
- load();
- else
- save();
+ if (new File("OneConfig/" + configFile).exists()) load();
+ else save();
}
@Override
@@ -37,6 +37,4 @@ public class OneConfigConfig extends Config {
e.printStackTrace();
}
}
-
- public static String currentProfile = "Default Profile";
}
diff --git a/src/main/java/io/polyfrost/oneconfig/config/core/ConfigCore.java b/src/main/java/io/polyfrost/oneconfig/config/core/ConfigCore.java
index a66a8a0..9bb2e85 100644
--- a/src/main/java/io/polyfrost/oneconfig/config/core/ConfigCore.java
+++ b/src/main/java/io/polyfrost/oneconfig/config/core/ConfigCore.java
@@ -10,13 +10,13 @@ import java.util.HashMap;
public class ConfigCore {
public static HashMap<ModData, ArrayList<Option>> settings = new HashMap<>();
- public static void saveAll () {
+ public static void saveAll() {
for (ModData modData : settings.keySet()) {
modData.config.save();
}
}
- public static void reInitAll () {
+ public static void reInitAll() {
ArrayList<ModData> data = new ArrayList<>(settings.keySet());
settings.clear();
HudCore.huds.clear();
diff --git a/src/main/java/io/polyfrost/oneconfig/config/interfaces/Config.java b/src/main/java/io/polyfrost/oneconfig/config/interfaces/Config.java
index 2e3e92d..73dbbe7 100644
--- a/src/main/java/io/polyfrost/oneconfig/config/interfaces/Config.java
+++ b/src/main/java/io/polyfrost/oneconfig/config/interfaces/Config.java
@@ -20,8 +20,7 @@ import java.util.Optional;
public class Config {
protected final String configFile;
- protected final Gson gson = new GsonBuilder().excludeFieldsWithModifiers(Modifier.TRANSIENT).setPrettyPrinting()
- .registerTypeAdapterFactory(OneConfigTypeAdapterFactory.getStaticTypeAdapterFactory()).create();
+ protected final Gson gson = new GsonBuilder().excludeFieldsWithModifiers(Modifier.TRANSIENT).setPrettyPrinting().registerTypeAdapterFactory(OneConfigTypeAdapterFactory.getStaticTypeAdapterFactory()).create();
/**
* @param modData information about the mod
@@ -33,10 +32,8 @@ public class Config {
}
public void init(ModData modData) {
- if (Profiles.getProfileFile(configFile).exists())
- load();
- else
- save();
+ if (Profiles.getProfileFile(configFile).exists()) load();
+ else save();
modData.config = this;
ConfigCore.settings.put(modData, generateOptionList(this.getClass()));
}
@@ -109,8 +106,7 @@ public class Config {
}
} else {
Option customOption = processCustomOption(field);
- if (customOption != null)
- options.add(customOption);
+ if (customOption != null) options.add(customOption);
}
}
return options;
diff --git a/src/main/java/io/polyfrost/oneconfig/config/interfaces/Option.java b/src/main/java/io/polyfrost/oneconfig/config/interfaces/Option.java
index 5980a63..99cf656 100644
--- a/src/main/java/io/polyfrost/oneconfig/config/interfaces/Option.java
+++ b/src/main/java/io/polyfrost/oneconfig/config/interfaces/Option.java
@@ -19,8 +19,7 @@ public abstract class Option {
this.field = field;
this.name = name;
this.description = description;
- if (field != null)
- field.setAccessible(true);
+ if (field != null) field.setAccessible(true);
}
/**
diff --git a/src/main/java/io/polyfrost/oneconfig/config/profiles/Profiles.java b/src/main/java/io/polyfrost/oneconfig/config/profiles/Profiles.java
index db9fce2..45d448d 100644
--- a/src/main/java/io/polyfrost/oneconfig/config/profiles/Profiles.java
+++ b/src/main/java/io/polyfrost/oneconfig/config/profiles/Profiles.java
@@ -11,8 +11,8 @@ import java.util.ArrayList;
import java.util.Arrays;
public class Profiles {
- public static ArrayList<String> profiles;
private static final File profileDir = new File("OneConfig/profiles");
+ public static ArrayList<String> profiles;
public static String getCurrentProfile() {
if (!profileDir.exists() && !profileDir.mkdir()) {
@@ -21,8 +21,7 @@ public class Profiles {
}
if (profiles == null) {
String[] profilesArray = new File("OneConfig/profiles").list((file, s) -> file.isDirectory());
- if (profilesArray != null)
- profiles = new ArrayList<>(Arrays.asList(profilesArray));
+ if (profilesArray != null) profiles = new ArrayList<>(Arrays.asList(profilesArray));
}
if (!getProfileDir(OneConfigConfig.currentProfile).exists()) {
createProfile(OneConfigConfig.currentProfile);
@@ -62,8 +61,7 @@ public class Profiles {
try {
File newFile = new File(new File("OneConfig/profiles"), newName);
FileUtils.moveDirectory(getProfileDir(name), newFile);
- if (OneConfigConfig.currentProfile.equals(name))
- OneConfigConfig.currentProfile = newName;
+ if (OneConfigConfig.currentProfile.equals(name)) OneConfigConfig.currentProfile = newName;
profiles.remove(name);
profiles.add(newName);
} catch (IOException e) {
diff --git a/src/main/java/io/polyfrost/oneconfig/gui/Window.java b/src/main/java/io/polyfrost/oneconfig/gui/Window.java
index 62576a9..fa672d5 100644
--- a/src/main/java/io/polyfrost/oneconfig/gui/Window.java
+++ b/src/main/java/io/polyfrost/oneconfig/gui/Window.java
@@ -1,10 +1,8 @@
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;
import io.polyfrost.oneconfig.themes.Themes;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
@@ -24,10 +22,11 @@ public class Window extends GuiScreen {
long secondCounter = System.currentTimeMillis();
long prevTime = System.currentTimeMillis();
int frames = 0;
- OCBlock block = new OCBlock(-1, 100, 200);
+ OCBlock block = new OCBlock(() -> {
+ t.getFont().drawString("hi", 10, 10, 1f, 1f, -1);
+ },750, 144);
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() {
@@ -74,15 +73,16 @@ public class Window extends GuiScreen {
int bottom = (int) (1024 * currentProgress);
//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.BACKGROUND, left, top, right, bottom);
//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.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);
- button.draw(500,300);
+ block.draw(100,200);
//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 180215c..abcd5ca 100644
--- a/src/main/java/io/polyfrost/oneconfig/gui/elements/OCBlock.java
+++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/OCBlock.java
@@ -5,7 +5,6 @@ import io.polyfrost.oneconfig.themes.Theme;
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.renderer.GlStateManager;
import org.jetbrains.annotations.NotNull;
import org.lwjgl.input.Keyboard;
@@ -22,9 +21,10 @@ import static io.polyfrost.oneconfig.gui.Window.resolution;
public class OCBlock {
public static final Theme theme = Themes.getActiveTheme();
private static final Minecraft mc = Minecraft.getMinecraft();
- private Color color;
- private String text;
private final boolean bold;
+ private final Color elementColor = theme.getElementColor();
+ private final Color hoverColor = theme.getHoverColor();
+ private final Runnable draw;
/**
* Width of the element in pixels.
*/
@@ -33,34 +33,44 @@ public class OCBlock {
* Height of the element in pixels.
*/
public int height;
+ private Color color;
+ private String text;
private ThemeElement element;
private boolean clicked = false;
private boolean rightClicked = false;
private int mouseX, mouseY;
private boolean hovered;
+ private float percentHoveredRed = 0f;
+ private float percentHoveredGreen = 0f;
+ private float percentHoveredBlue = 0f;
+ private float percentHoveredAlpha = 0f;
/**
- * Create a basic element with nothing. Used for extended classes.
+ * Create a basic element.
*/
public OCBlock(int width, int height) {
- this(null, false, -1, width, height);
+ this(null, false, theme.getElementColor().getRGB(), width, height);
}
/**
* Create a new basic element.
- * @param color color of the element
- * @param width width of the element
+ *
+ * @param color color of the element
+ * @param width width of the element
* @param height height of the element
+ * @deprecated This method DOES NOT respect the theme colors for the element. Use of {@link #OCBlock(int, int)} is recommended instead.
*/
+ @Deprecated()
public OCBlock(int color, int width, int height) {
this(null, false, color, width, height);
}
/**
* Create a new element with the specified text, and automatic width/height + padding.
- * @param text text to use
- * @param bold weather or not to use bold text
- * @param color color of the background to use
+ *
+ * @param text text to use
+ * @param bold weather or not to use bold text
+ * @param color color for the text
*/
public OCBlock(@NotNull String text, boolean bold, int color) {
this(text, bold, color, theme.getFont().getWidth(text) + 6, theme.getFont().getHeight() + 4);
@@ -68,11 +78,13 @@ public class OCBlock {
/**
* Create a new element with the specified text, and custom width/height.
- * @param text text to use
- * @param bold weather or not to use bold text
- * @param color color of the background to use
+ *
+ * @param text text to use
+ * @param bold weather or not to use bold text
+ * @param color color for the text (use {@link Theme#getTextColor()} or {@link Theme#getAccentTextColor()} for default colors)
*/
public OCBlock(String text, boolean bold, int color, int width, int height) {
+ this.draw = null;
this.text = text;
this.bold = bold;
this.color = Renderer.getColorFromInt(color);
@@ -82,10 +94,12 @@ public class OCBlock {
/**
* Create a new Element with the specified image.
- * @param element element to use
+ *
+ * @param element element to use
* @param colorMask color mast to use (-1 for default)
*/
public OCBlock(ThemeElement element, int colorMask, int width, int height) {
+ this.draw = null;
this.element = element;
this.color = Renderer.getColorFromInt(colorMask);
this.width = width;
@@ -94,26 +108,48 @@ public class OCBlock {
}
/**
+ * Create a new Element with a custom render script. The {@link Runnable} should ONLY contain #draw() calls or equivalent.
+ *
+ * @param whatToDraw a {@link Runnable}, containing draw scripts for elements. You will need to instantiate the objects first, if they are sub-elements.
+ */
+ public OCBlock(Runnable whatToDraw, int width, int height) {
+ this.draw = whatToDraw;
+ this.bold = false;
+ this.width = width;
+ this.height = height;
+ }
+
+ /**
* Draw the element at the specified coordinates.
*/
public void draw(int x, int y) {
+ GlStateManager.enableBlend();
+ 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);
+ GlStateManager.color(percentHoveredRed, percentHoveredGreen, percentHoveredBlue, percentHoveredAlpha);
update(x, y);
- if(element != null) {
- Gui.drawRect(x, y, x + width, y + height, color.getRGB());
+ if (draw != null) {
+ draw.run();
+ }
+ if (element != null) {
+ theme.getTextureManager().draw(ThemeElement.BUTTON, x, y, width, height);
GlStateManager.color(color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f, color.getAlpha() / 255f);
theme.getTextureManager().draw(element, x, y, width, height);
}
- if(text == null) {
- Gui.drawRect(x, y, x + width, y + height, color.getRGB());
- }
- else {
- Gui.drawRect(x, y, x + width, y + height, color.getRGB());
- if(bold) {
- theme.getBoldFont().drawString(text, x + 3, y + 2, 1f, 1f, -1);
+ if (text == null) {
+ theme.getTextureManager().draw(ThemeElement.BUTTON, x, y, width, height);
+ } else {
+ theme.getTextureManager().draw(ThemeElement.BUTTON, x, y, width, height);
+ if (bold) {
+ theme.getBoldFont().drawString(text, x + 3, y + 2, 1f, 1f, color.getRGB());
} else {
- theme.getFont().drawString(text, x + 3, y + 2, 1.1f, 1f, -1);
+ theme.getFont().drawString(text, x + 3, y + 2, 1.1f, 1f, color.getRGB());
}
}
+ GlStateManager.disableBlend();
+
}
@@ -124,7 +160,7 @@ public class OCBlock {
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;
- if(hovered) {
+ if (hovered) {
onHover();
if (Mouse.isButtonDown(0) && !clicked) {
onClick(0);
@@ -137,7 +173,10 @@ public class OCBlock {
rightClicked = Mouse.isButtonDown(1);
onKeyPress(Keyboard.getEventKey());
}
- if(!hovered && clicked) clicked = false;
+ if (clicked) {
+ Renderer.color(theme.getClickColor());
+ }
+ if (!hovered && clicked) clicked = false;
}
/**
@@ -152,6 +191,7 @@ public class OCBlock {
/**
* Override this method to set a function when a key is pressed while this element is hovered.
+ *
* @param keyCode key code that was pressed (check org.lwjgl.Keyboard for keymap)
*/
public void onKeyPress(int keyCode) {
@@ -160,6 +200,7 @@ public class OCBlock {
/**
* Override this method to set a function when the element is hovered.
+ *
* @param button the button that was pressed (0 is left, 1 is right)
*/
public void onClick(int button) {
@@ -174,36 +215,49 @@ public class OCBlock {
}
- public void setText(String text) {
- this.text = text;
- }
- public void setWidth(int width) {
- this.width = width;
- }
+ private float smooth(float current, float min, float max) {
+ current = Renderer.easeOut(current, isHovered() ? 1f : 0f);
+ if (current <= min) {
+ current = min;
+ }
- public void setHeight(int height) {
- this.height = height;
+ if (current >= max) {
+ current = max;
+ }
+ return current;
}
public int getHeight() {
return height;
}
+ public void setHeight(int height) {
+ this.height = height;
+ }
+
public Color getColor() {
return color;
}
+ public void setColor(Color color) {
+ this.color = color;
+ }
+
public int getWidth() {
return width;
}
+ public void setWidth(int width) {
+ this.width = width;
+ }
+
public String getText() {
return text;
}
- public void setColor(Color color) {
- this.color = color;
+ public void setText(String text) {
+ this.text = text;
}
public boolean isHovered() {
diff --git a/src/main/java/io/polyfrost/oneconfig/gui/elements/OCButton.java b/src/main/java/io/polyfrost/oneconfig/gui/elements/OCButton.java
index 2ffeaf7..5f78baa 100644
--- a/src/main/java/io/polyfrost/oneconfig/gui/elements/OCButton.java
+++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/OCButton.java
@@ -8,13 +8,13 @@ import org.jetbrains.annotations.NotNull;
import java.awt.*;
public class OCButton extends OCBlock {
+ private final Color elementColor = theme.getElementColor();
+ private final Color hoverColor = theme.getHoverColor();
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;
@@ -58,27 +58,27 @@ public class OCButton extends OCBlock {
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) {
+ if (!alwaysShowDesc) {
percentDescription = Renderer.clamp(Renderer.easeOut(percentDescription, isHovered() ? 1f : 0f));
}
GlStateManager.color(percentHoveredRed, percentHoveredGreen, percentHoveredBlue, percentHoveredAlpha);
- if(isClicked()) {
- Renderer.setGlColor(theme.getClickColor());
+ 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);
+ 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) {
+ 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));
+ 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());
}
@@ -89,11 +89,11 @@ public class OCButton extends OCBlock {
private float smooth(float current, float min, float max) {
current = Renderer.easeOut(current, isHovered() ? 1f : 0f);
- if(current <= min) {
+ if (current <= min) {
current = min;
}
- if(current >= max) {
+ if (current >= max) {
current = max;
}
return current;
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 3d23b2f..d7fa7e9 100644
--- a/src/main/java/io/polyfrost/oneconfig/gui/elements/OCStoreBlock.java
+++ b/src/main/java/io/polyfrost/oneconfig/gui/elements/OCStoreBlock.java
@@ -1,16 +1,15 @@
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.*;
public class OCStoreBlock extends OCBlock {
- private ResourceLocation image;
- private String description, title;
- private Color color;
+ private final ResourceLocation image;
+ private final String description;
+ private final String title;
+ private final Color color;
public OCStoreBlock(String title, String description, ResourceLocation image, int color) {
super(color, 300, 400);
@@ -31,6 +30,6 @@ public class OCStoreBlock extends OCBlock {
}
public void draw(int x, int y, int width, int height) {
- draw(x,y);
+ draw(x, y);
}
}
diff --git a/src/main/java/io/polyfrost/oneconfig/hud/gui/HudGui.java b/src/main/java/io/polyfrost/oneconfig/hud/gui/HudGui.java
index 6e1ce6c..7620a26 100644
--- a/src/main/java/io/polyfrost/oneconfig/hud/gui/HudGui.java
+++ b/src/main/java/io/polyfrost/oneconfig/hud/gui/HudGui.java
@@ -47,10 +47,8 @@ public class HudGui extends GuiScreen {
float pos = getXSnapping(mouseX, true);
float newWidth = pos - xFloat;
float newScale = newWidth / ((hud.getWidth(hud.scale) + hud.paddingX * hud.scale) / hud.scale);
- if (newScale > 20)
- newScale = 20;
- else if (newScale < 0.3)
- newScale = 0.3f;
+ if (newScale > 20) newScale = 20;
+ else if (newScale < 0.3) newScale = 0.3f;
hud.scale = newScale;
if (xFloat / this.width > 0.5)
@@ -68,8 +66,7 @@ public class HudGui extends GuiScreen {
int color = new Color(215, 224, 235).getRGB();
if (editingHud == hud) {
color = new Color(43, 159, 235).getRGB();
- if (isDragging)
- Gui.drawRect(x, y, x + width, y + height, new Color(108, 176, 255, 60).getRGB());
+ if (isDragging) Gui.drawRect(x, y, x + width, y + height, new Color(108, 176, 255, 60).getRGB());
}
Renderer.drawLine(x - 2 / 4f, y, x + width + 2 / 4f, y, 2, color);
Renderer.drawLine(x, y, x, y + height, 2, color);
@@ -87,28 +84,20 @@ public class HudGui extends GuiScreen {
float width = editingHud.getWidth(editingHud.scale) + editingHud.paddingX * editingHud.scale;
float height = editingHud.getHeight(editingHud.scale) + editingHud.paddingY * editingHud.scale;
- if (newX < 0)
- newX = 0;
- else if (newX + width > this.width)
- newX = this.width - width;
- if (newY < 0)
- newY = 0;
- else if (newY + height > this.height)
- newY = this.height - height;
+ if (newX < 0) newX = 0;
+ else if (newX + width > this.width) newX = this.width - width;
+ if (newY < 0) newY = 0;
+ else if (newY + height > this.height) newY = this.height - height;
if (snap) {
newX = getXSnapping(newX, false);
newY = getYSnapping(newY);
}
- if (newX / this.width <= 0.5)
- editingHud.xUnscaled = newX / (double) this.width;
- else
- editingHud.xUnscaled = (newX + width) / (double) this.width;
- if (newY / this.height <= 0.5)
- editingHud.yUnscaled = newY / (double) this.height;
- else
- editingHud.yUnscaled = (newY + height) / (double) this.height;
+ if (newX / this.width <= 0.5) editingHud.xUnscaled = newX / (double) this.width;
+ else editingHud.xUnscaled = (newX + width) / (double) this.width;
+ if (newY / this.height <= 0.5) editingHud.yUnscaled = newY / (double) this.height;
+ else editingHud.yUnscaled = (newY + height) / (double) this.height;
}
private float getXSnapping(float pos, boolean rightOnly) {
diff --git a/src/main/java/io/polyfrost/oneconfig/hud/interfaces/BasicHud.java b/src/main/java/io/polyfrost/oneconfig/hud/interfaces/BasicHud.java
index 723a09e..cce2440 100644
--- a/src/main/java/io/polyfrost/oneconfig/hud/interfaces/BasicHud.java
+++ b/src/main/java/io/polyfrost/oneconfig/hud/interfaces/BasicHud.java
@@ -55,9 +55,7 @@ public abstract class BasicHud {
}
private void drawBackground(float x, float y, float scale) {
- Renderer.drawRoundRect((int) x, (int) y,
- (int) (getTotalWidth(scale) + paddingX * scale), (int) (getTotalHeight(scale) + paddingY * scale),
- (int) (2 * scale), new Color(0, 0, 0, 120).getRGB());
+ Renderer.drawRoundRect((int) x, (int) y, (int) (getTotalWidth(scale) + paddingX * scale), (int) (getTotalHeight(scale) + paddingY * scale), (int) (2 * scale), new Color(0, 0, 0, 120).getRGB());
}
public float getXScaled(int screenWidth) {
diff --git a/src/main/java/io/polyfrost/oneconfig/hud/interfaces/TextHud.java b/src/main/java/io/polyfrost/oneconfig/hud/interfaces/TextHud.java
index 33bbd79..3c9cf4c 100644
--- a/src/main/java/io/polyfrost/oneconfig/hud/interfaces/TextHud.java
+++ b/src/main/java/io/polyfrost/oneconfig/hud/interfaces/TextHud.java
@@ -14,10 +14,10 @@ public class TextHud extends BasicHud {
*/
private final FontRenderer fb = Minecraft.getMinecraft().fontRendererObj;
boolean shadow = false;
+ boolean doExample = false;
private List<String> cachedLines;
private int cachedWidth;
private int cachedHeight;
- boolean doExample = false;
private List<String> cachedExampleLines;
private int cachedExampleWidth;
private int cachedExampleHeight;
@@ -35,8 +35,7 @@ public class TextHud extends BasicHud {
cachedWidth = 0;
for (String line : cachedLines) {
int width = fb.getStringWidth(line);
- if (width > cachedWidth)
- cachedWidth = width;
+ if (width > cachedWidth) cachedWidth = width;
}
}
if (doExample) {
@@ -46,8 +45,7 @@ public class TextHud extends BasicHud {
cachedExampleWidth = 0;
for (String line : cachedExampleLines) {
int width = fb.getStringWidth(line);
- if (width > cachedExampleWidth)
- cachedExampleWidth = width;
+ if (width > cachedExampleWidth) cachedExampleWidth = width;
}
}
}
@@ -59,20 +57,18 @@ public class TextHud extends BasicHud {
@Override
public void draw(int x, int y, float scale) {
- if (cachedLines != null)
- drawText(cachedLines, x, y, scale);
+ if (cachedLines != null) drawText(cachedLines, x, y, scale);
}
@Override
public void drawExample(int x, int y, float scale) {
doExample = true;
- if (cachedExampleLines != null)
- drawText(cachedExampleLines, x, y, scale);
+ if (cachedExampleLines != null) drawText(cachedExampleLines, x, y, scale);
}
private void drawText(List<String> lines, int x, int y, float scale) {
for (int i = 0; i < lines.size(); i++) {
- Renderer.drawTextScale(lines.get(i), x, y + i * 12, 0xffffff, shadow, scale);
+ Renderer.drawScaledString(lines.get(i), x, y + i * 12, 0xffffff, shadow, scale);
}
}
diff --git a/src/main/java/io/polyfrost/oneconfig/renderer/Renderer.java b/src/main/java/io/polyfrost/oneconfig/renderer/Renderer.java
index 44e1b34..b77b8cd 100644
--- a/src/main/java/io/polyfrost/oneconfig/renderer/Renderer.java
+++ b/src/main/java/io/polyfrost/oneconfig/renderer/Renderer.java
@@ -10,7 +10,7 @@ import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.util.ResourceLocation;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
-import org.lwjgl.opengl.*;
+import org.lwjgl.opengl.GL11;
import java.awt.*;
@@ -22,11 +22,32 @@ public class Renderer extends Gui {
private static final WorldRenderer worldRenderer = tessellator.getWorldRenderer();
- public static void drawRectangle(int left, int top, int right, int bottom, int color) {
- Gui.drawRect(left, top, right, bottom, color);
+ /**
+ * Draw a basic rectangle. Please note that this is to be used WITH a {@link net.minecraft.client.renderer.GlStateManager#color(float, float, float)} before to color it.
+ */
+ public static void drawRectangle(int x, int y, int width, int height) {
+ int right = x + width;
+ int bottom = y + height;
+ if (x < right) {
+ x = right;
+ }
+ if (y < bottom) {
+ y = bottom;
+ }
+ GlStateManager.enableBlend();
+ GlStateManager.disableTexture2D();
+ GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
+ worldRenderer.begin(7, DefaultVertexFormats.POSITION);
+ worldRenderer.pos(x, bottom, 0.0D).endVertex();
+ worldRenderer.pos(right, bottom, 0.0D).endVertex();
+ worldRenderer.pos(right, y, 0.0D).endVertex();
+ worldRenderer.pos(x, y, 0.0D).endVertex();
+ tessellator.draw();
+ GlStateManager.enableTexture2D();
+ GlStateManager.disableBlend();
}
- public static void drawTextScale(String text, float x, float y, int color, boolean shadow, float scale) {
+ public static void drawScaledString(String text, float x, float y, int color, boolean shadow, float scale) {
GlStateManager.pushMatrix();
GlStateManager.scale(scale, scale, 1);
mc.fontRendererObj.drawString(text, x * (1 / scale), y * (1 / scale), color, shadow);
@@ -42,7 +63,7 @@ public class Renderer extends Gui {
public static void drawRegularPolygon(double x, double y, int radius, int sides, int color, double lowerAngle, double upperAngle) {
GL11.glDisable(GL11.GL_TEXTURE_2D);
- setGlColor(color);
+ color(color);
GlStateManager.enableBlend();
GlStateManager.disableAlpha();
worldRenderer.begin(GL11.GL_POLYGON, DefaultVertexFormats.POSITION);
@@ -120,14 +141,14 @@ public class Renderer extends Gui {
/**
* Set GL color from the given Color variable.
*/
- public static void setGlColor(Color color) {
+ public static void color(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) {
+ public static void color(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;
diff --git a/src/main/java/io/polyfrost/oneconfig/renderer/TrueTypeFont.java b/src/main/java/io/polyfrost/oneconfig/renderer/TrueTypeFont.java
index 9a51e68..d26b953 100644
--- a/src/main/java/io/polyfrost/oneconfig/renderer/TrueTypeFont.java
+++ b/src/main/java/io/polyfrost/oneconfig/renderer/TrueTypeFont.java
@@ -29,10 +29,7 @@ import java.util.Map;
* @author version edited by David Aaron Muhar (bobjob) (modified in Bobjob's Engine)
*/
public class TrueTypeFont {
- public final static int
- ALIGN_LEFT = 0,
- ALIGN_RIGHT = 1,
- ALIGN_CENTER = 2;
+ public final static int ALIGN_LEFT = 0, ALIGN_RIGHT = 1, ALIGN_CENTER = 2;
/**
* Array that holds necessary information about the font characters
*/
@@ -52,54 +49,26 @@ public class TrueTypeFont {
* Font's size
*/
private final int fontSize;
-
- /**
- * Font's height
- */
- private int fontHeight = 0;
-
- /**
- * Texture used to cache the font 0-255 characters
- */
- private int fontTextureID;
-
/**
* Default font texture width
*/
private final int textureWidth = 512;
-
/**
* Default font texture height
*/
private final int textureHeight = 512;
-
/**
* A reference to Java's AWT Font that we create our font texture from
*/
private final Font font;
-
-
- private static class IntObject {
- /**
- * Character's width
- */
- public int width;
-
- /**
- * Character's height
- */
- public int height;
-
- /**
- * Character's stored x position
- */
- public int storedX;
-
- /**
- * Character's stored y position
- */
- public int storedY;
- }
+ /**
+ * Font's height
+ */
+ private int fontHeight = 0;
+ /**
+ * Texture used to cache the font 0-255 characters
+ */
+ private int fontTextureID;
public TrueTypeFont(Font font, boolean antiAlias, char[] additionalChars) {
@@ -113,18 +82,86 @@ public class TrueTypeFont {
if (fontHeight <= 0) fontHeight = 1;
}
+
public TrueTypeFont(Font font, boolean antiAlias) {
this(font, antiAlias, null);
}
+ public static int loadImage(BufferedImage bufferedImage) {
+ try {
+ short width = (short) bufferedImage.getWidth();
+ short height = (short) bufferedImage.getHeight();
+ //textureLoader.bpp = bufferedImage.getColorModel().hasAlpha() ? (byte)32 : (byte)24;
+ int bpp = (byte) bufferedImage.getColorModel().getPixelSize();
+ ByteBuffer byteBuffer;
+ DataBuffer db = bufferedImage.getData().getDataBuffer();
+ if (db instanceof DataBufferInt) {
+ int[] intI = ((DataBufferInt) (bufferedImage.getData().getDataBuffer())).getData();
+ byte[] newI = new byte[intI.length * 4];
+ for (int i = 0; i < intI.length; i++) {
+ byte[] b = intToByteArray(intI[i]);
+ int newIndex = i * 4;
+
+ newI[newIndex] = b[1];
+ newI[newIndex + 1] = b[2];
+ newI[newIndex + 2] = b[3];
+ newI[newIndex + 3] = b[0];
+ }
+
+ byteBuffer = ByteBuffer.allocateDirect(width * height * (bpp / 8)).order(ByteOrder.nativeOrder()).put(newI);
+ } else {
+ byteBuffer = ByteBuffer.allocateDirect(width * height * (bpp / 8)).order(ByteOrder.nativeOrder()).put(((DataBufferByte) (bufferedImage.getData().getDataBuffer())).getData());
+ }
+ byteBuffer.flip();
+
+
+ int internalFormat = GL11.GL_RGBA8, format = GL11.GL_RGBA;
+ IntBuffer textureId = BufferUtils.createIntBuffer(1);
+
+ GL11.glGenTextures(textureId);
+ GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureId.get(0));
+
+
+ GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP);
+ GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_CLAMP);
+
+ GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
+ GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
+
+ GL11.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_MODULATE);
+
+
+ GLU.gluBuild2DMipmaps(GL11.GL_TEXTURE_2D, internalFormat, width, height, format, GL11.GL_UNSIGNED_BYTE, byteBuffer);
+ return textureId.get(0);
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return -1;
+ }
+
+ public static boolean isSupported(String fontname) {
+ Font[] font = getFonts();
+ for (int i = font.length - 1; i >= 0; i--) {
+ if (font[i].getName().equalsIgnoreCase(fontname)) return true;
+ }
+ return false;
+ }
+
+ public static Font[] getFonts() {
+ return GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts();
+ }
+
+ public static byte[] intToByteArray(int value) {
+ return new byte[]{(byte) (value >>> 24), (byte) (value >>> 16), (byte) (value >>> 8), (byte) value};
+ }
+
private BufferedImage getFontImage(char ch) {
// Create a temporary image to extract the character's size
- BufferedImage tempfontImage = new BufferedImage(1, 1,
- BufferedImage.TYPE_INT_ARGB);
+ BufferedImage tempfontImage = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = (Graphics2D) tempfontImage.getGraphics();
if (antiAlias) {
- g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
- RenderingHints.VALUE_ANTIALIAS_ON);
+ g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
}
g.setFont(font);
FontMetrics fontMetrics = g.getFontMetrics();
@@ -140,20 +177,17 @@ public class TrueTypeFont {
// Create another image holding the character we are creating
BufferedImage fontImage;
- fontImage = new BufferedImage(charwidth, charheight,
- BufferedImage.TYPE_INT_ARGB);
+ fontImage = new BufferedImage(charwidth, charheight, BufferedImage.TYPE_INT_ARGB);
Graphics2D gt = (Graphics2D) fontImage.getGraphics();
if (antiAlias) {
- gt.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
- RenderingHints.VALUE_ANTIALIAS_ON);
+ gt.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
}
gt.setFont(font);
gt.setColor(Color.WHITE);
int charx = 3;
int chary = 1;
- gt.drawString(String.valueOf(ch), (charx), (chary)
- + fontMetrics.getAscent());
+ gt.drawString(String.valueOf(ch), (charx), (chary) + fontMetrics.getAscent());
return fontImage;
@@ -223,8 +257,7 @@ public class TrueTypeFont {
}
}
- private void drawQuad(float drawX, float drawY, float drawX2, float drawY2,
- float srcX, float srcY, float srcX2, float srcY2) {
+ private void drawQuad(float drawX, float drawY, float drawX2, float drawY2, float srcX, float srcY, float srcX2, float srcY2) {
float DrawWidth = drawX2 - drawX;
float DrawHeight = drawY2 - drawY;
float TextureSrcX = srcX / textureWidth;
@@ -260,8 +293,7 @@ public class TrueTypeFont {
intObject = customChars.get((char) currentChar);
}
- if (intObject != null)
- totalWidth += intObject.width;
+ if (intObject != null) totalWidth += intObject.width;
}
return totalWidth;
}
@@ -281,18 +313,18 @@ public class TrueTypeFont {
String[] words = text.split("\\W+");
int totalWidth = 0;
String line = "";
- for(String word : words) {
+ for (String word : words) {
int width = getWidth(word);
word += " "; // add the space
totalWidth += width;
line += word;
- if(totalWidth >= wrapWidth) { // wrap line if it is too long
+ if (totalWidth >= wrapWidth) { // wrap line if it is too long
splitString.add(line);
totalWidth = 0;
line = "";
}
}
- if(!line.equals("")) { // add extra if there is any (last line)
+ if (!line.equals("")) { // add extra if there is any (last line)
splitString.add(line);
}
int i1 = 0;
@@ -305,10 +337,6 @@ public class TrueTypeFont {
}
}
-
-
-
-
public void drawString(String text, float x, float y, float scaleX, float scaleY, int format, int color) {
int startIndex = 0;
int endIndex = text.length() - 1;
@@ -356,7 +384,7 @@ public class TrueTypeFont {
GlStateManager.enableAlpha();
GlStateManager.enableBlend();
- Renderer.setGlColor(color);
+ Renderer.color(color);
while (i >= startIndex && i <= endIndex) {
charCurrent = text.charAt(i);
if (charCurrent < 256) {
@@ -367,11 +395,7 @@ public class TrueTypeFont {
if (intObject != null) {
if (d < 0) totalWidth += (intObject.width - c) * d;
- drawQuad((totalWidth + intObject.width) * scaleX + x, startY * scaleY + y,
- totalWidth * scaleX + x,
- (startY + intObject.height) * scaleY + y, intObject.storedX + intObject.width,
- intObject.storedY + intObject.height, intObject.storedX,
- intObject.storedY);
+ drawQuad((totalWidth + intObject.width) * scaleX + x, startY * scaleY + y, totalWidth * scaleX + x, (startY + intObject.height) * scaleY + y, intObject.storedX + intObject.width, intObject.storedY + intObject.height, intObject.storedX, intObject.storedY);
if (d > 0) totalWidth += (intObject.width - c) * d;
} else if (charCurrent == '\n') {
startY += fontHeight * d;
@@ -393,94 +417,7 @@ public class TrueTypeFont {
i += d;
}
GlStateManager.disableBlend();
- GlStateManager.color(1f,1f,1f,1f);
- }
-
- public static int loadImage(BufferedImage bufferedImage) {
- try {
- short width = (short) bufferedImage.getWidth();
- short height = (short) bufferedImage.getHeight();
- //textureLoader.bpp = bufferedImage.getColorModel().hasAlpha() ? (byte)32 : (byte)24;
- int bpp = (byte) bufferedImage.getColorModel().getPixelSize();
- ByteBuffer byteBuffer;
- DataBuffer db = bufferedImage.getData().getDataBuffer();
- if (db instanceof DataBufferInt) {
- int[] intI = ((DataBufferInt) (bufferedImage.getData().getDataBuffer())).getData();
- byte[] newI = new byte[intI.length * 4];
- for (int i = 0; i < intI.length; i++) {
- byte[] b = intToByteArray(intI[i]);
- int newIndex = i * 4;
-
- newI[newIndex] = b[1];
- newI[newIndex + 1] = b[2];
- newI[newIndex + 2] = b[3];
- newI[newIndex + 3] = b[0];
- }
-
- byteBuffer = ByteBuffer.allocateDirect(
- width * height * (bpp / 8))
- .order(ByteOrder.nativeOrder())
- .put(newI);
- } else {
- byteBuffer = ByteBuffer.allocateDirect(
- width * height * (bpp / 8))
- .order(ByteOrder.nativeOrder())
- .put(((DataBufferByte) (bufferedImage.getData().getDataBuffer())).getData());
- }
- byteBuffer.flip();
-
-
- int internalFormat = GL11.GL_RGBA8,
- format = GL11.GL_RGBA;
- IntBuffer textureId = BufferUtils.createIntBuffer(1);
-
- GL11.glGenTextures(textureId);
- GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureId.get(0));
-
-
- GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP);
- GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_CLAMP);
-
- GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
- GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
-
- GL11.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_MODULATE);
-
-
- GLU.gluBuild2DMipmaps(GL11.GL_TEXTURE_2D,
- internalFormat,
- width,
- height,
- format,
- GL11.GL_UNSIGNED_BYTE,
- byteBuffer);
- return textureId.get(0);
-
- } catch (Exception e) {
- e.printStackTrace();
- }
- return -1;
- }
-
- public static boolean isSupported(String fontname) {
- Font[] font = getFonts();
- for (int i = font.length - 1; i >= 0; i--) {
- if (font[i].getName().equalsIgnoreCase(fontname))
- return true;
- }
- return false;
- }
-
- public static Font[] getFonts() {
- return GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts();
- }
-
- public static byte[] intToByteArray(int value) {
- return new byte[]{
- (byte) (value >>> 24),
- (byte) (value >>> 16),
- (byte) (value >>> 8),
- (byte) value};
+ GlStateManager.color(1f, 1f, 1f, 1f);
}
public void destroy() {
@@ -489,4 +426,26 @@ public class TrueTypeFont {
GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
GL11.glDeleteTextures(scratch);
}
+
+ private static class IntObject {
+ /**
+ * Character's width
+ */
+ public int width;
+
+ /**
+ * Character's height
+ */
+ public int height;
+
+ /**
+ * Character's stored x position
+ */
+ public int storedX;
+
+ /**
+ * Character's stored y position
+ */
+ public int storedY;
+ }
}
diff --git a/src/main/java/io/polyfrost/oneconfig/test/TestHud.java b/src/main/java/io/polyfrost/oneconfig/test/TestHud.java
index 0ce2984..67f0610 100644
--- a/src/main/java/io/polyfrost/oneconfig/test/TestHud.java
+++ b/src/main/java/io/polyfrost/oneconfig/test/TestHud.java
@@ -18,6 +18,6 @@ public class TestHud extends BasicHud {
@Override
public void draw(int x, int y, float scale) {
- Renderer.drawTextScale("FPS: " + Minecraft.getDebugFPS(), x, y, 0xffffff, false, scale);
+ Renderer.drawScaledString("FPS: " + Minecraft.getDebugFPS(), x, y, 0xffffff, false, scale);
}
}
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 9b583ef..a2e96d4 100644
--- a/src/main/java/io/polyfrost/oneconfig/themes/textures/TextureManager.java
+++ b/src/main/java/io/polyfrost/oneconfig/themes/textures/TextureManager.java
@@ -46,7 +46,7 @@ public class TextureManager {
if (img.getWidth() != element.size) {
themeLog.warn("Theme element " + element.name() + " with size " + img.getWidth() + "px is not recommended, expected " + element.size + "px. Continuing anyway.");
}
- if(element.ordinal() < 26) {
+ if (element.ordinal() < 26) {
if (img.getWidth() != img.getHeight()) {
themeLog.info("found tickable animated texture (" + element.name() + "). Loading texture");
try {
@@ -57,8 +57,8 @@ public class TextureManager {
}
}
} else {
- if(element.ordinal() < 29) {
- if(img.getHeight() != 144 || img.getWidth() != 758) {
+ if (element.ordinal() < 29) {
+ if (img.getHeight() != 144 || img.getWidth() != 758) {
themeLog.warn("found badly sized button texture " + element.location);
}
}
@@ -67,7 +67,7 @@ public class TextureManager {
}
/**
- * Draw the specified icon at the coordinates, scaled to the width and height.
+ * Draw the specified {@link ThemeElement} at the coordinates, scaled to the width and height.
*
* @param element element to draw
* @param x x coordinate (top left)
@@ -99,4 +99,15 @@ public class TextureManager {
}
}
}
+
+ /**
+ * Draw the specified {@link ThemeElement} at the coordinates, using its recommended width and height.
+ *
+ * @param element element to draw
+ * @param x x coordinate (top left)
+ * @param y y coordinate (top left)
+ */
+ public void draw(@NotNull ThemeElement element, int x, int y) {
+ this.draw(element, x, y, element.size, element.size);
+ }
}
diff --git a/src/main/java/io/polyfrost/oneconfig/themes/textures/TickableTexture.java b/src/main/java/io/polyfrost/oneconfig/themes/textures/TickableTexture.java
index b9882d0..5fe1242 100644
--- a/src/main/java/io/polyfrost/oneconfig/themes/textures/TickableTexture.java
+++ b/src/main/java/io/polyfrost/oneconfig/themes/textures/TickableTexture.java
@@ -2,7 +2,6 @@ package io.polyfrost.oneconfig.themes.textures;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
-import io.polyfrost.oneconfig.themes.textures.ThemeElement;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.renderer.GlStateManager;
@@ -23,10 +22,10 @@ public class TickableTexture {
private final int framesToSkip;
private final BufferedImage image;
private final int sizeX, sizeY, frames;
- private int tick;
- private int tick2;
private final ThemeElement thisElement;
private final ResourceLocation location;
+ private int tick;
+ private int tick2;
public TickableTexture(ThemeElement element) throws IOException {
thisElement = element;
@@ -42,7 +41,7 @@ public class TickableTexture {
frametime = jsonObject.get("frametime").getAsInt();
if (frametime == 0) {
frametime = 1;
- themeLog.warn("You cannot have a frame tick time of 0. This will mean there is no animation as it will happen way too fast. Defaulting to 1, as we assume you wanted it fast.");
+ themeLog.warn("You cannot have a frame tick time of 0. This will mean there is no animation as it will happen impossibly fast. Defaulting to 1, as we assume you wanted it fast.");
}
} catch (Exception e) {
themeLog.error("failed to load metadata for tickable texture (" + element.location + "). Setting default (5)");
@@ -53,7 +52,7 @@ public class TickableTexture {
public void draw(int x, int y) {
GlStateManager.enableBlend();
- GlStateManager.color(1f,1f,1f,1f);
+ GlStateManager.color(1f, 1f, 1f, 1f);
Minecraft.getMinecraft().getTextureManager().bindTexture(location);
if (tick < frames) {
Gui.drawModalRectWithCustomSizedTexture(x, y, 0, (tick * sizeX), sizeX, sizeX, sizeX, sizeX);