Skip to content

Commit

Permalink
Merge pull request #5558 from SJuliez/name-plates
Browse files Browse the repository at this point in the history
Fixing Nameplates
  • Loading branch information
HammerGS authored Jun 8, 2024
2 parents c581945 + c4bef5a commit 06dc7ca
Showing 1 changed file with 16 additions and 13 deletions.
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

0 comments on commit 06dc7ca

Please sign in to comment.