Skip to content

Commit

Permalink
Merge pull request #4932 from kuronekochomusuke/tooltipIllumination
Browse files Browse the repository at this point in the history
add illumination indicator to the hextooltip and unittooltip
  • Loading branch information
NickAragua authored Dec 5, 2023
2 parents 94266d8 + d3fe70e commit c045637
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 11 deletions.
2 changes: 1 addition & 1 deletion megamek/src/megamek/client/ui/swing/GUIPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ protected GUIPreferences() {
setDefault(BOARD_MOVE_FONT_STYLE, Font.BOLD);
store.setDefault(BOARD_ATTACK_ARROW_TRANSPARENCY, 0x80);
store.setDefault(BOARD_ECM_TRANSPARENCY, 0x80);
store.setDefault(BOARD_DARKEN_MAP_AT_NIGHT, false);
store.setDefault(BOARD_DARKEN_MAP_AT_NIGHT, true);
store.setDefault(BOARD_TRANSLUCENT_HIDDEN_UNITS, true);
setDefault(BOARD_TMM_PIP_MODE, 2); // show pips with colors based on move type

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5754,7 +5754,7 @@ public void appendTerrainTooltip(StringBuffer txt, @Nullable Hex mhex) {
if (mhex == null) {
return;
}
txt.append(HexTooltip.getTerrainTip(mhex));
txt.append(HexTooltip.getTerrainTip(mhex, game));
}

/**
Expand Down
11 changes: 7 additions & 4 deletions megamek/src/megamek/client/ui/swing/tooltip/HexTooltip.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
import megamek.common.*;
import megamek.common.annotations.Nullable;
import megamek.common.enums.BasementType;
import megamek.common.enums.IlluminationLevel;

import java.util.Vector;

import static megamek.client.ui.swing.tooltip.TipUtil.BUILDING_BGCOLOR;
import static megamek.client.ui.swing.tooltip.TipUtil.LIGHT_BGCOLOR;
import static megamek.client.ui.swing.util.UIUtil.guiScaledFontHTML;
import static megamek.client.ui.swing.util.UIUtil.uiBlack;
import static megamek.client.ui.swing.util.UIUtil.*;

public final class HexTooltip {

Expand Down Expand Up @@ -155,6 +155,7 @@ public static String getHexTip(Hex mhex, @Nullable Client client) {
result.append("<BR>");
}
}

return result.toString();
}

Expand Down Expand Up @@ -187,17 +188,19 @@ public static String getOneLineSummary(BuildingTarget target, Board board) {
return result;
}

public static String getTerrainTip(Hex mhex)
public static String getTerrainTip(Hex mhex, Game game)
{
Coords mcoords = mhex.getCoords();
String illuminated = IlluminationLevel.getIlluminationLevelIndicator(game, mcoords);
String result = "";
StringBuilder sTerrain = new StringBuilder(Messages.getString("BoardView1.Tooltip.Hex", mcoords.getBoardNum(), mhex.getLevel()) + "<BR>");
StringBuilder sTerrain = new StringBuilder(Messages.getString("BoardView1.Tooltip.Hex", mcoords.getBoardNum(), mhex.getLevel()) + illuminated + "<BR>");

// cycle through the terrains and report types found
for (int terType: mhex.getTerrainTypes()) {
int tf = mhex.getTerrain(terType).getTerrainFactor();
int ttl = mhex.getTerrain(terType).getLevel();
String name = Terrains.getDisplayName(terType, ttl);

if (name != null) {
String msg_tf = Messages.getString("BoardView1.Tooltip.TF");
name += (tf > 0) ? " (" + msg_tf + ": " + tf + ')' : "";
Expand Down
17 changes: 12 additions & 5 deletions megamek/src/megamek/client/ui/swing/tooltip/UnitToolTip.java
Original file line number Diff line number Diff line change
Expand Up @@ -1369,9 +1369,17 @@ private static StringBuilder inGameValues(Entity entity, Player localPlayer, boo
}
}

String searchLight = entity.isUsingSearchlight() ? DOT_SPACER +"\uD83D\uDD26" : "";
searchLight += entity.usedSearchlight() ? " \u2580\u2580" : "";
result += guiScaledFontHTML(uiYellow()) + searchLight + "</FONT>";
String illuminated = entity.isIlluminated() ? DOT_SPACER +"\uD83D\uDCA1" : "";
result += guiScaledFontHTML(uiYellow()) + illuminated + "</FONT>";

if (entity.hasSearchlight()) {
String searchLight = entity.isUsingSearchlight() ? DOT_SPACER + "\uD83D\uDD26" : "";
searchLight += entity.usedSearchlight() ? " \u2580\u2580" : "";
result += guiScaledFontHTML(uiYellow()) + searchLight + "</FONT>";
} else {
String searchLight = "\uD83D\uDD26";
result += guiScaledFontHTML(GUIP.getWarningColor()) + DOT_SPACER + searchLight + "</FONT>";
}

// Gun Emplacement Status
if (isGunEmplacement) {
Expand Down Expand Up @@ -1505,9 +1513,8 @@ private static StringBuilder inGameValues(Entity entity, Player localPlayer, boo
}
}

// Coloring and italic to make these transient entries stand out
// Coloring to make these transient entries stand out
result = guiScaledFontHTML(uiLightViolet()) + result + "</FONT>";
result = "<I>" + result + "</I>";

return new StringBuilder().append(result);
}
Expand Down
15 changes: 15 additions & 0 deletions megamek/src/megamek/common/enums/IlluminationLevel.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

import java.util.Objects;

import static megamek.client.ui.swing.util.UIUtil.*;

public enum IlluminationLevel {
//region Enum Declarations
NONE,
Expand Down Expand Up @@ -88,4 +90,17 @@ public static IlluminationLevel determineIlluminationLevel(final Game game, fina

return neighbouringFire ? IlluminationLevel.FIRE : IlluminationLevel.NONE;
}

public static String getIlluminationLevelIndicator(final Game game, final Coords coords) {
switch (IlluminationLevel.determineIlluminationLevel(game, coords)) {
case FIRE:
return DOT_SPACER + guiScaledFontHTML(uiYellow()) + " \uD83D\uDD25" + "</FONT>";
case FLARE:
return DOT_SPACER + guiScaledFontHTML(uiYellow()) + " \uD83C\uDF86" + "</FONT>";
case SEARCHLIGHT:
return DOT_SPACER + guiScaledFontHTML(uiYellow()) + " \uD83D\uDD26" + "</FONT>";
default:
return "";
}
}
}
1 change: 1 addition & 0 deletions megamek/src/megamek/common/util/SerializationHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public static XStream getSaveGameXStream() {
megamek.common.CompositeTechLevel.DateRange.class,
megamek.common.CriticalSlot.class,
megamek.common.EquipmentMode.class,
megamek.common.Flare.class,
megamek.common.Game.class,
megamek.common.Hex.class,
megamek.common.Minefield.class,
Expand Down

0 comments on commit c045637

Please sign in to comment.