From f6ba429409ac73ee45992fd80e527c96b39e52e3 Mon Sep 17 00:00:00 2001 From: Kevinthegreat <92656833+kevinthegreat1@users.noreply.github.com> Date: Sun, 4 Feb 2024 17:35:52 -0500 Subject: Add waypoint deleting --- .../skyblock/waypoint/WaypointsListWidget.java | 56 ++++++++++++++++------ .../skyblock/waypoint/WaypointsScreen.java | 5 +- 2 files changed, 44 insertions(+), 17 deletions(-) (limited to 'src/main/java/de/hysky/skyblocker/skyblock/waypoint') diff --git a/src/main/java/de/hysky/skyblocker/skyblock/waypoint/WaypointsListWidget.java b/src/main/java/de/hysky/skyblocker/skyblock/waypoint/WaypointsListWidget.java index 22d3e2bb..7a01a494 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/waypoint/WaypointsListWidget.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/waypoint/WaypointsListWidget.java @@ -1,5 +1,6 @@ package de.hysky.skyblocker.skyblock.waypoint; +import de.hysky.skyblocker.debug.Debug; import de.hysky.skyblocker.utils.Utils; import de.hysky.skyblocker.utils.waypoint.NamedWaypoint; import de.hysky.skyblocker.utils.waypoint.WaypointCategory; @@ -37,6 +38,16 @@ public class WaypointsListWidget extends ElementListWidget getCategory() { if (getSelectedOrNull() instanceof WaypointCategoryEntry category) { return Optional.of(category); @@ -65,21 +76,17 @@ public class WaypointsListWidget extends ElementListWidget { - @Override - public boolean mouseClicked(double mouseX, double mouseY, int button) { - super.mouseClicked(mouseX, mouseY, button); - return true; - } } protected class WaypointCategoryEntry extends AbstractWaypointEntry { private final WaypointCategory category; private final List children; private final ButtonWidget buttonNewWaypoint; + private final ButtonWidget buttonDelete; public WaypointCategoryEntry() { this(new WaypointCategory("New Category", island, new ArrayList<>())); @@ -94,14 +101,22 @@ public class WaypointsListWidget extends ElementListWidget { + int entryIndex = WaypointsListWidget.this.children().indexOf(this) + 1; + while (entryIndex < WaypointsListWidget.this.children().size() && !(WaypointsListWidget.this.children().get(entryIndex) instanceof WaypointCategoryEntry)) { + WaypointsListWidget.this.children().remove(entryIndex); + } + WaypointsListWidget.this.children().remove(this); + waypoints.remove(category); + }).width(50).build(); + children = List.of(buttonNewWaypoint, buttonDelete); } @Override @@ -116,15 +131,19 @@ public class WaypointsListWidget extends ElementListWidget children; + private final ButtonWidget buttonDelete; public WaypointEntry(WaypointCategoryEntry category) { this(category, new NamedWaypoint(BlockPos.ORIGIN, "New Waypoint", new float[]{0f, 1f, 0f})); @@ -133,24 +152,31 @@ public class WaypointsListWidget extends ElementListWidget { + category.category.waypoints().remove(waypoint); + WaypointsListWidget.this.children().remove(this); + }).width(50).build(); + children = List.of(buttonDelete); } @Override public List selectableChildren() { - return List.of(); + return children; } @Override public List children() { - return List.of(); + return children; } @Override public void render(DrawContext context, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) { context.drawTextWithShadow(client.textRenderer, waypoint.getName(), width / 2 - 125, y + 5, 0xFFFFFF); - context.drawTextWithShadow(client.textRenderer, waypoint.pos.toString(), width / 2 - 50, y + 5, 0xFFFFFF); + context.drawTextWithShadow(client.textRenderer, waypoint.pos.toShortString(), width / 2 - 25, y + 5, 0xFFFFFF); float[] colorComponents = waypoint.getColorComponents(); - context.drawTextWithShadow(client.textRenderer, String.format("#%02X%02X%02X", (int) (colorComponents[0] * 255), (int) (colorComponents[1] * 255), (int) (colorComponents[2] * 255)), width / 2 + 10, y + 5, 0xFFFFFF); + context.drawTextWithShadow(client.textRenderer, String.format("#%02X%02X%02X", (int) (colorComponents[0] * 255), (int) (colorComponents[1] * 255), (int) (colorComponents[2] * 255)), width / 2 + 25, y + 5, 0xFFFFFF); + buttonDelete.setPosition(x + entryWidth - 54, y); + buttonDelete.render(context, mouseX, mouseY, tickDelta); } } } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/waypoint/WaypointsScreen.java b/src/main/java/de/hysky/skyblocker/skyblock/waypoint/WaypointsScreen.java index 4f760995..9f82f7a2 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/waypoint/WaypointsScreen.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/waypoint/WaypointsScreen.java @@ -13,7 +13,7 @@ import net.minecraft.text.Text; public class WaypointsScreen extends Screen { private final Screen parent; - final Multimap waypoints = MultimapBuilder.hashKeys().arrayListValues().build(Waypoints.waypoints); // TODO deep copy + final Multimap waypoints = MultimapBuilder.hashKeys().arrayListValues().build(); private WaypointsListWidget waypointsListWidget; private ButtonWidget buttonNew; private ButtonWidget buttonDone; @@ -25,12 +25,13 @@ public class WaypointsScreen extends Screen { public WaypointsScreen(Screen parent) { super(Text.translatable("skyblocker.waypoints.config")); this.parent = parent; + Waypoints.waypoints.forEach((island, category) -> waypoints.put(island, new WaypointCategory(category))); } @Override protected void init() { super.init(); - waypointsListWidget = addDrawableChild(new WaypointsListWidget(client, this, width, height - 96, 32, 25)); + waypointsListWidget = addDrawableChild(new WaypointsListWidget(client, this, width, height - 96, 32, 24)); GridWidget gridWidget = new GridWidget(); gridWidget.getMainPositioner().marginX(5).marginY(2); GridWidget.Adder adder = gridWidget.createAdder(2); -- cgit