From 44bd1692d1e7620e948872d8d998ac9f96e163af Mon Sep 17 00:00:00 2001 From: luisc Date: Fri, 1 Oct 2021 01:17:12 -0500 Subject: [PATCH] GUI's properly implemented, script data still needs work. --- CustomNPC-Plus-1.21.iml | 77 ++- build.gradle | 3 + .../java/noppes/npcs/PacketHandlerServer.java | 6 +- .../gui/script/EventGuiNPCInterface.java | 225 ++++----- .../client/gui/script/EventGuiScriptList.java | 111 ++++ .../client/gui/script/GuiScriptEvent.java | 284 ----------- .../client/gui/script/GuiScriptGlobal.java | 14 +- .../client/gui/script/GuiScriptInterface.java | 336 ++++++------- .../npcs/client/gui/util/GuiCustomScroll.java | 3 + .../npcs/client/gui/util/GuiTextArea.java | 473 ++++++++++++++++++ .../noppes/npcs/client/gui/util/IGui.java | 16 + .../npcs/client/gui/util/IKeyListener.java | 10 + .../npcs/client/gui/util/IMouseListener.java | 10 + .../npcs/client/gui/util/TextContainer.java | 225 +++++++++ .../java/noppes/npcs/config/TrueTypeFont.java | 340 +++++++++++++ 15 files changed, 1538 insertions(+), 595 deletions(-) create mode 100644 src/main/java/noppes/npcs/client/gui/script/EventGuiScriptList.java delete mode 100644 src/main/java/noppes/npcs/client/gui/script/GuiScriptEvent.java create mode 100644 src/main/java/noppes/npcs/client/gui/util/GuiTextArea.java create mode 100644 src/main/java/noppes/npcs/client/gui/util/IGui.java create mode 100644 src/main/java/noppes/npcs/client/gui/util/IKeyListener.java create mode 100644 src/main/java/noppes/npcs/client/gui/util/IMouseListener.java create mode 100644 src/main/java/noppes/npcs/client/gui/util/TextContainer.java create mode 100644 src/main/java/noppes/npcs/config/TrueTypeFont.java diff --git a/CustomNPC-Plus-1.21.iml b/CustomNPC-Plus-1.21.iml index b060a7da0..371deae12 100644 --- a/CustomNPC-Plus-1.21.iml +++ b/CustomNPC-Plus-1.21.iml @@ -1,13 +1,86 @@ - + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/build.gradle b/build.gradle index 5695c93b2..4698f6eab 100644 --- a/build.gradle +++ b/build.gradle @@ -26,6 +26,9 @@ minecraft { runDir = "eclipse" } +sourceCompatibility = 1.8 +targetCompatibility = 1.8 + dependencies { // you may put jars on which you depend on in ./libs // or you may define them like so.. diff --git a/src/main/java/noppes/npcs/PacketHandlerServer.java b/src/main/java/noppes/npcs/PacketHandlerServer.java index 5fe882a43..48c533168 100644 --- a/src/main/java/noppes/npcs/PacketHandlerServer.java +++ b/src/main/java/noppes/npcs/PacketHandlerServer.java @@ -106,7 +106,7 @@ public class PacketHandlerServer{ clonePackets(type, buffer, player); else if(item.getItem() == CustomItems.teleporter) featherPackets(type, buffer, player); - else if(type == EnumPacketServer.ScriptPlayerGet && type == EnumPacketServer.ScriptPlayerSave) + else if(type == EnumPacketServer.ScriptPlayerGet || type == EnumPacketServer.ScriptPlayerSave) playerScriptPackets(type, buffer, player, npc); else if(item.getItem() == CustomItems.scripter) scriptPackets(type, buffer, player, npc); @@ -132,11 +132,11 @@ public class PacketHandlerServer{ private void playerScriptPackets(EnumPacketServer type, ByteBuf buffer, EntityPlayerMP player, EntityNPCInterface npc) throws Exception { NBTTagCompound compound; - if (type == EnumPacketServer.ScriptPlayerGet) { + if(type == EnumPacketServer.ScriptPlayerGet) { compound = ScriptController.Instance.playerScripts.writeToNBT(new NBTTagCompound()); compound.setTag("Languages", ScriptController.Instance.nbtLanguages()); Server.sendData(player, EnumPacketClient.GUI_DATA, new Object[]{compound}); - } else if (type == EnumPacketServer.ScriptPlayerSave) { + } else if(type == EnumPacketServer.ScriptPlayerSave) { ScriptController.Instance.setPlayerScripts(Server.readNBT(buffer)); } } diff --git a/src/main/java/noppes/npcs/client/gui/script/EventGuiNPCInterface.java b/src/main/java/noppes/npcs/client/gui/script/EventGuiNPCInterface.java index 65b6154ed..83f24a15a 100644 --- a/src/main/java/noppes/npcs/client/gui/script/EventGuiNPCInterface.java +++ b/src/main/java/noppes/npcs/client/gui/script/EventGuiNPCInterface.java @@ -17,9 +17,9 @@ import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; -import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.client.renderer.RenderHelper; +import net.minecraft.client.renderer.entity.RenderItem; import net.minecraft.entity.EntityLivingBase; import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.event.GuiScreenEvent.ActionPerformedEvent.Post; @@ -28,6 +28,7 @@ import net.minecraftforge.common.MinecraftForge; import noppes.npcs.client.gui.util.*; import noppes.npcs.entity.EntityNPCInterface; import org.lwjgl.input.Mouse; +import org.lwjgl.opengl.GL11; public abstract class EventGuiNPCInterface extends GuiScreen { public EntityPlayerSP player; @@ -69,15 +70,15 @@ public abstract class EventGuiNPCInterface extends GuiScreen { this.background = null; this.closeOnEsc = false; this.bgScale = 1.0F; - this.player = Minecraft.func_71410_x().field_71439_g; + this.player = Minecraft.getMinecraft().thePlayer; this.npc = npc; this.title = ""; this.xSize = 200; this.ySize = 222; this.drawDefaultBackground = false; - this.field_146297_k = Minecraft.func_71410_x(); - this.field_146296_j = this.field_146297_k.func_175599_af(); - this.field_146289_q = this.field_146297_k.field_71466_p; + this.mc = Minecraft.getMinecraft(); + this.itemRender = RenderItem.getInstance(); + this.fontRendererObj = this.mc.fontRenderer; } public EventGuiNPCInterface() { @@ -92,25 +93,25 @@ public abstract class EventGuiNPCInterface extends GuiScreen { return new ResourceLocation("customnpcs", "textures/gui/" + texture); } - public void func_146280_a(Minecraft mc, int width, int height) { - super.func_146280_a(mc, width, height); + public void setWorldAndResolution(Minecraft mc, int width, int height) { + super.setWorldAndResolution(mc, width, height); this.initPacket(); } public void initPacket() { } - public void func_73866_w_() { - super.func_73866_w_(); + public void initGui() { + super.initGui(); GuiNpcTextField.unfocus(); if (this.subgui != null) { - this.subgui.func_146280_a(this.field_146297_k, this.field_146294_l, this.field_146295_m); - this.subgui.func_73866_w_(); + this.subgui.setWorldAndResolution(this.mc, this.width, this.height); + this.subgui.initGui(); } - this.guiLeft = (this.field_146294_l - this.xSize) / 2; - this.guiTop = (this.field_146295_m - this.ySize) / 2; - this.field_146292_n = Lists.newArrayList(); + this.guiLeft = (this.width - this.xSize) / 2; + this.guiTop = (this.height - this.ySize) / 2; + this.buttonList = Lists.newArrayList(); this.buttons = new ConcurrentHashMap(); this.topbuttons = new ConcurrentHashMap(); this.sidebuttons = new ConcurrentHashMap(); @@ -122,16 +123,16 @@ public abstract class EventGuiNPCInterface extends GuiScreen { this.components = new ArrayList(); } - public void func_73876_c() { + public void updateScreen() { if (this.subgui != null) { - this.subgui.func_73876_c(); + this.subgui.updateScreen(); } else { Iterator var1 = (new ArrayList(this.textfields.values())).iterator(); while(var1.hasNext()) { GuiNpcTextField tf = (GuiNpcTextField)var1.next(); if (tf.enabled) { - tf.func_146178_a(); + tf.updateCursorCounter(); } } @@ -142,26 +143,26 @@ public abstract class EventGuiNPCInterface extends GuiScreen { comp.updateScreen(); } - super.func_73876_c(); + super.updateScreen(); } } public void addExtra(GuiHoverText gui) { - gui.func_146280_a(this.field_146297_k, 350, 250); + gui.setWorldAndResolution(this.mc, 350, 250); this.extra.put(gui.id, gui); } - public void func_73864_a(int i, int j, int k) { + public void mouseClicked(int i, int j, int k) { if (this.subgui != null) { - this.subgui.func_73864_a(i, j, k); + this.subgui.mouseClicked(i, j, k); } else { Iterator var4 = (new ArrayList(this.textfields.values())).iterator(); while(var4.hasNext()) { GuiNpcTextField tf = (GuiNpcTextField)var4.next(); if (tf.enabled) { - tf.func_146192_a(i, j, k); + tf.mouseClicked(i, j, k); } } @@ -180,22 +181,21 @@ public abstract class EventGuiNPCInterface extends GuiScreen { while(var4.hasNext()) { GuiCustomScroll scroll = (GuiCustomScroll)var4.next(); - scroll.func_73864_a(i, j, k); + scroll.mouseClicked(i, j, k); } - var4 = this.field_146292_n.iterator(); + var4 = this.buttonList.iterator(); while(var4.hasNext()) { GuiButton guibutton = (GuiButton)var4.next(); - if (guibutton.func_146116_c(this.field_146297_k, this.mouseX, this.mouseY)) { - Pre event = new Pre(this, guibutton, this.field_146292_n); + if (guibutton.mousePressed(this.mc, this.mouseX, this.mouseY)) { + Pre event = new Pre(this, guibutton, this.buttonList); if (!MinecraftForge.EVENT_BUS.post(event)) { - guibutton = event.getButton(); this.selectedButton = guibutton; - guibutton.func_146113_a(this.field_146297_k.func_147118_V()); - this.func_146284_a(guibutton); - if (this.equals(this.field_146297_k.field_71462_r)) { - MinecraftForge.EVENT_BUS.post(new Post(this, event.getButton(), this.field_146292_n)); + guibutton.func_146113_a(this.mc.getSoundHandler()); + this.actionPerformed(guibutton); + if (this.equals(this.mc.currentScreen)) { + MinecraftForge.EVENT_BUS.post(new Post(this, guibutton, this.buttonList)); } } break; @@ -206,9 +206,9 @@ public abstract class EventGuiNPCInterface extends GuiScreen { } - public void func_146286_b(int mouseX, int mouseY, int state) { + public void mouseReleased(int mouseX, int mouseY, int state) { if (this.selectedButton != null && state == 0) { - this.selectedButton.func_146118_a(mouseX, mouseY); + this.selectedButton.mouseReleased(mouseX, mouseY); this.selectedButton = null; } @@ -217,7 +217,7 @@ public abstract class EventGuiNPCInterface extends GuiScreen { public void mouseEvent(int i, int j, int k) { } - protected void func_146284_a(GuiButton guibutton) { + protected void actionPerformed(GuiButton guibutton) { if (this.subgui != null) { this.subgui.buttonEvent(guibutton); } else { @@ -225,13 +225,11 @@ public abstract class EventGuiNPCInterface extends GuiScreen { } } + public void buttonEvent(GuiButton guibutton){}; - public void buttonEvent(GuiButton guibutton) { - } - - public void func_73869_a(char c, int i) { + public void keyTyped(char c, int i) { if (this.subgui != null) { - this.subgui.func_73869_a(c, i); + this.subgui.keyTyped(c, i); } else { boolean active = false; Iterator var4 = this.components.iterator(); @@ -251,7 +249,7 @@ public abstract class EventGuiNPCInterface extends GuiScreen { while(var4.hasNext()) { GuiNpcTextField tf = (GuiNpcTextField)var4.next(); - tf.func_146201_a(c, i); + tf.textboxKeyTyped(c, i); } var4 = (new ArrayList(this.components)).iterator(); @@ -269,29 +267,29 @@ public abstract class EventGuiNPCInterface extends GuiScreen { } } - public void func_146281_b() { + public void onGuiClosed() { GuiNpcTextField.unfocus(); } public void close() { this.displayGuiScreen((GuiScreen)null); - this.field_146297_k.func_71381_h(); + this.mc.setIngameFocus(); this.save(); } public void addButton(GuiNpcButton button) { - this.buttons.put(button.field_146127_k, button); - this.field_146292_n.add(button); + this.buttons.put(button.id, button); + this.buttonList.add(button); } public void addTopButton(GuiMenuTopButton button) { - this.topbuttons.put(button.field_146127_k, button); - this.field_146292_n.add(button); + this.topbuttons.put(button.id, button); + this.buttonList.add(button); } public void addSideButton(GuiMenuSideButton button) { - this.sidebuttons.put(button.field_146127_k, button); - this.field_146292_n.add(button); + this.sidebuttons.put(button.id, button); + this.buttonList.add(button); } public GuiNpcButton getButton(int i) { @@ -307,7 +305,7 @@ public abstract class EventGuiNPCInterface extends GuiScreen { } public void addTextField(GuiNpcTextField tf) { - this.textfields.put(tf.field_175208_g, tf); + this.textfields.put(tf.id, tf); } public GuiNpcTextField getTextField(int i) { @@ -342,8 +340,8 @@ public abstract class EventGuiNPCInterface extends GuiScreen { } public void addSlider(GuiNpcSlider slider) { - this.sliders.put(slider.field_146127_k, slider); - this.field_146292_n.add(slider); + this.sliders.put(slider.id, slider); + this.buttonList.add(slider); } public GuiNpcSlider getSlider(int i) { @@ -351,7 +349,7 @@ public abstract class EventGuiNPCInterface extends GuiScreen { } public void addScroll(GuiCustomScroll scroll) { - scroll.func_146280_a(this.field_146297_k, 350, 250); + scroll.setWorldAndResolution(this.mc, 350, 250); this.scrolls.put(scroll.id, scroll); } @@ -361,7 +359,7 @@ public abstract class EventGuiNPCInterface extends GuiScreen { public abstract void save(); - public void func_73863_a(int mouseX, int mouseY, float partialTicks) { + public void drawScreen(int mouseX, int mouseY, float partialTicks) { this.mouseX = mouseX; this.mouseY = mouseY; int x = mouseX; @@ -372,31 +370,31 @@ public abstract class EventGuiNPCInterface extends GuiScreen { } if (this.drawDefaultBackground && this.subgui == null) { - this.func_146276_q_(); + this.drawDefaultBackground(); } - if (this.background != null && this.field_146297_k.field_71446_o != null) { - GlStateManager.func_179131_c(1.0F, 1.0F, 1.0F, 1.0F); - GlStateManager.func_179094_E(); - GlStateManager.func_179109_b((float)this.guiLeft, (float)this.guiTop, 0.0F); - GlStateManager.func_179152_a(this.bgScale, this.bgScale, this.bgScale); - this.field_146297_k.field_71446_o.func_110577_a(this.background); + if (this.background != null && this.mc.renderEngine != null) { + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + GL11.glPushMatrix(); + GL11.glTranslatef((float) this.guiLeft, (float) this.guiTop, 0.0F); + GL11.glScalef(this.bgScale, this.bgScale, this.bgScale); + this.mc.renderEngine.bindTexture(this.background); if (this.xSize > 256) { - this.func_73729_b(0, 0, 0, 0, 250, this.ySize); - this.func_73729_b(250, 0, 256 - (this.xSize - 250), 0, this.xSize - 250, this.ySize); + this.drawTexturedModalRect(0, 0, 0, 0, 250, this.ySize); + this.drawTexturedModalRect(250, 0, 256 - (this.xSize - 250), 0, this.xSize - 250, this.ySize); } else { - this.func_73729_b(0, 0, 0, 0, this.xSize, this.ySize); + this.drawTexturedModalRect(0, 0, 0, 0, this.xSize, this.ySize); } - GlStateManager.func_179121_F(); + GL11.glPopMatrix(); } - this.func_73732_a(this.field_146289_q, this.title, this.field_146294_l / 2, 8, 16777215); + this.drawCenteredString(this.fontRendererObj, this.title, this.width / 2, 8, 16777215); Iterator var6 = (new ArrayList(this.labels.values())).iterator(); while(var6.hasNext()) { GuiNpcLabel label = (GuiNpcLabel)var6.next(); - label.drawLabel(this, this.field_146289_q); + label.drawLabel(this, this.fontRendererObj); } var6 = (new ArrayList(this.textfields.values())).iterator(); @@ -424,18 +422,18 @@ public abstract class EventGuiNPCInterface extends GuiScreen { while(var6.hasNext()) { GuiScreen gui = (GuiScreen)var6.next(); - gui.func_73863_a(x, y, partialTicks); + gui.drawScreen(x, y, partialTicks); } - super.func_73863_a(x, y, partialTicks); + super.drawScreen(x, y, partialTicks); if (this.subgui != null) { - this.subgui.func_73863_a(mouseX, mouseY, partialTicks); + this.subgui.drawScreen(mouseX, mouseY, partialTicks); } } public FontRenderer getFontRenderer() { - return this.field_146289_q; + return this.fontRendererObj; } public void elementClicked() { @@ -445,7 +443,7 @@ public abstract class EventGuiNPCInterface extends GuiScreen { } - public boolean func_73868_f() { + public boolean doesGuiPauseGame() { return false; } @@ -453,23 +451,23 @@ public abstract class EventGuiNPCInterface extends GuiScreen { } public boolean isInventoryKey(int i) { - return i == this.field_146297_k.field_71474_y.field_151445_Q.func_151463_i(); + return i == this.mc.gameSettings.keyBindInventory.getKeyCode(); } - public void func_146276_q_() { - super.func_146276_q_(); + public void drawDefaultBackground() { + super.drawDefaultBackground(); } public void displayGuiScreen(GuiScreen gui) { - this.field_146297_k.func_147108_a(gui); + this.mc.displayGuiScreen(gui); } public void setSubGui(SubGuiInterface gui) { this.subgui = gui; this.subgui.npc = this.npc; - this.subgui.func_146280_a(this.field_146297_k, this.field_146294_l, this.field_146295_m); + this.subgui.setWorldAndResolution(this.mc, this.width, this.height); this.subgui.parent = this; - this.func_73866_w_(); + this.initGui(); } public void closeSubGui(SubGuiInterface gui) { @@ -489,58 +487,41 @@ public abstract class EventGuiNPCInterface extends GuiScreen { } public void drawNpc(EntityLivingBase entity, int x, int y, float zoomed, int rotation) { - EntityNPCInterface npc = null; - if (entity instanceof EntityNPCInterface) { - npc = (EntityNPCInterface)entity; - } - - GlStateManager.func_179131_c(1.0F, 1.0F, 1.0F, 1.0F); - GlStateManager.func_179142_g(); - GlStateManager.func_179094_E(); - GlStateManager.func_179109_b((float)(this.guiLeft + x), (float)(this.guiTop + y), 50.0F); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + GL11.glColorMaterial(0,1); + GL11.glPushMatrix(); + GL11.glTranslatef((float)(this.guiLeft + x), (float)(this.guiTop + y), 50.0F); float scale = 1.0F; - if ((double)entity.field_70131_O > 2.4D) { - scale = 2.0F / entity.field_70131_O; + if ((double)entity.height > 2.4D) { + scale = 2.0F / entity.height; } - GlStateManager.func_179152_a(-30.0F * scale * zoomed, 30.0F * scale * zoomed, 30.0F * scale * zoomed); - GlStateManager.func_179114_b(180.0F, 0.0F, 0.0F, 1.0F); - RenderHelper.func_74519_b(); - float f2 = entity.field_70761_aq; - float f3 = entity.field_70177_z; - float f4 = entity.field_70125_A; - float f7 = entity.field_70759_as; + GL11.glScalef(-30.0F * scale * zoomed, 30.0F * scale * zoomed, 30.0F * scale * zoomed); + GL11.glRotatef(180.0F, 0.0F, 0.0F, 1.0F); + RenderHelper.enableStandardItemLighting(); + float f2 = entity.renderYawOffset; + float f3 = entity.rotationYaw; + float f4 = entity.rotationPitch; + float f7 = entity.rotationYawHead; float f5 = (float)(this.guiLeft + x) - (float)this.mouseX; float f6 = (float)(this.guiTop + y) - 50.0F * scale * zoomed - (float)this.mouseY; - int orientation = 0; - if (npc != null) { - orientation = npc.ais.orientation; - npc.ais.orientation = rotation; - } - GlStateManager.func_179114_b(135.0F, 0.0F, 1.0F, 0.0F); - GlStateManager.func_179114_b(-135.0F, 0.0F, 1.0F, 0.0F); - GlStateManager.func_179114_b(-((float)Math.atan((double)(f6 / 40.0F))) * 20.0F, 1.0F, 0.0F, 0.0F); - entity.field_70761_aq = (float)rotation; - entity.field_70177_z = (float)Math.atan((double)(f5 / 80.0F)) * 40.0F + (float)rotation; - entity.field_70125_A = -((float)Math.atan((double)(f6 / 40.0F))) * 20.0F; - entity.field_70759_as = entity.field_70177_z; - this.field_146297_k.func_175598_ae().field_78735_i = 180.0F; - this.field_146297_k.func_175598_ae().func_188391_a(entity, 0.0D, 0.0D, 0.0D, 0.0F, 1.0F, false); - entity.field_70760_ar = entity.field_70761_aq = f2; - entity.field_70126_B = entity.field_70177_z = f3; - entity.field_70127_C = entity.field_70125_A = f4; - entity.field_70758_at = entity.field_70759_as = f7; - if (npc != null) { - npc.ais.orientation = orientation; - } + GL11.glRotatef(135.0F, 0.0F, 1.0F, 0.0F); + GL11.glRotatef(-135.0F, 0.0F, 1.0F, 0.0F); + GL11.glRotatef(-((float) Math.atan((double) (f6 / 40.0F))) * 20.0F, 1.0F, 0.0F, 0.0F); + entity.renderYawOffset = (float)rotation; + entity.rotationYaw = (float)Math.atan((double)(f5 / 80.0F)) * 40.0F + (float)rotation; + entity.rotationPitch = -((float)Math.atan((double)(f6 / 40.0F))) * 20.0F; + entity.rotationYawHead = entity.rotationYaw; + RenderItem.getInstance().zLevel = 180.0F; + RenderItem.getInstance().doRender(entity, 0.0D, 0.0D, 0.0D, 0.0F, 1.0F); + entity.prevRenderYawOffset = entity.renderYawOffset = f2; + entity.prevRotationYaw = entity.rotationYaw = f3; + entity.prevRotationPitch = entity.rotationPitch = f4; + entity.prevRotationYawHead = entity.rotationYawHead = f7; - GlStateManager.func_179121_F(); - RenderHelper.func_74518_a(); - GlStateManager.func_179101_C(); - GlStateManager.func_179138_g(OpenGlHelper.field_77476_b); - GlStateManager.func_179090_x(); - GlStateManager.func_179138_g(OpenGlHelper.field_77478_a); + GL11.glPopMatrix(); + RenderHelper.disableStandardItemLighting(); } public void openLink(String link) { diff --git a/src/main/java/noppes/npcs/client/gui/script/EventGuiScriptList.java b/src/main/java/noppes/npcs/client/gui/script/EventGuiScriptList.java new file mode 100644 index 000000000..533a7654f --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/script/EventGuiScriptList.java @@ -0,0 +1,111 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.client.gui.script; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import net.minecraft.client.gui.GuiButton; +import noppes.npcs.EventScriptContainer; +import noppes.npcs.client.gui.util.GuiCustomScroll; +import noppes.npcs.client.gui.util.GuiNpcButton; +import noppes.npcs.client.gui.util.GuiNpcLabel; +import noppes.npcs.client.gui.util.SubGuiInterface; + +public class EventGuiScriptList extends SubGuiInterface { + private GuiCustomScroll scroll1; + private GuiCustomScroll scroll2; + private EventScriptContainer container; + private List scripts; + + public EventGuiScriptList(List scripts, EventScriptContainer container) { + this.container = container; + this.setBackground("menubg.png"); + this.xSize = 346; + this.ySize = 216; + if(scripts == null) { + scripts = new ArrayList(); + } + + this.scripts = (List)scripts; + } + + public void initGui() { + super.initGui(); + if(this.scroll1 == null) { + this.scroll1 = new GuiCustomScroll(this, 0); + this.scroll1.setSize(140, 180); + } + + this.scroll1.guiLeft = this.guiLeft + 4; + this.scroll1.guiTop = this.guiTop + 14; + this.addScroll(this.scroll1); + this.addLabel(new GuiNpcLabel(1, "script.availableScripts", this.guiLeft + 4, this.guiTop + 4)); + if(this.scroll2 == null) { + this.scroll2 = new GuiCustomScroll(this, 1); + this.scroll2.setSize(140, 180); + } + + this.scroll2.guiLeft = this.guiLeft + 200; + this.scroll2.guiTop = this.guiTop + 14; + this.addScroll(this.scroll2); + this.addLabel(new GuiNpcLabel(2, "script.loadedScripts", this.guiLeft + 200, this.guiTop + 4)); + ArrayList temp = new ArrayList(this.scripts); + temp.removeAll(this.container.scripts); + this.scroll1.setList(temp); + this.scroll2.setList(this.container.scripts); + this.addButton(new GuiNpcButton(1, this.guiLeft + 145, this.guiTop + 40, 55, 20, ">")); + this.addButton(new GuiNpcButton(2, this.guiLeft + 145, this.guiTop + 62, 55, 20, "<")); + this.addButton(new GuiNpcButton(3, this.guiLeft + 145, this.guiTop + 90, 55, 20, ">>")); + this.addButton(new GuiNpcButton(4, this.guiLeft + 145, this.guiTop + 112, 55, 20, "<<")); + this.addButton(new GuiNpcButton(66, this.guiLeft + 260, this.guiTop + 194, 60, 20, "gui.done")); + } + + protected void actionPerformed(GuiButton guibutton) { + GuiNpcButton button = (GuiNpcButton)guibutton; + if(button.id == 1 && this.scroll1.hasSelected()) { + this.container.scripts.add(this.scroll1.getSelected()); + this.scroll1.selected = -1; + this.scroll1.selected = -1; + this.initGui(); + } + + if(button.id == 2 && this.scroll2.hasSelected()) { + this.container.scripts.remove(this.scroll2.getSelected()); + this.scroll2.selected = -1; + this.initGui(); + } + + if(button.id == 3) { + this.container.scripts.clear(); + Iterator var3 = this.scripts.iterator(); + + while(var3.hasNext()) { + String script = (String)var3.next(); + this.container.scripts.add(script); + } + + this.scroll1.selected = -1; + this.scroll1.selected = -1; + this.initGui(); + } + + if(button.id == 4) { + this.container.scripts.clear(); + this.scroll1.selected = -1; + this.scroll1.selected = -1; + this.initGui(); + } + + if(button.id == 66) { + this.close(); + } + + } + + public void save() { + } +} diff --git a/src/main/java/noppes/npcs/client/gui/script/GuiScriptEvent.java b/src/main/java/noppes/npcs/client/gui/script/GuiScriptEvent.java deleted file mode 100644 index a108ef1bc..000000000 --- a/src/main/java/noppes/npcs/client/gui/script/GuiScriptEvent.java +++ /dev/null @@ -1,284 +0,0 @@ -package noppes.npcs.client.gui.script; - -import net.minecraft.client.gui.GuiButton; -import net.minecraft.client.gui.GuiConfirmOpenLink; -import net.minecraft.client.gui.GuiYesNoCallback; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; -import net.minecraft.server.MinecraftServer; -import noppes.npcs.EventDataScript; -import noppes.npcs.EventScriptContainer; -import noppes.npcs.NoppesStringUtils; -import noppes.npcs.client.Client; -import noppes.npcs.client.NoppesUtil; -import noppes.npcs.client.gui.EventGuiScriptList; -import noppes.npcs.client.gui.swing.GuiJTextArea; -import noppes.npcs.client.gui.util.*; -import noppes.npcs.constants.EnumPacketServer; -import noppes.npcs.controllers.ScriptContainer; -import noppes.npcs.controllers.ScriptController; -import noppes.npcs.controllers.data.PlayerScriptData; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class GuiScriptEvent extends GuiNPCInterface implements IGuiData, GuiYesNoCallback, ICustomScrollListener, IJTextAreaListener { - public boolean showScript = false; - private int activeTab = 0; - private String activeScriptTab = "init"; - private PlayerScriptData script = new PlayerScriptData((EntityPlayer)null); - public Map> languages = new HashMap>(); - - private static int activeConsole = 0; - - public GuiScriptEvent(){ - super(); - drawDefaultBackground = true; - closeOnEsc = true; - xSize = 420; - - setBackground("menubg.png"); - Client.sendData(EnumPacketServer.ScriptPlayerGet); - } - - public void initGui() { - super.initGui(); - guiTop += 10; - GuiMenuTopButton top; - addTopButton(top = new GuiMenuTopButton(13, guiLeft + 4, guiTop - 17, "eventscript.playerevent")); - top.active = showScript; - addTopButton(top = new GuiMenuTopButton(14, top, "gui.settings")); - top.active = !showScript; - addTopButton(new GuiMenuTopButton(15, top, "gui.website")); - - List list = new ArrayList(); - list.add("playerscript.attack"); - list.add("playerscript.chat"); - list.add("playerscript.containerclosed"); - list.add("playerscript.containeropen"); - list.add("playerscript.damagedentity"); - list.add("playerscript.damaged"); - list.add("playerscript.killed"); - list.add("playerscript.init"); - list.add("playerscript.interact"); - list.add("playerscript.keypressed"); - list.add("playerscript.kills"); - list.add("playerscript.levelup"); - list.add("playerscript.login"); - list.add("playerscript.logout"); - list.add("playerscript.pickup"); - list.add("playerscript.rangedlaunched"); - list.add("playerscript.toss"); - list.add("playerscript.update"); - - if(showScript) { - addLabel(new GuiNpcLabel(0, "script.hooks", guiLeft + 4, guiTop + 5)); - GuiCustomScroll hooks = new GuiCustomScroll(this, 1); - hooks.setSize(68, 198); - hooks.guiLeft = guiLeft + 4; - hooks.guiTop = guiTop + 14; - hooks.setUnsortedList(list); - hooks.selected = script.getScripts().indexOf(activeScriptTab); - addScroll(hooks); - - EventScriptContainer container = script.getScripts().get(script.getScripts().indexOf(activeScriptTab)); - - addTextField(new GuiNpcTextArea(2, this, guiLeft + 74, guiTop + 4, 239, 208, container == null?"":container.script)); - - addButton(new GuiNpcButton(102, guiLeft + 315, guiTop + 4, 50, 20, "gui.clear")); - addButton(new GuiNpcButton(101, guiLeft + 366, guiTop + 4, 50, 20, "gui.paste")); - addButton(new GuiNpcButton(100, guiLeft + 315, guiTop + 25, 50, 20, "gui.copy")); - - addButton(new GuiNpcButton(108, guiLeft + 315, guiTop + 47, 80, 20, "gui.editor")); - - addButton(new GuiNpcButton(107, guiLeft + 315, guiTop + 70, 80, 20, "script.loadscript")); - - GuiCustomScroll scroll = new GuiCustomScroll(this, 0).setUnselectable(); - scroll.setSize(100, 120); - scroll.guiLeft = guiLeft + 315; - scroll.guiTop = guiTop + 92; - if(container != null) - scroll.setList(container.scripts); - addScroll(scroll); - } - else{ - addLabel(new GuiNpcLabel(0, "script.console", guiLeft + 4, guiTop + 16)); - getTopButton(14).active = true; - addTextField(new GuiNpcTextArea(2, this, guiLeft + 4, guiTop + 26, 226, 186, getConsoleText())); - getTextField(2).canEdit = false; - addButton(new GuiNpcButton(100, guiLeft + 232, guiTop + 170, 56, 20, "gui.copy")); - addButton(new GuiNpcButton(102, guiLeft + 232, guiTop + 192, 56, 20, "gui.clear")); - - List l = new ArrayList(); - l.add("All"); - l.addAll(list); - addButton(new GuiNpcButton(105, guiLeft + 60, guiTop + 4, 80, 20, l.toArray(new String[l.size()]), activeConsole)); - - addLabel(new GuiNpcLabel(1, "script.language", guiLeft + 232, guiTop + 30)); - addButton(new GuiNpcButton(103, guiLeft + 294, guiTop + 25, 80, 20, languages.keySet().toArray(new String[languages.keySet().size()]), getScriptIndex())); - getButton(103).enabled = languages.size() > 0; - - addLabel(new GuiNpcLabel(2, "gui.enabled", guiLeft + 232, guiTop + 53)); - //addButton(new GuiNpcButton(104, guiLeft + 294, guiTop + 48, 50, 20, new String[]{"gui.no","gui.yes"}, script.enabled?1:0)); - - if(MinecraftServer.getServer() != null) - addButton(new GuiNpcButton(106, guiLeft + 232, guiTop + 71, 150, 20, "script.openfolder")); - } - } - - private int getScriptIndex() { - int i = 0; - for(String language : languages.keySet()){ - if(language.equalsIgnoreCase(script.getLanguage())) - return i; - i++; - } - return 0; - } - - private String getConsoleText() { - String console = ""; - if(activeConsole == 0){ - for(EventScriptContainer container : script.scripts){ - if(!container.console.isEmpty()) - for(Long l : container.console.keySet()) - console += container.console.get(l) + '\n'; - } - } - else{ - EventScriptContainer container = script.scripts.get(activeConsole - 1); - if(container != null) - console = container.console.toString(); - } - return console; - } - - @Override - public void confirmClicked(boolean flag, int i){ - if(flag) - openLink("http://www.kodevelopment.nl/minecraft/customnpcs/scripting"); - displayGuiScreen(this); - } - - @Override - protected void actionPerformed(GuiButton guibutton) { - if(guibutton.id == 13){ - showScript = true; - initGui(); - } - if(guibutton.id == 14){ - setScript(); - showScript = false; - initGui(); - } - if(guibutton.id == 15){ - GuiConfirmOpenLink guiyesno = new GuiConfirmOpenLink(this, "http://www.kodevelopment.nl/minecraft/customnpcs/scripting", 0, true); - mc.displayGuiScreen(guiyesno); - } - if (guibutton.id == 100) { - NoppesStringUtils.setClipboardContents(getTextField(2).getText()); - } - if (guibutton.id == 101) { - getTextField(2).setText(NoppesStringUtils.getClipboardContents()); - } - if (guibutton.id == 102) { - getTextField(2).setText(""); - if(!showScript){ - if(activeConsole == 0){ - for(EventScriptContainer container : script.scripts) - for(Long l : container.console.keySet()) - container.console.put(l,""); - } - else{ - System.out.println("test"); - EventScriptContainer container = script.scripts.get(activeConsole - 1); - System.out.println("test2"); - if(container != null) - for(Long l : container.console.keySet()) - container.console.put(l,""); - } - } - } - if (guibutton.id == 103) { - script.setLanguage(((GuiNpcButton)guibutton).displayString); - } - if (guibutton.id == 104) { - script.setEnabled(((GuiNpcButton)guibutton).getValue() == 1); - } - if (guibutton.id == 105) { - activeConsole = ((GuiNpcButton)guibutton).getValue(); - initGui(); - } - if (guibutton.id == 106) { - NoppesUtil.openFolder(ScriptController.Instance.dir); - } - if (guibutton.id == 107) { - EventScriptContainer container = script.scripts.get(activeTab); - if(container == null) - script.scripts.set(activeTab, container = new EventScriptContainer(new EventDataScript())); - setSubGui(new EventGuiScriptList(languages.get(script.getLanguage()), container)); - } - if (guibutton.id == 108) { - EventScriptContainer container = script.scripts.get(activeTab); - if(container != null){ - setScript(); - this.AWTWindow = new GuiJTextArea(container.script).setListener(this); - } - } - } - - private void setScript(){ - if(showScript){ - EventScriptContainer container = script.scripts.get(activeTab); - if(container == null) - script.scripts.set(activeTab, container = new EventScriptContainer(new EventDataScript())); - String text = getTextField(2).getText(); - text = text.replace("\r\n", "\n"); - text = text.replace("\r", "\n"); - container.script = text; - } - } - - @Override - public void customScrollClicked(int i, int j, int k, GuiCustomScroll scroll) { - if(scroll.id == 1){ - setScript(); - activeTab = scroll.selected; - initGui(); - } - } - - @Override - public void saveText(String text) { - EventScriptContainer container = script.scripts.get(activeTab); - if(container != null) - container.script = text; - initGui(); - } - - @Override - public void setGuiData(NBTTagCompound compound) { - script.readFromNBT(compound); - NBTTagList data = compound.getTagList("Languages", 10); - Map> languages = new HashMap>(); - for(int i = 0; i < data.tagCount(); i++){ - NBTTagCompound comp = data.getCompoundTagAt(i); - List scripts = new ArrayList(); - NBTTagList list = comp.getTagList("Scripts", 8); - for(int j = 0; j < list.tagCount(); j++){ - scripts.add(list.getStringTagAt(j)); - } - languages.put(comp.getString("Language"), scripts); - } - this.languages = languages; - initGui(); - } - - @Override - public void save() { - Client.sendData(EnumPacketServer.ScriptPlayerSave, new Object[]{this.script.writeToNBT(new NBTTagCompound())}); - } -} diff --git a/src/main/java/noppes/npcs/client/gui/script/GuiScriptGlobal.java b/src/main/java/noppes/npcs/client/gui/script/GuiScriptGlobal.java index a1fa86401..e554014e4 100644 --- a/src/main/java/noppes/npcs/client/gui/script/GuiScriptGlobal.java +++ b/src/main/java/noppes/npcs/client/gui/script/GuiScriptGlobal.java @@ -9,8 +9,9 @@ import net.minecraft.client.gui.GuiButton; import net.minecraft.util.ResourceLocation; import noppes.npcs.client.gui.util.GuiNPCInterface; import noppes.npcs.client.gui.util.GuiNpcButton; +import org.lwjgl.opengl.GL11; -public class GuiScriptGlobal extends GuiNPCInterface { +public class GuiScriptGlobal extends EventGuiNPCInterface { private final ResourceLocation resource = new ResourceLocation("customnpcs", "textures/gui/smallbg.png"); public GuiScriptGlobal() { @@ -23,12 +24,12 @@ public class GuiScriptGlobal extends GuiNPCInterface { public void initGui() { super.initGui(); this.addButton(new GuiNpcButton(0, this.guiLeft + 38, this.guiTop + 20, 100, 20, "Players")); - //this.addButton(new GuiNpcButton(1, this.guiLeft + 38, this.guiTop + 50, 100, 20, "Forge")); + this.addButton(new GuiNpcButton(1, this.guiLeft + 38, this.guiTop + 50, 100, 20, "Forge")); } public void drawScreen(int i, int j, float f) { this.drawDefaultBackground(); - //GlStateManager.func_179131_c(1.0F, 1.0F, 1.0F, 1.0F); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); this.mc.renderEngine.bindTexture(this.resource); this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize); super.drawScreen(i, j, f); @@ -38,18 +39,15 @@ public class GuiScriptGlobal extends GuiNPCInterface { if (guibutton.id == 0) { this.displayGuiScreen(new GuiScriptPlayers()); } - /* - if (guibutton.id == 1) { + /*if (guibutton.id == 1) { this.displayGuiScreen(new GuiScriptForge()); - } - */ + }*/ } public void keyTyped(char c, int i) { if (i == 1 || this.isInventoryKey(i)) { this.close(); } - } public void save() { diff --git a/src/main/java/noppes/npcs/client/gui/script/GuiScriptInterface.java b/src/main/java/noppes/npcs/client/gui/script/GuiScriptInterface.java index 7e4c0676c..375a45cb5 100644 --- a/src/main/java/noppes/npcs/client/gui/script/GuiScriptInterface.java +++ b/src/main/java/noppes/npcs/client/gui/script/GuiScriptInterface.java @@ -1,6 +1,6 @@ // // Source code recreated from a .class file by IntelliJ IDEA -// (powered by FernFlower decompiler) +// (powered by Fernflower decompiler) // package noppes.npcs.client.gui.script; @@ -16,31 +16,20 @@ import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiConfirmOpenLink; import net.minecraft.client.gui.GuiYesNo; import net.minecraft.client.gui.GuiYesNoCallback; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; -import net.minecraft.server.MinecraftServer; -import noppes.npcs.EventDataScript; import noppes.npcs.EventScriptContainer; import noppes.npcs.NoppesStringUtils; import noppes.npcs.client.NoppesUtil; -import noppes.npcs.client.gui.EventGuiScriptList; -import noppes.npcs.client.gui.swing.GuiJTextArea; import noppes.npcs.client.gui.util.*; import noppes.npcs.controllers.IScriptHandler; -import noppes.npcs.controllers.ScriptContainer; import noppes.npcs.controllers.ScriptController; -import noppes.npcs.controllers.data.PlayerScriptData; -public class GuiScriptInterface extends GuiNPCInterface implements IGuiData, ITextChangeListener, GuiYesNoCallback, ICustomScrollListener, IJTextAreaListener { +public class GuiScriptInterface extends EventGuiNPCInterface implements GuiYesNoCallback, IGuiData, ITextChangeListener { private int activeTab = 0; public IScriptHandler handler; - private String activeScriptTab = "init"; public Map> languages = new HashMap(); - public boolean showScript = false; - private static int activeConsole = 0; - public GuiScriptInterface() { this.drawDefaultBackground = true; this.closeOnEsc = true; @@ -49,98 +38,91 @@ public class GuiScriptInterface extends GuiNPCInterface implements IGuiData, ITe } public void initGui() { + this.xSize = (int)((double)this.width * 0.88D); + this.ySize = (int)((double)this.xSize * 0.56D); + if((double)this.ySize > (double)this.height * 0.95D) { + this.ySize = (int)((double)this.height * 0.95D); + this.xSize = (int)((double)this.ySize / 0.56D); + } + + this.bgScale = (float)this.xSize / 400.0F; super.initGui(); - guiTop += 10; + this.guiTop += 10; + int yoffset = (int)((double)this.ySize * 0.02D); GuiMenuTopButton top; - addTopButton(top = new GuiMenuTopButton(13, guiLeft + 4, guiTop - 17, "eventscript.playerevent")); - top.active = showScript; - addTopButton(top = new GuiMenuTopButton(14, top, "gui.settings")); - top.active = !showScript; - addTopButton(new GuiMenuTopButton(15, top, "gui.website")); + this.addTopButton(top = new GuiMenuTopButton(0, this.guiLeft + 4, this.guiTop - 17, "gui.settings")); - List list = new ArrayList(); - list.add("playerscript.attack"); - list.add("playerscript.chat"); - list.add("playerscript.containerclosed"); - list.add("playerscript.containeropen"); - list.add("playerscript.damagedentity"); - list.add("playerscript.damaged"); - list.add("playerscript.killed"); - list.add("playerscript.init"); - list.add("playerscript.interact"); - list.add("playerscript.keypressed"); - list.add("playerscript.kills"); - list.add("playerscript.levelup"); - list.add("playerscript.login"); - list.add("playerscript.logout"); - list.add("playerscript.pickup"); - list.add("playerscript.rangedlaunched"); - list.add("playerscript.toss"); - list.add("playerscript.update"); - - if(showScript) { - addLabel(new GuiNpcLabel(0, "script.hooks", guiLeft + 4, guiTop + 5)); - GuiCustomScroll hooks = new GuiCustomScroll(this, 1); - hooks.setSize(68, 198); - hooks.guiLeft = guiLeft + 4; - hooks.guiTop = guiTop + 14; - hooks.setUnsortedList(list); - hooks.selected = activeTab; - addScroll(hooks); - - EventScriptContainer container = handler.getScripts().get(activeTab); - - addTextField(new GuiNpcTextArea(2, this, guiLeft + 74, guiTop + 4, 239, 208, container == null?"":container.script)); - - addButton(new GuiNpcButton(102, guiLeft + 315, guiTop + 4, 50, 20, "gui.clear")); - addButton(new GuiNpcButton(101, guiLeft + 366, guiTop + 4, 50, 20, "gui.paste")); - addButton(new GuiNpcButton(100, guiLeft + 315, guiTop + 25, 50, 20, "gui.copy")); - - addButton(new GuiNpcButton(108, guiLeft + 315, guiTop + 47, 80, 20, "gui.editor")); - - addButton(new GuiNpcButton(107, guiLeft + 315, guiTop + 70, 80, 20, "script.loadscript")); - - GuiCustomScroll scroll = new GuiCustomScroll(this, 0).setUnselectable(); - scroll.setSize(100, 120); - scroll.guiLeft = guiLeft + 315; - scroll.guiTop = guiTop + 92; - if(container != null) - scroll.setList(container.scripts); - addScroll(scroll); + for(int ta = 0; ta < this.handler.getScripts().size(); ++ta) { + EventScriptContainer var10000 = (EventScriptContainer)this.handler.getScripts().get(ta); + this.addTopButton(top = new GuiMenuTopButton(ta + 1, top, ta + 1 + "")); } - else{ - addLabel(new GuiNpcLabel(0, "script.console", guiLeft + 4, guiTop + 16)); - getTopButton(14).active = true; - addTextField(new GuiNpcTextArea(2, this, guiLeft + 4, guiTop + 26, 226, 186, getConsoleText())); - getTextField(2).canEdit = false; - addButton(new GuiNpcButton(100, guiLeft + 232, guiTop + 170, 56, 20, "gui.copy")); - addButton(new GuiNpcButton(102, guiLeft + 232, guiTop + 192, 56, 20, "gui.clear")); - List l = new ArrayList(); - l.add("All"); - l.addAll(list); - addButton(new GuiNpcButton(105, guiLeft + 60, guiTop + 4, 80, 20, l.toArray(new String[l.size()]), activeConsole)); - - addLabel(new GuiNpcLabel(1, "script.language", guiLeft + 232, guiTop + 30)); - addButton(new GuiNpcButton(103, guiLeft + 294, guiTop + 25, 80, 20, languages.keySet().toArray(new String[languages.keySet().size()]), getScriptIndex())); - getButton(103).enabled = languages.size() > 0; - - addLabel(new GuiNpcLabel(2, "gui.enabled", guiLeft + 232, guiTop + 53)); - //addButton(new GuiNpcButton(104, guiLeft + 294, guiTop + 48, 50, 20, new String[]{"gui.no","gui.yes"}, handler.enabled?1:0)); - - if(MinecraftServer.getServer() != null) - addButton(new GuiNpcButton(106, guiLeft + 232, guiTop + 71, 150, 20, "script.openfolder")); + if(this.handler.getScripts().size() < 16) { + this.addTopButton(new GuiMenuTopButton(12, top, "+")); } + + top = this.getTopButton(this.activeTab); + if(top == null) { + this.activeTab = 0; + top = this.getTopButton(0); + } + + top.active = true; + if(this.activeTab > 0) { + EventScriptContainer var7 = (EventScriptContainer)this.handler.getScripts().get(this.activeTab - 1); + GuiTextArea left = new GuiTextArea(2, this.guiLeft + 1 + yoffset, this.guiTop + yoffset, this.xSize - 108 - yoffset, (int)((double)this.ySize * 0.96D) - yoffset * 2, var7 == null?"":var7.script); + //left.enableCodeHighlighting(); + //left.setListener(this); + this.add(left); + int left1 = this.guiLeft + this.xSize - 104; + this.addButton(new GuiNpcButton(102, left1, this.guiTop + yoffset, 60, 20, "gui.clear")); + this.addButton(new GuiNpcButton(101, left1 + 61, this.guiTop + yoffset, 60, 20, "gui.paste")); + this.addButton(new GuiNpcButton(100, left1, this.guiTop + 21 + yoffset, 60, 20, "gui.copy")); + this.addButton(new GuiNpcButton(105, left1 + 61, this.guiTop + 21 + yoffset, 60, 20, "gui.remove")); + this.addButton(new GuiNpcButton(107, left1, this.guiTop + 66 + yoffset, 80, 20, "script.loadscript")); + GuiCustomScroll scroll = (new GuiCustomScroll(this, 0)).setUnselectable(); + scroll.setSize(100, (int)((double)this.ySize * 0.54D) - yoffset * 2); + scroll.guiLeft = left1; + scroll.guiTop = this.guiTop + 88 + yoffset; + if(var7 != null) { + scroll.setList(var7.scripts); + } + + this.addScroll(scroll); + } else { + GuiTextArea var8 = new GuiTextArea(2, this.guiLeft + 4 + yoffset, this.guiTop + 6 + yoffset, this.xSize - 160 - yoffset, (int)((float)this.ySize * 0.92F) - yoffset * 2, this.getConsoleText()); + var8.enabled = false; + this.add(var8); + int var9 = this.guiLeft + this.xSize - 150; + this.addButton(new GuiNpcButton(100, var9, this.guiTop + 125, 60, 20, "gui.copy")); + this.addButton(new GuiNpcButton(102, var9, this.guiTop + 146, 60, 20, "gui.clear")); + this.addLabel(new GuiNpcLabel(1, "script.language", var9, this.guiTop + 15)); + this.addButton(new GuiNpcButton(103, var9 + 60, this.guiTop + 10, 80, 20, (String[])this.languages.keySet().toArray(new String[this.languages.keySet().size()]), this.getScriptIndex())); + this.getButton(103).enabled = this.languages.size() > 0; + this.addLabel(new GuiNpcLabel(2, "gui.enabled", var9, this.guiTop + 36)); + this.addButton(new GuiNpcButton(104, var9 + 60, this.guiTop + 31, 50, 20, new String[]{"gui.no", "gui.yes"}, this.handler.getEnabled()?1:0)); + if(this.player.worldObj.isRemote) { + this.addButton(new GuiNpcButton(106, var9, this.guiTop + 55, 150, 20, "script.openfolder")); + } + + this.addButton(new GuiNpcButton(109, var9, this.guiTop + 78, 80, 20, "gui.website")); + this.addButton(new GuiNpcButton(112, var9 + 81, this.guiTop + 78, 80, 20, "gui.forum")); + this.addButton(new GuiNpcButton(110, var9, this.guiTop + 99, 80, 20, "script.apidoc")); + this.addButton(new GuiNpcButton(111, var9 + 81, this.guiTop + 99, 80, 20, "script.apisrc")); + } + + this.xSize = 420; + this.ySize = 256; } private String getConsoleText() { - Map map = this.handler.getConsoleText(); + Map map = this.handler.getConsoleText(); StringBuilder builder = new StringBuilder(); Iterator var3 = map.entrySet().iterator(); while(var3.hasNext()) { - Entry entry = (Entry)var3.next(); - builder.insert(0, new Date((Long)entry.getKey()) + (String)entry.getValue() + "\n"); + Entry entry = (Entry)var3.next(); + builder.insert(0, new Date(((Long)entry.getKey()).longValue()) + (String)entry.getValue() + "\n"); } return builder.toString(); @@ -151,7 +133,7 @@ public class GuiScriptInterface extends GuiNPCInterface implements IGuiData, ITe for(Iterator var2 = this.languages.keySet().iterator(); var2.hasNext(); ++i) { String language = (String)var2.next(); - if (language.equalsIgnoreCase(this.handler.getLanguage())) { + if(language.equalsIgnoreCase(this.handler.getLanguage())) { return i; } } @@ -159,25 +141,25 @@ public class GuiScriptInterface extends GuiNPCInterface implements IGuiData, ITe return 0; } - public void func_73878_a(boolean flag, int i) { - if (flag) { - if (i == 0) { + public void confirmClicked(boolean flag, int i) { + if(flag) { + if(i == 0) { this.openLink("http://www.kodevelopment.nl/minecraft/customnpcs/scripting"); } - if (i == 1) { + if(i == 1) { this.openLink("http://www.kodevelopment.nl/customnpcs/api/"); } - if (i == 2) { + if(i == 2) { this.openLink("http://www.kodevelopment.nl/minecraft/customnpcs/scripting"); } - if (i == 3) { + if(i == 3) { this.openLink("http://www.minecraftforge.net/forum/index.php/board,122.0.html"); } - if (i == 10) { + if(i == 10) { this.handler.getScripts().remove(this.activeTab - 1); this.activeTab = 0; } @@ -187,79 +169,97 @@ public class GuiScriptInterface extends GuiNPCInterface implements IGuiData, ITe } protected void actionPerformed(GuiButton guibutton) { - if(guibutton.id == 13){ - showScript = true; - initGui(); + if(guibutton.id >= 0 && guibutton.id < 12) { + this.setScript(); + this.activeTab = guibutton.id; + this.initGui(); } - if(guibutton.id == 14){ - setScript(); - showScript = false; - initGui(); + + if(guibutton.id == 12) { + this.handler.getScripts().add(new EventScriptContainer(this.handler)); + this.activeTab = this.handler.getScripts().size(); + this.initGui(); } - if(guibutton.id == 15){ - GuiConfirmOpenLink guiyesno = new GuiConfirmOpenLink(this, "http://www.kodevelopment.nl/minecraft/customnpcs/scripting", 0, true); - mc.displayGuiScreen(guiyesno); + + if(guibutton.id == 109) { + this.displayGuiScreen(new GuiConfirmOpenLink(this, "http://www.kodevelopment.nl/minecraft/customnpcs/scripting", 0, true)); } - if (guibutton.id == 100) { - NoppesStringUtils.setClipboardContents(getTextField(2).getText()); + + if(guibutton.id == 110) { + this.displayGuiScreen(new GuiConfirmOpenLink(this, "http://www.kodevelopment.nl/customnpcs/api/", 1, true)); } - if (guibutton.id == 101) { - getTextField(2).setText(NoppesStringUtils.getClipboardContents()); + + if(guibutton.id == 111) { + this.displayGuiScreen(new GuiConfirmOpenLink(this, "https://github.com/Noppes/CustomNPCsAPI", 2, true)); } - if (guibutton.id == 102) { - getTextField(2).setText(""); - if(!showScript){ - if(activeConsole == 0){ - for(EventScriptContainer container : handler.getScripts()) - for(Long l : container.console.keySet()) - container.console.put(l,""); - } - else{ - System.out.println("test"); - EventScriptContainer container = handler.getScripts().get(activeConsole - 1); - System.out.println("test2"); - if(container != null) - for(Long l : container.console.keySet()) - container.console.put(l,""); - } + + if(guibutton.id == 112) { + this.displayGuiScreen(new GuiConfirmOpenLink(this, "http://www.minecraftforge.net/forum/index.php/board,122.0.html", 3, true)); + } + + if(guibutton.id == 100) { + NoppesStringUtils.setClipboardContents(((GuiTextArea)this.get(2)).getText()); + } + + if(guibutton.id == 101) { + ((GuiTextArea)this.get(2)).setText(NoppesStringUtils.getClipboardContents()); + } + + EventScriptContainer container; + if(guibutton.id == 102) { + if(this.activeTab > 0) { + container = (EventScriptContainer)this.handler.getScripts().get(this.activeTab - 1); + container.script = ""; + } else { + this.handler.clearConsole(); } + + this.initGui(); } - if (guibutton.id == 103) { - handler.setLanguage(((GuiNpcButton)guibutton).displayString); + + if(guibutton.id == 103) { + this.handler.setLanguage(((GuiNpcButton)guibutton).displayString); } - if (guibutton.id == 104) { - handler.setEnabled(((GuiNpcButton)guibutton).getValue() == 1); + + if(guibutton.id == 104) { + this.handler.setEnabled(((GuiNpcButton)guibutton).getValue() == 1); } - if (guibutton.id == 105) { - activeConsole = ((GuiNpcButton)guibutton).getValue(); - initGui(); + + if(guibutton.id == 105) { + GuiYesNo container1 = new GuiYesNo(this, "", ((GuiNpcButton)guibutton).displayString, 10); + this.displayGuiScreen(container1); } - if (guibutton.id == 106) { + + if(guibutton.id == 106) { NoppesUtil.openFolder(ScriptController.Instance.dir); } - if (guibutton.id == 107) { - EventScriptContainer container = handler.getScripts().get(activeTab); - if(container == null) - handler.getScripts().set(activeTab, container = new EventScriptContainer(new EventDataScript())); - setSubGui(new EventGuiScriptList(languages.get(handler.getLanguage()), container)); - } - if (guibutton.id == 108) { - EventScriptContainer container = handler.getScripts().get(activeTab); - if(container != null){ - setScript(); - this.AWTWindow = new GuiJTextArea(container.script).setListener(this); - } - } - } - private void setScript() { - if (this.activeTab > 0) { - EventScriptContainer container = (EventScriptContainer)this.handler.getScripts().get(this.activeTab - 1); - if (container == null) { + if(guibutton.id == 107) { + container = (EventScriptContainer)this.handler.getScripts().get(this.activeTab - 1); + if(container == null) { this.handler.getScripts().add(container = new EventScriptContainer(this.handler)); } - String text = this.getConsoleText(); + this.setSubGui(new EventGuiScriptList((List)this.languages.get(this.handler.getLanguage()), container)); + } + + if(guibutton.id == 108) { + container = (EventScriptContainer)this.handler.getScripts().get(this.activeTab - 1); + if(container != null) { + this.setScript(); + } + } + + } + + private void setScript() { + if(this.activeTab > 0) { + EventScriptContainer container = (EventScriptContainer)this.handler.getScripts().get(this.activeTab - 1); + if(container == null) { + this.handler.getScripts().add(container = new EventScriptContainer(this.handler)); + } + + String text = ((GuiTextArea)this.get(2)).getText(); text = text.replace("\r\n", "\n"); text = text.replace("\r", "\n"); container.script = text; @@ -269,11 +269,11 @@ public class GuiScriptInterface extends GuiNPCInterface implements IGuiData, ITe public void setGuiData(NBTTagCompound compound) { NBTTagList data = compound.getTagList("Languages", 10); - Map> languages = new HashMap(); + HashMap languages = new HashMap(); for(int i = 0; i < data.tagCount(); ++i) { NBTTagCompound comp = data.getCompoundTagAt(i); - List scripts = new ArrayList(); + ArrayList scripts = new ArrayList(); NBTTagList list = comp.getTagList("Scripts", 8); for(int j = 0; j < list.tagCount(); ++j) { @@ -293,25 +293,9 @@ public class GuiScriptInterface extends GuiNPCInterface implements IGuiData, ITe public void textUpdate(String text) { EventScriptContainer container = (EventScriptContainer)this.handler.getScripts().get(this.activeTab - 1); - if (container != null) { + if(container != null) { container.script = text; } - } - @Override - public void customScrollClicked(int i, int j, int k, GuiCustomScroll scroll) { - if(scroll.id == 1){ - setScript(); - activeTab = scroll.selected; - initGui(); - } - } - - @Override - public void saveText(String text) { - EventScriptContainer container = handler.getScripts().get(activeTab); - if(container != null) - container.script = text; - initGui(); } } diff --git a/src/main/java/noppes/npcs/client/gui/util/GuiCustomScroll.java b/src/main/java/noppes/npcs/client/gui/util/GuiCustomScroll.java index f567c7043..362400803 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiCustomScroll.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiCustomScroll.java @@ -280,4 +280,7 @@ public class GuiCustomScroll extends GuiScreen return this; } + public boolean isMouseOver(int x, int y) { + return x >= this.guiLeft && x <= this.guiLeft + this.xSize && y >= this.guiTop && y <= this.guiTop + this.ySize; + } } diff --git a/src/main/java/noppes/npcs/client/gui/util/GuiTextArea.java b/src/main/java/noppes/npcs/client/gui/util/GuiTextArea.java new file mode 100644 index 000000000..5103da22e --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/util/GuiTextArea.java @@ -0,0 +1,473 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.client.gui.util; + +import java.awt.Font; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.regex.Matcher; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.Gui; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.renderer.texture.TextureManager; +import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; +import net.minecraft.util.ChatAllowedCharacters; +import net.minecraftforge.client.GuiIngameForge; +import noppes.npcs.CustomNpcs; +import noppes.npcs.NoppesStringUtils; +import noppes.npcs.client.gui.util.TextContainer.LineData; +import noppes.npcs.config.TrueTypeFont; +import org.lwjgl.input.Mouse; + +public class GuiTextArea extends Gui implements IGui, IKeyListener, IMouseListener { + public int id; + public int x; + public int y; + public int width; + public int height; + private int cursorCounter; + private ITextChangeListener listener; + private static TrueTypeFont font; + public String text = null; + private TextContainer container = null; + public boolean active = false; + public boolean enabled = true; + public boolean visible = true; + public boolean clicked = false; + public boolean doubleClicked = false; + public boolean clickScrolling = false; + private int startSelection; + private int endSelection; + private int cursorPosition; + private int scrolledLine = 0; + private boolean enableCodeHighlighting = false; + private static final char colorChar = '\uffff'; + public List undoList = new ArrayList(); + public List redoList = new ArrayList(); + public boolean undoing = false; + private long lastClicked = 0L; + + public GuiTextArea(int id, int x, int y, int width, int height, String text) { + this.id = id; + this.x = x; + this.y = y; + this.width = width; + this.height = height; + this.undoing = true; + this.setText(text); + this.undoing = false; + font.setSpecial('\uffff'); + } + + public void drawScreen(int xMouse, int yMouse) { + if(this.visible) { + drawRect(this.x - 1, this.y - 1, this.x + this.width + 1, this.y + this.height + 1, -6250336); + drawRect(this.x, this.y, this.x + this.width, this.y + this.height, -16777216); + this.container.visibleLines = this.height / this.container.lineHeight; + int startBracket; + if(this.clicked) { + this.clicked = Mouse.isButtonDown(0); + startBracket = this.getSelectionPos(xMouse, yMouse); + if(startBracket != this.cursorPosition) { + if(this.doubleClicked) { + this.startSelection = this.endSelection = this.cursorPosition; + this.doubleClicked = false; + } + + this.setCursor(startBracket, true); + } + } else if(this.doubleClicked) { + this.doubleClicked = false; + } + + if(this.clickScrolling) { + this.clickScrolling = Mouse.isButtonDown(0); + startBracket = this.container.linesCount - this.container.visibleLines; + this.scrolledLine = Math.min(Math.max((int)(1.0F * (float)startBracket * (float)(yMouse - this.y) / (float)this.height), 0), startBracket); + } + + startBracket = 0; + int endBracket = 0; + if(this.endSelection - this.startSelection == 1 || this.startSelection == this.endSelection && this.startSelection < this.text.length()) { + char list = this.text.charAt(this.startSelection); + int wordHightLight = 0; + if(list == 123) { + wordHightLight = this.findClosingBracket(this.text.substring(this.startSelection), '{', '}'); + } else if(list == 91) { + wordHightLight = this.findClosingBracket(this.text.substring(this.startSelection), '[', ']'); + } else if(list == 40) { + wordHightLight = this.findClosingBracket(this.text.substring(this.startSelection), '(', ')'); + } else if(list == 125) { + wordHightLight = this.findOpeningBracket(this.text.substring(0, this.startSelection + 1), '{', '}'); + } else if(list == 93) { + wordHightLight = this.findOpeningBracket(this.text.substring(0, this.startSelection + 1), '[', ']'); + } else if(list == 41) { + wordHightLight = this.findOpeningBracket(this.text.substring(0, this.startSelection + 1), '(', ')'); + } + + if(wordHightLight != 0) { + startBracket = this.startSelection; + endBracket = this.startSelection + wordHightLight; + } + } + + ArrayList var15 = new ArrayList(this.container.lines); + String var18 = null; + if(this.startSelection != this.endSelection) { + Matcher sbSize = this.container.regexWord.matcher(this.text); + + while(sbSize.find()) { + if(sbSize.start() == this.startSelection && sbSize.end() == this.endSelection) { + var18 = this.text.substring(this.startSelection, this.endSelection); + } + } + } + + int var16; + for(var16 = 0; var16 < var15.size(); ++var16) { + LineData posX = (LineData)var15.get(var16); + String posY = posX.text; + int w = posY.length(); + int yPos; + int posX1; + int posY1; + if(startBracket != endBracket) { + if(startBracket >= posX.start && startBracket < posX.end) { + yPos = font.width(posY.substring(0, startBracket - posX.start)); + posX1 = font.width(posY.substring(0, startBracket - posX.start + 1)) + 1; + posY1 = this.y + 1 + (var16 - this.scrolledLine) * this.container.lineHeight; + drawRect(this.x + 1 + yPos, posY1, this.x + 1 + posX1, posY1 + this.container.lineHeight + 1, -1728001024); + } + + if(endBracket >= posX.start && endBracket < posX.end) { + yPos = font.width(posY.substring(0, endBracket - posX.start)); + posX1 = font.width(posY.substring(0, endBracket - posX.start + 1)) + 1; + posY1 = this.y + 1 + (var16 - this.scrolledLine) * this.container.lineHeight; + drawRect(this.x + 1 + yPos, posY1, this.x + 1 + posX1, posY1 + this.container.lineHeight + 1, -1728001024); + } + } + + if(var16 >= this.scrolledLine && var16 < this.scrolledLine + this.container.visibleLines) { + if(var18 != null) { + Matcher var20 = this.container.regexWord.matcher(posY); + + while(var20.find()) { + if(posY.substring(var20.start(), var20.end()).equals(var18)) { + posX1 = font.width(posY.substring(0, var20.start())); + posY1 = font.width(posY.substring(0, var20.end())) + 1; + int posY2 = this.y + 1 + (var16 - this.scrolledLine) * this.container.lineHeight; + drawRect(this.x + 1 + posX1, posY2, this.x + 1 + posY1, posY2 + this.container.lineHeight + 1, -1728033792); + } + } + } + + if(this.startSelection != this.endSelection && this.endSelection > posX.start && this.startSelection <= posX.end && this.startSelection < posX.end) { + yPos = font.width(posY.substring(0, Math.max(this.startSelection - posX.start, 0))); + posX1 = font.width(posY.substring(0, Math.min(this.endSelection - posX.start, w))) + 1; + posY1 = this.y + 1 + (var16 - this.scrolledLine) * this.container.lineHeight; + drawRect(this.x + 1 + yPos, posY1, this.x + 1 + posX1, posY1 + this.container.lineHeight + 1, -1728052993); + } + + yPos = this.y + (var16 - this.scrolledLine) * this.container.lineHeight + 1; + font.draw(posX.getFormattedString(), (float)(this.x + 1), (float)yPos, -2039584); + if(this.active && this.isEnabled() && this.cursorCounter / 6 % 2 == 0 && this.cursorPosition >= posX.start && this.cursorPosition < posX.end) { + posX1 = this.x + font.width(posY.substring(0, this.cursorPosition - posX.start)); + drawRect(posX1 + 1, yPos, posX1 + 2, yPos + 1 + this.container.lineHeight, -3092272); + } + } + } + + if(this.hasVerticalScrollbar()) { + Minecraft.getMinecraft().renderEngine.bindTexture(GuiCustomScroll.resource); + + var16 = Math.max((int)(1.0F * (float)this.container.visibleLines / (float)this.container.linesCount * (float)this.height), 2); + int var17 = this.x + this.width - 6; + int var19 = (int)((float)this.y + 1.0F * (float)this.scrolledLine / (float)this.container.linesCount * (float)(this.height - 4)) + 1; + drawRect(var17, var19, var17 + 5, var19 + var16, -2039584); + } + + } + } + + private int findClosingBracket(String str, char s, char e) { + int found = 0; + char[] chars = str.toCharArray(); + + for(int i = 0; i < chars.length; ++i) { + char c = chars[i]; + if(c == s) { + ++found; + } else if(c == e) { + --found; + if(found == 0) { + return i; + } + } + } + + return 0; + } + + private int findOpeningBracket(String str, char s, char e) { + int found = 0; + char[] chars = str.toCharArray(); + + for(int i = chars.length - 1; i >= 0; --i) { + char c = chars[i]; + if(c == e) { + ++found; + } else if(c == s) { + --found; + if(found == 0) { + return i - chars.length + 1; + } + } + } + + return 0; + } + + private int getSelectionPos(int xMouse, int yMouse) { + xMouse -= this.x + 1; + yMouse -= this.y + 1; + ArrayList list = new ArrayList(this.container.lines); + + for(int i = 0; i < list.size(); ++i) { + LineData data = (LineData)list.get(i); + if(i >= this.scrolledLine && i < this.scrolledLine + this.container.visibleLines) { + int yPos = (i - this.scrolledLine) * this.container.lineHeight; + if(yMouse >= yPos && yMouse < yPos + this.container.lineHeight) { + int lineWidth = 0; + char[] chars = data.text.toCharArray(); + + for(int j = 1; j <= chars.length; ++j) { + int w = font.width(data.text.substring(0, j)); + if(xMouse < lineWidth + (w - lineWidth) / 2) { + return data.start + j - 1; + } + + lineWidth = w; + } + + return data.end - 1; + } + } + } + + return this.container.text.length(); + } + + public int getID() { + return this.id; + } + + + public void keyTyped(char c, int i) { + if(this.active && this.isEnabled()) { + if(i == 15) { + this.addText(" "); + } + + if(i == 28) { + this.addText(Character.toString('\n') + this.getIndentCurrentLine()); + } + + if(ChatAllowedCharacters.isAllowedCharacter(c)) { + this.addText(Character.toString(c)); + } + } + } + + private String getIndentCurrentLine() { + Iterator var1 = this.container.lines.iterator(); + + LineData data; + do { + if(!var1.hasNext()) { + return ""; + } + + data = (LineData)var1.next(); + } while(this.cursorPosition <= data.start || this.cursorPosition > data.end); + + int i; + for(i = 0; i < data.text.length() && data.text.charAt(i) == 32; ++i) { + ; + } + + return data.text.substring(0, i); + } + + private void setCursor(int i, boolean select) { + i = Math.min(Math.max(i, 0), this.text.length()); + if(i != this.cursorPosition) { + if(!select) { + this.endSelection = this.startSelection = this.cursorPosition = i; + } else { + int diff = this.cursorPosition - i; + if(this.cursorPosition == this.startSelection) { + this.startSelection -= diff; + } else if(this.cursorPosition == this.endSelection) { + this.endSelection -= diff; + } + + if(this.startSelection > this.endSelection) { + int j = this.endSelection; + this.endSelection = this.startSelection; + this.startSelection = j; + } + + this.cursorPosition = i; + } + } + } + + private void addText(String s) { + this.setText(this.getSelectionBeforeText() + s + this.getSelectionAfterText()); + this.endSelection = this.startSelection = this.cursorPosition = this.startSelection + s.length(); + } + + private int cursorUp() { + for(int i = 0; i < this.container.lines.size(); ++i) { + LineData data = (LineData)this.container.lines.get(i); + if(this.cursorPosition >= data.start && this.cursorPosition < data.end) { + if(i == 0) { + return 0; + } + + int var10000 = this.cursorPosition - data.start; + return this.getSelectionPos(this.x + 1 + font.width(data.text.substring(0, this.cursorPosition - data.start)), this.y + 1 + (i - 1 - this.scrolledLine) * this.container.lineHeight); + } + } + + return 0; + } + + private int cursorDown() { + for(int i = 0; i < this.container.lines.size(); ++i) { + LineData data = (LineData)this.container.lines.get(i); + if(this.cursorPosition >= data.start && this.cursorPosition < data.end) { + int var10000 = this.cursorPosition - data.start; + return this.getSelectionPos(this.x + 1 + font.width(data.text.substring(0, this.cursorPosition - data.start)), this.y + 1 + (i + 1 - this.scrolledLine) * this.container.lineHeight); + } + } + + return this.text.length(); + } + + public String getSelectionBeforeText() { + return this.startSelection == 0?"":this.text.substring(0, this.startSelection); + } + + public String getSelectionAfterText() { + return this.text.substring(this.endSelection); + } + + public boolean mouseClicked(int xMouse, int yMouse, int mouseButton) { + this.active = xMouse >= this.x && xMouse < this.x + this.width && yMouse >= this.y && yMouse < this.y + this.height; + if(this.active) { + this.startSelection = this.endSelection = this.cursorPosition = this.getSelectionPos(xMouse, yMouse); + this.clicked = mouseButton == 0; + this.doubleClicked = false; + long time = System.currentTimeMillis(); + if(this.clicked && this.container.linesCount * this.container.lineHeight > this.height && xMouse > this.x + this.width - 8) { + this.clicked = false; + this.clickScrolling = true; + } else if(time - this.lastClicked < 500L) { + this.doubleClicked = true; + Matcher m = this.container.regexWord.matcher(this.text); + + while(m.find()) { + if(this.cursorPosition > m.start() && this.cursorPosition < m.end()) { + this.startSelection = m.start(); + this.endSelection = m.end(); + break; + } + } + } + + this.lastClicked = time; + } + + return this.active; + } + + public void updateScreen() { + ++this.cursorCounter; + int k2 = Mouse.getDWheel(); + if(k2 != 0) { + this.scrolledLine += k2 > 0?-1:1; + this.scrolledLine = Math.max(Math.min(this.scrolledLine, this.container.linesCount - this.height / this.container.lineHeight), 0); + } + + } + + public void setText(String text) { + text = text.replace("\r", ""); + if(this.text == null || !this.text.equals(text)) { + if(this.listener != null) { + this.listener.textUpdate(text); + } + + if(!this.undoing) { + this.undoList.add(new GuiTextArea.UndoData(this.text, this.cursorPosition)); + this.redoList.clear(); + } + + this.text = text; + this.container = new TextContainer(text); + this.container.init(font, this.width, this.height); + if(this.enableCodeHighlighting) { + this.container.formatCodeText(); + } + + if(this.scrolledLine > this.container.linesCount - this.container.visibleLines) { + this.scrolledLine = Math.max(0, this.container.linesCount - this.container.visibleLines); + } + + } + } + + public String getText() { + return this.text; + } + + public boolean isEnabled() { + return this.enabled && this.visible; + } + + public boolean hasVerticalScrollbar() { + return this.container.visibleLines < this.container.linesCount; + } + + public void enableCodeHighlighting() { + this.enableCodeHighlighting = true; + this.container.formatCodeText(); + } + + public void setListener(ITextChangeListener listener) { + this.listener = listener; + } + + public boolean isActive() { + return this.active; + } + + static { + font = new TrueTypeFont(new Font("Arial Unicode MS", 0, CustomNpcs.FontSize), 1.0F); + } + + class UndoData { + public String text; + public int cursorPosition; + + public UndoData(String text, int cursorPosition) { + this.text = text; + this.cursorPosition = cursorPosition; + } + } +} diff --git a/src/main/java/noppes/npcs/client/gui/util/IGui.java b/src/main/java/noppes/npcs/client/gui/util/IGui.java new file mode 100644 index 000000000..cc0d20135 --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/util/IGui.java @@ -0,0 +1,16 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.client.gui.util; + +public interface IGui { + int getID(); + + void drawScreen(int var1, int var2); + + void updateScreen(); + + boolean isActive(); +} diff --git a/src/main/java/noppes/npcs/client/gui/util/IKeyListener.java b/src/main/java/noppes/npcs/client/gui/util/IKeyListener.java new file mode 100644 index 000000000..643352735 --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/util/IKeyListener.java @@ -0,0 +1,10 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.client.gui.util; + +public interface IKeyListener { + void keyTyped(char var1, int var2); +} diff --git a/src/main/java/noppes/npcs/client/gui/util/IMouseListener.java b/src/main/java/noppes/npcs/client/gui/util/IMouseListener.java new file mode 100644 index 000000000..7204139b4 --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/util/IMouseListener.java @@ -0,0 +1,10 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.client.gui.util; + +public interface IMouseListener { + boolean mouseClicked(int var1, int var2, int var3); +} diff --git a/src/main/java/noppes/npcs/client/gui/util/TextContainer.java b/src/main/java/noppes/npcs/client/gui/util/TextContainer.java new file mode 100644 index 000000000..8d8fc3b6d --- /dev/null +++ b/src/main/java/noppes/npcs/client/gui/util/TextContainer.java @@ -0,0 +1,225 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.client.gui.util; + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.Iterator; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import noppes.npcs.config.TrueTypeFont; + +public class TextContainer { + private static final char colorChar = '\uffff'; + private static final Comparator MarkUpComparator = (o1, o2) -> { + return o1.start > o2.start?1:(o1.start < o2.start?-1:0); + }; + public final Pattern regexString = Pattern.compile("([\"\'])(?:(?=(\\\\?))\\2.)*?\\1", 8); + public final Pattern regexFunction = Pattern.compile("\\b(if|else|switch|with|for|while|in|var|const|let|throw|then|function|continue|break|foreach|return|try|catch|finally|do|this|typeof|instanceof|new)(?=[^\\w])"); + public final Pattern regexWord = Pattern.compile("[\\p{L}-]+|\\n|$"); + public final Pattern regexNumber = Pattern.compile("\\b-?(?:0[xX][\\dA-Fa-f]+|0[bB][01]+|0[oO][0-7]+|\\d*\\.?\\d+(?:[Ee][+-]?\\d+)?(?:[fFbBdDlLsS])?|NaN|null|Infinity|unidentified|true|false)\\b"); + public final Pattern regexComment = Pattern.compile("\\/\\*[\\s\\S]*?(?:\\*\\/|$)|\\/\\/.*|#.*"); + public String text; + public List makeup = new ArrayList(); + public List lines = new ArrayList(); + private TrueTypeFont font; + public int lineHeight; + public int totalHeight; + public int visibleLines = 1; + public int linesCount; + + public TextContainer(String text) { + this.text = text; + text.replaceAll("\\r?\\n|\\r", "\n"); + double l = 1.0D; + } + + public void init(TrueTypeFont font, int width, int height) { + this.font = font; + this.lineHeight = font.height(this.text); + if(this.lineHeight == 0) { + this.lineHeight = 12; + } + + String[] split = this.text.split("\n"); + int totalChars = 0; + String[] var6 = split; + int var7 = split.length; + + for(int var8 = 0; var8 < var7; ++var8) { + String l = var6[var8]; + StringBuilder line = new StringBuilder(); + Matcher m = this.regexWord.matcher(l); + + for(int i = 0; m.find(); i = m.start()) { + String word = l.substring(i, m.start()); + if(font.width(line + word) > width - 10) { + this.lines.add(new TextContainer.LineData(line.toString(), totalChars, totalChars + line.length())); + totalChars += line.length(); + line = new StringBuilder(); + } + + line.append(word); + } + + this.lines.add(new TextContainer.LineData(line.toString(), totalChars, totalChars + line.length() + 1)); + totalChars += line.length() + 1; + } + + this.linesCount = this.lines.size(); + this.totalHeight = this.linesCount * this.lineHeight; + this.visibleLines = Math.max(height / this.lineHeight, 1); + } + + public void formatCodeText() { + TextContainer.MarkUp markup = null; + + for(int start = 0; (markup = this.getNextMatching(start)) != null; start = markup.end) { + this.makeup.add(markup); + } + + } + + private TextContainer.MarkUp getNextMatching(int start) { + TextContainer.MarkUp markup = null; + String s = this.text.substring(start); + Matcher matcher = this.regexNumber.matcher(s); + if(matcher.find()) { + markup = new TextContainer.MarkUp(matcher.start(), matcher.end(), '6', 0); + } + + matcher = this.regexFunction.matcher(s); + TextContainer.MarkUp markup2; + if(matcher.find()) { + markup2 = new TextContainer.MarkUp(matcher.start(), matcher.end(), '2', 0); + if(this.compareMarkUps(markup, markup2)) { + markup = markup2; + } + } + + matcher = this.regexString.matcher(s); + if(matcher.find()) { + markup2 = new TextContainer.MarkUp(matcher.start(), matcher.end(), '4', 7); + if(this.compareMarkUps(markup, markup2)) { + markup = markup2; + } + } + + matcher = this.regexComment.matcher(s); + if(matcher.find()) { + markup2 = new TextContainer.MarkUp(matcher.start(), matcher.end(), '8', 7); + if(this.compareMarkUps(markup, markup2)) { + markup = markup2; + } + } + + if(markup != null) { + markup.start += start; + markup.end += start; + } + + return markup; + } + + public boolean compareMarkUps(TextContainer.MarkUp mu1, TextContainer.MarkUp mu2) { + return mu1 == null?true:mu1.start > mu2.start; + } + + public void addMakeUp(int start, int end, char c, int level) { + if(this.removeConflictingMarkUp(start, end, level)) { + this.makeup.add(new TextContainer.MarkUp(start, end, c, level)); + } + } + + private boolean removeConflictingMarkUp(int start, int end, int level) { + ArrayList conflicting = new ArrayList(); + Iterator var5 = this.makeup.iterator(); + + while(true) { + TextContainer.MarkUp m; + do { + if(!var5.hasNext()) { + this.makeup.removeAll(conflicting); + return true; + } + + m = (TextContainer.MarkUp)var5.next(); + } while((start < m.start || start > m.end) && (end < m.start || end > m.end) && (start >= m.start || end <= m.start)); + + if(level < m.level || level == m.level && m.start <= start) { + return false; + } + + conflicting.add(m); + } + } + + public String getFormattedString() { + StringBuilder builder = new StringBuilder(this.text); + Iterator var2 = this.makeup.iterator(); + + while(var2.hasNext()) { + TextContainer.MarkUp entry = (TextContainer.MarkUp)var2.next(); + builder.insert(entry.start, Character.toString('\uffff') + Character.toString(entry.c)); + builder.insert(entry.end, Character.toString('\uffff') + Character.toString('r')); + } + + return builder.toString(); + } + + class MarkUp { + public int start; + public int end; + public int level; + public char c; + + public MarkUp(int start, int end, char c, int level) { + this.start = start; + this.end = end; + this.c = c; + this.level = level; + } + } + + class LineData { + public String text; + public int start; + public int end; + + public LineData(String text, int start, int end) { + this.text = text; + this.start = start; + this.end = end; + } + + public String getFormattedString() { + StringBuilder builder = new StringBuilder(this.text); + int found = 0; + Iterator var3 = TextContainer.this.makeup.iterator(); + + while(var3.hasNext()) { + TextContainer.MarkUp entry = (TextContainer.MarkUp)var3.next(); + if(entry.start >= this.start && entry.start < this.end) { + builder.insert(entry.start - this.start + found * 2, Character.toString('\uffff') + Character.toString(entry.c)); + ++found; + } + + if(entry.start < this.start && entry.end > this.start) { + builder.insert(0, Character.toString('\uffff') + Character.toString(entry.c)); + ++found; + } + + if(entry.end >= this.start && entry.end < this.end) { + builder.insert(entry.end - this.start + found * 2, Character.toString('\uffff') + Character.toString('r')); + ++found; + } + } + + return builder.toString(); + } + } +} diff --git a/src/main/java/noppes/npcs/config/TrueTypeFont.java b/src/main/java/noppes/npcs/config/TrueTypeFont.java new file mode 100644 index 000000000..15cbd65dd --- /dev/null +++ b/src/main/java/noppes/npcs/config/TrueTypeFont.java @@ -0,0 +1,340 @@ +// +// Source code recreated from a .class file by IntelliJ IDEA +// (powered by Fernflower decompiler) +// + +package noppes.npcs.config; + +import java.awt.Font; +import java.awt.FontFormatException; +import java.awt.FontMetrics; +import java.awt.Graphics2D; +import java.awt.GraphicsEnvironment; +import java.awt.RenderingHints; +import java.awt.image.BufferedImage; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.texture.TextureUtil; +import net.minecraft.util.ResourceLocation; +import noppes.npcs.util.LRUHashMap; +import org.lwjgl.opengl.GL11; + +public class TrueTypeFont { + private static final int MaxWidth = 512; + private static final List allFonts = Arrays.asList(GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts()); + private List usedFonts = new ArrayList(); + private LinkedHashMap textcache = new LRUHashMap(100); + private Map glyphcache = new HashMap(); + private List textures = new ArrayList(); + private Font font; + private int lineHeight = 1; + private Graphics2D globalG = (Graphics2D)(new BufferedImage(1, 1, 2)).getGraphics(); + public float scale = 1.0F; + private int specialChar = 167; + + public TrueTypeFont(Font font, float scale) { + this.font = font; + this.scale = scale; + this.globalG.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + this.lineHeight = this.globalG.getFontMetrics(font).getHeight(); + } + + public TrueTypeFont(ResourceLocation resource, int fontSize, float scale) throws IOException, FontFormatException { + InputStream stream = Minecraft.getMinecraft().getResourceManager().getResource(resource).getInputStream(); + GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); + Font font = Font.createFont(0, stream); + ge.registerFont(font); + this.font = font.deriveFont(0, (float)fontSize); + this.scale = scale; + this.globalG.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + this.lineHeight = this.globalG.getFontMetrics(font).getHeight(); + } + + public void setSpecial(char c) { + this.specialChar = c; + } + + public void draw(String text, float x, float y, int color) { + TrueTypeFont.GlyphCache cache = this.getOrCreateCache(text); + float r = (float)(color >> 16 & 255) / 255.0F; + float g = (float)(color >> 8 & 255) / 255.0F; + float b = (float)(color & 255) / 255.0F; + GL11.glColor4f(r, g, b, 1.0F); + //GlStateManager.func_179147_l(); + GL11.glPushMatrix(); + GL11.glTranslatef(x, y, 0.0F); + GL11.glScalef(this.scale, this.scale, 1.0F); + float i = 0.0F; + Iterator var10 = cache.glyphs.iterator(); + + while(var10.hasNext()) { + TrueTypeFont.Glyph gl = (TrueTypeFont.Glyph)var10.next(); + if(gl.type != TrueTypeFont.GlyphType.NORMAL) { + if(gl.type == TrueTypeFont.GlyphType.RESET) { + GL11.glColor4f(r, g, b, 1.0F); + } else if(gl.type == TrueTypeFont.GlyphType.COLOR) { + GL11.glColor4f((float) (gl.color >> 16 & 255) / 255.0F, (float) (gl.color >> 8 & 255) / 255.0F, (float) (gl.color & 255) / 255.0F, 1.0F); + } + } else { + GL11.glBindTexture(gl.texture, gl.texture); + this.drawTexturedModalRect(i, 0.0F, (float)gl.x * this.textureScale(), (float)gl.y * this.textureScale(), (float)gl.width * this.textureScale(), (float)gl.height * this.textureScale()); + i += (float)gl.width * this.textureScale(); + } + } + + //GlStateManager.func_179084_k(); + GL11.glPopMatrix(); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + } + + private TrueTypeFont.GlyphCache getOrCreateCache(String text) { + TrueTypeFont.GlyphCache cache = (TrueTypeFont.GlyphCache)this.textcache.get(text); + if(cache != null) { + return cache; + } else { + cache = new TrueTypeFont.GlyphCache(); + + for(int i = 0; i < text.length(); ++i) { + char c = text.charAt(i); + if(c == this.specialChar && i + 1 < text.length()) { + char g = text.toLowerCase(Locale.ENGLISH).charAt(i + 1); + int index = "0123456789abcdefklmnor".indexOf(g); + if(index >= 0) { + TrueTypeFont.Glyph g1 = new TrueTypeFont.Glyph(); + if(index < 16) { + g1.type = TrueTypeFont.GlyphType.COLOR; + //g1.color = Minecraft.getMinecraft().fontRenderer.func_175064_b(g); + g1.color = 0; + } else if(index == 16) { + g1.type = TrueTypeFont.GlyphType.RANDOM; + } else if(index == 17) { + g1.type = TrueTypeFont.GlyphType.BOLD; + } else if(index == 18) { + g1.type = TrueTypeFont.GlyphType.STRIKETHROUGH; + } else if(index == 19) { + g1.type = TrueTypeFont.GlyphType.UNDERLINE; + } else if(index == 20) { + g1.type = TrueTypeFont.GlyphType.ITALIC; + } else { + g1.type = TrueTypeFont.GlyphType.RESET; + } + + cache.glyphs.add(g1); + ++i; + continue; + } + } + + TrueTypeFont.Glyph var8 = this.getOrCreateGlyph(c); + cache.glyphs.add(var8); + cache.width += var8.width; + cache.height = Math.max(cache.height, var8.height); + } + + this.textcache.put(text, cache); + return cache; + } + } + + private TrueTypeFont.Glyph getOrCreateGlyph(char c) { + TrueTypeFont.Glyph g = (TrueTypeFont.Glyph)this.glyphcache.get(Character.valueOf(c)); + if(g != null) { + return g; + } else { + TrueTypeFont.TextureCache cache = this.getCurrentTexture(); + Font font = this.getFontForChar(c); + FontMetrics metrics = this.globalG.getFontMetrics(font); + g = new TrueTypeFont.Glyph(); + g.width = Math.max(metrics.charWidth(c), 1); + g.height = Math.max(metrics.getHeight(), 1); + if(cache.x + g.width >= 512) { + cache.x = 0; + cache.y += this.lineHeight + 1; + if(cache.y >= 512) { + cache.full = true; + cache = this.getCurrentTexture(); + } + } + + g.x = cache.x; + g.y = cache.y; + cache.x += g.width + 3; + this.lineHeight = Math.max(this.lineHeight, g.height); + cache.g.setFont(font); + cache.g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + cache.g.drawString(c + "", g.x, g.y + metrics.getAscent()); + g.texture = cache.textureId; + TextureUtil.uploadTextureImage(cache.textureId, cache.bufferedImage); + this.glyphcache.put(Character.valueOf(c), g); + return g; + } + } + + private TrueTypeFont.TextureCache getCurrentTexture() { + TrueTypeFont.TextureCache cache = null; + Iterator var2 = this.textures.iterator(); + + while(var2.hasNext()) { + TrueTypeFont.TextureCache t = (TrueTypeFont.TextureCache)var2.next(); + if(!t.full) { + cache = t; + break; + } + } + + if(cache == null) { + this.textures.add(cache = new TrueTypeFont.TextureCache()); + } + + return cache; + } + + public void drawCentered(String text, float x, float y, int color) { + this.draw(text, x - (float)this.width(text) / 2.0F, y, color); + } + + private Font getFontForChar(char c) { + if(this.font.canDisplay(c)) { + return this.font; + } else { + Iterator fa = this.usedFonts.iterator(); + + Font f; + do { + if(!fa.hasNext()) { + Font fa1 = new Font("Arial Unicode MS", 0, this.font.getSize()); + if(fa1.canDisplay(c)) { + return fa1; + } + + Iterator f2 = allFonts.iterator(); + + Font f1; + do { + if(!f2.hasNext()) { + return this.font; + } + + f1 = (Font)f2.next(); + } while(!f1.canDisplay(c)); + + this.usedFonts.add(f1 = f1.deriveFont(0, (float)this.font.getSize())); + return f1; + } + + f = (Font)fa.next(); + } while(!f.canDisplay(c)); + + return f; + } + } + + public void drawTexturedModalRect(float p_73729_1_, float p_73729_2_, float p_73729_3_, float p_73729_4_, float p_73729_5_, float p_73729_6_) + { + float f = 0.00390625F; + float f1 = 0.00390625F; + byte zLevel = 0; + Tessellator tessellator = Tessellator.instance; + tessellator.startDrawingQuads(); + tessellator.addVertexWithUV((double)(p_73729_1_ + 0), (double)(p_73729_2_ + p_73729_6_), (double)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)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)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)zLevel, (double)((float)(p_73729_3_ + 0) * f), (double)((float)(p_73729_4_ + 0) * f1)); + tessellator.draw(); + } + + public int width(String text) { + TrueTypeFont.GlyphCache cache = this.getOrCreateCache(text); + return (int)((float)cache.width * this.scale * this.textureScale()); + } + + public int height(String text) { + if(text != null && !text.trim().isEmpty()) { + TrueTypeFont.GlyphCache cache = this.getOrCreateCache(text); + return Math.max(1, (int)((float)cache.height * this.scale * this.textureScale())); + } else { + return (int)((float)this.lineHeight * this.scale * this.textureScale()); + } + } + + private float textureScale() { + return 0.5F; + } + + public void dispose() { + Iterator var1 = this.textures.iterator(); + + while(var1.hasNext()) { + TrueTypeFont.TextureCache cache = (TrueTypeFont.TextureCache)var1.next(); + GL11.glDeleteTextures(cache.textureId); + } + + this.textcache.clear(); + } + + public String getFontName() { + return this.font.getFontName(); + } + + class GlyphCache { + public int width; + public int height; + List glyphs = new ArrayList(); + + GlyphCache() { + } + } + + class Glyph { + TrueTypeFont.GlyphType type; + int color; + int x; + int y; + int height; + int width; + int texture; + + Glyph() { + this.type = TrueTypeFont.GlyphType.NORMAL; + this.color = -1; + } + } + + class TextureCache { + int x; + int y; + int textureId = GL11.glGenTextures(); + BufferedImage bufferedImage = new BufferedImage(512, 512, 2); + Graphics2D g; + boolean full; + + TextureCache() { + this.g = (Graphics2D)this.bufferedImage.getGraphics(); + } + } + + static enum GlyphType { + NORMAL, + COLOR, + RANDOM, + BOLD, + STRIKETHROUGH, + UNDERLINE, + ITALIC, + RESET, + OTHER; + + private GlyphType() { + } + } +}