Skip to content

Commit

Permalink
Add Ability to Toggle Fancy UI with Command
Browse files Browse the repository at this point in the history
- Toggle Fancy UI with `/fwm on` and `/fwm off`
- Use `/fwm` to open mod settings
- Fix error spam due to InventoryChangeListener not being removed when GuiFancyWarp stops initialization due to an error
- Fix version missing warning from Forge on startup
- Bump version to v2.0-beta.1
  • Loading branch information
ILikePlayingGames committed May 21, 2024
1 parent 6dbb3ae commit a8aab6c
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 11 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ tasks.processResources {
inputs.property("mcversion", mcVersion)
inputs.property("modid", modid)

filesMatching("mcmod.info") {
filesMatching(arrayListOf("mcmod.info", "version.properties")) {
expand(inputs.properties)
}

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ org.gradle.jvmargs=-Xmx2g
baseGroup = ca.tirelesstraveler
mcVersion = 1.8.9
modid = fancywarpmenu
version = 2.0
version = 2.0-beta.1
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

package ca.tirelesstraveler.fancywarpmenu;

import ca.tirelesstraveler.fancywarpmenu.commands.OpenConfigCommand;
import ca.tirelesstraveler.fancywarpmenu.commands.FancyWarpMenuCommand;
import ca.tirelesstraveler.fancywarpmenu.data.layout.Island;
import ca.tirelesstraveler.fancywarpmenu.data.layout.Layout;
import ca.tirelesstraveler.fancywarpmenu.data.Settings;
Expand Down Expand Up @@ -103,7 +103,7 @@ public void init(FMLInitializationEvent event) {
updateCheckResult = ForgeVersion.getResult(modContainer);
keyBindingOpenWarpMenu = new KeyBinding("fancywarpmenu.key.openMenu", Keyboard.KEY_C, "fancywarpmenu.key.categories.fancyWarpMenu");
ClientRegistry.registerKeyBinding(keyBindingOpenWarpMenu);
ClientCommandHandler.instance.registerCommand(new OpenConfigCommand());
ClientCommandHandler.instance.registerCommand(new FancyWarpMenuCommand());

Layout overworldLayout = FancyWarpMenuState.getOverworldLayout();
ProgressManager.ProgressBar bar = ProgressManager.push("Loading Textures",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,33 @@

package ca.tirelesstraveler.fancywarpmenu.commands;

import ca.tirelesstraveler.fancywarpmenu.data.Settings;
import ca.tirelesstraveler.fancywarpmenu.state.FancyWarpMenuState;
import net.minecraft.command.CommandBase;
import net.minecraft.command.ICommandSender;
import ca.tirelesstraveler.fancywarpmenu.utils.ChatUtils;
import net.minecraft.command.*;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.util.ChatStyle;
import net.minecraft.util.EnumChatFormatting;

import java.util.Collections;
import java.util.List;

public class OpenConfigCommand extends CommandBase {
/**
* This is the main command of the mod.<br>
* <bold>Syntax</bold><br>
* <ul>
* <li>/fancywarpmenu &lt;args&gt;</li>
* <li>/fwm &lt;args&gt;</li>
* </ul>
* <br>
* <bold>Arguments</bold>
* <ul>
* <li>(empty) - Open mod config menu</li>
* <li>"on" or "1" - Enable Fancy Warp Menu</li>
* <li>"off" or "0" - Disable Fancy Warp Menu</li>
* </ul>
*/
public class FancyWarpMenuCommand extends CommandBase {
@Override
public int getRequiredPermissionLevel() {
return 0;
Expand All @@ -42,7 +61,7 @@ public List<String> getCommandAliases() {

@Override
public String getCommandName() {
return "fancywarpmenuconfig";
return "fancywarpmenu";
}

@Override
Expand All @@ -56,7 +75,28 @@ public String getCommandUsage(ICommandSender sender) {
* The {@link net.minecraftforge.event.CommandEvent} is intercepted instead to prevent the screen from being closed.
*/
@Override
public void processCommand(ICommandSender sender, String[] args) {
FancyWarpMenuState.setOpenConfigMenuRequested(true);
public void processCommand(ICommandSender sender, String[] args) throws CommandException {
if (args.length > 0) {
switch (args[0]) {
case "1":
case "on":
Settings.setWarpMenuEnabled(true);
ChatUtils.sendMessageWithModNamePrefix(
new ChatComponentTranslation("fancywarpmenu.messages.fancyWarpMenuEnabled")
.setChatStyle(new ChatStyle().setColor(EnumChatFormatting.GREEN)));
break;
case "0":
case "off":
Settings.setWarpMenuEnabled(false);
ChatUtils.sendMessageWithModNamePrefix(
new ChatComponentTranslation("fancywarpmenu.messages.fancyWarpMenuDisabled")
.setChatStyle(new ChatStyle().setColor(EnumChatFormatting.RED)));
break;
default:
throw new SyntaxErrorException();
}
} else {
FancyWarpMenuState.setOpenConfigMenuRequested(true);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ public void initGui() {
inventoryTooSmallMessageTranslationKey, chestInventory.getSizeInventory(), lastSlotIndexToCheck)
.setChatStyle(new ChatStyle().setColor(EnumChatFormatting.RED)));
setCustomUIState(false, false);
chestInventory.removeInventoryChangeListener(inventoryListener);
return;
}

Expand All @@ -143,6 +144,7 @@ public void initGui() {
} catch (RuntimeException e) {
guiInitException = e;
buttonList.clear();
chestInventory.removeInventoryChangeListener(inventoryListener);

int lineCount = 2;
int labelX = 0;
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/fancywarpmenu/lang/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ fancywarpmenu.key.categories.fancyWarpMenu=Fancy Warp Menu

fancywarpmenu.messages.useWarpMenuInsteadOfCommand=Reminder to use the Fancy Warp Menu instead!
fancywarpmenu.messages.fancyWarpMenuEnabled=Fancy Warp Menu Enabled
fancywarpmenu.messages.fancyWarpMenuDisabled=Fancy Warp Menu Disabled

fancywarpmenu.errors.notUnlocked=Not Unlocked
fancywarpmenu.errors.unknownDestination=Unknown Destination
Expand Down
25 changes: 25 additions & 0 deletions src/main/resources/version.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#
# Copyright (c) 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
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
# OR OTHER DEALINGS IN THE SOFTWARE.
#

# Forge expects a mod version in the main mod class or in this file, otherwise it logs a warning on startup.
# suppress inspection "UnusedProperty"
fancywarpmenu.version = ${version}
2 changes: 1 addition & 1 deletion version/update.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"homepage": "https://github.com/ILikePlayingGames/FancyWarpMenu/releases",
"promos": {
"1.8.9-recommended": "1.0",
"1.8.9-latest": "1.0"
"1.8.9-latest": "2.0-beta.1"
},
"1.8.9": {
"1.0": "New textures and additional language support",
Expand Down

0 comments on commit a8aab6c

Please sign in to comment.