CustomGuiTexturedRect:

-Fixed uv values for textures.

CustomGuiButton:
-Fixed hover text
This commit is contained in:
c0508383 committed 2022-07-20 15:17:16 -05:00
1 parent 8cda6fbea8
commit 95f889f92b
6 files changed
+88 -36

No files matched your search

@@ -90,8 +90,6 @@ public class CustomGuiButton extends GuiButton implements IClickListener {
}
public void onRender(Minecraft mc, int mouseX, int mouseY, int mouseWheel, float partialTicks) {
//GL11.func_179094_E();
//GL11.func_179109_b(0.0F, 0.0F, (float)this.id);
GL11.glPushMatrix();
float red = (color >> 16 & 255) / 255f;
float green = (color >> 8 & 255) / 255f;
@@ -131,11 +129,12 @@ public class CustomGuiButton extends GuiButton implements IClickListener {
//GL11.func_187401_a(SourceFactor.SRC_ALPHA, DestFactor.ONE_MINUS_SRC_ALPHA);
this.drawTexturedModalRect(this.xPosition, this.yPosition, this.textureX, this.textureY + i * this.height, this.width, this.height);
this.drawCenteredString(fontRenderer, this.label, this.xPosition + this.width / 2, this.yPosition + (this.height - 8) / 2, this.color);
if (this.field_146123_n && this.hoverText != null && this.hoverText.length > 0) {
this.parent.hoverText = this.hoverText;
}
}
GL11.glPopMatrix();
if (this.field_146123_n && this.hoverText != null && this.hoverText.length > 0) {
this.parent.hoverText = this.hoverText;
}
}
public ICustomGuiComponent toComponent() {
@@ -116,7 +116,10 @@ public class CustomGuiLabel extends Gui implements IGuiComponent {
public void onRender(Minecraft mc, int mouseX, int mouseY, int mouseWheel, float partialTicks) {
boolean hovered = mouseX >= this.x && mouseY >= this.y && mouseX < this.x + this.field_146167_a && mouseY < this.y + this.field_146161_f;
GL11.glPushMatrix();
GL11.glTranslatef(0.0F,0.0F,(float)this.id);
this.drawLabel();
GL11.glPopMatrix();
if (hovered && this.hoverText != null && this.hoverText.length > 0) {
this.parent.hoverText = this.hoverText;
}
@@ -50,7 +50,7 @@ public class CustomGuiLine extends Gui implements IGuiComponent {
float blue = (color & 255) / 255f;
GL11.glColor4f(red,green,blue,this.alpha);
GL11.glTranslatef(GuiCustom.guiLeft+this.x1,GuiCustom.guiTop+this.y1,0.0F);
GL11.glTranslatef(GuiCustom.guiLeft+this.x1,GuiCustom.guiTop+this.y1,(float)this.id);
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);
@@ -23,17 +23,10 @@ import org.lwjgl.opengl.GL11;
public class CustomGuiScrollComponent extends GuiCustomScroll implements IDataHolder, IClickListener {
GuiCustom parent;
String[] hoverText;
public boolean multiSelect = false;
public boolean multiSelect;
int color;
float alpha;
public CustomGuiScrollComponent(Minecraft mc, GuiScreen parent, int id) {
super(parent, id);
this.mc = mc;
this.fontRendererObj = mc.fontRenderer;
}
public CustomGuiScrollComponent(Minecraft mc, GuiScreen parent, int id, boolean multiSelect) {
super(parent, id, multiSelect);
this.mc = mc;
@@ -40,7 +40,10 @@ public class CustomGuiTextField extends GuiTextField implements IKeyListener, ID
float green = (color >> 8 & 255) / 255f;
float blue = (color & 255) / 255f;
GL11.glColor4f(red,green,blue,this.alpha);
GL11.glPushMatrix();
GL11.glTranslatef(0.0F,0.0F,(float)this.id);
this.drawTextBox();
GL11.glPopMatrix();
GL11.glColor4f(1.0F,1.0F,1.0F,1.0F);
if (hovered && this.hoverText != null && this.hoverText.length > 0) {
this.parent.hoverText = this.hoverText;
@@ -10,6 +10,7 @@ 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.IResource;
import net.minecraft.util.ResourceLocation;
import noppes.npcs.client.ImageDownloadAlt;
import noppes.npcs.client.gui.custom.GuiCustom;
@@ -19,9 +20,14 @@ import noppes.npcs.scripted.gui.ScriptGuiTexturedRect;
import noppes.npcs.scripted.interfaces.gui.ICustomGuiComponent;
import org.lwjgl.opengl.GL11;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
public class CustomGuiTexturedRect extends Gui implements IGuiComponent {
GuiCustom parent;
ResourceLocation texture;
ResourceLocation location;
int id;
int x;
int y;
@@ -36,14 +42,19 @@ public class CustomGuiTexturedRect extends Gui implements IGuiComponent {
float alpha;
float rotation;
private int totalWidth, totalHeight;
private ImageDownloadAlt imageDownloadAlt = null;
private boolean isUrl = false;
private boolean gotWidthHeight = false;
public CustomGuiTexturedRect(int id, String texture, int x, int y, int width, int height) {
this(id, texture, x, y, width, height, 0, 0);
}
public CustomGuiTexturedRect(int id, String texture, int x, int y, int width, int height, int textureX, int textureY) {
public CustomGuiTexturedRect(int id, String directory, int x, int y, int width, int height, int textureX, int textureY) {
this.scale = 1.0F;
this.id = id;
this.texture = new ResourceLocation(texture);
this.location = new ResourceLocation(directory);
this.x = x;
this.y = y;
this.width = width;
@@ -51,10 +62,17 @@ public class CustomGuiTexturedRect extends Gui implements IGuiComponent {
this.textureX = textureX;
this.textureY = textureY;
if(texture.startsWith("https://")){
if(directory.startsWith("https://")){
this.isUrl = true;
TextureManager texturemanager = Minecraft.getMinecraft().getTextureManager();
ITextureObject object = new ImageDownloadAlt(null, texture, new ResourceLocation("customnpcs:textures/gui/invisible.png"), new ImageBufferDownloadAlt(true,false));
texturemanager.loadTexture(this.texture, object);
this.imageDownloadAlt = new ImageDownloadAlt(null, directory, new ResourceLocation("customnpcs:textures/gui/invisible.png"), new ImageBufferDownloadAlt(true,false));
texturemanager.loadTexture(this.location, this.imageDownloadAlt);
} else {
try {
this.getWidthHeight();
} catch (IOException e) {
e.printStackTrace();
}
}
}
@@ -68,7 +86,16 @@ public class CustomGuiTexturedRect extends Gui implements IGuiComponent {
public void onRender(Minecraft mc, int mouseX, int mouseY, int mouseWheel, float partialTicks) {
boolean hovered = mouseX >= this.x + GuiCustom.guiLeft && mouseY >= this.y + GuiCustom.guiTop && mouseX < this.x + GuiCustom.guiLeft + this.width && mouseY < this.y + GuiCustom.guiTop + this.height;
mc.getTextureManager().bindTexture(this.texture);
mc.getTextureManager().bindTexture(this.location);
float u1 = (float)textureX/(float)totalWidth;
float u2 = u1 + (float)width/(float)totalWidth;
float v1 = (float)textureY/(float)totalHeight;
float v2 = v1 + (float)height/(float)totalHeight;
if(imageDownloadAlt != null && isUrl && !gotWidthHeight){
getURLWidthHeight();
}
GL11.glPushMatrix();
float red = (color >> 16 & 255) / 255f;
@@ -76,27 +103,18 @@ public class CustomGuiTexturedRect extends Gui implements IGuiComponent {
float blue = (color & 255) / 255f;
GL11.glColor4f(red,green,blue,this.alpha);
GL11.glTranslatef(GuiCustom.guiLeft,GuiCustom.guiTop,0.0F);
GL11.glTranslatef(GuiCustom.guiLeft + this.x - u1 * totalWidth, GuiCustom.guiTop + this.y - v1 * totalHeight,(float)this.id);
GL11.glRotatef(this.rotation,0.0F,0.0F,1.0F);
GL11.glScalef(this.scale, this.scale, this.scale);
int p_73729_1_ = (int) (this.x/this.scale);
int p_73729_2_ = (int) (this.y/this.scale);
int p_73729_3_ = this.textureX;
int p_73729_4_ = this.textureY;
int p_73729_5_ = (int)(this.width);
int p_73729_6_ = (int)(this.height);
float f = 0.00390625F;
float f1 = 0.00390625F;
Tessellator tessellator = Tessellator.instance;
tessellator.startDrawingQuads();
tessellator.setColorOpaque_F(1, 1, 1);
tessellator.setColorRGBA_F(red, green, blue, alpha);
tessellator.addVertexWithUV((double)(p_73729_1_ + 0), (double)(p_73729_2_ + p_73729_6_), (double)this.zLevel, (double)((float)(p_73729_3_ + 0) * f), (double)((float)(p_73729_4_ + p_73729_6_) * f1));
tessellator.addVertexWithUV((double)(p_73729_1_ + p_73729_5_), (double)(p_73729_2_ + p_73729_6_), (double)this.zLevel, (double)((float)(p_73729_3_ + p_73729_5_) * f), (double)((float)(p_73729_4_ + p_73729_6_) * f1));
tessellator.addVertexWithUV((double)(p_73729_1_ + p_73729_5_), (double)(p_73729_2_ + 0), (double)this.zLevel, (double)((float)(p_73729_3_ + p_73729_5_) * f), (double)((float)(p_73729_4_ + 0) * f1));
tessellator.addVertexWithUV((double)(p_73729_1_ + 0), (double)(p_73729_2_ + 0), (double)this.zLevel, (double)((float)(p_73729_3_ + 0) * f), (double)((float)(p_73729_4_ + 0) * f1));
tessellator.addVertexWithUV( u2 * totalWidth, v2 * totalHeight, 0, u2, v2);
tessellator.addVertexWithUV( u2 * totalWidth, v1 * totalHeight, 0, u2, v1);
tessellator.addVertexWithUV( u1 * totalWidth, v1 * totalHeight, 0, u1, v1);
tessellator.addVertexWithUV( u1 * totalWidth, v2 * totalHeight, 0, u1, v2);
tessellator.draw();
GL11.glPopMatrix();
@@ -106,7 +124,7 @@ public class CustomGuiTexturedRect extends Gui implements IGuiComponent {
}
public ICustomGuiComponent toComponent() {
ScriptGuiTexturedRect component = new ScriptGuiTexturedRect(this.id, this.texture.toString(), this.x, this.y, this.width, this.height, this.textureX, this.textureY);
ScriptGuiTexturedRect component = new ScriptGuiTexturedRect(this.id, this.location.toString(), this.x, this.y, this.width, this.height, this.textureX, this.textureY);
component.setHoverText(this.hoverText);
component.setScale(this.scale);
component.setColor(color);
@@ -134,4 +152,40 @@ public class CustomGuiTexturedRect extends Gui implements IGuiComponent {
return rect;
}
public void getWidthHeight() throws IOException {
InputStream inputstream = null;
try {
IResource iresource = Minecraft.getMinecraft().getResourceManager().getResource(this.location);
inputstream = iresource.getInputStream();
BufferedImage bufferedimage = ImageIO.read(inputstream);
gotWidthHeight = true;
this.totalWidth = bufferedimage.getWidth();
this.totalHeight = bufferedimage.getHeight();
correctWidthHeight();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (inputstream != null) {
inputstream.close();
}
}
}
public void getURLWidthHeight(){
if(imageDownloadAlt.getBufferedImage() != null) {
gotWidthHeight = true;
this.totalWidth = imageDownloadAlt.getBufferedImage().getWidth();
this.totalHeight = imageDownloadAlt.getBufferedImage().getHeight();
correctWidthHeight();
}
}
public void correctWidthHeight(){
totalWidth = Math.max(totalWidth, 1);
totalHeight = Math.max(totalHeight, 1);
this.width = width < 0 ? totalWidth : width;
this.height = height < 0 ? totalHeight : height;
}
}