diff --git a/megamek/i18n/megamek/client/messages.properties b/megamek/i18n/megamek/client/messages.properties index 948ae58efe7..d7098a98db7 100644 --- a/megamek/i18n/megamek/client/messages.properties +++ b/megamek/i18n/megamek/client/messages.properties @@ -3632,6 +3632,7 @@ TargetingPhaseDisplay.fireSkip=Skip TargetingPhaseDisplay.fireTwist=Twist TargetingPhaseDisplay.fireSearchlight=Searchlight TargetingPhaseDisplay.fireDisengage=Disengage +TargetingPhaseDisplay.fireClearWeaponJam=Unjam Weapon TargetingPhaseDisplay.Skip=Skip Firing TargetingPhaseDisplay.waitingForFiringPhase=Waiting to begin Firing phase... TargetingPhaseDisplay.waitingForTargetingPhase=Waiting to begin Targeting phase... diff --git a/megamek/src/megamek/client/ui/swing/TargetingPhaseDisplay.java b/megamek/src/megamek/client/ui/swing/TargetingPhaseDisplay.java index 20a9bbd2d9b..52fd9c6b23e 100644 --- a/megamek/src/megamek/client/ui/swing/TargetingPhaseDisplay.java +++ b/megamek/src/megamek/client/ui/swing/TargetingPhaseDisplay.java @@ -18,6 +18,7 @@ import java.awt.event.MouseEvent; import java.util.*; +import javax.swing.*; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; @@ -30,15 +31,7 @@ import megamek.client.ui.swing.widget.MegaMekButton; import megamek.client.ui.swing.widget.MekPanelTabStrip; import megamek.common.*; -import megamek.common.actions.ArtilleryAttackAction; -import megamek.common.actions.DisengageAction; -import megamek.common.actions.EntityAction; -import megamek.common.actions.FlipArmsAction; -import megamek.common.actions.SearchlightAttackAction; -import megamek.common.actions.TorsoTwistAction; -import megamek.common.actions.TriggerAPPodAction; -import megamek.common.actions.TriggerBPodAction; -import megamek.common.actions.WeaponAttackAction; +import megamek.common.actions.*; import megamek.common.enums.AimingMode; import megamek.common.enums.GamePhase; import megamek.common.event.GamePhaseChangeEvent; @@ -78,7 +71,8 @@ public enum TargetingCommand implements PhaseCommand { FIRE_FLIP_ARMS("fireFlipArms"), FIRE_SEARCHLIGHT("fireSearchlight"), FIRE_CANCEL("fireCancel"), - FIRE_DISENGAGE("fireDisengage"); + FIRE_DISENGAGE("fireDisengage"), + FIRE_CLEAR_WEAPON("fireClearWeaponJam"); String cmd; @@ -317,6 +311,9 @@ protected ArrayList getButtonList() { if ((cmd == TargetingCommand.FIRE_DISENGAGE) && ((ce() == null) || !ce().isOffBoard())) { continue; } + if (cmd == TargetingCommand.FIRE_CLEAR_WEAPON && !(ce() instanceof Tank)) { + continue; + } buttonList.add(buttons.get(cmd)); } return buttonList; @@ -384,6 +381,9 @@ private void selectEntity(int en) { if (!ce().isOffBoard()) { clientgui.showFiringSolutions(ce()); } + + updateClearWeaponJam(); + } else { logger.error("Tried to select non-existent entity: " + en); } @@ -481,6 +481,7 @@ private void disableButtons() { setFireModeEnabled(false); setNextTargetEnabled(false); setDisengageEnabled(false); + setFireClearWeaponJamEnabled(false); } /** @@ -638,6 +639,8 @@ private void fire() { } } + updateClearWeaponJam(); + updateDisplayForPendingAttack(mounted, waa); } @@ -1253,6 +1256,34 @@ public void actionPerformed(ActionEvent ev) { clear(); addAttack(new DisengageAction(currentEntity)); ready(); + } else if(ev.getActionCommand().equals(TargetingCommand.FIRE_CLEAR_WEAPON.getCmd())) { + doClearWeaponJam(); + } + } + + /** + * clear weapon jam + */ + protected void doClearWeaponJam() { + ArrayList> weapons = ((Tank) ce()).getJammedWeapons(); + String[] names = new String[weapons.size()]; + for (int loop = 0; loop < names.length; loop++) { + names[loop] = weapons.get(loop).getDesc(); + } + String input = (String) JOptionPane.showInputDialog(clientgui.getFrame(), + Messages.getString("FiringDisplay.ClearWeaponJam.question"), + Messages.getString("FiringDisplay.ClearWeaponJam.title"), + JOptionPane.QUESTION_MESSAGE, null, names, null); + + if (input != null) { + for (int loop = 0; loop < names.length; loop++) { + if (input.equals(names[loop])) { + RepairWeaponMalfunctionAction rwma = new RepairWeaponMalfunctionAction( + ce().getId(), ce().getEquipmentNum(weapons.get(loop))); + addAttack(rwma); + ready(); + } + } } } @@ -1280,6 +1311,11 @@ && ce().getCrew().isActive() && SearchlightAttackAction.isPossible(clientgui.getClient().getGame(), currentEntity, target, null)); } + private void updateClearWeaponJam(){ + setFireClearWeaponJamEnabled((ce() instanceof Tank) && ((Tank) ce()).canUnjamWeapon() + && attacks.isEmpty()); + } + private void setFireEnabled(boolean enabled) { buttons.get(TargetingCommand.FIRE_FIRE).setEnabled(enabled); clientgui.getMenuBar().setEnabled(FiringCommand.FIRE_FIRE.getCmd(), enabled); @@ -1326,6 +1362,12 @@ private void setDisengageEnabled(boolean enabled) { } } + private void setFireClearWeaponJamEnabled(boolean enabled) { + if (buttons.containsKey(TargetingCommand.FIRE_CLEAR_WEAPON)) { + buttons.get(TargetingCommand.FIRE_CLEAR_WEAPON).setEnabled(enabled); + } + } + @Override public void clear() { clearAttacks();