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

Infantry Tooltip improvement #3927

Merged
merged 1 commit into from
Oct 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions megamek/src/megamek/client/ui/swing/tooltip/UnitToolTip.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,16 @@ private static StringBuilder getEntityTipTable(Entity entity, Player localPlayer
return result;
}

private static boolean hideArmorLocation(Entity entity, int location) {
return ((entity.getOArmor(location) <= 0) && (entity.getOInternal(location) <= 0) && !entity.hasRearArmor(location))
|| (entity.isConventionalInfantry() && (location != Infantry.LOC_INFANTRY));
}

private static String locationHeader(Entity entity, int location) {
return entity.isConventionalInfantry() ?
((Infantry) entity).getShootingStrength() + " Active Troopers" : entity.getLocationAbbr(location);
}

/** Returns the graphical Armor representation. */
private static StringBuilder addArmorMiniVisToTT(Entity entity) {
GUIPreferences guip = GUIPreferences.getInstance();
Expand All @@ -186,7 +196,7 @@ private static StringBuilder addArmorMiniVisToTT(Entity entity) {
result.append("<TABLE CELLSPACING=0 CELLPADDING=0><TBODY>");
for (int loc = 0 ; loc < entity.locations(); loc++) {
// do not show locations that do not support/have armor/internals like HULL on Aero
if (entity.getOArmor(loc) <= 0 && entity.getOInternal(loc) <= 0 && !entity.hasRearArmor(loc)) {
if (hideArmorLocation(entity, loc)) {
continue;
}
result.append("<TR><TD>");
Expand All @@ -195,7 +205,7 @@ private static StringBuilder addArmorMiniVisToTT(Entity entity) {
// Destroyed location
result.append("</TD><TD></TD><TD>");
result.append(guiScaledFontHTML(TT_SMALLFONT_DELTA));
result.append("&nbsp;&nbsp;" + entity.getLocationAbbr(loc)+ ":&nbsp;");
result.append("&nbsp;&nbsp;" + locationHeader(entity, loc) + ":&nbsp;");
result.append("</FONT></TD><TD>");
result.append(guiScaledFontHTML(colorDamaged, TT_SMALLFONT_DELTA));
result.append(destroyedLocBar(entity.getOArmor(loc, true)));
Expand All @@ -204,7 +214,7 @@ private static StringBuilder addArmorMiniVisToTT(Entity entity) {
// Rear armor
if (entity.hasRearArmor(loc)) {
result.append(guiScaledFontHTML(TT_SMALLFONT_DELTA));
result.append("&nbsp;&nbsp;" + entity.getLocationAbbr(loc)+ "R:&nbsp;");
result.append("&nbsp;&nbsp;" + locationHeader(entity, loc) + "R:&nbsp;");
result.append("</FONT></TD><TD>");
result.append(intactLocBar(entity.getOArmor(loc, true), entity.getArmor(loc, true), armorChar));
result.append("</TD><TD>");
Expand All @@ -217,7 +227,7 @@ private static StringBuilder addArmorMiniVisToTT(Entity entity) {
}
// Front armor
result.append(guiScaledFontHTML(TT_SMALLFONT_DELTA));
result.append("&nbsp;&nbsp;" + entity.getLocationAbbr(loc)+ ":&nbsp;");
result.append("&nbsp;&nbsp;" + locationHeader(entity, loc) + ":&nbsp;");
result.append("</FONT></TD><TD>");
result.append(intactLocBar(entity.getOInternal(loc), entity.getInternal(loc), internalChar));
result.append(intactLocBar(entity.getOArmor(loc), entity.getArmor(loc), armorChar));
Expand Down Expand Up @@ -784,7 +794,9 @@ private static StringBuilder entityValues(Entity entity) {
}

// Armor and Internals
if (!isGunEmplacement) {
if (entity.isConventionalInfantry()) {
result.append("<BR>");
} else if (!isGunEmplacement) {
String armorType = TROView.formatArmorType(entity, true).replace("UNKNOWN", "");
if (!armorType.isBlank()) {
armorType = (entity.isCapitalScale() ? getString("BoardView1.Tooltip.ArmorCapital") + " " : "") + armorType;
Expand Down