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

done and skip buttons handle changes in GUI Scale better #4875

Merged
merged 1 commit into from
Nov 12, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public abstract class AbstractPhaseDisplay extends SkinnedJPanel implements
BoardViewListener, GameListener, Distractable {
private static final long serialVersionUID = 4421205210788230341L;

public static final int DONE_BUTTON_WIDTH = 125;
public static final int DONE_BUTTON_WIDTH = 160;
// Distraction implementation.
protected DistractableAdapter distracted = new DistractableAdapter();

Expand Down
8 changes: 7 additions & 1 deletion megamek/src/megamek/client/ui/swing/ActionPhaseDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import megamek.client.ui.swing.util.UIUtil;
import megamek.client.ui.swing.widget.MegamekButton;
import megamek.client.ui.swing.widget.SkinSpecification;
import megamek.common.Report;
import megamek.common.annotations.Nullable;
import megamek.common.preference.PreferenceChangeEvent;

Expand All @@ -46,7 +47,7 @@ protected ActionPhaseDisplay(ClientGUI cg) {
protected UIUtil.FixedXPanel setupDonePanel() {
var donePanel = super.setupDonePanel();
butSkipTurn = new MegamekButton("SKIP", SkinSpecification.UIComponents.PhaseDisplayDoneButton.getComp());
butSkipTurn.setPreferredSize(new Dimension(DONE_BUTTON_WIDTH, MIN_BUTTON_SIZE.height * 1));
butSkipTurn.setPreferredSize(new Dimension(UIUtil.scaleForGUI(DONE_BUTTON_WIDTH), MIN_BUTTON_SIZE.height * 1));
String f = guiScaledFontHTML(UIUtil.uiLightViolet()) + KeyCommandBind.getDesc(KeyCommandBind.DONE_NO_ACTION)+ "</FONT>";
butSkipTurn.setToolTipText("<html><body>" + f + "</body></html>");
addToDonePanel(donePanel, butSkipTurn);
Expand Down Expand Up @@ -109,6 +110,7 @@ public void performAction() {
public void preferenceChange(PreferenceChangeEvent e) {
super.preferenceChange(e);
updateDonePanel();
adaptToGUIScale();
}

protected void initDonePanelForNewTurn()
Expand Down Expand Up @@ -174,4 +176,8 @@ protected void updateDonePanelButtons(final String doneButtonLabel, final String
clientgui.getBoardView().turnDetailsOverlay.setLines(turnDetails);
}
}

private void adaptToGUIScale() {
butSkipTurn.setPreferredSize(new Dimension(UIUtil.scaleForGUI(DONE_BUTTON_WIDTH), MIN_BUTTON_SIZE.height * 1));
}
}
2 changes: 1 addition & 1 deletion megamek/src/megamek/client/ui/swing/ChatterBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public void focusLost(FocusEvent e) {
gbc.fill = GridBagConstraints.BOTH;
gbc.weightx = .13; gbc.weighty = .05;
chatPanel.add(butDone, gbc);
butDone.setSize(AbstractPhaseDisplay.DONE_BUTTON_WIDTH, butDone.getHeight());
butDone.setSize(UIUtil.scaleForGUI(AbstractPhaseDisplay.DONE_BUTTON_WIDTH), butDone.getHeight());
butDone.setPreferredSize(butDone.getSize());
butDone.setMinimumSize(butDone.getSize());
chatPanel.setMinimumSize(chatPanel.getPreferredSize());
Expand Down
17 changes: 13 additions & 4 deletions megamek/src/megamek/client/ui/swing/StatusBarPhaseDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import java.util.stream.Collectors;

import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;

import megamek.client.ui.GBC;
import megamek.client.ui.Messages;
Expand Down Expand Up @@ -88,6 +90,8 @@ public int compare(PhaseCommand c1, PhaseCommand c2) {
protected JPanel panStatus = new JPanel();
protected JPanel panButtons = new JPanel();

private UIUtil.FixedXPanel donePanel;

/** The button group that is currently displayed */
protected int currentButtonGroup = 0;

Expand Down Expand Up @@ -227,18 +231,18 @@ public void setupButtonPanel() {

protected UIUtil.FixedXPanel setupDonePanel()
{
var donePanel = new UIUtil.FixedXPanel();
donePanel.setPreferredSize(new Dimension(DONE_BUTTON_WIDTH+5, MIN_BUTTON_SIZE.height*2+5));
donePanel = new UIUtil.FixedXPanel();
donePanel.setPreferredSize(new Dimension(UIUtil.scaleForGUI(DONE_BUTTON_WIDTH+5), MIN_BUTTON_SIZE.height*2+5));
donePanel.setOpaque(false);
donePanel.setBackground(Color.darkGray);
donePanel.setBorder( BorderFactory.createLoweredBevelBorder() );
donePanel.setBorder( new EmptyBorder(0, 10, 0, 0));
donePanel.setLayout(new GridBagLayout());
addToDonePanel(donePanel, butDone);
return donePanel;
}

protected void addToDonePanel(JPanel donePanel, JComponent item) {
item.setPreferredSize(new Dimension(DONE_BUTTON_WIDTH, MIN_BUTTON_SIZE.height));
item.setPreferredSize(new Dimension(UIUtil.scaleForGUI(DONE_BUTTON_WIDTH), MIN_BUTTON_SIZE.height));
butDone.setAlignmentX(LEFT_ALIGNMENT);
donePanel.add(item, GBC.eol().fill(GridBagConstraints.BOTH).weighty(1));
}
Expand All @@ -261,6 +265,8 @@ protected void setStatusBarText(String text) {
private void adaptToGUIScale() {
UIUtil.adjustContainer(panButtons, UIUtil.FONT_SCALE1);
UIUtil.adjustContainer(panStatus, UIUtil.FONT_SCALE2);

donePanel.setPreferredSize(new Dimension(UIUtil.scaleForGUI(DONE_BUTTON_WIDTH), MIN_BUTTON_SIZE.height * 1));
}

@Override
Expand All @@ -274,6 +280,8 @@ public void preferenceChange(PreferenceChangeEvent e) {
} else if (e.getName().equals(KeyBindParser.KEYBINDS_CHANGED)) {
setButtonsTooltips();
}

adaptToGUIScale();
}

@Override
Expand Down Expand Up @@ -394,4 +402,5 @@ public void setWeaponFieldOfFire(Entity unit, int[][] ranges, int arc, int loc,

clientgui.getBoardView().setWeaponFieldOfFire(unit, cmd);
}

}