mirror of
https://github.com/correl/mage.git
synced 2025-04-11 09:11:12 -09:00
UI: improved ask dialog (same size for all buttons)
This commit is contained in:
parent
8fd5d92152
commit
5fa20278b0
2 changed files with 79 additions and 6 deletions
Mage.Client/src/main/java/mage/client/game
|
@ -151,6 +151,7 @@ public class FeedbackPanel extends javax.swing.JPanel {
|
||||||
this.helper.setLinks(btnLeft, btnRight, btnSpecial, btnUndo);
|
this.helper.setLinks(btnLeft, btnRight, btnSpecial, btnUndo);
|
||||||
|
|
||||||
this.helper.setVisible(true);
|
this.helper.setVisible(true);
|
||||||
|
this.helper.autoSizeButtons();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setButtonState(String leftText, String rightText, FeedbackMode mode) {
|
private void setButtonState(String leftText, String rightText, FeedbackMode mode) {
|
||||||
|
@ -211,6 +212,8 @@ public class FeedbackPanel extends javax.swing.JPanel {
|
||||||
if (options.containsKey("dialog")) {
|
if (options.containsKey("dialog")) {
|
||||||
connectedDialog = (MageDialog) options.get("dialog");
|
connectedDialog = (MageDialog) options.get("dialog");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.helper.autoSizeButtons();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,8 @@ import java.awt.event.ActionListener;
|
||||||
import java.awt.event.MouseAdapter;
|
import java.awt.event.MouseAdapter;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
import java.awt.event.MouseListener;
|
import java.awt.event.MouseListener;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Random;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
import javax.swing.JMenuItem;
|
import javax.swing.JMenuItem;
|
||||||
|
@ -48,6 +50,7 @@ import javax.swing.ScrollPaneConstants;
|
||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
import javax.swing.ToolTipManager;
|
import javax.swing.ToolTipManager;
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
|
import javax.swing.border.LineBorder;
|
||||||
|
|
||||||
import mage.client.SessionHandler;
|
import mage.client.SessionHandler;
|
||||||
import mage.client.components.MageTextArea;
|
import mage.client.components.MageTextArea;
|
||||||
|
@ -56,6 +59,8 @@ import mage.client.game.FeedbackPanel.FeedbackMode;
|
||||||
|
|
||||||
import static mage.client.game.FeedbackPanel.FeedbackMode.QUESTION;
|
import static mage.client.game.FeedbackPanel.FeedbackMode.QUESTION;
|
||||||
import mage.client.util.GUISizeHelper;
|
import mage.client.util.GUISizeHelper;
|
||||||
|
import mage.util.RandomUtil;
|
||||||
|
|
||||||
import static mage.constants.PlayerAction.REQUEST_AUTO_ANSWER_ID_NO;
|
import static mage.constants.PlayerAction.REQUEST_AUTO_ANSWER_ID_NO;
|
||||||
import static mage.constants.PlayerAction.REQUEST_AUTO_ANSWER_ID_YES;
|
import static mage.constants.PlayerAction.REQUEST_AUTO_ANSWER_ID_YES;
|
||||||
import static mage.constants.PlayerAction.REQUEST_AUTO_ANSWER_RESET_ALL;
|
import static mage.constants.PlayerAction.REQUEST_AUTO_ANSWER_RESET_ALL;
|
||||||
|
@ -77,6 +82,7 @@ public class HelperPanel extends JPanel {
|
||||||
//private javax.swing.JButton btnStopTimer;
|
//private javax.swing.JButton btnStopTimer;
|
||||||
private JScrollPane textAreaScrollPane;
|
private JScrollPane textAreaScrollPane;
|
||||||
private MageTextArea dialogTextArea;
|
private MageTextArea dialogTextArea;
|
||||||
|
JPanel buttonGrid;
|
||||||
JPanel buttonContainer;
|
JPanel buttonContainer;
|
||||||
|
|
||||||
private javax.swing.JButton linkLeft;
|
private javax.swing.JButton linkLeft;
|
||||||
|
@ -141,6 +147,8 @@ public class HelperPanel extends JPanel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
autoSizeButtons();
|
||||||
|
|
||||||
GUISizeHelper.changePopupMenuFont(popupMenuAskNo);
|
GUISizeHelper.changePopupMenuFont(popupMenuAskNo);
|
||||||
GUISizeHelper.changePopupMenuFont(popupMenuAskYes);
|
GUISizeHelper.changePopupMenuFont(popupMenuAskYes);
|
||||||
revalidate();
|
revalidate();
|
||||||
|
@ -166,25 +174,29 @@ public class HelperPanel extends JPanel {
|
||||||
add(textAreaScrollPane);
|
add(textAreaScrollPane);
|
||||||
|
|
||||||
buttonContainer = new JPanel();
|
buttonContainer = new JPanel();
|
||||||
buttonContainer.setLayout(new FlowLayout(FlowLayout.CENTER, 15, 0));
|
buttonContainer.setLayout(new FlowLayout(FlowLayout.CENTER, 0, 0));
|
||||||
buttonContainer.setOpaque(false);
|
buttonContainer.setOpaque(false);
|
||||||
add(buttonContainer);
|
add(buttonContainer);
|
||||||
|
|
||||||
|
buttonGrid = new JPanel(); // buttons layout auto changes by autoSizeButtons
|
||||||
|
buttonGrid.setOpaque(false);
|
||||||
|
buttonContainer.add(buttonGrid);
|
||||||
|
|
||||||
btnSpecial = new JButton("Special");
|
btnSpecial = new JButton("Special");
|
||||||
btnSpecial.setVisible(false);
|
btnSpecial.setVisible(false);
|
||||||
buttonContainer.add(btnSpecial);
|
buttonGrid.add(btnSpecial);
|
||||||
|
|
||||||
btnLeft = new JButton("OK");
|
btnLeft = new JButton("OK");
|
||||||
btnLeft.setVisible(false);
|
btnLeft.setVisible(false);
|
||||||
buttonContainer.add(btnLeft);
|
buttonGrid.add(btnLeft);
|
||||||
|
|
||||||
btnRight = new JButton("Cancel");
|
btnRight = new JButton("Cancel");
|
||||||
btnRight.setVisible(false);
|
btnRight.setVisible(false);
|
||||||
buttonContainer.add(btnRight);
|
buttonGrid.add(btnRight);
|
||||||
|
|
||||||
btnUndo = new JButton("Undo");
|
btnUndo = new JButton("Undo");
|
||||||
btnUndo.setVisible(false);
|
btnUndo.setVisible(false);
|
||||||
buttonContainer.add(btnUndo);
|
buttonGrid.add(btnUndo);
|
||||||
|
|
||||||
MouseListener checkPopupAdapter = new MouseAdapter() {
|
MouseListener checkPopupAdapter = new MouseAdapter() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -280,7 +292,7 @@ public class HelperPanel extends JPanel {
|
||||||
this.btnRight.setActionCommand(mode.toString() + txtRight);
|
this.btnRight.setActionCommand(mode.toString() + txtRight);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
autoSizeButtons();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSpecial(String txtSpecial, boolean specialVisible) {
|
public void setSpecial(String txtSpecial, boolean specialVisible) {
|
||||||
|
@ -290,6 +302,7 @@ public class HelperPanel extends JPanel {
|
||||||
|
|
||||||
public void setUndoEnabled(boolean enabled) {
|
public void setUndoEnabled(boolean enabled) {
|
||||||
this.btnUndo.setVisible(enabled);
|
this.btnUndo.setVisible(enabled);
|
||||||
|
autoSizeButtons();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLeft(String text, boolean visible) {
|
public void setLeft(String text, boolean visible) {
|
||||||
|
@ -297,6 +310,7 @@ public class HelperPanel extends JPanel {
|
||||||
if (!text.isEmpty()) {
|
if (!text.isEmpty()) {
|
||||||
this.btnLeft.setText(text);
|
this.btnLeft.setText(text);
|
||||||
}
|
}
|
||||||
|
autoSizeButtons();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRight(String txtRight, boolean rightVisible) {
|
public void setRight(String txtRight, boolean rightVisible) {
|
||||||
|
@ -304,6 +318,62 @@ public class HelperPanel extends JPanel {
|
||||||
if (!txtRight.isEmpty()) {
|
if (!txtRight.isEmpty()) {
|
||||||
this.btnRight.setText(txtRight);
|
this.btnRight.setText(txtRight);
|
||||||
}
|
}
|
||||||
|
autoSizeButtons();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void autoSizeButtons() {
|
||||||
|
// two mode: same size for small texts (flow), different size for long texts (grid)
|
||||||
|
|
||||||
|
int BUTTONS_H_GAP = 15;
|
||||||
|
|
||||||
|
// cleanup current settings to default (flow layout - different sizes)
|
||||||
|
this.buttonGrid.setLayout(new FlowLayout(FlowLayout.CENTER, BUTTONS_H_GAP, 0));
|
||||||
|
this.buttonGrid.setPreferredSize(null);
|
||||||
|
|
||||||
|
ArrayList<JButton> buttons = new ArrayList<>();
|
||||||
|
if (this.btnLeft.isVisible()) { buttons.add(this.btnLeft); }
|
||||||
|
if (this.btnRight.isVisible()) { buttons.add(this.btnRight); }
|
||||||
|
if (this.btnSpecial.isVisible()) { buttons.add(this.btnSpecial); }
|
||||||
|
if (this.btnUndo.isVisible()) { buttons.add(this.btnUndo); }
|
||||||
|
|
||||||
|
if (buttons.size() == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.buttonGrid.removeAll();
|
||||||
|
for (JButton button : buttons) {
|
||||||
|
this.buttonGrid.add(button);
|
||||||
|
}
|
||||||
|
|
||||||
|
// random text test (click to any objects to change)
|
||||||
|
/*
|
||||||
|
Integer i = 1 + RandomUtil.nextInt(50);
|
||||||
|
String longText = i.toString() + "-";
|
||||||
|
while (longText.length() < i) {longText += "a";}
|
||||||
|
this.btnRight.setText(longText);
|
||||||
|
//*/
|
||||||
|
|
||||||
|
// search max preferred size to draw full button's text
|
||||||
|
int needButtonSizeW = 0;
|
||||||
|
for (JButton button : buttons) {
|
||||||
|
needButtonSizeW = Math.max(needButtonSizeW, button.getPreferredSize().width);
|
||||||
|
}
|
||||||
|
|
||||||
|
// search max const size
|
||||||
|
int constButtonSizeW = GUISizeHelper.gameDialogButtonWidth * 200 / 100;
|
||||||
|
int constGridSizeW = buttons.size() * constButtonSizeW + BUTTONS_H_GAP * (buttons.size() - 1);
|
||||||
|
int constGridSizeH = Math.round(GUISizeHelper.gameDialogButtonHeight * 150 / 100);
|
||||||
|
|
||||||
|
if (needButtonSizeW < constButtonSizeW) {
|
||||||
|
// same size mode (grid)
|
||||||
|
GridLayout gl = new GridLayout(1, buttons.size(), BUTTONS_H_GAP, 0);
|
||||||
|
this.buttonGrid.setLayout(gl);
|
||||||
|
this.buttonGrid.setPreferredSize(new Dimension(constGridSizeW, constGridSizeH));
|
||||||
|
} else {
|
||||||
|
// different size mode (flow) -- already used by default
|
||||||
|
//FlowLayout fl = new FlowLayout(FlowLayout.CENTER, BUTTONS_H_GAP, 0);
|
||||||
|
//this.buttonGrid.setLayout(fl);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLinks(JButton left, JButton right, JButton special, JButton undo) {
|
public void setLinks(JButton left, JButton right, JButton special, JButton undo) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue