From e4ae63e2a122e95b7cf0220d67842f62d1333197 Mon Sep 17 00:00:00 2001 From: UnRealDinnerbone Date: Fri, 9 Aug 2024 11:38:16 -0500 Subject: [PATCH 1/2] Fix widget alignment code --- .../sidebar/SidebarGroupGuiButton.java | 52 +++++++++---------- 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/common/src/main/java/dev/ftb/mods/ftblibrary/sidebar/SidebarGroupGuiButton.java b/common/src/main/java/dev/ftb/mods/ftblibrary/sidebar/SidebarGroupGuiButton.java index 0266390b..0dc10fe1 100644 --- a/common/src/main/java/dev/ftb/mods/ftblibrary/sidebar/SidebarGroupGuiButton.java +++ b/common/src/main/java/dev/ftb/mods/ftblibrary/sidebar/SidebarGroupGuiButton.java @@ -161,7 +161,7 @@ private void renderSidebarButtons(GuiGraphics graphics, int mx, int my) { } private void renderEditMode(GuiGraphics graphics, int mx, int my) { - drawHoveredGrid(graphics, xRenderStart, yRenderStart, currentGirdWidth, currentGridHeight, BUTTON_SPACING, Color4I.GRAY.withAlpha(70), Color4I.BLACK.withAlpha(90), mx, my, gridStartBottom, gridStartRight, getX(), getY()); + drawHoveredGrid(graphics, xRenderStart, yRenderStart, currentGirdWidth, currentGridHeight, BUTTON_SPACING, Color4I.GRAY.withAlpha(70), Color4I.BLACK.withAlpha(90), mx, my, gridStartBottom, gridStartRight); List disabledButtonList = SidebarButtonManager.INSTANCE.getDisabledButtonList(isEditMode); if (!disabledButtonList.isEmpty()) { @@ -190,10 +190,10 @@ private void renderEditMode(GuiGraphics graphics, int mx, int my) { graphics.pose().translate(0, 0, 1000); if (gridStartRight) { - drawHoveredGrid(graphics, addIconX, gridY, 1, disabledButtonList.size(), BUTTON_SPACING, Color4I.GRAY, Color4I.BLACK, mx, my, gridStartBottom, gridStartRight, gridX, gridY); + drawHoveredGrid(graphics, addIconX, gridY, 1, disabledButtonList.size(), BUTTON_SPACING, Color4I.GRAY, Color4I.BLACK, mx, my, gridStartBottom, gridStartRight); drawGrid(graphics, addIconX - maxWidth - 6, gridY, 1, disabledButtonList.size(), maxWidth + 6, BUTTON_SPACING, Color4I.GRAY, Color4I.BLACK); } else { - drawHoveredGrid(graphics, gridX, gridY, 1, disabledButtonList.size(), BUTTON_SPACING, Color4I.GRAY, Color4I.BLACK, mx, my, gridStartBottom, gridStartRight, gridX, gridY); + drawHoveredGrid(graphics, gridX, gridY, 1, disabledButtonList.size(), BUTTON_SPACING, Color4I.GRAY, Color4I.BLACK, mx, my, gridStartBottom, gridStartRight); drawGrid(graphics, gridX + BUTTON_SPACING, gridY, 1, disabledButtonList.size(), maxWidth + 6, BUTTON_SPACING, Color4I.GRAY, Color4I.BLACK); } @@ -376,17 +376,15 @@ private void updateWidgetSize() { currentGridHeight += 1; } - xRenderStart = (gridStartRight ? maxGirdAmountX - currentGirdWidth : 0) * BUTTON_SPACING; - yRenderStart = (gridStartBottom ? maxGirdAmountY - currentGridHeight + 1 : 0) * BUTTON_SPACING; + // Calculates the renderStart values need for drawing the grid at the correct location + // do to the fact the getX() and getY() change if is edit mode we want to make sure we are always + // drawing the main grid at the correct location + // when starting from bottom or right, calculate the value max screen size of that axis + // Subtracts are need to make gird align correctly + yRenderStart = gridStartBottom ? (screenHeight - currentGridHeight * BUTTON_SPACING - 2) : 0; + xRenderStart = gridStartRight ? (screenWidth - currentGirdWidth * BUTTON_SPACING - 1) : 0; - if (gridStartBottom) { - yRenderStart -= 4; - } - if (gridStartRight) { - xRenderStart += 3; - } - - // Set the last drawn area so recipe viewer knows where we are and we can move it out the way + // Set the last drawn area so recipe viewer knows where we are, and we can move it out the way lastDrawnArea = new Rect2i(getX(), getY(), width, height); } @@ -499,25 +497,25 @@ public static void drawGrid(GuiGraphics graphics, int x, int y, int width, int h drawGrid(graphics, x, y, width, height, spacing, spacing, backgroundColor, gridColor); } - private static void drawHoveredGrid(GuiGraphics graphics, int x, int y, int width, int height, int spacing, Color4I backgroundColor, Color4I gridColor, int mx, int my, boolean gridStartBottom, boolean gridStartRight, int posX, int posY) { + private static void drawHoveredGrid(GuiGraphics graphics, int x, int y, int width, int height, int spacing, Color4I backgroundColor, Color4I gridColor, int mx, int my, boolean gridStartBottom, boolean gridStartRight) { drawGrid(graphics, x, y, width, height, spacing, backgroundColor, gridColor); - int adjustedMx = mx; - int adjustedMy = my; + int adjustedMx = gridStartRight ? x + width * spacing - (mx - x) : mx; + int adjustedMy = gridStartBottom ? y + height * spacing - (my - y) : my; - if (gridStartRight) { - adjustedMx = x + width * spacing - (mx - x); - } + if (adjustedMx >= x && adjustedMy >= y && adjustedMx < x + width * spacing && adjustedMy < y + height * spacing) { + int gridX = (adjustedMx - x) / spacing; + int gridY = (adjustedMy - y) / spacing; - if (gridStartBottom) { - adjustedMy = y + height * spacing - (my - y); - } + if (gridStartRight) { + gridX = width - gridX - 1; + } - if (adjustedMx >= x + posX && adjustedMy >= y + posY && adjustedMx < x + posX + width * spacing && adjustedMy < y + posY + height * spacing) { - int gridX = (adjustedMx - x - posX) / spacing; - int gridY = (adjustedMy - y - posY) / spacing; - Color4I.WHITE.withAlpha(127).draw(graphics, gridX * BUTTON_SPACING + 1, gridY * BUTTON_SPACING + 1, spacing - 1, spacing - 1); + if (gridStartBottom) { + gridY = height - gridY - 1; + } + + Color4I.WHITE.withAlpha(127).draw(graphics, x + gridX * spacing + 1, y + gridY * spacing + 1, spacing - 1, spacing - 1); } } - } From 5715a0b2e6fe282a87ecf8366a07e262ccc568e1 Mon Sep 17 00:00:00 2001 From: UnRealDinnerbone Date: Fri, 9 Aug 2024 11:42:00 -0500 Subject: [PATCH 2/2] Fixed comments --- .../dev/ftb/mods/ftblibrary/sidebar/SidebarGroupGuiButton.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/src/main/java/dev/ftb/mods/ftblibrary/sidebar/SidebarGroupGuiButton.java b/common/src/main/java/dev/ftb/mods/ftblibrary/sidebar/SidebarGroupGuiButton.java index 0dc10fe1..ba46b454 100644 --- a/common/src/main/java/dev/ftb/mods/ftblibrary/sidebar/SidebarGroupGuiButton.java +++ b/common/src/main/java/dev/ftb/mods/ftblibrary/sidebar/SidebarGroupGuiButton.java @@ -379,7 +379,7 @@ private void updateWidgetSize() { // Calculates the renderStart values need for drawing the grid at the correct location // do to the fact the getX() and getY() change if is edit mode we want to make sure we are always // drawing the main grid at the correct location - // when starting from bottom or right, calculate the value max screen size of that axis + // when starting from bottom or right, calculate the value from the screen size of that axis // Subtracts are need to make gird align correctly yRenderStart = gridStartBottom ? (screenHeight - currentGridHeight * BUTTON_SPACING - 2) : 0; xRenderStart = gridStartRight ? (screenWidth - currentGirdWidth * BUTTON_SPACING - 1) : 0;