From f24c91702adcb13001112d056cf938502485bc65 Mon Sep 17 00:00:00 2001 From: Astoria Date: Mon, 10 Apr 2023 13:12:21 -0500 Subject: [PATCH] Better programming GUI --- .../afloydwiremod/gui/GuiButtonExtended.java | 22 ---- .../afloydwiremod/gui/GuiProgrammer.java | 101 ++++++++++++------ .../afloydwiremod/gui/GuiScrollable.java | 24 +---- .../afloydwiremod/gui/GuiSettings.java | 2 +- .../afloydwiremod/gui/GuiWireTool.java | 10 +- .../assets/afloydwiremod/gui/programmer.ase | Bin 0 -> 770 bytes .../assets/afloydwiremod/gui/programmer.png | Bin 0 -> 639 bytes 7 files changed, 76 insertions(+), 83 deletions(-) create mode 100644 src/main/resources/assets/afloydwiremod/gui/programmer.ase create mode 100644 src/main/resources/assets/afloydwiremod/gui/programmer.png diff --git a/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiButtonExtended.java b/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiButtonExtended.java index b473463..72cbf45 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiButtonExtended.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiButtonExtended.java @@ -9,7 +9,6 @@ public class GuiButtonExtended extends GuiButton { public String type; public int slot; - public int scroll; public static final int width = 80; public static final int height = 10; public GuiButtonExtended(int id, int xPosition, String s, String extra, int slot) { @@ -20,25 +19,4 @@ public class GuiButtonExtended extends GuiButton { public GuiButtonExtended(int id, int xPosition, String s) { super(id, xPosition / 2 - (width / 2), 50 - height + (height * (id + 1)), width, height, s); } - @Override - public void drawButton(Minecraft minecraft, int i, int j) { - if (!this.visible) { - return; - } - FontRenderer fontrenderer = minecraft.fontRenderer; - GL11.glBindTexture(3553, minecraft.renderEngine.getTexture("/gui/gui.png")); - GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); - boolean flag = i >= this.xPosition && j >= this.yPosition + scroll && i < this.xPosition + this.width && j < this.yPosition + scroll + this.height; - int k = this.getButtonState(flag); - this.drawTexturedModalRect(this.xPosition, this.yPosition + scroll, 0, 46 + k * 20, this.width / 2, this.height); - this.drawTexturedModalRect(this.xPosition + this.width / 2, this.yPosition + scroll, 200 - this.width / 2, 46 + k * 20, this.width / 2, this.height); - this.mouseDragged(minecraft, i, j); - if (!this.enabled) { - this.drawCenteredString(fontrenderer, this.displayString, this.xPosition + this.width / 2, this.yPosition + (this.height - 8) / 2 + scroll, -6250336); - } else if (flag) { - this.drawCenteredString(fontrenderer, this.displayString, this.xPosition + this.width / 2, this.yPosition + (this.height - 8) / 2 + scroll, 0xFFFFA0); - } else { - this.drawCenteredString(fontrenderer, this.displayString, this.xPosition + this.width / 2, this.yPosition + (this.height - 8) / 2 + scroll, 0xE0E0E0); - } - } } diff --git a/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiProgrammer.java b/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiProgrammer.java index 17d5883..d509fc0 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiProgrammer.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiProgrammer.java @@ -1,51 +1,53 @@ package net.brokenmoon.afloydwiremod.gui; import net.brokenmoon.afloydwiremod.api.AbstractWireTileEntity; -import net.brokenmoon.afloydwiremod.mixinInterfaces.IEntityPlayer; -import net.brokenmoon.afloydwiremod.mixinInterfaces.INetHandler; import net.brokenmoon.afloydwiremod.packet.WiremodProgrammerPacket; import net.brokenmoon.afloydwiremod.tileentity.ChipTileEntity; import net.minecraft.client.Minecraft; import net.minecraft.src.*; +import org.lwjgl.input.Mouse; +import org.lwjgl.opengl.GL11; public class GuiProgrammer extends GuiScrollable { private AbstractWireTileEntity wireEntity; + public int xSize = 100; + public int ySize = 180; + private int slot = 0; + @Override public void initGui() { //this.height - 240 is top //This.width / 2 - int i = 0; - this.controlList.add(new GuiButtonExtended(i++, this.width - GuiButtonExtended.width * 2, "TRUE")); - this.controlList.add(new GuiButtonExtended(i++, this.width - GuiButtonExtended.width * 2, "FALSE")); - this.controlList.add(new GuiButtonExtended(i++, this.width - GuiButtonExtended.width * 2, "AND")); - this.controlList.add(new GuiButtonExtended(i++, this.width - GuiButtonExtended.width * 2, "NAND")); - this.controlList.add(new GuiButtonExtended(i++, this.width - GuiButtonExtended.width * 2, "OR")); - this.controlList.add(new GuiButtonExtended(i++, this.width - GuiButtonExtended.width * 2, "NOR")); - this.controlList.add(new GuiButtonExtended(i++, this.width - GuiButtonExtended.width * 2, "XOR")); - this.controlList.add(new GuiButtonExtended(i++, this.width - GuiButtonExtended.width * 2, "XNOR")); - this.controlList.add(new GuiButtonExtended(i++, this.width - GuiButtonExtended.width * 2, "NOT")); - i = 0; - this.controlList.add(new GuiButtonExtended(i++, this.width, "Constant")); - this.controlList.add(new GuiButtonExtended(i++, this.width, "Increment")); - this.controlList.add(new GuiButtonExtended(i++, this.width, "Decrement")); - this.controlList.add(new GuiButtonExtended(i++, this.width, "Increment/Decrement")); - this.controlList.add(new GuiButtonExtended(i++, this.width, "Duplicate")); - this.controlList.add(new GuiButtonExtended(i++, this.width, "Addition")); - this.controlList.add(new GuiButtonExtended(i++, this.width, "Subtraction")); - this.controlList.add(new GuiButtonExtended(i++, this.width, "Multiplication")); - this.controlList.add(new GuiButtonExtended(i++, this.width, "Division")); - this.controlList.add(new GuiButtonExtended(i++, this.width, "Memory")); - this.controlList.add(new GuiButtonExtended(i++, this.width, "Pulse")); - i = 0; - this.controlList.add(new GuiButtonExtended(i++, this.width + GuiButtonExtended.width * 2, "==")); - this.controlList.add(new GuiButtonExtended(i++, this.width + GuiButtonExtended.width * 2, "!=")); - this.controlList.add(new GuiButtonExtended(i++, this.width + GuiButtonExtended.width * 2, ">")); - this.controlList.add(new GuiButtonExtended(i++, this.width + GuiButtonExtended.width * 2, ">=")); - this.controlList.add(new GuiButtonExtended(i++, this.width + GuiButtonExtended.width * 2, "<")); - this.controlList.add(new GuiButtonExtended(i++, this.width + GuiButtonExtended.width * 2, "<=")); - this.controlList.add(new GuiButtonExtended(i++, this.width + GuiButtonExtended.width * 2, "<=>")); + slot = 0; + this.controlList.add(new GuiButtonExtended(slot++, this.width, "Constant")); + this.controlList.add(new GuiButtonExtended(slot++, this.width, "Increment")); + this.controlList.add(new GuiButtonExtended(slot++, this.width, "Decrement")); + this.controlList.add(new GuiButtonExtended(slot++, this.width, "Increment/Decrement")); + this.controlList.add(new GuiButtonExtended(slot++, this.width, "Duplicate")); + this.controlList.add(new GuiButtonExtended(slot++, this.width, "Addition")); + this.controlList.add(new GuiButtonExtended(slot++, this.width, "Subtraction")); + this.controlList.add(new GuiButtonExtended(slot++, this.width, "Multiplication")); + this.controlList.add(new GuiButtonExtended(slot++, this.width, "Division")); + this.controlList.add(new GuiButtonExtended(slot++, this.width, "Memory")); + this.controlList.add(new GuiButtonExtended(slot++, this.width, "Pulse")); + this.controlList.add(new GuiButtonExtended(slot++, this.width, "TRUE")); + this.controlList.add(new GuiButtonExtended(slot++, this.width, "FALSE")); + this.controlList.add(new GuiButtonExtended(slot++, this.width, "AND")); + this.controlList.add(new GuiButtonExtended(slot++, this.width, "NAND")); + this.controlList.add(new GuiButtonExtended(slot++, this.width, "OR")); + this.controlList.add(new GuiButtonExtended(slot++, this.width, "NOR")); + this.controlList.add(new GuiButtonExtended(slot++, this.width, "XOR")); + this.controlList.add(new GuiButtonExtended(slot++, this.width, "XNOR")); + this.controlList.add(new GuiButtonExtended(slot++, this.width, "NOT")); + this.controlList.add(new GuiButtonExtended(slot++, this.width, "==")); + this.controlList.add(new GuiButtonExtended(slot++, this.width, "!=")); + this.controlList.add(new GuiButtonExtended(slot++, this.width, ">")); + this.controlList.add(new GuiButtonExtended(slot++, this.width, ">=")); + this.controlList.add(new GuiButtonExtended(slot++, this.width, "<")); + this.controlList.add(new GuiButtonExtended(slot++, this.width, "<=")); + this.controlList.add(new GuiButtonExtended(slot++, this.width, "<=>")); } public GuiProgrammer(EntityPlayer player, ChipTileEntity wireEntity) { @@ -119,4 +121,39 @@ public class GuiProgrammer extends GuiScrollable { ((ChipTileEntity)Minecraft.getMinecraft().theWorld.getBlockTileEntity(wireEntity.xCoord, wireEntity.yCoord, wireEntity.zCoord)).setMode(string); } + + @Override + public void drawScreen(int x, int y, float renderPartialTicks){ + this.drawDefaultBackground(); + //Draw the overlay + this.drawGuiBackground(renderPartialTicks); + GL11.glPushMatrix(); + GL11.glPopMatrix(); + int k = (this.height - this.ySize) / 2; + int wheel = Mouse.getDWheel(); + if(wheel > 0) + scroll++; + if (wheel < 0) + scroll--; + if(scroll > 0) + scroll = 0; + if(-scroll > slot - 16) + scroll = -(slot - 16); + for (int i = 0; i < this.controlList.size(); ++i) { + GuiButtonExtended guibutton = (GuiButtonExtended)this.controlList.get(i); + guibutton.yPosition = k + (guibutton.height * (guibutton.id + 1) + scroll * GuiButtonExtended.height); + if(guibutton.yPosition > k && guibutton.yPosition < k + 170){ + guibutton.drawButton(this.mc, x, y); + } + } + } + + protected void drawGuiBackground(float f) { + int guiTexture = this.mc.renderEngine.getTexture("/assets/afloydwiremod/gui/programmer.png"); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + this.mc.renderEngine.bindTexture(guiTexture); + int j = (this.width - this.xSize) / 2; + int k = (this.height - this.ySize) / 2; + this.drawTexturedModalRect(j, k, 0, 0, this.xSize, this.ySize); + } } diff --git a/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiScrollable.java b/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiScrollable.java index 27e7b25..a433aa3 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiScrollable.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiScrollable.java @@ -7,27 +7,5 @@ import org.lwjgl.input.Mouse; public class GuiScrollable extends GuiScreen { public EntityPlayer player; - private int scroll; - @Override - public void drawScreen(int x, int y, float renderPartialTicks) { - //TODO: Tweak these values later to fit all the stuff - int wheel = Mouse.getDWheel(); - if(wheel > 0) - scroll++; - if (wheel < 0) - scroll--; - if(scroll > 150) - scroll = 150; - if(scroll < 0) - scroll = 0; - for (int i = 0; i < this.controlList.size(); ++i) { - GuiButtonExtended guibutton = (GuiButtonExtended)this.controlList.get(i); - if(scroll >= 0) - guibutton.scroll = scroll; - if(scroll <= 0) - guibutton.scroll = scroll; - if(guibutton.yPosition >= 50 && guibutton.yPosition <= 200) - guibutton.drawButton(this.mc, x, y); - } - } + public int scroll; } diff --git a/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiSettings.java b/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiSettings.java index 341b504..977c685 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiSettings.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiSettings.java @@ -65,7 +65,7 @@ public class GuiSettings extends GuiScreen { if(guiButton.id == 1){ ((ChipTileEntity)wireEntity).tickAmount++; } - if(guiButton.id == 2){ + if(guiButton.id == 2 && ((ChipTileEntity)wireEntity).tickAmount > 0){ ((ChipTileEntity)wireEntity).tickAmount--; } if(this.player instanceof EntityClientPlayerMP){ diff --git a/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiWireTool.java b/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiWireTool.java index b2e5645..9abf74e 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiWireTool.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/gui/GuiWireTool.java @@ -23,11 +23,11 @@ public class GuiWireTool extends GuiScreen { @Override public void initGui() { - red = new GuiSlider(1, this.width/2-100, this.height/2-40, 200, 20, "Red", tool.red); - green = new GuiSlider(2, this.width/2-100, this.height/2-20, 200, 20, "Green", tool.green); - blue = new GuiSlider(3, this.width/2-100, this.height/2-0, 200, 20, "Blue", tool.blue); - alpha = new GuiSlider(4, this.width/2-100, this.height/2+20, 200, 20, "Alpha", tool.alpha); - widthslider = new GuiSlider(5, this.width/2-100, this.height/2+40, 200, 20, "Width", tool.width); + red = new GuiSlider(1, this.width/2-100, this.height/2-50, 200, 20, "Red", tool.red); + green = new GuiSlider(2, this.width/2-100, this.height/2-30, 200, 20, "Green", tool.green); + blue = new GuiSlider(3, this.width/2-100, this.height/2-10, 200, 20, "Blue", tool.blue); + alpha = new GuiSlider(4, this.width/2-100, this.height/2+10, 200, 20, "Alpha", tool.alpha); + widthslider = new GuiSlider(5, this.width/2-100, this.height/2+30, 200, 20, "Width", tool.width); this.controlList.add(red); this.controlList.add(green); this.controlList.add(blue); diff --git a/src/main/resources/assets/afloydwiremod/gui/programmer.ase b/src/main/resources/assets/afloydwiremod/gui/programmer.ase new file mode 100644 index 0000000000000000000000000000000000000000..934d7c6c7a98b51b34f1306239cab159a8ad075a GIT binary patch literal 770 zcmcJNOGs2v7=Zt=nH1b4iW+k94g@(f(iDTHi8vA>(df{GxNycO-w`;Lk+0b(fwl=+ z1mZx5iVGi$L=hwr7ZRj2LM^OCu1fHcQes4O`i@1pbkiB`H{5d<|M#7H<4%aIk61)3 zVo3lZwOs#}Q!IK@PVxI6t2<8Q`=0G^s*M4uT=C}N$Rp!Y**I-F|Li!9JQ1;{XDE>Z z^DKzYHOi?Fe|A9}CcgV{M{FeUvQylMns)0tWrb%x=xyA!Iw1I@)j z%|31Wu_PZ(xb@sNLtFU`A9NVnztE8j10L=CxU3SsxP1$%$*}6>9IX1CIXMFkfO^vD z*3mmX38$lZxy-8q?;Ku%qNPl&6c zgtWDSdaZ@=>Oh0@rP?31I{tsxeBw%M@@jkQT7UiUU=33TX?aC$ZC5M%IG>DG|0O#n zy*Tjo|BL$%UMyaIC?kKSgJ-dhsjrBHp0{jJrb@~jt%5W9)&GOa{~ucTzti}ctL0jK z*9uvGe_0<*S#4WQvmj&pe&6uDSxNub6`XxK>ln}_S|ve#!3_V21?v89M1X#&^mK6y zshIQj%0bS<1|lww+ZDgZXDCg&lX^jE+8OPHkMb?+y(gt5S1;GEy7cE>b+Iqo@AdyB z=j_Ybc;Rn;?{xFlA79 z0)g!6i4aCZ-&GF?%i(yI3WT*F*;EL^y0CH38Ta8k!}l9^Vp%@?yy38z`N1hhP+(jU z&ZuMvPS}6&j!o_L$z}hUcdwhS;yDQ?TDekud56x0h1-{Cf;{T!>gTe~DWM4f<@DfP literal 0 HcmV?d00001