Skip to content

Commit

Permalink
Nickaragua Review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
SJuliez committed Apr 22, 2021
1 parent 1532a19 commit 090f5b0
Show file tree
Hide file tree
Showing 39 changed files with 1,971 additions and 2,345 deletions.
110 changes: 25 additions & 85 deletions megamek/src/megamek/client/ui/swing/lobby/ChatLounge.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
/*
* MegaMek -
* Copyright (C) 2000,2001,2002,2003,2004,2005,2006 Ben Mazur (bmazur@sev.org)
* Copyright © 2013 Edward Cullen (eddy@obsessedcomputers.co.uk)
* Copyright (c) 2021 - The MegaMek Team. All Rights Reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
* This file is part of MegaMek.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
* MegaMek is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MegaMek is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MegaMek. If not, see <http://www.gnu.org/licenses/>.
*/
package megamek.client.ui.swing.lobby;

Expand Down Expand Up @@ -2440,24 +2444,24 @@ public void actionPerformed(ActionEvent e) {
StringTokenizer st = new StringTokenizer(e.getActionCommand(), "|");
String command = st.nextToken();
switch (command) {
case "CONFIG":
case PlayerTablePopup.PTP_CONFIG:
configPlayer();
break;

case "TEAM":
case PlayerTablePopup.PTP_TEAM:
int newTeam = Integer.parseInt(st.nextToken());
lobbyActions.changeTeam(getselectedPlayers(), newTeam);
break;

case "BOTREMOVE":
case PlayerTablePopup.PTP_BOTREMOVE:
removeBot();
break;

case "BOTSETTINGS":
case PlayerTablePopup.PTP_BOTSETTINGS:
doBotSettings();
break;

case "DEPLOY":
case PlayerTablePopup.PTP_DEPLOY:
int startPos = Integer.parseInt(st.nextToken());
if (game().getOptions().booleanOption(OptionsConstants.BASE_DEEP_DEPLOYMENT)
&& (startPos >= 1) && (startPos <= 9)) {
Expand Down Expand Up @@ -2525,15 +2529,6 @@ public void keyPressed(KeyEvent e) {
e.consume();
importClipboard();

} else if (code == KeyEvent.VK_P) {
e.consume();
System.out.println(game().getEntitiesVector().size() + " Units");
game().getEntitiesVector().stream().forEach(System.out::println);

} else if (code == KeyEvent.VK_F) {
e.consume();
System.out.println("Forces: ---");
System.out.println(game().getForces());
}
}
};
Expand Down Expand Up @@ -2686,15 +2681,6 @@ public void keyPressed(KeyEvent e) {
e.consume();
importClipboard();

} else if (code == KeyEvent.VK_P) {
e.consume();
System.out.println(game().getEntitiesVector().size() + " Units");
game().getEntitiesVector().stream().forEach(System.out::println);

} else if (code == KeyEvent.VK_F) {
e.consume();
System.out.println("Forces: ---");
System.out.println(game().getForces());
}
}
};
Expand All @@ -2707,11 +2693,11 @@ public void actionPerformed(ActionEvent action) {
String[] command = action.getActionCommand().split(":");

switch (command[0]) {
case "BOARD":
case MapListPopup.MLP_BOARD:
changeMapDnD(command[2], mapButtons.get(Integer.parseInt(command[1])));
break;

case "SURPRISE":
case MapListPopup.MLP_SURPRISE:
changeMapDnD(command[2], mapButtons.get(Integer.parseInt(command[1])));
break;
}
Expand Down Expand Up @@ -2945,56 +2931,6 @@ private boolean isLoadable(Entity carried, Entity carrier) {
&& (isEditable(carrier) || isEditable(carried));
}


public void load(Collection<Entity> selEntities, String info) {
StringTokenizer stLoad = new StringTokenizer(info, ":");
int loaderId = Integer.parseInt(stLoad.nextToken());
Entity loader = clientgui.getClient().getEntity(loaderId);
int bayNumber = Integer.parseInt(stLoad.nextToken());
// Remove those entities from the candidates that are already carried by that loader
Collection<Entity> entities = new HashSet<>(selEntities);
entities.removeIf(e -> e.getTransportId() == loaderId);
if (entities.isEmpty()) {
return;
}

// If a unit of the selected units is currently loaded onto another, 2nd unit of the selected
// units, do not continue. The player should unload units first. This would require
// a server update offloading that second unit AND embarking it. Currently not possible
// as a single server update and updates for one unit shouldn't be chained.
Set<Entity> carriers = entities.stream()
.filter(e -> e.getTransportId() != Entity.NONE)
.map(e -> game().getEntity(e.getTransportId())).collect(Collectors.toSet());
if (!Collections.disjoint(entities, carriers)) {
LobbyErrors.showNoDualLoad(clientgui.frame);
return;
}

boolean loadRear = false;
if (stLoad.hasMoreTokens()) {
loadRear = Boolean.parseBoolean(stLoad.nextToken());
}

StringBuilder errorMsg = new StringBuilder();
if (!LobbyUtility.validateLobbyLoad(entities, loader, bayNumber, loadRear, errorMsg)) {
JOptionPane.showMessageDialog(clientgui.frame, errorMsg.toString(),
Messages.getString("LoadingBay.error"), JOptionPane.ERROR_MESSAGE);
return;
}

for (Entity e : entities) {
if (e.getTransportId() != Entity.NONE) {
Set<Entity> updateCandidates = new HashSet<>();
disembark(e, updateCandidates);
if (!updateCandidates.isEmpty()) {
Entity formerLoader = game().getEntity(e.getTransportId());
getLocalClient(formerLoader).sendUpdateEntity(formerLoader);
}
}
loadOnto(e, loaderId, bayNumber);
}
}

@Override
public void preferenceChange(PreferenceChangeEvent e) {
if (e.getName().equals(GUIPreferences.GUI_SCALE)) {
Expand Down Expand Up @@ -3279,7 +3215,7 @@ public boolean isCompact() {
* Returns a list of the selected entities in the Mek table.
* The list may be empty but not null.
*/
private ArrayList<Entity> getSelectedEntities() {
private List<Entity> getSelectedEntities() {
ArrayList<Entity> result = new ArrayList<>();
int[] rows = mekTable.getSelectedRows();
for (int i = 0; i < rows.length; i++) {
Expand Down Expand Up @@ -3617,5 +3553,9 @@ Client client() {
return clientgui.getClient();
}

boolean isForceView() {
return butForceView.isSelected();
}

}

54 changes: 30 additions & 24 deletions megamek/src/megamek/client/ui/swing/lobby/LobbyActions.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
/*
* MegaMek - Copyright (C) 2021 - The MegaMek Team
*
* listener program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* listener program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
/*
* Copyright (c) 2021 - The MegaMek Team. All Rights Reserved.
*
* This file is part of MegaMek.
*
* MegaMek is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MegaMek is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MegaMek. If not, see <http://www.gnu.org/licenses/>.
*/
package megamek.client.ui.swing.lobby;

Expand All @@ -36,6 +41,7 @@

import static megamek.client.ui.swing.lobby.LobbyUtility.*;
import static java.util.stream.Collectors.*;
import static megamek.client.ui.swing.lobby.LobbyMekPopup.*;

/** This class contains the methods that perform entity and force changes from the pop-up menu and elsewhere. */
public class LobbyActions {
Expand Down Expand Up @@ -108,8 +114,8 @@ void applyProne(Collection<Entity> entities, String info) {
return;
}
Set<Entity> updateCandidates = new HashSet<>();
boolean goProne = info.equals("PRONE");
boolean goHullDown = info.equals("HULLDOWN");
boolean goProne = info.equals(LMP_PRONE);
boolean goHullDown = info.equals(LMP_HULLDOWN);
boolean stand = !goProne && !goHullDown;
for (Entity entity: entities) {
if ((goProne && !entity.isProne()) || (goHullDown && !entity.isHullDown())
Expand Down Expand Up @@ -182,7 +188,7 @@ void configureDamage(Collection<Entity> entities) {
if (!validateUpdate(entities)) {
return;
}
Entity entity = CollectionUtil.randomElement(entities);
Entity entity = CollectionUtil.anyOneElement(entities);
UnitEditorDialog med = new UnitEditorDialog(frame(), entity);
med.setVisible(true);
sendUpdates(entities);
Expand All @@ -209,15 +215,15 @@ void forceMove(Collection<Force> forceList, Collection<Entity> entityList, boole
var changedForce = new HashSet<Force>();
if (up) {
if (!forceList.isEmpty()) {
changedForce.addAll(forces.moveUp(CollectionUtil.randomElement(forceList)));
changedForce.addAll(forces.moveUp(CollectionUtil.anyOneElement(forceList)));
} else if (!entityList.isEmpty()) {
changedForce.addAll(forces.moveUp(CollectionUtil.randomElement(entityList)));
changedForce.addAll(forces.moveUp(CollectionUtil.anyOneElement(entityList)));
}
} else {
if (!forceList.isEmpty()) {
changedForce.addAll(forces.moveDown(CollectionUtil.randomElement(forceList)));
changedForce.addAll(forces.moveDown(CollectionUtil.anyOneElement(forceList)));
} else if (!entityList.isEmpty()) {
changedForce.addAll(forces.moveDown(CollectionUtil.randomElement(entityList)));
changedForce.addAll(forces.moveDown(CollectionUtil.anyOneElement(entityList)));
}
}

Expand All @@ -238,7 +244,7 @@ public void individualCamo(Collection<Entity> entities) {

// Display the CamoChooser and await the result
// The dialog is preset to a random entity's settings
Entity entity = CollectionUtil.randomElement(entities);
Entity entity = CollectionUtil.anyOneElement(entities);
CamoChooserDialog ccd = new CamoChooserDialog(frame(), entity.getOwner().getCamouflage());
if ((ccd.showDialog() == JOptionPane.CANCEL_OPTION) || (ccd.getSelectedItem() == null)) {
return;
Expand Down Expand Up @@ -271,7 +277,7 @@ public void customizeMechs(Collection<Entity> entities) {
LobbyErrors.showSingleOwnerRequired(frame());
return;
}
Entity randomSelected = CollectionUtil.randomElement(entities);
Entity randomSelected = CollectionUtil.anyOneElement(entities);
String ownerName = randomSelected.getOwner().getName();
int ownerId = randomSelected.getOwner().getId();

Expand Down Expand Up @@ -504,7 +510,7 @@ void forceCreateFrom(Collection<Entity> entities) {
if ((name == null) || (name.trim().length() == 0)) {
return;
}
client().sendAddForce(Force.createToplevelForce(name, CollectionUtil.randomElement(entities).getOwner()), entities);
client().sendAddForce(Force.createToplevelForce(name, CollectionUtil.anyOneElement(entities).getOwner()), entities);
}

/**
Expand Down Expand Up @@ -721,7 +727,7 @@ void swapPilots(Collection<Entity> entities, int targetId) {
LobbyErrors.showSingleUnit(frame(), "swap pilots");
return;
}
Entity selected = CollectionUtil.randomElement(entities);
Entity selected = CollectionUtil.anyOneElement(entities);
if (!validateUpdate(Arrays.asList(target, selected))) {
return;
}
Expand Down Expand Up @@ -957,7 +963,7 @@ void unloadFromBay(Collection<Entity> entities, int bayId) {
LobbyErrors.showSingleUnit(frame(), "offload from bays");
return;
}
Entity carrier = CollectionUtil.randomElement(entities);
Entity carrier = CollectionUtil.anyOneElement(entities);
if (!validateUpdate(Arrays.asList(carrier))) {
return;
}
Expand Down
18 changes: 18 additions & 0 deletions megamek/src/megamek/client/ui/swing/lobby/LobbyErrors.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
* Copyright (c) 2021 - The MegaMek Team. All Rights Reserved.
*
* This file is part of MegaMek.
*
* MegaMek is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MegaMek is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MegaMek. If not, see <http://www.gnu.org/licenses/>.
*/
package megamek.client.ui.swing.lobby;

import java.awt.Frame;
Expand Down
Loading

0 comments on commit 090f5b0

Please sign in to comment.