GUI, preferences: reworked size settings:

- added size settings for player's panel size (closes #12455, closes #12451, closes #5605);
- size settings can be edit by slider or by text edit;
- size settings for fonts has preview button with real text sample;
- improved some tabs and hints for better UX;
- improved GUI rendering performance;
This commit is contained in:
Oleg Agafonov 2024-07-21 23:35:44 +04:00
parent 921e656e3c
commit 1f3fad6594
15 changed files with 3224 additions and 5913 deletions

View file

@ -37,11 +37,9 @@
}
public void activated() {
}
public void deactivated() {
}
public void handleEvent(AWTEvent event) {

View file

@ -131,6 +131,7 @@ public class HoverButton extends JPanel implements MouseListener {
@Override
public void paintComponent(Graphics g) {
// must ignore look and fill, so no calls of super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
if (isEnabled()) {
if (isHovered || textAlwaysVisible) {

View file

@ -40,6 +40,7 @@ public class KeyboundButton extends JButton {
@Override
protected void paintComponent(Graphics g) {
// must ignore look and fill, so no calls of super.paintComponent(g);
if (ui != null && g != null) {
Graphics sg = g.create();
try {

View file

@ -42,7 +42,7 @@ public final class Constants {
public static final int POWBOX_TEXT_MAX_LEFT = 212;
public static final int DAMAGE_MAX_LEFT = 180;
// tooltip hints delay in ms (need more time to display long hints withour hiding)
// tooltip hints delay in ms (need more time to display long hints without hiding)
public static final int TOOLTIPS_DELAY_MS = 60 * 1000;
public static final Border EMPTY_BORDER = BorderFactory.createEmptyBorder(2, 2, 2, 2);

View file

@ -24,12 +24,17 @@ public class MageDialog extends javax.swing.JInternalFrame {
protected boolean modal = false;
/**
* Creates new form MageDialog
*/
// GUI performance and bugs issues:
// TODO: swing components should override paintComponent() instead paint()
// TODO: swing components should use this.revalidate() instead parent.validate()
// TODO: swing components in paintComponent() must call super or paint full rect on opaque = true
public MageDialog() {
initComponents();
// paint calls optimization - no needs in transparent
setOpaque(true);
// enable a minimizing window on double clicks
if (this instanceof MageDesktopIconifySupport) {
BasicInternalFrameUI ui = (BasicInternalFrameUI) this.getUI();
@ -54,6 +59,12 @@ public class MageDialog extends javax.swing.JInternalFrame {
}
}
@Override
public boolean isValidateRoot() {
// paint calls optimization - no frame auto-size on child changes
return true;
}
public void changeGUISize() {
}

View file

@ -332,14 +332,18 @@ public class TestCardRenderDialog extends MageDialog {
possibleTargets.add(playerYou.getId());
}
// need re-create panel, because it can't change size in real time
this.playerPanel.removeAll();
// player's panel
if (this.player == null) {
// create new panel
this.playerPanel.setLayout(new BorderLayout(5, 5));
this.player = new PlayerPanelExt(this.playerSizeMod);
this.playerPanel.add(player, BorderLayout.CENTER);
} else {
// update existing panel (recreate all inner components)
this.player.fullRefresh(this.playerSizeMod);
}
this.playerPanel.setPreferredSize(new java.awt.Dimension(Math.round(100 * this.playerSizeMod), 10));
this.playerPanel.setLayout(new BorderLayout(5, 5));
this.player = new PlayerPanelExt(this.playerSizeMod);
this.playerPanel.add(player, BorderLayout.CENTER);
//this.player.cleanUp();
//this.player.changeGUISize();
// update data in player's panel
GameView gameView = new GameView(this.game.getState(), this.game, controlledId, null);
PlayerView currentPlayerView = gameView.getPlayers()
.stream()
@ -348,7 +352,7 @@ public class TestCardRenderDialog extends MageDialog {
.orElse(null);
this.player.init(this.game.getId(), playerYou.getId(), isMe, this.bigCard, 0);
this.player.update(gameView, currentPlayerView, possibleTargets);
PlayAreaPanel.sizePlayerPanel(this.player, isMe, smallMode);
this.player.sizePlayerPanel(smallMode);
// update CARDS

View file

@ -248,12 +248,14 @@ public final class GamePanel extends javax.swing.JPanel {
resizeTimer = new Timer(1000, evt -> SwingUtilities.invokeLater(() -> {
resizeTimer.stop();
setGUISize();
setGUISize(false);
feedbackPanel.changeGUISize();
}));
pnlHelperHandButtonsStackArea.addComponentListener(componentAdapterPlayField);
initComponents = false;
setGUISize(true);
}
private Map<String, JComponent> getUIComponents(JLayeredPane jLayeredPane) {
@ -377,7 +379,7 @@ public final class GamePanel extends javax.swing.JPanel {
public void changeGUISize() {
initComponents = true;
setGUISize();
setGUISize(true);
stackObjects.changeGUISize();
feedbackPanel.changeGUISize();
handContainer.changeGUISize();
@ -418,7 +420,7 @@ public final class GamePanel extends javax.swing.JPanel {
initComponents = false;
}
private void setGUISize() {
private void setGUISize(boolean themeReload) {
jSplitPane0.setDividerSize(GUISizeHelper.dividerBarSize);
jSplitPane1.setDividerSize(GUISizeHelper.dividerBarSize);
jSplitPane2.setDividerSize(GUISizeHelper.dividerBarSize);
@ -453,7 +455,9 @@ public final class GamePanel extends javax.swing.JPanel {
pnlShortCuts.setMinimumSize(newDimension);
pnlShortCuts.setMaximumSize(newDimension);
reloadThemeRelatedGraphic();
if (themeReload) {
reloadThemeRelatedGraphic();
}
}
private void reloadThemeRelatedGraphic() {
@ -485,6 +489,20 @@ public final class GamePanel extends javax.swing.JPanel {
phaseButtons.forEach((phaseName, phaseButton) -> {
phaseButton.update(phaseButton.getText(), ImageManagerImpl.instance.getPhaseImage(phaseName));
});
// player panels
if (lastGameData.game != null) {
lastGameData.game.getPlayers().forEach(player -> {
PlayAreaPanel playPanel = this.players.getOrDefault(player.getPlayerId(), null);
if (playPanel != null) {
// see test render dialog for refresh commands order
playPanel.getPlayerPanel().fullRefresh(GUISizeHelper.playerPanelGuiScale);
playPanel.init(player, bigCard, gameId, player.getPriorityTimeLeftSecs());
playPanel.update(lastGameData.game, player, lastGameData.targets);
playPanel.getPlayerPanel().sizePlayerPanel(isSmallMode());
}
});
}
}
private void saveDividerLocations() {
@ -521,7 +539,13 @@ public final class GamePanel extends javax.swing.JPanel {
}
}
private boolean isSmallMode() {
// TODO: no needs on gui scale?
return this.getBounds().height < 770;
}
private void sizeToScreen() {
// on resize frame
Rectangle rect = this.getBounds();
if (rect.height < 770) {
@ -534,7 +558,7 @@ public final class GamePanel extends javax.swing.JPanel {
pnlShortCuts.revalidate();
pnlShortCuts.repaint();
for (PlayAreaPanel p : players.values()) {
p.setSizeMode(smallMode);
p.getPlayerPanel().sizePlayerPanel(smallMode);
}
}
} else if (smallMode) {
@ -546,7 +570,7 @@ public final class GamePanel extends javax.swing.JPanel {
pnlShortCuts.revalidate();
pnlShortCuts.repaint();
for (PlayAreaPanel p : players.values()) {
p.setSizeMode(smallMode);
p.getPlayerPanel().sizePlayerPanel(smallMode);
}
}
@ -667,6 +691,7 @@ public final class GamePanel extends javax.swing.JPanel {
public synchronized void init(int messageId, GameView game, boolean callGameUpdateAfterInit) {
addPlayers(game);
// default menu states
setMenuStates(
PreferencesDialog.getCachedValue(KEY_GAME_MANA_AUTOPAYMENT, "true").equals("true"),
@ -772,8 +797,10 @@ public final class GamePanel extends javax.swing.JPanel {
break;
}
}
// set init sizes
for (PlayAreaPanel p : players.values()) {
p.setSizeMode(smallMode);
p.getPlayerPanel().sizePlayerPanel(isSmallMode());
}
GridBagConstraints panelC = new GridBagConstraints();
@ -785,21 +812,6 @@ public final class GamePanel extends javax.swing.JPanel {
this.pnlBattlefield.add(topPanel, panelC);
panelC.gridy = 1;
this.pnlBattlefield.add(bottomPanel, panelC);
// TODO: combat arrows aren't visible on re-connect, must click on avatar to update correctrly
// reason: panels aren't visible/located here, so battlefieldpanel see wrong sizes
// recalc all component sizes and update permanents/arrows positions
// if you don't do it here then will catch wrong arrows drawing on re-connect (no sortLayout calls)
/*
this.validate();
for (Map.Entry<UUID, PlayAreaPanel> p : players.entrySet()) {
PlayerView playerView = game.getPlayers().stream().filter(view -> view.getPlayerId().equals(p.getKey())).findFirst().orElse(null);
if (playerView != null) {
p.getValue().getBattlefieldPanel().updateSize();
p.getValue().update(null, playerView, null);
}
}
*/
}
public synchronized void updateGame(int messageId, GameView game) {
@ -2423,8 +2435,6 @@ public final class GamePanel extends javax.swing.JPanel {
initPopupMenuTriggerOrder();
setGUISize();
// Replay panel to control replay of games
javax.swing.GroupLayout gl_pnlReplay = new javax.swing.GroupLayout(pnlReplay);
pnlReplay.setLayout(gl_pnlReplay);

View file

@ -25,7 +25,7 @@ import static mage.client.dialog.PreferencesDialog.*;
/**
* GUI: play area panel (player with avatar/mana panel + battlefield panel)
*
* @author BetaSteward_at_googlemail.com
* @author BetaSteward_at_googlemail.com, JayDi85
*/
public class PlayAreaPanel extends javax.swing.JPanel {
@ -49,16 +49,6 @@ public class PlayAreaPanel extends javax.swing.JPanel {
public static final int PANEL_HEIGHT_SMALL = 220;
private static final int PANEL_HEIGHT_EXTRA_FOR_ME = 25;
/**
* Creates new form PlayAreaPanel
*
* @param player
* @param bigCard
* @param gameId
* @param priorityTime
* @param gamePanel
* @param options
*/
public PlayAreaPanel(PlayerView player, BigCard bigCard, UUID gameId, int priorityTime, GamePanel gamePanel,
PlayAreaPanelOptions options) {
this.gamePanel = gamePanel;
@ -70,6 +60,7 @@ public class PlayAreaPanel extends javax.swing.JPanel {
// data init
init(player, bigCard, gameId, priorityTime);
update(null, player, null);
playerPanel.sizePlayerPanel(isSmallMode());
// init popup menu (must run after data init)
popupMenu = new JPopupMenu();
@ -78,7 +69,6 @@ public class PlayAreaPanel extends javax.swing.JPanel {
} else {
addPopupMenuWatcher();
}
this.add(popupMenu);
setGUISize();
}
@ -545,52 +535,18 @@ public class PlayAreaPanel extends javax.swing.JPanel {
private void initComponents() {
setBorder(BorderFactory.createLineBorder(new Color(0, 0, 0, 0)));
playerPanel = new PlayerPanelExt();
btnCheat = new javax.swing.JButton();
playerPanel = new PlayerPanelExt(GUISizeHelper.playerPanelGuiScale);
btnCheat = new javax.swing.JButton(); // TODO: not used? Delete
battlefieldPanel = new mage.client.game.BattlefieldPanel();
battlefieldPanel.setTopPanelBattlefield(options.topRow);
battlefieldPanel.setPreferredSize(new Dimension(Short.MAX_VALUE, Short.MAX_VALUE));
btnCheat.setText("Cheat");
btnCheat.addActionListener(evt -> btnCheatActionPerformed(evt));
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
layout.setHorizontalGroup(
layout.createSequentialGroup()
.addComponent(playerPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(battlefieldPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(Alignment.LEADING)
.addComponent(playerPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(battlefieldPanel, GroupLayout.DEFAULT_SIZE, 160, Short.MAX_VALUE)
);
this.setLayout(layout);
}
public void setSizeMode(boolean smallMode) {
this.smallMode = smallMode;
sizePlayerPanel(this.playerPanel, this.isMe, this.smallMode);
sizeBattlefieldPanel(this.battlefieldPanel, this.isMe, this.smallMode);
}
public static void sizePlayerPanel(PlayerPanelExt playerPanel, boolean isMe, boolean smallMode) {
playerPanel.sizePlayerPanel(smallMode);
int extraForMe = isMe ? PANEL_HEIGHT_EXTRA_FOR_ME : 0;
if (smallMode) {
playerPanel.setPreferredSize(new Dimension(92, PANEL_HEIGHT_SMALL + extraForMe));
} else {
playerPanel.setPreferredSize(new Dimension(92, PANEL_HEIGHT + extraForMe));
}
}
public static void sizeBattlefieldPanel(BattlefieldPanel battlefieldPanel, boolean isMe, boolean smallMode) {
int extraForMe = isMe ? PANEL_HEIGHT_EXTRA_FOR_ME : 0;
if (smallMode) {
battlefieldPanel.setPreferredSize(new Dimension(160, PANEL_HEIGHT_SMALL + extraForMe));
} else {
battlefieldPanel.setPreferredSize(new Dimension(160, PANEL_HEIGHT + extraForMe));
}
this.setLayout(new BorderLayout());
this.add(playerPanel, BorderLayout.WEST);
this.add(battlefieldPanel, BorderLayout.CENTER);
}
private void btnCheatActionPerformed(java.awt.event.ActionEvent evt) {

View file

@ -64,35 +64,49 @@ public class PlayerPanelExt extends javax.swing.JPanel {
private static final int PANEL_HEIGHT_SMALL = 218; // small mode (with avatar button) // TODO: no need in small mode after GUI scale added
private static final int PANEL_HEIGHT_EXTRA_FOR_ME = 25; // hints button
private final Border GREEN_BORDER;
private final Border RED_BORDER;
private final Border YELLOW_BORDER;
private final Border EMPTY_BORDER;
private Border GREEN_BORDER;
private Border RED_BORDER;
private Border YELLOW_BORDER;
private Border EMPTY_BORDER;
float guiScaleMod = 1.0f;
private final Color activeValueColor = new Color(244, 9, 47);
private final Font fontValuesZero;
private final Font fontValuesNonZero;
private Color activeValueColor = new Color(244, 9, 47);
private Font fontValuesZero;
private Font fontValuesNonZero;
private int avatarId = -1;
private String flagName;
private String basicTooltipText;
private static final Map<UUID, Integer> playerLives = new HashMap<>();
private Font defaultFont = null;
private PriorityTimer timer;
/**
* Creates new form PlayerPanel
*/
public PlayerPanelExt() {
this(1.0f);
}
public PlayerPanelExt(float guiScaleMod) {
// gui scale
// save default font cause panel can be recreated manually
this.defaultFont = this.getFont();
createAllComponents(guiScaleMod);
}
/**
* Refresh full panel's components due actual GUI settings
*/
public void fullRefresh(float guiScaleMod) {
this.cleanUp();
this.removeAll();
this.createAllComponents(guiScaleMod);
}
public void createAllComponents(float guiScaleMod) {
this.guiScaleMod = guiScaleMod;
this.setFont(this.getFont().deriveFont(sizeMod(this.getFont().getSize2D())));
this.setFont(this.defaultFont.deriveFont(sizeMod(this.defaultFont.getSize2D())));
this.fontValuesZero = this.getFont().deriveFont(Font.PLAIN);
this.fontValuesNonZero = this.getFont().deriveFont(Font.BOLD);
this.GREEN_BORDER = new LineBorder(Color.green, sizeMod(3));
@ -123,7 +137,8 @@ public class PlayerPanelExt extends javax.swing.JPanel {
toolHintsHelper.setVisible(this.isMe);
toolHintsHelper.setFocusable(false);
flagName = null;
if (priorityTime > 0) {
avatarId = -1;
if (priorityTime > 0 && priorityTime != Integer.MAX_VALUE) {
long delay = 1000L;
timer = new PriorityTimer(priorityTime, delay, () -> {
@ -360,9 +375,9 @@ public class PlayerPanelExt extends javax.swing.JPanel {
}
}
if (this.timer != null) {
if (player.getPriorityTimeLeft() != Integer.MAX_VALUE) {
if (player.getPriorityTimeLeftSecs() != Integer.MAX_VALUE) {
String priorityTimeValue = getPriorityTimeLeftString(player);
this.timer.setCount(player.getPriorityTimeLeft());
this.timer.setCount(player.getPriorityTimeLeftSecs());
this.timer.setBufferCount(player.getBufferTimeLeft());
this.avatar.setTopText(priorityTimeValue);
this.timerLabel.setText(priorityTimeValue);
@ -372,7 +387,7 @@ public class PlayerPanelExt extends javax.swing.JPanel {
if (player.getBufferTimeLeft() > 0) {
textColor = Color.GREEN;
foregroundColor = Color.GREEN.darker().darker();
} else if (player.getPriorityTimeLeft() < 300) { // visual indication for under 5 minutes
} else if (player.getPriorityTimeLeftSecs() < 300) { // visual indication for under 5 minutes
textColor = Color.RED;
foregroundColor = Color.RED.darker().darker();
} else {
@ -476,7 +491,7 @@ public class PlayerPanelExt extends javax.swing.JPanel {
}
private String getPriorityTimeLeftString(PlayerView player) {
int priorityTimeLeft = player.getPriorityTimeLeft() + player.getBufferTimeLeft();
int priorityTimeLeft = player.getPriorityTimeLeftSecs() + player.getBufferTimeLeft();
return getPriorityTimeLeftString(priorityTimeLeft);
}
@ -975,7 +990,7 @@ public class PlayerPanelExt extends javax.swing.JPanel {
}// </editor-fold>//GEN-END:initComponents
protected void sizePlayerPanel(boolean smallMode) {
public void sizePlayerPanel(boolean smallMode) {
int extraForMe = this.isMe ? PANEL_HEIGHT_EXTRA_FOR_ME : 0;
if (smallMode) {
avatar.setVisible(false);

View file

@ -7,6 +7,7 @@ import org.mage.card.arcane.CardRenderer;
import javax.swing.*;
import java.awt.*;
import java.lang.reflect.Field;
import java.util.Locale;
/**
@ -62,6 +63,8 @@ public final class GUISizeHelper {
public static Dimension handCardDimension;
public static int stackWidth; // percent
public static float playerPanelGuiScale;
public static Dimension otherZonesCardDimension;
public static int otherZonesCardVerticalOffset;
@ -126,7 +129,7 @@ public final class GUISizeHelper {
gameRequestsFont = new Font("Arial", 0, dialogFontSize);
// used in the feedback area of the game panel
int feedbackFontSize = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GUI_FEEDBACK_AREA_SIZE, 14);
int feedbackFontSize = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GUI_FEEDBACK_FONT_SIZE, 14);
gameDialogAreaFontSizeBig = feedbackFontSize;
gameDialogAreaFontSizeTooltip = feedbackFontSize - 2;
gameDialogAreaFontSizeSmall = (feedbackFontSize / 2) + 2;
@ -149,6 +152,8 @@ public final class GUISizeHelper {
handCardDimension = new Dimension(CARD_IMAGE_WIDTH * handCardSize / 42, CARD_IMAGE_HEIGHT * handCardSize / 42);
stackWidth = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GUI_STACK_WIDTH, 30);
playerPanelGuiScale = (float) (PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GUI_PLAYER_PANEL_SIZE, 14) / 14.0);
int otherZonesCardSize = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GUI_CARD_OTHER_ZONES_SIZE, 14);
otherZonesCardDimension = new Dimension(CARD_IMAGE_WIDTH * otherZonesCardSize / 42, CARD_IMAGE_HEIGHT * otherZonesCardSize / 42);
if (PreferencesDialog.getRenderMode() == 0) {
@ -234,4 +239,22 @@ public final class GUISizeHelper {
}
return text;
}
/**
* Swing don't store name in the component, so it allow to find component by field's name instead
*/
static public <T extends Component> T getComponentByFieldName(Window dialog, String name) {
for (Field field : dialog.getClass().getDeclaredFields()) {
try {
field.setAccessible(true);
if (name.equals(field.getName())) {
final Object potentialMatch = field.get(dialog);
return (T) potentialMatch;
}
} catch (SecurityException | IllegalArgumentException | IllegalAccessException ignore) {
}
}
return null;
}
}

View file

@ -82,6 +82,7 @@ public class ThemePluginImpl implements ThemePlugin {
if (ui.containsKey("gamePanel") && ui.containsKey("jLayeredPane")) {
ImagePanel bgPanel = new ImagePanel(backgroundImage, ImagePanelStyle.TILED);
// TODO: research - is all components used? And why it make transparent?
unsetOpaque(ui.get("jSplitPane1"));
unsetOpaque(ui.get("pnlBattlefield"));
unsetOpaque(ui.get("pnlHelperHandButtonsStackArea"));