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

Choosing Elevation at Deployment #5996

Merged
merged 13 commits into from
Sep 17, 2024
39 changes: 25 additions & 14 deletions megamek/i18n/megamek/client/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1656,24 +1656,14 @@ DeploymentDisplay.buttonInferno=Inferno({0})
DeploymentDisplay.buttonVibrabomb=Vibrabomb({0})
DeploymentDisplay.buttonRemove=Remove
DeploymentDisplay.cantDeployInto={0} can not deploy into {1}.
DeploymentDisplay.outsideDeployArea=This position is outside of this unit's deployment area.
DeploymentDisplay.ConfirmDoomed.title=Deploy doomed?
DeploymentDisplay.ConfirmDoomed.message=Due to planetary conditions, deploying this unit will cause it to be destroyed. \nReason: {0}\nDo you wish to proceed?
DeploymentDisplay.deployDock=Dock
DeploymentDisplay.dropshipBuildingDeploy=Landed dropships cannot be deployed on top of buildings.
DeploymentDisplay.elevationTooLow={0} can not deploy into {1} because elevation is too low.
DeploymentDisplay.Deploy=Deploy
DeploymentDisplay.floor=Floor \#
DeploymentDisplay.floorsDialog.message=What floor should {0} be placed on?
DeploymentDisplay.floorsDialog.title=What floor?
DeploymentDisplay.ground=Ground floor
DeploymentDisplay.belowbridge=Below the bridge
DeploymentDisplay.topbridge=On top of the bridge
DeploymentDisplay.bridgeDialog.message=Where should {0} be placed?
DeploymentDisplay.bridgeDialog.title=Below or on bridge?
DeploymentDisplay.FormSquadron=Form Squadron
DeploymentDisplay.its_others_turn=It''s {0}''s turn to deploy.
DeploymentDisplay.its_your_turn=It's your turn to deploy.
DeploymentDisplay.deployLoad=Load
DeploymentDisplay.loadUnitDialog.message={0} has the following unused space:\r\n{1}\n\nWhich unit do you want to load?
DeploymentDisplay.loadUnitDialog.title=Load Unit
DeploymentDisplay.loadUnitBayNumberDialog.message=Which of {0}'s bays do you wish to load into?
Expand All @@ -1682,19 +1672,40 @@ DeploymentDisplay.loadProtoClampMountDialog.message=Which side of {0} do you wis
DeploymentDisplay.loadProtoClampMountDialog.title=Choose Position
DeploymentDisplay.loadProtoClampMountDialog.front=Front
DeploymentDisplay.loadProtoClampMountDialog.rear=Rear
# The following are accessed programmatically and are not unused:
DeploymentDisplay.deployNext=Next Unit
DeploymentDisplay.deployRemove=Remove Unit
DeploymentDisplay.deployTurn=Turn
DeploymentDisplay.deployLoad=Load
DeploymentDisplay.deployUnload=Unload
DeploymentDisplay.deployDock=Dock
# ---
DeploymentDisplay.removeTitle=Remove Unit
DeploymentDisplay.removeUnit=Are you sure you want to remove {0}?
DeploymentDisplay.top=Top of the building
DeploymentDisplay.towUnitDialog.message={0} has an available tow hitch.\n\nWhich unit do you want to tow?
DeploymentDisplay.towUnitDialog.title=Tow Unit
DeploymentDisplay.deployTurn=Turn
DeploymentDisplay.deployUnload=Unload
DeploymentDisplay.unloadUnitDialog.message={0} has the following unused space:\r\n{1}\n\nWhich unit do you want to unload?
DeploymentDisplay.unloadUnitDialog.title=Unload Unit
DeploymentDisplay.waitingForDeploymentPhase=Waiting to begin Deployment phase...
DeploymentDisplay.wrongMapType={0} can not deploy onto a {1} map.
DeploymentDisplay.choiceDialogTitle=Select Deployment
DeploymentDisplay.choice=Choose where to deploy:
DeploymentDisplay.elevationChoice=Choose an elevation:
DeploymentDisplay.elevation=Elevation:
DeploymentDisplay.altitude=Altitude:
# The following are accessed programmatically and are not unused:
DeploymentDisplay.deployElevation.ON_GROUND=On the Ground
DeploymentDisplay.deployElevation.ON_ICE=On the Ice
DeploymentDisplay.deployElevation.SUBMERGED=Submerged
DeploymentDisplay.deployElevation.ON_SEAFLOOR=Seafloor / Riverbed
DeploymentDisplay.deployElevation.WATER_SURFACE=Water Surface
DeploymentDisplay.deployElevation.ALTITUDE=Airborne
DeploymentDisplay.deployElevation.ELEVATION=Airborne
DeploymentDisplay.deployElevation.ELEVATIONS_ABOVE=Choose Elevation...
DeploymentDisplay.deployElevation.BUILDING_FLOOR=Building Floor
DeploymentDisplay.deployElevation.BUILDING_TOP=Building Top
DeploymentDisplay.deployElevation.BRIDGE=On the Bridge
# ---

#Deploy Minefields
DeployMinefieldDisplay.deployMineActive=Active({0})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* Copyright (c) 2024 - 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;

import megamek.client.ui.Messages;
import megamek.client.ui.swing.util.UIUtil;
import megamek.common.DeploymentElevationType;
import megamek.common.ElevationOption;

import javax.swing.*;
import javax.swing.border.MatteBorder;
import java.util.List;

import static megamek.client.ui.swing.util.UIUtil.spanCSS;

/**
* This dialog allows selecting an elevation (or altitude) during deployment.
*/
public class DeployElevationChoiceDialog extends AbstractChoiceDialog<ElevationOption> {

private static final int BASE_PADDING = 10;

protected DeployElevationChoiceDialog(JFrame parent, List<ElevationOption> elevationOptions) {
super(parent, "DeploymentDisplay.choiceDialogTitle", titleMessage(), elevationOptions, false);
setColumns(elevationOptions.size() > 6 ? 2 : 1);
initialize();
setUseDetailed(false);
}

@Override
protected void detailLabel(JToggleButton button, ElevationOption elevationOption) {
String description = Messages.getString("DeploymentDisplay.deployElevation." + elevationOption.type());
String elevationAltitude = elevationOption.type() == DeploymentElevationType.ALTITUDE
? Messages.getString("DeploymentDisplay.altitude")
: Messages.getString("DeploymentDisplay.elevation");
String elevationText = elevationAltitude + elevationOption.elevation();
String text = "<HTML><HEAD>" + styles() + "</HEAD><BODY><CENTER>" + spanCSS("description", description);
if (elevationOption.type() != DeploymentElevationType.ELEVATIONS_ABOVE) {
text += "<BR>" + spanCSS("elevation", elevationText) + "</BODY></HTML>";
}
button.setText(text);
}

@Override
protected JPanel createButtonPanel() {
JPanel buttonPanel = new JPanel();
buttonPanel.setBorder(BorderFactory.createCompoundBorder(
new MatteBorder(1, 0, 0, 0, UIManager.getColor("Separator.foreground")),
new UIUtil.ScaledEmptyBorder(10, 0, 10, 0)));
buttonPanel.add(new ButtonEsc(new CloseAction(this)));
return buttonPanel;
}

@Override
protected void summaryLabel(JToggleButton button, ElevationOption target) {
detailLabel(button, target);
}

private static String titleMessage() {
return "<HTML><HEAD>" + styles() + "</HEAD><BODY><div class=frame>"
+ spanCSS("label", Messages.getString("DeploymentDisplay.choice"))
+ "</div></BODY></HTML>";
}

@Override
public void setVisible(boolean visible) {
if (visible) {
UIUtil.adjustDialog(this, UIUtil.FONT_SCALE1);
pack();
}
super.setVisible(visible);
}

public static String styles() {
int descriptionSize = UIUtil.scaleForGUI(UIUtil.FONT_SCALE1);
int elevationSize = (int) (0.8 * UIUtil.scaleForGUI(UIUtil.FONT_SCALE1));
int padding = UIUtil.scaleForGUI(BASE_PADDING);
return "<style> " +
".description { font-family:Noto Sans; font-size:" + descriptionSize + "; }" +
".elevation { font-family:Noto Sans; font-size:" + elevationSize + "; }" +
".frame { padding:" + padding + " " + 2 * padding + " 0 0; }";
}
}
Loading