From 83e13285f9298306822adf94db86dea7f4406b15 Mon Sep 17 00:00:00 2001 From: luisc Date: Mon, 31 Jan 2022 14:51:06 -0600 Subject: [PATCH] Added rotation to overlay components, and color codes to overlay labels --- .../custom/components/CustomGuiButton.java | 11 +++ .../gui/custom/components/CustomGuiLabel.java | 64 +++++++++++++-- .../components/CustomGuiTexturedRect.java | 11 +++ .../components/CustomOverlayLabel.java | 78 +++++++++++++++---- .../components/CustomOverlayLine.java | 4 + .../components/CustomOverlayTexturedRect.java | 16 ++++ .../interfaces/ICustomOverlayComponent.java | 4 + .../overlay/ScriptOverlayComponent.java | 11 +++ 8 files changed, 180 insertions(+), 19 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiButton.java b/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiButton.java index 9cce17988..b2d73a5cd 100644 --- a/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiButton.java +++ b/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiButton.java @@ -8,9 +8,14 @@ package noppes.npcs.client.gui.custom.components; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.renderer.texture.ITextureObject; +import net.minecraft.client.renderer.texture.TextureManager; +import net.minecraft.client.resources.SkinManager; import net.minecraft.util.ResourceLocation; +import noppes.npcs.client.ImageDownloadAlt; import noppes.npcs.client.gui.custom.GuiCustom; import noppes.npcs.client.gui.custom.interfaces.IClickListener; +import noppes.npcs.client.renderer.ImageBufferDownloadAlt; import noppes.npcs.scripted.gui.ScriptGuiButton; import noppes.npcs.scripted.interfaces.ICustomGuiComponent; import org.lwjgl.opengl.GL11; @@ -45,6 +50,12 @@ public class CustomGuiButton extends GuiButton implements IClickListener { this.textureY = textureY; this.label = buttonText; this.texture = new ResourceLocation(texture); + + if(texture.startsWith("https://")){ + TextureManager texturemanager = Minecraft.getMinecraft().getTextureManager(); + ITextureObject object = new ImageDownloadAlt(null, texture, SkinManager.field_152793_a, new ImageBufferDownloadAlt(false)); + texturemanager.loadTexture(this.texture, object); + } } public void setParent(GuiCustom parent) { diff --git a/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiLabel.java b/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiLabel.java index d7fde5ad7..7ab9f2d64 100644 --- a/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiLabel.java +++ b/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiLabel.java @@ -58,6 +58,7 @@ public class CustomGuiLabel extends Gui implements IGuiComponent { protected final ResourceLocation locationFontTexture; protected int[] charWidth = new int[256]; protected byte[] glyphWidth = new byte[65536]; + private final int[] colorCode = new int[32]; private float red; @@ -68,10 +69,6 @@ public class CustomGuiLabel extends Gui implements IGuiComponent { private float posY; public CustomGuiLabel(int id, String fullLabel, int x, int y, int width, int height, boolean shadow){ - locationFontTexture = new ResourceLocation("textures/font/ascii.png"); - readFontTexture(); - readGlyphSizes(); - this.id = id; this.fullLabel = fullLabel; this.x = x; @@ -79,6 +76,41 @@ public class CustomGuiLabel extends Gui implements IGuiComponent { this.width = width; this.height = height; this.labelShadowEnabled = shadow; + + locationFontTexture = new ResourceLocation("textures/font/ascii.png"); + readFontTexture(); + readGlyphSizes(); + for (int i = 0; i < 32; ++i) + { + int j = (i >> 3 & 1) * 85; + int k = (i >> 2 & 1) * 170 + j; + int l = (i >> 1 & 1) * 170 + j; + int i1 = (i >> 0 & 1) * 170 + j; + + if (i == 6) + { + k += 85; + } + + if (Minecraft.getMinecraft().gameSettings.anaglyph) + { + int j1 = (k * 30 + l * 59 + i1 * 11) / 100; + int k1 = (k * 30 + l * 70) / 100; + int l1 = (k * 30 + i1 * 70) / 100; + k = j1; + l = k1; + i1 = l1; + } + + if (i >= 16) + { + k /= 4; + l /= 4; + i1 /= 4; + } + + this.colorCode[i] = (k & 255) << 16 | (l & 255) << 8 | i1 & 255; + } } public void setParent(GuiCustom parent) { @@ -198,7 +230,27 @@ public class CustomGuiLabel extends Gui implements IGuiComponent { { j = "0123456789abcdefklmnor".indexOf(p_78255_1_.toLowerCase().charAt(i + 1)); - if (j == 16) + if(j < 16){ + this.randomStyle = false; + this.boldStyle = false; + this.strikethroughStyle = false; + this.underlineStyle = false; + this.italicStyle = false; + + if (j < 0 || j > 15) + { + j = 15; + } + + if (p_78255_2_) + { + j += 16; + } + + k = this.colorCode[j]; + setColor((float)(k >> 16) / 255.0F, (float)(k >> 8 & 255) / 255.0F, (float)(k & 255) / 255.0F, this.alpha); + } + else if (j == 16) { this.randomStyle = true; } @@ -403,7 +455,7 @@ public class CustomGuiLabel extends Gui implements IGuiComponent { protected void setColor(float r, float g, float b, float a) { - GL11.glColor4f(r, g, b, alpha); + GL11.glColor4f(r, g, b, a); } protected void bindTexture(ResourceLocation location) diff --git a/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiTexturedRect.java b/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiTexturedRect.java index 0f480771c..b17939da4 100644 --- a/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiTexturedRect.java +++ b/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiTexturedRect.java @@ -8,9 +8,14 @@ package noppes.npcs.client.gui.custom.components; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.texture.ITextureObject; +import net.minecraft.client.renderer.texture.TextureManager; +import net.minecraft.client.resources.SkinManager; import net.minecraft.util.ResourceLocation; +import noppes.npcs.client.ImageDownloadAlt; import noppes.npcs.client.gui.custom.GuiCustom; import noppes.npcs.client.gui.custom.interfaces.IGuiComponent; +import noppes.npcs.client.renderer.ImageBufferDownloadAlt; import noppes.npcs.scripted.gui.ScriptGuiTexturedRect; import noppes.npcs.scripted.interfaces.ICustomGuiComponent; import org.lwjgl.opengl.GL11; @@ -48,6 +53,12 @@ public class CustomGuiTexturedRect extends Gui implements IGuiComponent { this.height = height; this.textureX = textureX; this.textureY = textureY; + + if(texture.startsWith("https://")){ + TextureManager texturemanager = Minecraft.getMinecraft().getTextureManager(); + ITextureObject object = new ImageDownloadAlt(null, texture, SkinManager.field_152793_a, new ImageBufferDownloadAlt(false)); + texturemanager.loadTexture(this.texture, object); + } } public void setParent(GuiCustom parent) { diff --git a/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayLabel.java b/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayLabel.java index 74a47455a..741ee9ed9 100644 --- a/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayLabel.java +++ b/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayLabel.java @@ -27,14 +27,14 @@ import static org.lwjgl.opengl.GL11.GL_SRC_ALPHA; public class CustomOverlayLabel extends Gui implements IOverlayComponent { OverlayCustom parent; - int alignment; int id; - int x, y, width, height; String fullLabel; + int x, y, width, height, alignment; + float scale, rotation; int color; float alpha; - float scale; + int border = 2; boolean labelBgEnabled = true; boolean labelShadowEnabled = false; @@ -56,7 +56,7 @@ public class CustomOverlayLabel extends Gui implements IOverlayComponent { protected final ResourceLocation locationFontTexture; protected int[] charWidth = new int[256]; protected byte[] glyphWidth = new byte[65536]; - + private final int[] colorCode = new int[32]; private float red; private float green; @@ -66,10 +66,6 @@ public class CustomOverlayLabel extends Gui implements IOverlayComponent { private float posY; public CustomOverlayLabel(int id, String fullLabel, int x, int y, int width, int height, boolean shadow){ - locationFontTexture = new ResourceLocation("textures/font/ascii.png"); - readFontTexture(); - readGlyphSizes(); - this.id = id; this.fullLabel = fullLabel; this.x = x; @@ -77,6 +73,41 @@ public class CustomOverlayLabel extends Gui implements IOverlayComponent { this.width = width; this.height = height; this.labelShadowEnabled = shadow; + + locationFontTexture = new ResourceLocation("textures/font/ascii.png"); + readFontTexture(); + readGlyphSizes(); + for (int i = 0; i < 32; ++i) + { + int j = (i >> 3 & 1) * 85; + int k = (i >> 2 & 1) * 170 + j; + int l = (i >> 1 & 1) * 170 + j; + int i1 = (i >> 0 & 1) * 170 + j; + + if (i == 6) + { + k += 85; + } + + if (Minecraft.getMinecraft().gameSettings.anaglyph) + { + int j1 = (k * 30 + l * 59 + i1 * 11) / 100; + int k1 = (k * 30 + l * 70) / 100; + int l1 = (k * 30 + i1 * 70) / 100; + k = j1; + l = k1; + i1 = l1; + } + + if (i >= 16) + { + k /= 4; + l /= 4; + i1 /= 4; + } + + this.colorCode[i] = (k & 255) << 16 | (l & 255) << 8 | i1 & 255; + } } public void setParent(OverlayCustom parent) { @@ -99,12 +130,11 @@ public class CustomOverlayLabel extends Gui implements IOverlayComponent { CustomOverlayLabel lbl = new CustomOverlayLabel(component.getID(), component.getText(), component.getPosX(), component.getPosY(), component.getWidth(), component.getHeight(), component.getShadow()); lbl.scale = 1.0F; lbl.color = component.getColor(); - lbl.setScale(component.getScale()); - lbl.labelShadowEnabled = component.getShadow(); lbl.alignment = component.getAlignment(); lbl.alpha = component.getAlpha(); - lbl.color = component.getColor(); + lbl.rotation = component.getRotation(); + lbl.setScale(component.getScale()); return lbl; } @@ -115,6 +145,7 @@ public class CustomOverlayLabel extends Gui implements IOverlayComponent { component.setAlignment(alignment); component.setAlpha(alpha); component.setColor(color); + component.setRotation(rotation); return component; } @@ -129,6 +160,7 @@ public class CustomOverlayLabel extends Gui implements IOverlayComponent { blue = (color & 255) / 255f; GL11.glTranslatef(this.x,this.y,0.0F); + GL11.glRotated(rotation,0.0D,0.0D,1.0D); GL11.glScalef(this.scale, this.scale, this.scale); this.drawString(fullLabel, 0, 0, this.color, this.labelShadowEnabled); GL11.glPopMatrix(); @@ -194,7 +226,27 @@ public class CustomOverlayLabel extends Gui implements IOverlayComponent { { j = "0123456789abcdefklmnor".indexOf(p_78255_1_.toLowerCase().charAt(i + 1)); - if (j == 16) + if(j < 16){ + this.randomStyle = false; + this.boldStyle = false; + this.strikethroughStyle = false; + this.underlineStyle = false; + this.italicStyle = false; + + if (j < 0 || j > 15) + { + j = 15; + } + + if (p_78255_2_) + { + j += 16; + } + + k = this.colorCode[j]; + setColor((float)(k >> 16) / 255.0F, (float)(k >> 8 & 255) / 255.0F, (float)(k & 255) / 255.0F, this.alpha); + } + else if (j == 16) { this.randomStyle = true; } @@ -399,7 +451,7 @@ public class CustomOverlayLabel extends Gui implements IOverlayComponent { protected void setColor(float r, float g, float b, float a) { - GL11.glColor4f(r, g, b, alpha); + GL11.glColor4f(r, g, b, a); } protected void bindTexture(ResourceLocation location) diff --git a/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayLine.java b/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayLine.java index eef06f3ff..be019ee22 100644 --- a/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayLine.java +++ b/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayLine.java @@ -26,6 +26,7 @@ public class CustomOverlayLine extends Gui implements IOverlayComponent { int color; int thickness; float alpha; + float rotation; public CustomOverlayLine(int id, int x1, int y1, int x2, int y2, int color, int thickness){ this.id = id; @@ -58,6 +59,7 @@ public class CustomOverlayLine extends Gui implements IOverlayComponent { GL11.glTranslatef(this.x1,this.y1,0.0F); GL11.glRotated(-Math.toDegrees(Math.atan2(x2-x1,y2-y1)),0.0F,0.0F,1.0F); + GL11.glRotated(rotation,0.0D,0.0D,1.0D); GL11.glScaled(thickness, distance,0.0D); int p_73729_1_ = 0; @@ -86,6 +88,7 @@ public class CustomOverlayLine extends Gui implements IOverlayComponent { line.setAlignment(alignment); line.setAlpha(alpha); line.setColor(color); + line.setRotation(rotation); return line; } @@ -94,6 +97,7 @@ public class CustomOverlayLine extends Gui implements IOverlayComponent { line.alignment = component.getAlignment(); line.alpha = component.getAlpha(); line.color = component.getColor(); + line.rotation = component.getRotation(); return line; } diff --git a/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayTexturedRect.java b/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayTexturedRect.java index 8447964b5..06867b921 100644 --- a/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayTexturedRect.java +++ b/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayTexturedRect.java @@ -4,9 +4,14 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.texture.ITextureObject; +import net.minecraft.client.renderer.texture.TextureManager; +import net.minecraft.client.resources.SkinManager; import net.minecraft.util.ResourceLocation; +import noppes.npcs.client.ImageDownloadAlt; import noppes.npcs.client.gui.customoverlay.OverlayCustom; import noppes.npcs.client.gui.customoverlay.interfaces.IOverlayComponent; +import noppes.npcs.client.renderer.ImageBufferDownloadAlt; import noppes.npcs.scripted.interfaces.ICustomOverlayComponent; import noppes.npcs.scripted.overlay.ScriptOverlayTexturedRect; import org.lwjgl.opengl.GL11; @@ -30,6 +35,7 @@ public class CustomOverlayTexturedRect extends Gui implements IOverlayComponent int color; float alpha; + float rotation; public CustomOverlayTexturedRect(int id, String texture, int x, int y, int width, int height) { this(id, texture, x, y, width, height, 0, 0); @@ -46,6 +52,12 @@ public class CustomOverlayTexturedRect extends Gui implements IOverlayComponent this.height = height; this.textureX = textureX; this.textureY = textureY; + + if(texture.startsWith("https://")){ + TextureManager texturemanager = Minecraft.getMinecraft().getTextureManager(); + ITextureObject object = new ImageDownloadAlt(null, texture, SkinManager.field_152793_a, new ImageBufferDownloadAlt(false)); + texturemanager.loadTexture(this.texture, object); + } } public void setParent(OverlayCustom parent) { @@ -68,6 +80,8 @@ public class CustomOverlayTexturedRect extends Gui implements IOverlayComponent GL11.glScalef(this.scale, this.scale, this.scale); + GL11.glRotatef(this.rotation,0.0F,0.0F,1.0F); + int p_73729_1_ = (int) (this.x/this.scale); int p_73729_2_ = (int) (this.y/this.scale); int p_73729_3_ = this.textureX; @@ -95,6 +109,7 @@ public class CustomOverlayTexturedRect extends Gui implements IOverlayComponent component.setAlignment(alignment); component.setAlpha(alpha); component.setColor(color); + component.setRotation(rotation); return component; } @@ -110,6 +125,7 @@ public class CustomOverlayTexturedRect extends Gui implements IOverlayComponent rect.alignment = component.getAlignment(); rect.alpha = component.getAlpha(); rect.color = component.getColor(); + rect.rotation = component.getRotation(); return rect; } diff --git a/src/main/java/noppes/npcs/scripted/interfaces/ICustomOverlayComponent.java b/src/main/java/noppes/npcs/scripted/interfaces/ICustomOverlayComponent.java index 806983ba1..7abb2155d 100644 --- a/src/main/java/noppes/npcs/scripted/interfaces/ICustomOverlayComponent.java +++ b/src/main/java/noppes/npcs/scripted/interfaces/ICustomOverlayComponent.java @@ -22,4 +22,8 @@ public interface ICustomOverlayComponent { float getAlpha(); void setAlpha(float alpha); + + float getRotation(); + + void setRotation(float rotation); } diff --git a/src/main/java/noppes/npcs/scripted/overlay/ScriptOverlayComponent.java b/src/main/java/noppes/npcs/scripted/overlay/ScriptOverlayComponent.java index edbcab83d..88aa3f396 100644 --- a/src/main/java/noppes/npcs/scripted/overlay/ScriptOverlayComponent.java +++ b/src/main/java/noppes/npcs/scripted/overlay/ScriptOverlayComponent.java @@ -15,6 +15,7 @@ public abstract class ScriptOverlayComponent implements ICustomOverlayComponent int alignment = 0; int color = 0xFFFFFF; float alpha = 1.0F; + float rotation = 0; /* ========ALIGNMENTS======== 0 1 2 @@ -74,6 +75,14 @@ public abstract class ScriptOverlayComponent implements ICustomOverlayComponent this.alpha = alpha; } + public float getRotation() { + return rotation; + } + + public void setRotation(float rotation) { + this.rotation = rotation; + } + public abstract int getType(); public NBTTagCompound toNBT(NBTTagCompound nbt) { @@ -82,6 +91,7 @@ public abstract class ScriptOverlayComponent implements ICustomOverlayComponent nbt.setInteger("alignment",this.alignment); nbt.setInteger("color", this.color); nbt.setFloat("alpha",this.alpha); + nbt.setFloat("rotation",this.rotation); nbt.setInteger("type", this.getType()); return nbt; @@ -93,6 +103,7 @@ public abstract class ScriptOverlayComponent implements ICustomOverlayComponent this.setAlignment(nbt.getInteger("alignment")); this.setColor(nbt.getInteger("color")); this.setAlpha(nbt.getFloat("alpha")); + this.setRotation(nbt.getInteger("rotation")); return this; }