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

Fixing Nameplates #5558

Merged
merged 1 commit into from
Jun 8, 2024
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
29 changes: 16 additions & 13 deletions megamek/src/megamek/client/ui/swing/boardview/EntitySprite.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class EntitySprite extends Sprite {
private static final int MAX_TMM_PIPS = 6;
private static final int TMM_PIP_SIZE = STATUS_BAR_LENGTH / MAX_TMM_PIPS;
private static final boolean DIRECT = true;
private static final Color LABEL_TEXT_COLOR = Color.WHITE;
private static final Color LABEL_CRITICAL_BACK = new Color(200, 0, 0, 200);
private static final Color LABEL_SPACE_BACK = new Color(0, 0, 200, 200);
private static final Color LABEL_GROUND_BACK = new Color(50, 50, 50, 200);
Expand Down Expand Up @@ -77,7 +76,7 @@ enum Positioning { LEFT, RIGHT }
"Wheeled", "Command", "Standard", "Hover", "Hovercraft", "Mechanized",
"(Standard)", "Platoon", "Transport", "Vehicle", "Air",
"Assault", "Mobile", "Platform", "Battle Armor", "Vessel", "Infantry",
"Fighting", "Fire", "Suport", "Reconnaissance", "Fast");
"Fighting", "Fire", "Support", "Reconnaissance", "Fast");

private static final GUIPreferences GUIP = GUIPreferences.getInstance();

Expand Down Expand Up @@ -114,20 +113,20 @@ private String getAdjShortName() {
case ABBREV:
return (entity instanceof Mech) ? entity.getModel() : abbreviateUnitName(standardLabelName());
case CHASSIS:
return reduceVehicleName(entity.getChassis());
return reduceVehicleName(entity);
case NICKNAME:
if (!pilotNick().isBlank()) {
return "\"" + pilotNick().toUpperCase() + "\"";
} else if (!unitNick().isBlank()) {
return "\'" + unitNick() + "\'";
return "'" + unitNick() + "'";
} else {
return reduceVehicleName(entity.getChassis());
return reduceVehicleName(entity);
}
case ONLY_NICKNAME:
if (!pilotNick().isBlank()) {
return "\"" + pilotNick().toUpperCase() + "\"";
} else if (!unitNick().isBlank()) {
return "\'" + unitNick() + "\'";
return "'" + unitNick() + "'";
} else {
return "";
}
Expand All @@ -143,15 +142,19 @@ private String getAdjShortName() {
* until something is encountered that is not contained in that list.
* On Mech names this will typically have no effect.
*/
private static String reduceVehicleName(String unitName) {
String[] tokens = unitName.split(" ");
int i = tokens.length - 1;
for ( ; i > 0; i--) {
if (!REMOVABLE_NAME_PARTS.contains(tokens[i])) {
break;
private static String reduceVehicleName(Entity entity) {
if (!entity.isVehicle()) {
return entity.getChassis();
} else {
String[] tokens = entity.getChassis().split(" ");
int i = tokens.length - 1;
for (; i > 0; i--) {
if (!REMOVABLE_NAME_PARTS.contains(tokens[i])) {
break;
}
}
return String.join(" ", Arrays.copyOfRange(tokens, 0, i + 1));
}
return String.join(" ", Arrays.copyOfRange(tokens, 0, i + 1));
}

/** Returns the string with some content shortened like Battle Armor -> BA */
Expand Down
Loading