Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rift Warp Menu #10

Merged
merged 10 commits into from
Feb 20, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Rift update rewrite
- Rewrite GUIs for easier maintainability
- Add additional checks for determining the currently open SB menu (incomplete)
- Finish rift layout
- Fix build fail when Crowdin doesn't download any strings
- Update Gradle to 8.5
ILikePlayingGames committed Jan 30, 2024
commit 86fdb719c1cbaa6e34ddd710a5b34860353b24ea
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -51,7 +51,7 @@ jobs:
CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_PROJECT_ID }}
CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }}
- name: Fix ownership of Gradle build directory
run: sudo chown -R $(whoami):$(id -gn) build
run: '[ -d build ] && sudo chown -R $(whoami):$(id -gn) build || echo "Skipped, build directory does not exist."'
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
39 changes: 16 additions & 23 deletions src/main/java/ca/tirelesstraveler/fancywarpmenu/FancyWarpMenu.java
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@

package ca.tirelesstraveler.fancywarpmenu;

import ca.tirelesstraveler.fancywarpmenu.commands.OpenConfigCommand;
import ca.tirelesstraveler.fancywarpmenu.data.layout.Island;
import ca.tirelesstraveler.fancywarpmenu.data.layout.Layout;
import ca.tirelesstraveler.fancywarpmenu.data.Settings;
@@ -30,6 +31,8 @@
import ca.tirelesstraveler.fancywarpmenu.listeners.SkyBlockJoinListener;
import ca.tirelesstraveler.fancywarpmenu.listeners.WarpMenuListener;
import ca.tirelesstraveler.fancywarpmenu.resourceloaders.SkyBlockConstantsLoader;
import ca.tirelesstraveler.fancywarpmenu.state.EnvironmentDetails;
import ca.tirelesstraveler.fancywarpmenu.state.FancyWarpMenuState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.client.resources.IReloadableResourceManager;
@@ -58,8 +61,6 @@ public class FancyWarpMenu {
private static String modId;
static Logger logger;
private static ForgeVersion.CheckResult updateCheckResult;
private static Layout layout;
private static Layout riftLayout;
private static SkyBlockConstants skyBlockConstants;
private static SkyBlockJoinListener skyblockJoinListener;
private static WarpMenuListener warpMenuListener;
@@ -72,7 +73,7 @@ public static FancyWarpMenu getInstance() {
@Mod.EventHandler
public void preInit(FMLPreInitializationEvent event) {
ProgressManager.ProgressBar bar = ProgressManager.push("Pre-init", 5);
EnvironmentDetails.deobfuscatedEnvironment = (Boolean) Launch.blackboard.get("fml.deobfuscatedEnvironment");
EnvironmentDetails.setDeobfuscatedEnvironment((Boolean) Launch.blackboard.get("fml.deobfuscatedEnvironment"));
modId = event.getModMetadata().modId;
modContainer = Loader.instance().activeModContainer();
bar.step("Initializing Listeners");
@@ -90,9 +91,9 @@ public void preInit(FMLPreInitializationEvent event) {
bar.step("Loading SkyBlock Constants");
skyBlockConstants = SkyBlockConstantsLoader.loadSkyBlockConstants();
bar.step("Loading Layout");
layout = LayoutLoader.loadLayout(LayoutLoader.LAYOUT_LOCATION);
FancyWarpMenuState.setOverworldLayout(LayoutLoader.loadLayout(LayoutLoader.OVERWORLD_LAYOUT_LOCATION));
bar.step("Loading Rift Layout");
riftLayout = LayoutLoader.loadLayout(LayoutLoader.RIFT_LAYOUT_LOCATION);
FancyWarpMenuState.setRiftLayout(LayoutLoader.loadLayout(LayoutLoader.RIFT_LAYOUT_LOCATION));
ProgressManager.pop(bar);
}

@@ -103,25 +104,25 @@ public void init(FMLInitializationEvent event) {
ClientRegistry.registerKeyBinding(keyBindingOpenWarpMenu);
ClientCommandHandler.instance.registerCommand(new OpenConfigCommand());

ProgressManager.ProgressBar bar = ProgressManager.push("Loading Textures", layout.getIslandList().size() + 1);
Layout overworldLayout = FancyWarpMenuState.getOverworldLayout();
ProgressManager.ProgressBar bar = ProgressManager.push("Loading Textures",
overworldLayout.getIslandList().size() + 1);
TextureManager textureManager = Minecraft.getMinecraft().getTextureManager();

for (Island island : layout.getIslandList()) {
for (Island island : overworldLayout.getIslandList()) {
bar.step(island.getName());
textureManager.bindTexture(island.getTextureLocation());
}

bar.step("Warp Icon");
textureManager.bindTexture(layout.getWarpIcon().getTextureLocation());
textureManager.bindTexture(overworldLayout.getWarpIcon().getTextureLocation());

ProgressManager.pop(bar);
}

@Mod.EventHandler
public void postInit(FMLPostInitializationEvent event) {
if (Loader.isModLoaded("patcher")) {
EnvironmentDetails.patcherInstalled = true;
}
EnvironmentDetails.setPatcherInstalled(Loader.isModLoaded("patcher"));
}

public ModContainer getModContainer() {
@@ -156,16 +157,16 @@ public void reloadSkyBlockConstants() {
}

public void reloadLayouts() {
Layout loadedLayout = LayoutLoader.loadLayout(LayoutLoader.LAYOUT_LOCATION);
Layout loadedOverworldLayout = LayoutLoader.loadLayout(LayoutLoader.OVERWORLD_LAYOUT_LOCATION);
Layout loadedRiftLayout = LayoutLoader.loadLayout(LayoutLoader.RIFT_LAYOUT_LOCATION);

// Will be null if json syntax is wrong or layout is invalid
if (loadedLayout != null) {
FancyWarpMenu.layout = loadedLayout;
if (loadedOverworldLayout != null) {
FancyWarpMenuState.setOverworldLayout(loadedOverworldLayout);
}

if (loadedRiftLayout != null) {
FancyWarpMenu.riftLayout = loadedRiftLayout;
FancyWarpMenuState.setRiftLayout(loadedRiftLayout);
}
}

@@ -180,14 +181,6 @@ public static KeyBinding getKeyBindingOpenWarpMenu() {
return keyBindingOpenWarpMenu;
}

public static Layout getLayout() {
return layout;
}

public static Layout getRiftLayout() {
return riftLayout;
}

public static SkyBlockConstants getSkyBlockConstants() {
return skyBlockConstants;
}
Original file line number Diff line number Diff line change
@@ -20,8 +20,9 @@
* OR OTHER DEALINGS IN THE SOFTWARE.
*/

package ca.tirelesstraveler.fancywarpmenu;
package ca.tirelesstraveler.fancywarpmenu.commands;

import ca.tirelesstraveler.fancywarpmenu.state.FancyWarpMenuState;
import net.minecraft.command.CommandBase;
import net.minecraft.command.ICommandSender;

@@ -48,6 +49,6 @@ public String getCommandUsage(ICommandSender sender) {
*/
@Override
public void processCommand(ICommandSender sender, String[] args) {
FancyWarpMenu.getInstance().getWarpMenuListener().onOpenConfigMenuCommand();
FancyWarpMenuState.setOpenConfigMenuRequested(true);
}
}
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@

package ca.tirelesstraveler.fancywarpmenu.data;

import ca.tirelesstraveler.fancywarpmenu.EnvironmentDetails;
import ca.tirelesstraveler.fancywarpmenu.state.EnvironmentDetails;
import ca.tirelesstraveler.fancywarpmenu.FancyWarpMenu;
import ca.tirelesstraveler.fancywarpmenu.gui.FancyWarpMenuConfigScreen;
import net.minecraft.util.EnumChatFormatting;
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.util.ResourceLocation;

import static ca.tirelesstraveler.fancywarpmenu.data.DataCommon.gson;
import static ca.tirelesstraveler.fancywarpmenu.resourceloaders.ResourceLoader.gson;

/**
* Class that holds the settings for drawing buttons that are not islands, like the config button.
@@ -35,19 +35,19 @@
@SuppressWarnings("unused")
public abstract class Button {

/** x-coordinate on {@link ca.tirelesstraveler.fancywarpmenu.gui.GuiFancyWarp} to draw the config button at (0-{@link Island#GRID_UNIT_WIDTH_FACTOR}) */
/** x-coordinate on {@link ca.tirelesstraveler.fancywarpmenu.gui.GuiFancyWarp} to draw the button at (0-{@link Island#GRID_UNIT_WIDTH_FACTOR}) */
private int gridX;
/** y-coordinate on {@link ca.tirelesstraveler.fancywarpmenu.gui.GuiFancyWarp} to draw the config button at (0-{@link Island#GRID_UNIT_HEIGHT_FACTOR}) */
/** y-coordinate on {@link ca.tirelesstraveler.fancywarpmenu.gui.GuiFancyWarp} to draw the button at (0-{@link Island#GRID_UNIT_HEIGHT_FACTOR}) */
private int gridY;
/** Width to render the config button texture at as a percentage of the screen width. Texture height is set automatically. */
/** Width to render the button texture at as a percentage of the screen width. Texture height is set automatically. */
private float widthPercentage;
/** Width of the warp icon texture, used to set the width of the warp button */
/** Width of the icon texture in pixels, used to set the width of the button */
private transient int textureWidth;
/** Height of the warp icon texture, used to set the height of the warp button */
/** Height of the icon texture in pixels, used to set the height of the button */
private transient int textureHeight;
/** Width of the config button */
/** Width of the button in pixels */
private transient int width;
/** Height of the config button */
/** Height of the button in pixels */
private transient int height;

Button(){}
@@ -75,7 +75,7 @@ public int getHeight() {
}

/**
* Initialize config button width and height.
* Initialize button width and height.
* This should be called in {@link GuiScreen#initGui()}.
*/
public void init(ScaledResolution res) {
@@ -103,8 +103,9 @@ public static void validateButtonIcon(Button button) throws IllegalArgumentExcep
throw new IllegalArgumentException("Button gridX must be between 0 and " + Island.GRID_UNIT_HEIGHT_FACTOR + " inclusive");
}

if (button.widthPercentage < 0 || button.widthPercentage > 1) {
throw new IllegalArgumentException("Button icon widthPercentage must be between 0 and 1");
// A button width of zero causes a stack overflow
if (button.widthPercentage <= 0 || button.widthPercentage > 1) {
throw new IllegalArgumentException("Button icon widthPercentage must be within the interval (0,1]");
}
}
}
Original file line number Diff line number Diff line change
@@ -32,7 +32,7 @@
import java.io.IOException;
import java.util.List;

import static ca.tirelesstraveler.fancywarpmenu.data.DataCommon.gson;
import static ca.tirelesstraveler.fancywarpmenu.resourceloaders.ResourceLoader.gson;

/**
* Island data used to create the island buttons on the GUI
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@

import java.util.List;

import static ca.tirelesstraveler.fancywarpmenu.data.DataCommon.gson;
import static ca.tirelesstraveler.fancywarpmenu.resourceloaders.ResourceLoader.gson;

@SuppressWarnings("unused")
public class Layout {
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StringUtils;

import static ca.tirelesstraveler.fancywarpmenu.data.DataCommon.gson;
import static ca.tirelesstraveler.fancywarpmenu.resourceloaders.ResourceLoader.gson;

/**
* Warp entry data used to create the warp buttons on the GUI
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@

import java.io.IOException;

import static ca.tirelesstraveler.fancywarpmenu.data.DataCommon.gson;
import static ca.tirelesstraveler.fancywarpmenu.resourceloaders.ResourceLoader.gson;

/**
* Class that holds the settings for drawing the warp icon (portal)
Original file line number Diff line number Diff line change
@@ -22,24 +22,35 @@

package ca.tirelesstraveler.fancywarpmenu.data.skyblockconstants;

import ca.tirelesstraveler.fancywarpmenu.data.skyblockconstants.menu.Menu;
import ca.tirelesstraveler.fancywarpmenu.data.skyblockconstants.menu.matchconditions.MenuMatchCondition;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;

import java.util.List;
import java.util.Map;

import static ca.tirelesstraveler.fancywarpmenu.data.DataCommon.gson;
import static ca.tirelesstraveler.fancywarpmenu.resourceloaders.ResourceLoader.gson;

@SuppressWarnings("unused")
public class SkyBlockConstants {
private SkyBlockConstants() {
}

/** A map with SkyBlock menus as keys and lists of conditions used to identify them as values */
private Map<Menu, List<MenuMatchCondition>> menuMatchingMap;

/** Chat messages sent by the server when a warp attempt succeeds or fails */
private WarpMessages warpMessages;
/** Names of the warp command and its aliases */
private List<WarpCommandVariant> warpCommandVariants;
/** Chat messages are checked to see if they start with this string in order to see if the player joined SkyBlock */
private String skyBlockJoinMessage;

public Map<Menu, List<MenuMatchCondition>> getMenuMatchingMap() {
return menuMatchingMap;
}

public WarpMessages getWarpMessages() {
return warpMessages;
}
@@ -62,6 +73,14 @@ public static void validateSkyBlockConstants(SkyBlockConstants skyBlockConstants
throw new NullPointerException("SkyBlock constants cannot be null");
}

for(Map.Entry<Menu, List<MenuMatchCondition>> menuMatchingMapEntry : skyBlockConstants.menuMatchingMap.entrySet()) {
List<MenuMatchCondition> matchConditions = getMenuMatchConditions(menuMatchingMapEntry);

for (MenuMatchCondition menuMatchCondition : matchConditions) {
menuMatchCondition.validateCondition();
}
}

WarpMessages.validateWarpMessages(skyBlockConstants.getWarpMessages());

if (skyBlockConstants.warpCommandVariants == null || skyBlockConstants.warpCommandVariants.isEmpty()) {
@@ -76,4 +95,18 @@ public static void validateSkyBlockConstants(SkyBlockConstants skyBlockConstants
throw new IllegalArgumentException("SkyBlock join message cannot be null or empty.");
}
}

@NotNull
private static List<MenuMatchCondition> getMenuMatchConditions(Map.Entry<Menu, List<MenuMatchCondition>> menuMatchingMapEntry) {
List<MenuMatchCondition> matchConditions = menuMatchingMapEntry.getValue();

if (matchConditions == null) {
throw new NullPointerException(String.format("Menu %s's menu match conditions list cannot be null",
menuMatchingMapEntry.getKey().name()));
} else if (matchConditions.isEmpty()) {
throw new IllegalArgumentException(String.format("Menu %s's menu match conditions list cannot be empty",
menuMatchingMapEntry.getKey().name()));
}
return matchConditions;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023. TirelessTraveler
* Copyright (c) 2023-2024. TirelessTraveler
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -20,25 +20,15 @@
* OR OTHER DEALINGS IN THE SOFTWARE.
*/

package ca.tirelesstraveler.fancywarpmenu.data.skyblockconstants;
package ca.tirelesstraveler.fancywarpmenu.data.skyblockconstants.menu;

/**
* In-game menus, not serialized
*/
public enum Menu {
/** Value used when player is not in a menu or in an unknown or irrelevant menu */
NONE("None"),
SKYBLOCK_MENU("SkyBlock Menu"),
FAST_TRAVEL("Fast Travel"),
PORHTAL("Porhtal");

/** Title of menu as it appears on the top of the {@code GuiChest}*/
private final String MENU_TITLE;
Menu(String menuTitle) {
MENU_TITLE = menuTitle;
}

public String getMenuTitle() {
return MENU_TITLE;
}
NONE,
SKYBLOCK_MENU,
FAST_TRAVEL,
PORHTAL
}
Loading