Implemented Scripted Overlays which stay on the player's screen. Overlays persist in the client, and can be removed from the screen as well.

This commit is contained in:
luisc committed 2022-01-30 04:05:01 -06:00
1 parent 8b24dad211
commit 534f716991
25 files changed
+1105 -19

No files matched your search

@@ -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<Integer, OverlayCustom> customOverlays = new HashMap<>();
public static void sendData(EnumPacketServer enu, Object... obs) {
ByteBuf buffer = Unpooled.buffer();
@@ -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);
}
}
}
@@ -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);
}
}
}
@@ -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;
@@ -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();
}
@@ -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<Integer, IOverlayComponent> 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();
}
}
@@ -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
}
}
}
@@ -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;
}
}
@@ -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;
}
}
@@ -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);
}
@@ -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);
}
@@ -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
}
@@ -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)) {
@@ -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<T extends EntityPlayerMP> extends ScriptLivingBase<T>
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() {
@@ -0,0 +1,4 @@
package noppes.npcs.scripted.interfaces;
public interface ICustomOverlay {
}
@@ -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);
}
@@ -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);
}
@@ -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);
}
@@ -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);
}
@@ -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<ICustomOverlayComponent> components = new ArrayList();
public ScriptOverlay(){
}
public ScriptOverlay(int id){
this.id = id;
}
public int getID() {
return this.id;
}
public List<ICustomOverlayComponent> 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<ICustomOverlayComponent> 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;
}
}
@@ -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;
}
}
}
@@ -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;
}
}
@@ -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;
}
}
@@ -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;
}
}
@@ -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);
}
}