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

ReplacePlayerDialog can now edit existing bot configs #4605

Merged
merged 7 commits into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
20 changes: 13 additions & 7 deletions megamek/i18n/megamek/client/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4368,14 +4368,20 @@ BotConfigDialog.saveNewTaken=That name already exists.
BotConfigDialog.previousConfig=Previous Configuration

#Replace Player Dialog
ReplacePlayersDialog.title=Replace Players with Princess Bots
ReplacePlayersDialog.princess=Princess
ReplacePlayersDialog.noReplacement=No replacement
ReplacePlayersDialog.ghostPlayerHeader=Ghost Player
ReplacePlayersDialog.configAvailableHeader=Princess Config
ReplacePlayersDialog.chooseReplacementHeader=Replace With
ReplacePlayersDialog.configAvailable=Available
ReplacePlayersDialog.title=Replace Ghosts Players with Princess Bots and Edit Local Bots
ReplacePlayersDialog.optionReplace=Replace with Princess
ReplacePlayersDialog.optionDoNotReplace=Keep as Ghost
ReplacePlayersDialog.optionNone=No Action
ReplacePlayersDialog.optionEdit=Edit Bot
ReplacePlayersDialog.optionKick=Kick Bot
ReplacePlayersDialog.playerNameHeader=Player
ReplacePlayersDialog.playerTypeHeader=Type
ReplacePlayersDialog.configAvailableHeader=Saved Bot Config
ReplacePlayersDialog.chooseActionHeader=Action
ReplacePlayersDialog.configAvailable=Restore Saved Config
ReplacePlayersDialog.config=Bot Settings...
ReplacePlayersDialog.local=Local
ReplacePlayersDialog.remote=Remote

#Point Blank Shot Dialog
StatusBarPhaseDisplay.pointblankShot=Pointblank shot from a hidden unit!
Expand Down
8 changes: 4 additions & 4 deletions megamek/i18n/megamek/client/messages_es.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4212,11 +4212,11 @@ BotConfigDialog.previousConfig=Configuración Anterior

#Replace Player Dialog
ReplacePlayersDialog.title=Reemplazar Jugadores con Princess Bots
ReplacePlayersDialog.princess=Princess
ReplacePlayersDialog.noReplacement=Sin reemplazo
ReplacePlayersDialog.ghostPlayerHeader=Jugador Fantasma
ReplacePlayersDialog.optionReplace=Princess
ReplacePlayersDialog.optionDoNotReplace=Sin reemplazo
ReplacePlayersDialog.playerNameHeader=Jugador Fantasma
ReplacePlayersDialog.configAvailableHeader=Configuración de Princess
ReplacePlayersDialog.chooseReplacementHeader=Reemplazar con
ReplacePlayersDialog.chooseActionHeader=Reemplazar con
ReplacePlayersDialog.configAvailable=Disponible
ReplacePlayersDialog.config=Configuración del Bot...

Expand Down
32 changes: 19 additions & 13 deletions megamek/src/megamek/client/ui/swing/ClientGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@
import java.net.URL;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;

public class ClientGUI extends JPanel implements BoardViewListener,
ActionListener, ComponentListener, IPreferenceChangeListener {
Expand Down Expand Up @@ -2795,14 +2794,6 @@ public void componentShown(ComponentEvent evt) {
}

void replacePlayer() {
Set<Player> ghostPlayers = client.getGame().getPlayersVector().stream()
.filter(Player::isGhost).collect(Collectors.toSet());
if (ghostPlayers.isEmpty()) {
doAlertDialog( Messages.getString("ClientGUI.noGhostPlayersToReplace"),
Messages.getString("ClientGUI.noGhosts"), JOptionPane.INFORMATION_MESSAGE);
return;
}

var rpd = new ReplacePlayersDialog(frame, this);
rpd.setVisible(true);
if (rpd.getResult() == DialogResult.CANCELLED) {
Expand All @@ -2811,17 +2802,32 @@ void replacePlayer() {

AddBotUtil util = new AddBotUtil();
Map<String, BehaviorSettings> newBotSettings = rpd.getNewBots();
for (String player : newBotSettings.keySet()) {
for (String ghostName : newBotSettings.keySet()) {
StringBuilder message = new StringBuilder();
Princess princess = util.addBot(newBotSettings.get(player), player,
client.getGame(), client.getHost(), client.getPort(), message);
Princess princess = util.replaceGhostWithBot(newBotSettings.get(ghostName), ghostName,
client, this, message);
systemMessage(message.toString());
// Make this princess a locally owned bot if in the lobby. This way it
// can be configured, and it will faithfully press Done when the local player does.
if ((princess != null) && client.getGame().getPhase().isLounge()) {
getBots().put(player, princess);
getBots().put(ghostName, princess);
}
}

Map<String, BehaviorSettings> changedBots = rpd.getChangedBots();
for (String botName : changedBots.keySet()) {
StringBuilder message = new StringBuilder();
util.changeBotSettings(changedBots.get(botName), botName,
client, this, message);
systemMessage(message.toString());
}

Set<String> kickBotNames = rpd.getKickBots();
for (String botName : kickBotNames) {
StringBuilder message = new StringBuilder();
util.kickBot( botName, client, message);
systemMessage(message.toString());
}
}

/**
Expand Down
Loading