diff --git a/src/main/java/noppes/npcs/client/gui/custom/GuiCustom.java b/src/main/java/noppes/npcs/client/gui/custom/GuiCustom.java index 217c85816..91df8f5ef 100644 --- a/src/main/java/noppes/npcs/client/gui/custom/GuiCustom.java +++ b/src/main/java/noppes/npcs/client/gui/custom/GuiCustom.java @@ -75,6 +75,8 @@ public class GuiCustom extends GuiScreen implements ICustomScrollListener, IGuiD private boolean field_146993_M; private ItemStack field_146994_N; + public boolean closeOnEsc = true; + public GuiCustom(ContainerCustomGui container) { this.inventorySlots = container; this.field_146995_H = true; @@ -508,7 +510,7 @@ public class GuiCustom extends GuiScreen implements ICustomScrollListener, IGuiD } protected void keyTyped(char typedChar, int keyCode) { - if (keyCode == 1) + if (keyCode == 1 && closeOnEsc) { this.mc.thePlayer.closeScreen(); } @@ -654,6 +656,7 @@ public class GuiCustom extends GuiScreen implements ICustomScrollListener, IGuiD this.gui = gui; this.xSize = gui.getWidth(); this.ySize = gui.getHeight(); + this.closeOnEsc = gui.doesCloseOnEscape(); if (!gui.getBackgroundTexture().isEmpty()) { this.background = new ResourceLocation(gui.getBackgroundTexture()); } diff --git a/src/main/java/noppes/npcs/scripted/gui/ScriptGui.java b/src/main/java/noppes/npcs/scripted/gui/ScriptGui.java index f24dbfe5f..7f7e99bbb 100644 --- a/src/main/java/noppes/npcs/scripted/gui/ScriptGui.java +++ b/src/main/java/noppes/npcs/scripted/gui/ScriptGui.java @@ -23,8 +23,9 @@ public class ScriptGui implements ICustomGui { int playerInvY; boolean pauseGame; boolean showPlayerInv; + boolean closeOnEsc = true; String backgroundTexture = ""; - HashMap components = new HashMap<>(); + HashMap components = new HashMap<>(); List slots = new ArrayList(); public ScriptGui() { @@ -71,6 +72,14 @@ public class ScriptGui implements ICustomGui { this.height = height; } + public void setCloseOnEscape(boolean close) { + this.closeOnEsc = close; + } + + public boolean doesCloseOnEscape() { + return this.closeOnEsc; + } + public void setDoesPauseGame(boolean pauseGame) { this.pauseGame = pauseGame; } @@ -90,67 +99,67 @@ public class ScriptGui implements ICustomGui { public IButton addButton(int id, String label, int x, int y) { ScriptGuiButton component = new ScriptGuiButton(id, label, x, y); this.updateComponent(component); - return (IButton)this.getComponent(id); + return (IButton) this.getComponent(id); } public IButton addButton(int id, String label, int x, int y, int width, int height) { ScriptGuiButton component = new ScriptGuiButton(id, label, x, y, width, height); this.updateComponent(component); - return (IButton)this.getComponent(id); + return (IButton) this.getComponent(id); } public IButton addTexturedButton(int id, String label, int x, int y, int width, int height, String texture) { ScriptGuiButton component = new ScriptGuiButton(id, label, x, y, width, height, texture); this.updateComponent(component); - return (IButton)this.getComponent(id); + return (IButton) this.getComponent(id); } public IButton addTexturedButton(int id, String label, int x, int y, int width, int height, String texture, int textureX, int textureY) { ScriptGuiButton component = new ScriptGuiButton(id, label, x, y, width, height, texture, textureX, textureY); this.updateComponent(component); - return (IButton)this.getComponent(id); + return (IButton) this.getComponent(id); } public ILabel addLabel(int id, String label, int x, int y, int width, int height) { ScriptGuiLabel component = new ScriptGuiLabel(id, label, x, y, width, height); this.updateComponent(component); - return (ILabel)this.getComponent(id); + return (ILabel) this.getComponent(id); } public ILabel addLabel(int id, String label, int x, int y, int width, int height, int color) { ScriptGuiLabel component = new ScriptGuiLabel(id, label, x, y, width, height, color); this.updateComponent(component); - return (ILabel)this.getComponent(id); + return (ILabel) this.getComponent(id); } public ITextField addTextField(int id, int x, int y, int width, int height) { ScriptGuiTextField component = new ScriptGuiTextField(id, x, y, width, height); this.updateComponent(component); - return (ITextField)this.getComponent(id); + return (ITextField) this.getComponent(id); } public ITexturedRect addTexturedRect(int id, String texture, int x, int y, int width, int height) { ScriptGuiTexturedRect component = new ScriptGuiTexturedRect(id, texture, x, y, width, height); this.updateComponent(component); - return (ITexturedRect)this.getComponent(id); + return (ITexturedRect) this.getComponent(id); } public ITexturedRect addTexturedRect(int id, String texture, int x, int y, int width, int height, int textureX, int textureY) { ScriptGuiTexturedRect component = new ScriptGuiTexturedRect(id, texture, x, y, width, height, textureX, textureY); this.updateComponent(component); - return (ITexturedRect)this.getComponent(id); + return (ITexturedRect) this.getComponent(id); } public IItemSlot addItemSlot(int id, int x, int y) { ScriptGuiItemSlot slot = new ScriptGuiItemSlot(id, x, y); this.updateComponent(slot); - return (IItemSlot)this.getComponent(id); + return (IItemSlot) this.getComponent(id); } public IItemSlot addItemSlot(int id, int x, int y, IItemStack stack) { ScriptGuiItemSlot slot = new ScriptGuiItemSlot(id, x, y, stack); this.updateComponent(slot); - return (IItemSlot)this.getComponent(id); + return (IItemSlot) this.getComponent(id); } public IItemSlot addItemSlot(int x, int y) { @@ -164,7 +173,7 @@ public class ScriptGui implements ICustomGui { public IScroll addScroll(int id, int x, int y, int width, int height, String[] list) { ScriptGuiScroll component = new ScriptGuiScroll(id, x, y, width, height, list); this.updateComponent(component); - return (IScroll)this.getComponent(id); + return (IScroll) this.getComponent(id); } public ILine addLine(int id, int x1, int y1, int x2, int y2, int color, int thickness) { @@ -246,40 +255,34 @@ public class ScriptGui implements ICustomGui { this.height = tag.getIntArray("size")[1]; this.pauseGame = tag.getBoolean("pause"); this.backgroundTexture = tag.getString("bgTexture"); - + this.closeOnEsc = tag.getBoolean("closeOnEsc"); NBTTagList list = tag.getTagList("components", 10); - for(int i = 0; i < list.tagCount(); i++){ + for (int i = 0; i < list.tagCount(); i++) { NBTBase b = list.getCompoundTagAt(i); - ScriptGuiComponent component = ScriptGuiComponent.createFromNBT((NBTTagCompound)b); + ScriptGuiComponent component = ScriptGuiComponent.createFromNBT((NBTTagCompound) b); if (component != null && !(component instanceof ScriptGuiItemSlot)) { components.put(component.getID(), component); } } - List slots = new ArrayList<>(); list = tag.getTagList("slots", 10); - - for(int i = 0; i < list.tagCount(); i++){ + for (int i = 0; i < list.tagCount(); i++) { NBTTagCompound slotNbt = list.getCompoundTagAt(i); - int id = slotNbt.getInteger("id"); if (!components.containsKey(id)) { components.put(id, ScriptGuiComponent.createFromNBT(slotNbt)); } else { components.get(id).fromNBT(slotNbt); } - ScriptGuiItemSlot slot = (ScriptGuiItemSlot) components.get(id); slots.add(slot); } - this.slots = slots; this.showPlayerInv = tag.getBoolean("showPlayerInv"); if (this.showPlayerInv) { this.playerInvX = tag.getIntArray("pInvPos")[0]; this.playerInvY = tag.getIntArray("pInvPos")[1]; } - return this; } @@ -289,33 +292,29 @@ public class ScriptGui implements ICustomGui { tag.setIntArray("size", new int[]{this.width, this.height}); tag.setBoolean("pause", this.pauseGame); tag.setString("bgTexture", this.backgroundTexture); + tag.setBoolean("closeOnEsc", this.closeOnEsc); NBTTagList list = new NBTTagList(); Iterator var3 = this.components.values().iterator(); - ICustomGuiComponent c; - while(var3.hasNext()) { - c = (ICustomGuiComponent)var3.next(); - list.appendTag(((ScriptGuiComponent)c).toNBT(new NBTTagCompound())); + while (var3.hasNext()) { + c = (ICustomGuiComponent) var3.next(); + list.appendTag(((ScriptGuiComponent) c).toNBT(new NBTTagCompound())); } - tag.setTag("components", list); list = new NBTTagList(); var3 = this.slots.iterator(); - - while(var3.hasNext()) { - c = (ICustomGuiComponent)var3.next(); + while (var3.hasNext()) { + c = (ICustomGuiComponent) var3.next(); if (c.getID() == -1) { - c.setID(this.getMaxId()+1); + c.setID(this.getMaxId() + 1); } - list.appendTag(((ScriptGuiComponent)c).toNBT(new NBTTagCompound())); + list.appendTag(((ScriptGuiComponent) c).toNBT(new NBTTagCompound())); } - tag.setTag("slots", list); tag.setBoolean("showPlayerInv", this.showPlayerInv); if (this.showPlayerInv) { tag.setIntArray("pInvPos", new int[]{this.playerInvX, this.playerInvY}); } - return tag; } }