From b43f781ac491a7435226135bbcc33439c22f9807 Mon Sep 17 00:00:00 2001 From: Robert Maguire Date: Fri, 4 Oct 2024 20:53:36 -0500 Subject: [PATCH] Console now runs on the main menu --- .../org/lazywizard/console/BaseCommand.java | 14 ++++++++- .../org/lazywizard/console/CommandStore.java | 2 +- .../lazywizard/console/commands/SourceOf.java | 29 ++++++++++--------- .../org/lazywizard/console/ConsolePlugins.kt | 3 +- 4 files changed, 31 insertions(+), 17 deletions(-) diff --git a/src/main/java/org/lazywizard/console/BaseCommand.java b/src/main/java/org/lazywizard/console/BaseCommand.java index 25fa71d..f507692 100644 --- a/src/main/java/org/lazywizard/console/BaseCommand.java +++ b/src/main/java/org/lazywizard/console/BaseCommand.java @@ -88,7 +88,12 @@ enum CommandContext * * @since 2.0 */ - COMBAT_SIMULATION; + COMBAT_SIMULATION, + /** + * Command was entered on the main menu. + */ + // TODO: Add @since whenever I get around to untangling the version number mess + MAIN_MENU; /** * Returns whether this context is on the combat map. @@ -127,6 +132,13 @@ public boolean isInMarket() return (this == CAMPAIGN_MARKET); } + /** + * Returns whether the player is viewing the main menu. + * + * @return {@code true} if the player is at the main menu, {@code false} otherwise. + */ + public boolean isInMainMenu() { return (this == MAIN_MENU); } + /** * Returns whether the player is in campaign mode, including in campaign battles (even refit simulation * battles). diff --git a/src/main/java/org/lazywizard/console/CommandStore.java b/src/main/java/org/lazywizard/console/CommandStore.java index 75f9162..7d887ba 100644 --- a/src/main/java/org/lazywizard/console/CommandStore.java +++ b/src/main/java/org/lazywizard/console/CommandStore.java @@ -265,7 +265,7 @@ else if (context.isInCombat()) return tags.contains("combat") || (!tags.contains("campaign") && !tags.contains("market")); } - return true; + return !context.isInMainMenu(); } /** diff --git a/src/main/java/org/lazywizard/console/commands/SourceOf.java b/src/main/java/org/lazywizard/console/commands/SourceOf.java index d2f9e1d..798c86a 100644 --- a/src/main/java/org/lazywizard/console/commands/SourceOf.java +++ b/src/main/java/org/lazywizard/console/commands/SourceOf.java @@ -1,13 +1,13 @@ package org.lazywizard.console.commands; -import java.util.Collections; -import java.util.List; import org.lazywizard.console.BaseCommand; import org.lazywizard.console.CommandStore; import org.lazywizard.console.CommandStore.StoredCommand; import org.lazywizard.console.Console; -// TODO: Extend to cover ships/weapons/modspecs/commodities/etc +import java.util.Collections; +import java.util.List; + public class SourceOf implements BaseCommand { @Override @@ -18,29 +18,30 @@ public CommandResult runCommand(String args, CommandContext context) return CommandResult.BAD_SYNTAX; } - if ("all".equalsIgnoreCase(args)) + if ("all".equalsIgnoreCase(args) || "commands".equalsIgnoreCase(args)) { Console.showMessage("Loaded commands come from the following mods:"); - List allCommands = CommandStore.getLoadedCommands(); + final List allCommands = CommandStore.getLoadedCommands(); Collections.sort(allCommands, String.CASE_INSENSITIVE_ORDER); for (String tmp : allCommands) { - StoredCommand command = CommandStore.retrieveCommand(tmp); - Console.showMessage(" - "+ tmp + ": " + command.getSource()); + final StoredCommand command = CommandStore.retrieveCommand(tmp); + Console.showMessage(" - " + tmp + ": " + command.getSource()); } return CommandResult.SUCCESS; } - StoredCommand command = CommandStore.retrieveCommand(args); - if (command == null) + final StoredCommand command = CommandStore.retrieveCommand(args); + if (command != null) { - Console.showMessage("No command with the name '" + args + "' was found!"); - return CommandResult.ERROR; + Console.showMessage("Command '" + args + "' is from the following mod:\n" + + " - " + command.getSource()); + return CommandResult.SUCCESS; } - Console.showMessage("Command '" + args + "' is from the following mod:\n" - + " - " + command.getSource()); - return CommandResult.SUCCESS; + // TODO: Extend to cover ships/weapons/modspecs/commodities/classes/files/etc + Console.showMessage("No command with the name '" + args + "' was found!"); + return CommandResult.ERROR; } } diff --git a/src/main/kotlin/org/lazywizard/console/ConsolePlugins.kt b/src/main/kotlin/org/lazywizard/console/ConsolePlugins.kt index dbca330..2c665c6 100644 --- a/src/main/kotlin/org/lazywizard/console/ConsolePlugins.kt +++ b/src/main/kotlin/org/lazywizard/console/ConsolePlugins.kt @@ -64,7 +64,8 @@ internal class ConsoleCombatListener : BaseEveryFrameCombatPlugin(), ConsoleList context = when { engine.isSimulation -> CommandContext.COMBAT_SIMULATION engine.isInCampaign -> CommandContext.COMBAT_CAMPAIGN - else -> CommandContext.COMBAT_MISSION + engine.missionId != null -> CommandContext.COMBAT_MISSION + else -> CommandContext.MAIN_MENU } engine.customData["consolePlugin"] = this