From 534f716991833c6cfde46056cc5a97542c29cf7e Mon Sep 17 00:00:00 2001 From: luisc Date: Sun, 30 Jan 2022 04:05:01 -0600 Subject: [PATCH] Implemented Scripted Overlays which stay on the player's screen. Overlays persist in the client, and can be removed from the screen as well. --- src/main/java/noppes/npcs/client/Client.java | 3 + .../npcs/client/ClientEventHandler.java | 11 +- .../npcs/client/PacketHandlerClient.java | 11 ++ .../gui/custom/components/CustomGuiLabel.java | 1 - .../gui/custom/components/CustomGuiLine.java | 13 +- .../gui/customoverlay/OverlayCustom.java | 104 +++++++++++ .../components/CustomOverlayLabel.java | 125 ++++++++++++++ .../components/CustomOverlayLine.java | 73 ++++++++ .../components/CustomOverlayTexturedRect.java | 83 +++++++++ .../interfaces/IOverlayComponent.java | 7 + .../npcs/client/renderer/RenderCustomNpc.java | 2 - .../npcs/constants/EnumPacketClient.java | 2 +- .../npcs/controllers/CustomGuiController.java | 13 +- .../npcs/scripted/entity/ScriptPlayer.java | 16 +- .../scripted/interfaces/ICustomOverlay.java | 4 + .../interfaces/ICustomOverlayComponent.java | 17 ++ .../scripted/interfaces/IOverlayLabel.java | 21 +++ .../scripted/interfaces/IOverlayLine.java | 17 ++ .../interfaces/IOverlayTexturedRect.java | 23 +++ .../npcs/scripted/overlay/ScriptOverlay.java | 161 ++++++++++++++++++ .../overlay/ScriptOverlayComponent.java | 88 ++++++++++ .../scripted/overlay/ScriptOverlayLabel.java | 109 ++++++++++++ .../scripted/overlay/ScriptOverlayLine.java | 106 ++++++++++++ .../overlay/ScriptOverlayTexturedRect.java | 109 ++++++++++++ .../npcs/scripted/wrapper/WrapperNpcAPI.java | 5 + 25 files changed, 1105 insertions(+), 19 deletions(-) create mode 100644 src/main/java/noppes/npcs/client/gui/customoverlay/OverlayCustom.java create mode 100644 src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayLabel.java create mode 100644 src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayLine.java create mode 100644 src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayTexturedRect.java create mode 100644 src/main/java/noppes/npcs/client/gui/customoverlay/interfaces/IOverlayComponent.java create mode 100644 src/main/java/noppes/npcs/scripted/interfaces/ICustomOverlay.java create mode 100644 src/main/java/noppes/npcs/scripted/interfaces/ICustomOverlayComponent.java create mode 100644 src/main/java/noppes/npcs/scripted/interfaces/IOverlayLabel.java create mode 100644 src/main/java/noppes/npcs/scripted/interfaces/IOverlayLine.java create mode 100644 src/main/java/noppes/npcs/scripted/interfaces/IOverlayTexturedRect.java create mode 100644 src/main/java/noppes/npcs/scripted/overlay/ScriptOverlay.java create mode 100644 src/main/java/noppes/npcs/scripted/overlay/ScriptOverlayComponent.java create mode 100644 src/main/java/noppes/npcs/scripted/overlay/ScriptOverlayLabel.java create mode 100644 src/main/java/noppes/npcs/scripted/overlay/ScriptOverlayLine.java create mode 100644 src/main/java/noppes/npcs/scripted/overlay/ScriptOverlayTexturedRect.java diff --git a/src/main/java/noppes/npcs/client/Client.java b/src/main/java/noppes/npcs/client/Client.java index 7d57987b3..cb37e5d72 100644 --- a/src/main/java/noppes/npcs/client/Client.java +++ b/src/main/java/noppes/npcs/client/Client.java @@ -4,13 +4,16 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import java.io.IOException; +import java.util.HashMap; import noppes.npcs.CustomNpcs; import noppes.npcs.Server; +import noppes.npcs.client.gui.customoverlay.OverlayCustom; import noppes.npcs.constants.EnumPacketServer; import cpw.mods.fml.common.network.internal.FMLProxyPacket; public class Client { + public static HashMap customOverlays = new HashMap<>(); public static void sendData(EnumPacketServer enu, Object... obs) { ByteBuf buffer = Unpooled.buffer(); diff --git a/src/main/java/noppes/npcs/client/ClientEventHandler.java b/src/main/java/noppes/npcs/client/ClientEventHandler.java index 919318be6..6c1bbc382 100644 --- a/src/main/java/noppes/npcs/client/ClientEventHandler.java +++ b/src/main/java/noppes/npcs/client/ClientEventHandler.java @@ -1,5 +1,14 @@ package noppes.npcs.client; -public class ClientEventHandler { +import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.client.event.RenderGameOverlayEvent; +import noppes.npcs.client.gui.customoverlay.OverlayCustom; +public class ClientEventHandler { + @SubscribeEvent + public void onOverlayRender(RenderGameOverlayEvent.Pre event){ + for(OverlayCustom overlayCustom : Client.customOverlays.values()){ + overlayCustom.renderGameOverlay(event.partialTicks); + } + } } diff --git a/src/main/java/noppes/npcs/client/PacketHandlerClient.java b/src/main/java/noppes/npcs/client/PacketHandlerClient.java index 138958ed4..ea6c4891c 100644 --- a/src/main/java/noppes/npcs/client/PacketHandlerClient.java +++ b/src/main/java/noppes/npcs/client/PacketHandlerClient.java @@ -26,6 +26,7 @@ import noppes.npcs.ServerEventsHandler; import noppes.npcs.client.ClientProxy.FontContainer; import noppes.npcs.client.controllers.MusicController; import noppes.npcs.client.gui.GuiNpcMobSpawnerAdd; +import noppes.npcs.client.gui.customoverlay.OverlayCustom; import noppes.npcs.client.gui.player.GuiBook; import noppes.npcs.client.gui.util.GuiContainerNPCInterface; import noppes.npcs.client.gui.util.GuiNPCInterface; @@ -259,5 +260,15 @@ public class PacketHandlerClient extends PacketHandlerServer{ NoppesUtil.isGUIOpen(isGUIOpen); } + else if(type == EnumPacketClient.OVERLAY_DATA){ + OverlayCustom overlayCustom = new OverlayCustom(Minecraft.getMinecraft()); + overlayCustom.setOverlayData(Server.readNBT(buffer)); + + Client.customOverlays.put(overlayCustom.overlay.getID(),overlayCustom); + } + else if(type == EnumPacketClient.OVERLAY_CLOSE){ + int id = buffer.readInt(); + Client.customOverlays.remove(id); + } } } 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 31eb61e01..1a7085efe 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 @@ -44,7 +44,6 @@ public class CustomGuiLabel extends Gui implements IGuiComponent { private int field_146165_q; private FontRenderer field_146164_r; private int field_146163_s; - private static final String __OBFID = "CL_00000671"; public CustomGuiLabel(int id, String fullLabel, int x, int y, int width, int height, boolean shadow){ this.id = id; diff --git a/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiLine.java b/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiLine.java index 03685e9db..5bfcfe404 100644 --- a/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiLine.java +++ b/src/main/java/noppes/npcs/client/gui/custom/components/CustomGuiLine.java @@ -41,16 +41,17 @@ public class CustomGuiLine extends Gui implements IGuiComponent { public void onRender(Minecraft mc, int mouseX, int mouseY, int mouseWheel, float partialTicks) { double distance = Math.sqrt(Math.pow(x1-x2,2)+Math.pow(y1-y2,2)); - float particleRed = (color >> 16 & 255) / 255f; - float particleGreen = (color >> 8 & 255) / 255f; - float particleBlue = (color & 255) / 255f; + float red = (color >> 16 & 255) / 255f; + float green = (color >> 8 & 255) / 255f; + float blue = (color & 255) / 255f; mc.getTextureManager().bindTexture(new ResourceLocation("customnpcs:textures/gui/misc.png")); GL11.glPushMatrix(); - GL11.glColor4f(particleRed,particleGreen,particleBlue,1.0F); + GL11.glColor4f(red,green,blue,1.0F); GL11.glTranslatef(this.x1,this.y1,0.0F); - GL11.glRotatef((float) (Math.sin((x1-x2)/distance)*180/Math.PI),0.0F,0.0F,1.0F); - this.drawTexturedModalRect((int) -Math.ceil((double)thickness/2),0,0,0, thickness, (int) distance); + GL11.glRotated(-Math.toDegrees(Math.atan2(x2-x1,y2-y1)),0.0F,0.0F,1.0F); + GL11.glScaled(thickness, distance,0.0D); + this.drawTexturedModalRect(0,0,0,0, 1, 1); GL11.glPopMatrix(); } diff --git a/src/main/java/noppes/npcs/client/gui/customoverlay/OverlayCustom.java b/src/main/java/noppes/npcs/client/gui/customoverlay/OverlayCustom.java new file mode 100644 index 000000000..9c4d17fb5 --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/customoverlay/OverlayCustom.java @@ -0,0 +1,104 @@ +package noppes.npcs.client.gui.customoverlay; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Gui; +import net.minecraft.client.gui.ScaledResolution; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.ResourceLocation; +import noppes.npcs.client.gui.customoverlay.components.CustomOverlayLabel; +import noppes.npcs.client.gui.customoverlay.components.CustomOverlayLine; +import noppes.npcs.client.gui.customoverlay.components.CustomOverlayTexturedRect; +import noppes.npcs.client.gui.customoverlay.interfaces.IOverlayComponent; +import noppes.npcs.scripted.interfaces.ICustomOverlayComponent; +import noppes.npcs.scripted.overlay.*; +import org.lwjgl.opengl.GL11; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +public class OverlayCustom extends Gui { + protected final Minecraft mc; + + private ScaledResolution res = null; + public static int scaledWidth = 0; + public static int scaledHeight = 0; + + public ScriptOverlay overlay; + Map components = new HashMap(); + + float scale = 1.0F; + int x = 0; + int y = 0; + int textureX = 0; + int textureY = 0; + int width = 200; + int height = 200; + + public OverlayCustom(Minecraft mc) { + this.mc = mc; + } + + public void initOverlay(){ + res = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight); + if(this.overlay != null){ + scaledWidth = res.getScaledWidth(); + scaledHeight = res.getScaledHeight(); + + this.components.clear(); + Iterator var1 = this.overlay.getComponents().iterator(); + + while(var1.hasNext()) { + ICustomOverlayComponent c = (ICustomOverlayComponent)var1.next(); + this.addComponent(c); + } + } + } + + private void addComponent(ICustomOverlayComponent component) { + ScriptOverlayComponent c = (ScriptOverlayComponent)component; + switch(c.getType()) { + case 0: + CustomOverlayTexturedRect rect = CustomOverlayTexturedRect.fromComponent((ScriptOverlayTexturedRect) component); + rect.setParent(this); + this.components.put(rect.getID(), rect); + break; + case 1: + CustomOverlayLabel lbl = CustomOverlayLabel.fromComponent((ScriptOverlayLabel)component); + lbl.setParent(this); + this.components.put(lbl.getID(), lbl); + break; + case 2: + CustomOverlayLine line = CustomOverlayLine.fromComponent((ScriptOverlayLine) component); + line.setParent(this); + this.components.put(line.getID(), line); + break; + } + } + + public void renderGameOverlay(float partialTicks){ + res = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight); + scaledWidth = res.getScaledWidth(); + scaledHeight = res.getScaledHeight(); + + GL11.glPushMatrix(); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + GL11.glDisable(GL11.GL_BLEND); + + Iterator var4 = this.components.values().iterator(); + + while(var4.hasNext()) { + IOverlayComponent component = (IOverlayComponent)var4.next(); + component.onRender(this.mc, partialTicks); + } + + GL11.glEnable(GL11.GL_BLEND); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + GL11.glPopMatrix(); + } + + public void setOverlayData(NBTTagCompound compound) { + this.overlay = (ScriptOverlay)(new ScriptOverlay()).fromNBT(compound); + this.initOverlay(); + } +} 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 new file mode 100644 index 000000000..3095d31f7 --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayLabel.java @@ -0,0 +1,125 @@ +package noppes.npcs.client.gui.customoverlay.components; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.Gui; +import net.minecraft.client.renderer.OpenGlHelper; +import noppes.npcs.client.gui.custom.GuiCustom; +import noppes.npcs.client.gui.customoverlay.OverlayCustom; +import noppes.npcs.client.gui.customoverlay.interfaces.IOverlayComponent; +import noppes.npcs.scripted.interfaces.ICustomOverlayComponent; +import noppes.npcs.scripted.overlay.ScriptOverlayLabel; +import org.lwjgl.opengl.GL11; + +import java.util.ArrayList; + +public class CustomOverlayLabel extends Gui implements IOverlayComponent { + OverlayCustom parent; + int alignment; + int id; + + int x, y, width, height; + String fullLabel; + int color; + String[] hoverText; + float scale; + int border = 2; + boolean labelBgEnabled = true; + boolean labelShadowEnabled = false; + + protected int field_146167_a; + protected int field_146161_f; + public int field_146162_g; + public int field_146174_h; + private ArrayList field_146173_k; + private boolean field_146170_l; + public boolean field_146172_j; + private boolean field_146171_m; + private int field_146168_n; + private int field_146169_o; + private int field_146166_p; + private int field_146165_q; + private FontRenderer field_146164_r; + private int field_146163_s; + + public CustomOverlayLabel(int id, String fullLabel, int x, int y, int width, int height, boolean shadow){ + this.id = id; + this.fullLabel = fullLabel; + this.x = x; + this.y = y; + this.width = width; + this.height = height; + this.labelShadowEnabled = shadow; + } + + public void setParent(OverlayCustom parent) { + this.parent = parent; + } + + public void onRender(Minecraft mc, float partialTicks) { + this.drawLabel(); + } + + public int getID() { + return this.id; + } + + public void setScale(float scale) { + this.scale = scale; + } + + public static CustomOverlayLabel fromComponent(ScriptOverlayLabel component) { + CustomOverlayLabel lbl = new CustomOverlayLabel(component.getID(), component.getText(), GuiCustom.guiLeft + component.getPosX(), GuiCustom.guiTop + component.getPosY(), component.getWidth(), component.getHeight(), component.hasShadow()); + lbl.scale = 1.0F; + lbl.color = component.getColor(); + lbl.field_146172_j = true; + lbl.setScale(component.getScale()); + + lbl.labelShadowEnabled = component.hasShadow(); + lbl.alignment = component.getAlignment(); + + return lbl; + } + + public ICustomOverlayComponent toComponent() { + ScriptOverlayLabel component = new ScriptOverlayLabel(this.id, this.fullLabel, this.field_146162_g, this.field_146174_h, this.field_146167_a, this.field_146161_f, this.color); + component.enableShadow(this.labelShadowEnabled); + component.setAlignment(alignment); + return component; + } + + public void drawLabel() + { + if (this.field_146172_j) + { + GL11.glEnable(GL11.GL_BLEND); + OpenGlHelper.glBlendFunc(770, 771, 1, 0); + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + + this.drawLabelBackground(); + GL11.glPushMatrix(); + GL11.glTranslatef(this.alignment%3*((float)(OverlayCustom.scaledWidth)/2), (float) (Math.floor((float)(alignment/3))*((float)(OverlayCustom.scaledHeight)/2)),0.0F);//alignment%3 * width/2 Math.floor(alignment/3) * height/2 + + GL11.glTranslatef(this.x,this.y,0.0F); + GL11.glScalef(this.scale, this.scale, this.scale); + Minecraft.getMinecraft().fontRenderer.drawString(fullLabel, 0, 0, this.color, this.labelShadowEnabled); + GL11.glPopMatrix(); + } + } + + protected void drawLabelBackground() + { + if (this.labelBgEnabled) + { + int k = (int)(this.width*this.scale) + this.border * 2; + int l = (int)(this.height*this.scale) + this.border * 2; + int i1 = this.x - this.border; + int j1 = this.y - this.border; + drawRect(i1, j1, i1 + k, j1 + l, this.color);//backColor + this.drawHorizontalLine(i1, i1 + k, j1, this.color);//ulColor + this.drawHorizontalLine(i1, i1 + k, j1 + l, this.color);//brColor + this.drawVerticalLine(i1, j1, j1 + l, this.color);//ulColor + this.drawVerticalLine(i1 + k, j1, j1 + l, this.color);//brColor + } + } +} 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 new file mode 100644 index 000000000..28b020a21 --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayLine.java @@ -0,0 +1,73 @@ +package noppes.npcs.client.gui.customoverlay.components; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Gui; +import net.minecraft.util.ResourceLocation; +import noppes.npcs.client.gui.customoverlay.OverlayCustom; +import noppes.npcs.client.gui.customoverlay.interfaces.IOverlayComponent; +import noppes.npcs.scripted.interfaces.ICustomOverlayComponent; +import noppes.npcs.scripted.overlay.ScriptOverlayLine; +import org.lwjgl.opengl.GL11; + +public class CustomOverlayLine extends Gui implements IOverlayComponent { + OverlayCustom parent; + int alignment; + int id; + + int x1; + int y1; + int x2; + int y2; + int color; + int thickness; + + public CustomOverlayLine(int id, int x1, int y1, int x2, int y2, int color, int thickness){ + this.id = id; + this.x1 = x1; + this.y1 = y1; + this.x2 = x2; + this.y2 = y2; + this.color = color; + this.thickness = thickness; + } + + public void setParent(OverlayCustom parent) { + this.parent = parent; + } + + public int getID() { + return this.id; + } + + public void onRender(Minecraft mc, float partialTicks) { + double distance = Math.hypot(x1-x2, y1-y2); + + float red = (color >> 16 & 255) / 255f; + float green = (color >> 8 & 255) / 255f; + float blue = (color & 255) / 255f; + + mc.getTextureManager().bindTexture(new ResourceLocation("customnpcs:textures/gui/misc.png")); + GL11.glPushMatrix(); + GL11.glTranslatef(this.alignment%3*((float)(OverlayCustom.scaledWidth)/2), (float) (Math.floor((float)(alignment/3))*((float)(OverlayCustom.scaledHeight)/2)),0.0F);//alignment%3 * width/2 Math.floor(alignment/3) * height/2 + + GL11.glColor4f(red,green,blue,1.0F); + 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.glScaled(thickness, distance,0.0D); + this.drawTexturedModalRect(0,0,0,0, 1, 1); + GL11.glPopMatrix(); + } + + public ICustomOverlayComponent toComponent() { + ScriptOverlayLine line = new ScriptOverlayLine(this.id, this.x1,this.y1,this.x2,this.y2,this.color,this.thickness); + line.setAlignment(alignment); + return line; + } + + public static CustomOverlayLine fromComponent(ScriptOverlayLine component) { + CustomOverlayLine line = new CustomOverlayLine(component.getID(), component.getX1(), component.getY1(), component.getX2(), component.getY2(), component.getColor(), component.getThickness()); + line.alignment = component.getAlignment(); + + 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 new file mode 100644 index 000000000..5d0b97ba5 --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/customoverlay/components/CustomOverlayTexturedRect.java @@ -0,0 +1,83 @@ +package noppes.npcs.client.gui.customoverlay.components; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Gui; +import net.minecraft.util.ResourceLocation; +import noppes.npcs.client.gui.customoverlay.OverlayCustom; +import noppes.npcs.client.gui.customoverlay.interfaces.IOverlayComponent; +import noppes.npcs.scripted.interfaces.ICustomOverlayComponent; +import noppes.npcs.scripted.overlay.ScriptOverlayTexturedRect; +import org.lwjgl.opengl.GL11; + +public class CustomOverlayTexturedRect extends Gui implements IOverlayComponent { + OverlayCustom parent; + int alignment; + int id; + + ResourceLocation texture; + int x; + int y; + int width; + int height; + int textureX; + int textureY; + float scale; + + public CustomOverlayTexturedRect(int id, String texture, int x, int y, int width, int height) { + this(id, texture, x, y, width, height, 0, 0); + } + + public CustomOverlayTexturedRect(int id, String texture, int x, int y, int width, int height, int textureX, int textureY) { + this.scale = 1.0F; + this.alignment = 0; + this.id = id; + this.texture = new ResourceLocation(texture); + this.x = x; + this.y = y; + this.width = width; + this.height = height; + this.textureX = textureX; + this.textureY = textureY; + } + + public void setParent(OverlayCustom parent) { + this.parent = parent; + } + + public int getID() { + return this.id; + } + + public void onRender(Minecraft mc, float partialTicks) { + mc.getTextureManager().bindTexture(this.texture); + + GL11.glPushMatrix(); + GL11.glTranslatef(this.alignment%3*((float)(OverlayCustom.scaledWidth)/2), (float) (Math.floor((float)(alignment/3))*((float)(OverlayCustom.scaledHeight)/2)),0.0F);//alignment%3 * width/2 Math.floor(alignment/3) * height/2 + + GL11.glColor4f(1.0F,1.0F,1.0F,1.0F); + GL11.glScalef(this.scale, this.scale, this.scale); + this.drawTexturedModalRect((int) (this.x/this.scale), (int) (this.y/this.scale), this.textureX, this.textureY, (int)(this.width), (int)(this.height)); + GL11.glPopMatrix(); + } + + public ICustomOverlayComponent toComponent() { + ScriptOverlayTexturedRect component = new ScriptOverlayTexturedRect(this.id, this.texture.toString(), this.x, this.y, this.width, this.height, this.textureX, this.textureY); + component.setScale(this.scale); + component.setAlignment(alignment); + return component; + } + + public static CustomOverlayTexturedRect fromComponent(ScriptOverlayTexturedRect component) { + CustomOverlayTexturedRect rect; + if (component.getTextureX() >= 0 && component.getTextureY() >= 0) { + rect = new CustomOverlayTexturedRect(component.getID(), component.getTexture(), component.getPosX(), component.getPosY(), component.getWidth(), component.getHeight(), component.getTextureX(), component.getTextureY()); + } else { + rect = new CustomOverlayTexturedRect(component.getID(), component.getTexture(), component.getPosX(), component.getPosY(), component.getWidth(), component.getHeight()); + } + + rect.scale = component.getScale(); + rect.alignment = component.getAlignment(); + + return rect; + } +} diff --git a/src/main/java/noppes/npcs/client/gui/customoverlay/interfaces/IOverlayComponent.java b/src/main/java/noppes/npcs/client/gui/customoverlay/interfaces/IOverlayComponent.java new file mode 100644 index 000000000..685cb46da --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/customoverlay/interfaces/IOverlayComponent.java @@ -0,0 +1,7 @@ +package noppes.npcs.client.gui.customoverlay.interfaces; + +import net.minecraft.client.Minecraft; + +public interface IOverlayComponent { + void onRender(Minecraft mc, float partialTicks); +} diff --git a/src/main/java/noppes/npcs/client/renderer/RenderCustomNpc.java b/src/main/java/noppes/npcs/client/renderer/RenderCustomNpc.java index 57e9dd460..51a0ff9aa 100644 --- a/src/main/java/noppes/npcs/client/renderer/RenderCustomNpc.java +++ b/src/main/java/noppes/npcs/client/renderer/RenderCustomNpc.java @@ -112,8 +112,6 @@ public class RenderCustomNpc extends RenderNPCHumanMale{ @Override public void doRender(EntityLiving entityliving, double d, double d1, double d2, float f, float f1){ - EntityNPCInterface npc = (EntityNPCInterface) entityliving; - super.doRender(entityliving, d, d1, d2, f, f1); } diff --git a/src/main/java/noppes/npcs/constants/EnumPacketClient.java b/src/main/java/noppes/npcs/constants/EnumPacketClient.java index c11a36d6e..243674a9a 100644 --- a/src/main/java/noppes/npcs/constants/EnumPacketClient.java +++ b/src/main/java/noppes/npcs/constants/EnumPacketClient.java @@ -1,6 +1,6 @@ package noppes.npcs.constants; public enum EnumPacketClient { - CHAT, MESSAGE, SYNCRECIPES_ADD, SYNCRECIPES_WORKBENCH, DIALOG, QUEST_COMPLETION, EDIT_NPC, PLAY_SOUND, PLAY_MUSIC, UPDATE_NPC, ROLE, GUI, SCRIPTED_PARTICLE, PARTICLE, DELETE_NPC, SCROLL_LIST, SCROLL_DATA, SCROLL_DATA_PART, SCROLL_SELECTED, GUI_REDSTONE, GUI_WAYPOINT, GUI_DATA, GUI_ERROR, GUI_CLOSE, VILLAGER_LIST, CHATBUBBLE, SYNCRECIPES_CARPENTRYBENCH, CLONE, OPEN_BOOK, DIALOG_DUMMY, CONFIG, ISGUIOPEN + CHAT, MESSAGE, SYNCRECIPES_ADD, SYNCRECIPES_WORKBENCH, DIALOG, QUEST_COMPLETION, EDIT_NPC, PLAY_SOUND, PLAY_MUSIC, UPDATE_NPC, ROLE, GUI, SCRIPTED_PARTICLE, PARTICLE, DELETE_NPC, SCROLL_LIST, SCROLL_DATA, SCROLL_DATA_PART, SCROLL_SELECTED, GUI_REDSTONE, GUI_WAYPOINT, GUI_DATA, GUI_ERROR, GUI_CLOSE, VILLAGER_LIST, CHATBUBBLE, SYNCRECIPES_CARPENTRYBENCH, CLONE, OPEN_BOOK, DIALOG_DUMMY, CONFIG, ISGUIOPEN, OVERLAY_DATA, OVERLAY_CLOSE } diff --git a/src/main/java/noppes/npcs/controllers/CustomGuiController.java b/src/main/java/noppes/npcs/controllers/CustomGuiController.java index edb1cf15c..53cbc932d 100644 --- a/src/main/java/noppes/npcs/controllers/CustomGuiController.java +++ b/src/main/java/noppes/npcs/controllers/CustomGuiController.java @@ -3,10 +3,7 @@ package noppes.npcs.controllers; import io.netty.buffer.ByteBuf; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.Container; import net.minecraft.nbt.NBTTagList; -import net.minecraft.nbt.NBTTagString; import noppes.npcs.CustomNpcs; import noppes.npcs.Server; import noppes.npcs.constants.EnumGuiType; @@ -18,6 +15,7 @@ import noppes.npcs.scripted.entity.ScriptPlayer; import noppes.npcs.scripted.event.CustomGuiEvent; import noppes.npcs.scripted.gui.ScriptGui; import noppes.npcs.scripted.interfaces.IItemStack; +import noppes.npcs.scripted.overlay.ScriptOverlay; import noppes.npcs.scripted.wrapper.WrapperNpcAPI; import java.io.IOException; @@ -42,6 +40,15 @@ public class CustomGuiController { } } + public static void openOverlay(ScriptPlayer player, ScriptOverlay gui) { + Server.sendData((EntityPlayerMP)player.getMCEntity(), EnumPacketClient.OVERLAY_DATA, new Object[]{gui.toNBT()}); + } + + public static boolean updateOverlay(ScriptPlayer player, ScriptOverlay gui) { + Server.sendData((EntityPlayerMP)player.getMCEntity(), EnumPacketClient.OVERLAY_DATA, new Object[]{gui.toNBT()}); + return true; + } + static boolean checkGui(CustomGuiEvent event) { EntityPlayer player = (EntityPlayer) event.player.getMCEntity(); if (!(player.openContainer instanceof ContainerCustomGui)) { diff --git a/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java b/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java index 042302d19..05d577214 100644 --- a/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java +++ b/src/main/java/noppes/npcs/scripted/entity/ScriptPlayer.java @@ -25,10 +25,8 @@ import noppes.npcs.scripted.constants.EntityType; import noppes.npcs.scripted.event.FactionEvent; import noppes.npcs.scripted.gui.ScriptGui; import noppes.npcs.scripted.handler.data.IQuest; -import noppes.npcs.scripted.interfaces.IContainer; -import noppes.npcs.scripted.interfaces.ICustomGui; -import noppes.npcs.scripted.interfaces.IPlayer; -import noppes.npcs.scripted.interfaces.ITimers; +import noppes.npcs.scripted.interfaces.*; +import noppes.npcs.scripted.overlay.ScriptOverlay; import noppes.npcs.util.ValueUtil; import java.util.ArrayList; @@ -459,7 +457,15 @@ public class ScriptPlayer extends ScriptLivingBase public void closeGui() { ((EntityPlayerMP)this.entity).closeContainer(); - Server.sendData((EntityPlayerMP)this.entity, EnumPacketClient.GUI_CLOSE, new Object[]{-1, new NBTTagCompound()}); + Server.sendData((EntityPlayerMP)this.entity, EnumPacketClient.GUI_CLOSE, -1, new NBTTagCompound()); + } + + public void showCustomOverlay(ICustomOverlay overlay) { + CustomGuiController.openOverlay(this, (ScriptOverlay) overlay); + } + + public void closeOverlay(int id) { + Server.sendData((EntityPlayerMP)this.entity, EnumPacketClient.OVERLAY_CLOSE, id, new NBTTagCompound()); } public IQuest[] getFinishedQuests() { diff --git a/src/main/java/noppes/npcs/scripted/interfaces/ICustomOverlay.java b/src/main/java/noppes/npcs/scripted/interfaces/ICustomOverlay.java new file mode 100644 index 000000000..d95a12598 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/ICustomOverlay.java @@ -0,0 +1,4 @@ +package noppes.npcs.scripted.interfaces; + +public interface ICustomOverlay { +} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/ICustomOverlayComponent.java b/src/main/java/noppes/npcs/scripted/interfaces/ICustomOverlayComponent.java new file mode 100644 index 000000000..49d81bf53 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/ICustomOverlayComponent.java @@ -0,0 +1,17 @@ +package noppes.npcs.scripted.interfaces; + +public interface ICustomOverlayComponent { + int getID(); + + ICustomOverlayComponent setID(int id); + + int getPosX(); + + int getPosY(); + + ICustomOverlayComponent setPos(int x, int y); + + int getAlignment(); + + void setAlignment(int alignment); +} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/IOverlayLabel.java b/src/main/java/noppes/npcs/scripted/interfaces/IOverlayLabel.java new file mode 100644 index 000000000..d2283c103 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/IOverlayLabel.java @@ -0,0 +1,21 @@ +package noppes.npcs.scripted.interfaces; + +public interface IOverlayLabel extends ICustomOverlayComponent { + String getText(); + + IOverlayLabel setText(String var1); + + int getWidth(); + + int getHeight(); + + IOverlayLabel setSize(int var1, int var2); + + int getColor(); + + IOverlayLabel setColor(int var1); + + float getScale(); + + IOverlayLabel setScale(float var1); +} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/IOverlayLine.java b/src/main/java/noppes/npcs/scripted/interfaces/IOverlayLine.java new file mode 100644 index 000000000..18a1c9b2a --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/IOverlayLine.java @@ -0,0 +1,17 @@ +package noppes.npcs.scripted.interfaces; + +public interface IOverlayLine extends ICustomOverlayComponent { + int getX1(); + int getY1(); + int getX2(); + int getY2(); + int getColor(); + int getThickness(); + + void setX1(int x1); + void setY1(int y1); + void setX2(int x2); + void setY2(int y2); + void setColor(int color); + void setThickness(int thickness); +} diff --git a/src/main/java/noppes/npcs/scripted/interfaces/IOverlayTexturedRect.java b/src/main/java/noppes/npcs/scripted/interfaces/IOverlayTexturedRect.java new file mode 100644 index 000000000..bd5b6a2d6 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/interfaces/IOverlayTexturedRect.java @@ -0,0 +1,23 @@ +package noppes.npcs.scripted.interfaces; + +public interface IOverlayTexturedRect extends ICustomOverlayComponent { + String getTexture(); + + IOverlayTexturedRect setTexture(String var1); + + int getWidth(); + + int getHeight(); + + IOverlayTexturedRect setSize(int var1, int var2); + + float getScale(); + + IOverlayTexturedRect setScale(float var1); + + int getTextureX(); + + int getTextureY(); + + IOverlayTexturedRect setTextureOffset(int var1, int var2); +} diff --git a/src/main/java/noppes/npcs/scripted/overlay/ScriptOverlay.java b/src/main/java/noppes/npcs/scripted/overlay/ScriptOverlay.java new file mode 100644 index 000000000..a3394a7eb --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/overlay/ScriptOverlay.java @@ -0,0 +1,161 @@ +package noppes.npcs.scripted.overlay; + +import net.minecraft.nbt.NBTBase; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import noppes.npcs.controllers.CustomGuiController; +import noppes.npcs.controllers.ScriptController; +import noppes.npcs.controllers.data.PlayerDataScript; +import noppes.npcs.scripted.entity.ScriptPlayer; +import noppes.npcs.scripted.gui.ScriptGuiComponent; +import noppes.npcs.scripted.gui.ScriptGuiItemSlot; +import noppes.npcs.scripted.gui.ScriptGuiLabel; +import noppes.npcs.scripted.gui.ScriptGuiLine; +import noppes.npcs.scripted.interfaces.*; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +public class ScriptOverlay implements ICustomOverlay { + int id; + int defaultAlignment = 0; + List components = new ArrayList(); + + public ScriptOverlay(){ + } + + public ScriptOverlay(int id){ + this.id = id; + } + + public int getID() { + return this.id; + } + + public List getComponents() { + return this.components; + } + + public PlayerDataScript getScriptHandler() { + return ScriptController.Instance.playerScripts;//this.scriptHandler; + } + + public int getDefaultAlignment(){ + return this.defaultAlignment; + } + + public void setDefaultAlignment(int defaultAlignment) { + this.defaultAlignment = defaultAlignment; + } + + public IOverlayTexturedRect addTexturedRect(int id, String texture, int x, int y, int width, int height) { + ScriptOverlayTexturedRect component = new ScriptOverlayTexturedRect(id, texture, x, y, width, height); + this.components.add(component); + return (IOverlayTexturedRect)this.components.get(this.components.size() - 1); + } + + public IOverlayTexturedRect addTexturedRect(int id, String texture, int x, int y, int width, int height, int textureX, int textureY) { + ScriptOverlayTexturedRect component = new ScriptOverlayTexturedRect(id, texture, x, y, width, height, textureX, textureY); + this.components.add(component); + return (IOverlayTexturedRect)this.components.get(this.components.size() - 1); + } + + public IOverlayLabel addLabel(int id, String label, int x, int y, int width, int height) { + ScriptOverlayLabel component = new ScriptOverlayLabel(id, label, x, y, width, height); + this.components.add(component); + return (IOverlayLabel)this.components.get(this.components.size() - 1); + } + + public IOverlayLabel addLabel(int id, String label, int x, int y, int width, int height, int color) { + ScriptOverlayLabel component = new ScriptOverlayLabel(id, label, x, y, width, height, color); + this.components.add(component); + return (IOverlayLabel)this.components.get(this.components.size() - 1); + } + + public IOverlayLine addLine(int id, int x1, int y1, int x2, int y2, int color, int thickness) { + ScriptOverlayLine line = new ScriptOverlayLine(id, x1, y1, x2, y2, color, thickness); + this.components.add(line); + return (IOverlayLine) this.components.get(this.components.size() - 1); + } + + public IOverlayLine addLine(int id, int x1, int y1, int x2, int y2) { + ScriptOverlayLine line = new ScriptOverlayLine(id, x1, y1, x2, y2); + this.components.add(line); + return (IOverlayLine) this.components.get(this.components.size() - 1); + } + + public ICustomOverlayComponent getComponent(int componentID) { + Iterator var2 = this.components.iterator(); + + ICustomOverlayComponent component; + do { + if (!var2.hasNext()) { + return null; + } + + component = (ICustomOverlayComponent)var2.next(); + } while(component.getID() != componentID); + + return component; + } + + public void removeComponent(int componentID) { + for(int i = 0; i < this.components.size(); ++i) { + if (((ICustomOverlayComponent)this.components.get(i)).getID() == componentID) { + this.components.remove(i); + return; + } + } + + } + + public void updateComponent(ICustomOverlayComponent component) { + for(int i = 0; i < this.components.size(); ++i) { + ICustomOverlayComponent c = (ICustomOverlayComponent)this.components.get(i); + if (c.getID() == component.getID()) { + this.components.set(i, component); + return; + } + } + + } + + public void update(IPlayer player) { + CustomGuiController.updateOverlay((ScriptPlayer)player, this); + } + + public ICustomOverlay fromNBT(NBTTagCompound tag) { + this.id = tag.getInteger("id"); + List components = new ArrayList(); + + NBTTagList list = tag.getTagList("components", 10); + for(int i = 0; i < list.tagCount(); i++){ + NBTBase b = list.getCompoundTagAt(i); + ScriptOverlayComponent component = ScriptOverlayComponent.createFromNBT((NBTTagCompound)b); + components.add(component); + } + + this.components = components; + + return this; + } + + public NBTTagCompound toNBT() { + NBTTagCompound tag = new NBTTagCompound(); + tag.setInteger("id", this.id); + + NBTTagList list = new NBTTagList(); + Iterator var3 = this.components.iterator(); + + ICustomOverlayComponent c; + while(var3.hasNext()) { + c = (ICustomOverlayComponent)var3.next(); + list.appendTag(((ScriptOverlayComponent)c).toNBT(new NBTTagCompound())); + } + + tag.setTag("components", list); + + return tag; + } +} diff --git a/src/main/java/noppes/npcs/scripted/overlay/ScriptOverlayComponent.java b/src/main/java/noppes/npcs/scripted/overlay/ScriptOverlayComponent.java new file mode 100644 index 000000000..d9e8a3933 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/overlay/ScriptOverlayComponent.java @@ -0,0 +1,88 @@ +package noppes.npcs.scripted.overlay; + +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.nbt.NBTTagString; +import noppes.npcs.scripted.gui.*; +import noppes.npcs.scripted.interfaces.ICustomGuiComponent; +import noppes.npcs.scripted.interfaces.ICustomOverlayComponent; + +public abstract class ScriptOverlayComponent implements ICustomOverlayComponent { + int id; + int posX; + int posY; + int alignment = 0; + /* ========ALIGNMENTS======== + 0 1 2 + + 3 4 5 + + 6 7 8 + */ + + public ScriptOverlayComponent(){ + } + + public int getID() { + return this.id; + } + + public ICustomOverlayComponent setID(int id) { + this.id = id; + return this; + } + + public int getPosX() { + return this.posX; + } + + public int getPosY() { + return this.posY; + } + + public ICustomOverlayComponent setPos(int x, int y) { + this.posX = x; + this.posY = y; + return this; + } + + public int getAlignment() { + return this.alignment; + } + + public void setAlignment(int alignment) { + this.alignment = alignment; + } + + public abstract int getType(); + + public NBTTagCompound toNBT(NBTTagCompound nbt) { + nbt.setInteger("id", this.id); + nbt.setIntArray("pos", new int[]{this.posX, this.posY}); + nbt.setInteger("alignment",this.alignment); + + nbt.setInteger("type", this.getType()); + return nbt; + } + + public ScriptOverlayComponent fromNBT(NBTTagCompound nbt) { + this.setID(nbt.getInteger("id")); + this.setPos(nbt.getIntArray("pos")[0], nbt.getIntArray("pos")[1]); + this.setAlignment(nbt.getInteger("alignment")); + + return this; + } + + public static ScriptOverlayComponent createFromNBT(NBTTagCompound nbt) { + switch(nbt.getInteger("type")) { + case 0: + return (new ScriptOverlayTexturedRect()).fromNBT(nbt); + case 1: + return (new ScriptOverlayLabel()).fromNBT(nbt); + case 2: + return (new ScriptOverlayLine()).fromNBT(nbt); + default: + return null; + } + } +} diff --git a/src/main/java/noppes/npcs/scripted/overlay/ScriptOverlayLabel.java b/src/main/java/noppes/npcs/scripted/overlay/ScriptOverlayLabel.java new file mode 100644 index 000000000..080800f92 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/overlay/ScriptOverlayLabel.java @@ -0,0 +1,109 @@ +package noppes.npcs.scripted.overlay; + +import net.minecraft.nbt.NBTTagCompound; +import noppes.npcs.scripted.gui.ScriptGuiComponent; +import noppes.npcs.scripted.interfaces.ILabel; +import noppes.npcs.scripted.interfaces.IOverlayLabel; + +public class ScriptOverlayLabel extends ScriptOverlayComponent implements IOverlayLabel { + String label; + int width; + int height; + int color; + float scale; + boolean shadow; + + public ScriptOverlayLabel() { + this.color = 16777215; + this.scale = 1.0F; + } + + public ScriptOverlayLabel(int id, String label, int x, int y, int width, int height) { + this.color = 16777215; + this.scale = 1.0F; + this.setID(id); + this.setText(label); + this.setPos(x, y); + this.setSize(width, height); + this.enableShadow(false); + } + + public ScriptOverlayLabel(int id, String label, int x, int y, int width, int height, int color) { + this(id, label, x, y, width, height); + this.setColor(color); + } + + public String getText() { + return this.label; + } + + public IOverlayLabel setText(String label) { + this.label = label; + return this; + } + + public int getWidth() { + return this.width; + } + + public int getHeight() { + return this.height; + } + + public IOverlayLabel setSize(int width, int height) { + this.width = width; + this.height = height; + return this; + } + + public int getColor() { + return this.color; + } + + public IOverlayLabel setColor(int color) { + this.color = color; + return this; + } + + public float getScale() { + return this.scale; + } + + public IOverlayLabel setScale(float scale) { + this.scale = scale; + return this; + } + + public boolean hasShadow(){ + return this.shadow; + } + + public void enableShadow(boolean shadow){ + this.shadow = shadow; + } + + @Override + public int getType() { + return 1; + } + + public NBTTagCompound toNBT(NBTTagCompound nbt) { + super.toNBT(nbt); + nbt.setString("label", this.label); + nbt.setIntArray("size", new int[]{this.width, this.height}); + nbt.setInteger("color", this.color); + nbt.setFloat("scale", this.scale); + nbt.setBoolean("shadow",this.shadow); + return nbt; + } + + public ScriptOverlayLabel fromNBT(NBTTagCompound nbt) { + super.fromNBT(nbt); + this.setText(nbt.getString("label")); + this.setSize(nbt.getIntArray("size")[0], nbt.getIntArray("size")[1]); + this.setColor(nbt.getInteger("color")); + this.setScale(nbt.getFloat("scale")); + this.enableShadow(this.shadow); + return this; + } +} diff --git a/src/main/java/noppes/npcs/scripted/overlay/ScriptOverlayLine.java b/src/main/java/noppes/npcs/scripted/overlay/ScriptOverlayLine.java new file mode 100644 index 000000000..3ad778b3c --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/overlay/ScriptOverlayLine.java @@ -0,0 +1,106 @@ +package noppes.npcs.scripted.overlay; + +import net.minecraft.nbt.NBTTagCompound; +import noppes.npcs.scripted.gui.ScriptGuiComponent; +import noppes.npcs.scripted.interfaces.IOverlayLine; + +public class ScriptOverlayLine extends ScriptOverlayComponent implements IOverlayLine { + int x1; + int y1; + int x2; + int y2; + int color = 0; + int thickness = 2; + + public ScriptOverlayLine(){ + } + + public ScriptOverlayLine(int id, int x1, int y1, int x2, int y2){ + this.setPos(x1, y1); + this.setID(id); + + this.x1 = x1; + this.y1 = y1; + this.x2 = x2; + this.y2 = y2; + } + + public ScriptOverlayLine(int id, int x1, int y1, int x2, int y2, int color, int thickness){ + this.setPos(x1, y1); + this.setID(id); + + this.x1 = x1; + this.y1 = y1; + this.x2 = x2; + this.y2 = y2; + this.color = color; + this.thickness = thickness; + } + + @Override + public int getType() { + return 2; + } + + public NBTTagCompound toNBT(NBTTagCompound nbt) { + super.toNBT(nbt); + nbt.setInteger("X1",x1); + nbt.setInteger("Y1",y1); + nbt.setInteger("X2",x2); + nbt.setInteger("Y2",y2); + nbt.setInteger("Color",color); + nbt.setInteger("Thickness",thickness); + + return nbt; + } + + public ScriptOverlayLine fromNBT(NBTTagCompound nbt) { + super.fromNBT(nbt); + x1 = nbt.getInteger("X1"); + y1 = nbt.getInteger("Y1"); + x2 = nbt.getInteger("X2"); + y2 = nbt.getInteger("Y2"); + color = nbt.getInteger("Color"); + thickness = nbt.getInteger("Thickness"); + + return this; + } + + public int getX1(){ + return this.x1; + } + public int getY1(){ + return this.y1; + } + public int getX2(){ + return this.x2; + } + public int getY2(){ + return this.y2; + } + public int getColor(){ + return this.color; + } + public int getThickness(){ + return this.thickness; + } + + public void setX1(int x1){ + this.x1 = x1; + } + public void setY1(int y1){ + this.y1 = y1; + } + public void setX2(int x2){ + this.x2 = x2; + } + public void setY2(int y2){ + this.y2 = y2; + } + public void setColor(int color){ + this.color = color; + } + public void setThickness(int thickness){ + this.thickness = thickness; + } +} diff --git a/src/main/java/noppes/npcs/scripted/overlay/ScriptOverlayTexturedRect.java b/src/main/java/noppes/npcs/scripted/overlay/ScriptOverlayTexturedRect.java new file mode 100644 index 000000000..0fb2d0bd6 --- /dev/null +++ b/src/main/java/noppes/npcs/scripted/overlay/ScriptOverlayTexturedRect.java @@ -0,0 +1,109 @@ +package noppes.npcs.scripted.overlay; + +import net.minecraft.nbt.NBTTagCompound; +import noppes.npcs.scripted.gui.ScriptGuiComponent; +import noppes.npcs.scripted.interfaces.IOverlayTexturedRect; +import noppes.npcs.scripted.interfaces.ITexturedRect; + +public class ScriptOverlayTexturedRect extends ScriptOverlayComponent implements IOverlayTexturedRect { + int width; + int height; + int textureX; + int textureY; + float scale; + String texture; + + public ScriptOverlayTexturedRect() { + this.textureY = -1; + this.scale = 1.0F; + } + + public ScriptOverlayTexturedRect(int id, String texture, int x, int y, int width, int height) { + this.textureY = -1; + this.scale = 1.0F; + this.setID(id); + this.setTexture(texture); + this.setPos(x, y); + this.setSize(width, height); + } + + public ScriptOverlayTexturedRect(int id, String texture, int x, int y, int width, int height, int textureX, int textureY) { + this(id, texture, x, y, width, height); + this.setTextureOffset(textureX, textureY); + } + + public String getTexture() { + return this.texture; + } + + public IOverlayTexturedRect setTexture(String texture) { + this.texture = texture; + return this; + } + + public int getWidth() { + return this.width; + } + + public int getHeight() { + return this.height; + } + + public IOverlayTexturedRect setSize(int width, int height) { + this.width = width; + this.height = height; + return this; + } + + public float getScale() { + return this.scale; + } + + public IOverlayTexturedRect setScale(float scale) { + this.scale = scale; + return this; + } + + public int getTextureX() { + return this.textureX; + } + + public int getTextureY() { + return this.textureY; + } + + public IOverlayTexturedRect setTextureOffset(int offsetX, int offsetY) { + this.textureX = offsetX; + this.textureY = offsetY; + return this; + } + + @Override + public int getType() { + return 0; + } + + public NBTTagCompound toNBT(NBTTagCompound nbt) { + super.toNBT(nbt); + nbt.setIntArray("size", new int[]{this.width, this.height}); + nbt.setFloat("scale", this.scale); + nbt.setString("texture", this.texture); + if (this.textureX >= 0 && this.textureY >= 0) { + nbt.setIntArray("texPos", new int[]{this.textureX, this.textureY}); + } + + return nbt; + } + + public ScriptOverlayComponent fromNBT(NBTTagCompound nbt) { + super.fromNBT(nbt); + this.setSize(nbt.getIntArray("size")[0], nbt.getIntArray("size")[1]); + this.setScale(nbt.getFloat("scale")); + this.setTexture(nbt.getString("texture")); + if (nbt.hasKey("texPos")) { + this.setTextureOffset(nbt.getIntArray("texPos")[0], nbt.getIntArray("texPos")[1]); + } + + return this; + } +} diff --git a/src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java b/src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java index 7788edac9..631f486c6 100644 --- a/src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java +++ b/src/main/java/noppes/npcs/scripted/wrapper/WrapperNpcAPI.java @@ -41,6 +41,7 @@ import noppes.npcs.scripted.entity.*; import noppes.npcs.scripted.gui.ScriptGui; import noppes.npcs.scripted.handler.*; import noppes.npcs.scripted.interfaces.*; +import noppes.npcs.scripted.overlay.ScriptOverlay; import noppes.npcs.util.JsonException; import noppes.npcs.util.LRUHashMap; import noppes.npcs.util.NBTJsonUtil; @@ -275,4 +276,8 @@ public class WrapperNpcAPI extends NpcAPI { public ICustomGui createCustomGui(int id, int width, int height, boolean pauseGame) { return new ScriptGui(id, width, height, pauseGame); } + + public ICustomOverlay createCustomOverlay(int id) { + return new ScriptOverlay(id); + } }