Skip to content

Commit

Permalink
Speed up unit help. (#11957)
Browse files Browse the repository at this point in the history
  • Loading branch information
asvitkine authored Sep 13, 2023
1 parent 7259890 commit 190c090
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import games.strategy.engine.data.UnitTypeList;
import games.strategy.triplea.delegate.Matches;
import games.strategy.triplea.image.UnitImageFactory.ImageKey;
import games.strategy.triplea.ui.TooltipProperties;
import games.strategy.triplea.ui.UiContext;
import games.strategy.triplea.util.UnitCategory;
import java.awt.Color;
Expand Down Expand Up @@ -271,7 +270,8 @@ private JPanel getUnitButtonPanel(
"<html>"
+ category.getType().getName()
+ ": "
+ new TooltipProperties(uiContext)
+ uiContext
.getTooltipProperties()
.getTooltip(category.getType(), category.getOwner())
+ "</html>";
final ImageIcon img = uiContext.getUnitImageFactory().getIcon(ImageKey.of(category));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import games.strategy.engine.data.Unit;
import games.strategy.engine.data.UnitType;
import games.strategy.triplea.delegate.Matches;
import games.strategy.triplea.ui.TooltipProperties;
import games.strategy.triplea.ui.UiContext;
import games.strategy.triplea.util.UnitCategory;
import games.strategy.ui.ScrollableTextField;
Expand Down Expand Up @@ -38,7 +37,7 @@ public class UnitPanel extends JPanel {
+ ": "
+ costs.getInt(category.getType())
+ " cost, <br /> &nbsp;&nbsp;&nbsp;&nbsp; "
+ new TooltipProperties(uiContext).getTooltip(category.getType(), category.getOwner())
+ uiContext.getTooltipProperties().getTooltip(category.getType(), category.getOwner())
+ "</html>";
setCount(category.getUnits().size());
setLayout(new GridBagLayout());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public static String getTooltipTextForUnit(
count == 1 ? "" : (count + " "),
StringUtils.capitalize(unitType.getName()),
player.getName());
return firstLine + new TooltipProperties(uiContext).getTooltip(unitType, player);
return firstLine + uiContext.getTooltipProperties().getTooltip(unitType, player);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ protected JPanel getPanelComponent() {
tooltip
.append(type.getName())
.append(": ")
.append(new TooltipProperties(uiContext).getTooltip(type, player));
.append(uiContext.getTooltipProperties().getTooltip(type, player));
name.setText(type.getName());
if (attach.getConsumesUnits().totalValues() == 1) {
name.setForeground(Color.CYAN);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public class UiContext {
@Getter private final TileImageFactory tileImageFactory = new TileImageFactory();
@Getter private UnitImageFactory unitImageFactory;
@Getter private final ResourceImageFactory resourceImageFactory = new ResourceImageFactory();
@Getter private final TooltipProperties tooltipProperties;

@Getter
private final TerritoryEffectImageFactory territoryEffectImageFactory =
Expand Down Expand Up @@ -152,6 +153,7 @@ public class UiContext {
log.error("Failed to create cursor from: " + cursorUrl, e);
}
}
tooltipProperties = new TooltipProperties(this);
}

public JLabel newUnitImageLabel(final ImageKey imageKey) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import games.strategy.engine.data.UnitType;
import games.strategy.triplea.image.UnitImageFactory;
import games.strategy.triplea.image.UnitImageFactory.ImageKey;
import games.strategy.triplea.ui.TooltipProperties;
import games.strategy.triplea.ui.UiContext;
import games.strategy.triplea.util.TuvUtils;
import java.util.ArrayList;
Expand Down Expand Up @@ -72,7 +71,7 @@ public static String getUnitStatsTable(final GameData gameData, final UiContext
.append(costs.get(player).get(ut).toStringForHtml())
.append("</td>")
.append("<td>")
.append(new TooltipProperties(uiContext).getTooltip(ut, player))
.append(uiContext.getTooltipProperties().getTooltip(ut, player))
.append("</td></tr>");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ private static JPanel unitsInTerritoryPanel(
"<html>"
+ item.getType().getName()
+ ": "
+ new TooltipProperties(uiContext).getTooltip(item.getType(), currentPlayer)
+ uiContext.getTooltipProperties().getTooltip(item.getType(), currentPlayer)
+ "</html>";
label.setToolTipText(toolTipText);
panel.add(label);
Expand Down

0 comments on commit 190c090

Please sign in to comment.