From 00de5b8a964fcd731ebb8435f52f5b17c7603ead Mon Sep 17 00:00:00 2001 From: bigguy345 Date: Tue, 6 Aug 2024 21:43:48 +0300 Subject: [PATCH 1/9] GuiModelInterface fixes and QoL --- .../client/gui/util/GuiModelInterface.java | 177 +++++++++++------- 1 file changed, 107 insertions(+), 70 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/util/GuiModelInterface.java b/src/main/java/noppes/npcs/client/gui/util/GuiModelInterface.java index d226b4c01..fd4f1c6eb 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiModelInterface.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiModelInterface.java @@ -13,77 +13,117 @@ import org.lwjgl.input.Mouse; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL12; -public class GuiModelInterface extends GuiNPCInterface{ - public ModelData playerdata; +public class GuiModelInterface extends GuiNPCInterface { + public ModelData playerdata; - private static float rotation = 0; + private static float rotation = 0; - private GuiNpcButton left,right,zoom,unzoom; + private GuiNpcButton left, right, zoom, unzoom; - private static float zoomed = 60; + private static float zoomed = 60; + public float minSize = 10, maxSize = 100; - public int xOffset = 0; - public int yOffset = 0; - public boolean followMouse = true; + public int xOffset = 0, xOffsetButton = 0; + public int yOffset = 0, yOffsetButton = 0; + public boolean followMouse = true, drawNPConSub = true; - public EntityCustomNpc npc; + public boolean drawRenderButtons = true, drawXButton = true; - public GuiModelInterface(EntityCustomNpc npc){ - this.npc = npc; - playerdata = npc.modelData; - xSize = 380; - drawDefaultBackground = false; - } + public EntityCustomNpc npc; + + public GuiModelInterface(EntityCustomNpc npc) { + this.npc = npc; + playerdata = npc.modelData; + xSize = 380; + drawDefaultBackground = false; + } @Override public void initGui() { - super.initGui(); + super.initGui(); - addButton(unzoom = new GuiNpcButton(666, guiLeft + 148 + xOffset, guiTop + 200 + yOffset, 20, 20, "-")); - addButton(zoom = new GuiNpcButton(667, guiLeft + 214 + xOffset, guiTop + 200 + yOffset, 20, 20, "+")); - addButton(left = new GuiNpcButton(668, guiLeft + 170 + xOffset, guiTop + 200 + yOffset, 20, 20, "<")); - addButton(right = new GuiNpcButton(669, guiLeft + 192 + xOffset, guiTop + 200 + yOffset, 20, 20, ">")); - addButton(new GuiNpcButton(670, width - 22, 2, 20, 20, "X")); + if (drawRenderButtons) { + addButton(unzoom = new GuiNpcButton(666, guiLeft + 148 + xOffset + xOffsetButton, guiTop + 200 + yOffset + yOffsetButton, 20, 20, "-")); + addButton(zoom = new GuiNpcButton(667, guiLeft + 214 + xOffset + xOffsetButton, guiTop + 200 + yOffset + yOffsetButton, 20, 20, "+")); + addButton(left = new GuiNpcButton(668, guiLeft + 170 + xOffset + xOffsetButton, guiTop + 200 + yOffset + yOffsetButton, 20, 20, "<")); + addButton(right = new GuiNpcButton(669, guiLeft + 192 + xOffset + xOffsetButton, guiTop + 200 + yOffset + yOffsetButton, 20, 20, ">")); + } + + if (drawXButton) { + addButton(new GuiNpcButton(670, width - 22, 2, 20, 20, "X")); + } } @Override protected void actionPerformed(GuiButton btn) { - if(btn.id == 670){ - close(); - } + super.actionPerformed(btn); + if (btn.id == 670) { + close(); + } } + @Override - public boolean doesGuiPauseGame() - { + public boolean doesGuiPauseGame() { return false; } - private long start = -1; - @Override - public void drawScreen(int par1, int par2, float par3) - { - if(Mouse.isButtonDown(0)){ - if(left.mousePressed(mc, par1, par2)) - rotation+=par3 * 2; - else if(right.mousePressed(mc, par1, par2)) - rotation-=par3 * 2; - else if(zoom.mousePressed(mc, par1, par2)) - zoomed+=par3 * 2; - else if(unzoom.mousePressed(mc, par1, par2) && zoomed > 10) - zoomed-=par3 * 2; - } + private long start = -1; + + public boolean isMouseOverRenderer(int x, int y) { + return x >= guiLeft + xOffset + 40 && x <= guiLeft + xOffset + 330 && y >= guiTop + yOffset - 50 && y <= guiTop + yOffset + 250; + } + + + public void preRender(EntityLivingBase entity) { + EntityUtil.Copy(npc, entity); + + } + + public void postRender(EntityLivingBase entity) { + + } + + @Override + public void drawScreen(int par1, int par2, float par3) { + if (Mouse.isButtonDown(0)) { + if (this.left.mousePressed(this.mc, par1, par2)) { + rotation += par3 * 1.5F; + } else if (this.right.mousePressed(this.mc, par1, par2)) { + rotation -= par3 * 1.5F; + } else if (this.zoom.mousePressed(this.mc, par1, par2) && zoomed < maxSize) { + zoomed += par3 * 1.0F; + } else if (this.unzoom.mousePressed(this.mc, par1, par2) && zoomed > minSize) { + zoomed -= par3 * 1.0F; + } + } + + if (isMouseOverRenderer(par1, par2)) { + zoomed += Mouse.getDWheel() * 0.035f; + if (Mouse.isButtonDown(0) || Mouse.isButtonDown(1)) { + rotation -= Mouse.getDX() * 0.75f; + } + } + + if (zoomed > maxSize) + zoomed = maxSize; + if (zoomed < minSize) + zoomed = minSize; + + if (hasSubGui() && !drawNPConSub) + return; + this.drawDefaultBackground(); GL11.glColor4f(1, 1, 1, 1); - EntityLivingBase entity = playerdata.getEntity(npc); - if(entity == null) - entity = this.npc; + EntityLivingBase entity = playerdata.getEntity(npc); + if (entity == null) + entity = this.npc; - EntityUtil.Copy(npc, entity); + preRender(entity); - int l = guiLeft + 190 + xOffset; - int i1 = guiTop + 180 + yOffset; + int l = guiLeft + 190 + xOffset; + int i1 = guiTop + 180 + yOffset; GL11.glEnable(GL11.GL_COLOR_MATERIAL); GL11.glPushMatrix(); GL11.glTranslatef(l, i1, 60F); @@ -95,24 +135,23 @@ public class GuiModelInterface extends GuiNPCInterface{ float f3 = entity.rotationYaw; float f4 = entity.rotationPitch; float f7 = entity.rotationYawHead; - float f5 = (float)(l) - par1; - float f6 = (float)(i1 - 50) - par2; + float f5 = (float) (l) - par1; + float f6 = (float) (i1 - 50) - par2; GL11.glRotatef(135F, 0.0F, 1.0F, 0.0F); RenderHelper.enableStandardItemLighting(); GL11.glRotatef(-135F, 0.0F, 1.0F, 0.0F); - GL11.glRotatef(-(float)Math.atan(f6 / 80F) * 20F, 1.0F, 0.0F, 0.0F); + GL11.glRotatef(-(float) Math.atan(f6 / 800F) * 20F, 1.0F, 0.0F, 0.0F); entity.prevRenderYawOffset = entity.renderYawOffset = rotation; - entity.prevRotationYaw = entity.rotationYaw = (float)Math.atan(f5 / 80F) * 40F + rotation; - entity.rotationPitch = followMouse ? -(float)Math.atan(f6 / 80F) * 20F : 0; + entity.prevRotationYaw = entity.rotationYaw = (float) Math.atan(f5 / 80F) * 40F + rotation; + entity.rotationPitch = followMouse ? -(float) Math.atan(f6 / 40F) * 20F : 0; entity.prevRotationYawHead = entity.rotationYawHead = followMouse ? entity.rotationYaw : rotation; - GL11.glTranslatef(0.0F, entity.yOffset, 0.0F); + GL11.glTranslatef(0.0F, entity.yOffset, 1F); RenderManager.instance.playerViewY = 180F; - try{ + try { RenderManager.instance.renderEntityWithPosYaw(entity, 0.0D, 0.0D, 0.0D, 0.0F, 1.0F); - } - catch(Exception e){ - playerdata.setEntityClass(null); + } catch (Exception e) { + playerdata.setEntityClass(null); } entity.prevRenderYawOffset = entity.renderYawOffset = f2; entity.prevRotationYaw = entity.rotationYaw = f3; @@ -126,27 +165,25 @@ public class GuiModelInterface extends GuiNPCInterface{ OpenGlHelper.setActiveTexture(OpenGlHelper.defaultTexUnit); GL11.glPushMatrix(); GL11.glTranslatef(0.0F, 0f, 500.065F); - super.drawScreen(par1, par2, par3); + super.drawScreen(par1, par2, par3); GL11.glPopMatrix(); + + postRender(entity); } @Override - public void keyTyped(char par1, int par2) - { - super.keyTyped(par1, par2); - if (par2 == 1) - { - close(); - } + public void keyTyped(char par1, int par2) { + super.keyTyped(par1, par2); } - public void close(){ - this.mc.displayGuiScreen((GuiScreen)null); + + public void close() { + this.mc.displayGuiScreen((GuiScreen) null); this.mc.setIngameFocus(); } - @Override - public void save() { - // TODO Auto-generated method stub + @Override + public void save() { + // TODO Auto-generated method stub - } + } } From cbdd5079d807f54849d24c83e2ccd6e6d52325bf Mon Sep 17 00:00:00 2001 From: bigguy345 Date: Tue, 6 Aug 2024 21:44:21 +0300 Subject: [PATCH 2/9] Moved DBC Addon buttons from CNPC+ to addon --- .../client/gui/mainmenu/GuiNPCGlobalMainMenu.java | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNPCGlobalMainMenu.java b/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNPCGlobalMainMenu.java index 363cb5b58..e28d96658 100644 --- a/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNPCGlobalMainMenu.java +++ b/src/main/java/noppes/npcs/client/gui/mainmenu/GuiNPCGlobalMainMenu.java @@ -33,10 +33,7 @@ public class GuiNPCGlobalMainMenu extends GuiNPCInterface2{ y = guiTop + 10; this.addButton(new GuiNpcButton(18, guiLeft + 210, y, "menu.animations")); this.addButton(new GuiNpcButton(17, guiLeft + 210, y += 22, "menu.tags")); - if(Loader.isModLoaded("npcdbc")){ - this.addButton(new GuiNpcButton(200, guiLeft + 210, y + 154, 99, 20, "global.customforms")); - this.addButton(new GuiNpcButton(201, guiLeft + 210 + 99 + 3, y + 154, 99, 20, "global.customauras")); - } + } @Override @@ -76,13 +73,7 @@ public class GuiNPCGlobalMainMenu extends GuiNPCInterface2{ NoppesUtil.requestOpenGUI(EnumGuiType.ManageLinked); } - // DBC Addon - if (id == 200) { - NoppesUtil.requestOpenGUI(EnumGuiType.ManageCustomForms); - } - if (id == 201) { - NoppesUtil.requestOpenGUI(EnumGuiType.ManageCustomAuras); - } + } @Override public void save() { From 7cd51b3d8a77346c797041750e4ad455a03939a2 Mon Sep 17 00:00:00 2001 From: bigguy345 Date: Tue, 6 Aug 2024 21:46:07 +0300 Subject: [PATCH 3/9] Fixed bugs that happen on SubGUI closing --- .../npcs/client/gui/util/GuiNPCInterface.java | 545 +++++++++--------- 1 file changed, 285 insertions(+), 260 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/util/GuiNPCInterface.java b/src/main/java/noppes/npcs/client/gui/util/GuiNPCInterface.java index a19586e6a..04cceb311 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiNPCInterface.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiNPCInterface.java @@ -23,59 +23,61 @@ import java.net.URI; import java.util.ArrayList; import java.util.HashMap; -public abstract class GuiNPCInterface extends GuiScreen -{ - public EntityClientPlayerMP player; - public boolean drawDefaultBackground = true; - public EntityNPCInterface npc; - protected HashMap buttons = new HashMap(); - protected HashMap topbuttons = new HashMap(); - protected HashMap sidebuttons = new HashMap(); - protected HashMap textfields = new HashMap(); - protected HashMap labels = new HashMap(); - protected HashMap scrolls = new HashMap(); - protected HashMap sliders = new HashMap(); - protected HashMap extra = new HashMap(); +public abstract class GuiNPCInterface extends GuiScreen { + public EntityClientPlayerMP player; + public boolean drawDefaultBackground = true; + public EntityNPCInterface npc; + protected HashMap buttons = new HashMap(); + protected HashMap topbuttons = new HashMap(); + protected HashMap sidebuttons = new HashMap(); + protected HashMap textfields = new HashMap(); + protected HashMap labels = new HashMap(); + protected HashMap scrolls = new HashMap(); + protected HashMap sliders = new HashMap(); + protected HashMap extra = new HashMap(); protected HashMap scrollWindows = new HashMap<>(); - public String title; - private ResourceLocation background = null; - public boolean closeOnEsc = false; - public int guiLeft,guiTop,xSize,ySize; - private SubGuiInterface subgui; - public int mouseX, mouseY, mouseScroll; - public float bgScale = 1; - public float bgScaleX = 1; - public float bgScaleY = 1; - public float bgScaleZ = 1; + public String title; + private ResourceLocation background = null; + public boolean closeOnEsc = false; + public int guiLeft, guiTop, xSize, ySize; + private SubGuiInterface subgui; + public int mouseX, mouseY, mouseScroll; + public float bgScale = 1; + public float bgScaleX = 1; + public float bgScaleY = 1; + public float bgScaleZ = 1; + public long timeClosedSubGui; - public GuiNPCInterface(EntityNPCInterface npc) - { - this.player = Minecraft.getMinecraft().thePlayer; - this.npc = npc; - title = ""; - xSize = 200; - ySize = 222; + public GuiNPCInterface(EntityNPCInterface npc) { + this.player = Minecraft.getMinecraft().thePlayer; + this.npc = npc; + title = ""; + xSize = 200; + ySize = 222; } - public GuiNPCInterface() - { - this(null); + + public GuiNPCInterface() { + this(null); } - public void setBackground(String texture){ - background = new ResourceLocation("customnpcs","textures/gui/" + texture); + + public void setBackground(String texture) { + background = new ResourceLocation("customnpcs", "textures/gui/" + texture); } - public ResourceLocation getResource(String texture){ - return new ResourceLocation("customnpcs","textures/gui/" + texture); + + public ResourceLocation getResource(String texture) { + return new ResourceLocation("customnpcs", "textures/gui/" + texture); } + @Override - public void initGui(){ - super.initGui(); - GuiNpcTextField.unfocus(); - if(subgui != null){ - subgui.setWorldAndResolution(mc, width, height); - subgui.initGui(); - } - guiLeft = (width- xSize)/2; + public void initGui() { + super.initGui(); + GuiNpcTextField.unfocus(); + if (subgui != null) { + subgui.setWorldAndResolution(mc, width, height); + subgui.initGui(); + } + guiLeft = (width - xSize) / 2; guiTop = (height - ySize) / 2; buttonList.clear(); labels.clear(); @@ -88,329 +90,352 @@ public abstract class GuiNPCInterface extends GuiScreen scrollWindows.clear(); Keyboard.enableRepeatEvents(true); } + @Override - public void updateScreen(){ - if(subgui != null) - subgui.updateScreen(); - else{ - for(GuiNpcTextField tf : textfields.values()){ - if(tf.enabled) - tf.updateCursorCounter(); - } - super.updateScreen(); - } + public void updateScreen() { + if (subgui != null) + subgui.updateScreen(); + else { + for (GuiNpcTextField tf : textfields.values()) { + if (tf.enabled) + tf.updateCursorCounter(); + } + super.updateScreen(); + } } - public void addExtra(GuiHoverText gui) { - gui.setWorldAndResolution(mc, 350, 250); - extra.put(gui.id, gui); - } + public void addExtra(GuiHoverText gui) { + gui.setWorldAndResolution(mc, 350, 250); + extra.put(gui.id, gui); + } - public void addScrollableGui(int id, GuiScrollWindow gui){ + public void addScrollableGui(int id, GuiScrollWindow gui) { gui.setWorldAndResolution(mc, width, height); gui.initGui(); scrollWindows.put(id, gui); } - public void mouseClicked(int i, int j, int k) - { - if(subgui != null) - subgui.mouseClicked(i,j,k); - else{ - for(GuiNpcTextField tf : new ArrayList(textfields.values())) - if(tf.enabled) - tf.mouseClicked(i, j, k); + public void mouseClicked(int i, int j, int k) { + if (subgui != null) + subgui.mouseClicked(i, j, k); + else { + for (GuiNpcTextField tf : new ArrayList(textfields.values())) + if (tf.enabled) + tf.mouseClicked(i, j, k); - for(GuiScrollWindow guiScrollableComponent : scrollWindows.values()) { - if(guiScrollableComponent.isMouseOver(i, j)) + for (GuiScrollWindow guiScrollableComponent : scrollWindows.values()) { + if (guiScrollableComponent.isMouseOver(i, j)) guiScrollableComponent.mouseClicked(i, j, k); } - if (k == 0){ - for(GuiCustomScroll scroll : new ArrayList(scrolls.values())){ - scroll.mouseClicked(i, j, k); - } - } - mouseEvent(i,j,k); - super.mouseClicked(i, j, k); - } + if (k == 0) { + for (GuiCustomScroll scroll : new ArrayList(scrolls.values())) { + scroll.mouseClicked(i, j, k); + } + } + mouseEvent(i, j, k); + super.mouseClicked(i, j, k); + } } - public void mouseEvent(int i, int j, int k){}; + public void mouseEvent(int i, int j, int k){} @Override - protected void actionPerformed(GuiButton guibutton) { - if(subgui != null) - subgui.buttonEvent(guibutton); - else{ - buttonEvent(guibutton); - } - } - public void buttonEvent(GuiButton guibutton){}; + protected void actionPerformed(GuiButton guibutton) { + if (subgui != null) + subgui.buttonEvent(guibutton); + else { + buttonEvent(guibutton); + } + } + + public void buttonEvent(GuiButton guibutton){} @Override - public void keyTyped(char c, int i){ - if(subgui != null) - subgui.keyTyped(c,i); - for(GuiNpcTextField tf : textfields.values()) - tf.textboxKeyTyped(c, i); + public void keyTyped(char c, int i) { + if (subgui != null) + subgui.keyTyped(c, i); + for (GuiNpcTextField tf : textfields.values()) + tf.textboxKeyTyped(c, i); - for(GuiScrollWindow guiScrollableComponent : scrollWindows.values()) { + for (GuiScrollWindow guiScrollableComponent : scrollWindows.values()) { guiScrollableComponent.keyTyped(c, i); } - if (closeOnEsc && (i == 1 || !GuiNpcTextField.isFieldActive() && isInventoryKey(i))){ - close(); + //Fixes closing sub with escape closes all of it's parents + boolean enoughTimeSinceSubClosed = Minecraft.getSystemTime() - timeClosedSubGui > 50; + + if (closeOnEsc && enoughTimeSinceSubClosed && (i == 1 || !GuiNpcTextField.isFieldActive() && isInventoryKey(i))) { + close(); } } - public void onGuiClosed(){ - GuiNpcTextField.unfocus(); + + public void onGuiClosed() { + GuiNpcTextField.unfocus(); } - public void close(){ - Keyboard.enableRepeatEvents(false); + + public void close() { + Keyboard.enableRepeatEvents(false); displayGuiScreen(null); mc.setIngameFocus(); save(); } - public void addButton(GuiNpcButton button){ - buttons.put(button.id,button); - buttonList.add(button); + + public void addButton(GuiNpcButton button) { + buttons.put(button.id, button); + buttonList.add(button); } - public void addTopButton(GuiMenuTopButton button){ - topbuttons.put(button.id,button); - buttonList.add(button); + + public void addTopButton(GuiMenuTopButton button) { + topbuttons.put(button.id, button); + buttonList.add(button); } - public void addSideButton(GuiMenuSideButton button){ - sidebuttons.put(button.id,button); - buttonList.add(button); + + public void addSideButton(GuiMenuSideButton button) { + sidebuttons.put(button.id, button); + buttonList.add(button); } - public GuiNpcButton getButton(int i) { - return buttons.get(i); - } - public GuiMenuSideButton getSideButton(int i) { - return sidebuttons.get(i); - } - public GuiMenuTopButton getTopButton(int i) { - return topbuttons.get(i); - } - public void addTextField(GuiNpcTextField tf){ - textfields.put(tf.id,tf); + + public GuiNpcButton getButton(int i) { + return buttons.get(i); } - public GuiNpcTextField getTextField(int i){ - return textfields.get(i); + + public GuiMenuSideButton getSideButton(int i) { + return sidebuttons.get(i); } + + public GuiMenuTopButton getTopButton(int i) { + return topbuttons.get(i); + } + + public void addTextField(GuiNpcTextField tf) { + textfields.put(tf.id, tf); + } + + public GuiNpcTextField getTextField(int i) { + return textfields.get(i); + } + public void addLabel(GuiNpcLabel label) { - labels.put(label.id, label); - } - public GuiNpcLabel getLabel(int i){ - return labels.get(i); + labels.put(label.id, label); + } + + public GuiNpcLabel getLabel(int i) { + return labels.get(i); } public GuiScrollWindow getScrollableGui(int i) { return scrollWindows.get(i); } - public void addSlider(GuiNpcSlider slider){ - sliders.put(slider.id,slider); - buttonList.add(slider); + public void addSlider(GuiNpcSlider slider) { + sliders.put(slider.id, slider); + buttonList.add(slider); } - public GuiNpcSlider getSlider(int i) { - return sliders.get(i); - } - public void addScroll(GuiCustomScroll scroll) { + + public GuiNpcSlider getSlider(int i) { + return sliders.get(i); + } + + public void addScroll(GuiCustomScroll scroll) { scroll.setWorldAndResolution(mc, 350, 250); scrolls.put(scroll.id, scroll); - } - public GuiCustomScroll getScroll(int id){ - return scrolls.get(id); - } + } + + public GuiCustomScroll getScroll(int id) { + return scrolls.get(id); + } public abstract void save(); @Override - public void drawScreen(int i, int j, float f){ - mouseX = i; - mouseY = j; - if(drawDefaultBackground && subgui == null) - drawDefaultBackground(); + public void drawScreen(int i, int j, float f) { + mouseX = i; + mouseY = j; + if (drawDefaultBackground && subgui == null) + drawDefaultBackground(); - if(background != null && mc.renderEngine != null){ - drawBackground(); - } + if (background != null && mc.renderEngine != null) { + drawBackground(); + } boolean subGui = hasSubGui(); drawCenteredString(fontRendererObj, title, width / 2, guiTop + 4, 0xffffff); - for(GuiNpcLabel label : labels.values()) - label.drawLabel(this,fontRendererObj); - for(GuiNpcTextField tf : textfields.values()){ - tf.drawTextBox(i, j); - } - for(GuiCustomScroll scroll : scrolls.values()){ - scroll.updateSubGUI(subGui); - scroll.drawScreen(i, j, f, !subGui && scroll.isMouseOver(i, j)? Mouse.getDWheel():0); + for (GuiNpcLabel label : labels.values()) + label.drawLabel(this, fontRendererObj); + for (GuiNpcTextField tf : textfields.values()) { + tf.drawTextBox(i, j); } - for(GuiScreen gui : extra.values()) - gui.drawScreen(i, j, f); + for (GuiCustomScroll scroll : scrolls.values()) { + scroll.updateSubGUI(subGui); + scroll.drawScreen(i, j, f, !subGui && scroll.isMouseOver(i, j) ? Mouse.getDWheel() : 0); + } + for (GuiScreen gui : extra.values()) + gui.drawScreen(i, j, f); super.drawScreen(i, j, f); - for(GuiCustomScroll scroll : scrolls.values()) - if(scroll.hoverableText){ - scroll.drawHover(i, j); - } - for(GuiNpcButton button : buttons.values()){ + for (GuiCustomScroll scroll : scrolls.values()) + if (scroll.hoverableText) { + scroll.drawHover(i, j); + } + for (GuiNpcButton button : buttons.values()) { button.updateSubGUI(subGui); - if(!button.hoverableText.isEmpty()){ + if (!button.hoverableText.isEmpty()) { button.drawHover(i, j, subGui); } } - for(GuiScrollWindow guiScrollableComponent : scrollWindows.values()){ - guiScrollableComponent.drawScreen(i, j, f, !subGui && guiScrollableComponent.isMouseOver(i,j)?Mouse.getDWheel():0); + for (GuiScrollWindow guiScrollableComponent : scrollWindows.values()) { + guiScrollableComponent.drawScreen(i, j, f, !subGui && guiScrollableComponent.isMouseOver(i, j) ? Mouse.getDWheel() : 0); } - if(subgui != null){ - subgui.drawScreen(i,j,f); + if (subgui != null) { + subgui.drawScreen(i, j, f); } } - protected void drawBackground() { - GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - GL11.glPushMatrix(); - GL11.glTranslatef(guiLeft, guiTop, 0); - GL11.glScalef(bgScale*bgScaleX, bgScale*bgScaleY, bgScale*bgScaleZ); - mc.renderEngine.bindTexture(background); - if(xSize > 256){ - drawTexturedModalRect(0, 0, 0, 0, 250, ySize); - drawTexturedModalRect(250, 0, 256 - (xSize - 250), 0, xSize - 250, ySize); - } - else - drawTexturedModalRect(0, 0, 0, 0, xSize, ySize); - GL11.glPopMatrix(); - } + protected void drawBackground() { + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + GL11.glPushMatrix(); + GL11.glTranslatef(guiLeft, guiTop, 0); + GL11.glScalef(bgScale * bgScaleX, bgScale * bgScaleY, bgScale * bgScaleZ); + mc.renderEngine.bindTexture(background); + if (xSize > 256) { + drawTexturedModalRect(0, 0, 0, 0, 250, ySize); + drawTexturedModalRect(250, 0, 256 - (xSize - 250), 0, xSize - 250, ySize); + } else + drawTexturedModalRect(0, 0, 0, 0, xSize, ySize); + GL11.glPopMatrix(); + } protected void drawTextBlock(String text, int x, int y, int lineWidth) { TextBlockClient block = new TextBlockClient(StatCollector.translateToLocal(text), lineWidth, true, player); - for(int line = 0; line < block.lines.size(); line++){ + for (int line = 0; line < block.lines.size(); line++) { String lineText = block.lines.get(line).getFormattedText(); fontRendererObj.drawString(lineText, x, y + (line * fontRendererObj.FONT_HEIGHT), CustomNpcResourceListener.DefaultTextColor); } } - public FontRenderer getFontRenderer() { - return this.fontRendererObj; - } + public FontRenderer getFontRenderer() { + return this.fontRendererObj; + } - public void elementClicked() { - if(subgui != null) - subgui.elementClicked(); - } - @Override - public boolean doesGuiPauseGame(){ + public void elementClicked() { + if (subgui != null) + subgui.elementClicked(); + } + + @Override + public boolean doesGuiPauseGame() { return false; } - public void doubleClicked() { - } - - public boolean isInventoryKey(int i){ - return i == mc.gameSettings.keyBindInventory.getKeyCode(); //inventory key - } - @Override - public void drawDefaultBackground() { - super.drawDefaultBackground(); - } - - public void displayGuiScreen(GuiScreen gui) { - mc.displayGuiScreen(gui); - } - - public void setSubGui(SubGuiInterface gui){ - subgui = gui; - subgui.setWorldAndResolution(mc, width, height); - subgui.parent = this; - initGui(); + public void doubleClicked() { } - public void closeSubGui(SubGuiInterface gui) { - subgui = null; - } - public boolean hasSubGui() { - return subgui != null; - } - public SubGuiInterface getSubGui() { - if(hasSubGui() && subgui.hasSubGui()) - return subgui.getSubGui(); - return subgui; - } - public void drawNpc(int x, int y){ + public boolean isInventoryKey(int i) { + return i == mc.gameSettings.keyBindInventory.getKeyCode(); //inventory key + } + + @Override + public void drawDefaultBackground() { + super.drawDefaultBackground(); + } + + public void displayGuiScreen(GuiScreen gui) { + mc.displayGuiScreen(gui); + } + + public void setSubGui(SubGuiInterface gui) { + subgui = gui; + subgui.setWorldAndResolution(mc, width, height); + subgui.parent = this; + initGui(); + } + + public void closeSubGui(SubGuiInterface gui) { + subgui = null; + timeClosedSubGui = Minecraft.getSystemTime(); + initGui(); + } + + public boolean hasSubGui() { + return subgui != null; + } + + public SubGuiInterface getSubGui() { + if (hasSubGui() && subgui.hasSubGui()) + return subgui.getSubGui(); + return subgui; + } + + public void drawNpc(int x, int y) { drawNpc(npc, x, y, 1, 0); } - public void drawNpc(EntityLivingBase entity, int x, int y, float zoomed, int rotation){ + public void drawNpc(EntityLivingBase entity, int x, int y, float zoomed, int rotation) { EntityNPCInterface npc = null; - if(entity instanceof EntityNPCInterface) + if (entity instanceof EntityNPCInterface) npc = (EntityNPCInterface) entity; - GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); - if(npc != null) + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + if (npc != null) npc.isDrawn = true; - GL11.glEnable(GL11.GL_COLOR_MATERIAL); - GL11.glPushMatrix(); - GL11.glTranslatef(guiLeft + x, guiTop + y, 50F); + GL11.glEnable(GL11.GL_COLOR_MATERIAL); + GL11.glPushMatrix(); + GL11.glTranslatef(guiLeft + x, guiTop + y, 50F); float scale = 1; - if(entity.height > 2.4) - scale = 2 / npc.height; + if (entity.height > 2.4) + scale = 2 / npc.height; GL11.glScalef(-30 * scale * zoomed, 30 * scale * zoomed, 30 * scale * zoomed); - GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F); + GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F); - float f2 = entity.renderYawOffset; - float f3 = entity.rotationYaw; - float f4 = entity.rotationPitch; - float f7 = entity.rotationYawHead; - float f5 = (float) (guiLeft + x) - mouseX; + float f2 = entity.renderYawOffset; + float f3 = entity.rotationYaw; + float f4 = entity.rotationPitch; + float f7 = entity.rotationYawHead; + float f5 = (float) (guiLeft + x) - mouseX; float f6 = (float) ((guiTop + y) - 50 * scale * zoomed) - mouseY; int orientation = 0; - if(npc != null){ + if (npc != null) { orientation = npc.ai.orientation; npc.ai.orientation = rotation; } - GL11.glRotatef(135F, 0.0F, 1.0F, 0.0F); - RenderHelper.enableStandardItemLighting(); - GL11.glRotatef(-135F, 0.0F, 1.0F, 0.0F); - GL11.glRotatef(-(float) Math.atan(f6 / 40F) * 20F, 1.0F, 0.0F, 0.0F); + GL11.glRotatef(135F, 0.0F, 1.0F, 0.0F); + RenderHelper.enableStandardItemLighting(); + GL11.glRotatef(-135F, 0.0F, 1.0F, 0.0F); + GL11.glRotatef(-(float) Math.atan(f6 / 40F) * 20F, 1.0F, 0.0F, 0.0F); entity.renderYawOffset = rotation; - entity.rotationYaw = (float)Math.atan(f5 / 80F) * 40F + rotation; + entity.rotationYaw = (float) Math.atan(f5 / 80F) * 40F + rotation; entity.rotationPitch = -(float) Math.atan(f6 / 40F) * 20F; entity.rotationYawHead = entity.rotationYaw; - GL11.glTranslatef(0.0F, entity.yOffset, 0.0F); - RenderManager.instance.playerViewY = 180F; - RenderManager.instance.renderEntityWithPosYaw(entity, 0, 0, 0, 0, 1); + GL11.glTranslatef(0.0F, entity.yOffset, 0.0F); + RenderManager.instance.playerViewY = 180F; + RenderManager.instance.renderEntityWithPosYaw(entity, 0, 0, 0, 0, 1); entity.prevRenderYawOffset = entity.renderYawOffset = f2; entity.prevRotationYaw = entity.rotationYaw = f3; entity.prevRotationPitch = entity.rotationPitch = f4; entity.prevRotationYawHead = entity.rotationYawHead = f7; - if(npc != null){ + if (npc != null) { npc.ai.orientation = orientation; } - GL11.glPopMatrix(); - RenderHelper.disableStandardItemLighting(); - GL11.glDisable(GL12.GL_RESCALE_NORMAL); - if(npc != null) + GL11.glPopMatrix(); + RenderHelper.disableStandardItemLighting(); + GL11.glDisable(GL12.GL_RESCALE_NORMAL); + if (npc != null) npc.isDrawn = false; - OpenGlHelper.setActiveTexture(OpenGlHelper.lightmapTexUnit); - GL11.glDisable(GL11.GL_TEXTURE_2D); - OpenGlHelper.setActiveTexture(OpenGlHelper.defaultTexUnit); - } + OpenGlHelper.setActiveTexture(OpenGlHelper.lightmapTexUnit); + GL11.glDisable(GL11.GL_TEXTURE_2D); + OpenGlHelper.setActiveTexture(OpenGlHelper.defaultTexUnit); + } - public void openLink(String link){ - try{ + public void openLink(String link) { + try { Class oclass = Class.forName("java.awt.Desktop"); - Object object = oclass.getMethod("getDesktop", new Class[0]).invoke((Object)null, new Object[0]); - oclass.getMethod("browse", new Class[] {URI.class}).invoke(object, new Object[] {new URI(link)}); - } - catch (Throwable throwable) - { + Object object = oclass.getMethod("getDesktop", new Class[0]).invoke((Object) null, new Object[0]); + oclass.getMethod("browse", new Class[]{URI.class}).invoke(object, new Object[]{new URI(link)}); + } catch (Throwable throwable) { } } } From c54795ff88903df252871b80d2c0940614549a4d Mon Sep 17 00:00:00 2001 From: bigguy345 Date: Tue, 6 Aug 2024 21:47:21 +0300 Subject: [PATCH 4/9] Changed GuiNpcMenu topButtons to public --- .../npcs/client/gui/util/GuiNpcMenu.java | 218 +++++++++--------- 1 file changed, 103 insertions(+), 115 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/util/GuiNpcMenu.java b/src/main/java/noppes/npcs/client/gui/util/GuiNpcMenu.java index 9c9feb891..01bbb8d20 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiNpcMenu.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiNpcMenu.java @@ -14,141 +14,129 @@ import noppes.npcs.constants.EnumPacketServer; import noppes.npcs.entity.EntityNPCInterface; import org.lwjgl.input.Keyboard; -public class GuiNpcMenu implements GuiYesNoCallback{ - - private GuiScreen parent; - private GuiMenuTopButton[] topButtons; +public class GuiNpcMenu implements GuiYesNoCallback { - private int activeMenu; - private EntityNPCInterface npc; - public boolean saveNPC = true; + private GuiScreen parent; + public GuiMenuTopButton[] topButtons; - public GuiNpcMenu(GuiScreen parent, int activeMenu, EntityNPCInterface npc) { - this.parent = parent; - this.activeMenu = activeMenu; - this.npc = npc; - } + private int activeMenu; + private EntityNPCInterface npc; + public boolean saveNPC = true; - public void initGui(int guiLeft, int guiTop, int width) - { + public GuiNpcMenu(GuiScreen parent, int activeMenu, EntityNPCInterface npc) { + this.parent = parent; + this.activeMenu = activeMenu; + this.npc = npc; + } + + public void initGui(int guiLeft, int guiTop, int width) { Keyboard.enableRepeatEvents(true); - GuiMenuTopButton close = new GuiMenuTopButton(0,guiLeft + width - 22, guiTop - 17, "X"); - if (npc != null) { - GuiMenuTopButton display = new GuiMenuTopButton(1, guiLeft + 4, guiTop - 17, "menu.display"); - GuiMenuTopButton stats = new GuiMenuTopButton(2, display.xPosition + display.getWidth(), guiTop - 17, "menu.stats"); - GuiMenuTopButton ai = new GuiMenuTopButton(6, stats.xPosition + stats.getWidth(), guiTop - 17, "menu.ai"); - GuiMenuTopButton inv = new GuiMenuTopButton(3, ai.xPosition + ai.getWidth(), guiTop - 17, "menu.inventory"); - GuiMenuTopButton advanced = new GuiMenuTopButton(4, inv.xPosition + inv.getWidth(), guiTop - 17, "menu.advanced"); - GuiMenuTopButton global = new GuiMenuTopButton(5, advanced.xPosition + advanced.getWidth(), guiTop - 17, "menu.global"); - GuiMenuTopButton delete = new GuiMenuTopButton(66,guiLeft + width - 72, guiTop - 17,"selectWorld.deleteButton"); - delete.xPosition = close.xPosition - delete.getWidth(); - topButtons = new GuiMenuTopButton[]{display,stats,ai,inv,advanced,global,close,delete}; - } else { - topButtons = new GuiMenuTopButton[]{close}; - } - - for(GuiMenuTopButton button : topButtons) - button.active = button.id == activeMenu; - } - - private void topButtonPressed(GuiMenuTopButton button) { - if(button.displayString.equals(activeMenu)) - return; - Minecraft mc = Minecraft.getMinecraft(); - NoppesUtil.clickSound(); + GuiMenuTopButton close = new GuiMenuTopButton(0, guiLeft + width - 22, guiTop - 17, "X"); + if (npc != null) { + GuiMenuTopButton display = new GuiMenuTopButton(1, guiLeft + 4, guiTop - 17, "menu.display"); + GuiMenuTopButton stats = new GuiMenuTopButton(2, display.xPosition + display.getWidth(), guiTop - 17, "menu.stats"); + GuiMenuTopButton ai = new GuiMenuTopButton(6, stats.xPosition + stats.getWidth(), guiTop - 17, "menu.ai"); + GuiMenuTopButton inv = new GuiMenuTopButton(3, ai.xPosition + ai.getWidth(), guiTop - 17, "menu.inventory"); + GuiMenuTopButton advanced = new GuiMenuTopButton(4, inv.xPosition + inv.getWidth(), guiTop - 17, "menu.advanced"); + GuiMenuTopButton global = new GuiMenuTopButton(5, advanced.xPosition + advanced.getWidth(), guiTop - 17, "menu.global"); + GuiMenuTopButton delete = new GuiMenuTopButton(66, guiLeft + width - 72, guiTop - 17, "selectWorld.deleteButton"); + delete.xPosition = close.xPosition - delete.getWidth(); + topButtons = new GuiMenuTopButton[]{display, stats, ai, inv, advanced, global, close, delete}; + } else { + topButtons = new GuiMenuTopButton[]{close}; + } - int id = button.id; - if(id == 0){ - close(); - return; - } - else if(id == 66){ + for (GuiMenuTopButton button : topButtons) + button.active = button.id == activeMenu; + } + + private void topButtonPressed(GuiMenuTopButton button) { + if (button.displayString.equals(activeMenu)) + return; + Minecraft mc = Minecraft.getMinecraft(); + NoppesUtil.clickSound(); + + int id = button.id; + if (id == 0) { + close(); + return; + } else if (id == 66) { GuiYesNo guiyesno = new GuiYesNo(this, "Confirm", StatCollector.translateToLocal("gui.delete"), 0); mc.displayGuiScreen(guiyesno); return; - } - save(); - if(id == 1){ - CustomNpcs.proxy.openGui(npc, EnumGuiType.MainMenuDisplay); - } - else if(id == 2){ - CustomNpcs.proxy.openGui(npc, EnumGuiType.MainMenuStats); - } - else if(id == 3){ - NoppesUtil.requestOpenGUI(EnumGuiType.MainMenuInv); - } - else if(id == 4){ - CustomNpcs.proxy.openGui(npc, EnumGuiType.MainMenuAdvanced); - } - else if(id == 5){ - CustomNpcs.proxy.openGui(npc, EnumGuiType.MainMenuGlobal); - } - else if(id == 6){ - CustomNpcs.proxy.openGui(npc, EnumGuiType.MainMenuAI); - } - activeMenu = id; - } + } + save(); + if (id == 1) { + CustomNpcs.proxy.openGui(npc, EnumGuiType.MainMenuDisplay); + } else if (id == 2) { + CustomNpcs.proxy.openGui(npc, EnumGuiType.MainMenuStats); + } else if (id == 3) { + NoppesUtil.requestOpenGUI(EnumGuiType.MainMenuInv); + } else if (id == 4) { + CustomNpcs.proxy.openGui(npc, EnumGuiType.MainMenuAdvanced); + } else if (id == 5) { + CustomNpcs.proxy.openGui(npc, EnumGuiType.MainMenuGlobal); + } else if (id == 6) { + CustomNpcs.proxy.openGui(npc, EnumGuiType.MainMenuAI); + } + activeMenu = id; + } - private void save() { - GuiNpcTextField.unfocus(); - - if(parent instanceof GuiContainerNPCInterface2) - ((GuiContainerNPCInterface2)parent).save(); - - if(parent instanceof GuiNPCInterface2) - ((GuiNPCInterface2)parent).save(); - } + private void save() { + GuiNpcTextField.unfocus(); - private void close() { - Keyboard.enableRepeatEvents(false); + if (parent instanceof GuiContainerNPCInterface2) + ((GuiContainerNPCInterface2) parent).save(); - if(parent instanceof GuiContainerNPCInterface2) - ((GuiContainerNPCInterface2)parent).close(); - - if(parent instanceof GuiNPCInterface2) - ((GuiNPCInterface2)parent).close(); - if(npc != null){ - npc.reset(); - if(saveNPC) - Client.sendData(EnumPacketServer.NpcMenuClose); - } - } + if (parent instanceof GuiNPCInterface2) + ((GuiNPCInterface2) parent).save(); + } - public void mouseClicked(int i, int j, int k) { - - if (k == 0) - { - Minecraft mc = Minecraft.getMinecraft(); - for (GuiMenuTopButton button : topButtons) - { - if (button.mousePressed(mc, i, j)) - { + private void close() { + Keyboard.enableRepeatEvents(false); + + if (parent instanceof GuiContainerNPCInterface2) + ((GuiContainerNPCInterface2) parent).close(); + + if (parent instanceof GuiNPCInterface2) + ((GuiNPCInterface2) parent).close(); + if (npc != null) { + npc.reset(); + if (saveNPC) + Client.sendData(EnumPacketServer.NpcMenuClose); + } + } + + public void mouseClicked(int i, int j, int k) { + + if (k == 0) { + Minecraft mc = Minecraft.getMinecraft(); + for (GuiMenuTopButton button : topButtons) { + if (button.mousePressed(mc, i, j)) { topButtonPressed(button); } } } - } + } - public void drawElements(FontRenderer fontRenderer, int i, int j, - Minecraft mc, float f) { - for(GuiMenuTopButton button: topButtons) - button.drawButton(mc, i, j); - - } + public void drawElements(FontRenderer fontRenderer, int i, int j, Minecraft mc, float f) { + for (GuiMenuTopButton button : topButtons) + button.drawButton(mc, i, j); + + } + - @Override - public void confirmClicked(boolean flag, int i){ - Minecraft mc = Minecraft.getMinecraft(); - if(flag){ - Client.sendData(EnumPacketServer.Delete); - mc.displayGuiScreen(null); - mc.setIngameFocus(); - } - else{ - NoppesUtil.openGUI(mc.thePlayer, parent); - } + public void confirmClicked(boolean flag, int i) { + Minecraft mc = Minecraft.getMinecraft(); + if (flag) { + Client.sendData(EnumPacketServer.Delete); + mc.displayGuiScreen(null); + mc.setIngameFocus(); + } else { + NoppesUtil.openGUI(mc.thePlayer, parent); + } } } From 5ecf69eeb29c4e7f1748eab3a9a3bbb201602dd2 Mon Sep 17 00:00:00 2001 From: bigguy345 Date: Tue, 6 Aug 2024 21:47:54 +0300 Subject: [PATCH 5/9] Textfield cursor position defaulted to 0 (instead of last) --- .../npcs/client/gui/util/GuiNpcTextField.java | 351 +++++++++--------- 1 file changed, 176 insertions(+), 175 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/util/GuiNpcTextField.java b/src/main/java/noppes/npcs/client/gui/util/GuiNpcTextField.java index 5fb5b8f0c..0f26d9d36 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiNpcTextField.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiNpcTextField.java @@ -5,199 +5,200 @@ import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.GuiTextField; -public class GuiNpcTextField extends GuiTextField{ - public boolean enabled = true; - public boolean inMenu = true; - public boolean integersOnly = false; - public boolean doublesOnly = false; - public boolean floatsOnly = false; - private ITextfieldListener listener; +public class GuiNpcTextField extends GuiTextField { + public boolean enabled = true; + public boolean inMenu = true; + public boolean integersOnly = false; + public boolean doublesOnly = false; + public boolean floatsOnly = false; + private ITextfieldListener listener; public int id; - public int min = 0,max = Integer.MAX_VALUE,def = 0; - public double minDouble = 0, maxDouble = Double.MAX_VALUE, defDouble = 0; - public float minFloat = 0, maxFloat = Float.MAX_VALUE, defFloat = 0; + public int min = 0, max = Integer.MAX_VALUE, def = 0; + public double minDouble = 0, maxDouble = Double.MAX_VALUE, defDouble = 0; + public float minFloat = 0, maxFloat = Float.MAX_VALUE, defFloat = 0; protected static GuiNpcTextField activeTextfield = null; - public boolean canEdit = true; - - private final int[] allowedSpecialChars = {14,211,203,205}; - - public GuiNpcTextField(int id,GuiScreen parent, FontRenderer fontRenderer, - int i, int j, int k, int l, String s) { - super(fontRenderer, i, j, k, l); - setMaxStringLength(500); - this.setText(s); - this.id = id; - if(parent instanceof ITextfieldListener) - listener = (ITextfieldListener) parent; - } - - public static boolean isFieldActive(){ - return activeTextfield != null; - } - - public GuiNpcTextField(int id,GuiScreen parent, - int i, int j, int k, int l, String s) { - this(id, parent, Minecraft.getMinecraft().fontRenderer, i, j, k, l, s); - } + public boolean canEdit = true; - protected boolean charAllowed(char c, int i){ - if(!integersOnly || Character.isDigit(c)) - return true; + private final int[] allowedSpecialChars = {14, 211, 203, 205}; - if(integersOnly && getText().isEmpty() && c == '-') - return true; - - for(int j : allowedSpecialChars) - if(j == i) - return true; - - return false; - } - - @Override - public boolean textboxKeyTyped(char c, int i) - { - if(!charAllowed(c,i) || !canEdit) - return false; - return super.textboxKeyTyped(c, i); - } - - public boolean isEmpty(){ - return getText().trim().length() == 0; + public GuiNpcTextField(int id, GuiScreen parent, FontRenderer fontRenderer, int i, int j, int k, int l, String s) { + super(fontRenderer, i, j, k, l); + setMaxStringLength(500); + this.setText(s); + setCursorPositionZero(); + this.id = id; + if (parent instanceof ITextfieldListener) + listener = (ITextfieldListener) parent; } - public int getInteger(){ - return Integer.parseInt(getText()); + public static boolean isFieldActive() { + return activeTextfield != null; } - public boolean isInteger(){ - try{ - Integer.parseInt(getText()); - return true; - }catch(NumberFormatException e){ - return false; - } + public GuiNpcTextField(int id, GuiScreen parent, int i, int j, int k, int l, String s) { + this(id, parent, Minecraft.getMinecraft().fontRenderer, i, j, k, l, s); } - public double getDouble(){ - return Double.parseDouble(getText()); - } + protected boolean charAllowed(char c, int i) { + if (!integersOnly || Character.isDigit(c)) + return true; - public boolean isDouble() { - try{ - Double.parseDouble(getText()); - return true; - }catch(NumberFormatException e){ - return false; - } - } + if (integersOnly && getText().isEmpty() && c == '-') + return true; - public float getFloat(){ - return Float.parseFloat(getText()); - } + for (int j : allowedSpecialChars) + if (j == i) + return true; - public boolean isFloat() { - try{ - Float.parseFloat(getText()); - return true; - }catch(NumberFormatException e){ - return false; - } - } - - @Override - public void mouseClicked(int i, int j, int k){ - if(!canEdit) - return; - boolean wasFocused = this.isFocused(); - super.mouseClicked(i, j, k); - if(wasFocused != isFocused()){ - if(wasFocused){ - unFocused(); - } - } - if(isFocused()) - activeTextfield = this; + return false; } - public void unFocused(){ - if(integersOnly && !doublesOnly && !floatsOnly){ - if(isEmpty() || !isInteger()) - setText(def+""); - else if(getInteger() < min) - setText(min+""); - else if(getInteger() > max) - setText(max+""); - } - else if(doublesOnly && !floatsOnly){ - if (isEmpty() || !isDouble()) - setText(defDouble + ""); - else if (getDouble() < minDouble) - setText(minDouble + ""); - else if (getDouble() > maxDouble) - setText(maxDouble + ""); - } - else if(floatsOnly){ - if(isEmpty() || !isFloat()) - setText(defFloat +""); - else if(getFloat() < minFloat) - setText(minFloat +""); - else if(getFloat() > maxFloat) - setText(maxFloat +""); - } - - if(listener != null) - listener.unFocused(this); - - if(this == activeTextfield) - activeTextfield = null; - } - - @Override - public void drawTextBox() - { - if(enabled) - super.drawTextBox(); + @Override + public boolean textboxKeyTyped(char c, int i) { + if (!charAllowed(c, i) || !canEdit) + return false; + return super.textboxKeyTyped(c, i); } - public void setMinMaxDefault(int min, int max, int def) { - this.min = min; - this.max = max; - this.def = def; - } - public void setMinMaxDefaultDouble(double min, double max, double def) { - minDouble = min; - maxDouble = max; - defDouble = def; - } - public void setMinMaxDefaultFloat(float min, float max, float def) { - minFloat = min; - maxFloat = max; - defFloat = def; - } - public static void unfocus() { - GuiNpcTextField prev = activeTextfield; - activeTextfield = null; - if(prev != null){ - prev.unFocused(); - } - } - public void drawTextBox(int mousX, int mousY) { - drawTextBox(); - } + public boolean isEmpty() { + return getText().trim().length() == 0; + } - public GuiNpcTextField setIntegersOnly() { - integersOnly = true; - return this; - } + public int getInteger() { + return Integer.parseInt(getText()); + } + + public boolean isInteger() { + try { + Integer.parseInt(getText()); + return true; + } catch (NumberFormatException e) { + return false; + } + } + + public double getDouble() { + return Double.parseDouble(getText()); + } + + public boolean isDouble() { + try { + Double.parseDouble(getText()); + return true; + } catch (NumberFormatException e) { + return false; + } + } + + public float getFloat() { + return Float.parseFloat(getText()); + } + + public boolean isFloat() { + try { + Float.parseFloat(getText()); + return true; + } catch (NumberFormatException e) { + return false; + } + } + + @Override + public void mouseClicked(int i, int j, int k) { + if (!canEdit) + return; + boolean wasFocused = this.isFocused(); + super.mouseClicked(i, j, k); + if (wasFocused != isFocused()) { + if (wasFocused) { + unFocused(); + } + } + if (isFocused()) + activeTextfield = this; + } + + public void unFocused() { + if (integersOnly && !doublesOnly && !floatsOnly) { + if (isEmpty() || !isInteger()) + setText(def + ""); + else if (getInteger() < min) + setText(min + ""); + else if (getInteger() > max) + setText(max + ""); + } else if (doublesOnly && !floatsOnly) { + if (isEmpty() || !isDouble()) + setText(defDouble + ""); + else if (getDouble() < minDouble) + setText(minDouble + ""); + else if (getDouble() > maxDouble) + setText(maxDouble + ""); + } else if (floatsOnly) { + if (isEmpty() || !isFloat()) + setText(defFloat + ""); + else if (getFloat() < minFloat) + setText(minFloat + ""); + else if (getFloat() > maxFloat) + setText(maxFloat + ""); + } + setCursorPositionZero(); + if (listener != null) + listener.unFocused(this); + + if (this == activeTextfield) + activeTextfield = null; + } + + @Override + public void drawTextBox() { + if (enabled) + super.drawTextBox(); + } + + public void setMinMaxDefault(int min, int max, int def) { + this.min = min; + this.max = max; + this.def = def; + } + + public void setMinMaxDefaultDouble(double min, double max, double def) { + minDouble = min; + maxDouble = max; + defDouble = def; + } + + public void setMinMaxDefaultFloat(float min, float max, float def) { + minFloat = min; + maxFloat = max; + defFloat = def; + } + + public static void unfocus() { + GuiNpcTextField prev = activeTextfield; + activeTextfield = null; + if (prev != null) { + prev.unFocused(); + } + } + + public void drawTextBox(int mousX, int mousY) { + drawTextBox(); + } + + public GuiNpcTextField setIntegersOnly() { + integersOnly = true; + return this; + } + + public GuiNpcTextField setDoublesOnly() { + doublesOnly = true; + return this; + } + + public GuiNpcTextField setFloatsOnly() { + floatsOnly = true; + return this; + } - public GuiNpcTextField setDoublesOnly() { - doublesOnly = true; - return this; - } - public GuiNpcTextField setFloatsOnly() { - floatsOnly = true; - return this; - } } From 2f0f32b1adabf914d52fd8a30fe3958f31ab96bf Mon Sep 17 00:00:00 2001 From: bigguy345 Date: Tue, 6 Aug 2024 21:48:26 +0300 Subject: [PATCH 6/9] GuiScrollWindow fixes and QoL --- .../npcs/client/gui/util/GuiScrollWindow.java | 276 +++++++++--------- 1 file changed, 144 insertions(+), 132 deletions(-) diff --git a/src/main/java/noppes/npcs/client/gui/util/GuiScrollWindow.java b/src/main/java/noppes/npcs/client/gui/util/GuiScrollWindow.java index fff2d6a78..3b7e27b46 100644 --- a/src/main/java/noppes/npcs/client/gui/util/GuiScrollWindow.java +++ b/src/main/java/noppes/npcs/client/gui/util/GuiScrollWindow.java @@ -9,21 +9,21 @@ import noppes.npcs.entity.EntityNPCInterface; import org.lwjgl.input.Keyboard; import org.lwjgl.input.Mouse; import org.lwjgl.opengl.GL11; + import java.util.ArrayList; import java.util.HashMap; -public class GuiScrollWindow extends GuiScreen implements ITextfieldListener, ICustomScrollListener, GuiYesNoCallback -{ - public static final ResourceLocation resource = new ResourceLocation("customnpcs","textures/gui/misc.png"); +public class GuiScrollWindow extends GuiScreen implements ITextfieldListener, ICustomScrollListener, GuiYesNoCallback { + public static final ResourceLocation resource = new ResourceLocation("customnpcs", "textures/gui/misc.png"); protected GuiNPCInterface parent; - public boolean drawDefaultBackground = true; - public EntityNPCInterface npc; - protected HashMap buttons = new HashMap(); - protected HashMap textfields = new HashMap(); - protected HashMap labels = new HashMap(); - protected HashMap scrolls = new HashMap(); - protected HashMap sliders = new HashMap(); + public boolean drawDefaultBackground = true; + public EntityNPCInterface npc; + protected HashMap buttons = new HashMap(); + protected HashMap textfields = new HashMap(); + protected HashMap labels = new HashMap(); + protected HashMap scrolls = new HashMap(); + protected HashMap sliders = new HashMap(); protected ScaledResolution scaledResolution; @@ -38,18 +38,20 @@ public class GuiScrollWindow extends GuiScreen implements ITextfieldListener, IC public int maxScrollY = 0; public float scrollY = 0; public float nextScrollY = 0; + public float scrollSpeed = 7; public int mouseScroll; boolean isScrolling; /** * Scrollable GUI component :P? - * @param posX the X Position of the gui element on the screen - * @param posY the Y Position of the GUI element on the screen - * @param clipWidth width of the element + * + * @param posX the X Position of the gui element on the screen + * @param posY the Y Position of the GUI element on the screen + * @param clipWidth width of the element * @param clipHeight height of the element - * @param maxScroll extra Y area displayed through the scrollbar. + * @param maxScroll extra Y area displayed through the scrollbar. */ - public GuiScrollWindow(GuiNPCInterface parent, int posX, int posY, int clipWidth, int clipHeight, int maxScroll){ + public GuiScrollWindow(GuiNPCInterface parent, int posX, int posY, int clipWidth, int clipHeight, int maxScroll) { this.parent = parent; this.xPos = posX; this.yPos = posY; @@ -60,19 +62,19 @@ public class GuiScrollWindow extends GuiScreen implements ITextfieldListener, IC @Override - public void initGui(){ - super.initGui(); + public void initGui() { + super.initGui(); scaledResolution = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight); float scrollPerc = 0; - if((yPos+clipHeight) != 0){ + if ((yPos + clipHeight) != 0) { scrollPerc = (nextScrollY) / (clipHeight); } nextScrollY = scrollPerc * (clipHeight); - GuiNpcTextField.unfocus(); + GuiNpcTextField.unfocus(); buttonList.clear(); labels.clear(); textfields.clear(); @@ -81,88 +83,100 @@ public class GuiScrollWindow extends GuiScreen implements ITextfieldListener, IC sliders.clear(); Keyboard.enableRepeatEvents(true); } + @Override - public void updateScreen(){ - for(GuiNpcTextField tf : textfields.values()){ - if(tf.enabled) + public void updateScreen() { + for (GuiNpcTextField tf : textfields.values()) { + if (tf.enabled) tf.updateCursorCounter(); } super.updateScreen(); } - public void mouseClicked(int i, int j, int k) - { + public void mouseClicked(int i, int j, int k) { i = i - xPos; - j = (int) (j-yPos+scrollY); + j = (int) (j - yPos + scrollY); - for(GuiNpcTextField tf : new ArrayList(textfields.values())) - if(tf.enabled) + for (GuiNpcTextField tf : new ArrayList(textfields.values())) + if (tf.enabled) tf.mouseClicked(i, j, k); - if (k == 0){ - for(GuiCustomScroll scroll : new ArrayList(scrolls.values())){ + if (k == 0) { + for (GuiCustomScroll scroll : new ArrayList(scrolls.values())) { scroll.mouseClicked(i, j, k); } } - mouseEvent(i,j,k); + mouseEvent(i, j, k); super.mouseClicked(i, j, k); } - public void mouseEvent(int i, int j, int k){}; + public void mouseEvent(int i, int j, int k) { + } + @Override - protected void actionPerformed(GuiButton guibutton) { + protected void actionPerformed(GuiButton guibutton) { + parent.actionPerformed(guibutton); + } + + public void buttonEvent(GuiButton guibutton) { parent.buttonEvent(guibutton); - } - public void buttonEvent(GuiButton guibutton){ - parent.buttonEvent(guibutton); - }; + } + @Override - public void keyTyped(char c, int i){ - for(GuiNpcTextField tf : textfields.values()) - tf.textboxKeyTyped(c, i); + public void keyTyped(char c, int i) { + for (GuiNpcTextField tf : textfields.values()) + tf.textboxKeyTyped(c, i); } - public void addButton(GuiNpcButton button){ - buttons.put(button.id,button); - buttonList.add(button); + public void addButton(GuiNpcButton button) { + buttons.put(button.id, button); + buttonList.add(button); } - public GuiNpcButton getButton(int i) { - return buttons.get(i); - } - public void addTextField(GuiNpcTextField tf){ - textfields.put(tf.id,tf); + + public GuiNpcButton getButton(int i) { + return buttons.get(i); } - public GuiNpcTextField getTextField(int i){ - return textfields.get(i); + + public void addTextField(GuiNpcTextField tf) { + textfields.put(tf.id, tf); } + + public GuiNpcTextField getTextField(int i) { + return textfields.get(i); + } + public void addLabel(GuiNpcLabel label) { - labels.put(label.id, label); - } - public GuiNpcLabel getLabel(int i){ - return labels.get(i); + labels.put(label.id, label); } - public void addSlider(GuiNpcSlider slider){ - sliders.put(slider.id,slider); - buttonList.add(slider); + public GuiNpcLabel getLabel(int i) { + return labels.get(i); } - public GuiNpcSlider getSlider(int i) { - return sliders.get(i); - } - public void addScroll(GuiCustomScroll scroll) { + + public void addSlider(GuiNpcSlider slider) { + sliders.put(slider.id, slider); + buttonList.add(slider); + } + + public GuiNpcSlider getSlider(int i) { + return sliders.get(i); + } + + public void addScroll(GuiCustomScroll scroll) { scroll.setWorldAndResolution(mc, 350, 250); scrolls.put(scroll.id, scroll); - } - public GuiCustomScroll getScroll(int id){ - return scrolls.get(id); - } + } + + public GuiCustomScroll getScroll(int id) { + return scrolls.get(id); + } @Override - public void drawScreen(int mouseX, int mouseY, float partialTicks){ + public void drawScreen(int mouseX, int mouseY, float partialTicks) { scrollY = (float) lerp(scrollY, nextScrollY, partialTicks); boolean drawBackground = this.drawDefaultBackground; @@ -173,181 +187,179 @@ public class GuiScrollWindow extends GuiScreen implements ITextfieldListener, IC setClip(xPos, yPos, clipWidth, clipHeight); this.drawDefaultBackground = false; - if(drawBackground) + if (drawBackground) this.drawGradientRect(0, 0, this.width, this.height, 0x66000000, 0x88000000); - if(maxScrollY > 0) - setClip(xPos, yPos, clipWidth-13, clipHeight); + if (maxScrollY > 0) + setClip(xPos, yPos, clipWidth - 13, clipHeight); - GL11.glTranslatef(xPos, yPos-scrollY, 0); + GL11.glTranslatef(xPos, yPos - scrollY, 0); - this.drawComponents(mouseX -xPos, (int) (mouseY +scrollY-yPos), partialTicks); + this.drawComponents(mouseX - xPos, (int) (mouseY + scrollY - yPos), partialTicks); this.drawDefaultBackground = drawBackground; //Disable clipping (VERY IMPORTANT) GL11.glDisable(GL11.GL_SCISSOR_TEST); - GL11.glTranslatef(-xPos, -yPos+scrollY, 0); + GL11.glTranslatef(-xPos, -yPos + scrollY, 0); - if(maxScrollY > 0){ + if (maxScrollY > 0) { drawScrollBar(); } GL11.glPopMatrix(); } - public void drawScreen(int mouseX, int mouseY, float partialTicks, int mouseScroll){ + public void drawScreen(int mouseX, int mouseY, float partialTicks, int mouseScroll) { adjustScroll(mouseX, mouseY, mouseScroll); this.mouseScroll = mouseScroll; this.drawScreen(mouseX, mouseY, partialTicks); } - public void drawComponents(int i, int j, float f){ - if(drawDefaultBackground) + public void drawComponents(int i, int j, float f) { + if (drawDefaultBackground) drawDefaultBackground(); boolean subGui = parent.hasSubGui(); - for(GuiNpcLabel label : labels.values()) - label.drawLabel(this,fontRendererObj); - for(GuiNpcTextField tf : textfields.values()){ + for (GuiNpcLabel label : labels.values()) + label.drawLabel(this, fontRendererObj); + for (GuiNpcTextField tf : textfields.values()) { tf.drawTextBox(i, j); } - for(GuiCustomScroll scroll : scrolls.values()){ + for (GuiCustomScroll scroll : scrolls.values()) { scroll.updateSubGUI(subGui); - scroll.drawScreen(i, j, f, !subGui && scroll.isMouseOver(i, j)?mouseScroll:0); + scroll.drawScreen(i, j, f, !subGui && scroll.isMouseOver(i, j) ? mouseScroll : 0); } super.drawScreen(i, j, f); - for(GuiCustomScroll scroll : scrolls.values()) - if(scroll.hoverableText){ + for (GuiCustomScroll scroll : scrolls.values()) + if (scroll.hoverableText) { scroll.drawHover(i, j); } - for(GuiNpcButton button : buttons.values()){ + for (GuiNpcButton button : buttons.values()) { button.updateSubGUI(subGui); - if(!button.hoverableText.isEmpty()){ + if (!button.hoverableText.isEmpty()) { button.drawHover(i, j, subGui); } } } - public void elementClicked() { + public void elementClicked() { parent.elementClicked(); - } - @Override - public boolean doesGuiPauseGame(){ + } + + @Override + public boolean doesGuiPauseGame() { return false; } - public void doubleClicked() {} + public void doubleClicked() { + } - public boolean isInventoryKey(int i){ + public boolean isInventoryKey(int i) { return i == mc.gameSettings.keyBindInventory.getKeyCode(); //inventory key - } + } @Override - public void drawDefaultBackground() { - super.drawDefaultBackground(); - } + public void drawDefaultBackground() { + super.drawDefaultBackground(); + } - protected void setClip(int x, int y, int width, int height){ - if(scaledResolution == null) + protected void setClip(int x, int y, int width, int height) { + if (scaledResolution == null) return; int scaleFactor = scaledResolution.getScaleFactor(); // Correct the positions for Screen Space in OpenGL - x*=scaleFactor; - y*=scaleFactor; - width*=scaleFactor; - height*=scaleFactor; + x *= scaleFactor; + y *= scaleFactor; + width *= scaleFactor; + height *= scaleFactor; // Adjust position to Top-Left origin (OpenGL window/screen space uses bottom-left origin) - y=mc.displayHeight-y; + y = mc.displayHeight - y; // Set clip - GL11.glScissor(x, y-height, width, height); + GL11.glScissor(x, y - height, width, height); } - public boolean isMouseOver(int mouseX, int mouseY){ - return mouseX >= xPos && mouseX <= clipWidth+xPos && mouseY >= yPos && mouseY <= clipHeight+yPos; + public boolean isMouseOver(int mouseX, int mouseY) { + return mouseX >= xPos && mouseX <= clipWidth + xPos && mouseY >= yPos && mouseY <= clipHeight + yPos; } public void adjustScroll(int mouseX, int mouseY, int mouseScroll) { mouseX -= xPos; mouseY -= yPos; - if(Mouse.isButtonDown(0)){ - if(mouseX >= clipWidth-9 && mouseX < clipWidth-4 && mouseY >= 4 && mouseY < clipHeight){ + if (Mouse.isButtonDown(0)) { + if (mouseX >= clipWidth - 9 && mouseX < clipWidth - 4 && mouseY >= 4 && mouseY < clipHeight) { isScrolling = true; } - } - else + } else isScrolling = false; - if(isScrolling){ + if (isScrolling) { // This Scroll Y is wrong float proportion = (mouseY - 4) / (float) (clipHeight - 8); nextScrollY = (int) (proportion * maxScrollY); - if(nextScrollY < 0){ - nextScrollY = 0; - } - if(nextScrollY > maxScrollY){ - nextScrollY = maxScrollY; - } + } - if(!parent.hasSubGui()){ - for(GuiCustomScroll guiCustomScroll : scrolls.values()) { + if (!parent.hasSubGui()) { + for (GuiCustomScroll guiCustomScroll : scrolls.values()) { if (guiCustomScroll.isMouseOver(mouseX, (int) (mouseY + scrollY))) { return; } } } - if(mouseScroll != 0){ - nextScrollY -= (float) mouseScroll/15; - if(nextScrollY > maxScrollY) - nextScrollY = maxScrollY; - if(nextScrollY < 0) - nextScrollY = 0; + if (mouseScroll != 0) + nextScrollY -= (float) mouseScroll / scrollSpeed; + + + if (nextScrollY < 0) { + nextScrollY = 0; + } + if (nextScrollY > maxScrollY) { + nextScrollY = maxScrollY; } } - private void drawScrollBar() - { + private void drawScrollBar() { mc.renderEngine.bindTexture(resource); GL11.glColor4f(1, 1, 1, 1); - int maxSize = (int) ((clipHeight) * ( (double) (clipHeight)/ (clipHeight + maxScrollY))); + int maxSize = (int) ((clipHeight) * ((double) (clipHeight) / (clipHeight + maxScrollY))); int x = xPos + clipWidth - 9; - int y = (int) (yPos + 4 + (scrollY/maxScrollY * (clipHeight-maxSize-8))); + int y = (int) (yPos + 4 + (scrollY / maxScrollY * (clipHeight - maxSize - 8))); - for(int k = y; k < y+maxSize && k-clipHeight+maxSize < clipHeight + yPos;k++){ + for (int k = y; k < y + maxSize && k - clipHeight + maxSize < clipHeight + yPos; k++) { drawTexturedModalRect(x, k, 176, 9, 5, 1); } } - private double lerp(double a, double b, double lambda){ + private double lerp(double a, double b, double lambda) { return a + lambda * (b - a); } @Override public void customScrollClicked(int i, int j, int k, GuiCustomScroll guiCustomScroll) { - if(parent instanceof ICustomScrollListener) + if (parent instanceof ICustomScrollListener) ((ICustomScrollListener) parent).customScrollClicked(i, j, k, guiCustomScroll); } @Override public void customScrollDoubleClicked(String selection, GuiCustomScroll scroll) { - if(parent instanceof ICustomScrollListener) + if (parent instanceof ICustomScrollListener) ((ICustomScrollListener) parent).customScrollDoubleClicked(selection, scroll); } @Override public void unFocused(GuiNpcTextField textfield) { - if(parent instanceof ITextfieldListener) + if (parent instanceof ITextfieldListener) ((ITextfieldListener) parent).unFocused(textfield); } } From 2fba5936476c845b7dcc9e932cbcd9404d52e6bd Mon Sep 17 00:00:00 2001 From: bigguy345 Date: Tue, 6 Aug 2024 21:48:57 +0300 Subject: [PATCH 7/9] Changed ModelMPM methods access to public (for addon NPC outline rendering) --- src/main/java/noppes/npcs/client/model/ModelMPM.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/noppes/npcs/client/model/ModelMPM.java b/src/main/java/noppes/npcs/client/model/ModelMPM.java index bf7e00d03..a74784678 100644 --- a/src/main/java/noppes/npcs/client/model/ModelMPM.java +++ b/src/main/java/noppes/npcs/client/model/ModelMPM.java @@ -730,7 +730,7 @@ public class ModelMPM extends ModelNPCMale{ to.rotationPointZ = from.rotationPointZ; } - private void renderHead(EntityCustomNpc entity, float f) { + public void renderHead(EntityCustomNpc entity, float f) { loadPlayerTexture(entity); float x = 0; float y = entity.modelData.getBodyY(); @@ -765,7 +765,7 @@ public class ModelMPM extends ModelNPCMale{ GL11.glPopMatrix(); } - private void renderBody(EntityCustomNpc entity, float f) { + public void renderBody(EntityCustomNpc entity, float f) { loadPlayerTexture(entity); float x = 0; float y = entity.modelData.getBodyY(); @@ -872,7 +872,7 @@ public class ModelMPM extends ModelNPCMale{ GL11.glPopMatrix(); } - private void renderLegs(EntityCustomNpc entity, float f) { + public void renderLegs(EntityCustomNpc entity, float f) { loadPlayerTexture(entity); ModelScalePart legs = entity.modelData.modelScale.legs; From 37e93df24a8e11c9c536bfe466904a05f916deda Mon Sep 17 00:00:00 2001 From: bigguy345 Date: Sun, 11 Aug 2024 19:55:00 +0300 Subject: [PATCH 8/9] Fixed SubGuiAnimationOptions not closing on escape --- .../java/noppes/npcs/client/gui/SubGuiAnimationOptions.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/noppes/npcs/client/gui/SubGuiAnimationOptions.java b/src/main/java/noppes/npcs/client/gui/SubGuiAnimationOptions.java index 4a0724644..9ac9f8ec3 100644 --- a/src/main/java/noppes/npcs/client/gui/SubGuiAnimationOptions.java +++ b/src/main/java/noppes/npcs/client/gui/SubGuiAnimationOptions.java @@ -12,6 +12,7 @@ public class SubGuiAnimationOptions extends SubGuiInterface { public SubGuiAnimationOptions(Animation animation) { this.animation = animation; setBackground("smallbg.png"); + closeOnEsc = true; } @Override @@ -50,6 +51,7 @@ public class SubGuiAnimationOptions extends SubGuiInterface { animation.whileMoving = value == 0; } + initGui(); } } From bce3b2f5eaf3da942ac150561975a20bf4ed1884 Mon Sep 17 00:00:00 2001 From: bigguy345 Date: Sun, 11 Aug 2024 20:22:35 +0300 Subject: [PATCH 9/9] Added closeOnEsc variable to ICustomGui --- .../npcs/client/gui/custom/GuiCustom.java | 5 +- .../noppes/npcs/scripted/gui/ScriptGui.java | 69 +++++++++---------- 2 files changed, 38 insertions(+), 36 deletions(-) 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; } }