diff --git a/src/main/java/nl/requios/effortlessbuilding/BuildConfig.java b/src/main/java/nl/requios/effortlessbuilding/BuildConfig.java index 2d0b54b..c72ac06 100644 --- a/src/main/java/nl/requios/effortlessbuilding/BuildConfig.java +++ b/src/main/java/nl/requios/effortlessbuilding/BuildConfig.java @@ -19,13 +19,13 @@ public class BuildConfig { @Comment({"Maximum reach in survival without upgrades", "Reach upgrades are craftable consumables that permanently increase reach.", "Set to 0 to disable Effortless Building until the player has consumed a reach upgrade."}) - public int maxReachLevel0 = 10; + public int maxReachLevel0 = 20; @Comment("Maximum reach in survival with one upgrade") - public int maxReachLevel1 = 20; + public int maxReachLevel1 = 50; @Comment("Maximum reach in survival with two upgrades") - public int maxReachLevel2 = 50; + public int maxReachLevel2 = 100; @Comment("Maximum reach in survival with three upgrades") public int maxReachLevel3 = 200; diff --git a/src/main/java/nl/requios/effortlessbuilding/gui/ArraySettingsGui.java b/src/main/java/nl/requios/effortlessbuilding/gui/ArraySettingsGui.java index 7c11492..1597544 100644 --- a/src/main/java/nl/requios/effortlessbuilding/gui/ArraySettingsGui.java +++ b/src/main/java/nl/requios/effortlessbuilding/gui/ArraySettingsGui.java @@ -65,6 +65,8 @@ public class ArraySettingsGui extends GuiCollapsibleScrollEntry { textArrayCount.setNumber(a.count); } + setCollapsed(!buttonArrayEnabled.isChecked()); + return id; } @@ -154,6 +156,9 @@ public class ArraySettingsGui extends GuiCollapsibleScrollEntry { @Override public void actionPerformed(GuiButton button) { super.actionPerformed(button); + if (button == buttonArrayEnabled) { + setCollapsed(!buttonArrayEnabled.isChecked()); + } arrayNumberFieldList.forEach(numberField -> numberField.actionPerformed(button)); } @@ -181,6 +186,11 @@ public class ArraySettingsGui extends GuiCollapsibleScrollEntry { return "Array"; } + @Override + protected int getExpandedHeight() { + return 80; + } + private int getArrayReach() { try { diff --git a/src/main/java/nl/requios/effortlessbuilding/gui/GuiCollapsibleScrollEntry.java b/src/main/java/nl/requios/effortlessbuilding/gui/GuiCollapsibleScrollEntry.java index 80b2cc2..deb0031 100644 --- a/src/main/java/nl/requios/effortlessbuilding/gui/GuiCollapsibleScrollEntry.java +++ b/src/main/java/nl/requios/effortlessbuilding/gui/GuiCollapsibleScrollEntry.java @@ -13,6 +13,8 @@ public abstract class GuiCollapsibleScrollEntry implements GuiScrollPane.IScroll public GuiScrollPane scrollPane; protected FontRenderer fontRenderer; protected Minecraft mc; + + protected boolean isCollapsed = true; protected int left, right, top, bottom; public GuiCollapsibleScrollEntry(GuiScrollPane scrollPane) { @@ -78,7 +80,24 @@ public abstract class GuiCollapsibleScrollEntry implements GuiScrollPane.IScroll } + @Override + public int getHeight() { + return isCollapsed ? getCollapsedHeight() : getExpandedHeight(); + } + + public void setCollapsed(boolean collapsed) { + this.isCollapsed = collapsed; + } + protected String getName() { return "Collapsible scroll entry"; } + + protected int getCollapsedHeight() { + return 24; + } + + protected int getExpandedHeight() { + return 100; + } } diff --git a/src/main/java/nl/requios/effortlessbuilding/gui/GuiScrollPane.java b/src/main/java/nl/requios/effortlessbuilding/gui/GuiScrollPane.java index f572a94..bbf21e0 100644 --- a/src/main/java/nl/requios/effortlessbuilding/gui/GuiScrollPane.java +++ b/src/main/java/nl/requios/effortlessbuilding/gui/GuiScrollPane.java @@ -1,5 +1,6 @@ package nl.requios.effortlessbuilding.gui; +import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiListExtended; @@ -11,6 +12,7 @@ import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.util.math.MathHelper; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; +import org.lwjgl.input.Mouse; import java.io.IOException; import java.util.ArrayList; @@ -41,18 +43,18 @@ public class GuiScrollPane extends GuiListExtended { return listEntries.size(); } - @Override - protected int getContentHeight() { - //TODO add every entry height - return this.getSize() * this.slotHeight + this.headerPadding; - } - @Override protected int getScrollBarX() { //return width / 2 + 140 + 10; return width - 15; } + @Override + public int getListWidth() { + return 280; + } + + //Removed background @Override public void drawScreen(int mouseXIn, int mouseYIn, float partialTicks) { @@ -60,72 +62,69 @@ public class GuiScrollPane extends GuiListExtended { { this.mouseX = mouseXIn; this.mouseY = mouseYIn; - int i = this.getScrollBarX(); - int j = i + 6; + int scrollBarLeft = this.getScrollBarX(); + int scrollBarRight = scrollBarLeft + 6; this.bindAmountScrolled(); GlStateManager.disableLighting(); GlStateManager.disableFog(); - //Own code: clipping - - - Tessellator tessellator = Tessellator.getInstance(); BufferBuilder bufferbuilder = tessellator.getBuffer(); - int k = this.left + this.width / 2 - this.getListWidth() / 2 + 2; - int l = this.top + 4 - (int)this.amountScrolled; + int insideLeft = this.left + this.width / 2 - this.getListWidth() / 2 + 2; + int insideTop = this.top + 4 - (int)this.amountScrolled; if (this.hasListHeader) { - this.drawListHeader(k, l, tessellator); + this.drawListHeader(insideLeft, insideTop, tessellator); } //All entries - this.drawSelectionBox(k, l, mouseXIn, mouseYIn, partialTicks); + this.drawSelectionBox(insideLeft, insideTop, mouseXIn, mouseYIn, partialTicks); GlStateManager.disableDepth(); //Dirt overlays on top and bottom - this.overlayBackground(0, this.top, 255, 255); - this.overlayBackground(this.bottom, this.height, 255, 255); +// this.overlayBackground(0, this.top, 255, 255); +// this.overlayBackground(this.bottom, this.height, 255, 255); GlStateManager.enableBlend(); GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ZERO, GlStateManager.DestFactor.ONE); GlStateManager.disableAlpha(); GlStateManager.shadeModel(7425); GlStateManager.disableTexture2D(); - //top fade - bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR); - bufferbuilder.pos((double)this.left, (double)(this.top + 5), 0.0D).tex(0.0D, 1.0D).color(100, 100, 100, 0).endVertex(); - bufferbuilder.pos((double)this.right, (double)(this.top + 5), 0.0D).tex(1.0D, 1.0D).color(100, 100, 100, 0).endVertex(); - bufferbuilder.pos((double)this.right, (double)this.top, 0.0D).tex(1.0D, 0.0D).color(100, 100, 100, 100).endVertex(); - bufferbuilder.pos((double)this.left, (double)this.top, 0.0D).tex(0.0D, 0.0D).color(100, 100, 100, 100).endVertex(); - tessellator.draw(); - //top line - bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR); - bufferbuilder.pos((double)this.left, (double)this.top, 0.0D).tex(0.0D, 1.0D).color(20, 20, 20, 255).endVertex(); - bufferbuilder.pos((double)this.right, (double)this.top, 0.0D).tex(1.0D, 1.0D).color(20, 20, 20, 255).endVertex(); - bufferbuilder.pos((double)this.right, (double)(this.top - 1), 0.0D).tex(1.0D, 0.0D).color(20, 20, 20, 255).endVertex(); - bufferbuilder.pos((double)this.left, (double)(this.top - 1), 0.0D).tex(0.0D, 0.0D).color(20, 20, 20, 255).endVertex(); - tessellator.draw(); - //bottom fade - bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR); - bufferbuilder.pos((double)this.left, (double)this.bottom, 0.0D).tex(0.0D, 1.0D).color(10, 10, 10, 100).endVertex(); - bufferbuilder.pos((double)this.right, (double)this.bottom, 0.0D).tex(1.0D, 1.0D).color(10, 10, 10, 100).endVertex(); - bufferbuilder.pos((double)this.right, (double)(this.bottom - 5), 0.0D).tex(1.0D, 0.0D).color(10, 10, 10, 0).endVertex(); - bufferbuilder.pos((double)this.left, (double)(this.bottom - 5), 0.0D).tex(0.0D, 0.0D).color(10, 10, 10, 0).endVertex(); - tessellator.draw(); - //bottom line - bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR); - bufferbuilder.pos((double)this.left, (double)(this.bottom + 1), 0.0D).tex(0.0D, 1.0D).color(20, 20, 20, 255).endVertex(); - bufferbuilder.pos((double)this.right, (double)(this.bottom + 1), 0.0D).tex(1.0D, 1.0D).color(20, 20, 20, 255).endVertex(); - bufferbuilder.pos((double)this.right, (double)this.bottom, 0.0D).tex(1.0D, 0.0D).color(20, 20, 20, 255).endVertex(); - bufferbuilder.pos((double)this.left, (double)this.bottom, 0.0D).tex(0.0D, 0.0D).color(20, 20, 20, 255).endVertex(); - tessellator.draw(); - int j1 = this.getMaxScroll(); +// //top fade +// bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR); +// bufferbuilder.pos((double)this.left, (double)(this.top + 5), 0.0D).tex(0.0D, 1.0D).color(100, 100, 100, 0).endVertex(); +// bufferbuilder.pos((double)this.right, (double)(this.top + 5), 0.0D).tex(1.0D, 1.0D).color(100, 100, 100, 0).endVertex(); +// bufferbuilder.pos((double)this.right, (double)this.top, 0.0D).tex(1.0D, 0.0D).color(100, 100, 100, 100).endVertex(); +// bufferbuilder.pos((double)this.left, (double)this.top, 0.0D).tex(0.0D, 0.0D).color(100, 100, 100, 100).endVertex(); +// tessellator.draw(); +// //top line +// bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR); +// bufferbuilder.pos((double)this.left, (double)this.top, 0.0D).tex(0.0D, 1.0D).color(20, 20, 20, 255).endVertex(); +// bufferbuilder.pos((double)this.right, (double)this.top, 0.0D).tex(1.0D, 1.0D).color(20, 20, 20, 255).endVertex(); +// bufferbuilder.pos((double)this.right, (double)(this.top - 1), 0.0D).tex(1.0D, 0.0D).color(20, 20, 20, 255).endVertex(); +// bufferbuilder.pos((double)this.left, (double)(this.top - 1), 0.0D).tex(0.0D, 0.0D).color(20, 20, 20, 255).endVertex(); +// tessellator.draw(); +// //bottom fade +// bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR); +// bufferbuilder.pos((double)this.left, (double)this.bottom, 0.0D).tex(0.0D, 1.0D).color(10, 10, 10, 100).endVertex(); +// bufferbuilder.pos((double)this.right, (double)this.bottom, 0.0D).tex(1.0D, 1.0D).color(10, 10, 10, 100).endVertex(); +// bufferbuilder.pos((double)this.right, (double)(this.bottom - 5), 0.0D).tex(1.0D, 0.0D).color(10, 10, 10, 0).endVertex(); +// bufferbuilder.pos((double)this.left, (double)(this.bottom - 5), 0.0D).tex(0.0D, 0.0D).color(10, 10, 10, 0).endVertex(); +// tessellator.draw(); +// //bottom line +// bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR); +// bufferbuilder.pos((double)this.left, (double)(this.bottom + 1), 0.0D).tex(0.0D, 1.0D).color(20, 20, 20, 255).endVertex(); +// bufferbuilder.pos((double)this.right, (double)(this.bottom + 1), 0.0D).tex(1.0D, 1.0D).color(20, 20, 20, 255).endVertex(); +// bufferbuilder.pos((double)this.right, (double)this.bottom, 0.0D).tex(1.0D, 0.0D).color(20, 20, 20, 255).endVertex(); +// bufferbuilder.pos((double)this.left, (double)this.bottom, 0.0D).tex(0.0D, 0.0D).color(20, 20, 20, 255).endVertex(); +// tessellator.draw(); - if (j1 > 0) + //Draw scrollbar + int maxScroll = this.getMaxScroll(); + if (maxScroll > 0) { int k1 = (this.bottom - this.top) * (this.bottom - this.top) / this.getContentHeight(); k1 = MathHelper.clamp(k1, 32, this.bottom - this.top - 8); - int l1 = (int)this.amountScrolled * (this.bottom - this.top - k1) / j1 + this.top; + int l1 = (int)this.amountScrolled * (this.bottom - this.top - k1) / maxScroll + this.top; if (l1 < this.top) { @@ -133,22 +132,22 @@ public class GuiScrollPane extends GuiListExtended { } bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR); - bufferbuilder.pos((double)i, (double)this.bottom, 0.0D).tex(0.0D, 1.0D).color(0, 0, 0, 255).endVertex(); - bufferbuilder.pos((double)j, (double)this.bottom, 0.0D).tex(1.0D, 1.0D).color(0, 0, 0, 255).endVertex(); - bufferbuilder.pos((double)j, (double)this.top, 0.0D).tex(1.0D, 0.0D).color(0, 0, 0, 255).endVertex(); - bufferbuilder.pos((double)i, (double)this.top, 0.0D).tex(0.0D, 0.0D).color(0, 0, 0, 255).endVertex(); + bufferbuilder.pos((double)scrollBarLeft, (double)this.bottom, 0.0D).tex(0.0D, 1.0D).color(0, 0, 0, 255).endVertex(); + bufferbuilder.pos((double)scrollBarRight, (double)this.bottom, 0.0D).tex(1.0D, 1.0D).color(0, 0, 0, 255).endVertex(); + bufferbuilder.pos((double)scrollBarRight, (double)this.top, 0.0D).tex(1.0D, 0.0D).color(0, 0, 0, 255).endVertex(); + bufferbuilder.pos((double)scrollBarLeft, (double)this.top, 0.0D).tex(0.0D, 0.0D).color(0, 0, 0, 255).endVertex(); tessellator.draw(); bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR); - bufferbuilder.pos((double)i, (double)(l1 + k1), 0.0D).tex(0.0D, 1.0D).color(128, 128, 128, 255).endVertex(); - bufferbuilder.pos((double)j, (double)(l1 + k1), 0.0D).tex(1.0D, 1.0D).color(128, 128, 128, 255).endVertex(); - bufferbuilder.pos((double)j, (double)l1, 0.0D).tex(1.0D, 0.0D).color(128, 128, 128, 255).endVertex(); - bufferbuilder.pos((double)i, (double)l1, 0.0D).tex(0.0D, 0.0D).color(128, 128, 128, 255).endVertex(); + bufferbuilder.pos((double)scrollBarLeft, (double)(l1 + k1), 0.0D).tex(0.0D, 1.0D).color(128, 128, 128, 255).endVertex(); + bufferbuilder.pos((double)scrollBarRight, (double)(l1 + k1), 0.0D).tex(1.0D, 1.0D).color(128, 128, 128, 255).endVertex(); + bufferbuilder.pos((double)scrollBarRight, (double)l1, 0.0D).tex(1.0D, 0.0D).color(128, 128, 128, 255).endVertex(); + bufferbuilder.pos((double)scrollBarLeft, (double)l1, 0.0D).tex(0.0D, 0.0D).color(128, 128, 128, 255).endVertex(); tessellator.draw(); bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR); - bufferbuilder.pos((double)i, (double)(l1 + k1 - 1), 0.0D).tex(0.0D, 1.0D).color(192, 192, 192, 255).endVertex(); - bufferbuilder.pos((double)(j - 1), (double)(l1 + k1 - 1), 0.0D).tex(1.0D, 1.0D).color(192, 192, 192, 255).endVertex(); - bufferbuilder.pos((double)(j - 1), (double)l1, 0.0D).tex(1.0D, 0.0D).color(192, 192, 192, 255).endVertex(); - bufferbuilder.pos((double)i, (double)l1, 0.0D).tex(0.0D, 0.0D).color(192, 192, 192, 255).endVertex(); + bufferbuilder.pos((double)scrollBarLeft, (double)(l1 + k1 - 1), 0.0D).tex(0.0D, 1.0D).color(192, 192, 192, 255).endVertex(); + bufferbuilder.pos((double)(scrollBarRight - 1), (double)(l1 + k1 - 1), 0.0D).tex(1.0D, 1.0D).color(192, 192, 192, 255).endVertex(); + bufferbuilder.pos((double)(scrollBarRight - 1), (double)l1, 0.0D).tex(1.0D, 0.0D).color(192, 192, 192, 255).endVertex(); + bufferbuilder.pos((double)scrollBarLeft, (double)l1, 0.0D).tex(0.0D, 0.0D).color(192, 192, 192, 255).endVertex(); tessellator.draw(); } @@ -159,6 +158,231 @@ public class GuiScrollPane extends GuiListExtended { } } + //SLOTHEIGHT MODIFICATIONS + //SlotHeight is still relied on for determining how much to scroll + @Override + protected int getContentHeight() { + //Add every entry height + int height = this.headerPadding; + for (IScrollEntry entry : listEntries) { + height += entry.getHeight(); + } + return height; + } + + public int getContentHeight(int count) { + //Add all count entry heights + int height = this.headerPadding; + for (int i = 0; i < count; i++) { + IScrollEntry entry = listEntries.get(i); + height += entry.getHeight(); + } + return height; + } + + @Override + public int getSlotIndexFromScreenCoords(int posX, int posY) { + int left = this.left + (this.width - this.getListWidth()) / 2; + int right = this.left + (this.width + this.getListWidth()) / 2; + int relativeMouseY = posY - this.top - this.headerPadding + (int)this.amountScrolled - 4; //click height in content dimensions + //int slotIndex = relativeMouseY / this.slotHeight; + + //Iterate over every entry until relativeMouseY falls within its height + for (int i = 0; i < listEntries.size(); i++) { + IScrollEntry entry = listEntries.get(i); + if (relativeMouseY <= entry.getHeight()) + return posX < this.getScrollBarX() && posX >= left && posX <= right && i >= 0 && + relativeMouseY >= 0 && i < this.getSize() ? i : -1; + relativeMouseY -= entry.getHeight(); + } + return -1; + } + + @Override + public boolean mouseClicked(int mouseX, int mouseY, int mouseEvent) + { + if (this.isMouseYWithinSlotBounds(mouseY)) + { + int i = this.getSlotIndexFromScreenCoords(mouseX, mouseY); + + if (i >= 0) + { + int j = this.left + this.width / 2 - this.getListWidth() / 2 + 2; + int k = this.top + 4 - this.getAmountScrolled() + getContentHeight(i) + this.headerPadding; + int relativeX = mouseX - j; + int relativeY = mouseY - k; + + if (this.getListEntry(i).mousePressed(i, mouseX, mouseY, mouseEvent, relativeX, relativeY)) + { + this.setEnabled(false); + return true; + } + } + } + + return false; + } + + @Override + public boolean mouseReleased(int x, int y, int mouseEvent) + { + for (int i = 0; i < this.getSize(); ++i) + { + int j = this.left + this.width / 2 - this.getListWidth() / 2 + 2; + int k = this.top + 4 - this.getAmountScrolled() + getContentHeight(i) + this.headerPadding; + int relativeX = x - j; + int relativeY = y - k; + this.getListEntry(i).mouseReleased(i, x, y, mouseEvent, relativeX, relativeY); + } + + this.setEnabled(true); + return false; + } + + @Override + public void handleMouseInput() { + if (this.isMouseYWithinSlotBounds(this.mouseY)) { + if (Mouse.getEventButton() == 0 && Mouse.getEventButtonState() && this.mouseY >= this.top && + this.mouseY <= this.bottom) { + int i = this.left + (this.width - this.getListWidth()) / 2; + int j = this.left + (this.width + this.getListWidth()) / 2; + int relativeMouseY = this.mouseY - this.top - this.headerPadding + (int) this.amountScrolled - + 4; //click height in content dimensions + int slotIndex = getSlotIndexFromScreenCoords(this.mouseX, this.mouseY); + + if (slotIndex > -1) { + this.elementClicked(slotIndex, false, this.mouseX, this.mouseY); + this.selectedElement = slotIndex; + } else if (this.mouseX >= i && this.mouseX <= j && relativeMouseY < 0) { + this.clickedHeader(this.mouseX - i, this.mouseY - this.top + (int) this.amountScrolled - 4); + } + } + + if (Mouse.isButtonDown(0) && this.getEnabled()) { + if (this.initialClickY == -1) { + boolean flag1 = true; + + if (this.mouseY >= this.top && this.mouseY <= this.bottom) { + int i2 = this.left + (this.width - this.getListWidth()) / 2; + int j2 = this.left + (this.width + this.getListWidth()) / 2; + int relativeMouseY = this.mouseY - this.top - this.headerPadding + (int) this.amountScrolled - + 4; //click height in content dimensions + int slotIndex = getSlotIndexFromScreenCoords(this.mouseX, this.mouseY); + + if (slotIndex > -1) { + boolean flag = slotIndex == this.selectedElement && + Minecraft.getSystemTime() - this.lastClicked < 250L; + this.elementClicked(slotIndex, flag, this.mouseX, this.mouseY); + this.selectedElement = slotIndex; + this.lastClicked = Minecraft.getSystemTime(); + } else if (this.mouseX >= i2 && this.mouseX <= j2 && relativeMouseY < 0) { + this.clickedHeader(this.mouseX - i2, + this.mouseY - this.top + (int) this.amountScrolled - 4); + flag1 = false; + } + + int i3 = this.getScrollBarX(); + int j1 = i3 + 6; + + if (this.mouseX >= i3 && this.mouseX <= j1) { + this.scrollMultiplier = -1.0F; + int maxScroll = this.getMaxScroll(); + + if (maxScroll < 1) { + maxScroll = 1; + } + + int l1 = (int) ((float) ((this.bottom - this.top) * (this.bottom - this.top)) / + (float) this.getContentHeight()); + l1 = MathHelper.clamp(l1, 32, this.bottom - this.top - 8); + this.scrollMultiplier /= (float) (this.bottom - this.top - l1) / (float) maxScroll; + } else { + this.scrollMultiplier = 1.0F; + } + + if (flag1) { + this.initialClickY = this.mouseY; + } else { + this.initialClickY = -2; + } + } else { + this.initialClickY = -2; + } + } else if (this.initialClickY >= 0) { + this.amountScrolled -= (float) (this.mouseY - this.initialClickY) * this.scrollMultiplier; + this.initialClickY = this.mouseY; + } + } else { + this.initialClickY = -1; + } + + int i2 = Mouse.getEventDWheel(); + + if (i2 != 0) { + if (i2 > 0) { + i2 = -1; + } else if (i2 < 0) { + i2 = 1; + } + + this.amountScrolled += (float) (i2 * this.slotHeight / 2); + } + } + } + + //Draw in center if it fits + @Override + protected void drawSelectionBox(int insideLeft, int insideTop, int mouseXIn, int mouseYIn, float partialTicks) + { + int size = this.getSize(); + Tessellator tessellator = Tessellator.getInstance(); + BufferBuilder bufferbuilder = tessellator.getBuffer(); + + //Find y to start with + int y = this.headerPadding + insideTop; + int contentHeight = getContentHeight(); + int insideHeight = this.bottom - this.top - 4; + + if (contentHeight < insideHeight) { + //it fits, so we can center it vertically + y += (insideHeight - contentHeight) / 2; + } + + //Draw all entries + for (int i = 0; i < size; ++i) + { + int entryHeight = listEntries.get(i).getHeight(); + int entryHeight2 = entryHeight - 4; + + if (y > this.bottom || y + entryHeight2 < this.top) + { + this.updateItemPos(i, insideLeft, y, partialTicks); + } + + if (this.showSelectionBox && this.isSelected(i)) + { + int i1 = this.left + this.width / 2 - this.getListWidth() / 2; + int j1 = this.left + this.width / 2 + this.getListWidth() / 2; + GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); + GlStateManager.disableTexture2D(); + bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX_COLOR); + bufferbuilder.pos((double)i1, (double)(y + entryHeight2 + 2), 0.0D).tex(0.0D, 1.0D).color(128, 128, 128, 255).endVertex(); + bufferbuilder.pos((double)j1, (double)(y + entryHeight2 + 2), 0.0D).tex(1.0D, 1.0D).color(128, 128, 128, 255).endVertex(); + bufferbuilder.pos((double)j1, (double)(y - 2), 0.0D).tex(1.0D, 0.0D).color(128, 128, 128, 255).endVertex(); + bufferbuilder.pos((double)i1, (double)(y - 2), 0.0D).tex(0.0D, 0.0D).color(128, 128, 128, 255).endVertex(); + bufferbuilder.pos((double)(i1 + 1), (double)(y + entryHeight2 + 1), 0.0D).tex(0.0D, 1.0D).color(0, 0, 0, 255).endVertex(); + bufferbuilder.pos((double)(j1 - 1), (double)(y + entryHeight2 + 1), 0.0D).tex(1.0D, 1.0D).color(0, 0, 0, 255).endVertex(); + bufferbuilder.pos((double)(j1 - 1), (double)(y - 1), 0.0D).tex(1.0D, 0.0D).color(0, 0, 0, 255).endVertex(); + bufferbuilder.pos((double)(i1 + 1), (double)(y - 1), 0.0D).tex(0.0D, 0.0D).color(0, 0, 0, 255).endVertex(); + tessellator.draw(); + GlStateManager.enableTexture2D(); + } + + this.drawSlot(i, insideLeft, y, entryHeight2, mouseXIn, mouseYIn, partialTicks); + y += entryHeight; + } + } + //PASSTHROUGHS public int initGui(int id, List buttonList) { for (IScrollEntry entry : this.listEntries) { @@ -205,5 +429,7 @@ public class GuiScrollPane extends GuiListExtended { void actionPerformed(GuiButton button); void onGuiClosed(); + + int getHeight(); } } diff --git a/src/main/java/nl/requios/effortlessbuilding/gui/MirrorSettingsGui.java b/src/main/java/nl/requios/effortlessbuilding/gui/MirrorSettingsGui.java index 6851383..4af5b7a 100644 --- a/src/main/java/nl/requios/effortlessbuilding/gui/MirrorSettingsGui.java +++ b/src/main/java/nl/requios/effortlessbuilding/gui/MirrorSettingsGui.java @@ -123,6 +123,8 @@ public class MirrorSettingsGui extends GuiCollapsibleScrollEntry { buttonList.addAll(mirrorButtonList); buttonList.addAll(mirrorIconButtonList); + setCollapsed(!buttonMirrorEnabled.isChecked()); + return id; } @@ -219,6 +221,9 @@ public class MirrorSettingsGui extends GuiCollapsibleScrollEntry { @Override public void actionPerformed(GuiButton button) { super.actionPerformed(button); + if (button == buttonMirrorEnabled) { + setCollapsed(!buttonMirrorEnabled.isChecked()); + } if (button == buttonCurrentPosition) { Vec3d pos = new Vec3d(Math.floor(mc.player.posX) + 0.5, Math.floor(mc.player.posY) + 0.5, Math.floor(mc.player.posZ) + 0.5); textMirrorPosX.setNumber(pos.x); @@ -281,4 +286,9 @@ public class MirrorSettingsGui extends GuiCollapsibleScrollEntry { protected String getName() { return "Mirror"; } + + @Override + protected int getExpandedHeight() { + return 100; + } } diff --git a/src/main/java/nl/requios/effortlessbuilding/gui/SettingsGui.java b/src/main/java/nl/requios/effortlessbuilding/gui/SettingsGui.java index c961f2f..778e863 100644 --- a/src/main/java/nl/requios/effortlessbuilding/gui/SettingsGui.java +++ b/src/main/java/nl/requios/effortlessbuilding/gui/SettingsGui.java @@ -24,7 +24,7 @@ public class SettingsGui extends GuiScreen { public void initGui() { int id = 0; - scrollPane = new GuiScrollPane(this, fontRenderer, 8, height - 17); + scrollPane = new GuiScrollPane(this, fontRenderer, 8, height - 30); mirrorSettingsGui = new MirrorSettingsGui(scrollPane); scrollPane.listEntries.add(mirrorSettingsGui); @@ -32,10 +32,6 @@ public class SettingsGui extends GuiScreen { arraySettingsGui = new ArraySettingsGui(scrollPane); scrollPane.listEntries.add(arraySettingsGui); - //TODO for testing - mirrorSettingsGui = new MirrorSettingsGui(scrollPane); - scrollPane.listEntries.add(mirrorSettingsGui); - id = scrollPane.initGui(id, buttonList); //Close button