GUI: improved GUI scale support (fixed font sizes in card icons popup, ability picker dialog, part of #969)

This commit is contained in:
Oleg Agafonov 2024-07-27 17:05:54 +04:00
parent 393dbc4047
commit ba929d5692
6 changed files with 19 additions and 14 deletions

View file

@ -327,8 +327,10 @@ public class CardIconsPanel extends JPanel {
BufferedImage iconImageWithText = ImageManagerImpl.deepCopy(iconImageCached); // must copy cached value before modify
// text
String hint = ManaSymbols.replaceSymbolsWithHTML(icon.getHint(), ManaSymbols.Type.CARD_ICON_HINT);
hint = GUISizeHelper.textToHtmlWithSize(hint, GUISizeHelper.cardTooltipFontSize);
JLabel label = new JLabel();
label.setToolTipText("<html>" + ManaSymbols.replaceSymbolsWithHTML(icon.getHint(), ManaSymbols.Type.CARD_ICON_HINT));
label.setToolTipText("<html>" + hint);
if (!icon.getText().isEmpty()) {
Graphics2D g2 = iconImageWithText.createGraphics();
try {

View file

@ -568,7 +568,7 @@ public class PreferencesDialog extends javax.swing.JDialog {
createSizeSetting(4, KEY_GUI_CARD_EDITOR_SIZE,14, false, "Size of cards in editor and draft panels", "The size of the card in editor and the picked zone of the draft panel ");
createSizeSetting(5, KEY_GUI_CARD_OFFSET_SIZE,14, false, "Offset of card's image", "The vertical offset of card images in editor areas "); // TODO: delete
createSizeSetting(6, KEY_GUI_ENLARGED_IMAGE_SIZE, 20, false, "Size of popup card hint (image mode by mouse wheel)", "The size of the image shown for the card your mouse pointer<br>is located over while you turn the mouse wheel");
createSizeSetting(7, KEY_GUI_TOOLTIP_SIZE,14, false, "Size of popup card hint (text mode)", "The size of the tooltip window for cards or permanents"); // TODO: share with popup image
createSizeSetting(7, KEY_GUI_TOOLTIP_SIZE,14, true, "Size of popup card hint (text mode)", "The size of the tooltip window for cards or permanents"); // TODO: share with popup image
// game
createSizeSetting(8, KEY_GUI_PLAYER_PANEL_SIZE,14, false, "Size of player panel", "The size of the player panels on battlefield");
createSizeSetting(9, KEY_GUI_CARD_HAND_SIZE,14, false, "Size of cards in hand and stack", "The size of the card images in hand and on the stack");

View file

@ -1997,7 +1997,7 @@ public final class GamePanel extends javax.swing.JPanel {
@SuppressWarnings("unchecked")
private void initComponents() {
abilityPicker = new mage.client.components.ability.AbilityPicker();
abilityPicker = new mage.client.components.ability.AbilityPicker(GUISizeHelper.dialogsGuiScale);
jSplitPane1 = new javax.swing.JSplitPane();
jSplitPane0 = new javax.swing.JSplitPane();
jPanel2 = new javax.swing.JPanel();

View file

@ -149,6 +149,9 @@ public final class GUISizeHelper {
cardTooltipFontSize = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GUI_TOOLTIP_SIZE, 14);
symbolTooltipSize = cardTooltipFontSize;
// control's tooltip on mouse move
UIManager.put("ToolTip.font", getCardFont().deriveFont(cardTooltipFontSize * 1.0f));
int handCardSize = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GUI_CARD_HAND_SIZE, 14);
handCardDimension = new Dimension(CARD_IMAGE_WIDTH * handCardSize / 42, CARD_IMAGE_HEIGHT * handCardSize / 42);
stackWidth = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GUI_STACK_WIDTH, 30);
@ -238,8 +241,12 @@ public final class GUISizeHelper {
}
public static String textToHtmlWithSize(String text, Font font) {
return textToHtmlWithSize(text, font.getSize());
}
public static String textToHtmlWithSize(String text, int fontSize) {
if (text != null && !text.toLowerCase(Locale.ENGLISH).startsWith("<html>")) {
return "<html><p style=\"font-size: " + font.getSize() + "pt;\">" + text + "</p>";
return "<html><p style=\"font-size: " + fontSize + "pt;\">" + text + "</p>";
}
return text;
}

View file

@ -621,9 +621,9 @@ public final class ManaSymbols {
symbolSize = GUISizeHelper.symbolDialogSize;
break;
case TOOLTIP:
case CARD_ICON_HINT:
symbolSize = GUISizeHelper.symbolTooltipSize;
break;
case CARD_ICON_HINT:
default:
symbolSize = 11;
break;

View file

@ -97,17 +97,13 @@ public class PlayerView implements Serializable {
sideboard.put(card.getId(), new CardView(card, game, CardUtil.canShowAsControlled(card, createdForPlayerId)));
}
}
try {
for (Permanent permanent : state.getBattlefield().getAllPermanents()) {
if (showInBattlefield(permanent, state)) {
PermanentView view = new PermanentView(permanent, game.getCard(permanent.getId()), createdForPlayerId, game);
battlefield.put(view.getId(), view);
}
}
} catch (ConcurrentModificationException e) {
// can happen as a player left battlefield while PlayerView is created
}
Card cardOnTop = (player.isTopCardRevealed() && player.getLibrary().hasCards())
? player.getLibrary().getFromTop(game) : null;
this.topCard = cardOnTop != null ? new CardView(cardOnTop, game) : null;