diff --git a/megamek/i18n/megamek/client/messages.properties b/megamek/i18n/megamek/client/messages.properties index dc3c2703c6..ec2d085035 100644 --- a/megamek/i18n/megamek/client/messages.properties +++ b/megamek/i18n/megamek/client/messages.properties @@ -1139,8 +1139,6 @@ CommonSettingsDialog.armorMiniCriticalChar.tooltip=The character representing bl CommonSettingsDialog.armorMiniCriticalChar=Critical Character: CommonSettingsDialog.armorMiniDestroyedChar.tooltip=The character representing a destroyed component when hovering the mouse over a unit. CommonSettingsDialog.armorMiniDestroyedChar=Destroyed Character: -CommonSettingsDialog.armorMiniFontSizeMod.tooltip=Font Size Modifier of the Armor mini display -CommonSettingsDialog.armorMiniFontSizeMod=Font Size Mod: CommonSettingsDialog.armorMiniInternalStructureChar.tooltip=The character representing blocks of internal structure when hovering the mouse over a unit. CommonSettingsDialog.armorMiniInternalStructureChar=Internal Structure Character: CommonSettingsDialog.armorMiniUnitsPerBlock.tooltip=The number of armor or IS points represented by each character "block" in the tooltip. @@ -1363,6 +1361,8 @@ CommonSettingsDialog.unitDisplay=Unit Tooltip / Unit Display CommonSettingsDialog.unitDisplayHeatToolTip=Max heat value for each level CommonSettingsDialog.unitTooltipMaxWidth=Max Width for Unit Tooltip CommonSettingsDialog.unitTooltipMaxWidth.tooltip=keeps tool tip from growing too wide +CommonSettingsDialog.unitTooltipFontSizeMod.tooltip=Font size modifier of the Unit Tool Tip +CommonSettingsDialog.unitTooltipFontSizeMod=Unit Tool Tip font size mod: CommonSettingsDialog.useAverageSkills=Use the current random skill settings when adding units in the lobby. CommonSettingsDialog.useGPinUnitSelection=Display Gunnery and Piloting in Unit Selection screen for BV/PV CommonSettingsDialog.useAutoCenter=Use automatic unit centering on the board diff --git a/megamek/src/megamek/client/ui/swing/CommonSettingsDialog.java b/megamek/src/megamek/client/ui/swing/CommonSettingsDialog.java index 7bb4f96e7d..431ca7b313 100644 --- a/megamek/src/megamek/client/ui/swing/CommonSettingsDialog.java +++ b/megamek/src/megamek/client/ui/swing/CommonSettingsDialog.java @@ -400,7 +400,7 @@ private void moveElement(DefaultListModel srcModel, int srcIndex, int trg private JTextField unitTooltipArmorMiniCriticalCharText; private JTextField unitTooltipArmorMiniDestroyedCharText; private JTextField unitTooltipArmorMiniCapArmorCharText; - private JTextField unitTooltipArmorMiniFontSizeModText; + private JComboBox unitTooltipFontSizeModCbo; private JTextField unitTooltipArmorMiniUnitsPerBlockText; private JTextField unitDisplayMekArmorLargeFontSizeText; private JTextField unitDisplayMekArmorMediumFontSizeText; @@ -1113,6 +1113,24 @@ private JPanel getUnitDisplayPanel() { row.add(tooltipDistSupression); comps.add(row); + JLabel unitTooltipFontSizeModLabel = new JLabel( + Messages.getString("CommonSettingsDialog.unitTooltipFontSizeMod")); + + unitTooltipFontSizeModCbo = new JComboBox<>(); + unitTooltipFontSizeModCbo.addItem("large"); + unitTooltipFontSizeModCbo.addItem("medium"); + unitTooltipFontSizeModCbo.addItem("small"); + unitTooltipFontSizeModCbo.addItem("x-small"); + unitTooltipFontSizeModCbo.addItem("xx-small"); + unitTooltipFontSizeModCbo.setSelectedItem(GUIP.getUnitToolTipFontSizeMod()); + unitTooltipFontSizeModCbo.setMaximumSize(new Dimension(300, 60)); + + unitTooltipFontSizeModCbo.setToolTipText(Messages.getString("CommonSettingsDialog.unitTooltipFontSizeMod.tooltip")); + row = new ArrayList<>(); + row.add(unitTooltipFontSizeModLabel); + row.add(unitTooltipFontSizeModCbo); + comps.add(row); + comps.add(checkboxEntry(showWpsinTT, null)); comps.add(checkboxEntry(showWpsLocinTT, null)); comps.add(checkboxEntry(showPilotPortraitTT, null)); @@ -1270,18 +1288,6 @@ private JPanel getUnitDisplayPanel() { row.add(unitTooltipArmorMiniUnitsPerBlockText); comps.add(row); - JLabel unitTooltipFontSizeModLabel = new JLabel( - Messages.getString("CommonSettingsDialog.armorMiniFontSizeMod")); - unitTooltipArmorMiniFontSizeModText = new JTextField(5); - unitTooltipArmorMiniFontSizeModText.setText(String.format("%d", GUIP.getUnitToolTipArmorMiniFontSizeMod())); - unitTooltipArmorMiniFontSizeModText.setMaximumSize(new Dimension(150, 40)); - unitTooltipArmorMiniFontSizeModText - .setToolTipText(Messages.getString("CommonSettingsDialog.armorMiniFontSizeMod.tooltip")); - row = new ArrayList<>(); - row.add(unitTooltipFontSizeModLabel); - row.add(unitTooltipArmorMiniFontSizeModText); - comps.add(row); - addLineSpacer(comps); JLabel unitTooltipSeenbyLabel = new JLabel(Messages.getString("CommonSettingsDialog.seenby.label")); @@ -2241,7 +2247,7 @@ protected void cancelAction() { unitTooltipArmorMiniDestroyedCharText.setText(GUIP.getUnitToolTipArmorMiniDestoryedChar()); unitTooltipArmorMiniCapArmorCharText.setText(GUIP.getUnitToolTipArmorMiniCapArmorChar()); unitTooltipArmorMiniUnitsPerBlockText.setText(String.format("%d", GUIP.getUnitToolTipArmorMiniUnitsPerBlock())); - unitTooltipArmorMiniFontSizeModText.setText(String.format("%d", GUIP.getUnitToolTipArmorMiniFontSizeMod())); + unitTooltipFontSizeModCbo.setSelectedItem(GUIP.getUnitToolTipFontSizeMod()); csbReportLinkColor.setColour(GUIP.getReportLinkColor()); csbReportSuccessColor.setColour(GUIP.getReportSuccessColor()); @@ -2732,7 +2738,7 @@ protected void okAction() { logger.error(ex, ""); } try { - GUIP.setUnitToolTipArmorMiniFontSize(Integer.parseInt(unitTooltipArmorMiniFontSizeModText.getText())); + GUIP.setUnitToolTipFontSize((String) unitTooltipFontSizeModCbo.getSelectedItem()); } catch (Exception ex) { logger.error(ex, ""); } diff --git a/megamek/src/megamek/client/ui/swing/GUIPreferences.java b/megamek/src/megamek/client/ui/swing/GUIPreferences.java index 2e5165a9ab..eab9def9a7 100644 --- a/megamek/src/megamek/client/ui/swing/GUIPreferences.java +++ b/megamek/src/megamek/client/ui/swing/GUIPreferences.java @@ -195,7 +195,7 @@ public class GUIPreferences extends PreferenceStoreProxy { public static final String UNIT_TOOLTIP_ARMORMINI_COLOR_INTACT = "UnitToolTipArmorMiniColorIntact"; public static final String UNIT_TOOLTIP_ARMORMINI_COLOR_PARTIAL_DMG = "UnitToolTipArmorMiniColorPartialDmg"; public static final String UNIT_TOOLTIP_ARMORMINI_COLOR_DAMAGED = "UnitToolTipArmorMiniColorDamaged"; - public static final String UNIT_TOOLTIP_ARMORMINI_FONT_SIZE_MOD = "UnitToolTipArmorMiniFrontSizeMod"; + public static final String UNIT_TOOLTIP_FONT_SIZE_MOD = "UnitToolTipFrontSizeMod"; public static final String UNIT_TOOLTIP_FGCOLOR = "UnitToolTipFGColor"; public static final String UNIT_TOOLTIP_LIGHT_FGCOLOR = "UnitToolTipLightFGColor"; @@ -616,7 +616,7 @@ protected GUIPreferences() { setDefault(UNIT_TOOLTIP_ARMORMINI_COLOR_INTACT, DEFAULT_MEDIUM_GREEN); setDefault(UNIT_TOOLTIP_ARMORMINI_COLOR_PARTIAL_DMG, DEFAULT_MEDIUM_YELLOW); setDefault(UNIT_TOOLTIP_ARMORMINI_COLOR_DAMAGED, DEFAULT_MEDIUM_DARK_RED); - store.setDefault(UNIT_TOOLTIP_ARMORMINI_FONT_SIZE_MOD, -2); + store.setDefault(UNIT_TOOLTIP_FONT_SIZE_MOD, "medium"); setDefault(UNIT_TOOLTIP_FGCOLOR, new Color(0xEEE6D9)); setDefault(UNIT_TOOLTIP_LIGHT_FGCOLOR, new Color(0x000000)); setDefault(UNIT_TOOLTIP_BUILDING_FGCOLOR, new Color(0x000000)); @@ -2934,8 +2934,8 @@ public int getUnitToolTipArmorMiniUnitsPerBlock() { return getInt(UNIT_TOOLTIP_ARMORMINI_UNITS_PER_BLOCK); } - public int getUnitToolTipArmorMiniFontSizeMod() { - return getInt(UNIT_TOOLTIP_ARMORMINI_FONT_SIZE_MOD); + public String getUnitToolTipFontSizeMod() { + return getString(UNIT_TOOLTIP_FONT_SIZE_MOD); } public Color getUnitToolTipFGColor() { @@ -3146,8 +3146,8 @@ public void setUnitTooltipArmorMiniUnitsPerBlock(int i) { store.setValue(UNIT_TOOLTIP_ARMORMINI_UNITS_PER_BLOCK, i); } - public void setUnitToolTipArmorMiniFontSize(int i) { - store.setValue(UNIT_TOOLTIP_ARMORMINI_FONT_SIZE_MOD, i); + public void setUnitToolTipFontSize(String s) { + store.setValue(UNIT_TOOLTIP_FONT_SIZE_MOD, s); } public void setUnitToolTipFGColor(Color c) { diff --git a/megamek/src/megamek/client/ui/swing/boardview/AbstractWreckSprite.java b/megamek/src/megamek/client/ui/swing/boardview/AbstractWreckSprite.java index 98f5cf48a1..68dd670c90 100644 --- a/megamek/src/megamek/client/ui/swing/boardview/AbstractWreckSprite.java +++ b/megamek/src/megamek/client/ui/swing/boardview/AbstractWreckSprite.java @@ -42,16 +42,16 @@ public abstract class AbstractWreckSprite extends Sprite { protected Rectangle modelRect; protected int secondaryPos; - + public AbstractWreckSprite(BoardView boardView1) { super(boardView1); } - + @Override public Rectangle getBounds() { // Start with the hex and add the label bounds = new Rectangle(0, 0, bv.hex_size.width, bv.hex_size.height); - + // Move to board position, save this origin for correct drawing Point hexOrigin = bounds.getLocation(); Point ePos; @@ -65,6 +65,10 @@ public Rectangle getBounds() { return bounds; } + public Entity getEntity() { + return entity; + } + /** * Creates the sprite for this entity. It is an extra pain to create * transparent images in AWT. @@ -74,13 +78,13 @@ public void prepare() { // create image for buffer image = ImageUtil.createAcceleratedImage(HexTileset.HEX_W, HexTileset.HEX_H); Graphics2D graph = (Graphics2D) image.getGraphics(); - + // if the entity is underwater or would sink underwater, we want to make the wreckage translucent // so it looks like it sunk boolean entityIsUnderwater = (entity.relHeight() < 0) || ((entity.relHeight() >= 0) && entity.getGame().getBoard().getHex(entity.getPosition()).containsTerrain(Terrains.WATER)) && !EntityWreckHelper.entityOnBridge(entity); - + if (entityIsUnderwater) { graph.setComposite(AlphaComposite.getInstance( AlphaComposite.SRC_OVER, 0.35f)); @@ -88,44 +92,44 @@ public void prepare() { // draw the 'destroyed decal' where appropriate boolean displayDestroyedDecal = EntityWreckHelper.displayDestroyedDecal(entity); - + if (displayDestroyedDecal) { Image destroyed = bv.tileManager.bottomLayerWreckMarkerFor(entity, 0); if (null != destroyed) { graph.drawImage(destroyed, 0, 0, this); } } - + // draw the 'fuel leak' decal where appropriate boolean drawFuelLeak = EntityWreckHelper.displayFuelLeak(entity); - + if (drawFuelLeak) { Image fuelLeak = bv.tileManager.bottomLayerFuelLeakMarkerFor(entity); if (null != fuelLeak) { graph.drawImage(fuelLeak, 0, 0, this); } } - + // draw the 'tires' or 'tracks' decal where appropriate boolean drawMotiveWreckage = EntityWreckHelper.displayMotiveDamage(entity); - + if (drawMotiveWreckage) { Image motiveWreckage = bv.tileManager.bottomLayerMotiveMarkerFor(entity); if (null != motiveWreckage) { graph.drawImage(motiveWreckage, 0, 0, this); } } - + // Draw wreck image, if we've got one. Image wreck; - + if (EntityWreckHelper.displayDevastation(entity)) { // objects in space should not have craters wreck = entity.getGame().getBoard().inSpace() ? bv.tileManager.wreckMarkerFor(entity, secondaryPos) : bv.tileManager.getCraterFor(entity, secondaryPos); } else { - wreck = EntityWreckHelper.useExplicitWreckImage(entity) ? + wreck = EntityWreckHelper.useExplicitWreckImage(entity) ? bv.tileManager.wreckMarkerFor(entity, secondaryPos) : bv.tileManager.imageFor(entity, secondaryPos); } @@ -133,12 +137,12 @@ public void prepare() { if (null != wreck) { graph.drawImage(wreck, 0, 0, this); } - + if (entityIsUnderwater) { graph.setComposite(AlphaComposite.getInstance( AlphaComposite.SRC_OVER, 1.0f)); } - + // create final image image = bv.getScaledImage(image, false); graph.dispose(); @@ -151,7 +155,7 @@ public void prepare() { public boolean isInside(Point point) { return false; } - + public Coords getPosition() { if (secondaryPos < 0 || secondaryPos >= entity.getSecondaryPositions().size()) { return entity.getPosition(); @@ -159,11 +163,11 @@ public Coords getPosition() { return entity.getSecondaryPositions().get(secondaryPos); } } - + @Override public StringBuffer getTooltip() { StringBuffer result = new StringBuffer(); - result.append(Messages.getString("BoardView1.Tooltip.Wreckof")); + result.append(Messages.getString("BoardView1.Tooltip.Wreckof") + " "); result.append(entity.getChassis()); result.append(MessageFormat.format(" ({0})", entity.getOwner().getName())); if (PreferenceManager.getClientPreferences().getShowUnitId()) { diff --git a/megamek/src/megamek/client/ui/swing/boardview/BoardView.java b/megamek/src/megamek/client/ui/swing/boardview/BoardView.java index 82a3c2df41..ae72e13eca 100644 --- a/megamek/src/megamek/client/ui/swing/boardview/BoardView.java +++ b/megamek/src/megamek/client/ui/swing/boardview/BoardView.java @@ -2288,7 +2288,7 @@ private void drawOrthograph(Coords c, Graphics boardGraph) { } } - boolean useIsometric() { + public boolean useIsometric() { return drawIsometric; } @@ -5156,11 +5156,11 @@ FovHighlightingAndDarkening getFovHighlighting() { return fovHighlightingAndDarkening; } - ArrayList getWreckSprites() { + public ArrayList getWreckSprites() { return wreckSprites; } - ArrayList getIsoWreckSprites() { + public ArrayList getIsoWreckSprites() { return isometricWreckSprites; } diff --git a/megamek/src/megamek/client/ui/swing/boardview/FlareSprite.java b/megamek/src/megamek/client/ui/swing/boardview/FlareSprite.java index 3fe9387fd2..79db7c733a 100644 --- a/megamek/src/megamek/client/ui/swing/boardview/FlareSprite.java +++ b/megamek/src/megamek/client/ui/swing/boardview/FlareSprite.java @@ -29,7 +29,7 @@ /** * A Sprite for a flare, as the name indicates. */ -class FlareSprite extends Sprite { +public class FlareSprite extends Sprite { private static final String FILENAME_FLARE_IMAGE = "flare.png"; private static final Image FLARE_IMAGE; @@ -63,4 +63,4 @@ public void prepare() { } public StringBuffer getTooltip() { return new StringBuffer(Messages.getString("BoardView1.flare", flare.turnsToBurn)); } -} \ No newline at end of file +} diff --git a/megamek/src/megamek/client/ui/swing/boardview/TWBoardViewTooltip.java b/megamek/src/megamek/client/ui/swing/boardview/TWBoardViewTooltip.java index 02616672e3..4557e87b92 100644 --- a/megamek/src/megamek/client/ui/swing/boardview/TWBoardViewTooltip.java +++ b/megamek/src/megamek/client/ui/swing/boardview/TWBoardViewTooltip.java @@ -20,7 +20,7 @@ import static megamek.client.ui.swing.util.UIUtil.uiWhite; -import java.awt.Point; +import java.awt.*; import java.util.ArrayList; import java.util.Collection; import java.util.Enumeration; @@ -63,6 +63,8 @@ public String getTooltip(Point point, Coords movementTarget) { if (!game.getBoard().contains(coords)) { return null; } + + String fontSizeAttr = String.format("class=%s", GUIP.getUnitToolTipFontSizeMod()); Entity selectedEntity = (clientGui != null) ? clientGui.getDisplayedUnit() : null; Player localPlayer = localPlayer(); Hex mhex = game.getBoard().getHex(coords); @@ -78,52 +80,41 @@ public String getTooltip(Point point, Coords movementTarget) { // Distance from the selected unit and a planned movement end point if ((selectedEntity != null) && (selectedEntity.getPosition() != null) && !selectedEntity.isOffBoard()) { int distance = selectedEntity.getPosition().distance(coords); - if (distance == 1) { - sTerrain += Messages.getString("BoardView1.Tooltip.Distance1"); - } else { - sTerrain += Messages.getString("BoardView1.Tooltip.DistanceN", distance); - } + + sTerrain += HexTooltip. getDistanceTip(GUIP, distance); + + int maxSensorRange = 0; + int minSensorRange = 0; if (game.getOptions().booleanOption(OptionsConstants.ADVANCED_TACOPS_SENSORS)) { LosEffects los = bv.getFovHighlighting().getCachedLosEffects(selectedEntity.getPosition(), coords); int bracket = Compute.getSensorRangeBracket(selectedEntity, null, - bv.getFovHighlighting().cachedAllECMInfo); + bv.getFovHighlighting().cachedAllECMInfo); int range = Compute.getSensorRangeByBracket(game, selectedEntity, null, los); - int maxSensorRange = bracket * range; - int minSensorRange = Math.max((bracket - 1) * range, 0); + maxSensorRange = bracket * range; + minSensorRange = Math.max((bracket - 1) * range, 0); if (game.getOptions().booleanOption(OptionsConstants.ADVANCED_INCLUSIVE_SENSOR_RANGE)) { minSensorRange = 0; } - sTerrain += "
"; - if ((distance > minSensorRange) && (distance <= maxSensorRange)) { - sTerrain += Messages.getString("BoardView1.Tooltip.SensorsHexInRange"); - } else { - sTerrain += Messages.getString("BoardView1.Tooltip.SensorsHexNotInRange1"); - String tmp = Messages.getString("BoardView1.Tooltip.SensorsHexNotInRange2"); - sTerrain += UIUtil.fontHTML(GUIP.getWarningColor()) + tmp + ""; - sTerrain += Messages.getString("BoardView1.Tooltip.SensorsHexNotInRange3"); - } } + boolean isMovement = false; + int disPM = 0; if (game.getPhase().isMovement() && (movementTarget != null)) { - sTerrain += "
"; - int disPM = movementTarget.distance(coords); - String sDinstanceMove = ""; - if (disPM == 1) { - sDinstanceMove = Messages.getString("BoardView1.Tooltip.DistanceMove1"); - } else { - sDinstanceMove = Messages.getString("BoardView1.Tooltip.DistanceMoveN", disPM); - } - sTerrain += "" + sDinstanceMove + ""; + + disPM = movementTarget.distance(coords); + isMovement = true; } - } - sTerrain = UIUtil.fontHTML(GUIP.getUnitToolTipTerrainFGColor()) + sTerrain + "
"; - String col = "" + sTerrain + ""; - String row = "" + col + ""; - String table = "" + row + "
"; + sTerrain += HexTooltip.getSensorRangeTip(GUIP, distance, minSensorRange, maxSensorRange, disPM, isMovement); + } + String attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString(GUIP.getUnitToolTipTerrainFGColor())); + sTerrain = UIUtil.tag("FONT", attr, sTerrain); + String col = UIUtil.tag("TD", "", sTerrain); + String row = UIUtil.tag("TR", "", col); + attr = String.format("BORDER=0 BGCOLOR=%s width=100%%", GUIPreferences.hexColor(GUIP.getUnitToolTipTerrainBGColor())); + String table = UIUtil.tag("TABLE", attr, row); result += table; StringBuffer sbBuildings = new StringBuffer(); @@ -136,8 +127,13 @@ public String getTooltip(Point point, Coords movementTarget) { String sInvalidHex = Messages.getString("BoardView1.invalidHex"); sInvalidHex += "
"; sInvalidHex += String.join("
", errors); - sInvalidHex = UIUtil.fontHTML(GUIP.getUnitToolTipFGColor()) + sInvalidHex + ""; - result += "
" + sInvalidHex; + attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString((GUIP.getUnitToolTipTerrainFGColor()))); + sInvalidHex += UIUtil.tag("FONT", attr, sInvalidHex); + sInvalidHex = UIUtil.tag("span", fontSizeAttr, sInvalidHex); + col = UIUtil.tag("TD", "", sInvalidHex); + row = UIUtil.tag("TR", "", col); + attr = String.format("BORDER=0 BGCOLOR=%s width=100%%", GUIPreferences.hexColor(GUIP.getUnitToolTipTerrainBGColor())); + result += UIUtil.tag("TABLE", attr, row); } } } @@ -145,71 +141,14 @@ public String getTooltip(Point point, Coords movementTarget) { // Show the player(s) that may deploy here // in the artillery autohit designation phase if (game.getPhase().isSetArtilleryAutohitHexes() && (mhex != null)) { - String sAttilleryAutoHix = ""; - boolean foundPlayer = false; - for (Player player : game.getPlayersList()) { - // loop through all players - if (game.getBoard().isLegalDeployment(coords, player)) { - if (!foundPlayer) { - foundPlayer = true; - sAttilleryAutoHix += Messages.getString("BoardView1.Tooltip.ArtyAutoHeader") + "
"; - } - - String sName = "  " + player.getName(); - sName = UIUtil.fontHTML(player.getColour().getColour()) + sName + ""; - sAttilleryAutoHix += "" + sName + ""; - sAttilleryAutoHix += "
"; - } - } - if (foundPlayer) { - sAttilleryAutoHix += "
"; - } - - // Add a hint with keybind that the zones can be shown graphically - String keybindText = KeyCommandBind.getDesc(KeyCommandBind.getBindByCmd("autoArtyDeployZone")); - String msg_artyautohit = Messages.getString("BoardView1.Tooltip.ArtyAutoHint1") + "
"; - msg_artyautohit += Messages.getString("BoardView1.Tooltip.ArtyAutoHint2") + "
"; - msg_artyautohit += Messages.getString("BoardView1.Tooltip.ArtyAutoHint3", keybindText); - sAttilleryAutoHix += "" + msg_artyautohit + ""; - - sAttilleryAutoHix = UIUtil.fontHTML(uiWhite()) + sAttilleryAutoHix + ""; - - String col = "" + sAttilleryAutoHix + ""; - String row = "" + col + ""; - String table = "" + row + "
"; - result += table; + result += HexTooltip.getAttilleryHit(GUIP, game, coords); } // check if it's on any flares - result += bv.getAllSprites().stream() - .filter(sprite -> sprite instanceof FlareSprite) - .filter(sprite -> sprite.isInside(point)) - .map(Sprite::getTooltip) - .collect(Collectors.joining()); + result += HexTooltip.getFlares(GUIP, bv, point); // Add wreck info - var wreckList = bv.useIsometric() ? bv.getIsoWreckSprites() : bv.getWreckSprites(); - for (var wSprite : wreckList) { - if (wSprite.getPosition().equals(coords)) { - String sWreck = wSprite.getTooltip().toString(); - sWreck = UIUtil.fontHTML(GUIP.getUnitToolTipAltFGColor()) + sWreck + ""; - String col = "" + sWreck + ""; - String row = "" + col + ""; - String rows = row; - - if (!wSprite.entity.getCrew().isEjected()) { - String sPilot = PilotToolTip.getPilotTipShort(wSprite.entity, - GUIP.getshowPilotPortraitTT(), false).toString(); - col = "" + sPilot + ""; - row = "" + col + ""; - rows += row; - } - - String table = "" + rows + "
"; - result += table; - } - } + result += HexTooltip.getWrecks(GUIP, bv, coords); // Entity tooltips int entityCount = 0; @@ -242,11 +181,13 @@ public String getTooltip(Point point, Coords movementTarget) { } sUnitsInfo += " in this hex..."; - sUnitsInfo = UIUtil.fontHTML(GUIP.getUnitToolTipBlockFGColor()) + sUnitsInfo + ""; - String col = "" + sUnitsInfo + ""; - String row = "" + col + ""; - String table = "" + row + "
"; + String attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString(GUIP.getUnitToolTipBlockFGColor())); + sUnitsInfo = UIUtil.tag("FONT", attr, sUnitsInfo); + sUnitsInfo = UIUtil.tag("span", fontSizeAttr, sUnitsInfo); + String col = UIUtil.tag("TD", "", sUnitsInfo); + String row = UIUtil.tag("TR", "", col); + attr = String.format("BORDER=0 BGCOLOR=%s width=100%%", GUIPreferences.hexColor(GUIP.getUnitToolTipBlockBGColor())); + String table = UIUtil.tag("TABLE", attr, row); result += table; } @@ -254,11 +195,14 @@ public String getTooltip(Point point, Coords movementTarget) { for (AttackSprite aSprite : bv.getAttackSprites()) { if (aSprite.isInside(coords)) { String sAttackSprite = aSprite.getTooltip().toString(); - sAttackSprite = UIUtil.fontHTML(GUIP.getUnitToolTipAltFGColor()) + sAttackSprite + ""; - String col = "" + sAttackSprite + ""; - String row = "" + col + ""; - String table = "" + row + "
"; + + String attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString(GUIP.getUnitToolTipAltFGColor())); + sAttackSprite = UIUtil.tag("FONT", attr, sAttackSprite); + sAttackSprite = UIUtil.tag("span", fontSizeAttr, sAttackSprite); + String col = UIUtil.tag("TD", "", sAttackSprite); + String row = UIUtil.tag("TR", "", col); + attr = String.format("BORDER=0 BGCOLOR=%s width=100%%", GUIPreferences.hexColor(GUIP.getUnitToolTipAltBGColor())); + String table = UIUtil.tag("TABLE", attr, row); result += table; } } @@ -293,11 +237,13 @@ public String getTooltip(Point point, Coords movementTarget) { msg_artilleryatack += Messages.getString("BoardView1.Tooltip.ArtilleryAttackN2", ammoName); } - msg_artilleryatack = UIUtil.fontHTML(GUIP.getUnitToolTipBlockFGColor()) + msg_artilleryatack + ""; - String col = "" + msg_artilleryatack + ""; - String row = "" + col + ""; - String table = "" + row + "
"; + String attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString(GUIP.getUnitToolTipBlockFGColor())); + msg_artilleryatack = UIUtil.tag("FONT", attr, msg_artilleryatack); + msg_artilleryatack = UIUtil.tag("span", fontSizeAttr, msg_artilleryatack); + String col = UIUtil.tag("TD", "", msg_artilleryatack); + String row = UIUtil.tag("TR", "", col); + attr = String.format("BORDER=0 BGCOLOR=%s width=100%%", GUIPreferences.hexColor(GUIP.getUnitToolTipBlockBGColor())); + String table = UIUtil.tag("TABLE", attr, row); result += table; } @@ -320,8 +266,15 @@ public String getTooltip(Point point, Coords movementTarget) { } else { msg_artilleryautohit = Messages.getString("BoardView1.ArtilleryAdjustment", amod); } - msg_artilleryautohit = UIUtil.fontHTML(UIUtil.uiWhite()) + msg_artilleryautohit + ""; - result += msg_artilleryautohit + "
"; + + String attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString(GUIP.getUnitToolTipFGColor())); + msg_artilleryautohit = UIUtil.tag("FONT", attr, msg_artilleryautohit); + + msg_artilleryautohit = UIUtil.tag("span", fontSizeAttr, msg_artilleryautohit); + String col = UIUtil.tag("TD", "", msg_artilleryautohit); + String row = UIUtil.tag("TR", "", col); + attr = String.format("BORDER=0 BGCOLOR=%s width=100%%", GUIPreferences.hexColor(GUIP.getUnitToolTipBGColor())); + result += UIUtil.tag("TABLE", attr, row); } final Collection shdList = game.getBoard().getSpecialHexDisplay(coords); @@ -349,16 +302,22 @@ public String getTooltip(Point point, Coords movementTarget) { String buf = shd.getInfo(); buf = buf.replaceAll("\\n", "
"); sSpecialHex += buf; - sSpecialHex = UIUtil.fontHTML(UIUtil.uiWhite()) + sSpecialHex + ""; + String attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString(GUIP.getUnitToolTipFGColor())); + sSpecialHex = UIUtil.tag("FONT", attr, sSpecialHex); sSpecialHex += "
"; } } - result += sSpecialHex; + sSpecialHex = UIUtil.tag("span", fontSizeAttr, sSpecialHex); + String col = UIUtil.tag("TD", "", sSpecialHex); + String row = UIUtil.tag("TR", "", col); + String attr = String.format("BORDER=0 BGCOLOR=%s width=100%%", GUIPreferences.hexColor(GUIP.getUnitToolTipBGColor())); + result += UIUtil.tag("TABLE", attr, row); } StringBuilder txt = new StringBuilder(); - String div = "
" + result + "
"; + String attr = String.format("WIDTH=%s", UIUtil.scaleForGUI(500)); + String div = UIUtil.tag("DIV", attr, result); txt.append(UnitToolTip.wrapWithHTML(div)); // Check to see if the tool tip is completely empty @@ -412,22 +371,9 @@ public void appendEntityTooltip(StringBuffer txt, @Nullable Entity entity) { return; } - String result = ""; - - result += "
"; - // Table to add a bar to the left of an entity in - // the player's color - String color = GUIPreferences.hexColor(GUIP.getUnitToolTipFGColor()); - if (!EntityVisibilityUtils.onlyDetectedBySensors(localPlayer(), entity)) { - color = entity.getOwner().getColour().getHexString(); - } - String col1 = ""; - // Entity tooltip - String col2 = "" + UnitToolTip.getEntityTipGame(entity, localPlayer()) + ""; - String row = "" + col1 + col2 + ""; - String table = "" + row + "
"; - result += table; + String result = "
"; + String entityTip = UnitToolTip.getEntityTipGame(entity, localPlayer()).toString(); + result += entityTip; txt.append(result); } diff --git a/megamek/src/megamek/client/ui/swing/tooltip/HexTooltip.java b/megamek/src/megamek/client/ui/swing/tooltip/HexTooltip.java index 0de32ab577..2f57a669b2 100644 --- a/megamek/src/megamek/client/ui/swing/tooltip/HexTooltip.java +++ b/megamek/src/megamek/client/ui/swing/tooltip/HexTooltip.java @@ -13,20 +13,26 @@ */ package megamek.client.ui.swing.tooltip; -import static megamek.client.ui.swing.util.UIUtil.DOT_SPACER; - +import java.awt.*; import java.util.List; import java.util.Vector; +import java.util.stream.Collectors; import megamek.client.Client; import megamek.client.ui.Messages; import megamek.client.ui.swing.GUIPreferences; +import megamek.client.ui.swing.boardview.BoardView; +import megamek.client.ui.swing.boardview.FlareSprite; +import megamek.client.ui.swing.boardview.Sprite; +import megamek.client.ui.swing.util.KeyCommandBind; import megamek.client.ui.swing.util.UIUtil; import megamek.common.*; import megamek.common.annotations.Nullable; import megamek.common.enums.BasementType; import megamek.common.planetaryconditions.IlluminationLevel; +import static megamek.client.ui.swing.util.UIUtil.*; + public final class HexTooltip { @@ -36,6 +42,7 @@ public static String getHexTip(Hex mhex, @Nullable Client client, GUIPreferences // All of the following can be null even if there's a ClientGUI! Game game = (client != null) ? client.getGame() : null; Player localPlayer = (client != null) ? client.getLocalPlayer() : null; + String fontSizeAttr = String.format("class=%s", GUIP.getUnitToolTipFontSizeMod()); // Fuel Tank if (mhex.containsTerrain(Terrains.FUEL_TANK)) { @@ -57,11 +64,13 @@ public static String getHexTip(Hex mhex, @Nullable Client client, GUIPreferences bldg.getMagnitude()); } - sFuelTank = UIUtil.fontHTML(GUIP.getUnitToolTipBuildingFGColor()) + sFuelTank + ""; - String col = "" + sFuelTank + ""; - String row = "" + col + ""; - String table = "" + row + "
"; + String attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString(GUIP.getUnitToolTipBuildingFGColor())); + sFuelTank = UIUtil.tag("FONT", attr, sFuelTank); + sFuelTank = UIUtil.tag("span", fontSizeAttr, sFuelTank); + String col = UIUtil.tag("TD", "", sFuelTank); + String row = UIUtil.tag("TR", "", col); + attr = String.format("CELLSPACING=0 CELLPADDING=0 BORDER=0 BGCOLOR=%s width=100%%", GUIPreferences.hexColor(GUIP.getUnitToolTipBuildingBGColor())); + String table = UIUtil.tag("TABLE", attr, row); result.append(table); } @@ -77,12 +86,6 @@ public static String getHexTip(Hex mhex, @Nullable Client client, GUIPreferences mhex.terrainLevel(Terrains.BLDG_CF), Math.max(mhex.terrainLevel(Terrains.BLDG_ARMOR), 0), BasementType.getType(mhex.terrainLevel(Terrains.BLDG_BASEMENT_TYPE)).toString()); - sBuilding = UIUtil.fontHTML(GUIP.getUnitToolTipBuildingFGColor()) + sBuilding + ""; - String col = "" + sBuilding + ""; - String row = "" + col + ""; - String table = "" + row + "
"; - result.append(table); } else { Building bldg = game.getBoard().getBuildingAt(mcoords); sBuilding = Messages.getString("BoardView1.Tooltip.Building", @@ -95,13 +98,16 @@ public static String getHexTip(Hex mhex, @Nullable Client client, GUIPreferences if (bldg.getBasementCollapsed(mcoords)) { sBuilding += Messages.getString("BoardView1.Tooltip.BldgBasementCollapsed"); } - sBuilding = UIUtil.fontHTML(GUIP.getUnitToolTipBuildingFGColor()) + sBuilding + ""; - String col = "" + sBuilding + ""; - String row = "" + col + ""; - String table = "" + row + "
"; - result.append(table); } + + String attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString(GUIP.getUnitToolTipBuildingFGColor())); + sBuilding = UIUtil.tag("FONT", attr, sBuilding); + sBuilding = UIUtil.tag("span", fontSizeAttr, sBuilding); + String col = UIUtil.tag("TD", "", sBuilding); + String row = UIUtil.tag("TR", "", col); + attr = String.format("CELLSPACING=0 CELLPADDING=0 BORDER=0 BGCOLOR=%s width=100%%", GUIPreferences.hexColor(GUIP.getUnitToolTipBuildingBGColor())); + String table = UIUtil.tag("TABLE", attr, row); + result.append(table); } // Bridge @@ -121,11 +127,14 @@ public static String getHexTip(Hex mhex, @Nullable Client client, GUIPreferences bldg.toString(), bldg.getCurrentCF(mcoords)); } - sBridge = UIUtil.fontHTML(GUIP.getUnitToolTipBuildingFGColor()) + sBridge + ""; - String col = "" + sBridge + ""; - String row = "" + col + ""; - String table = "" + row + "
"; + + String attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString(GUIP.getUnitToolTipBuildingFGColor())); + sBridge = UIUtil.tag("FONT", attr, sBridge); + sBridge = UIUtil.tag("span", fontSizeAttr, sBridge); + String col = UIUtil.tag("TD", "", sBridge); + String row = UIUtil.tag("TR", "", col); + attr = String.format("CELLSPACING=0 CELLPADDING=0 BORDER=0 BGCOLOR=%s width=100%%", GUIPreferences.hexColor(GUIP.getUnitToolTipBuildingBGColor())); + String table = UIUtil.tag("TABLE", attr, row); result.append(table); } @@ -155,7 +164,8 @@ public static String getHexTip(Hex mhex, @Nullable Client client, GUIPreferences break; } - sMinefield = UIUtil.fontHTML(UIUtil.uiWhite()) + sMinefield + ""; + String attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString(GUIP.getUnitToolTipFGColor())); + sMinefield = UIUtil.tag("FONT", attr, sMinefield); result.append(sMinefield); result.append("
"); } @@ -164,10 +174,11 @@ public static String getHexTip(Hex mhex, @Nullable Client client, GUIPreferences if ((game != null) && game.getGroundObjects(mcoords).size() > 0) { for (ICarryable groundObject : game.getGroundObjects(mcoords)) { result.append(" "); - result.append(UIUtil.fontHTML(UIUtil.uiWhite())); - result.append(groundObject.specificName()); - result.append(""); - result.append("
"); + String groundObj = groundObject.specificName(); + String attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString(GUIP.getUnitToolTipFGColor())); + groundObj = UIUtil.tag("FONT", attr, groundObj); + result.append(groundObj); + result.append("
"); } } @@ -179,6 +190,8 @@ public static String getBuildingTargetTip(BuildingTarget target, Board board, GU Coords mcoords = target.getPosition(); Building bldg = board.getBuildingAt(mcoords); Hex mhex = board.getHex(mcoords); + String fontSizeAttr = String.format("class=%s", GUIP.getUnitToolTipFontSizeMod()); + String sBuilding = Messages.getString("BoardView1.Tooltip.Building", mhex.terrainLevel(Terrains.BLDG_ELEV), bldg.toString(), bldg.getCurrentCF(mcoords), bldg.getArmor(mcoords), bldg.getBasement(mcoords).toString()); @@ -186,12 +199,15 @@ public static String getBuildingTargetTip(BuildingTarget target, Board board, GU if (bldg.getBasementCollapsed(mcoords)) { sBuilding += Messages.getString("BoardView1.Tooltip.BldgBasementCollapsed"); } - sBuilding = UIUtil.fontHTML(GUIP.getUnitToolTipBuildingFGColor()) + sBuilding + ""; - String col = "" + sBuilding + ""; - String row = "" + col + ""; - String table = "" + row + "
"; - result += table; - return result; + String attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString(GUIP.getUnitToolTipBuildingFGColor())); + sBuilding = UIUtil.tag("FONT", attr, sBuilding); + sBuilding = UIUtil.tag("span", fontSizeAttr, sBuilding); + String col = UIUtil.tag("TD", "", sBuilding); + String row = UIUtil.tag("TR", "", col); + attr = String.format("CELLSPACING=0 CELLPADDING=0 BORDER=0 BGCOLOR=%s width=100%%", GUIPreferences.hexColor(GUIP.getUnitToolTipBuildingBGColor())); + String table = UIUtil.tag("TABLE", attr, row); + + return table; } public static String getOneLineSummary(BuildingTarget target, Board board) { @@ -200,14 +216,19 @@ public static String getOneLineSummary(BuildingTarget target, Board board) { Building bldg = board.getBuildingAt(mcoords); Hex mhex = board.getHex(mcoords); result += Messages.getString("BoardView1.Tooltip.BuildingLine", mhex.terrainLevel(Terrains.BLDG_ELEV), bldg.getCurrentCF(mcoords), bldg.getArmor(mcoords)); + return result; } public static String getTerrainTip(Hex mhex, GUIPreferences GUIP, Game game) { boolean inAtmosphere = game.getBoard().inAtmosphere(); + String fontSizeAttr = String.format("class=%s", GUIP.getUnitToolTipFontSizeMod()); Coords mcoords = mhex.getCoords(); String indicator = IlluminationLevel.determineIlluminationLevel(game, mcoords).getIndicator(); - String illuminated = DOT_SPACER + UIUtil.fontHTML(GUIP.getCautionColor()) + " " + indicator + ""; + String attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString(GUIP.getCautionColor())); + String illuminated = UIUtil.tag("FONT", attr, " " + indicator); + illuminated = DOT_SPACER + illuminated; + String result = ""; StringBuilder sTerrain = new StringBuilder( Messages.getString( @@ -231,13 +252,159 @@ public static String getTerrainTip(Hex mhex, GUIPreferences GUIP, Game game) { String name = Terrains.getDisplayName(terType, ttl); if (name != null) { - String msg_tf = Messages.getString("BoardView1.Tooltip.TF"); + String msg_tf = Messages.getString("BoardView1.Tooltip.TF"); name += (tf > 0) ? " (" + msg_tf + ": " + tf + ')' : ""; sTerrain.append(name).append("
"); } } - result += UIUtil.fontHTML(GUIP.getUnitToolTipTerrainFGColor()) + sTerrain + ""; + attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString(GUIP.getUnitToolTipTerrainFGColor())); + result = UIUtil.tag("FONT", attr, sTerrain.toString()); + result = UIUtil.tag("span", fontSizeAttr, result); + + return result; + } + + public static String getDistanceTip(GUIPreferences GUIP, int distance) { + String sTerrain = ""; + String fontSizeAttr = String.format("class=%s", GUIP.getUnitToolTipFontSizeMod()); + + if (distance == 1) { + sTerrain += Messages.getString("BoardView1.Tooltip.Distance1"); + } else { + sTerrain += Messages.getString("BoardView1.Tooltip.DistanceN", distance); + } + + String attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString(GUIP.getUnitToolTipTerrainFGColor())); + String result = UIUtil.tag("FONT", attr, sTerrain); + result = UIUtil.tag("span", fontSizeAttr, result); + + return result; + } + + public static String getSensorRangeTip(GUIPreferences GUIP, int distance, int minSensorRange, int maxSensorRange, int disPM, boolean isMovement) { + String sTerrain = ""; + String fontSizeAttr = String.format("class=%s", GUIP.getUnitToolTipFontSizeMod()); + sTerrain += "
"; + if ((distance > minSensorRange) && (distance <= maxSensorRange)) { + sTerrain += Messages.getString("BoardView1.Tooltip.SensorsHexInRange"); + } else { + sTerrain += Messages.getString("BoardView1.Tooltip.SensorsHexNotInRange1"); + String tmp = Messages.getString("BoardView1.Tooltip.SensorsHexNotInRange2"); + + String attr = String.format("FACE=Dialog COLOR=%s",UIUtil.toColorHexString(GUIP.getWarningColor())); + sTerrain += UIUtil.tag("FONT", attr, tmp); + sTerrain += Messages.getString("BoardView1.Tooltip.SensorsHexNotInRange3"); + } + + if (isMovement) { + sTerrain += "
"; + String sDinstanceMove = ""; + if (disPM == 1) { + sDinstanceMove = Messages.getString("BoardView1.Tooltip.DistanceMove1"); + } else { + sDinstanceMove = Messages.getString("BoardView1.Tooltip.DistanceMoveN", disPM); + } + sTerrain += UIUtil.tag("I", "", sDinstanceMove); + } + + String attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString(GUIP.getUnitToolTipTerrainFGColor())); + sTerrain = UIUtil.tag("FONT", attr, sTerrain); + sTerrain = UIUtil.tag("span", fontSizeAttr, sTerrain); + + return sTerrain; + } + + public static String getAttilleryHit(GUIPreferences GUIP, Game game, Coords coords) { + String sAttilleryAutoHix = ""; + String fontSizeAttr = String.format("class=%s", GUIP.getUnitToolTipFontSizeMod()); + boolean foundPlayer = false; + for (Player player : game.getPlayersList()) { + // loop through all players + if (game.getBoard().isLegalDeployment(coords, player)) { + if (!foundPlayer) { + foundPlayer = true; + sAttilleryAutoHix += Messages.getString("BoardView1.Tooltip.ArtyAutoHeader") + "
"; + } + + String sName = "  " + player.getName(); + String attr = String.format("FACE=Dialog COLOR=%s",UIUtil.toColorHexString(player.getColour().getColour())); + sName = UIUtil.tag("FONT", attr, sName); + sAttilleryAutoHix += UIUtil.tag("B", "", sName); + sAttilleryAutoHix += "
"; + } + } + if (foundPlayer) { + sAttilleryAutoHix += "
"; + } + + // Add a hint with keybind that the zones can be shown graphically + String keybindText = KeyCommandBind.getDesc(KeyCommandBind.getBindByCmd("autoArtyDeployZone")); + String msg_artyautohit = Messages.getString("BoardView1.Tooltip.ArtyAutoHint1") + "
"; + msg_artyautohit += Messages.getString("BoardView1.Tooltip.ArtyAutoHint2") + "
"; + msg_artyautohit += Messages.getString("BoardView1.Tooltip.ArtyAutoHint3", keybindText); + sAttilleryAutoHix = UIUtil.tag("I", "", msg_artyautohit); + + String attr = String.format("FACE=Dialog COLOR=%s",UIUtil.toColorHexString(GUIP.getUnitToolTipFGColor())); + sAttilleryAutoHix = UIUtil.tag("FONT", attr, sAttilleryAutoHix); + + attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString(uiWhite())); + sAttilleryAutoHix = UIUtil.tag("FONT", attr, sAttilleryAutoHix); + sAttilleryAutoHix = UIUtil.tag("span", fontSizeAttr, sAttilleryAutoHix); + String col = UIUtil.tag("TD", "", sAttilleryAutoHix); + String row = UIUtil.tag("TR", "", col); + attr = String.format("CELLSPACING=0 CELLPADDING=0 BORDER=0 BGCOLOR=%s width=100%%", GUIPreferences.hexColor(GUIP.getUnitToolTipBGColor())); + String table = UIUtil.tag("TABLE", attr, row); + + return table; + } + + public static String getFlares(GUIPreferences GUIP, BoardView bv, Point point) { + String fontSizeAttr = String.format("class=%s", GUIP.getUnitToolTipFontSizeMod()); + + String result = bv.getAllSprites().stream() + .filter(sprite -> sprite instanceof FlareSprite) + .filter(sprite -> sprite.isInside(point)) + .map(Sprite::getTooltip) + .collect(Collectors.joining()); + + result = UIUtil.tag("span", fontSizeAttr, result); + + return result; + } + + public static String getWrecks(GUIPreferences GUIP, BoardView bv, Coords coords) { + String result = ""; + String fontSizeAttr = String.format("class=%s", GUIP.getUnitToolTipFontSizeMod()); + var wreckList = bv.useIsometric() ? bv.getIsoWreckSprites() : bv.getWreckSprites(); + for (var wSprite : wreckList) { + if (wSprite.getPosition().equals(coords)) { + String sWreck = wSprite.getTooltip().toString(); + String attr = String.format("FACE=Dialog COLOR=%s",UIUtil.toColorHexString(GUIP.getUnitToolTipAltFGColor())); + sWreck = UIUtil.tag("FONT", attr, sWreck); + sWreck = UIUtil.tag("span", fontSizeAttr, sWreck); + String col = UIUtil.tag("TD", "", sWreck); + String row = UIUtil.tag("TR", "", col); + String rows = row; + + if (!wSprite.getEntity().getCrew().isEjected()) { + String sPilot = PilotToolTip.getPilotTipShort(wSprite.getEntity(), + GUIP.getshowPilotPortraitTT(), false).toString(); + + attr = String.format("FACE=Dialog COLOR=%s",UIUtil.toColorHexString(GUIP.getUnitToolTipAltFGColor())); + sPilot = UIUtil.tag("FONT", attr, sPilot); + sPilot = UIUtil.tag("span", fontSizeAttr, sPilot); + col = UIUtil.tag("TD", "", sPilot); + row = UIUtil.tag("TR", "", col); + rows += row; + } + + attr = String.format("CELLSPACING=0 CELLPADDING=0 BORDER=0 BGCOLOR=%s width=100%%", GUIPreferences.hexColor(GUIP.getUnitToolTipAltBGColor())); + String table = UIUtil.tag("TABLE", attr, rows); + result = table; + } + } + return result; } diff --git a/megamek/src/megamek/client/ui/swing/tooltip/PilotToolTip.java b/megamek/src/megamek/client/ui/swing/tooltip/PilotToolTip.java index 30fada8bd5..51851f5901 100644 --- a/megamek/src/megamek/client/ui/swing/tooltip/PilotToolTip.java +++ b/megamek/src/megamek/client/ui/swing/tooltip/PilotToolTip.java @@ -15,8 +15,7 @@ import static megamek.client.ui.swing.tooltip.TipUtil.getOptionList; import static megamek.client.ui.swing.tooltip.TipUtil.htmlSpacer; -import static megamek.client.ui.swing.util.UIUtil.fontHTML; -import static megamek.client.ui.swing.util.UIUtil.uiQuirksColor; +import static megamek.client.ui.swing.util.UIUtil.*; import java.awt.Image; import java.awt.image.BufferedImage; @@ -98,10 +97,10 @@ private static StringBuilder getPilotTip(final Entity entity, boolean detailed, cols += crewInfoCell(entity); cols += crewPickedUpCell(entity); - row = "" + cols + ""; + row = UIUtil.tag("TR", "", cols); rows += row; - String table = "" + rows + "
"; - result += "
" + table + "
"; + String table = UIUtil.tag("TABLE", "CELLSPACING=0 CELLPADDING=2 BORDER=0", rows); + result += UIUtil.tag(""; + String result = htmlSpacer(3) + sCrewAdvs; return new StringBuilder().append(result); } @@ -123,11 +122,14 @@ public static StringBuilder getCrewAdvs(Entity entity, boolean detailed) { private static StringBuilder crewInfoLine(final Entity entity) { Crew crew = entity.getCrew(); Game game = entity.getGame(); - String result = ""; // Effective entity skill for the whole crew boolean rpg_skills = game.getOptions().booleanOption(OptionsConstants.RPG_RPG_GUNNERY); - result += CrewSkillSummaryUtil.getSkillNames(entity) + ": " + crew.getSkillsAsString(rpg_skills); - return new StringBuilder(result); + String col = CrewSkillSummaryUtil.getSkillNames(entity) + ": " + crew.getSkillsAsString(rpg_skills); + col = UIUtil.tag("TD", "", col); + String row = UIUtil.tag("TR", "", col); + String rows = row; + String table = UIUtil.tag("TABLE", "CELLSPACING=0 CELLPADDING=0 BORDER=0", rows); + return new StringBuilder(table); } /** Returns a tooltip part with names and skills of the crew. */ @@ -144,20 +146,22 @@ private static StringBuilder crewInfoCell(final Entity entity) { } if ((crew.getNickname(i) != null) && !crew.getNickname(i).isBlank()) { - String sNickName = "'" + crew.getNickname(i).toUpperCase() + "'"; - sCrew += UIUtil.fontHTML(UIUtil.uiNickColor()) + sNickName + ""; + String sNickName = UIUtil.tag("B", "", crew.getNickname(i).toUpperCase()); + String attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString(UIUtil.uiNickColor())); + sCrew += UIUtil.tag("FONT", attr, sNickName); } else if ((crew.getName(i) != null) && !crew.getName(i).isBlank()) { - sCrew += crew.getName(i); + sCrew += crew.getName(i) + " "; } else { sCrew += Messages.getString("BoardView1.Tooltip.Pilot"); } if (crew.getSlotCount() > 1) { - sCrew += " \u2B1D " + crew.getCrewType().getRoleName(i); + sCrew += " \u2B1D " + crew.getCrewType().getRoleName(i) + " "; } if (!crew.getStatusDesc(i).isEmpty()) { - sCrew += UIUtil.fontHTML(GUIP.getWarningColor()) + " (" + crew.getStatusDesc(i) + ")"; + String attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString(GUIP.getWarningColor())); + sCrew += UIUtil.tag("FONT", attr, crew.getStatusDesc(i)); } result += sCrew + "
"; } @@ -165,7 +169,9 @@ private static StringBuilder crewInfoCell(final Entity entity) { // Effective entity skill for the whole crew boolean rpg_skills = game.getOptions().booleanOption(OptionsConstants.RPG_RPG_GUNNERY); result += CrewSkillSummaryUtil.getSkillNames(entity) + ": " + crew.getSkillsAsString(rpg_skills); - String col = "" + result + ""; + String fontSizeAttr = String.format("class=%s", GUIP.getUnitToolTipFontSizeMod()); + result = UIUtil.tag("span", fontSizeAttr, result); + String col = UIUtil.tag("TD", "align=\"left\"", result); return new StringBuilder().append(col); } @@ -183,9 +189,11 @@ private static StringBuilder crewPickedUpCell(final Entity entity) { String col = ""; if (!pickedUp.isEmpty()) { - pickedUp = UIUtil.fontHTML(GUIP.getCautionColor()) + Messages.getString("BoardView1.Tooltip.PickedUp") - + pickedUp + ""; - col = "" + pickedUp + ""; + String attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString(GUIP.getCautionColor())); + pickedUp = UIUtil.tag("FONT", attr, Messages.getString("BoardView1.Tooltip.PickedUp") + pickedUp); + String fontSizeAttr = String.format("class=%s", GUIP.getUnitToolTipFontSizeMod()); + pickedUp = UIUtil.tag("span", fontSizeAttr, pickedUp); + col = UIUtil.tag("TD", "", pickedUp); } return new StringBuilder().append(col); @@ -225,9 +233,10 @@ private static StringBuilder crewPortraits(final Entity entity, boolean showDefa img = ""; } else { // span crew tag replaced later in Client.receiveReport with crew portrait - img = ""; + img = UIUtil.tag("span", "crew='" + entity.getId() + ":" + i + "'", ""); } - col += "" + img + ""; + + col += UIUtil.tag("TD", "VALIGN=TOP", img); } catch (Exception e) { logger.error("", e); } @@ -246,8 +255,10 @@ private static StringBuilder crewAdvs(final Entity entity, boolean detailed) { String sOptionList = ""; Crew crew = entity.getCrew(); sOptionList = getOptionList(crew.getOptions().getGroups(), crew::countOptions, detailed); - sOptionList = UIUtil.fontHTML(uiQuirksColor()) + sOptionList + ""; - result = "" + sOptionList + ""; + String attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString(GUIP.getUnitToolTipQuirkColor())); + sOptionList = UIUtil.tag("FONT", attr, sOptionList); + String fontSizeAttr = String.format("class=%s", GUIP.getUnitToolTipFontSizeMod()); + result = UIUtil.tag("span", fontSizeAttr, sOptionList); return new StringBuilder().append(result); } diff --git a/megamek/src/megamek/client/ui/swing/tooltip/UnitToolTip.java b/megamek/src/megamek/client/ui/swing/tooltip/UnitToolTip.java index c8b0784e1e..87ff48859d 100644 --- a/megamek/src/megamek/client/ui/swing/tooltip/UnitToolTip.java +++ b/megamek/src/megamek/client/ui/swing/tooltip/UnitToolTip.java @@ -18,8 +18,6 @@ import static megamek.client.ui.swing.tooltip.TipUtil.getOptionList; import static megamek.client.ui.swing.util.UIUtil.DOT_SPACER; import static megamek.client.ui.swing.util.UIUtil.ECM_SIGN; -import static megamek.client.ui.swing.util.UIUtil.addGray; -import static megamek.client.ui.swing.util.UIUtil.fontHTML; import static megamek.client.ui.swing.util.UIUtil.repeat; import java.awt.Color; @@ -102,8 +100,10 @@ public static StringBuilder getEntityTipReport(Entity entity) { public static String wrapWithHTML(String text) { String fgColor = GUIP.hexColor(GUIP.getUnitToolTipFGColor()); String bgColor = GUIP.hexColor(GUIP.getUnitToolTipBGColor()); - String format = "%s"; - return String.format(format, fgColor, bgColor, text); + String attr = String.format("style=\"color:%s; background-color:%s;\"", fgColor, bgColor); + String body = UIUtil.tag("BODY", attr, text); + String html = UIUtil.tag("HTML", "", body); + return html; } // PRIVATE @@ -139,9 +139,9 @@ private static StringBuilder getEntityTipTable(Entity entity, Player localPlayer // An empty squadron should not show any info if (entity instanceof FighterSquadron && entity.getLoadedUnits().isEmpty()) { - String col = "" + result + ""; - String row = "" + col + ""; - String table = "" + row + "
"; + String col = UIUtil.tag("TD", "", result); + String row = UIUtil.tag("TR", "", col); + String table = UIUtil.tag("TABLE", "CELLSPACING=0 CELLPADDING=0 width=100%", row); return new StringBuilder().append(table); } @@ -163,9 +163,6 @@ private static StringBuilder getEntityTipTable(Entity entity, Player localPlayer // Bomb List result += bombList(entity); - // StratOps quirks, chassis and weapon - result += getQuirks(entity, game, details); - // Partial repairs result += getPartialRepairs(entity, details); @@ -178,10 +175,13 @@ private static StringBuilder getEntityTipTable(Entity entity, Player localPlayer // C3 Info result += c3Info(entity, details); - String col = "" + result + ""; - String row = "" + col + ""; - String table = "" + row + "
"; + // StratOps quirks, chassis and weapon + result += getQuirks(entity, game, details); + String col = UIUtil.tag("TD", "", result); + String row = UIUtil.tag("TR", "", col); + String table = UIUtil.tag("TABLE", "CELLSPACING=0 CELLPADDING=0 width=100%", row); + table = UnitToolTip.addPlayerColorBoarder(GUIP, entity, table); return new StringBuilder().append(table); } @@ -202,8 +202,10 @@ public static String getTargetTipDetail(Targetable target, @Nullable Client clie public static String getTargetTipSummary(Targetable target, @Nullable Client client) { if (target == null) { return Messages.getString("BoardView1.Tooltip.NoTarget"); - } else if (target instanceof Entity) { - return getTargetTipSummaryEntity((Entity) target, client); + } else if (target instanceof Entity targetEntity) { + String result = getTargetTipSummaryEntity((Entity) target, client); + result = UnitToolTip.addPlayerColorBoarder(GUIP, targetEntity, result); + return result; } else if (target instanceof BuildingTarget) { return HexTooltip.getOneLineSummary((BuildingTarget) target, (client != null) ? client.getBoard() : null); } @@ -226,24 +228,71 @@ public static String getTargetTipSummaryEntity(Entity entity, @Nullable Client c return result; } + private static String addPlayerColorBoarder(GUIPreferences GUIP, Entity entity, String entityTip) { + Color color = GUIP.getUnitToolTipFGColor(); + // the player's color + // Table to add a bar to the left of an entity in + if (!EntityVisibilityUtils.onlyDetectedBySensors(entity.getOwner(), entity)) { + color = entity.getOwner().getColour().getColour(); + } + + String attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString(color)); + entityTip = UIUtil.tag("FONT", attr, entityTip); + attr = String.format("BGCOLOR=%s WIDTH=6", UIUtil.toColorHexString(color)); + String col1 = UIUtil.tag("TD", attr, ""); + String col2 = UIUtil.tag("TD", "", entityTip); + String row = UIUtil.tag("TR", "", col1 + col2); + attr = String.format("CELLSPACING=0 CELLPADDING=4 BORDER=0 BGCOLOR=%s WIDTH=100%%", GUIPreferences.hexColor(GUIP.getUnitToolTipBGColor())); + String table = UIUtil.tag("TABLE", attr, row); + return table; + } + + private static String getChassisInfo(Entity entity) { + String msg_clanbrackets = Messages.getString("BoardView1.Tooltip.ClanBrackets"); + String clanStr = entity.isClan() && !entity.isMixedTech() ? " " + msg_clanbrackets + " " : ""; + String chassis = entity.getFullChassis() + clanStr + " (" + (int) entity.getWeight() + "t)"; + chassis += "  " + entity.getEntityTypeName(entity.getEntityType()); + return chassis; + } + + private static String getOwnerInfo(Entity entity, Player owner) { + String ownerName = (owner != null) ? owner.getName() : ReportMessages.getString("BoardView1.Tooltip.unknownOwner"); + String msg_id = MessageFormat.format(" [ID: {0}]", entity.getId()); + String attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString(GUIP.getUnitToolTipFGColor())); + ownerName += UIUtil.tag("FONT", attr, msg_id); + + return ownerName; + } + private static String getDisplayNames(Entity entity, @Nullable Game game, boolean showName) { String result = ""; if (showName) { - // Unit Chassis and Player + String col = ""; + String row = ""; + String rows = ""; + String fontSizeAttr = String.format("class=%s", GUIP.getUnitToolTipFontSizeMod()); Player owner = (game != null) ? game.getPlayer(entity.getOwnerId()) : null; + + col = getChassisInfo(entity); Color ownerColor = (owner != null) ? owner.getColour().getColour() : GUIP.getUnitToolTipFGColor(); - String ownerName = (owner != null) ? owner.getName() - : ReportMessages.getString("BoardView1.Tooltip.unknownOwner"); - String msg_clanbrackets = Messages.getString("BoardView1.Tooltip.ClanBrackets"); - String clanStr = entity.isClan() && !entity.isMixedTech() ? " " + msg_clanbrackets + " " : ""; - result = entity.getFullChassis() + clanStr; - result += " (" + (int) entity.getWeight() + "t)"; - result += "  " + entity.getEntityTypeName(entity.getEntityType()); - result += "
" + ownerName; - String msg_id = MessageFormat.format(" [ID: {0}]", entity.getId()); - result += UIUtil.fontHTML(GUIP.getUnitToolTipFGColor()) + msg_id + ""; - result = UIUtil.fontHTML(ownerColor) + result + ""; + String attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString(ownerColor)); + col = UIUtil.tag("FONT", attr, col); + col = UIUtil.tag("span", fontSizeAttr, col); + col = UIUtil.tag("TD", "", col); + row = UIUtil.tag("TR", "", col); + rows = row; + + col = getOwnerInfo(entity, owner); + attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString(ownerColor)); + col = UIUtil.tag("FONT", attr, col); + col = UIUtil.tag("span", fontSizeAttr, col); + col = UIUtil.tag("TD", "", col); + row = UIUtil.tag("TR", "", col); + rows += row; + + String table = UIUtil.tag("TABLE", "CELLSPACING=0 CELLPADDING=0", rows); + result = table; } return result; @@ -258,13 +307,13 @@ private static String getPilotInfo(Entity entity, boolean pilotInfoShow, boolean if (pilotInfoStandard) { return PilotToolTip.getPilotTipShort(entity, GUIP.getshowPilotPortraitTT(), report).toString(); } else { - return "
" + PilotToolTip.getPilotTipLine(entity).toString(); + return PilotToolTip.getPilotTipLine(entity).toString(); } } private static String getQuirks(Entity entity, Game game, boolean details) { if (game.getOptions().booleanOption(OptionsConstants.ADVANCED_STRATOPS_QUIRKS)) { - String sQuirks = "
"; + String sQuirks = ""; String quirksList = getOptionList(entity.getQuirks().getGroups(), entity::countQuirks, details); if (!quirksList.isEmpty()) { sQuirks += quirksList; @@ -278,8 +327,19 @@ private static String getQuirks(Entity entity, Game game, boolean details) { } } - sQuirks = UIUtil.fontHTML(GUIP.getUnitToolTipQuirkColor()) + sQuirks + ""; - return "" + sQuirks + ""; + if (!sQuirks.isEmpty()) { + String attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString(GUIP.getUnitToolTipQuirkColor())); + sQuirks = UIUtil.tag("FONT", attr, sQuirks); + String fontSizeAttr = String.format("class=%s", GUIP.getUnitToolTipFontSizeMod()); + sQuirks = UIUtil.tag("span", fontSizeAttr, sQuirks); + + String col = UIUtil.tag("TD", "", sQuirks); + String row = UIUtil.tag("TR", "", col); + String tbody = UIUtil.tag("TBODY", "", row); + sQuirks = UIUtil.tag("TABLE", "CELLSPACING=0 CELLPADDING=0", tbody); + } + + return sQuirks; } return ""; @@ -291,8 +351,15 @@ private static String getPartialRepairs(Entity entity, boolean details) { grp -> entity.countPartialRepairs(), details); if (!partialList.isEmpty()) { - partialList = UIUtil.fontHTML(GUIP.getPrecautionColor()) + partialList + ""; - result += "" + partialList + ""; + String attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString(GUIP.getPrecautionColor())); + partialList = UIUtil.tag("FONT", attr, partialList); + String fontSizeAttr = String.format("class=%s", GUIP.getUnitToolTipFontSizeMod()); + partialList = UIUtil.tag("span", fontSizeAttr, partialList); + + String col = UIUtil.tag("TD", "", partialList); + String row = UIUtil.tag("TR", "", col); + String tbody = UIUtil.tag("TBODY", "", row); + result = UIUtil.tag("TABLE", "CELLSPACING=0 CELLPADDING=0", tbody); } return result; @@ -311,16 +378,17 @@ private static String locationHeader(Entity entity, int location) { } private static StringBuilder sysCrits(Entity entity, int type, int index, int loc, String locAbbr) { - String result = "" + " " + "";; + String result = ""; int total = entity.getNumberOfCriticals(type, index, loc); int hits = entity.getHitCriticals(type, index, loc); int good = total - hits; boolean bad = (entity.getBadCriticals(type, index, loc) > 0); if ((good + hits) > 0) { - locAbbr = "  " + locAbbr + ": "; - result = "" + locAbbr + ""; + result = "  " + locAbbr + ": "; result += systemBar(good, hits, bad); + } else { + result = " "; } return new StringBuilder().append(result); @@ -333,8 +401,7 @@ private static StringBuilder sysStabilizers(Tank tank, int loc, String locAbbr) int good = total - hits; boolean bad = hits > 0; - locAbbr = "  " + locAbbr + ": "; - result = "" + locAbbr + ""; + result = "  " + locAbbr + ": "; result += systemBar(good, hits, bad); return new StringBuilder().append(result); @@ -347,8 +414,7 @@ private static StringBuilder sysTurretLocked(Tank tank, int loc, String locAbbr) int good = total - hits; boolean bad = hits > 0; - locAbbr = "  " + locAbbr + ": "; - result = "" + locAbbr + ""; + result = "  " + locAbbr + ": "; result += systemBar(good, hits, bad); return new StringBuilder().append(result); @@ -361,8 +427,7 @@ private static StringBuilder sysEngineHit(Tank tank, String locAbbr) { int good = total - hits; boolean bad = hits > 0; - locAbbr = "  " + locAbbr + ": "; - result = "" + locAbbr + ""; + result = "  " + locAbbr + ": "; result += systemBar(good, hits, bad); return new StringBuilder().append(result); @@ -375,8 +440,7 @@ private static StringBuilder sysSensorHit(Tank tank, String locAbbr) { int good = total - hits; boolean bad = hits > 0; - locAbbr = "  " + locAbbr + ": "; - result = "" + locAbbr + ""; + result = "  " + locAbbr + ": "; result += systemBar(good, hits, bad); return new StringBuilder().append(result); @@ -389,8 +453,7 @@ private static StringBuilder sysMinorMovementDamage(Tank tank, String locAbbr) { int good = total - hits; boolean bad = hits > 0; - locAbbr = "  " + locAbbr + ": "; - result = "" + locAbbr + ""; + result = "  " + locAbbr + ": "; result += systemBar(good, hits, bad); return new StringBuilder().append(result); @@ -403,8 +466,7 @@ private static StringBuilder sysModerateMovementDamage(Tank tank, String locAbbr int good = total - hits; boolean bad = hits > 0; - locAbbr = "  " + locAbbr + ": "; - result = "" + locAbbr + ""; + result = "  " + locAbbr + ": "; result += systemBar(good, hits, bad); return new StringBuilder().append(result); @@ -417,13 +479,135 @@ private static StringBuilder sysHeavyMovementDamage(Tank tank, String locAbbr) { int good = total - hits; boolean bad = hits > 0; - locAbbr = "  " + locAbbr + ": "; - result = "" + locAbbr + ""; + result = "  " + locAbbr + ": "; result += systemBar(good, hits, bad); return new StringBuilder().append(result); } + private static StringBuilder buildSysCrits(Entity entity, int loc) { + String result = ""; + String msg_abbr_sensors = Messages.getString("BoardView1.Tooltip.AbbreviationSensors"); + String msg_abbr_lifesupport = Messages.getString("BoardView1.Tooltip.AbbreviationLifeSupport"); + String msg_abbr_engine = Messages.getString("BoardView1.Tooltip.AbbreviationEngine"); + String msg_abbr_gyro = Messages.getString("BoardView1.Tooltip.AbbreviationGyro"); + String msg_abbr_shoulder = Messages.getString("BoardView1.Tooltip.AbbreviationShoulder"); + String msg_abbr_upperarm = Messages.getString("BoardView1.Tooltip.AbbreviationUpperArm"); + String msg_abbr_lowerarm = Messages.getString("BoardView1.Tooltip.AbbreviationLowerArm"); + String msg_abbr_hand = Messages.getString("BoardView1.Tooltip.AbbreviationHand"); + String msg_abbr_hip = Messages.getString("BoardView1.Tooltip.AbbreviationHip"); + String msg_abbr_upperleg = Messages.getString("BoardView1.Tooltip.AbbreviationUpperLeg"); + String msg_abbr_lowerleg = Messages.getString("BoardView1.Tooltip.AbbreviationLowerLeg"); + String msg_abbr_foot = Messages.getString("BoardView1.Tooltip.AbbreviationLowerFoot"); + String msg_abbr_stabilizers = Messages.getString("BoardView1.Tooltip.AbbreviationStabilizers"); + String msg_abbr_turretlocked = Messages.getString("BoardView1.Tooltip.AbbreviationTurretLocked"); + + if (entity instanceof Mek) { + switch (loc) { + case Mek.LOC_HEAD: + result = sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mek.SYSTEM_SENSORS, loc, msg_abbr_sensors) + .toString(); + result += sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mek.SYSTEM_LIFE_SUPPORT, loc, + msg_abbr_lifesupport).toString(); + break; + case Mek.LOC_CT: + result = sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mek.SYSTEM_ENGINE, loc, msg_abbr_engine) + .toString(); + result += sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mek.SYSTEM_GYRO, loc, msg_abbr_gyro) + .toString(); + result += sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mek.SYSTEM_SENSORS, loc, msg_abbr_sensors) + .toString(); + result += sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mek.SYSTEM_LIFE_SUPPORT, loc, + msg_abbr_lifesupport).toString(); + break; + case Mek.LOC_RT: + case Mek.LOC_LT: + result = sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mek.SYSTEM_ENGINE, loc, msg_abbr_engine) + .toString(); + result += sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mek.SYSTEM_LIFE_SUPPORT, loc, + msg_abbr_lifesupport).toString(); + break; + case Mek.LOC_RARM: + case Mek.LOC_LARM: + result = sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mek.ACTUATOR_SHOULDER, loc, msg_abbr_shoulder) + .toString(); + result += sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mek.ACTUATOR_UPPER_ARM, loc, + msg_abbr_upperarm).toString(); + result += sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mek.ACTUATOR_LOWER_ARM, loc, + msg_abbr_lowerarm).toString(); + result += sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mek.ACTUATOR_HAND, loc, msg_abbr_hand) + .toString(); + result += sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mek.ACTUATOR_HIP, loc, msg_abbr_hip) + .toString(); + result += sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mek.ACTUATOR_UPPER_LEG, loc, + msg_abbr_upperleg).toString(); + result += sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mek.ACTUATOR_LOWER_LEG, loc, + msg_abbr_lowerleg).toString(); + result += sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mek.ACTUATOR_FOOT, loc, msg_abbr_foot) + .toString(); + break; + case Mek.LOC_RLEG: + case Mek.LOC_LLEG: + case Mek.LOC_CLEG: + result = sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mek.ACTUATOR_HIP, loc, msg_abbr_hip) + .toString(); + result += sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mek.ACTUATOR_UPPER_LEG, loc, + msg_abbr_upperleg).toString(); + result += sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mek.ACTUATOR_LOWER_LEG, loc, + msg_abbr_lowerleg).toString(); + result += sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mek.ACTUATOR_FOOT, loc, msg_abbr_foot) + .toString(); + break; + default: + result = " "; + } + } else if (entity instanceof SuperHeavyTank || entity instanceof LargeSupportTank) { + Tank tank = (Tank) entity; + + switch (loc) { + case SuperHeavyTank.LOC_BODY: + case SuperHeavyTank.LOC_FRONT: + case SuperHeavyTank.LOC_RIGHT: + case SuperHeavyTank.LOC_LEFT: + case SuperHeavyTank.LOC_REARRIGHT: + case SuperHeavyTank.LOC_REARLEFT: + case SuperHeavyTank.LOC_REAR: + result = sysStabilizers(tank, loc, msg_abbr_stabilizers).toString(); + break; + case SuperHeavyTank.LOC_TURRET: + case SuperHeavyTank.LOC_TURRET_2: + result = sysStabilizers(tank, loc, msg_abbr_stabilizers).toString(); + result += tank.getTurretCount() > 0 ? sysTurretLocked(tank, loc, msg_abbr_turretlocked).toString() + : " "; + break; + default: + result = " "; + } + } else if (entity instanceof Tank) { + Tank tank = (Tank) entity; + + switch (loc) { + case Tank.LOC_BODY: + case Tank.LOC_FRONT: + case Tank.LOC_RIGHT: + case Tank.LOC_LEFT: + case Tank.LOC_REAR: + result = sysStabilizers(tank, loc, msg_abbr_stabilizers).toString(); + break; + case Tank.LOC_TURRET: + case Tank.LOC_TURRET_2: + result = sysStabilizers(tank, loc, msg_abbr_stabilizers).toString(); + result += tank.getTurretCount() > 0 ? sysTurretLocked(tank, loc, msg_abbr_turretlocked).toString() + : " "; + break; + default: + result = " "; + } + } + + return new StringBuilder().append(result); + } + /** Returns the graphical Armor representation. */ private static StringBuilder addArmorMiniVisToTT(Entity entity) { if (!GUIP.getshowArmorMiniVisTT()) { @@ -435,6 +619,7 @@ private static StringBuilder addArmorMiniVisToTT(Entity entity) { armorChar = GUIP.getUnitToolTipArmorMiniCapArmorChar(); } String internalChar = GUIP.getUnitToolTipArmorMiniISChar(); + String fontSizeAttr = String.format("class=%s", GUIP.getUnitToolTipFontSizeMod()); String col1 = ""; String col2 = ""; String col3 = ""; @@ -442,22 +627,9 @@ private static StringBuilder addArmorMiniVisToTT(Entity entity) { String rows = ""; String msg_abbr_sensors = Messages.getString("BoardView1.Tooltip.AbbreviationSensors"); - String msg_abbr_lifesupport = Messages.getString("BoardView1.Tooltip.AbbreviationLifeSupport"); String msg_abbr_engine = Messages.getString("BoardView1.Tooltip.AbbreviationEngine"); - String msg_abbr_gyro = Messages.getString("BoardView1.Tooltip.AbbreviationGyro"); - String msg_abbr_shoulder = Messages.getString("BoardView1.Tooltip.AbbreviationShoulder"); - String msg_abbr_upperarm = Messages.getString("BoardView1.Tooltip.AbbreviationUpperArm"); - String msg_abbr_lowerarm = Messages.getString("BoardView1.Tooltip.AbbreviationLowerArm"); - String msg_abbr_hand = Messages.getString("BoardView1.Tooltip.AbbreviationHand"); - String msg_abbr_hip = Messages.getString("BoardView1.Tooltip.AbbreviationHip"); - String msg_abbr_upperleg = Messages.getString("BoardView1.Tooltip.AbbreviationUpperLeg"); - String msg_abbr_lowerleg = Messages.getString("BoardView1.Tooltip.AbbreviationLowerLeg"); - String msg_abbr_foot = Messages.getString("BoardView1.Tooltip.AbbreviationLowerFoot"); - String msg_abbr_stabilizers = Messages.getString("BoardView1.Tooltip.AbbreviationStabilizers"); - String msg_abbr_turretlocked = Messages.getString("BoardView1.Tooltip.AbbreviationTurretLocked"); String msg_abbr_minormovementdamage = Messages.getString("BoardView1.Tooltip.AbbreviationMinorMovementDamage"); - String msg_abbr_moderatemovementdamage = Messages - .getString("BoardView1.Tooltip.AbbreviationModerateMovementDamage"); + String msg_abbr_moderatemovementdamage = Messages.getString("BoardView1.Tooltip.AbbreviationModerateMovementDamage"); String msg_abbr_heavymovementdamage = Messages.getString("BoardView1.Tooltip.AbbreviationHeavyMovementDamage"); for (int loc = 0; loc < entity.locations(); loc++) { @@ -472,162 +644,70 @@ private static StringBuilder addArmorMiniVisToTT(Entity entity) { if (locDestroyed) { // Destroyed location - col1 = ""; - String sLocHeader = "  " + locationHeader(entity, loc) + ": "; - col2 = "" + sLocHeader + ""; + col1 = " "; + col2 = "  " + locationHeader(entity, loc) + ": "; col2 += destroyedLocBar(entity.getOArmor(loc, true)).toString(); } else { // Rear armor if (entity.hasRearArmor(loc)) { String msg_abbr_rear = Messages.getString("BoardView1.Tooltip.AbbreviationRear"); - String sLocHeader = "  " + locationHeader(entity, loc) + msg_abbr_rear + " "; - col1 = "" + sLocHeader + ""; + col1 = "  " + locationHeader(entity, loc) + msg_abbr_rear + " "; col1 += intactLocBar(entity.getOArmor(loc, true), entity.getArmor(loc, true), armorChar).toString(); } else { // No rear armor: empty table cells instead // At small font sizes, writing one character at the correct font size is // necessary to prevent the table rows from being spaced non-beautifully - col1 = "" + " " + ""; + col1 = " "; } // Front armor - String sLocHeader = "  " + locationHeader(entity, loc) + ": "; - col2 = "" + sLocHeader + ""; + col2 = "  " + locationHeader(entity, loc) + ": "; col2 += intactLocBar(entity.getOInternal(loc), entity.getInternal(loc), internalChar).toString(); col2 += intactLocBar(entity.getOArmor(loc), entity.getArmor(loc), armorChar).toString(); } - if (entity instanceof Mek) { - switch (loc) { - case Mek.LOC_HEAD: - col3 = sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mek.SYSTEM_SENSORS, loc, msg_abbr_sensors) - .toString(); - col3 += sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mek.SYSTEM_LIFE_SUPPORT, loc, - msg_abbr_lifesupport).toString(); - break; - case Mek.LOC_CT: - col3 = sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mek.SYSTEM_ENGINE, loc, msg_abbr_engine) - .toString(); - col3 += sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mek.SYSTEM_GYRO, loc, msg_abbr_gyro) - .toString(); - col3 += sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mek.SYSTEM_SENSORS, loc, msg_abbr_sensors) - .toString(); - col3 += sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mek.SYSTEM_LIFE_SUPPORT, loc, - msg_abbr_lifesupport).toString(); - break; - case Mek.LOC_RT: - case Mek.LOC_LT: - col3 = sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mek.SYSTEM_ENGINE, loc, msg_abbr_engine) - .toString(); - col3 += sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mek.SYSTEM_LIFE_SUPPORT, loc, - msg_abbr_lifesupport).toString(); - break; - case Mek.LOC_RARM: - case Mek.LOC_LARM: - col3 = sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mek.ACTUATOR_SHOULDER, loc, msg_abbr_shoulder) - .toString(); - col3 += sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mek.ACTUATOR_UPPER_ARM, loc, - msg_abbr_upperarm).toString(); - col3 += sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mek.ACTUATOR_LOWER_ARM, loc, - msg_abbr_lowerarm).toString(); - col3 += sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mek.ACTUATOR_HAND, loc, msg_abbr_hand) - .toString(); - col3 += sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mek.ACTUATOR_HIP, loc, msg_abbr_hip) - .toString(); - col3 += sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mek.ACTUATOR_UPPER_LEG, loc, - msg_abbr_upperleg).toString(); - col3 += sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mek.ACTUATOR_LOWER_LEG, loc, - msg_abbr_lowerleg).toString(); - col3 += sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mek.ACTUATOR_FOOT, loc, msg_abbr_foot) - .toString(); - break; - case Mek.LOC_RLEG: - case Mek.LOC_LLEG: - case Mek.LOC_CLEG: - col3 = sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mek.ACTUATOR_HIP, loc, msg_abbr_hip) - .toString(); - col3 += sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mek.ACTUATOR_UPPER_LEG, loc, - msg_abbr_upperleg).toString(); - col3 += sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mek.ACTUATOR_LOWER_LEG, loc, - msg_abbr_lowerleg).toString(); - col3 += sysCrits(entity, CriticalSlot.TYPE_SYSTEM, Mek.ACTUATOR_FOOT, loc, msg_abbr_foot) - .toString(); - break; - default: - col3 = "" + " " + ""; - } - } else if (entity instanceof SuperHeavyTank || entity instanceof LargeSupportTank) { - Tank tank = (Tank) entity; - - switch (loc) { - case SuperHeavyTank.LOC_BODY: - case SuperHeavyTank.LOC_FRONT: - case SuperHeavyTank.LOC_RIGHT: - case SuperHeavyTank.LOC_LEFT: - case SuperHeavyTank.LOC_REARRIGHT: - case SuperHeavyTank.LOC_REARLEFT: - case SuperHeavyTank.LOC_REAR: - col3 = sysStabilizers(tank, loc, msg_abbr_stabilizers).toString(); - break; - case SuperHeavyTank.LOC_TURRET: - case SuperHeavyTank.LOC_TURRET_2: - col3 = sysStabilizers(tank, loc, msg_abbr_stabilizers).toString(); - col3 += tank.getTurretCount() > 0 ? sysTurretLocked(tank, loc, msg_abbr_turretlocked).toString() - : ""; - break; - default: - col3 = "" + " " + ""; - } - } else if (entity instanceof Tank) { - Tank tank = (Tank) entity; - - switch (loc) { - case Tank.LOC_BODY: - case Tank.LOC_FRONT: - case Tank.LOC_RIGHT: - case Tank.LOC_LEFT: - case Tank.LOC_REAR: - col3 = sysStabilizers(tank, loc, msg_abbr_stabilizers).toString(); - break; - case Tank.LOC_TURRET: - case Tank.LOC_TURRET_2: - col3 = sysStabilizers(tank, loc, msg_abbr_stabilizers).toString(); - col3 += tank.getTurretCount() > 0 ? sysTurretLocked(tank, loc, msg_abbr_turretlocked).toString() - : ""; - break; - default: - col3 = "" + " " + ""; - } - } + col3 = buildSysCrits(entity, loc).toString(); - col1 = "" + col1 + ""; - col2 = "" + col2 + ""; - col3 = "" + col3 + ""; - row = "" + col1 + col2 + col3 + ""; + col1 = UIUtil.tag("span", fontSizeAttr, col1); + col2 = UIUtil.tag("span", fontSizeAttr, col2); + col3 = UIUtil.tag("span", fontSizeAttr, col3); + + col1 = UIUtil.tag("TD", "", col1); + col2 = UIUtil.tag("TD", "", col2); + col3 = UIUtil.tag("TD", "", col3); + row = UIUtil.tag("TR", "", col1 + col2 + col3); rows += row; } if (entity instanceof GunEmplacement) { Tank tank = (Tank) entity; - col1 = ""; + col1 = " "; col2 = sysSensorHit(tank, msg_abbr_sensors).toString(); - col3 = ""; + col3 = " "; + + col1 = UIUtil.tag("span", fontSizeAttr, col1); + col2 = UIUtil.tag("span", fontSizeAttr, col2); + col3 = UIUtil.tag("span", fontSizeAttr, col3); - col1 = "" + col1 + ""; - col2 = "" + col2 + ""; - col3 = "" + col3 + ""; - row = "" + col1 + col2 + col3 + ""; + col1 = UIUtil.tag("TD", "", col1); + col2 = UIUtil.tag("TD", "", col2); + col3 = UIUtil.tag("TD", "", col3); + row = UIUtil.tag("TR", "", col1 + col2 + col3); rows += row; } else if (entity instanceof VTOL) { Tank tank = (Tank) entity; - col1 = ""; + col1 = " "; col2 = sysEngineHit(tank, msg_abbr_engine).toString(); col2 += sysSensorHit(tank, msg_abbr_sensors).toString(); - col3 = ""; + col3 = " "; - col1 = "" + col1 + ""; - col2 = "" + col2 + ""; - col3 = "" + col3 + ""; - row = "" + col1 + col2 + col3 + ""; + col1 = UIUtil.tag("span", fontSizeAttr, col1); + col2 = UIUtil.tag("span", fontSizeAttr, col2); + col3 = UIUtil.tag("span", fontSizeAttr, col3); + + col1 = UIUtil.tag("TD", "", col1); + col2 = UIUtil.tag("TD", "", col2); + col3 = UIUtil.tag("TD", "", col3); + row = UIUtil.tag("TR", "", col1 + col2 + col3); rows += row; } else if (entity instanceof Tank) { Tank tank = (Tank) entity; @@ -638,15 +718,22 @@ private static StringBuilder addArmorMiniVisToTT(Entity entity) { col3 += sysModerateMovementDamage(tank, msg_abbr_moderatemovementdamage).toString(); col3 += sysHeavyMovementDamage(tank, msg_abbr_heavymovementdamage).toString(); - col1 = "" + col1 + ""; - col2 = "" + col2 + ""; - col3 = "" + col3 + ""; - row = "" + col1 + col2 + col3 + ""; + col1 = UIUtil.tag("span", fontSizeAttr, col1); + col2 = UIUtil.tag("span", fontSizeAttr, col2); + col3 = UIUtil.tag("span", fontSizeAttr, col3); + + col1 = UIUtil.tag("TD", "", col1); + col2 = UIUtil.tag("TD", "", col2); + col3 = UIUtil.tag("TD", "", col3); + row = UIUtil.tag("TR", "", col1 + col2 + col3); rows += row; } - String tbody = "" + rows + ""; - String table = "" + tbody + "
"; + String attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString(GUIP.getUnitToolTipFGColor())); + rows = UIUtil.tag("FONT", attr, rows); + + String tbody = UIUtil.tag("TBODY", "", rows); + String table = UIUtil.tag("TABLE", "CELLSPACING=0 CELLPADDING=0", tbody); return new StringBuilder().append(table); } @@ -711,18 +798,18 @@ private static StringBuilder locBar(int orig, int curr, String dChar, boolean de String msg_x = Messages.getString("BoardView1.Tooltip.X"); String sIntact = dChar + msg_x + tensIntact * 10; sIntact += repeat(dChar, numIntact - 10 * tensIntact); - sIntact = UIUtil.fontHTML(colorIntact) + sIntact + ""; - result += "" + sIntact + ""; + String attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString(colorIntact)); + result += UIUtil.tag("FONT", attr, sIntact); } else { String sIntact = repeat(dChar, numIntact); - sIntact = UIUtil.fontHTML(colorIntact) + sIntact + ""; - result += "" + sIntact + ""; + String attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString(colorIntact)); + result += UIUtil.tag("FONT", attr, sIntact); } } if (numPartial > 0) { String sPartial = repeat(dChar, numPartial); - sPartial = UIUtil.fontHTML(colorPartialDmg) + sPartial + ""; - result += "" + sPartial + ""; + String attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString(colorPartialDmg)); + result += UIUtil.tag("FONT", attr, sPartial); } if (numDmgd > 0) { if (numDmgd > 15 && numIntact + numDmgd > 30) { @@ -730,12 +817,12 @@ private static StringBuilder locBar(int orig, int curr, String dChar, boolean de String msg_x = Messages.getString("BoardView1.Tooltip.X"); String sDamage = dChar + msg_x + tensDmgd * 10; sDamage += repeat(dChar, numDmgd - 10 * tensDmgd); - sDamage = UIUtil.fontHTML(colorDamaged) + sDamage + ""; - result += "" + sDamage + ""; + String attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString(colorDamaged)); + result += UIUtil.tag("FONT", attr, sDamage); } else { String sDamage = repeat(dChar, numDmgd); - sDamage = UIUtil.fontHTML(colorDamaged) + sDamage + ""; - result += "" + sDamage + ""; + String attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString(colorDamaged)); + result += UIUtil.tag("FONT", attr, sDamage); } } return new StringBuilder().append(result); @@ -756,18 +843,18 @@ private static StringBuilder systemBar(int good, int bad, boolean destroyed) { if (good > 0) { if (!destroyed) { String sGood = repeat(iChar, good); - sGood = UIUtil.fontHTML(colorIntact) + sGood + ""; - result = "" + sGood + ""; + String attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString(colorIntact)); + result += UIUtil.tag("FONT", attr, sGood); } else { String sGood = repeat(iChar, good); - sGood = UIUtil.fontHTML(colorDamaged) + sGood + ""; - result = "" + sGood + ""; + String attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString(colorDamaged)); + result += UIUtil.tag("FONT", attr, sGood); } } if (bad > 0) { String sBad = repeat(dChar, bad); - sBad = UIUtil.fontHTML(colorDamaged) + sBad + ""; - result += "" + sBad + ""; + String attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString(colorDamaged)); + result += UIUtil.tag("FONT", attr, sBad); } return new StringBuilder().append(result); } @@ -985,6 +1072,7 @@ private static StringBuilder weaponList(Entity entity) { String col2 = ""; String row = ""; String rows = ""; + String fontSizeAttr = String.format("class=%s", GUIP.getUnitToolTipFontSizeMod()); // Display sorted by weapon name var wps = new ArrayList<>(wpInfos.values()); @@ -1043,7 +1131,7 @@ private static StringBuilder weaponList(Entity entity) { col2 = addToTT("Weapon", false, currentEquip.count, techBase, nameStr, destStr).toString(); col2 += weaponModifier(isDestroyed, currentEquip); if (isDestroyed) { - col2 = "" + col2 + ""; + col2 = UIUtil.tag("S", "", col2); } } else { col1 = " "; @@ -1053,28 +1141,32 @@ private static StringBuilder weaponList(Entity entity) { col2 += addToTT("Weapon", false, currentEquip.count, techBase, nameStr, destStr).toString(); col2 += weaponModifier(isDestroyed, currentEquip); if (isDestroyed) { - col2 = "" + col2 + ""; + col2 = UIUtil.tag("S", "", col2); } col2 += "
"; } col2 = col2.substring(1, col2.length() - 4); } - ; - col1 = UIUtil.fontHTML(GUIP.getUnitToolTipWeaponColor()) + col1 + ""; - col1 = "" + col1 + ""; - col1 = "" + col1 + ""; - col2 = UIUtil.fontHTML(GUIP.getUnitToolTipWeaponColor()) + col2 + ""; - col2 = "" + col2 + ""; - col2 = "" + col2 + ""; - row = "" + col1 + col2 + ""; + String attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString(GUIP.getUnitToolTipWeaponColor())); + col1 = UIUtil.tag("FONT", attr, col1); + col1 = UIUtil.tag("span", fontSizeAttr, col1); + col1 = UIUtil.tag("TD", "", col1); + + attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString(GUIP.getUnitToolTipWeaponColor())); + col2 = UIUtil.tag("FONT", attr, col2); + col2 = UIUtil.tag("span", fontSizeAttr, col2); + col2 = UIUtil.tag("TD", "", col2); +; + row = UIUtil.tag("TR", "", col1 + col2); } rows += row; } - String tbody = "" + rows + ""; - String table = "" + tbody + "
"; + String tbody = UIUtil.tag("TBODY", "", rows); + String table = UIUtil.tag("TABLE", "CELLSPACING=0 CELLPADDING=0", tbody); + return new StringBuilder().append(table); } @@ -1085,9 +1177,11 @@ private static StringBuilder bombList(Entity entity) { String row = ""; String rows = ""; String table = ""; + String result = ""; if (entity.isBomber()) { int[] loadout = {}; + String fontSizeAttr = String.format("class=%s", GUIP.getUnitToolTipFontSizeMod()); if (entity.getGame().getPhase().isLounge()) { loadout = ((IBomber) entity).getBombChoices(); @@ -1103,13 +1197,22 @@ private static StringBuilder bombList(Entity entity) { col2 = " x "; col3 = BombType.getBombName(i); - col1 = UIUtil.fontHTML(GUIP.getUnitToolTipWeaponColor()) + col1 + ""; - col1 = "" + col1 + ""; - col2 = UIUtil.fontHTML(GUIP.getUnitToolTipWeaponColor()) + col2 + ""; - col2 = "" + col2 + ""; - col3 = UIUtil.fontHTML(GUIP.getUnitToolTipWeaponColor()) + col3 + ""; - col3 = "" + col3 + ""; - row = "" + col1 + col2 + col3 + ""; + String attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString(GUIP.getUnitToolTipWeaponColor())); + col1 = UIUtil.tag("FONT", attr, col1); + col1 = UIUtil.tag("span", fontSizeAttr, col1); + col1 = UIUtil.tag("TD", "", col1); + + attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString(GUIP.getUnitToolTipWeaponColor())); + col2 = UIUtil.tag("FONT", attr, col2); + col2 = UIUtil.tag("span", fontSizeAttr, col2); + col2 = UIUtil.tag("TD", "", col2); + + attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString(GUIP.getUnitToolTipWeaponColor())); + col3 = UIUtil.tag("FONT", attr, col3); + col3 = UIUtil.tag("span", fontSizeAttr, col3); + col3 = UIUtil.tag("TD", "", col3); + + row = UIUtil.tag("TR", "", col1 + col2 + col3); } else { row = ""; } @@ -1117,11 +1220,13 @@ private static StringBuilder bombList(Entity entity) { rows += row; } - String tbody = "" + rows + ""; - table = "" + tbody + "
"; + String tbody = UIUtil.tag("TBODY", "", rows); + table = UIUtil.tag("TABLE", "CELLSPACING=0 CELLPADDING=0", tbody); + String attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString(GUIP.getUnitToolTipFGColor())); + result = UIUtil.tag("FONT", attr, table); } - return new StringBuilder().append(table); + return new StringBuilder().append(result); } private static String weaponModifier(boolean isDestroyed, WeaponInfo currentEquip) { @@ -1130,11 +1235,11 @@ private static String weaponModifier(boolean isDestroyed, WeaponInfo currentEqui return ""; } else if (currentEquip.isHotloaded) { String msg_hotloaded = Messages.getString("BoardView1.Tooltip.HotLoaded"); - String s = " " + msg_hotloaded + ""; + String s = UIUtil.tag("I", "", msg_hotloaded); return " \u22EF" + s; } else if (currentEquip.isRapidFire) { String msg_rapidfire = Messages.getString("BoardView1.Tooltip.Rapidfire"); - String s = " " + msg_rapidfire + ""; + String s = UIUtil.tag("I", "", msg_rapidfire); return " \u22EF" + s; } return ""; @@ -1146,18 +1251,23 @@ private static StringBuilder createAmmoEntry(WeaponInfo ammoInfo) { String col2 = ""; String row = ""; String rows = ""; + String fontSizeAttr = String.format("class=%s", GUIP.getUnitToolTipFontSizeMod()); int totalAmmo = ammoInfo.ammos.values().stream().mapToInt(n -> n).sum(); if (totalAmmo == 0 && ammoInfo.ammoActiveWeaponCount > 0) { String msg_outofammo = Messages.getString("BoardView1.Tooltip.OutOfAmmo"); col1 = " "; - col1 = "" + col1 + ""; - col1 = "" + col1 + ""; col2 = "      " + msg_outofammo; - col2 = UIUtil.fontHTML(GUIP.getCautionColor()) + col2 + ""; - col2 = "" + col2 + ""; - col2 = "" + col2 + ""; - row = "" + col1 + col2 + ""; + + col1 = UIUtil.tag("span", fontSizeAttr, col1); + col1 = UIUtil.tag("TD", "", col1); + + String attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString(GUIP.getCautionColor())); + col2 = UIUtil.tag("FONT", attr, col2); + col2 = UIUtil.tag("span", fontSizeAttr, col2); + col2 = UIUtil.tag("TD", "", col2); + + row = UIUtil.tag("TR", "", col1 + col2); rows += row; } else { for (Entry ammo : ammoInfo.ammos.entrySet()) { @@ -1182,12 +1292,15 @@ private static StringBuilder createAmmoEntry(WeaponInfo ammoInfo) { col2 += ammoName + ammo.getValue() + " " + msg_shots; } - col1 = "" + col1 + ""; - col1 = "" + col1 + ""; - col2 = UIUtil.fontHTML(GUIP.getCautionColor()) + col2 + ""; - col2 = "" + col2 + ""; - col2 = "" + col2 + ""; - row = "" + col1 + col2 + ""; + col1 = UIUtil.tag("span", fontSizeAttr, col1); + col1 = UIUtil.tag("TD", "", col1); + + String attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString(GUIP.getCautionColor())); + col2 = UIUtil.tag("FONT", attr, col2); + col2 = UIUtil.tag("span", fontSizeAttr, col2); + col2 = UIUtil.tag("TD", "", col2); + + row = UIUtil.tag("TR", "", col1 + col2); rows += row; } } @@ -1208,9 +1321,15 @@ private static StringBuilder ecmInfo(Entity entity) { sECMInfo += ECM_SIGN + " " + msg_eccmsource; } - sECMInfo = UIUtil.fontHTML() + sECMInfo + ""; - result = "" + sECMInfo + ""; - result = UIUtil.fontHTML() + result + ""; + if (!sECMInfo.isEmpty()) { + String fontSizeAttr = String.format("class=%s", GUIP.getUnitToolTipFontSizeMod()); + sECMInfo = UIUtil.tag("span", fontSizeAttr, sECMInfo); + + String col = UIUtil.tag("TD", "", sECMInfo); + String row = UIUtil.tag("TR", "", col); + String tbody = UIUtil.tag("TBODY", "", row); + result = UIUtil.tag("TABLE", "CELLSPACING=0 CELLPADDING=0", tbody); + } return new StringBuilder().append(result); } @@ -1280,14 +1399,14 @@ public static String getOneLineSummary(Entity entity) { result += ' ' + getDamageLevelDesc(entity, true); if (!isGunEmplacement && entity.isImmobile()) { - result += ' ' + UIUtil.fontHTML(GUIP.getWarningColor()) - + Messages.getString("BoardView1.Tooltip.Immobile") + ""; + String attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString(GUIP.getWarningColor())); + result += UIUtil.tag("FONT", attr, Messages.getString("BoardView1.Tooltip.Immobile")); } // Unit Prone if (!isGunEmplacement && entity.isProne()) { - result += ' ' + UIUtil.fontHTML(GUIP.getWarningColor()) + Messages.getString("BoardView1.Tooltip.Prone") - + ""; + String attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString(GUIP.getWarningColor())); + result += UIUtil.tag("FONT", attr, Messages.getString("BoardView1.Tooltip.Prone")); } return result; @@ -1312,20 +1431,22 @@ public static String getSensorDesc(Entity e) { public static String getDamageLevelDesc(Entity entity, boolean useHtml) { String result; + String attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString(GUIP.getWarningColor())); if (entity.isDoomed() || entity.isDestroyed()) { String msg_destroyed = Messages.getString("BoardView1.Tooltip.Destroyed"); - return useHtml ? UIUtil.fontHTML(GUIP.getWarningColor()) + msg_destroyed + "" : msg_destroyed; + + return useHtml ? UIUtil.tag("FONT", attr, msg_destroyed) : msg_destroyed; } switch (entity.getDamageLevel()) { case Entity.DMG_CRIPPLED: String msg_crippled = Messages.getString("BoardView1.Tooltip.Crippled"); - result = useHtml ? UIUtil.fontHTML(GUIP.getWarningColor()) + msg_crippled + "" : msg_crippled; + result = useHtml ? UIUtil.tag("FONT", attr, msg_crippled) : msg_crippled; break; case Entity.DMG_HEAVY: String msg_heavydmg = Messages.getString("BoardView1.Tooltip.HeavyDmg"); - result = useHtml ? UIUtil.fontHTML(GUIP.getWarningColor()) + msg_heavydmg + "" : msg_heavydmg; + result = useHtml ? UIUtil.tag("FONT", attr, msg_heavydmg) : msg_heavydmg; break; case Entity.DMG_MODERATE: String msg_moderatedmg = Messages.getString("BoardView1.Tooltip.ModerateDmg"); @@ -1343,110 +1464,104 @@ public static String getDamageLevelDesc(Entity entity, boolean useHtml) { return result; } - /** Returns values that only are relevant when in-game such as heat. */ - private static StringBuilder inGameValues(Entity entity, Player localPlayer, boolean inGameValue, - boolean showBV, boolean showSensors, boolean showSeenBy) { - Game game = entity.getGame(); - GameOptions gameOptions = game.getOptions(); - PlanetaryConditions conditions = game.getPlanetaryConditions(); - boolean isGunEmplacement = entity instanceof GunEmplacement; + private static String getBvInfo(GameOptions gameOptions, Entity entity, Player localPlayer, boolean showBV) { String result = ""; - - if (!inGameValue) { - return new StringBuilder(); - } - if (showBV) { // BV Info // Hidden for invisible units when in double blind and hide enemy bv is selected // Also not shown in the lobby as BV is shown there outside the tooltip boolean showEnemyBV = !(gameOptions.booleanOption(OptionsConstants.ADVANCED_SUPPRESS_DB_BV) - && gameOptions.booleanOption(OptionsConstants.ADVANCED_DOUBLE_BLIND)); + && gameOptions.booleanOption(OptionsConstants.ADVANCED_DOUBLE_BLIND)); boolean isVisible = EntityVisibilityUtils.trackThisEntitiesVisibilityInfo(localPlayer, entity); if (isVisible || showEnemyBV) { int currentBV = entity.calculateBattleValue(false, false); int initialBV = entity.getInitialBV(); double percentage = (double) currentBV / initialBV; - result += addToTT("BV", BR, currentBV, initialBV, percentage).toString(); + result += addToTT("BV", false, currentBV, initialBV, percentage).toString(); } } - result += " " + getDamageLevelDesc(entity, true); + return result; + } - // Actual Movement - if (!isGunEmplacement) { - // "Has not yet moved" only during movement phase - if (!entity.isDone() && game.getPhase().isMovement()) { - String sNotYetMoved = addToTT("NotYetMoved", BR).toString(); - sNotYetMoved = "" + sNotYetMoved + ""; - result += UIUtil.fontHTML(GUIP.getColorForMovement(entity.moved)) + sNotYetMoved + ""; - } else if ((entity.isDone() && game.getPhase().isMovement()) - || (game.getPhase().isMovementReport()) - || (game.getPhase().isFiring()) - || (game.getPhase().isFiringReport()) - || (game.getPhase().isPhysical()) - || (game.getPhase().isPhysicalReport())) { - int tmm = Compute.getTargetMovementModifier(game, entity.getId()).getValue(); - String sMove = ""; - - if (entity.moved == EntityMovementType.MOVE_NONE) { - sMove = addToTT("NoMove", BR, tmm).toString(); - sMove = "" + sMove + ""; - } else { - sMove = addToTT("MovementF", BR, entity.getMovementString(entity.moved), - entity.delta_distance, tmm).toString(); - sMove = "" + sMove + ""; - } + private static String getMovementInfo(Game game, Entity entity) { + String result = ""; + // "Has not yet moved" only during movement phase + if (!entity.isDone() && game.getPhase().isMovement()) { + String sNotYetMoved = addToTT("NotYetMoved", NOBR).toString(); + String attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString(GUIP.getColorForMovement(entity.moved))); + sNotYetMoved = UIUtil.tag("FONT", attr, sNotYetMoved); + result += UIUtil.tag("I", "", sNotYetMoved); + } else if ((entity.isDone() && game.getPhase().isMovement()) + || (game.getPhase().isMovementReport()) + || (game.getPhase().isFiring()) + || (game.getPhase().isFiringReport()) + || (game.getPhase().isPhysical()) + || (game.getPhase().isPhysicalReport())) { + int tmm = Compute.getTargetMovementModifier(game, entity.getId()).getValue(); + String sMove = ""; + + if (entity.moved == EntityMovementType.MOVE_NONE) { + sMove = addToTT("NoMove", NOBR, tmm).toString(); + sMove = UIUtil.tag("I", "", sMove); + } else { + sMove = addToTT("MovementF", NOBR, entity.getMovementString(entity.moved), + entity.delta_distance, tmm).toString(); + sMove = UIUtil.tag("I", "", sMove); + } - // Special Moves - if (entity.isEvading()) { - String sSpecialMove = addToTT("Evade", BR).toString(); - sSpecialMove = "" + sSpecialMove + ""; - sSpecialMove = UIUtil.fontHTML(GUIP.getPrecautionColor()) + sSpecialMove + ""; - sMove += sSpecialMove; - } + // Special Moves + if (entity.isEvading()) { + String sSpecialMove = addToTT("Evade", NOBR).toString(); + String attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString(GUIP.getPrecautionColor())); + sSpecialMove = UIUtil.tag("FONT", attr, sSpecialMove); + sSpecialMove = UIUtil.tag("I", "", sSpecialMove); + sMove += sSpecialMove; + } - if ((entity instanceof Infantry) && ((Infantry) entity).isTakingCover()) { - String sTakingCover = addToTT("TakingCover", BR).toString(); - sTakingCover = "" + sTakingCover + ""; - sTakingCover = UIUtil.fontHTML(GUIP.getPrecautionColor()) + sTakingCover + ""; - sMove += sTakingCover; - } + if ((entity instanceof Infantry) && ((Infantry) entity).isTakingCover()) { + String sTakingCover = addToTT("TakingCover", NOBR).toString(); + String attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString(GUIP.getPrecautionColor())); + sTakingCover = UIUtil.tag("FONT", attr, sTakingCover); + sTakingCover = UIUtil.tag("I", "", sTakingCover); + sMove += sTakingCover; + } - if (entity.isCharging()) { - sMove += addToTT("Charging", BR).toString(); - } + if (entity.isCharging()) { + sMove += addToTT("Charging", NOBR).toString(); + } - if (entity.isMakingDfa()) { - String sDFA = addToTT("DFA", BR).toString(); - sDFA = "" + sDFA + ""; - sDFA = UIUtil.fontHTML(GUIP.getWarningColor()) + sDFA + ""; - sMove += sDFA; - } + if (entity.isMakingDfa()) { + String sDFA = addToTT("DFA", NOBR).toString(); + sDFA = UIUtil.tag("I", "", sDFA); + String attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString(GUIP.getWarningColor())); + sDFA = UIUtil.tag("FONT", attr, sDFA); + sMove += sDFA; + } - if (entity.isUnjammingRAC()) { - String sUnJamming = "
"; - String msg_unjammingrac = Messages.getString("BoardView1.Tooltip.UnjammingRAC"); - sUnJamming += msg_unjammingrac; - if (entity.getGame().getOptions().booleanOption(OptionsConstants.ADVCOMBAT_UNJAM_UAC)) { - String msg_andac = Messages.getString("BoardView1.Tooltip.AndAC"); - sUnJamming += msg_andac; - } - sMove += sUnJamming; + if (entity.isUnjammingRAC()) { + String sUnJamming = " "; + String msg_unjammingrac = Messages.getString("BoardView1.Tooltip.UnjammingRAC"); + sUnJamming += msg_unjammingrac; + if (entity.getGame().getOptions().booleanOption(OptionsConstants.ADVCOMBAT_UNJAM_UAC)) { + String msg_andac = Messages.getString("BoardView1.Tooltip.AndAC"); + sUnJamming += msg_andac; } - - result += UIUtil.fontHTML(GUIP.getColorForMovement(entity.moved)) + sMove + ""; + sMove += sUnJamming; } + + String attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString(GUIP.getColorForMovement(entity.moved))); + result += UIUtil.tag("FONT", attr, sMove); } if (entity instanceof Infantry) { InfantryMount mount = ((Infantry) entity).getMount(); if ((mount != null) && entity.getMovementMode().isSubmarine() && (entity.underwaterRounds > 0)) { - String uw = "
" - + addToTT("InfUWDuration", NOBR, mount.getUWEndurance() - entity.underwaterRounds).toString(); + String uw = " " + addToTT("InfUWDuration", NOBR, mount.getUWEndurance() - entity.underwaterRounds); if (entity.underwaterRounds >= mount.getUWEndurance()) { - uw = UIUtil.fontHTML(GUIP.getWarningColor()) + uw + ""; + String attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString(GUIP.getWarningColor())); + uw = UIUtil.tag("FONT", attr, uw); } result += uw; } @@ -1457,198 +1572,320 @@ private static StringBuilder inGameValues(Entity entity, Player localPlayer, boo if (entity.isAero()) { // Velocity, Altitude, Elevation, Fuel IAero aero = (IAero) entity; - sAeroInfo = addToTT("AeroVelAltFuel", BR, aero.getCurrentVelocity(), aero.getAltitude(), - aero.getCurrentFuel()).toString(); + sAeroInfo = addToTT("AeroVelAltFuel", NOBR, aero.getCurrentVelocity(), aero.getAltitude(), + aero.getCurrentFuel()).toString(); } else if (entity.getElevation() != 0) { // Elevation only - sAeroInfo = addToTT("Elev", BR, entity.getElevation()).toString(); + sAeroInfo = addToTT("Elev", NOBR, entity.getElevation()).toString(); } - sAeroInfo = "" + sAeroInfo + ""; - result += UIUtil.fontHTML(GUIP.getUnitToolTipHighlightColor()) + sAeroInfo + ""; - result += "
"; - String msg_facing = Messages.getString("BoardView1.Tooltip.Facing"); - String sFacingTwist = "  " + msg_facing + ": " + entity.getFacingName(entity.getFacing()); - if (entity.getFacing() != entity.getSecondaryFacing()) { - String msg_twist = Messages.getString("BoardView1.Tooltip.Twist"); - sFacingTwist += "  " + msg_twist + ": " + entity.getFacingName(entity.getSecondaryFacing()); - } - result += UIUtil.fontHTML() + sFacingTwist + ""; + String attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString(GUIP.getUnitToolTipHighlightColor())); + sAeroInfo = UIUtil.tag("FONT", attr, sAeroInfo); + result += UIUtil.tag("I", attr, sAeroInfo); + + return result; + } + + private static String getHeatInfo(Entity entity) { + String attr = ""; + String result = ""; // Heat, not shown for units with 999 heat sinks (vehicles) if (entity.getHeatCapacity() != 999) { int heat = entity.heat; String sHeat = ""; if (heat == 0) { - sHeat += addToTT("Heat0", BR).toString(); + sHeat += addToTT("Heat0", NOBR).toString(); } else { - sHeat += addToTT("Heat", BR, heat).toString(); + sHeat += addToTT("Heat", NOBR, heat).toString(); } HeatDisplayHelper hdh = getHeatCapacityForDisplay(entity); sHeat += " / " + hdh.heatCapacityStr; - result += UIUtil.fontHTML(GUIP.getColorForHeat(heat, GUIP.getUnitToolTipFGColor())) + sHeat + ""; + attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString(GUIP.getColorForHeat(heat, GUIP.getUnitToolTipFGColor()))); + result += UIUtil.tag("FONT", attr, sHeat); if (entity instanceof Mek && ((Mek) entity).hasActiveTSM()) { result += DOT_SPACER; String sTSM = "TSM"; - result += UIUtil.fontHTML(GUIP.getPrecautionColor()) + sTSM + ""; + attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString(GUIP.getColorForHeat(heat, GUIP.getPrecautionColor()))); + result += UIUtil.tag("FONT", attr, sTSM); } } String illuminated = entity.isIlluminated() ? DOT_SPACER + "\uD83D\uDCA1" : ""; - result += UIUtil.fontHTML(GUIP.getCautionColor()) + illuminated + ""; + if (!illuminated.isEmpty()) { + attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString((GUIP.getCautionColor()))); + result += UIUtil.tag("FONT", attr, illuminated); + } if (entity.hasSearchlight()) { - String searchLight = entity.isUsingSearchlight() ? DOT_SPACER + "\uD83D\uDD26" : ""; + String searchLight = entity.isUsingSearchlight() ? DOT_SPACER + "\uD83D\uDD26" : " "; searchLight += entity.usedSearchlight() ? " \u2580\u2580" : ""; - result += UIUtil.fontHTML(GUIP.getCautionColor()) + searchLight + ""; + attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString((GUIP.getCautionColor()))); + result += UIUtil.tag("FONT", attr, searchLight); } else { String searchLight = "\uD83D\uDD26"; - result += UIUtil.fontHTML(GUIP.getWarningColor()) + DOT_SPACER + searchLight + ""; + attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString((GUIP.getWarningColor()))); + result += UIUtil.tag("FONT", attr, DOT_SPACER + searchLight); } + return result; + } + + private static String getUnitStatus(Game game, Entity entity, boolean isGunEmplacement) { + String attr = ""; + String result = ""; + // Gun Emplacement Status if (isGunEmplacement) { GunEmplacement emp = (GunEmplacement) entity; if (emp.isTurret() && emp.isTurretLocked(emp.getLocTurret())) { - String sTurretLocked = addToTT("TurretLocked", BR).toString(); - sTurretLocked = "" + sTurretLocked + ""; - result += UIUtil.fontHTML(GUIP.getWarningColor()) + sTurretLocked + ""; + String sTurretLocked = addToTT("TurretLocked", NOBR).toString() + " "; + attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString((GUIP.getWarningColor()))); + sTurretLocked = UIUtil.tag("FONT", attr, sTurretLocked); + result += UIUtil.tag("I", "", sTurretLocked); } } // Unit Immobile if (!isGunEmplacement && entity.isImmobile()) { - String sImmobile = addToTT("Immobile", BR).toString(); - result += UIUtil.fontHTML(GUIP.getWarningColor()) + sImmobile + ""; + String sImmobile = addToTT("Immobile", NOBR).toString() + " "; + attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString((GUIP.getWarningColor()))); + result += UIUtil.tag("FONT", attr, sImmobile); } // Unit Prone if (!isGunEmplacement && entity.isProne()) { - String sUnitProne = addToTT("Prone", BR).toString(); - result += UIUtil.fontHTML(GUIP.getCautionColor()) + sUnitProne + ""; + String sUnitProne = addToTT("Prone", NOBR).toString() + " "; + attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString((GUIP.getCautionColor()))); + result += UIUtil.tag("FONT", attr, sUnitProne); } if (!entity.getHiddenActivationPhase().isUnknown()) { - result += addToTT("HiddenActivating", BR, entity.getHiddenActivationPhase().toString()).toString(); + result += addToTT("HiddenActivating", NOBR, entity.getHiddenActivationPhase().toString()).toString() + " "; } else if (entity.isHidden()) { - result += addToTT("Hidden", BR).toString(); + result += addToTT("Hidden", BR).toString() + " "; } - // Jammed by ECM - don't know how to replicate this correctly from the boardview - // if (isAffectedByECM()) { - // addToTT("Jammed", BR); - // } - // Swarmed if (entity.getSwarmAttackerId() != Entity.NONE) { final Entity swarmAttacker = game.getEntity(entity.getSwarmAttackerId()); if (swarmAttacker == null) { logger.error(String.format( - "Entity %s is currently swarmed by an unknown attacker with id %s", - entity.getId(), entity.getSwarmAttackerId())); + "Entity %s is currently swarmed by an unknown attacker with id %s", + entity.getId(), entity.getSwarmAttackerId())); } String msg_error = Messages.getString("ERROR"); String sa = (swarmAttacker == null) ? msg_error : swarmAttacker.getDisplayName(); - String sSwarmed = addToTT("Swarmed", BR, sa).toString(); - result += UIUtil.fontHTML(GUIP.getWarningColor()) + sSwarmed + ""; + String sSwarmed = addToTT("Swarmed", NOBR, sa).toString() + " "; + attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString((GUIP.getWarningColor()))); + result += UIUtil.tag("FONT", attr, sSwarmed); } // Spotting if (entity.isSpotting() && game.hasEntity(entity.getSpotTargetId())) { - String sSpotting = addToTT("Spotting", BR, game.getEntity(entity.getSpotTargetId()).getDisplayName()) - .toString(); - result += UIUtil.fontHTML() + sSpotting + ""; + String sSpotting = addToTT("Spotting", NOBR, game.getEntity(entity.getSpotTargetId()).getDisplayName()) + .toString() + " "; + result += sSpotting; } - if (showSeenBy) { - // If Double Blind, add information about who sees this Entity - if (gameOptions.booleanOption(OptionsConstants.ADVANCED_DOUBLE_BLIND)) { - StringBuffer tempList = new StringBuffer(); - boolean teamVision = gameOptions.booleanOption(OptionsConstants.ADVANCED_TEAM_VISION); - int seenByResolution = GUIP.getUnitToolTipSeenByResolution(); - String tmpStr = ""; - - dance: for (Player player : entity.getWhoCanSee()) { - if (player.isEnemyOf(entity.getOwner()) || !teamVision) { - switch (seenByResolution) { - case 0: - String msg_someone = Messages.getString("BoardView1.Tooltip.Someone"); - tempList.append(msg_someone); - tempList.append(", "); - break dance; - case 1: - Team team = game.getTeamForPlayer(player); - tmpStr = team != null ? team.toString() : ""; - break; - case 2: - tmpStr = player.getName(); - break; - case 3: - tmpStr = player.toString(); - break; - default: - break dance; - } + if (entity.hasAnyTypeNarcPodsAttached()) { + String sNarced = addToTT(entity.hasNarcPodsAttached() ? "Narced" : "INarced", NOBR).toString() + " "; + attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString((GUIP.getPrecautionColor()))); + result += UIUtil.tag("FONT", attr, sNarced); + } + + // Towing + if (!entity.getAllTowedUnits().isEmpty()) { + String unitList = entity.getAllTowedUnits().stream() + .map(id -> entity.getGame().getEntity(id).getShortName()) + .collect(Collectors.joining(", ")); + if (unitList.length() > 1) { + result += addToTT("Towing", NOBR, unitList).toString() + " "; + } + } + + return result; + } + + private static String getSeenByInfo(Game game, GameOptions gameOptions, Entity entity) { + String result = ""; - if (tempList.indexOf(tmpStr) == -1) { - tempList.append(tmpStr); + // If Double Blind, add information about who sees this Entity + if (gameOptions.booleanOption(OptionsConstants.ADVANCED_DOUBLE_BLIND)) { + StringBuffer tempList = new StringBuffer(); + boolean teamVision = gameOptions.booleanOption(OptionsConstants.ADVANCED_TEAM_VISION); + int seenByResolution = GUIP.getUnitToolTipSeenByResolution(); + String tmpStr = ""; + + dance: for (Player player : entity.getWhoCanSee()) { + if (player.isEnemyOf(entity.getOwner()) || !teamVision) { + switch (seenByResolution) { + case 0: + String msg_someone = Messages.getString("BoardView1.Tooltip.Someone"); + tempList.append(msg_someone); tempList.append(", "); - } + break dance; + case 1: + Team team = game.getTeamForPlayer(player); + tmpStr = team != null ? team.toString() : ""; + break; + case 2: + tmpStr = player.getName(); + break; + case 3: + tmpStr = player.toString(); + break; + default: + break dance; + } + + if (tempList.indexOf(tmpStr) == -1) { + tempList.append(tmpStr); + tempList.append(", "); } } - if (tempList.length() > 1) { - tempList.delete(tempList.length() - 2, tempList.length()); - String sSeenBy = addToTT("SeenBy", BR, tempList.toString()).toString(); - sSeenBy = UIUtil.fontHTML() + sSeenBy + ""; - result += "" + sSeenBy + ""; - } + } + if (tempList.length() > 1) { + tempList.delete(tempList.length() - 2, tempList.length()); + String sSeenBy = addToTT("SeenBy", NOBR, tempList.toString()).toString(); + result = sSeenBy; } } - if (showSensors) { - String sensors = ""; - // If sensors, display what sensors this unit is using - if (gameOptions.booleanOption(OptionsConstants.ADVANCED_TACOPS_SENSORS) - || (gameOptions.booleanOption(OptionsConstants.ADVAERORULES_STRATOPS_ADVANCED_SENSORS)) - && entity.isSpaceborne()) { - String visualRange = Compute.getMaxVisualRange(entity, false) + ""; - if (conditions.getLight().isDuskOrFullMoonOrMoonlessOrPitchBack()) { - visualRange += " (" + Compute.getMaxVisualRange(entity, true) + ")"; - } - sensors += addToTT("Sensors", BR, getSensorDesc(entity), visualRange); - } else { - String visualRange = Compute.getMaxVisualRange(entity, false) + ""; - if (conditions.getLight().isDuskOrFullMoonOrMoonlessOrPitchBack()) { - visualRange += " (" + Compute.getMaxVisualRange(entity, true) + ")"; - } - sensors += addToTT("Visual", BR, visualRange); + return result; + } + + private static String getSensorInfo(GameOptions gameOptions, Entity entity, PlanetaryConditions conditions) { + String sensors = ""; + // If sensors, display what sensors this unit is using + if (gameOptions.booleanOption(OptionsConstants.ADVANCED_TACOPS_SENSORS) + || (gameOptions.booleanOption(OptionsConstants.ADVAERORULES_STRATOPS_ADVANCED_SENSORS)) + && entity.isSpaceborne()) { + String visualRange = Compute.getMaxVisualRange(entity, false) + ""; + if (conditions.getLight().isDuskOrFullMoonOrMoonlessOrPitchBack()) { + visualRange += " (" + Compute.getMaxVisualRange(entity, true) + ")"; } - if (gameOptions.booleanOption(OptionsConstants.ADVANCED_TACOPS_BAP) && entity.hasBAP()) { - sensors += addToTT("BAPRange", NOBR, entity.getBAPRange()); + sensors += addToTT("Sensors", NOBR, getSensorDesc(entity), visualRange); + } else { + String visualRange = Compute.getMaxVisualRange(entity, false) + ""; + if (conditions.getLight().isDuskOrFullMoonOrMoonlessOrPitchBack()) { + visualRange += " (" + Compute.getMaxVisualRange(entity, true) + ")"; } - result += "" + sensors + ""; + sensors += addToTT("Visual", NOBR, visualRange); + } + if (gameOptions.booleanOption(OptionsConstants.ADVANCED_TACOPS_BAP) && entity.hasBAP()) { + sensors += addToTT("BAPRange", NOBR, entity.getBAPRange()); } - if (entity.hasAnyTypeNarcPodsAttached()) { - String sNarced = addToTT(entity.hasNarcPodsAttached() ? "Narced" : "INarced", BR).toString(); - result += UIUtil.fontHTML(GUIP.getPrecautionColor()) + sNarced + ""; + return sensors; + } + + /** Returns values that only are relevant when in-game such as heat. */ + private static StringBuilder inGameValues(Entity entity, Player localPlayer, boolean inGameValue, + boolean showBV, boolean showSensors, boolean showSeenBy) { + String col = ""; + String row = ""; + String rows = ""; + String attr = ""; + Game game = entity.getGame(); + GameOptions gameOptions = game.getOptions(); + PlanetaryConditions conditions = game.getPlanetaryConditions(); + boolean isGunEmplacement = entity instanceof GunEmplacement; + String fontSizeAttr = String.format("class=%s", GUIP.getUnitToolTipFontSizeMod()); + + if (!inGameValue) { + return new StringBuilder(); } - // Towing - if (!entity.getAllTowedUnits().isEmpty()) { - String unitList = entity.getAllTowedUnits().stream() - .map(id -> entity.getGame().getEntity(id).getShortName()) - .collect(Collectors.joining(", ")); - if (unitList.length() > 1) { - result += addToTT("Towing", BR, unitList).toString(); + // BV and Damage + String bvDamageLevel = getBvInfo(gameOptions, entity, localPlayer, showBV); + + bvDamageLevel += " " + getDamageLevelDesc(entity, true); + + if (!bvDamageLevel.isEmpty()) { + attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString((GUIP.getUnitToolTipHighlightColor()))); + bvDamageLevel = UIUtil.tag("FONT", attr, bvDamageLevel); + bvDamageLevel = UIUtil.tag("span", fontSizeAttr, bvDamageLevel); + col = UIUtil.tag("TD", "", bvDamageLevel); + row = UIUtil.tag("TR", "", col); + rows += row; + } + + // Actual Movement + if (!isGunEmplacement) { + String movementInfo = getMovementInfo(game, entity); + if (!movementInfo.isEmpty()) { + movementInfo = UIUtil.tag("span", fontSizeAttr, movementInfo); + col = UIUtil.tag("TD", "", movementInfo); + row = UIUtil.tag("TR", "", col); + rows += row; } } - // Coloring to make these transient entries stand out - result = UIUtil.fontHTML(GUIP.getUnitToolTipHighlightColor()) + result + ""; + // Facing + String msg_facing = Messages.getString("BoardView1.Tooltip.Facing"); + String sFacingTwist = "  " + msg_facing + ": " + entity.getFacingName(entity.getFacing()); - return new StringBuilder().append(result); + if (entity.getFacing() != entity.getSecondaryFacing()) { + String msg_twist = Messages.getString("BoardView1.Tooltip.Twist"); + sFacingTwist += "  " + msg_twist + ": " + entity.getFacingName(entity.getSecondaryFacing()); + } + + if (!sFacingTwist.isEmpty()) { + attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString((GUIP.getUnitToolTipHighlightColor()))); + sFacingTwist = UIUtil.tag("FONT", attr, sFacingTwist); + sFacingTwist = UIUtil.tag("span", fontSizeAttr, sFacingTwist); + col = UIUtil.tag("TD", "", sFacingTwist); + row = UIUtil.tag("TR", "", col); + rows += row; + } + + // Heat + String heatInfo = getHeatInfo(entity); + if (!heatInfo.isEmpty()) { + heatInfo = UIUtil.tag("span", fontSizeAttr, heatInfo); + col = UIUtil.tag("TD", "", heatInfo); + row = UIUtil.tag("TR", "", col); + rows += row; + } + + // Unit status + String unitStatus = getUnitStatus(game, entity, isGunEmplacement); + if (!unitStatus.isEmpty()) { + unitStatus = UIUtil.tag("span", fontSizeAttr, unitStatus); + col = UIUtil.tag("TD", "", unitStatus); + row = UIUtil.tag("TR", "", col); + rows += row; + } + + // Seen by + if (showSeenBy) { + String seenByInfo = getSeenByInfo(game, gameOptions, entity);; + if (!seenByInfo.isEmpty()) { + attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString((GUIP.getUnitToolTipHighlightColor()))); + seenByInfo = UIUtil.tag("FONT", attr, seenByInfo); + seenByInfo = UIUtil.tag("span", fontSizeAttr, seenByInfo); + col = UIUtil.tag("TD", "", seenByInfo); + row = UIUtil.tag("TR", "", col); + rows += row; + } + } + + // Sensors + if (showSensors) { + String sensorInfo = getSensorInfo(gameOptions, entity, conditions); + attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString((GUIP.getUnitToolTipHighlightColor()))); + sensorInfo = UIUtil.tag("FONT", attr, sensorInfo); + sensorInfo = UIUtil.tag("span", fontSizeAttr, sensorInfo); + col = UIUtil.tag("TD", "", sensorInfo); + row = UIUtil.tag("TR", "", col); + rows += row; + } + + String table = UIUtil.tag("TABLE", "CELLSPACING=0 CELLPADDING=0", rows); + + return new StringBuilder().append(table); } /** @@ -1657,11 +1894,11 @@ private static StringBuilder inGameValues(Entity entity, Player localPlayer, boo */ private static StringBuilder getMovement(Entity entity) { boolean isGunEmplacement = entity instanceof GunEmplacement; + String fontSizeAttr = String.format("class=%s", GUIP.getUnitToolTipFontSizeMod()); String result = ""; - String l1 = ""; - String l2 = ""; - String l3 = ""; - String l4 = ""; + String col = ""; + String row = ""; + String rows = ""; // Unit movement ability if (!isGunEmplacement) { @@ -1765,14 +2002,16 @@ private static StringBuilder getMovement(Entity entity) { if (entity.getGame().getPlanetaryConditions().getGravity() != 1.0) { sMove += DOT_SPACER; String sGravity = entity.getGame().getPlanetaryConditions().getGravity() + "g"; - sMove += UIUtil.fontHTML(GUIP.getWarningColor()) + sGravity + ""; + String attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString((GUIP.getWarningColor()))); + sMove += UIUtil.tag("FONT", attr, sGravity); } int walkMPNoHeat = entity.getWalkMP(MPCalculationSetting.NO_HEAT); int runMPNoHeat = entity.getRunMP(MPCalculationSetting.NO_HEAT); if ((walkMPNoHeat != walkMPModified) || (runMPNoHeat != runMPModified)) { sMove += DOT_SPACER; String sHeat = "\uD83D\uDD25"; - sMove += UIUtil.fontHTML(GUIP.getWarningColor()) + sHeat + ""; + String attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString((GUIP.getWarningColor()))); + sMove += UIUtil.tag("FONT", attr, sHeat); } } @@ -1782,7 +2021,8 @@ private static StringBuilder getMovement(Entity entity) { if (bombMod != walkMP) { sMove += DOT_SPACER; String sBomb = "\uD83D\uDCA3"; - sMove += UIUtil.fontHTML(GUIP.getWarningColor()) + sBomb + ""; + String attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString((GUIP.getWarningColor()))); + sMove += UIUtil.tag("FONT", attr, sBomb); } } @@ -1791,7 +2031,8 @@ private static StringBuilder getMovement(Entity entity) { if ((weatherMod != 0) || (partialWingWeaterMod != 0)) { sMove += DOT_SPACER; String sWeather = "\u2602"; - sMove += UIUtil.fontHTML(GUIP.getWarningColor()) + sWeather + ""; + String attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString((GUIP.getWarningColor()))); + sMove += UIUtil.tag("FONT", attr, sWeather); } if ((legsDestroyed > 0) || (hipHits > 0) || (actuatorHits > 0) || (jumpJetDistroyed > 0) @@ -1799,7 +2040,8 @@ private static StringBuilder getMovement(Entity entity) { || (jumpBoosterDistroyed > 0) || (entity.isImmobile()) || (entity.isGyroDestroyed())) { sMove += DOT_SPACER; String sDamage = "\uD83D\uDD27"; - sMove += UIUtil.fontHTML(GUIP.getWarningColor()) + sDamage + ""; + String attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString((GUIP.getWarningColor()))); + sMove += UIUtil.tag("FONT", attr, sDamage); } if ((entity instanceof BipedMek) || (entity instanceof TripodMek)) { @@ -1812,18 +2054,22 @@ private static StringBuilder getMovement(Entity entity) { if (shieldMod != 0) { sMove += DOT_SPACER; String sShield = "\u26E8"; - sMove += UIUtil.fontHTML(GUIP.getWarningColor()) + sShield + ""; + String attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString((GUIP.getWarningColor()))); + sMove += UIUtil.tag("FONT", attr, sShield); } } if (entity.hasModularArmor()) { sMove += DOT_SPACER; String sArmor = "\u27EC\u25AE"; - sMove += DOT_SPACER + UIUtil.fontHTML(GUIP.getWarningColor()) + sArmor + ""; + String attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString((GUIP.getWarningColor()))); + sMove += UIUtil.tag("FONT", attr, sArmor); } - l1 = "
  • " - + sMove + "
  • "; + sMove = UIUtil.tag("span", fontSizeAttr, sMove); + col = UIUtil.tag("TD", "", sMove); + row = UIUtil.tag("TR", "", col); + rows += row; if ((jumpJetDistroyed > 0) || (jumpBoosterDistroyed > 0) || (paritalWingDistroyed > 0)) { String jj = ""; @@ -1842,8 +2088,11 @@ private static StringBuilder getMovement(Entity entity) { if (jj.startsWith(";")) { jj = jj.substring(2); } - l2 = "
  • " + jj - + "
  • "; + + jj = UIUtil.tag("span", fontSizeAttr, jj); + col = UIUtil.tag("TD", "", jj); + row = UIUtil.tag("TR", "", col); + rows += row; } } @@ -1853,14 +2102,18 @@ private static StringBuilder getMovement(Entity entity) { int spec = inf.getSpecializations(); if (spec > 0) { String sInfantrySpec = addToTT("InfSpec", NOBR, Infantry.getSpecializationName(spec)).toString(); - l3 = "
  • " - + sInfantrySpec + "
  • "; + sInfantrySpec = UIUtil.tag("span", fontSizeAttr, sInfantrySpec); + col = UIUtil.tag("TD", "", sInfantrySpec); + row = UIUtil.tag("TR", "", col); + rows += row; } } - String ul = "
      " + l1 + l2 - + l3 + "
    "; - result = UIUtil.fontHTML() + ul + ""; + String tbody = UIUtil.tag("TBODY", "", rows); + String table = UIUtil.tag("TABLE", "CELLSPACING=0 CELLPADDING=0", tbody); + + String attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString(GUIP.getUnitToolTipFGColor())); + result = UIUtil.tag("FONT", attr, table); return new StringBuilder().append(result); } @@ -1869,14 +2122,21 @@ private static StringBuilder getArmor(Entity entity) { boolean isGunEmplacement = entity instanceof GunEmplacement; String result = ""; String l1 = ""; + String col = ""; + String row = ""; + String rows = ""; + String fontSizeAttr = String.format("class=%s", GUIP.getUnitToolTipFontSizeMod()); // Armor and Internals if (entity instanceof FighterSquadron) { String msg_armorcapital = Messages.getString("BoardView1.Tooltip.ArmorCapital"); String armorStr = entity.getTotalArmor() + " / " + entity.getTotalOArmor() + " " + msg_armorcapital; String sArmorInternals = Messages.getString("BoardView1.Tooltip.FSQTotalArmor", armorStr); - l1 = "
  • " - + sArmorInternals + "
  • "; + sArmorInternals = UIUtil.tag("span", fontSizeAttr, sArmorInternals); + + col = UIUtil.tag("TD", "", sArmorInternals); + row = UIUtil.tag("TR", "", col); + rows += row; } else if (!isGunEmplacement) { String msg_unknown = Messages.getString("BoardView1.Tooltip.Unknown"); String armorType = TROView.formatArmorType(entity, true).replace(msg_unknown, ""); @@ -1888,13 +2148,18 @@ private static StringBuilder getArmor(Entity entity) { String armorStr = entity.getTotalArmor() + " / " + entity.getTotalOArmor() + armorType; String internalStr = entity.getTotalInternal() + " / " + entity.getTotalOInternal(); String sArmorInternals = addToTT("ArmorInternals", NOBR, armorStr, internalStr).toString(); - l1 = "
  • " - + sArmorInternals + "
  • "; + sArmorInternals = UIUtil.tag("span", fontSizeAttr, sArmorInternals); + + col = UIUtil.tag("TD", "", sArmorInternals); + row = UIUtil.tag("TR", "", col); + rows += row; } - String ul = "
      " + l1 - + "
    "; - result = UIUtil.fontHTML() + ul + ""; + String tbody = UIUtil.tag("TBODY", "", rows); + String table = UIUtil.tag("TABLE", "CELLSPACING=0 CELLPADDING=0", tbody); + + String attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString(GUIP.getUnitToolTipFGColor())); + result = UIUtil.tag("FONT", attr, table); return new StringBuilder().append(result); } @@ -1926,7 +2191,8 @@ private static StringBuilder deploymentWarnings(Entity entity, MapSettings mapSe String msg_cannotsurvivespace = Messages.getString("BoardView1.Tooltip.CannotSurviveSpace"); sWarnings += "
    " + msg_cannotsurvivespace; } - result += UIUtil.fontHTML(GUIP.getWarningColor()) + sWarnings + ""; + + result += sWarnings; String sNoncritial = ""; // Non-critical (yellow) warnings @@ -1943,7 +2209,16 @@ private static StringBuilder deploymentWarnings(Entity entity, MapSettings mapSe sNoncritial += "
    " + msg_fightersquadronempty; } - result += UIUtil.fontHTML(GUIP.getCautionColor()) + sNoncritial + "" + "
    "; + result += sNoncritial; + if (!result.isEmpty()) { + String attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString(GUIP.getCautionColor())); + result += UIUtil.tag("FONT", attr, result); + + String col = UIUtil.tag("TD", "", result); + String row = UIUtil.tag("TR", "", col); + String tbody = UIUtil.tag("TBODY", "", row); + result = UIUtil.tag("TABLE", "CELLSPACING=0 CELLPADDING=0", tbody); + } return new StringBuilder().append(result); } @@ -1969,8 +2244,13 @@ private static StringBuilder carriedUnits(Entity entity) { } } - sCarriedUnits = UIUtil.fontHTML() + sCarriedUnits + ""; - result = "" + sCarriedUnits + ""; + String fontSizeAttr = String.format("class=%s", GUIP.getUnitToolTipFontSizeMod()); + sCarriedUnits = UIUtil.tag("span", fontSizeAttr, sCarriedUnits); + + String col = UIUtil.tag("TD", "", sCarriedUnits); + String row = UIUtil.tag("TR", "", col); + String tbody = UIUtil.tag("TBODY", "", row); + result = UIUtil.tag("TABLE", "CELLSPACING=0 CELLPADDING=0", tbody); } return new StringBuilder().append(result); @@ -1978,21 +2258,38 @@ private static StringBuilder carriedUnits(Entity entity) { private static StringBuilder carriedCargo(Entity entity) { StringBuilder sb = new StringBuilder(); + String result = ""; List cargoList = entity.getDistinctCarriedObjects(); if (!cargoList.isEmpty()) { - sb.append(UIUtil.fontHTML()); - sb.append(Messages.getString("MissionRole.cargo")); - sb.append(":
      "); + String carriedCargo = Messages.getString("MissionRole.cargo"); + carriedCargo += ":
      "; for (ICarryable cargo : entity.getDistinctCarriedObjects()) { - sb.append(cargo.toString()); - sb.append("
      "); + carriedCargo += cargo.toString(); + carriedCargo += "
      "; } - sb.append(""); + + String col = UIUtil.tag("TD", "", carriedCargo); + String row = UIUtil.tag("TR", "", col); + String tbody = UIUtil.tag("TBODY", "", row); + result = UIUtil.tag("TABLE", "CELLSPACING=0 CELLPADDING=0", tbody); } - return sb; + return sb.append(result); + } + + + private static String getForceInfo(Entity entity) { + String sForceEntry = ""; + var forceChain = entity.getGame().getForces().forceChain(entity); + + for (int i = forceChain.size() - 1; i >= 0; i--) { + sForceEntry += forceChain.get(i).getName(); + sForceEntry += i != 0 ? ", " : ""; + } + + return sForceEntry; } /** Returns the full force chain the entity is in as one text line. */ @@ -2008,15 +2305,19 @@ private static StringBuilder forceEntry(Entity entity, Player localPlayer) { } else if (localPlayer != null && !localPlayer.isEnemyOf(entity.getOwner())) { color = GUIP.getAllyUnitColor(); } - color = addGray(color, 128).brighter(); - sForceEntry = "
    "; - var forceChain = entity.getGame().getForces().forceChain(entity); - for (int i = forceChain.size() - 1; i >= 0; i--) { - sForceEntry += forceChain.get(i).getName(); - sForceEntry += i != 0 ? ", " : ""; + + String force = getForceInfo(entity); + if (!force.isEmpty()) { + String attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString(color)); + sForceEntry = UIUtil.tag("FONT", attr, force); + String fontSizeAttr = String.format("class=%s", GUIP.getUnitToolTipFontSizeMod()); + sForceEntry = UIUtil.tag("span", fontSizeAttr, sForceEntry); + + String col = UIUtil.tag("TD", "", sForceEntry); + String row = UIUtil.tag("TR", "", col); + String tbody = UIUtil.tag("TBODY", "", row); + result = UIUtil.tag("TABLE", "CELLSPACING=0 CELLPADDING=0", tbody); } - sForceEntry = UIUtil.fontHTML(color) + sForceEntry + ""; - result = "" + sForceEntry + ""; } return new StringBuilder().append(result); @@ -2047,9 +2348,15 @@ private static StringBuilder c3Info(Entity entity, boolean details) { sC3Info += "
    "; } - sC3Info = UIUtil.fontHTML(GUIP.getUnitToolTipHighlightColor()) + sC3Info + ""; - result = "" + sC3Info + ""; + String attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString(GUIP.getUnitToolTipHighlightColor())); + sC3Info = UIUtil.tag("FONT", attr, sC3Info); + String fontSizeAttr = String.format("class=%s", GUIP.getUnitToolTipFontSizeMod()); + sC3Info = UIUtil.tag("span", fontSizeAttr, sC3Info); + String col = UIUtil.tag("TD", "", sC3Info); + String row = UIUtil.tag("TR", "", col); + String tbody = UIUtil.tag("TBODY", "", row); + result = UIUtil.tag("TABLE", "CELLSPACING=0 CELLPADDING=0", tbody); } return new StringBuilder().append(result); @@ -2069,16 +2376,19 @@ private static String c3UnitName(Entity c3member, Entity entity) { msg_c3 = Messages.getString("BoardView1.Tooltip.C3M") + " "; } - sC3UnitName += "" + msg_c3 + ""; - sC3UnitName = UIUtil.fontHTML(GUIP.getUnitToolTipFGColor()) + sC3UnitName + ""; - result += "" + sC3UnitName + ""; + sC3UnitName += UIUtil.tag("I", "", msg_c3); + String attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString(GUIP.getUnitToolTipFGColor())); + sC3UnitName = UIUtil.tag("FONT", attr, sC3UnitName); + String fontSizeAttr = String.format("class=%s", GUIP.getUnitToolTipFontSizeMod()); + result += UIUtil.tag("span", fontSizeAttr, sC3UnitName); result += c3member.getShortNameRaw(); String msg_thisunit = " (" + Messages.getString("BoardView1.Tooltip.ThisUnit") + ")"; - tmp = "" + msg_thisunit + ""; + tmp += UIUtil.tag("I", "", msg_thisunit); String sC3Member = c3member.equals(entity) ? tmp : ""; - sC3Member = UIUtil.fontHTML(GUIP.getUnitToolTipFGColor()) + sC3Member + ""; - result += "" + sC3Member + ""; + attr = String.format("FACE=Dialog COLOR=%s", UIUtil.toColorHexString(GUIP.getUnitToolTipFGColor())); + sC3Member = UIUtil.tag("FONT", attr, sC3Member); + result += UIUtil.tag("span", fontSizeAttr, sC3Member); return result; } diff --git a/megamek/src/megamek/client/ui/swing/unitDisplay/SummaryPanel.java b/megamek/src/megamek/client/ui/swing/unitDisplay/SummaryPanel.java index 8c24a9dabc..6cecbd8919 100644 --- a/megamek/src/megamek/client/ui/swing/unitDisplay/SummaryPanel.java +++ b/megamek/src/megamek/client/ui/swing/unitDisplay/SummaryPanel.java @@ -32,6 +32,7 @@ import megamek.client.ui.swing.tooltip.HexTooltip; import megamek.client.ui.swing.tooltip.PilotToolTip; import megamek.client.ui.swing.tooltip.UnitToolTip; +import megamek.client.ui.swing.util.UIUtil; import megamek.client.ui.swing.widget.BackGroundDrawer; import megamek.client.ui.swing.widget.PMUtil; import megamek.client.ui.swing.widget.PicMap; @@ -70,7 +71,6 @@ public class SummaryPanel extends PicMap { panel.add(unitInfo); } - private void setBackGround() { UnitDisplaySkinSpecification udSpec = SkinXMLHandler.getUnitDisplaySkin(); @@ -145,30 +145,47 @@ public void displayMek(Entity entity) { } else if (EntityVisibilityUtils.onlyDetectedBySensors(localPlayer, entity)) { txt = padLeft(Messages.getString("BoardView1.sensorReturn")); } else { - // This is html tables inside tables to maintain transparency to the bg image but - // also allow cells do have bg colors - StringBuilder hexTxt = new StringBuilder(); - hexTxt.append(PilotToolTip.getPilotTipDetailed(entity, true)); - hexTxt.append(UnitToolTip.getEntityTipUnitDisplay(entity, localPlayer)); String col; String row; + String rows = ""; + // This is html tables inside tables to maintain transparency to the bg image but + // also allow cells do have bg colors + String pilotTip = PilotToolTip.getPilotTipDetailed(entity, true).toString(); + col = UIUtil.tag("TD", "", pilotTip); + row = UIUtil.tag("TR", "", col); + rows += row; + + String unitTip = UnitToolTip.getEntityTipUnitDisplay(entity, localPlayer).toString(); + col = UIUtil.tag("TD", "", unitTip); + row = UIUtil.tag("TR", "", col); + rows += row; + Hex mhex = entity.getGame().getBoard().getHex(entity.getPosition()); if (mhex != null) { - StringBuilder sb = new StringBuilder(); - sb.append(HexTooltip.getTerrainTip(mhex, GUIP, entity.getGame())); - col = "" + sb + ""; - row = "" + col + ""; - hexTxt.append("" + row + "
    "); - sb.append(HexTooltip.getHexTip(mhex, unitDisplay.getClientGUI().getClient(), GUIP)); + String terrainTip = HexTooltip.getTerrainTip(mhex, GUIP, entity.getGame()); + String attr = String.format("FACE=Dialog BGCOLOR=%s", UIUtil.toColorHexString(GUIP.getUnitToolTipTerrainBGColor())); + col = UIUtil.tag("TD", attr, terrainTip); + row = UIUtil.tag("TR", "", col); + rows += row; + + String hexTip = HexTooltip.getHexTip(mhex, unitDisplay.getClientGUI().getClient(), GUIP); + if (!hexTip.isEmpty()) { + attr = String.format("FACE=Dialog BGCOLOR=%s", UIUtil.toColorHexString(GUIP.getUnitToolTipTerrainBGColor())); + col = UIUtil.tag("TD", attr, hexTip); + row = UIUtil.tag("TR", "", col); + rows += row; + } } - String t = PilotToolTip.getCrewAdvs(entity, true).toString(); - col = "" + t + ""; - row = "" + col + ""; - hexTxt.append("" + row + "
    "); - txt = padLeft(hexTxt.toString()); + String edgeTip = PilotToolTip.getCrewAdvs(entity, true).toString(); + col = UIUtil.tag("TD", "", edgeTip); + row = UIUtil.tag("TR", "", col); + rows += row; + + String table = UIUtil.tag("TABLE", "CELLSPACING=0 CELLPADDING=0 width=100%", rows); + txt = padLeft(table); + //txt = table; } unitInfo.setText(UnitToolTip.wrapWithHTML(txt)); @@ -176,15 +193,11 @@ public void displayMek(Entity entity) { } private String padLeft(String html) { - int dist = 5; - String col = ""; - String row = ""; - String tbody = ""; - String table = ""; - col = "" + html + ""; - row = "" + col + ""; - tbody = "" + row + ""; - table = "" + tbody + "
    "; + int dist = 4; + String col = UIUtil.tag("TD", "", html); + String row = UIUtil.tag("TR", "", col); + String attr = String.format("CELLSPACING=0 CELLPADDING=%s width=100%%", dist); + String table = UIUtil.tag("TABLE", attr, row); return table; } diff --git a/megamek/src/megamek/client/ui/swing/unitDisplay/WeaponPanel.java b/megamek/src/megamek/client/ui/swing/unitDisplay/WeaponPanel.java index 8b38e7a540..a4244c3639 100644 --- a/megamek/src/megamek/client/ui/swing/unitDisplay/WeaponPanel.java +++ b/megamek/src/megamek/client/ui/swing/unitDisplay/WeaponPanel.java @@ -482,7 +482,6 @@ void setupTextPane(JTextPane pane) { pane.setBackground(TEXT_BG); pane.setEditable(false); pane.setOpaque(true); - pane.setFont(new Font(MMConstants.FONT_SANS_SERIF, Font.PLAIN, 10)); } private void addSubdisplay(JPanel parent, JComponent child, int minHeight, int fill) { diff --git a/megamek/src/megamek/client/ui/swing/util/UIUtil.java b/megamek/src/megamek/client/ui/swing/util/UIUtil.java index 95ff27801f..889c83cee9 100644 --- a/megamek/src/megamek/client/ui/swing/util/UIUtil.java +++ b/megamek/src/megamek/client/ui/swing/util/UIUtil.java @@ -106,6 +106,16 @@ public static String fontHTML(float deltaScale) { return ""; } + /** + * Returns an HTML - tag attribute text end tag + */ + public static String tag(String tag, String attributes, String text) { + attributes = attributes.isEmpty() ? attributes : ' ' + attributes; + String format = "<%s%s>%s"; + String result = String.format(format, tag, attributes, text, tag); + return result; + } + /** Returns the yellow and gui-scaled warning sign. */ public static String warningSign() { return fontHTML(uiYellow()) + WARNING_SIGN + ""; @@ -1196,6 +1206,14 @@ public static String colorString(Color col) { return " COLOR=" + Integer.toHexString(col.getRGB() & 0xFFFFFF) + " "; } + /** + * Returns Color Hex String, e.g. #FFFFFF according to the given + * color. + */ + public static String toColorHexString(Color col) { + return Integer.toHexString(col.getRGB() & 0xFFFFFF); + } + private static int uiBgBrightness() { Color bgColor = UIManager.getColor("Table.background"); if (bgColor == null) { diff --git a/megamek/src/megamek/common/Report.java b/megamek/src/megamek/common/Report.java index 7d8b899ad1..527999f635 100644 --- a/megamek/src/megamek/common/Report.java +++ b/megamek/src/megamek/common/Report.java @@ -724,6 +724,8 @@ public static void setupStylesheet(StyleSheet styleSheet) { styleSheet.addRule("span.success { color: " + hexColor(GUIP.getReportSuccessColor()) + " }"); styleSheet.addRule("span.miss { color: " + hexColor(GUIP.getReportMissColor()) + " }"); styleSheet.addRule("span.info { color: " + hexColor(GUIP.getReportInfoColor()) + " }"); + styleSheet.addRule("span.large { font-size: large; }"); + styleSheet.addRule("span.medium { font-size: medium; }"); styleSheet.addRule("span.small { font-size: small; }"); styleSheet.addRule("span.x-small { font-size: x-small; }"); styleSheet.addRule("span.xx-small { font-size: xx-small; }");