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

Add more target info to the WeaponsPanel of the Unit Display #4423

Merged
merged 18 commits into from
Jun 10, 2023
Merged
2 changes: 2 additions & 0 deletions megamek/i18n/megamek/client/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1964,6 +1964,8 @@ MechDisplay.TSEMPShutdown=Shutdown due to TSEMP
MechDisplay.SelectMulti.title=Choose Ammobin
MechDisplay.SelectMulti.question=Which ammobin do you want do select?
MechDisplay.over=over
MechDisplay.NoTarget=No Target Selected
MechDisplay.AimingAt=Aiming at <b>%s</b>

MechGroupView.title=Group View

Expand Down
3 changes: 2 additions & 1 deletion megamek/src/megamek/client/ui/swing/AimedShotDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ public AimedShotDialog(JFrame parent, String title, String message,
gridbag.setConstraints(labMessage, c);
getContentPane().add(labMessage);

String div = "<DIV WIDTH=" + UIUtil.scaleForGUI(500) + ">" + UnitToolTip.getTargetTipDetail(target, clientGUI.getClient().getBoard(), clientGUI) + "</DIV>";
String div = "<DIV WIDTH=" + UIUtil.scaleForGUI(500) + ">" + UnitToolTip.getTargetTipDetail(target, clientGUI.getClient()) + "</DIV>";
JLabel labTarget = new JLabel("<html>" + div + "</hmtl>", SwingConstants.LEFT);

c.weightx = 1.0;
c.weighty = 1.0;
c.gridwidth = 0;
Expand Down
2 changes: 1 addition & 1 deletion megamek/src/megamek/client/ui/swing/AimedShotHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ public String getAimingLocation() {
if (this.firingDisplay.target instanceof GunEmplacement) {
return GunEmplacement.HIT_LOCATION_NAMES[aimingAt];
} else if (this.firingDisplay.target instanceof Entity) {
return ((Entity) this.firingDisplay.target).getLocationAbbrs()[aimingAt];
return ((Entity) this.firingDisplay.target).getLocationName(aimingAt);
}
}
return null;
Expand Down
4 changes: 2 additions & 2 deletions megamek/src/megamek/client/ui/swing/EntityChoiceDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ protected EntityChoiceDialog(JFrame frame, String title, String message,

@Override
protected void detailLabel(JToggleButton button, Entity target) {
String div = "<DIV WIDTH=" + UIUtil.scaleForGUI(500) + ">" + UnitToolTip.getEntityTipVitals(target, null) + "</DIV>";
String div = "<DIV WIDTH=" + UIUtil.scaleForGUI(500) + ">" + UnitToolTip.getEntityTipAsTarget(target, null) + "</DIV>";
button.setText("<html>" + div + "</html>");
}

@Override
protected void summaryLabel(JToggleButton button, Entity target) {
button.setText("<html><b>" + target.getDisplayName() + "</b></html>");
button.setText("<html><b>" +UnitToolTip.getTargetTipSummaryEntity(target, null) + "</b></html>");
}

/**
Expand Down
48 changes: 22 additions & 26 deletions megamek/src/megamek/client/ui/swing/FiringDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import megamek.client.event.BoardViewEvent;
import megamek.client.ui.Messages;
import megamek.client.ui.swing.tooltip.UnitToolTip;
import megamek.client.ui.swing.unitDisplay.WeaponPanel;
import megamek.client.ui.swing.util.CommandAction;
import megamek.client.ui.swing.util.KeyCommandBind;
Expand Down Expand Up @@ -841,7 +842,7 @@ public void selectEntity(int en) {
setFindClubEnabled(false);
setFlipArmsEnabled(false);
setStrafeEnabled(false);
clientgui.getUnitDisplay().wPan.toHitText.setText("Hidden units are only allowed to spot!");
clientgui.getUnitDisplay().wPan.setToHit("Hidden units are only allowed to spot!");
}
} else {
LogManager.getLogger().error("Tried to select non-existent entity " + en);
Expand Down Expand Up @@ -1495,7 +1496,7 @@ private void updateStrafingTargets() {
// Could check legality on buildings, but I don't believe there are
// any weapons that are still legal that aren't legal on buildings
}
clientgui.getUnitDisplay().wPan.toHitText.setText(toHitBuff.toString());
clientgui.getUnitDisplay().wPan.setToHit(toHitBuff.toString());
}

private int[] getBombPayload(boolean isSpace, int limit) {
Expand Down Expand Up @@ -1916,15 +1917,18 @@ public void updateTarget() {
}

// update target panel

final int weaponId = clientgui.getUnitDisplay().wPan.getSelectedWeaponNum();
if (isStrafing && weaponId != -1) {
clientgui.getUnitDisplay().wPan.wTargetR.setText(Messages
.getString("FiringDisplay.Strafing.TargetLabel"));
clientgui.getUnitDisplay().wPan.setTarget(target, Messages
.getString("FiringDisplay.Strafing.TargetLabel") );

updateStrafingTargets();
} else if ((ce() != null) && ce().equals(clientgui.getUnitDisplay().getCurrentEntity())
&& (target != null) && (target.getPosition() != null)
&& (weaponId != -1)) {
ToHitData toHit;

if (!ash.getAimingMode().isNone()) {
Mounted weapon = ce().getEquipment(weaponId);
boolean aiming = ash.isAimingAtLocation() && ash.allowAimedShotWith(weapon);
Expand All @@ -1933,21 +1937,18 @@ public void updateTarget() {
toHit = WeaponAttackAction.toHit(game, cen, target,
weaponId, ash.getAimingAt(), ash.getAimingMode(),
false);

String t = String.format("<html><div WIDTH=%d>%s</div></html>", WeaponPanel.TARGET_DISPLAY_WIDTH, target.getDisplayName() + " (" + ash.getAimingLocation() + ")");
clientgui.getUnitDisplay().wPan.wTargetR.setText(t);
clientgui.getUnitDisplay().wPan.setTarget(target, Messages.getFormattedString("MechDisplay.AimingAt", ash.getAimingLocation()));
} else {
toHit = WeaponAttackAction.toHit(game, cen, target, weaponId, Entity.LOC_NONE,
AimingMode.NONE, false);
String t = String.format("<html><div WIDTH=%d>%s</div></html>", WeaponPanel.TARGET_DISPLAY_WIDTH, target.getDisplayName());
clientgui.getUnitDisplay().wPan.wTargetR.setText(t);
clientgui.getUnitDisplay().wPan.setTarget(target, null);

}
ash.setPartialCover(toHit.getCover());
} else {
toHit = WeaponAttackAction.toHit(game, cen, target, weaponId,
Entity.LOC_NONE, AimingMode.NONE, false);
String t = String.format("<html><div WIDTH=%d>%s</div></html>", WeaponPanel.TARGET_DISPLAY_WIDTH, target.getDisplayName());
clientgui.getUnitDisplay().wPan.wTargetR.setText(t);
clientgui.getUnitDisplay().wPan.setTarget(target, null);
}
int effectiveDistance = Compute.effectiveDistance(game, ce(), target);
clientgui.getUnitDisplay().wPan.wRangeR.setText("" + effectiveDistance);
Expand All @@ -1958,38 +1959,33 @@ public void updateTarget() {
clientgui.getUnitDisplay().wPan.selectWeapon(weaponId);
}
if (m.isUsedThisRound()) {
clientgui.getUnitDisplay().wPan.wToHitR.setText(
Messages.getString("FiringDisplay.alreadyFired"));
clientgui.getUnitDisplay().wPan.setToHit(Messages.getString("FiringDisplay.alreadyFired"));
setFireEnabled(false);
} else if ((m.getType().hasFlag(WeaponType.F_AUTO_TARGET)
&& !m.curMode().equals(Weapon.MODE_AMS_MANUAL))
|| (m.getType().hasModes() && m.curMode().equals("Point Defense"))) {
clientgui.getUnitDisplay().wPan.wToHitR.setText(
Messages.getString("FiringDisplay.autoFiringWeapon"));
clientgui.getUnitDisplay().wPan.setToHit(Messages.getString("FiringDisplay.autoFiringWeapon"));
setFireEnabled(false);
} else if (m.isInBearingsOnlyMode()) {
clientgui.getUnitDisplay().wPan.wToHitR.setText(
Messages.getString("FiringDisplay.bearingsOnlyWrongPhase"));
clientgui.getUnitDisplay().wPan.setToHit(Messages.getString("FiringDisplay.bearingsOnlyWrongPhase"));
setFireEnabled(false);
} else if (toHit.getValue() == TargetRoll.IMPOSSIBLE) {
clientgui.getUnitDisplay().wPan.wToHitR.setText(toHit.getValueAsString());
clientgui.getUnitDisplay().wPan.setToHit(toHit);
setFireEnabled(false);
} else if (toHit.getValue() == TargetRoll.AUTOMATIC_FAIL) {
clientgui.getUnitDisplay().wPan.wToHitR.setText(toHit.getValueAsString());
clientgui.getUnitDisplay().wPan.setToHit(toHit);
setFireEnabled(true);
} else {
boolean natAptGunnery = ce().hasAbility(OptionsConstants.PILOT_APTITUDE_GUNNERY);
clientgui.getUnitDisplay().wPan.wToHitR.setText(toHit.getValueAsString()
+ " (" + Compute.oddsAbove(toHit.getValue(), natAptGunnery) + "%)");
clientgui.getUnitDisplay().wPan.setToHit(toHit, true);

setFireEnabled(true);
}
clientgui.getUnitDisplay().wPan.toHitText.setText(toHit.getDesc());
setSkipEnabled(true);
} else {
clientgui.getUnitDisplay().wPan.wTargetR.setText("---");
clientgui.getUnitDisplay().wPan.setTarget(null, null);
clientgui.getUnitDisplay().wPan.wRangeR.setText("---");
clientgui.getUnitDisplay().wPan.wToHitR.setText("---");
clientgui.getUnitDisplay().wPan.toHitText.setText("");
clientgui.getUnitDisplay().wPan.clearToHit();
}

if ((weaponId != -1) && (ce() != null) && !isStrafing) {
Expand All @@ -2010,7 +2006,7 @@ public void updateTarget() {
setFindClubEnabled(false);
setFlipArmsEnabled(false);
setStrafeEnabled(false);
clientgui.getUnitDisplay().wPan.toHitText.setText("Hidden units are only allowed to spot!");
clientgui.getUnitDisplay().wPan.setToHit("Hidden units are only allowed to spot!");
}
}

Expand Down
29 changes: 11 additions & 18 deletions megamek/src/megamek/client/ui/swing/PointblankShotDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -860,24 +860,20 @@ public void updateTarget() {
toHit = WeaponAttackAction.toHit(game, cen, target,
weaponId, ash.getAimingAt(), ash.getAimingMode(),
false, false, null, null, false, true);
String t = String.format("<html><div WIDTH=%d>%s</div></html>", WeaponPanel.TARGET_DISPLAY_WIDTH, target.getDisplayName() + " (" + ash.getAimingLocation() + ")");
clientgui.getUnitDisplay().wPan.wTargetR.setText(t);
clientgui.getUnitDisplay().wPan.setTarget(target, Messages.getFormattedString("MechDisplay.AimingAt", ash.getAimingLocation()));

} else {
toHit = WeaponAttackAction.toHit(game, cen, target, weaponId, Entity.LOC_NONE,
AimingMode.NONE, false, false,
null, null, false, true);

String t = String.format("<html><div WIDTH=%d>%s</div></html>", WeaponPanel.TARGET_DISPLAY_WIDTH, target.getDisplayName());
clientgui.getUnitDisplay().wPan.wTargetR.setText(t);
clientgui.getUnitDisplay().wPan.setTarget(target, null);
}
ash.setPartialCover(toHit.getCover());
} else {
toHit = WeaponAttackAction.toHit(game, cen, target, weaponId, Entity.LOC_NONE,
AimingMode.NONE, false, false, null,
null, false, true);

String t = String.format("<html><div WIDTH=%d>%s</div></html>", WeaponPanel.TARGET_DISPLAY_WIDTH, target.getDisplayName());
clientgui.getUnitDisplay().wPan.wTargetR.setText(t);
clientgui.getUnitDisplay().wPan.setTarget(target, null);
}
int effectiveDistance = Compute.effectiveDistance(game, ce(), target);
clientgui.getUnitDisplay().wPan.wRangeR.setText("" + effectiveDistance);
Expand All @@ -889,30 +885,27 @@ public void updateTarget() {
}

if (m.isUsedThisRound()) {
clientgui.getUnitDisplay().wPan.wToHitR.setText(Messages.getString("FiringDisplay.alreadyFired"));
clientgui.getUnitDisplay().wPan.setToHit(Messages.getString("FiringDisplay.alreadyFired"));
setFireEnabled(false);
} else if ((m.getType().hasFlag(WeaponType.F_AUTO_TARGET) && !m.curMode().equals(Weapon.MODE_AMS_MANUAL))) {
clientgui.getUnitDisplay().wPan.wToHitR.setText(Messages.getString("FiringDisplay.autoFiringWeapon"));
clientgui.getUnitDisplay().wPan.setToHit(Messages.getString("FiringDisplay.autoFiringWeapon"));
setFireEnabled(false);
} else if (toHit.getValue() == TargetRoll.IMPOSSIBLE) {
clientgui.getUnitDisplay().wPan.wToHitR.setText(toHit.getValueAsString());
clientgui.getUnitDisplay().wPan.setToHit(toHit);
setFireEnabled(false);
} else if (toHit.getValue() == TargetRoll.AUTOMATIC_FAIL) {
clientgui.getUnitDisplay().wPan.wToHitR.setText(toHit.getValueAsString());
clientgui.getUnitDisplay().wPan.setToHit(toHit);
setFireEnabled(true);
} else {
boolean natAptGunnery = ce().hasAbility(OptionsConstants.PILOT_APTITUDE_GUNNERY);
clientgui.getUnitDisplay().wPan.wToHitR.setText(toHit.getValueAsString()
+ " (" + Compute.oddsAbove(toHit.getValue(), natAptGunnery) + "%)");
clientgui.getUnitDisplay().wPan.setToHit(toHit, natAptGunnery);
setFireEnabled(true);
}
clientgui.getUnitDisplay().wPan.toHitText.setText(toHit.getDesc());
setSkipEnabled(true);
} else {
clientgui.getUnitDisplay().wPan.wTargetR.setText("---");
clientgui.getUnitDisplay().wPan.setTarget(null, null);
clientgui.getUnitDisplay().wPan.wRangeR.setText("---");
clientgui.getUnitDisplay().wPan.wToHitR.setText("---");
clientgui.getUnitDisplay().wPan.toHitText.setText("");
clientgui.getUnitDisplay().wPan.clearToHit();
}

if ((weaponId != -1) && (ce() != null)) {
Expand Down
10 changes: 5 additions & 5 deletions megamek/src/megamek/client/ui/swing/TargetChoiceDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,19 @@ protected TargetChoiceDialog(JFrame frame, String title, String message,

@Override
protected void detailLabel(JToggleButton button, Targetable target) {
String div = "<DIV WIDTH=" + UIUtil.scaleForGUI(500) + ">" + infoText(target) + UnitToolTip.getTargetTipDetail(target,
clientGUI.getClient().getBoard(), clientGUI) + "</DIV>";
String div = "<DIV WIDTH=" + UIUtil.scaleForGUI(500) + ">" + infoText(target) + " " + UnitToolTip.getTargetTipDetail(target,
clientGUI.getClient()) + "</DIV>";
button.setText("<html>" + div + "</html>");
}

@Override
protected void summaryLabel(JToggleButton button, Targetable target) {
button.setText("<html>" + infoText(target) + UnitToolTip.getTargetTipSummary(target,
clientGUI.getClient().getBoard()) + "</html>");
button.setText("<html>" + infoText(target) + "<BR>" + UnitToolTip.getTargetTipSummary(target,
clientGUI.getClient()) + "</html>");
}

protected String infoText(Targetable target) {
String result = "<b>" + target.getDisplayName() + "</b>";
String result = "";

if (firingEntity != null) {
ToHitData thd = WeaponAttackAction.toHit(clientGUI.getClient().getGame(), firingEntity.getId(), target);
Expand Down
23 changes: 9 additions & 14 deletions megamek/src/megamek/client/ui/swing/TargetingPhaseDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -1045,44 +1045,39 @@ public void updateTarget() {
flightTimeText = String.format("(%d turns)", aaa.getTurnsTilHit());
}

String t = String.format("<html><div WIDTH=%d>%s</div></html>", WeaponPanel.TARGET_DISPLAY_WIDTH, target.getDisplayName());
clientgui.getUnitDisplay().wPan.wTargetR.setText(t);
clientgui.getUnitDisplay().wPan.setTarget(target, null);
clientgui.getUnitDisplay().wPan.wRangeR.setText(String.format("%d %s", targetDistance, flightTimeText));

Game game = clientgui.getClient().getGame();
int distance = Compute.effectiveDistance(game, ce(), target);
if (m.isUsedThisRound()) {
clientgui.getUnitDisplay().wPan.wToHitR.setText(
clientgui.getUnitDisplay().wPan.setToHit(
Messages.getString("TargetingPhaseDisplay.alreadyFired"));
setFireEnabled(false);
} else if (m.isInBearingsOnlyMode() && distance < RangeType.RANGE_BEARINGS_ONLY_MINIMUM) {
clientgui.getUnitDisplay().wPan.wToHitR.setText(
clientgui.getUnitDisplay().wPan.setToHit(
Messages.getString("TargetingPhaseDisplay.bearingsOnlyMinRange"));
setFireEnabled(false);
} else if ((m.getType().hasFlag(WeaponType.F_AUTO_TARGET)
&& !m.curMode().equals(Weapon.MODE_AMS_MANUAL))) {
clientgui.getUnitDisplay().wPan.wToHitR.setText(
clientgui.getUnitDisplay().wPan.setToHit(
Messages.getString("TargetingPhaseDisplay.autoFiringWeapon"));
setFireEnabled(false);
} else if (toHit.getValue() == TargetRoll.IMPOSSIBLE) {
clientgui.getUnitDisplay().wPan.wToHitR.setText(toHit.getValueAsString());
clientgui.getUnitDisplay().wPan.setToHit(toHit);
setFireEnabled(false);
} else if (toHit.getValue() == TargetRoll.AUTOMATIC_FAIL) {
clientgui.getUnitDisplay().wPan.wToHitR.setText(toHit.getValueAsString());
clientgui.getUnitDisplay().wPan.setToHit(toHit);
setFireEnabled(true);
} else {
clientgui.getUnitDisplay().wPan.wToHitR.setText(toHit.getValueAsString() + " ("
+ Compute.oddsAbove(toHit.getValue(), ce().hasAbility(OptionsConstants.PILOT_APTITUDE_GUNNERY))
+ "%)");
clientgui.getUnitDisplay().wPan.setToHit(toHit, ce().hasAbility(OptionsConstants.PILOT_APTITUDE_GUNNERY));
setFireEnabled(true);
}
clientgui.getUnitDisplay().wPan.toHitText.setText(toHit.getDesc());
setSkipEnabled(true);
} else {
clientgui.getUnitDisplay().wPan.wTargetR.setText("---");
clientgui.getUnitDisplay().wPan.setTarget(null, null);
clientgui.getUnitDisplay().wPan.wRangeR.setText("---");
clientgui.getUnitDisplay().wPan.wToHitR.setText("---");
clientgui.getUnitDisplay().wPan.toHitText.setText("");
clientgui.getUnitDisplay().wPan.clearToHit();
}
updateSearchlight();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5782,7 +5782,7 @@ public void appendBuildingsTooltip(StringBuffer txt, @Nullable Hex mhex) {
if (mhex == null) {
return;
}
String result = HexTooltip.getHexTip(mhex, clientgui);
String result = HexTooltip.getHexTip(mhex, clientgui.getClient());
txt.append(result);
}

Expand Down
3 changes: 1 addition & 2 deletions megamek/src/megamek/client/ui/swing/tooltip/HexTooltip.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@

public final class HexTooltip {

public static String getHexTip(Hex mhex, @Nullable ClientGUI clientGUI) {
public static String getHexTip(Hex mhex, @Nullable Client client) {
StringBuilder result = new StringBuilder();
Coords mcoords = mhex.getCoords();
// All of the following can be null even if there's a ClientGUI!
Client client = (clientGUI != null) ? clientGUI.getClient() : null;
Game game = (client != null) ? client.getGame() : null;
Player localPlayer = (client != null) ? client.getLocalPlayer() : null;

Expand Down
Loading