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

button tool tip for hot keys #4125

Merged
merged 9 commits into from
Jan 30, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
5 changes: 3 additions & 2 deletions megamek/src/megamek/client/ui/swing/AbstractPhaseDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,9 @@ public void actionPerformed(ActionEvent e) {

@Override
public boolean shouldPerformAction() {
if ((!clientgui.getClient().isMyTurn() && (clientgui
.getClient().getGame().getTurn() != null))
if (((!clientgui.getClient().isMyTurn()
&& (clientgui.getClient().getGame().getTurn() != null)
&& (!clientgui.getClient().getGame().getPhase().isReport())))
|| clientgui.getBoardView().getChatterBoxActive()
|| display.isIgnoringEvents()
|| !display.isVisible()
Expand Down
57 changes: 51 additions & 6 deletions megamek/src/megamek/client/ui/swing/DeployMinefieldDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import megamek.client.event.BoardViewEvent;
import megamek.client.ui.Messages;
import megamek.client.ui.swing.util.KeyCommandBind;
import megamek.client.ui.swing.widget.MegamekButton;
import megamek.client.ui.swing.widget.SkinSpecification;
import megamek.common.*;
Expand All @@ -25,6 +26,9 @@
import java.awt.event.MouseEvent;
import java.util.*;

import static megamek.client.ui.swing.util.UIUtil.guiScaledFontHTML;
import static megamek.client.ui.swing.util.UIUtil.uiLightViolet;

public class DeployMinefieldDisplay extends StatusBarPhaseDisplay {
private static final long serialVersionUID = -1243277953037374936L;

Expand Down Expand Up @@ -56,6 +60,17 @@ public String getCmd() {
public String toString() {
return cmd;
}

public String getHotKeyDesc() {
kuronekochomusuke marked this conversation as resolved.
Show resolved Hide resolved
kuronekochomusuke marked this conversation as resolved.
Show resolved Hide resolved
String result = "";

switch (this) {
default:
break;
}

return result;
}
}

// buttons
Expand Down Expand Up @@ -84,6 +99,19 @@ public DeployMinefieldDisplay(ClientGUI clientgui) {

p = clientgui.getClient().getLocalPlayer();

setButtons();
setButtonsTooltips();

butDone.setText(Messages.getString("DeployMinefieldDisplay.Done"));
String f = guiScaledFontHTML(uiLightViolet()) + KeyCommandBind.getDesc(KeyCommandBind.DONE)+ "</FONT>";
butDone.setToolTipText("<html><body>" + f + "</body></html>");
butDone.setEnabled(false);

setupButtonPanel();
}

@Override
protected void setButtons() {
buttons = new HashMap<>((int) (Command.values().length * 1.25 + 0.5));
for (Command cmd : Command.values()) {
String title = Messages.getString("DeployMinefieldDisplay."
Expand All @@ -98,13 +126,30 @@ public DeployMinefieldDisplay(ClientGUI clientgui) {
newButton.setActionCommand(cmd.getCmd());
newButton.setEnabled(false);
buttons.put(cmd, newButton);
}
}
numButtonGroups = (int) Math.ceil((buttons.size()+0.0) / buttonsPerGroup);

butDone.setText(Messages.getString("DeployMinefieldDisplay.Done"));
butDone.setEnabled(false);

setupButtonPanel();
}

@Override
protected void setButtonsTooltips() {
for (Command cmd : Command.values()) {
String ttKey = "DeployMinefieldDisplay." + cmd.getCmd() + ".tooltip";
String tt = cmd.getHotKeyDesc();
if (!tt.isEmpty()) {
String title = Messages.getString("DeployMinefieldDisplay." + cmd.getCmd());
tt = guiScaledFontHTML(uiLightViolet()) + title + ": " + tt + "</FONT>";
tt += "<BR>";
}
if (Messages.keyExists(ttKey)) {
String msg_key = Messages.getString(ttKey);
tt += guiScaledFontHTML() + msg_key + "</FONT>";
}
String b = "<BODY>" + tt + "</BODY>";
String h = "<HTML>" + b + "</HTML>";
if (!tt.isEmpty()) {
buttons.get(cmd).setToolTipText(h);
}
}
}

@Override
Expand Down
66 changes: 55 additions & 11 deletions megamek/src/megamek/client/ui/swing/DeploymentDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import megamek.client.event.BoardViewEvent;
import megamek.client.ui.Messages;
import megamek.client.ui.SharedUtility;
import megamek.client.ui.swing.util.KeyCommandBind;
import megamek.client.ui.swing.widget.MegamekButton;
import megamek.client.ui.swing.widget.SkinSpecification;
import megamek.common.*;
Expand All @@ -37,6 +38,9 @@
import java.awt.event.MouseEvent;
import java.util.*;

import static megamek.client.ui.swing.util.UIUtil.guiScaledFontHTML;
import static megamek.client.ui.swing.util.UIUtil.uiLightViolet;

public class DeploymentDisplay extends StatusBarPhaseDisplay {

/**
Expand Down Expand Up @@ -84,6 +88,21 @@ public void setPriority(int p) {
public String toString() {
return Messages.getString("DeploymentDisplay." + getCmd());
}

public String getHotKeyDesc() {
String result = "";

switch (this) {
case DEPLOY_NEXT:
result += "&nbsp;&nbsp;" + "Next" + ": " + KeyCommandBind.getDesc(KeyCommandBind.NEXT_UNIT);
result += "&nbsp;&nbsp;" + "Previous" + ": " + KeyCommandBind.getDesc(KeyCommandBind.PREV_UNIT);
break;
default:
break;
}

return result;
}
}

protected Map<DeployCommand,MegamekButton> buttons;
Expand All @@ -100,26 +119,51 @@ public DeploymentDisplay(ClientGUI clientgui) {
super(clientgui);
clientgui.getClient().getGame().addGameListener(this);
clientgui.getBoardView().addBoardViewListener(this);
setupStatusBar(Messages.getString("DeploymentDisplay.waitingForDeploymentPhase"));

setupStatusBar(Messages.getString("DeploymentDisplay.waitingForDeploymentPhase"));

setButtons();
setButtonsTooltips();

butDone.setText("<html><body>" + Messages.getString("DeploymentDisplay.Deploy") + "</body></html>");
String f = guiScaledFontHTML(uiLightViolet()) + KeyCommandBind.getDesc(KeyCommandBind.DONE)+ "</FONT>";
butDone.setToolTipText("<html><body>" + f + "</body></html>");
butDone.setEnabled(false);
setupButtonPanel();
}

@Override
protected void setButtons() {
buttons = new HashMap<>((int) (DeployCommand.values().length * 1.25 + 0.5));
for (DeployCommand cmd : DeployCommand.values()) {
String title = Messages.getString("DeploymentDisplay." + cmd.getCmd());
MegamekButton newButton = new MegamekButton(title, SkinSpecification.UIComponents.PhaseDisplayButton.getComp());
String ttKey = "DeploymentDisplay." + cmd.getCmd() + ".tooltip";
if (Messages.keyExists(ttKey)) {
newButton.setToolTipText(Messages.getString(ttKey));
}
newButton.addActionListener(this);
newButton.setActionCommand(cmd.getCmd());
newButton.setEnabled(false);
buttons.put(cmd, newButton);
}
}
numButtonGroups = (int) Math.ceil((buttons.size() + 0.0) / buttonsPerGroup);

butDone.setText("<html><b>" + Messages.getString("DeploymentDisplay.Deploy") + "</b></html>");
butDone.setEnabled(false);
setupButtonPanel();
}
@Override
protected void setButtonsTooltips() {
for (DeployCommand cmd : DeployCommand.values()) {
String ttKey = "DeploymentDisplay." + cmd.getCmd() + ".tooltip";
String tt = cmd.getHotKeyDesc();
if (!tt.isEmpty()) {
String title = Messages.getString("DeploymentDisplay." + cmd.getCmd());
tt = guiScaledFontHTML(uiLightViolet()) + title + ": " + tt + "</FONT>";
tt += "<BR>";
}
if (Messages.keyExists(ttKey)) {
String msg_key = Messages.getString(ttKey);
tt += guiScaledFontHTML() + msg_key + "</FONT>";
}
String b = "<BODY>" + tt + "</BODY>";
String h = "<HTML>" + b + "</HTML>";
if (!tt.isEmpty()) {
buttons.get(cmd).setToolTipText(h);
}
}
}

@Override
Expand Down
113 changes: 97 additions & 16 deletions megamek/src/megamek/client/ui/swing/FiringDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
import java.awt.event.*;
import java.util.*;

import static megamek.client.ui.swing.util.UIUtil.guiScaledFontHTML;
import static megamek.client.ui.swing.util.UIUtil.uiLightViolet;

public class FiringDisplay extends StatusBarPhaseDisplay implements ItemListener, ListSelectionListener {
private static final long serialVersionUID = -5586388490027013723L;

Expand Down Expand Up @@ -102,6 +105,59 @@ public void setPriority(int p) {
public String toString() {
return Messages.getString("FiringDisplay." + getCmd());
}

public String getHotKeyDesc() {
String result = "";

switch (this) {
case FIRE_NEXT:
result = "<BR>";
result += "&nbsp;&nbsp;" + "Next" + ": " + KeyCommandBind.getDesc(KeyCommandBind.NEXT_UNIT);
result += "&nbsp;&nbsp;" + "Previous" + ": " + KeyCommandBind.getDesc(KeyCommandBind.PREV_UNIT);
break;
case FIRE_TWIST:
result = "<BR>";
result += "&nbsp;&nbsp;" + "Left" + ": " + KeyCommandBind.getDesc(KeyCommandBind.TWIST_LEFT);
result += "&nbsp;&nbsp;" + "Right" + ": " + KeyCommandBind.getDesc(KeyCommandBind.TWIST_RIGHT);
break;
case FIRE_FIRE:
result = "<BR>";
result += "&nbsp;&nbsp;" + KeyCommandBind.getDesc(KeyCommandBind.FIRE);
break;
case FIRE_NEXT_TARG:
result = "<BR>";
result += "&nbsp;&nbsp;" + "Next" + ": " + KeyCommandBind.getDesc(KeyCommandBind.NEXT_TARGET);
result += "&nbsp;&nbsp;" + "Previous" + ": " + KeyCommandBind.getDesc(KeyCommandBind.PREV_TARGET);
result += "<BR>";
result += "&nbsp;&nbsp;" + "Valid" + " " + "Next" + ": " + KeyCommandBind.getDesc(KeyCommandBind.NEXT_TARGET_VALID);
result += "&nbsp;&nbsp;" + "Previous" + ": " + KeyCommandBind.getDesc(KeyCommandBind.PREV_TARGET_VALID);
result += "<BR>";
result += "&nbsp;&nbsp;" + "No Allies" + " " + "Next" + ": " + KeyCommandBind.getDesc(KeyCommandBind.NEXT_TARGET_NOALLIES);
result += "&nbsp;&nbsp;" + "Previous" + ": " + KeyCommandBind.getDesc(KeyCommandBind.PREV_TARGET_NOALLIES);
result += "<BR>";
result += "&nbsp;&nbsp;" + "Valid No Allies" + " " + "Next " + ": " + KeyCommandBind.getDesc(KeyCommandBind.NEXT_TARGET_VALID_NO_ALLIES);
result += "&nbsp;&nbsp;" + "Previous" + ": " + KeyCommandBind.getDesc(KeyCommandBind.PREV_TARGET_VALID_NO_ALLIES);
break;
case FIRE_SKIP:
result = "<BR>";
result += "&nbsp;&nbsp;" +"Next" + ": " + KeyCommandBind.getDesc(KeyCommandBind.NEXT_WEAPON);
result += "&nbsp;&nbsp;" +"Previous" + ": " + KeyCommandBind.getDesc(KeyCommandBind.PREV_WEAPON);
break;
case FIRE_MODE:
result = "<BR>";
result += "&nbsp;&nbsp;" +"Next" + ": " + KeyCommandBind.getDesc(KeyCommandBind.NEXT_MODE);
result += "&nbsp;&nbsp;" +"Previous" + ": " + KeyCommandBind.getDesc(KeyCommandBind.PREV_MODE);
break;
case FIRE_CANCEL:
result = "<BR>";
result += "&nbsp;&nbsp;" + KeyCommandBind.getDesc(KeyCommandBind.CANCEL);
break;
default:
break;
}

return result;
}
}

// buttons
Expand Down Expand Up @@ -153,23 +209,12 @@ public FiringDisplay(final ClientGUI clientgui) {

setupStatusBar(Messages.getString("FiringDisplay.waitingForFiringPhase"));

buttons = new HashMap<>((int) (FiringCommand.values().length * 1.25 + 0.5));
for (FiringCommand cmd : FiringCommand.values()) {
String title = Messages.getString("FiringDisplay." + cmd.getCmd());
MegamekButton newButton = new MegamekButton(title,
SkinSpecification.UIComponents.PhaseDisplayButton.getComp());
String ttKey = "FiringDisplay." + cmd.getCmd() + ".tooltip";
if (Messages.keyExists(ttKey)) {
newButton.setToolTipText(Messages.getString(ttKey));
}
newButton.addActionListener(this);
newButton.setActionCommand(cmd.getCmd());
newButton.setEnabled(false);
buttons.put(cmd, newButton);
}
numButtonGroups = (int) Math.ceil((buttons.size() + 0.0) / buttonsPerGroup);
setButtons();
setButtonsTooltips();

butDone.setText("<html><b>" + Messages.getString("FiringDisplay.Done") + "</b></html>");
butDone.setText("<html><body>" + Messages.getString("FiringDisplay.Done") + "</body></html>");
String f = guiScaledFontHTML(uiLightViolet()) + KeyCommandBind.getDesc(KeyCommandBind.DONE)+ "</FONT>";
butDone.setToolTipText("<html><body>" + f + "</body></html>");
butDone.setEnabled(false);

setupButtonPanel();
Expand All @@ -185,6 +230,42 @@ public FiringDisplay(final ClientGUI clientgui) {
registerKeyCommands();
}

@Override
protected void setButtons() {
buttons = new HashMap<>((int) (FiringCommand.values().length * 1.25 + 0.5));
for (FiringCommand cmd : FiringCommand.values()) {
String title = Messages.getString("FiringDisplay." + cmd.getCmd());
MegamekButton newButton = new MegamekButton(title, SkinSpecification.UIComponents.PhaseDisplayButton.getComp());
newButton.addActionListener(this);
newButton.setActionCommand(cmd.getCmd());
newButton.setEnabled(false);
buttons.put(cmd, newButton);
}
numButtonGroups = (int) Math.ceil((buttons.size() + 0.0) / buttonsPerGroup);
}

@Override
protected void setButtonsTooltips() {
kuronekochomusuke marked this conversation as resolved.
Show resolved Hide resolved
for (FiringCommand cmd : FiringCommand.values()) {
String ttKey = "FiringDisplay." + cmd.getCmd() + ".tooltip";
String tt = cmd.getHotKeyDesc();
if (!tt.isEmpty()) {
String title = Messages.getString("FiringDisplay." + cmd.getCmd());
tt = guiScaledFontHTML(uiLightViolet()) + title + ": " + tt + "</FONT>";
tt += "<BR>";
}
if (Messages.keyExists(ttKey)) {
String msg_key = Messages.getString(ttKey);
tt += guiScaledFontHTML() + msg_key + "</FONT>";
}
String b = "<BODY>" + tt + "</BODY>";
kuronekochomusuke marked this conversation as resolved.
Show resolved Hide resolved
String h = "<HTML>" + b + "</HTML>";
if (!tt.isEmpty()) {
buttons.get(cmd).setToolTipText(h);
}
}
}

/**
* Register all of the <code>CommandAction</code>s for this panel display.
*/
Expand Down
Loading