From 94ce1537e27ab67a8534ee9fdf9f3040d51e2ac4 Mon Sep 17 00:00:00 2001 From: Jamie Date: Sat, 18 Nov 2023 11:48:16 +0000 Subject: [PATCH] feat: Export favorites and waypoints from main menu (#696) * feat: Export favorites and waypoints from update available screen * Revert UpdateAvailableScreen, add ExportScreen and button, only force show on first launch * fix: Don't always open UpdateAvailableScreen * chore: Change button text and export message * chore: Change modrinth link and remove 1.20.2 mention --- .../modules/core/config/CoreDBConfig.java | 3 + .../modules/core/events/ClientEvents.java | 13 ++- .../core/instances/MainMenuButtons.java | 11 ++ .../core/overlays/ui/ExportScreen.java | 108 ++++++++++++++++++ 4 files changed, 134 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/wynntils/modules/core/overlays/ui/ExportScreen.java diff --git a/src/main/java/com/wynntils/modules/core/config/CoreDBConfig.java b/src/main/java/com/wynntils/modules/core/config/CoreDBConfig.java index d3c1eee79..9e8f80327 100644 --- a/src/main/java/com/wynntils/modules/core/config/CoreDBConfig.java +++ b/src/main/java/com/wynntils/modules/core/config/CoreDBConfig.java @@ -47,6 +47,9 @@ public class CoreDBConfig extends SettingsClass { @Setting(upload = false) public String lastVersion = "0.0.0"; + @Setting(upload = false) + public boolean shownExportScreen = false; + @Setting(displayName = "Main Menu Wynncraft Button", description = "Should a button be added to the main menu that allows you to connect to Wynncraft directly?") public boolean addMainMenuButton = true; diff --git a/src/main/java/com/wynntils/modules/core/events/ClientEvents.java b/src/main/java/com/wynntils/modules/core/events/ClientEvents.java index ff0de7c33..60bcc6766 100644 --- a/src/main/java/com/wynntils/modules/core/events/ClientEvents.java +++ b/src/main/java/com/wynntils/modules/core/events/ClientEvents.java @@ -21,6 +21,8 @@ import com.wynntils.core.utils.objects.Location; import com.wynntils.core.utils.objects.TimedSet; import com.wynntils.core.utils.reflections.ReflectionFields; +import com.wynntils.modules.core.CoreModule; +import com.wynntils.modules.core.config.CoreDBConfig; import com.wynntils.modules.core.instances.GatheringBake; import com.wynntils.modules.core.instances.MainMenuButtons; import com.wynntils.modules.core.instances.TotemTracker; @@ -30,6 +32,8 @@ import com.wynntils.modules.core.overlays.inventories.HorseReplacer; import com.wynntils.modules.core.overlays.inventories.IngameMenuReplacer; import com.wynntils.modules.core.overlays.inventories.InventoryReplacer; +import com.wynntils.modules.core.overlays.ui.ExportScreen; +import com.wynntils.modules.core.overlays.ui.UpdateAvailableScreen; import com.wynntils.modules.utilities.UtilitiesModule; import com.wynntils.modules.utilities.configs.OverlayConfig; import com.wynntils.modules.utilities.instances.ShamanMaskType; @@ -456,7 +460,14 @@ public void addMainMenuButtons(GuiScreenEvent.InitGuiEvent.Post e) { if (gui instanceof GuiMainMenu) { boolean resize = lastScreen != null && lastScreen instanceof GuiMainMenu; - MainMenuButtons.addButtons((GuiMainMenu) gui, e.getButtonList(), resize); + + if (!CoreDBConfig.INSTANCE.shownExportScreen) { + McIf.mc().displayGuiScreen(new ExportScreen()); + CoreDBConfig.INSTANCE.shownExportScreen = true; + CoreDBConfig.INSTANCE.saveSettings(CoreModule.getModule()); + } else { + MainMenuButtons.addButtons((GuiMainMenu) gui, e.getButtonList(), resize); + } } lastScreen = gui; diff --git a/src/main/java/com/wynntils/modules/core/instances/MainMenuButtons.java b/src/main/java/com/wynntils/modules/core/instances/MainMenuButtons.java index c1131e987..f4ff2f58b 100644 --- a/src/main/java/com/wynntils/modules/core/instances/MainMenuButtons.java +++ b/src/main/java/com/wynntils/modules/core/instances/MainMenuButtons.java @@ -10,6 +10,7 @@ import com.wynntils.core.utils.ServerUtils; import com.wynntils.modules.core.config.CoreDBConfig; import com.wynntils.modules.core.overlays.UpdateOverlay; +import com.wynntils.modules.core.overlays.ui.ExportScreen; import com.wynntils.modules.core.overlays.ui.UpdateAvailableScreen; import com.wynntils.modules.utilities.instances.ServerIcon; import com.wynntils.webapi.WebManager; @@ -31,12 +32,16 @@ public class MainMenuButtons { private static ServerList serverList = null; private static final int WYNNCRAFT_BUTTON_ID = 3790627; + private static final int EXPORT_BUTTON_ID = 3790628; private static WynncraftButton lastButton = null; private static boolean alreadyLoaded = false; public static void addButtons(GuiMainMenu to, List buttonList, boolean resize) { + GuiButton exportButton = new GuiButton(EXPORT_BUTTON_ID, to.width / 2 + 104, to.height / 4 + 48 + 48, 100, 20, "§cExport to Artemis"); + buttonList.add(exportButton); + if (!CoreDBConfig.INSTANCE.addMainMenuButton) return; if (lastButton == null || !resize) { @@ -64,6 +69,8 @@ public static void addButtons(GuiMainMenu to, List buttonList, boolea public static void actionPerformed(GuiMainMenu on, GuiButton button, List buttonList) { if (button.id == WYNNCRAFT_BUTTON_ID) { clickedWynncraftButton(((WynncraftButton) button).serverIcon.getServer(), on); + } else if (button.id == EXPORT_BUTTON_ID) { + clickedExportButton(); } } @@ -76,6 +83,10 @@ private static void clickedWynncraftButton(ServerData server, GuiScreen backGui) } } + private static void clickedExportButton() { + McIf.mc().displayGuiScreen(new ExportScreen()); + } + private static boolean hasUpdate() { return !Reference.developmentEnvironment && WebManager.getUpdate() != null && WebManager.getUpdate().hasUpdate(); } diff --git a/src/main/java/com/wynntils/modules/core/overlays/ui/ExportScreen.java b/src/main/java/com/wynntils/modules/core/overlays/ui/ExportScreen.java new file mode 100644 index 000000000..ec4708a1e --- /dev/null +++ b/src/main/java/com/wynntils/modules/core/overlays/ui/ExportScreen.java @@ -0,0 +1,108 @@ +package com.wynntils.modules.core.overlays.ui; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonArray; +import com.wynntils.McIf; +import com.wynntils.core.utils.Utils; +import com.wynntils.modules.map.configs.MapConfig; +import com.wynntils.modules.map.instances.WaypointProfile; +import com.wynntils.modules.utilities.configs.UtilitiesConfig; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.GuiScreen; + +import java.util.ArrayList; +import java.util.List; + +public class ExportScreen extends GuiScreen { + private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create(); + private String line1; + private String line2; + private String line3; + private String line4; + private String line5; + + public ExportScreen() { + line1 = "Wynncraft will be phasing out 1.12 by the end of this year (2023)."; + line2 = "We highly recommend updating to Wynntils Artemis as soon as you can."; + line3 = "Waypoints and favorites can be exported using the buttons below."; + line4 = "This will save them to your clipboard, either save them to a text"; + line5 = "editor to import later or immediately import into Artemis."; + } + + @Override + public void initGui() { + int spacing = 24; + int y = this.height / 4 + 84; + // row 1 + this.buttonList.add(new GuiButton(0, this.width / 2 - 100, y, 200, 20, "Get Artemis")); + // row 2 + y += spacing; + this.buttonList.add(new GuiButton(1, this.width / 2 - 100, y, 98, 20, "Export Favorites")); + this.buttonList.add(new GuiButton(2, this.width / 2 + 2, y, 98, 20, "Export Waypoints")); + // row 3 + y += spacing; + this.buttonList.add(new GuiButton(3, this.width / 2 - 100, y, 200, 20, "Continue")); + } + + @Override + public void drawScreen(int mouseX, int mouseY, float partialTicks) { + drawDefaultBackground(); + + List lines = new ArrayList() {{ + add(line1); + add(line2); + add(line3); + add(line4); + add(line5); + }}; + + int spacing = this.fontRenderer.FONT_HEIGHT + 2; // 11 + int y = this.height / 4 + (84 - spacing * lines.size()); + + for (String line : lines) { + drawCenteredString(this.fontRenderer, line, this.width / 2, y, 0xFFFFFF); + y += spacing; + } + + // draw gui buttons + super.drawScreen(mouseX, mouseY, partialTicks); + + // Draw hover text + for (GuiButton button : buttonList) { + if (button.isMouseOver()) { + if (button.id == 0) { + drawHoveringText("Open a link to the Wynntils Artemis Modrinth page", mouseX, mouseY); + } else if (button.id == 1) { + drawHoveringText("Copy your favorites to your clipboard", mouseX, mouseY); + } else if (button.id == 2) { + drawHoveringText("Copy your waypoints to your clipboard", mouseX, mouseY); + } else if (button.id == 3) { + drawHoveringText("Continue to Wynncraft", mouseX, mouseY); + } + } + } + } + + @Override + public void actionPerformed(GuiButton button) { + if (button.id == 1) { + List combinedList = new ArrayList<>(); + combinedList.addAll(UtilitiesConfig.INSTANCE.favoriteItems); + combinedList.addAll(UtilitiesConfig.INSTANCE.favoriteIngredients); + combinedList.addAll(UtilitiesConfig.INSTANCE.favoritePowders); + combinedList.addAll(UtilitiesConfig.INSTANCE.favoriteEmeraldPouches); + + Utils.copyToClipboard("wynntilsFavorites," + String.join(",", combinedList)); + } else if (button.id == 2) { + JsonArray array = new JsonArray(); + MapConfig.Waypoints.INSTANCE.waypoints.stream().map(WaypointProfile::toArtemisObject).forEach(array::add); + Utils.copyToClipboard(GSON.toJson(array)); + } else if (button.id == 3) { + // Cancel + McIf.mc().displayGuiScreen(null); + } else if (button.id == 0) { + Utils.openUrl("https://modrinth.com/mod/wynntils/"); + } + } +}