From da74c0a76bd42ec92b45516c83d34e28d575833c Mon Sep 17 00:00:00 2001 From: UnRealDinnerbone Date: Tue, 13 Aug 2024 09:21:19 -0500 Subject: [PATCH] Fix Collapse and Expand buttons in Waypoint Edit screen --- .../client/gui/WaypointEditorScreen.java | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/common/src/main/java/dev/ftb/mods/ftbchunks/client/gui/WaypointEditorScreen.java b/common/src/main/java/dev/ftb/mods/ftbchunks/client/gui/WaypointEditorScreen.java index 3e424a00..2b399320 100644 --- a/common/src/main/java/dev/ftb/mods/ftbchunks/client/gui/WaypointEditorScreen.java +++ b/common/src/main/java/dev/ftb/mods/ftbchunks/client/gui/WaypointEditorScreen.java @@ -1,5 +1,6 @@ package dev.ftb.mods.ftbchunks.client.gui; +import com.mojang.blaze3d.platform.InputConstants; import dev.architectury.networking.NetworkManager; import dev.ftb.mods.ftbchunks.client.map.MapManager; import dev.ftb.mods.ftbchunks.client.map.WaypointImpl; @@ -51,12 +52,17 @@ public WaypointEditorScreen() { } buttonExpandAll = new SimpleButton(topPanel, List.of(Component.translatable("gui.expand_all"), hotkeyTooltip("="), hotkeyTooltip("+")), Icons.UP, - (widget, button) -> toggleAll(false)); - buttonCollapseAll = new SimpleButton(topPanel, List.of(Component.translatable("gui.collapse_all"), hotkeyTooltip("-")), Icons.DOWN, (widget, button) -> toggleAll(true)); + buttonCollapseAll = new SimpleButton(topPanel, List.of(Component.translatable("gui.collapse_all"), hotkeyTooltip("-")), Icons.DOWN, + (widget, button) -> toggleAll(false)); } private void toggleAll(boolean collapsed) { + boolean allOpen = this.collapsed.values().stream().noneMatch(b -> b); + //Don't try and re-render if everything is already open + if (allOpen && !collapsed) { + return; + } this.collapsed.keySet().forEach(levelResourceKey -> this.collapsed.put(levelResourceKey, collapsed)); scrollBar.setValue(0); getGui().refreshWidgets(); @@ -77,6 +83,19 @@ public boolean onInit() { return true; } + @Override + public boolean keyPressed(Key key) { + if (super.keyPressed(key)) { + return true; + } else if (key.is(InputConstants.KEY_ADD) || key.is(InputConstants.KEY_EQUALS)) { + toggleAll(false); + } else if (key.is(InputConstants.KEY_MINUS) || key.is(GLFW.GLFW_KEY_KP_SUBTRACT)) { + toggleAll(true); + } + return false; + } + + @Override protected int getTopPanelHeight() { return 22; @@ -238,7 +257,7 @@ public void setWidth(int newWidth) { distField.setPos(hideButton.getPosX() - 5 - distField.width, yOff); nameField.setPos(5, yOff); - nameField.setText(ClientTextComponentUtils.ellipsize(getTheme().getFont(), Component.literal(wp.getName()),distField.getPosX() - 5).getString()); + nameField.setText(ClientTextComponentUtils.ellipsize(getTheme().getFont(), Component.literal(wp.getName()), distField.getPosX() - 5).getString()); nameField.setHeight(getTheme().getFontHeight() + 2); } }