Skip to content

Commit

Permalink
Review Changes pt. 1
Browse files Browse the repository at this point in the history
  • Loading branch information
SJuliez committed Apr 17, 2021
1 parent 10d62a9 commit 1532a19
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 89 deletions.
11 changes: 5 additions & 6 deletions megamek/src/megamek/client/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -1890,12 +1890,11 @@ public boolean isLocalBot(IPlayer player) {
return bots.containsKey(player.getName());
}

/** Returns true when the player is a bot added/controlled by this client. */
/**
* Returns the Client associated with the given local bot player. If
* the player is not a local bot, returns null.
*/
public Client getBotClient(IPlayer player) {
if (isLocalBot(player)) {
return bots.get(player.getName());
} else {
throw new IllegalArgumentException("The given player is not a local bot.");
}
return bots.get(player.getName());
}
}
17 changes: 14 additions & 3 deletions megamek/src/megamek/client/ui/swing/ClientDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,31 @@ public class ClientDialog extends JDialog {
protected JFrame owner = null;
private boolean isScaling = false;

/**
* @param owner - the <code>Frame</code> that owns this dialog.
* @param title - the title of this Dialog window
/**
* Creates a basic ClientDialog.
* @see JDialog#JDialog(java.awt.Frame, String)
*/
public ClientDialog(JFrame owner, String title) {
super(owner, title);
this.owner = owner;
}

/**
* Creates a ClientDialog with modality as given by modal.
* @see JDialog#JDialog(java.awt.Frame, String, boolean)
*/
public ClientDialog(JFrame owner, String title, boolean modal) {
super(owner, title, modal);
this.owner = owner;
}

/**
* Creates a ClientDialog with modality as given by modal. This dialog
* will automatically scale with the current GUI scaling value. Results of
* this may vary with the complexity of the dialog; manual scaling will
* often be better.
* @see JDialog#JDialog(java.awt.Frame, String, boolean)
*/
public ClientDialog(JFrame owner, String title, boolean modal, boolean scale) {
super(owner, title, modal);
this.owner = owner;
Expand Down
26 changes: 1 addition & 25 deletions megamek/src/megamek/client/ui/swing/CommonMenuBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ public class CommonMenuBar extends JMenuBar implements ActionListener,
private JMenuItem fileUnitsReinforce;
private JMenuItem fileUnitsReinforceRAT;
private JMenuItem fileRefreshCache;
private JMenuItem fileUnitsOpen;
private JMenuItem fileUnitsSave;
private JMenuItem fileUnitsPaste;
/**
* The <code>Entity</code> current selected. This value may be
Expand Down Expand Up @@ -252,7 +250,7 @@ public CommonMenuBar() {
fileGameQSave.setActionCommand(ClientGUI.FILE_GAME_QSAVE);
fileGameQSave.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_DOWN_MASK));
submenu.add(fileGameQSave);
fileGameQLoad = new JMenuItem(Messages.getString("CommonMenuBar.fileGameQuickSave")); //$NON-NLS-1$
fileGameQLoad = new JMenuItem(Messages.getString("CommonMenuBar.fileGameQuickLoad")); //$NON-NLS-1$
fileGameQLoad.addActionListener(this);
fileGameQLoad.setActionCommand(ClientGUI.FILE_GAME_QLOAD);
fileGameQLoad.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_L, InputEvent.CTRL_DOWN_MASK));
Expand Down Expand Up @@ -333,16 +331,6 @@ public CommonMenuBar() {
fileRefreshCache.addActionListener(this);
fileRefreshCache.setActionCommand(ClientGUI.FILE_REFRESH_CACHE);
submenu.add(fileRefreshCache);
fileUnitsOpen = new JMenuItem(Messages
.getString("CommonMenuBar.fileUnitsOpen")); //$NON-NLS-1$
fileUnitsOpen.addActionListener(this);
fileUnitsOpen.setActionCommand(ClientGUI.FILE_UNITS_OPEN);
submenu.add(fileUnitsOpen);
fileUnitsSave = new JMenuItem(Messages
.getString("CommonMenuBar.fileUnitsSave")); //$NON-NLS-1$
fileUnitsSave.addActionListener(this);
fileUnitsSave.setActionCommand(ClientGUI.FILE_UNITS_SAVE);
submenu.add(fileUnitsSave);
fileUnitsPaste = new JMenuItem(Messages
.getString("CommonMenuBar.fileUnitsPaste"));
fileUnitsPaste.addActionListener(this);
Expand Down Expand Up @@ -967,18 +955,6 @@ private synchronized void manageMenu() {

fileUnitsPaste.setEnabled(phase == IGame.Phase.PHASE_LOUNGE);

// If we have a unit list, and if we are in the lounge,
// then we can still perform all unit list actions.
if (hasUnitList) {
fileUnitsOpen.setEnabled(phase == IGame.Phase.PHASE_LOUNGE);
// fileUnitsSave.setEnabled(phase == IGame.Phase.PHASE_LOUNGE);
}
// If we don't have a unit list, but we are in the lounge,
// then we can open a unit list.
else {
fileUnitsOpen.setEnabled(phase == IGame.Phase.PHASE_LOUNGE);
// fileUnitsSave.setEnabled(false);
}
// Reinforcements cannot be added in the lounge!
fileUnitsReinforce.setEnabled(phase != IGame.Phase.PHASE_LOUNGE);
fileUnitsReinforceRAT.setEnabled(phase != IGame.Phase.PHASE_LOUNGE);
Expand Down
30 changes: 15 additions & 15 deletions megamek/src/megamek/client/ui/swing/GameOptionsDialog.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
/**
* MegaMek - Copyright (C) 2000,2001,2002,2003,2004,2005 Ben Mazur (bmazur@sev.org)
/*
* Copyright (C) 2000,2001,2002,2003,2004,2005 Ben Mazur (bmazur@sev.org)
* 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.
*/

/*
* GameOptionsDialog.java
* 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.
*
* Created on April 26, 2002, 2:14 PM
* 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,8 @@ private void refreshWarning(JLabel label, StringBuilder text) {

/**
* Updates the enabled state of some fields based on the atmosphere setting.
* Also, for some weather settings,
* Also resets the state for some settings, e.g. vacuum will set wind and
* weather to none.
*/
private void adaptToWeatherAtmo() {
boolean isVacuum = comAtmosphere.getSelectedIndex() == ATMO_VACUUM;
Expand All @@ -468,6 +469,9 @@ private void adaptToWeatherAtmo() {
chkBlowingSands.setSelected(false);
chkShiftWindDir.setSelected(false);
chkShiftWindStr.setSelected(false);
comWind.setSelectedIndex(WI_NONE);
comWeather.setSelectedIndex(WE_NONE);
comFog.setSelectedIndex(FOG_NONE);
}
if (specificWind) {
chkShiftWindStr.setSelected(false);
Expand Down
30 changes: 0 additions & 30 deletions megamek/src/megamek/client/ui/swing/RandomArmyDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -543,11 +543,9 @@ public RandomArmyDialog(ClientGUI cl) {

// construct the main dialog
setLayout(new BorderLayout());
// this.setPreferredSize(new Dimension(800,500));
add(m_pButtons, BorderLayout.SOUTH);
add(m_pSplit, BorderLayout.CENTER);
validate();
// pack();
setLocationRelativeTo(cl.frame);

m_pSplit.setDividerLocation(guip.getRndArmySplitPos());
Expand Down Expand Up @@ -790,32 +788,6 @@ public void actionPerformed(ActionEvent ev) {
}
}

// public void windowActivated(WindowEvent arg0) {
// //ignored
// }
//
//
//
// public void windowClosing(WindowEvent arg0) {
// setVisible(false);
// }
//
// public void windowDeactivated(WindowEvent arg0) {
// saveWindowSettings();
// }
//
// public void windowDeiconified(WindowEvent arg0) {
// //ignored
// }
//
// public void windowIconified(WindowEvent arg0) {
// //ignored
// }
//
// public void windowOpened(WindowEvent arg0) {
// //ignored
// }

WindowListener windowListener = new WindowAdapter() {

public void windowClosed(WindowEvent arg0) {
Expand All @@ -833,8 +805,6 @@ private void saveWindowSettings() {

};



private void updatePlayerChoice() {
String lastChoice = (String) m_chPlayer.getSelectedItem();
String clientName = m_clientgui.getClient().getName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ private void setUserPreferences() {
((DefaultRowSorter<?, ?>) tableUnits.getRowSorter()).sort();

tableUnits.invalidate(); // force re-layout of window
// pack();
splitPane.setDividerLocation(guiPreferences.getMechSelectorSplitPos());
setSize(guiPreferences.getMechSelectorSizeWidth(), guiPreferences.getMechSelectorSizeHeight());
setLocation(guiPreferences.getMechSelectorPosX(), guiPreferences.getMechSelectorPosY());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ public void windowClosed(WindowEvent e) {
lblMain.setBorder(new EmptyBorder(0, 20, 0, 20));
add(lblMain, BorderLayout.CENTER);
setMinimumSize(UIUtil.scaleForGUI(MINIMUM_SIZE));
// setPreferredSize(UIUtil.scaleForGUI(MINIMUM_SIZE));
center();
// Make the dialog take ENTER as Yes and ESC as No
getRootPane().setDefaultButton(butYes);
Expand Down
7 changes: 0 additions & 7 deletions megamek/src/megamek/client/ui/swing/lobby/ChatLounge.java
Original file line number Diff line number Diff line change
Expand Up @@ -576,20 +576,17 @@ private void setupMapPanel() {
panMapType.setAlignmentX(JPanel.CENTER_ALIGNMENT);
panMapType.add(butGroundMap);
panMapType.add(butLowAtmoMap);
// panMapType.add(butHighAtmoMap);
panMapType.add(butSpaceMap);
grpMap.add(butGroundMap);
grpMap.add(butLowAtmoMap);
grpMap.add(butHighAtmoMap);
grpMap.add(butSpaceMap);
// panMap.add(panMapType);

// Planetary Conditions and Random Map Settings buttons
FixedYPanel panSettings = new FixedYPanel();
panSettings.setAlignmentX(JPanel.CENTER_ALIGNMENT);
panSettings.add(butConditions);
panSettings.add(butRandomMap);
// panMap.add(panSettings);

FixedYPanel panTopRows = new FixedYPanel();
panTopRows.setLayout(new BoxLayout(panTopRows, BoxLayout.PAGE_AXIS));
Expand Down Expand Up @@ -1994,15 +1991,11 @@ private void loadMapSetup() {
private void removeBot() {
Client c = getSelectedClient();
if (!client().bots.containsValue(c)) {
// if ((c == null) || c.equals(clientgui.getClient())) {
// clientgui.doAlertDialog(Messages.getString("ChatLounge.ImproperCommand"),
// Messages.getString("ChatLounge.SelectBo"));
LobbyErrors.showOnlyOwnBot(clientgui.frame);
return;
}
// Delete units first, which safely disembarks and offloads them
// Don't delete the bot's forces, as that could also delete other players' entitites
// lobbyActions.delete(new ArrayList<>(), game().getPlayerEntities(c.getLocalPlayer(), false), false);
c.die();
clientgui.getBots().remove(c.getName());
}
Expand Down

0 comments on commit 1532a19

Please sign in to comment.