mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-22 22:29:50 +00:00
Fixed dialog image size issue. Dialog images can also use URLs now.
This commit is contained in:
1 parent
cc39e62bd4
commit
4b1fb37366
2 files changed
+100
-24
No files matched your search
@@ -5,6 +5,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.customoverlay.OverlayCustom;
|
||||
@@ -12,6 +13,11 @@ import noppes.npcs.client.renderer.ImageBufferDownloadAlt;
|
||||
import noppes.npcs.controllers.data.DialogImage;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class GuiDialogImage extends Gui {
|
||||
GuiDialogInteract parent;
|
||||
ResourceLocation location;
|
||||
@@ -34,6 +40,11 @@ public class GuiDialogImage extends Gui {
|
||||
public int imageType = 0; //0 - Default, 1 - Text, 2 - Option
|
||||
public int alignment = 0;
|
||||
|
||||
private int totalWidth, totalHeight;
|
||||
private ImageDownloadAlt imageDownloadAlt = null;
|
||||
private boolean isUrl = false;
|
||||
private boolean gotWidthHeight = false;
|
||||
|
||||
public GuiDialogImage(DialogImage dialogImage) {
|
||||
this.location = new ResourceLocation(dialogImage.texture);
|
||||
|
||||
@@ -56,9 +67,16 @@ public class GuiDialogImage extends Gui {
|
||||
this.alignment = dialogImage.alignment;
|
||||
|
||||
if(texture.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.location, object);
|
||||
this.imageDownloadAlt = new ImageDownloadAlt(null, texture, 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,6 +93,15 @@ public class GuiDialogImage extends Gui {
|
||||
mc.getTextureManager().bindTexture(this.location);
|
||||
} catch (Exception ignored) { return; }
|
||||
|
||||
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;
|
||||
float green = (color >> 8 & 255) / 255f;
|
||||
@@ -84,24 +111,51 @@ public class GuiDialogImage extends Gui {
|
||||
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();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user