Skip to content

Commit

Permalink
GUI, preferences: reworked size settings:
Browse files Browse the repository at this point in the history
- 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;
  • Loading branch information
JayDi85 committed Jul 25, 2024
1 parent 921e656 commit 1f3fad6
Show file tree
Hide file tree
Showing 15 changed files with 3,851 additions and 6,540 deletions.
2 changes: 0 additions & 2 deletions Mage.Client/src/main/java/mage/client/MagePane.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,9 @@ public void removeFrame() {
}

public void activated() {

}

public void deactivated() {

}

public void handleEvent(AWTEvent event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ private float sizeMod(float value) {

@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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public void setShowKey(boolean showKey) {

@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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private 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);
Expand Down
17 changes: 14 additions & 3 deletions Mage.Client/src/main/java/mage/client/dialog/MageDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -54,6 +59,12 @@ public void mouseClicked(MouseEvent e) {
}
}

@Override
public boolean isValidateRoot() {
// paint calls optimization - no frame auto-size on child changes
return true;
}

public void changeGUISize() {

}
Expand Down
6,803 changes: 1,981 additions & 4,822 deletions Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.form

Large diffs are not rendered by default.

3,331 changes: 1,728 additions & 1,603 deletions Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -332,14 +332,18 @@ private void reloadCardsAndPlayer(boolean refreshTheme) {
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()
Expand All @@ -348,7 +352,7 @@ private void reloadCardsAndPlayer(boolean refreshTheme) {
.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

Expand Down
58 changes: 34 additions & 24 deletions Mage.Client/src/main/java/mage/client/game/GamePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,14 @@ public void componentResized(ComponentEvent e) {

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) {
Expand Down Expand Up @@ -377,7 +379,7 @@ private void clearPickPileDialogs() {

public void changeGUISize() {
initComponents = true;
setGUISize();
setGUISize(true);
stackObjects.changeGUISize();
feedbackPanel.changeGUISize();
handContainer.changeGUISize();
Expand Down Expand Up @@ -418,7 +420,7 @@ public void changeGUISize() {
initComponents = false;
}

private void setGUISize() {
private void setGUISize(boolean themeReload) {
jSplitPane0.setDividerSize(GUISizeHelper.dividerBarSize);
jSplitPane1.setDividerSize(GUISizeHelper.dividerBarSize);
jSplitPane2.setDividerSize(GUISizeHelper.dividerBarSize);
Expand Down Expand Up @@ -453,7 +455,9 @@ private void setGUISize() {
pnlShortCuts.setMinimumSize(newDimension);
pnlShortCuts.setMaximumSize(newDimension);

reloadThemeRelatedGraphic();
if (themeReload) {
reloadThemeRelatedGraphic();
}
}

private void reloadThemeRelatedGraphic() {
Expand Down Expand Up @@ -485,6 +489,20 @@ private void reloadThemeRelatedGraphic() {
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() {
Expand Down Expand Up @@ -521,7 +539,13 @@ private void restoreDividerLocations() {
}
}

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) {
Expand All @@ -534,7 +558,7 @@ private void sizeToScreen() {
pnlShortCuts.revalidate();
pnlShortCuts.repaint();
for (PlayAreaPanel p : players.values()) {
p.setSizeMode(smallMode);
p.getPlayerPanel().sizePlayerPanel(smallMode);
}
}
} else if (smallMode) {
Expand All @@ -546,7 +570,7 @@ private void sizeToScreen() {
pnlShortCuts.revalidate();
pnlShortCuts.repaint();
for (PlayAreaPanel p : players.values()) {
p.setSizeMode(smallMode);
p.getPlayerPanel().sizePlayerPanel(smallMode);
}
}

Expand Down Expand Up @@ -667,6 +691,7 @@ public void removeGame() {

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"),
Expand Down Expand Up @@ -772,8 +797,10 @@ private void addPlayers(GameView game) {
break;
}
}

// set init sizes
for (PlayAreaPanel p : players.values()) {
p.setSizeMode(smallMode);
p.getPlayerPanel().sizePlayerPanel(isSmallMode());
}

GridBagConstraints panelC = new GridBagConstraints();
Expand All @@ -785,21 +812,6 @@ private void addPlayers(GameView game) {
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) {
Expand Down Expand Up @@ -2423,8 +2435,6 @@ public void actionPerformed(ActionEvent actionEvent) {

initPopupMenuTriggerOrder();

setGUISize();

// Replay panel to control replay of games
javax.swing.GroupLayout gl_pnlReplay = new javax.swing.GroupLayout(pnlReplay);
pnlReplay.setLayout(gl_pnlReplay);
Expand Down
60 changes: 8 additions & 52 deletions Mage.Client/src/main/java/mage/client/game/PlayAreaPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
/**
* 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 {

Expand All @@ -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;
Expand All @@ -70,6 +60,7 @@ public PlayAreaPanel(PlayerView player, BigCard bigCard, UUID gameId, int priori
// 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();
Expand All @@ -78,7 +69,6 @@ public PlayAreaPanel(PlayerView player, BigCard bigCard, UUID gameId, int priori
} else {
addPopupMenuWatcher();
}
this.add(popupMenu);

setGUISize();
}
Expand Down Expand Up @@ -545,52 +535,18 @@ public PlayerPanelExt getPlayerPanel() {

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) {
Expand Down
Loading

0 comments on commit 1f3fad6

Please sign in to comment.