Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

limit the width of the unit tooltip so that it does not grow really wide #4468

Merged
merged 3 commits into from
Jun 4, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions megamek/i18n/megamek/client/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1278,6 +1278,8 @@ CommonSettingsDialog.translucentHiddenUnits=Make unseen units translucent
CommonSettingsDialog.uiTheme=UI Theme:
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.useAverageSkills=Use the current random skill settings when adding units in the lobby.
CommonSettingsDialog.useCamoOverlay=Use Camo Overlay
CommonSettingsDialog.useInclines=Show incline highlighting and shadows at hex borders
Expand Down
7 changes: 5 additions & 2 deletions megamek/src/megamek/client/ui/swing/AimedShotDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import megamek.client.ui.Messages;
import megamek.client.ui.swing.tooltip.UnitToolTip;
import megamek.client.ui.swing.util.UIUtil;
import megamek.client.ui.swing.widget.IndexedRadioButton;
import megamek.common.Targetable;
import megamek.common.annotations.Nullable;
Expand All @@ -44,6 +45,8 @@ public class AimedShotDialog extends JDialog {
private IndexedRadioButton[] checkboxes;
private boolean[] boxEnabled;

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

public AimedShotDialog(JFrame parent, String title, String message,
String[] choices, boolean[] enabled, int selectedIndex,
ClientGUI clientGUI, Targetable target,
Expand All @@ -66,8 +69,8 @@ public AimedShotDialog(JFrame parent, String title, String message,
gridbag.setConstraints(labMessage, c);
getContentPane().add(labMessage);

JLabel labTarget = new JLabel("<html>" + UnitToolTip.getTargetTipDetail(target, clientGUI.getClient().getBoard(), clientGUI) + "</hmtl>",
SwingConstants.LEFT);
String div = "<DIV WIDTH=" + GUIP.getUnitToolTipMaxWidth() + ">" + UnitToolTip.getTargetTipDetail(target, clientGUI.getClient().getBoard(), clientGUI) + "</DIV>";
JLabel labTarget = new JLabel("<html>" + div + "</hmtl>", SwingConstants.LEFT);
c.weightx = 1.0;
c.weighty = 1.0;
c.gridwidth = 0;
Expand Down
15 changes: 15 additions & 0 deletions megamek/src/megamek/client/ui/swing/CommonSettingsDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ private <T> void moveElement(DefaultListModel<T> srcModel, int srcIndex, int trg
private JTextField unitDisplayMechArmorSmallFontSizeText;
private JTextField unitDisplayMechLargeFontSizeText;
private JTextField unitDisplayMechMeduimFontSizeText;
private JSpinner unitTooltipMaxWidth;

// Report
private JTextPane reportKeywordsTextPane;
Expand Down Expand Up @@ -985,6 +986,16 @@ private JPanel getUnitDisplayPanel() {
row.add(unitTooltipSeenbyCbo);
comps.add(row);

SpinnerNumberModel munitTooltipMaxWidth = new SpinnerNumberModel(GUIP.getUnitToolTipMaxWidth(), 0, 20000, 1);
kuronekochomusuke marked this conversation as resolved.
Show resolved Hide resolved
unitTooltipMaxWidth = new JSpinner(munitTooltipMaxWidth);
unitTooltipMaxWidth.setMaximumSize(new Dimension(150, 40));
JLabel unitTooltipMaxWidthLabel = new JLabel(Messages.getString("CommonSettingsDialog.unitTooltipMaxWidth"));
row = new ArrayList<>();
row.add(unitTooltipMaxWidth);
row.add(unitTooltipMaxWidthLabel);
unitTooltipMaxWidth.setToolTipText(Messages.getString("CommonSettingsDialog.unitTooltipMaxWidth.tooltip"));
comps.add(row);

JLabel phaseLabel = new JLabel(Messages.getString("CommonSettingsDialog.colors.UnitDisplayHeatLevels"));
row = new ArrayList<>();
row.add(phaseLabel);
Expand Down Expand Up @@ -1775,6 +1786,8 @@ protected void cancelAction() {
unitTooltipSeenbyCbo.setSelectedIndex(GUIP.getUnitToolTipSeenByResolution());
unitDisplayWeaponListHeightText.setText(String.format("%d", GUIP.getUnitDisplayWeaponListHeight()));

unitTooltipMaxWidth.setValue(GUIP.getUnitToolTipMaxWidth());

unitDisplayMechArmorLargeFontSizeText.setText(String.format("%d", GUIP.getUnitDisplayMechArmorLargeFontSize()));
unitDisplayMechArmorMediumFontSizeText.setText(String.format("%d", GUIP.getUnitDisplayMechArmorMediumFontSize()));
unitDisplayMechArmorSmallFontSizeText.setText(String.format("%d", GUIP.getUnitDisplayMechArmorSmallFontSize()));
Expand Down Expand Up @@ -2187,6 +2200,8 @@ protected void okAction() {
LogManager.getLogger().error("", ex);
}

GUIP.setUnitTooltipMaxWidth((Integer) unitTooltipMaxWidth.getValue());

try {
GUIP.setUnitDisplayMechArmorLargeFontSize(Integer.parseInt(unitDisplayMechArmorLargeFontSizeText.getText()));
} catch (Exception ex) {
Expand Down
4 changes: 3 additions & 1 deletion megamek/src/megamek/client/ui/swing/EntityChoiceDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
* in brief or in detail.
*/
public class EntityChoiceDialog extends AbstractChoiceDialog<Entity> {
private static final GUIPreferences GUIP = GUIPreferences.getInstance();

/**
* This creates a modal dialog to pick one or more entities.
Expand All @@ -45,7 +46,8 @@ protected EntityChoiceDialog(JFrame frame, String title, String message,

@Override
protected void detailLabel(JToggleButton button, Entity target) {
button.setText("<html>" + UnitToolTip.getEntityTipVitals(target, null) + "</html>");
String div = "<DIV WIDTH=" + GUIP.getUnitToolTipMaxWidth() + ">" + UnitToolTip.getEntityTipVitals(target, null) + "</DIV>";
button.setText("<html>" + div + "</html>");
}

@Override
Expand Down
10 changes: 10 additions & 0 deletions megamek/src/megamek/client/ui/swing/GUIPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ public class GUIPreferences extends PreferenceStoreProxy {
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_MAX_WIDTH = "UnitToolTipMaxWidth";

public static final String SPLIT_PANE_A_DIVIDER_LOCATION = "SplitPaneADividerLocation";
public static final String GAME_SUMMARY_BOARD_VIEW = "GameSummaryBoardView";
Expand Down Expand Up @@ -560,6 +561,7 @@ protected GUIPreferences() {
setDefault(UNIT_TOOLTIP_ARMORMINI_COLOR_DAMAGED, DEFAULT_MEDIUM_DARK_RED);
store.setDefault(UNIT_TOOLTIP_ARMORMINI_FONT_SIZE_MOD, -2);
setDefault(UNIT_DISPLAY_WEAPON_LIST_HEIGHT, 200);
store.setDefault(UNIT_TOOLTIP_MAX_WIDTH, 500);

store.setDefault(GAME_SUMMARY_BOARD_VIEW, false);
store.setDefault(ENTITY_OWNER_LABEL_COLOR, true);
Expand Down Expand Up @@ -2669,6 +2671,10 @@ public int getUnitToolTipArmorMiniFontSizeMod() {
return getInt(UNIT_TOOLTIP_ARMORMINI_FONT_SIZE_MOD);
}

public int getUnitToolTipMaxWidth() {
return getInt(UNIT_TOOLTIP_MAX_WIDTH);
}

public boolean getDockOnLeft() {
return getBoolean(DOCK_ON_LEFT);
}
Expand Down Expand Up @@ -2809,6 +2815,10 @@ public void setUnitToolTipArmorMiniFontSize(int i) {
store.setValue(UNIT_TOOLTIP_ARMORMINI_FONT_SIZE_MOD, i);
}

public void setUnitTooltipMaxWidth(int i) {
store.setValue(UNIT_TOOLTIP_MAX_WIDTH, i);
}

public void setDockOnLeft(Boolean state) {
store.setValue(DOCK_ON_LEFT, state);
}
Expand Down
8 changes: 5 additions & 3 deletions megamek/src/megamek/client/ui/swing/TargetChoiceDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
package megamek.client.ui.swing;

import megamek.client.ui.enums.DialogResult;
import megamek.client.ui.swing.tooltip.HexTooltip;
import megamek.client.ui.swing.tooltip.UnitToolTip;
import megamek.common.*;
import megamek.common.actions.WeaponAttackAction;
Expand All @@ -31,6 +30,8 @@ public class TargetChoiceDialog extends AbstractChoiceDialog<Targetable> {
final ClientGUI clientGUI;
Entity firingEntity;

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

/**
* This creates a modal dialog to pick one or more Targetable objects.
* @param frame parent @JFrame that owns this dialog
Expand Down Expand Up @@ -73,8 +74,9 @@ protected TargetChoiceDialog(JFrame frame, String title, String message,

@Override
protected void detailLabel(JToggleButton button, Targetable target) {
button.setText("<html>" + infoText(target) + UnitToolTip.getTargetTipDetail(target,
clientGUI.getClient().getBoard(), clientGUI) + "</html>");
String div = "<DIV WIDTH=" + GUIP.getUnitToolTipMaxWidth() + ">" + infoText(target) + UnitToolTip.getTargetTipDetail(target,
clientGUI.getClient().getBoard(), clientGUI) + "</DIV>";
button.setText("<html>" + div + "</html>");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5743,7 +5743,7 @@ public String getHexTooltip(MouseEvent e) {
result += sSpecialHex;
}

String div = "<DIV WIDTH=" + UIUtil.scaleForGUI(500) + ">" + result + "</DIV>";
String div = "<DIV WIDTH=" + GUIP.getUnitToolTipMaxWidth() + ">" + result + "</DIV>";
StringBuffer txt = new StringBuffer();
txt.append(HTML_BEGIN + div + HTML_END);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import megamek.client.ui.swing.boardview.BoardView;
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.*;
import megamek.common.*;
import megamek.common.util.fileUtils.MegaMekFile;
Expand Down