Skip to content
This repository has been archived by the owner on Aug 8, 2024. It is now read-only.

Commit

Permalink
feat: Export favorites and waypoints from main menu (#696)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
ShadowCat117 authored Nov 18, 2023
1 parent 93739e0 commit 94ce153
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
13 changes: 12 additions & 1 deletion src/main/java/com/wynntils/modules/core/events/ClientEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<GuiButton> 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) {
Expand Down Expand Up @@ -64,6 +69,8 @@ public static void addButtons(GuiMainMenu to, List<GuiButton> buttonList, boolea
public static void actionPerformed(GuiMainMenu on, GuiButton button, List<GuiButton> buttonList) {
if (button.id == WYNNCRAFT_BUTTON_ID) {
clickedWynncraftButton(((WynncraftButton) button).serverIcon.getServer(), on);
} else if (button.id == EXPORT_BUTTON_ID) {
clickedExportButton();
}
}

Expand All @@ -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();
}
Expand Down
108 changes: 108 additions & 0 deletions src/main/java/com/wynntils/modules/core/overlays/ui/ExportScreen.java
Original file line number Diff line number Diff line change
@@ -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<String> lines = new ArrayList<String>() {{
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<String> 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/");
}
}
}

0 comments on commit 94ce153

Please sign in to comment.