Skip to content

Commit

Permalink
feat: commands need a second pass for test and eval
Browse files Browse the repository at this point in the history
  • Loading branch information
Scoppio committed Nov 15, 2024
1 parent 4d3ecda commit 36b6b37
Show file tree
Hide file tree
Showing 32 changed files with 1,149 additions and 370 deletions.
4 changes: 3 additions & 1 deletion megamek/i18n/megamek/client/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2693,7 +2693,6 @@ MovementDisplay.moveLowerElevation=Go Down
MovementDisplay.BackWardsElevationChange=Moving Backwards over an elevation change.\n
MovementDisplay.CarefulStand.title=Careful Stand?
MovementDisplay.CarefulStand.message=Do you wish to use careful stand?\n
MovementDisplay.Traitor=Traitor Unit
MovementDisplay.NotUpToSpeed=Selected unit cannot run/flank because it has poor performance and is not up to speed
MovementDisplay.UpToSpeed=Selected unit is up to speed so it can run/flank
MovementDisplay.UnjamRAC.title=Unjam?
Expand Down Expand Up @@ -4630,6 +4629,9 @@ CMVPanel.font=Font:
Gamemaster.Gamemaster=Gamemaster
Gamemaster.EditDamage=Edit Damage
Gamemaster.Configure=Configure
Gamemaster.Traitor=Traitor Unit
Gamemaster.SpecialCommands=Special Commands
Gamemaster.KillUnit=Kill Unit

# Scenario Chooser
ScenarioChooser.title=Choose Scenario
Expand Down
3 changes: 2 additions & 1 deletion megamek/i18n/megamek/client/messages_es.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2438,7 +2438,6 @@ MovementDisplay.moveLowerElevation=Bajar
MovementDisplay.BackWardsElevationChange=Moverse hacia atrás sobre un cambio de elevación.\n
MovementDisplay.CarefulStand.title=¿Mantenerse con Precaución?
MovementDisplay.CarefulStand.message=¿Desea Mantenerse con Precaución?\n
MovementDisplay.Traitor=Unidad Traidora
MovementDisplay.NotUpToSpeed=La unidad seleccionada no puede correr/flanquear porque tiene un rendimiento deficiente y no está al día
MovementDisplay.UpToSpeed=La unidad seleccionada está al día para que pueda correr/flanquear
MovementDisplay.UnjamRAC.title=¿Destrabar?
Expand Down Expand Up @@ -4267,3 +4266,5 @@ ForceGeneratorDialog.reinforced=Reforzado\
ForceGeneratorDialog.understrength=Más Débiles\
ForceGeneratorDialog.default=Predeterminado
ForceGeneratorDialog.noCrew=Sin tripulación

Gamemaster.Traitor=Unidad Traidora
3 changes: 2 additions & 1 deletion megamek/i18n/megamek/client/messages_ru.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1373,7 +1373,6 @@ MovementDisplay.moveLowerElevation=Спуститься
MovementDisplay.BackWardsElevationChange=Преодоление смены уровня высоты реверсом хода.\n
MovementDisplay.CarefulStand.title=Использовать осторожную стойку?
MovementDisplay.CarefulStand.message=Хотите ли вы использовать осторожную стойку?\n
MovementDisplay.Traitor=Юнит предатель
MovementDisplay.NotUpToSpeed=Выбранный юнит не может бежать/ехать быстро потому что у него плохая форма и он не достигнет скорости
MovementDisplay.UpToSpeed=Выбранному юниту хватает скорости и он может бежать/ехать быстро
MovementDisplay.UnjamRAC.title=Расклинить?
Expand Down Expand Up @@ -2258,3 +2257,5 @@ BotConfigDialog.princessHelp.title=Справка по Принцессе

SavePrincessDialog.question=Сохранить изменения в эту конфигурацию?
SavePrincessDialog.saveTargets=Сохранить список стратегичеких целей?

Gamemaster.Traitor=Юнит предатель
3 changes: 2 additions & 1 deletion megamek/i18n/megamek/common/report-messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@
1242=no effect

#1300s - Orbital Bombardment related
1300=<newline><newline><newline>An orbital bombardment hit hex <data>!!!
1300=<newline><newline><B>Orbital bombardment hit hex <data>!!!</B><newline>
1301=<span class='info'>End of orbital bombardment resolution</span>
1302=<data> has commenced an orbital bombardment, it will land at the end of the next weapons phase at hex <data>.

# 1500s - ammo handling related
1500=<data> (<data>) selected <data> <data>
Expand Down
5 changes: 0 additions & 5 deletions megamek/src/megamek/client/ui/swing/CommonMenuBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -356,11 +356,6 @@ public CommonMenuBar() {
toggleCFWarning.setToolTipText(Messages.getString("CommonMenuBar.viewToggleCFWarningToolTip"));
toggleCFWarning.setSelected(GUIP.getShowCFWarnings());

/*
* TODO: moveTraitor = createMenuItem(menu,
* getString("CommonMenuBar.moveTraitor"), MovementDisplay.MOVE_TRAITOR);
*/

// Create the Help menu
menu = new JMenu(Messages.getString("CommonMenuBar.HelpMenu"));
menu.setMnemonic(VK_H);
Expand Down
144 changes: 115 additions & 29 deletions megamek/src/megamek/client/ui/swing/MapMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,14 @@
import java.awt.event.InputEvent;
import java.awt.event.MouseEvent;
import java.math.BigInteger;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;
import java.util.StringTokenizer;
import java.util.Vector;

import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import javax.swing.UIManager;
import java.util.*;

import javax.swing.*;

import megamek.client.Client;
import megamek.client.event.BoardViewEvent;
import megamek.client.ui.Messages;
import megamek.client.ui.swing.gmCommands.GamemasterCommandPanel;
import megamek.client.ui.swing.lobby.LobbyUtility;
import megamek.common.*;
import megamek.common.Building.DemolitionCharge;
Expand All @@ -54,6 +46,8 @@
import megamek.common.weapons.other.CLFireExtinguisher;
import megamek.common.weapons.other.ISFireExtinguisher;
import megamek.logging.MMLogger;
import megamek.server.Server;
import megamek.server.commands.*;

/**
* Context menu for the board.
Expand Down Expand Up @@ -209,23 +203,6 @@ private boolean createMenu() {
}

}

// Traitor Command
JMenuItem item = new JMenuItem(Messages.getString("MovementDisplay.Traitor"));
item.setActionCommand(MovementDisplay.MoveCommand.MOVE_TRAITOR.getCmd());
item.addActionListener(evt -> {
try {
if (currentPanel instanceof MovementDisplay) {
((MovementDisplay) currentPanel).actionPerformed(evt);
}
} catch (Exception ex) {
logger.error(ex, "");
}
});

if (game.getPhase().isMovement()) {
add(item);
}
}

menu = touchOffExplosivesMenu();
Expand Down Expand Up @@ -433,21 +410,57 @@ private JMenu createGamemasterMenu() {

JMenu dmgMenu = new JMenu(Messages.getString("Gamemaster.EditDamage"));
JMenu cfgMenu = new JMenu(Messages.getString("Gamemaster.Configure"));
JMenu traitorMenu = new JMenu(Messages.getString("Gamemaster.Traitor"));
JMenu killMenu = new JMenu(Messages.getString("Gamemaster.KillUnit"));
JMenu specialCommandsMenu = createGMSpecialCommandsMenu();
var entities = client.getGame().getEntitiesVector(coords);
for (Entity entity : entities) {
dmgMenu.add(createUnitEditorMenuItem(entity));
cfgMenu.add(createCustomMekMenuItem(entity));
traitorMenu.add(createTraitorMenuItem(entity));
killMenu.add(createKillMenuItem(entity));
}
if (dmgMenu.getItemCount() != 0) {
menu.add(dmgMenu);
}
if (cfgMenu.getItemCount() != 0) {
menu.add(cfgMenu);
}
if (traitorMenu.getItemCount() != 0) {
menu.add(traitorMenu);
}
if (killMenu.getItemCount() != 0) {
menu.add(killMenu);
}
menu.add(specialCommandsMenu);
return menu;
}
}

private record Tuple(String name, GamemasterServerCommand command) {}

private JMenu createGMSpecialCommandsMenu() {
JMenu menu = new JMenu(Messages.getString("Gamemaster.SpecialCommands"));
var commands = List.of(
new Tuple("Kill Unit", new KillCommand(null, null)),
new Tuple("Change Ownership", new ChangeOwnershipCommand(null, null)),
new Tuple("Change Weather", new ChangeWeatherCommand(null, null)),
new Tuple("Disasters", new DisasterCommand(null, null)),
new Tuple("Orbital Bombardment", new OrbitalBombardmentCommand(null, null)),
new Tuple("Remove Smoke", new RemoveSmokeCommand(null, null)),
new Tuple("Firestarter", new FirestarterCommand(null, null)),
new Tuple("Firestorm", new FirestormCommand(null, null))
);

for (var cmd : commands) {
JMenuItem item = new JMenuItem(cmd.name());
item.addActionListener(evt -> new GamemasterCommandPanel(gui.getFrame(), gui, cmd.command()).setVisible(true));
menu.add(item);
}

return menu;
}

JMenuItem createCustomMekMenuItem(Entity entity) {
JMenuItem item = new JMenuItem(entity.getDisplayName());
item.addActionListener(evt -> {
Expand All @@ -473,6 +486,79 @@ JMenuItem createUnitEditorMenuItem(Entity entity) {
return item;
}

private JMenuItem createTraitorMenuItem(Entity en) {
// Traitor Command
JMenuItem item = new JMenuItem(Messages.getString("Gamemaster.Traitor") + " " + en.getDisplayName());
item.addActionListener(evt -> {
gui.getBoardView().setShouldIgnoreKeys(false);
var players = client.getGame().getPlayersList();
Integer[] playerIds = new Integer[players.size() - 1];
String[] playerNames = new String[players.size() - 1];
String[] options = new String[players.size() - 1];

Player currentOwner = en.getOwner();
// Loop through the players vector and fill in the arrays
int idx = 0;
for (var player : players) {
if (player.getName().equals(currentOwner.getName())
|| (player.getTeam() == Player.TEAM_UNASSIGNED)) {
continue;
}
playerIds[idx] = player.getId();
playerNames[idx] = player.getName();
options[idx] = player.getName() + " (ID: " + player.getId() + ")";
idx++;
}

// No players available?
if (idx == 0) {
JOptionPane.showMessageDialog(gui.getFrame(),
"No players available. Units cannot be traitored to players "
+ "that aren't assigned to a team.");
return;
}

// Dialog for choosing which player to transfer to
String option = (String) JOptionPane.showInputDialog(gui.getFrame(),
"Choose the player to gain ownership of this unit (" + en.getDisplayName() + ") when it turns traitor",
"Traitor", JOptionPane.QUESTION_MESSAGE, null,
options, options[0]);

// Verify that we have a valid option...
if (option != null) {
// Now that we've selected a player, correctly associate the ID and name
int id = playerIds[Arrays.asList(options).indexOf(option)];
String name = playerNames[Arrays.asList(options).indexOf(option)];

// And now we perform the actual transfer
int confirm = JOptionPane.showConfirmDialog(
gui.getFrame(),
en.getDisplayName() + " will switch to " + name
+ "'s side at the end of this turn. Are you sure?",
"Confirm",
JOptionPane.YES_NO_OPTION);
if (confirm == JOptionPane.YES_OPTION) {
client.sendChat(String.format("/changeOwner %d %d", en.getId(), id));
}
}
});

return item;
}

private JMenuItem createKillMenuItem(Entity en) {
JMenuItem item = new JMenuItem(Messages.getString("Gamemaster.KillUnit") + " " + en.getDisplayName());
item.addActionListener(evt -> {
int confirm = JOptionPane.showConfirmDialog(
gui.getFrame(),
"Are you sure you want to kill " + en.getDisplayName() + "?", "Confirm", JOptionPane.YES_NO_OPTION);
if (confirm == JOptionPane.YES_OPTION) {
client.sendChat(String.format("/kill %d", en.getId()));
}
});
return item;
}

private JMenu createSelectMenu() {
JMenu menu = new JMenu("Select");
// add select options
Expand Down
37 changes: 20 additions & 17 deletions megamek/src/megamek/client/ui/swing/MovementDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,6 @@
*/
package megamek.client.ui.swing;

import static megamek.common.MiscType.F_CHAFF_POD;
import static megamek.common.options.OptionsConstants.ADVGRNDMOV_TACOPS_ZIPLINES;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.InputEvent;
import java.awt.event.MouseEvent;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;

import megamek.client.event.BoardViewEvent;
import megamek.client.ui.Messages;
import megamek.client.ui.SharedUtility;
Expand Down Expand Up @@ -62,6 +48,19 @@
import megamek.common.preference.PreferenceManager;
import megamek.logging.MMLogger;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.InputEvent;
import java.awt.event.MouseEvent;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static megamek.common.MiscType.F_CHAFF_POD;
import static megamek.common.options.OptionsConstants.ADVGRNDMOV_TACOPS_ZIPLINES;

public class MovementDisplay extends ActionPhaseDisplay {
private static final MMLogger logger = MMLogger.create(MovementDisplay.class);

Expand Down Expand Up @@ -230,7 +229,7 @@ public String toString() {
}

public String getHotKeyDesc() {
String result = "";
String result;

String msgNext = Messages.getString("Next");
String msgPrevious = Messages.getString("Previous");
Expand Down Expand Up @@ -5297,11 +5296,15 @@ public synchronized void actionPerformed(ActionEvent ev) {
String[] playerNames = new String[players.size() - 1];
String[] options = new String[players.size() - 1];
Entity e = ce();
if (e == null) {
return;
}

Player currentOwner = e.getOwner();
// Loop through the players vector and fill in the arrays
int idx = 0;
for (var player : players) {
if (player.getName().equals(clientgui.getClient().getLocalPlayer().getName())
if (player.getName().equals(currentOwner.getName())
|| (player.getTeam() == Player.TEAM_UNASSIGNED)) {
continue;
}
Expand All @@ -5321,7 +5324,7 @@ public synchronized void actionPerformed(ActionEvent ev) {

// Dialog for choosing which player to transfer to
String option = (String) JOptionPane.showInputDialog(clientgui.getFrame(),
"Choose the player to gain ownership of this unit when it turns traitor",
"Choose the player to gain ownership of this unit (" + e.getDisplayName() + ") when it turns traitor",
"Traitor", JOptionPane.QUESTION_MESSAGE, null,
options, options[0]);

Expand Down
Loading

0 comments on commit 36b6b37

Please sign in to comment.