From 6522f8a022f605638abd01396a772c4e3f72cda3 Mon Sep 17 00:00:00 2001 From: Scoppio Date: Tue, 26 Nov 2024 01:20:20 -0300 Subject: [PATCH 1/2] feat: Allows GM to control any bot in the game --- megamek/src/megamek/client/ui/swing/MapMenu.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/megamek/src/megamek/client/ui/swing/MapMenu.java b/megamek/src/megamek/client/ui/swing/MapMenu.java index 6bae3128378..4e19b7b0d03 100644 --- a/megamek/src/megamek/client/ui/swing/MapMenu.java +++ b/megamek/src/megamek/client/ui/swing/MapMenu.java @@ -415,9 +415,11 @@ private JMenu createSpecialHexDisplayMenu() { */ private JMenu createPleaToRoyaltyMenu() { JMenu menu = new JMenu(Messages.getString("Bot.commands.title")); - + var isGM = client.getLocalPlayer().isGameMaster(); for (var player : client.getGame().getPlayersList()) { - if (!player.isEnemyOf(client.getLocalPlayer()) && player.isBot()) { + var isEnemy = player.isEnemyOf(client.getLocalPlayer()); + var playerIsBot = player.isBot(); + if (playerIsBot && (!isEnemy || isGM)) { menu.add(createBotCommands(player)); } } @@ -425,7 +427,7 @@ private JMenu createPleaToRoyaltyMenu() { } private JMenu createBotCommands(Player bot) { - JMenu menu = new JMenu(bot.getName()); + JMenu menu = new JMenu(bot.getName() + " (" + Player.TEAM_NAMES[bot.getTeam()] + ")"); JMenu targetHexMenu = new JMenu(Messages.getString("Bot.commands.targetHex")); JMenu prioritizeTargetUnitMenu = new JMenu(Messages.getString("Bot.commands.priority")); From 58eafea69d2f2e4c6334dc2f61d1dc6f70b50abb Mon Sep 17 00:00:00 2001 From: Scoppio Date: Tue, 26 Nov 2024 01:53:40 -0300 Subject: [PATCH 2/2] fix: fixed error with bot flee menu lacking the cardinal direction --- .../src/megamek/client/ui/swing/MapMenu.java | 47 +++++++++++-------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/megamek/src/megamek/client/ui/swing/MapMenu.java b/megamek/src/megamek/client/ui/swing/MapMenu.java index 4e19b7b0d03..84a8baf6554 100644 --- a/megamek/src/megamek/client/ui/swing/MapMenu.java +++ b/megamek/src/megamek/client/ui/swing/MapMenu.java @@ -29,6 +29,7 @@ import javax.swing.*; import megamek.client.Client; +import megamek.client.bot.princess.CardinalEdge; import megamek.client.event.BoardViewEvent; import megamek.client.ui.Messages; import megamek.client.ui.swing.gmCommands.GamemasterCommandPanel; @@ -432,13 +433,9 @@ private JMenu createBotCommands(Player bot) { JMenu targetHexMenu = new JMenu(Messages.getString("Bot.commands.targetHex")); JMenu prioritizeTargetUnitMenu = new JMenu(Messages.getString("Bot.commands.priority")); JMenu ignoreTargetMenu= new JMenu(Messages.getString("Bot.commands.ignore")); - - JMenu fleeMenu = new JMenu(Messages.getString("Bot.commands.flee")); + JMenu fleeMenu = createFleeMenu(bot); JMenu behaviorMenu = createBehaviorMenu(bot); - - behaviorMenu.add(createBehaviorMenu(bot)); - fleeMenu.add(createFleeMenu(bot)); targetHexMenu.add(createTargetHexMenuItem(bot)); menu.add(targetHexMenu); @@ -567,23 +564,33 @@ JMenu createCautionMenu(Player bot) { } - JMenuItem createFleeMenu(Player bot) { - JMenuItem item = new JMenuItem(Messages.getString("Bot.commands.flee.text")); - item.addActionListener(evt -> { - int confirm = JOptionPane.showConfirmDialog( - gui.getFrame(), - Messages.getString("Bot.commands.flee.confirmation", bot.getName()), - Messages.getString("Bot.commands.flee.confirm"), - JOptionPane.YES_NO_OPTION); + JMenu createFleeMenu(Player bot) { + JMenu menu = new JMenu(Messages.getString("Bot.commands.flee")); + menu.add(setFleeAction(new JMenuItem(Messages.getString("BotConfigDialog.northEdge")), bot, CardinalEdge.NORTH)); + menu.add(setFleeAction(new JMenuItem(Messages.getString("BotConfigDialog.southEdge")), bot, CardinalEdge.SOUTH)); + menu.add(setFleeAction(new JMenuItem(Messages.getString("BotConfigDialog.westEdge")), bot, CardinalEdge.WEST)); + menu.add(setFleeAction(new JMenuItem(Messages.getString("BotConfigDialog.eastEdge")), bot, CardinalEdge.EAST)); + menu.add(setFleeAction(new JMenuItem(Messages.getString("BotConfigDialog.nearestEdge")), bot, CardinalEdge.NEAREST)); + return menu; + } - if (confirm == JOptionPane.YES_OPTION) { - client.sendChat(String.format("%s: flee", - bot.getName() - )); - } + private JMenuItem setFleeAction(JMenuItem fleeMenuItem, Player bot, CardinalEdge cardinalEdge) { + fleeMenuItem.addActionListener(evt -> { + int confirm = JOptionPane.showConfirmDialog( + gui.getFrame(), + Messages.getString("Bot.commands.flee.confirmation", bot.getName()), + Messages.getString("Bot.commands.flee.confirm"), + JOptionPane.YES_NO_OPTION); + + if (confirm == JOptionPane.YES_OPTION) { + client.sendChat(String.format("%s: flee : %d", + bot.getName(), + cardinalEdge.getIndex() + )); } - ); - return item; + }); + + return fleeMenuItem; } JMenuItem createIgnoreTargetUnitMenu(Player bot, Entity entity) {