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

Commit

Permalink
Revert UpdateAvailableScreen, add ExportScreen and button, only force…
Browse files Browse the repository at this point in the history
… show on first launch
  • Loading branch information
ShadowCat117 committed Nov 3, 2023
1 parent 493229a commit 5b18b97
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 35 deletions.
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, 20, 20, "!");
buttonList.add(exportButton);

if (!CoreDBConfig.INSTANCE.addMainMenuButton) return;

if (lastButton == null || !resize) {
Expand Down Expand Up @@ -64,13 +69,19 @@ 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();
}
}

private static void clickedWynncraftButton(ServerData server, GuiScreen backGui) {
McIf.mc().displayGuiScreen(new UpdateAvailableScreen(server));
}

private static void clickedExportButton() {
McIf.mc().displayGuiScreen(new ExportScreen());
}

private static boolean hasUpdate() {
return !Reference.developmentEnvironment && WebManager.getUpdate() != null && WebManager.getUpdate().hasUpdate();
}
Expand Down
102 changes: 102 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,102 @@
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;

public ExportScreen() {
line1 = "Wynncraft will be phasing out 1.12 by the end of this year.";
line2 = "We highly recommend updating to Artemis (1.20.2) as soon as you can.";
line3 = "Waypoints and favorites can be exported using the buttons below.";
}

@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);
}};

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 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/version/latest");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,12 @@

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.Reference;
import com.wynntils.core.utils.ServerUtils;
import com.wynntils.core.utils.Utils;
import com.wynntils.modules.core.CoreModule;
import com.wynntils.modules.core.config.CoreDBConfig;
import com.wynntils.modules.core.enums.UpdateStream;
import com.wynntils.modules.map.configs.MapConfig;
import com.wynntils.modules.map.instances.WaypointProfile;
import com.wynntils.modules.utilities.configs.UtilitiesConfig;
import com.wynntils.webapi.WebManager;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
Expand All @@ -28,32 +21,35 @@

public class UpdateAvailableScreen extends GuiScreen {

private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
private ServerData server;
private String line1;
private String line2;
private String line3;

public UpdateAvailableScreen(ServerData server) {
this.server = server;
line1 = "Wynncraft will be phasing out 1.12 by the end of this year.";
line2 = "We highly recommend updating to Artemis (1.20.2) as soon as you can.";
line3 = "Waypoints and favorites can be exported using the buttons below.";
line1 = "A new update is available " + TextFormatting.YELLOW + WebManager.getUpdate().getLatestUpdate();
if (WebManager.getUpdate().getDownloadMD5() != null) {
line1 += TextFormatting.GRAY + " (md5: " + TextFormatting.YELLOW + WebManager.getUpdate().getDownloadMD5() + TextFormatting.GRAY + ")";
}
line2 = "You are currently on " + TextFormatting.YELLOW + Reference.VERSION;
if (WebManager.getUpdate().getMd5Installed() != null) {
line2 += TextFormatting.GRAY + " (md5: " + TextFormatting.YELLOW + WebManager.getUpdate().getMd5Installed() + TextFormatting.GRAY + ")";
}
}

@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"));
this.buttonList.add(new GuiButton(0, this.width / 2 - 100, y, 200, 20, "View changelog"));
// 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"));
this.buttonList.add(new GuiButton(1, this.width / 2 - 100, y, 98, 20, "Update now"));
this.buttonList.add(new GuiButton(2, this.width / 2 + 2, y, 98, 20, "Update at exit"));
// row 3
y += spacing;
this.buttonList.add(new GuiButton(3, this.width / 2 - 100, y, 98, 20, "Continue"));
this.buttonList.add(new GuiButton(3, this.width / 2 - 100, y, 98, 20, "Ignore update"));
this.buttonList.add(new GuiButton(4, this.width / 2 + 2, y, 98, 20, "Cancel"));
}

Expand All @@ -64,7 +60,7 @@ public void drawScreen(int mouseX, int mouseY, float partialTicks) {
List<String> lines = new ArrayList<String>() {{
add(line1);
add(line2);
add(line3);
add("Update now or when leaving Minecraft?");
}};

int spacing = this.fontRenderer.FONT_HEIGHT + 2; // 11
Expand All @@ -85,13 +81,13 @@ public void drawScreen(int mouseX, int mouseY, float partialTicks) {
for (GuiButton button : buttonList) {
if (button.isMouseOver()) {
if (button.id == 0) {
drawHoveringText("Open a link to the Artemis Modrinth page", mouseX, mouseY);
drawHoveringText("View the changelog for this update", mouseX, mouseY);
} else if (button.id == 1) {
drawHoveringText("Copy your favorites to your clipboard", mouseX, mouseY);
drawHoveringText("Update now and exit Minecraft", mouseX, mouseY);
} else if (button.id == 2) {
drawHoveringText("Copy your waypoints to your clipboard", mouseX, mouseY);
drawHoveringText("Update when you exit Minecraft", mouseX, mouseY);
} else if (button.id == 3) {
drawHoveringText("Continue to Wynncraft", mouseX, mouseY);
drawHoveringText("Ignore this update", mouseX, mouseY);
} else if (button.id == 4) {
drawHoveringText("Cancel", mouseX, mouseY);
}
Expand All @@ -101,18 +97,12 @@ public void drawScreen(int mouseX, int mouseY, float partialTicks) {

@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));
if (button.id == 1 || button.id == 2) {
// Update
CoreDBConfig.INSTANCE.showChangelogs = true;
CoreDBConfig.INSTANCE.lastVersion = Reference.VERSION;
CoreDBConfig.INSTANCE.saveSettings(CoreModule.getModule());
McIf.mc().displayGuiScreen(new UpdatingScreen(button.id == 1));
} else if (button.id == 3) {
// Ignore
WebManager.skipJoinUpdate();
Expand All @@ -121,7 +111,9 @@ public void actionPerformed(GuiButton button) {
// Cancel
McIf.mc().displayGuiScreen(null);
} else if (button.id == 0) {
Utils.openUrl("https://modrinth.com/mod/wynntils/version/latest");
// View changelog
boolean major = CoreDBConfig.INSTANCE.updateStream == UpdateStream.STABLE;
ChangelogUI.loadChangelogAndShow(this, major);
}
}

Expand Down

0 comments on commit 5b18b97

Please sign in to comment.