Skip to content

Commit

Permalink
Add settings for switching unit display to Summary and Firing tabs, p…
Browse files Browse the repository at this point in the history
…lus fixed some bugs
  • Loading branch information
Sleet01 committed Aug 4, 2024
1 parent 0f0d10d commit 4eebb0f
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 37 deletions.
3 changes: 3 additions & 0 deletions megamek/i18n/megamek/client/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1084,6 +1084,7 @@ CommonMenuBar.viewGameOptions=Game Options...
CommonMenuBar.viewLOSSetting=LOS Setting
CommonMenuBar.viewForceDisplay=Force Display
CommonMenuBar.viewMekDisplay=Unit Display
CommonMenuBar.viewFiringMovingTabs=Unit Display Tabs
CommonMenuBar.viewAccessibilityWindow=Accessibility Window
CommonMenuBar.viewIncGUIScale=Increase GUI Scale
CommonMenuBar.viewDecGUIScale=Decrease GUI Scale
Expand Down Expand Up @@ -1302,6 +1303,8 @@ CommonSettingsDialog.report=Report
CommonSettingsDialog.reportFontType=Report Font Type
CommonSettingsDialog.reportKeywords=Report Keywords
CommonSettingsDialog.reportPhases=Report Phases
CommonSettingsDialog.tabsMove=Movement Phases
CommonSettingsDialog.tabsFire=Firing Phases
CommonSettingsDialog.seenby.Player=Player
CommonSettingsDialog.seenby.PlayerDetailed=Player Detailed
CommonSettingsDialog.seenby.Someone=Someone
Expand Down
34 changes: 34 additions & 0 deletions megamek/src/megamek/client/ui/swing/CommonSettingsDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,8 @@ private <T> void moveElement(DefaultListModel<T> srcModel, int srcIndex, int trg
private JComboBox playerListAutoDisplayNonReportCombo;
private JComboBox forceDisplayAutoDisplayReportCombo;
private JComboBox forceDisplayAutoDisplayNonReportCombo;
private JCheckBox displayMoveDisplayDuringMovePhases;
private JCheckBox displayFireDisplayDuringFirePhases;

// Report
private JTextPane reportKeywordsTextPane;
Expand Down Expand Up @@ -2031,6 +2033,8 @@ protected void cancelAction() {
playerListAutoDisplayNonReportCombo.setSelectedItem(GUIP.getPlayerListAutoDisplayNonReportPhase());
forceDisplayAutoDisplayReportCombo.setSelectedItem(GUIP.getForceDisplayAutoDisplayReportPhase());
forceDisplayAutoDisplayNonReportCombo.setSelectedItem(GUIP.getForceDisplayAutoDisplayNonReportPhase());
displayMoveDisplayDuringMovePhases.setSelected(GUIP.getMoveDisplayTabDuringMovePhases());
displayFireDisplayDuringFirePhases.setSelected(GUIP.getFireDisplayTabDuringFiringPhases());

csbUnitDisplayHeatLevel1.setColour(GUIP.getUnitDisplayHeatLevel1());
csbUnitDisplayHeatLevel2.setColour(GUIP.getUnitDisplayHeatLevel2());
Expand Down Expand Up @@ -2460,6 +2464,8 @@ protected void okAction() {
GUIP.setPlayerListAutoDisplayNonReportPhase(playerListAutoDisplayNonReportCombo.getSelectedIndex());
GUIP.setForceDisplayAutoDisplayReportPhase(forceDisplayAutoDisplayReportCombo.getSelectedIndex());
GUIP.setForceDisplayAutoDisplayNonReportPhase(forceDisplayAutoDisplayNonReportCombo.getSelectedIndex());
GUIP.setMoveDisplayTabDuringMovePhases(displayMoveDisplayDuringMovePhases.isSelected());
GUIP.setFireDisplayTabDuringFiringPhases(displayFireDisplayDuringFirePhases.isSelected());

GUIP.setUnitDisplayHeatColorLevel1(csbUnitDisplayHeatLevel1.getColour());
GUIP.setUnitDisplayHeatColorLevel2(csbUnitDisplayHeatLevel2.getColour());
Expand Down Expand Up @@ -2840,6 +2846,14 @@ private JComboBox createHideShowComboBox(int i) {
return cb;
}

private JCheckBox createOnOffCheckBox(boolean b) {
JCheckBox chkb = new JCheckBox();
chkb.setEnabled(true);
chkb.setSelected(b);

return chkb;
}

private JPanel getPhasePanel() {
List<List<Component>> comps = new ArrayList<>();
ArrayList<Component> row;
Expand Down Expand Up @@ -2937,6 +2951,26 @@ private JPanel getPhasePanel() {
row.add(forceDisplayAutoDisplayNonReportCombo);
comps.add(row);

addLineSpacer(comps);

// Firing/Movement Display changes
row = new ArrayList<>();
JLabel tabsDisplayLabel = new JLabel(Messages.getString("CommonMenuBar.viewFiringMovingTabs"));
row.add(tabsDisplayLabel);
comps.add(row);
row = new ArrayList<>();
phaseLabel = new JLabel(Messages.getString("CommonSettingsDialog.tabsMove") + ": ");
row.add(phaseLabel);
displayMoveDisplayDuringMovePhases = createOnOffCheckBox(GUIP.getMoveDisplayTabDuringMovePhases());
row.add(displayMoveDisplayDuringMovePhases);
comps.add(row);
row = new ArrayList<>();
phaseLabel = new JLabel(Messages.getString("CommonSettingsDialog.tabsFire") + ": ");
row.add(phaseLabel);
displayFireDisplayDuringFirePhases = createOnOffCheckBox(GUIP.getFireDisplayTabDuringFiringPhases());
row.add(displayFireDisplayDuringFirePhases);
comps.add(row);

return createSettingsPanel(comps);
}

Expand Down
5 changes: 3 additions & 2 deletions megamek/src/megamek/client/ui/swing/DeploymentDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import megamek.client.event.BoardViewEvent;
import megamek.client.ui.Messages;
import megamek.client.ui.swing.util.KeyCommandBind;
import megamek.client.ui.swing.widget.MechPanelTabStrip;
import megamek.client.ui.swing.widget.MegamekButton;
import megamek.common.*;
import megamek.common.event.GamePhaseChangeEvent;
Expand Down Expand Up @@ -225,10 +226,10 @@ public void selectEntity(int en) {
setRemoveEnabled(true);

clientgui.getUnitDisplay().displayEntity(ce());
clientgui.getUnitDisplay().showPanel("movement");
clientgui.getUnitDisplay().showPanel(MechPanelTabStrip.SUMMARY);
clientgui.updateFiringArc(ce());
clientgui.showSensorRanges(ce());
computeCFWarningHexes(ce());
computeCFWarningHexes(ce());
} else {
disableButtons();
setNextEnabled(true);
Expand Down
9 changes: 7 additions & 2 deletions megamek/src/megamek/client/ui/swing/FiringDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import megamek.client.ui.Messages;
import megamek.client.ui.swing.util.KeyCommandBind;
import megamek.client.ui.swing.util.MegaMekController;
import megamek.client.ui.swing.widget.MechPanelTabStrip;
import megamek.client.ui.swing.widget.MegamekButton;
import megamek.common.*;
import megamek.common.actions.*;
Expand Down Expand Up @@ -262,7 +263,9 @@ private void viewActingUnit() {
Entity en_Target = clientgui.getUnitDisplay().getCurrentEntity();
// Avoided using selectEntity(), to avoid centering on active unit
clientgui.getUnitDisplay().displayEntity(ce());
clientgui.getUnitDisplay().showPanel("weapons");
if (GUIP.getFireDisplayTabDuringFiringPhases()) {
clientgui.getUnitDisplay().showPanel(MechPanelTabStrip.WEAPONS);
}
clientgui.getUnitDisplay().wPan.selectFirstWeapon();
target(en_Target);
}
Expand Down Expand Up @@ -1454,7 +1457,9 @@ protected void refreshAll() {
}
clientgui.getBoardView().redrawEntity(ce());
clientgui.getUnitDisplay().displayEntity(ce());
clientgui.getUnitDisplay().showPanel("weapons");
if (GUIP.getFireDisplayTabDuringFiringPhases()) {
clientgui.getUnitDisplay().showPanel(MechPanelTabStrip.WEAPONS);
}
clientgui.getUnitDisplay().wPan.selectFirstWeapon();
if (ce().isMakingVTOLGroundAttack()) {
updateVTOLGroundTarget();
Expand Down
20 changes: 20 additions & 0 deletions megamek/src/megamek/client/ui/swing/GUIPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,8 @@ public class GUIPreferences extends PreferenceStoreProxy {
public static final String MINI_MAP_SYMBOLS_DISPLAY_MODE = "MinimapSymbolsDisplayMode";
public static final String MINI_MAP_AUTO_DISPLAY_REPORT_PHASE = "MinimapAutoDisplayReportPhase";
public static final String MINI_MAP_AUTO_DISPLAY_NONREPORT_PHASE = "MinimapAutoDisplayNonReportPhase";
public static final String FIRE_DISPLAY_TAB_DURING_PHASES = "FireDisplayTabDuringPhases";
public static final String MOVE_DISPLAY_TAB_DURING_PHASES = "MoveDisplayTabDuringPhases";
public static final String MINIMUM_SIZE_HEIGHT = "MinimumSizeHeight";
public static final String MINIMUM_SIZE_WIDTH = "MinimumSizeWidth";
public static final String MOUSE_WHEEL_ZOOM = "MouseWheelZoom";
Expand Down Expand Up @@ -667,6 +669,8 @@ protected GUIPreferences() {
store.setDefault(MINI_MAP_ENABLED, true);
store.setDefault(MINI_MAP_AUTO_DISPLAY_REPORT_PHASE, 0);
store.setDefault(MINI_MAP_AUTO_DISPLAY_NONREPORT_PHASE, 1);
store.setDefault(MOVE_DISPLAY_TAB_DURING_PHASES, true);
store.setDefault(FIRE_DISPLAY_TAB_DURING_PHASES, true);

store.setDefault(MMSYMBOL, true);
store.setDefault(MINIMUM_SIZE_HEIGHT, 200);
Expand Down Expand Up @@ -1230,6 +1234,14 @@ public int getMinimapAutoDisplayNonReportPhase() {
return store.getInt(MINI_MAP_AUTO_DISPLAY_NONREPORT_PHASE);
}

public boolean getFireDisplayTabDuringFiringPhases() {
return store.getBoolean(FIRE_DISPLAY_TAB_DURING_PHASES);
}

public boolean getMoveDisplayTabDuringMovePhases() {
return store.getBoolean(MOVE_DISPLAY_TAB_DURING_PHASES);
}

public int getMinimapPosX() {
return store.getInt(MINI_MAP_POS_X);
}
Expand Down Expand Up @@ -2069,6 +2081,14 @@ public void setMinimapAutoDisplayNonReportPhase(int i) {
store.setValue(MINI_MAP_AUTO_DISPLAY_NONREPORT_PHASE, i);
}

public void setFireDisplayTabDuringFiringPhases(boolean b) {
store.setValue(FIRE_DISPLAY_TAB_DURING_PHASES, b);
}

public void setMoveDisplayTabDuringMovePhases(boolean b) {
store.setValue(MOVE_DISPLAY_TAB_DURING_PHASES, b);
}

public void setMiniReportEnabled(boolean b) {
store.setValue(MINI_REPORT_ENABLED, b);
}
Expand Down
63 changes: 33 additions & 30 deletions megamek/src/megamek/client/ui/swing/MovementDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import megamek.client.ui.swing.boardview.AbstractBoardViewOverlay;
import megamek.client.ui.swing.util.KeyCommandBind;
import megamek.client.ui.swing.util.MegaMekController;
import megamek.client.ui.swing.widget.MechPanelTabStrip;
import megamek.client.ui.swing.widget.MegamekButton;
import megamek.common.*;
import megamek.common.UnloadStrandedTurn;
Expand Down Expand Up @@ -696,7 +697,9 @@ private void updateUnitDisplayLater(Entity ce) {
@Override
public void run() {
clientgui.getUnitDisplay().displayEntity(ce);
clientgui.getUnitDisplay().showPanel("movement");
if (GUIP.getMoveDisplayTabDuringMovePhases()) {
clientgui.getUnitDisplay().showPanel(MechPanelTabStrip.SUMMARY);
}
}
});
}
Expand Down Expand Up @@ -946,7 +949,7 @@ private void addStepToMovePath(MoveStepType moveStep, int recover, int mineToLay
cmd.addStep(moveStep, recover, mineToLay);
updateMove();
}

private void addStepToMovePath(MoveStepType moveStep, Map<Integer, Integer> additionalIntData) {
cmd.addStep(moveStep, additionalIntData);
updateMove();
Expand Down Expand Up @@ -992,7 +995,7 @@ protected void updateDonePanel() {
if (!getClientgui().getClient().getGame().getPhase().isMovement()) {
return;
}

if (cmd == null || cmd.length() == 0) {
updateDonePanelButtons(Messages.getString("MovementDisplay.Move"), Messages.getString("MovementDisplay.Skip"), false, null);
return;
Expand Down Expand Up @@ -1130,7 +1133,7 @@ private synchronized void endMyTurn() {
clientgui.getBoardView().clearMovementData();
clientgui.clearFieldOfFire();
clientgui.clearTemporarySprites();
cmd = null;
cmd = null;
}

/**
Expand Down Expand Up @@ -2819,15 +2822,15 @@ private void updatePickupCargoButton() {
// there has to be an entity, objects are on the ground,
// the entity can pick them up
if ((ce == null) || (game().getGroundObjects(finalPosition(), ce).size() <= 0) ||
((cmd.getLastStep() != null) &&
((cmd.getLastStep() != null) &&
(cmd.getLastStep().getType() == MoveStepType.PICKUP_CARGO))) {
setPickupCargoEnabled(false);
return;
}

setPickupCargoEnabled(true);
}

/** Updates the status of the "drop cargo" button */
private void updateDropCargoButton() {
final Entity ce = ce();
Expand All @@ -2837,10 +2840,10 @@ private void updateDropCargoButton() {
setDropCargoEnabled(false);
return;
}

setDropCargoEnabled(true);
}

/** Updates the status of the Load button. */
private void updateLoadButton() {
final Entity ce = ce();
Expand Down Expand Up @@ -4919,19 +4922,19 @@ public synchronized void actionPerformed(ActionEvent ev) {
processPickupCargoCommand();
} else if (actionCmd.equals(MoveCommand.MOVE_DROP_CARGO.getCmd())) {
var options = ce().getDistinctCarriedObjects();

if (options.size() == 1) {
addStepToMovePath(MoveStepType.DROP_CARGO);
updateDonePanel();
} else if (options.size() > 1) {
// reverse lookup: location name to location ID - we're going to wind up with a name chosen
// but need to send the ID in the move path.
Map<String, Integer> locationMap = new HashMap<>();

for (int location : ce().getCarriedObjects().keySet()) {
locationMap.put(ce().getLocationName(location), location);
}

// Dialog for choosing which object to pick up
String title = "Choose Cargo to Drop";
String body = "Choose the cargo to drop:";
Expand Down Expand Up @@ -5313,19 +5316,19 @@ public synchronized void actionPerformed(ActionEvent ev) {
private void processPickupCargoCommand() {
var options = game().getGroundObjects(finalPosition());
var displayedOptions = game().getGroundObjects(finalPosition(), ce());

// if there's only one thing to pick up, just pick it up.
// regardless of how many objects we are picking up,
// regardless of how many objects we are picking up,
// we may have to choose the location with which to pick it up
if (displayedOptions.size() == 1) {
if (displayedOptions.size() == 1) {
Integer pickupLocation = getPickupLocation(displayedOptions.get(0));
if (pickupLocation != null) {

if (pickupLocation != null) {
Map<Integer, Integer> data = new HashMap<>();
// we pick the only eligible object out of all the objects on the ground
data.put(MoveStep.CARGO_PICKUP_KEY, options.indexOf(displayedOptions.get(0)));
data.put(MoveStep.CARGO_LOCATION_KEY, pickupLocation);

addStepToMovePath(MoveStepType.PICKUP_CARGO, data);
updateDonePanel();
}
Expand All @@ -5339,44 +5342,44 @@ private void processPickupCargoCommand() {

if (option != null) {
Integer pickupLocation = getPickupLocation(option);
if (pickupLocation != null) {

if (pickupLocation != null) {
int cargoIndex = options.indexOf(option);
Map<Integer, Integer> data = new HashMap<>();
data.put(MoveStep.CARGO_PICKUP_KEY, cargoIndex);
data.put(MoveStep.CARGO_LOCATION_KEY, pickupLocation);

addStepToMovePath(MoveStepType.PICKUP_CARGO, data);
updateDonePanel();
}
}
}
}

/**
* Worker function to chose a limb (or whatever) with which to pick up cargo
*/
private Integer getPickupLocation(ICarryable cargo) {
var validPickupLocations = ce().getValidHalfWeightPickupLocations(cargo);
int pickupLocation = Entity.LOC_NONE;

// if we need to choose a pickup location, then do so
if (validPickupLocations.size() > 1) {
// reverse lookup: location name to location ID - we're going to wind up with a name chosen
// but need to send the ID in the move path.
Map<String, Integer> locationMap = new HashMap<>();

for (int location : ce().getValidHalfWeightPickupLocations(cargo)) {
locationMap.put(ce().getLocationName(location), location);
}

// Dialog for choosing which object to pick up
String title = "Choose Pickup Location";
String body = "Choose the location with which to pick up cargo:";
String locationChoice = (String) JOptionPane.showInputDialog(clientgui.getFrame(),
body, title, JOptionPane.QUESTION_MESSAGE, null,
locationMap.keySet().toArray(), locationMap.keySet().toArray()[0]);

if (locationChoice != null) {
pickupLocation = locationMap.get(locationChoice);
} else {
Expand All @@ -5385,10 +5388,10 @@ private Integer getPickupLocation(ICarryable cargo) {
} else if (validPickupLocations.size() == 1) {
pickupLocation = validPickupLocations.get(0);
}

return pickupLocation;
}

/**
* Add enough <code>MoveStepType.CONVERT_MODE</code> steps to get to the requested mode, or
* clear the path if the unit is in the requested mode at the beginning of the turn.
Expand Down Expand Up @@ -5834,12 +5837,12 @@ private void setBombEnabled(boolean enabled) {
getBtn(MoveCommand.MOVE_BOMB).setEnabled(enabled);
clientgui.getMenuBar().setEnabled(MoveCommand.MOVE_BOMB.getCmd(), enabled);
}

private void setPickupCargoEnabled(boolean enabled) {
getBtn(MoveCommand.MOVE_PICKUP_CARGO).setEnabled(enabled);
clientgui.getMenuBar().setEnabled(MoveCommand.MOVE_PICKUP_CARGO.getCmd(), enabled);
}

private void setDropCargoEnabled(boolean enabled) {
getBtn(MoveCommand.MOVE_DROP_CARGO).setEnabled(enabled);
clientgui.getMenuBar().setEnabled(MoveCommand.MOVE_DROP_CARGO.getCmd(), enabled);
Expand Down
Loading

0 comments on commit 4eebb0f

Please sign in to comment.