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

turn sounds #4151

Merged
merged 10 commits into from
Feb 15, 2023
4 changes: 3 additions & 1 deletion megamek/i18n/megamek/client/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1185,7 +1185,9 @@ CommonSettingsDialog.uiTheme=UI Theme:
CommonSettingsDialog.skinFile=Skin File:
CommonSettingsDialog.skinFileFail.title=Failed to load skin!
CommonSettingsDialog.skinFileFail.msg=Error parsing skin specification file, reverting to previous skin!
CommonSettingsDialog.soundMute=Mute sound.
CommonSettingsDialog.soundMuteChat=Mute chat notification sound.
CommonSettingsDialog.soundMuteMyTurn=Mute my turn notification sound
CommonSettingsDialog.soundMuteOthersTurn=Mute others turn notification sound
CommonSettingsDialog.stampFilenames=Add a date/time stamp to all logs and savegames.
CommonSettingsDialog.stampFormat=Date Format to use for above stamp:
CommonSettingsDialog.tileset=Tileset:
Expand Down
75 changes: 56 additions & 19 deletions megamek/src/megamek/client/ui/swing/ClientGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,9 @@ public class ClientGUI extends JPanel implements BoardViewListener,
/**
* Cache for the "bing" soundclip.
*/
private Clip bingClip;
private Clip bingClipChat;
private Clip bingClipMyTurn;
private Clip bingClipOthersTurn;

/**
* Map each phase to the name of the card for the main display area.
Expand Down Expand Up @@ -338,7 +340,7 @@ public ClientGUI(Client client, MegaMekController c) {
this.addComponentListener(this);
this.client = client;
controller = c;
loadSoundClip();
loadSoundFiles();
panMain.setLayout(cardsMain);
panSecondary.setLayout(cardsSecondary);
JPanel panDisplay = new JPanel(new BorderLayout());
Expand All @@ -347,6 +349,22 @@ public ClientGUI(Client client, MegaMekController c) {
add(panDisplay, BorderLayout.CENTER);
}

private void loadSoundFiles() {
if (bingClipChat != null) {
bingClipChat.close();
}
if (bingClipMyTurn != null) {
bingClipMyTurn.close();
}
if (bingClipOthersTurn != null) {
bingClipOthersTurn.close();
}
kuronekochomusuke marked this conversation as resolved.
Show resolved Hide resolved

bingClipChat = loadSoundClip(GUIP.getSoundBingFilenameChat());
bingClipMyTurn = loadSoundClip(GUIP.getSoundBingFilenameMyTurn());
bingClipOthersTurn = loadSoundClip(GUIP.getSoundBingFilenameOthersTurn());
}

public BoardView getBoardView() {
return bv;
}
Expand Down Expand Up @@ -390,28 +408,29 @@ public void setMiniReportDisplayDialog(final MiniReportDisplayDialog miniReportD
/**
* Try to load the "bing" sound clip.
*/
private void loadSoundClip() {
if (GUIP.getSoundBingFilename() == null) {
return;
private Clip loadSoundClip(String filename) {
kuronekochomusuke marked this conversation as resolved.
Show resolved Hide resolved
Clip clip = null;
kuronekochomusuke marked this conversation as resolved.
Show resolved Hide resolved

if (filename == null) {
return null;
}
final File file = new File(GUIP.getSoundBingFilename());
final File file = new File(filename);
if (!file.exists()) {
LogManager.getLogger().error(Messages.getString("ClientGUI.failedToLoadAudioFile") + " " + GUIP.getSoundBingFilename());
return;
LogManager.getLogger().error(Messages.getString("ClientGUI.failedToLoadAudioFile") + " " + filename);
return null;
}

try {
if (bingClip != null) {
bingClip.close();
}
bingClip = AudioSystem.getClip();
clip = AudioSystem.getClip();
try (AudioInputStream ais = AudioSystem.getAudioInputStream(file)) {
bingClip.open(ais);
clip.open(ais);
}
} catch (Exception ex) {
LogManager.getLogger().error("", ex);
bingClip = null;
clip = null;
}

return clip;
kuronekochomusuke marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down Expand Up @@ -2102,10 +2121,24 @@ public void loadPreviewImage(JLabel bp, Entity entity, Player player) {
/**
* Make a "bing" sound.
*/
void bing() {
if (!GUIP.getSoundMute() && (bingClip != null)) {
bingClip.setFramePosition(0);
bingClip.start();
public void bingChat() {
if ((!GUIP.getSoundMuteChat()) && (bingClipMyTurn != null)) {
kuronekochomusuke marked this conversation as resolved.
Show resolved Hide resolved
Windchild292 marked this conversation as resolved.
Show resolved Hide resolved
bingClipChat.setFramePosition(0);
bingClipChat.start();
}
}

public void bingMyTurn() {
if ((!GUIP.getSoundMuteMyTurn()) && (bingClipMyTurn != null)) {
kuronekochomusuke marked this conversation as resolved.
Show resolved Hide resolved
bingClipMyTurn.setFramePosition(0);
bingClipMyTurn.start();
}
}

public void bingOthersTurn() {
if ((!GUIP.getSoundMuteOthersTurn()) && (bingClipMyTurn != null)) {
kuronekochomusuke marked this conversation as resolved.
Show resolved Hide resolved
bingClipOthersTurn.setFramePosition(0);
bingClipOthersTurn.start();
}
}

Expand Down Expand Up @@ -2139,7 +2172,7 @@ public void gamePlayerDisconnected(GamePlayerDisconnectedEvent evt) {

@Override
public void gamePlayerChat(GamePlayerChatEvent e) {
bing();
bingChat();
}

@Override
Expand Down Expand Up @@ -2809,6 +2842,10 @@ public void preferenceChange(PreferenceChangeEvent e) {
} else if (e.getName().equals(GUIPreferences.DEFAULT_WEAPON_SORT_ORDER)) {
setWeaponOrderPrefs(true);
getUnitDisplay().displayEntity(getUnitDisplay().getCurrentEntity());
} else if ((e.getName().equals(GUIPreferences.SOUND_BING_FILENAME_CHAT))
|| (e.getName().equals(GUIPreferences.SOUND_BING_FILENAME_MY_TURN))
|| (e.getName().equals(GUIPreferences.SOUND_BING_FILENAME_OTHERS_TURN))) {
loadSoundFiles();
}
}
}
46 changes: 41 additions & 5 deletions megamek/src/megamek/client/ui/swing/CommonSettingsDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,12 @@ private <T> void moveElement(DefaultListModel<T> srcModel, int srcIndex, int trg
private final JCheckBox nagForNoUnJamRAC = new JCheckBox(Messages.getString("CommonSettingsDialog.nagForUnJamRAC"));
private final JCheckBox animateMove = new JCheckBox(Messages.getString("CommonSettingsDialog.animateMove"));
private final JCheckBox showWrecks = new JCheckBox(Messages.getString("CommonSettingsDialog.showWrecks"));
private final JCheckBox soundMute = new JCheckBox(Messages.getString("CommonSettingsDialog.soundMute"));
private final JCheckBox soundMuteChat = new JCheckBox(Messages.getString("CommonSettingsDialog.soundMuteChat"));
private JTextField tfSoundMuteChatFileName;
private final JCheckBox soundMuteMyTurn = new JCheckBox(Messages.getString("CommonSettingsDialog.soundMuteMyTurn"));
private JTextField tfSoundMuteMyTurntFileName;
private final JCheckBox soundMuteOthersTurn = new JCheckBox(Messages.getString("CommonSettingsDialog.soundMuteOthersTurn"));
private JTextField tfSoundMuteOthersFileName;
private final JCheckBox showWpsinTT = new JCheckBox(Messages.getString("CommonSettingsDialog.showWpsinTT"));
private final JCheckBox showArmorMiniVisTT = new JCheckBox(Messages.getString("CommonSettingsDialog.showArmorMiniVisTT"));
private final JCheckBox showPilotPortraitTT = new JCheckBox(Messages.getString("CommonSettingsDialog.showPilotPortraitTT"));
Expand Down Expand Up @@ -433,9 +438,28 @@ private JPanel getSettingsPanel() {
comps.add(checkboxEntry(showWpsinTT, null));
comps.add(checkboxEntry(showArmorMiniVisTT, null));
comps.add(checkboxEntry(showPilotPortraitTT, null));

addLineSpacer(comps);
comps.add(checkboxEntry(soundMuteChat, null));
tfSoundMuteChatFileName = new JTextField(5);
tfSoundMuteChatFileName.setMaximumSize(new Dimension(450, 40));
row = new ArrayList<>();
row.add(tfSoundMuteChatFileName);
comps.add(row);
comps.add(checkboxEntry(soundMuteMyTurn, null));
tfSoundMuteMyTurntFileName = new JTextField(5);
tfSoundMuteMyTurntFileName.setMaximumSize(new Dimension(450, 40));
row = new ArrayList<>();
row.add(tfSoundMuteMyTurntFileName);
comps.add(row);
comps.add(checkboxEntry(soundMuteOthersTurn, null));
tfSoundMuteOthersFileName = new JTextField(5);
tfSoundMuteOthersFileName.setMaximumSize(new Dimension(450, 40));
row = new ArrayList<>();
row.add(tfSoundMuteOthersFileName);
comps.add(row);

addLineSpacer(comps);
comps.add(checkboxEntry(soundMute, null));

JLabel maxPathfinderTimeLabel = new JLabel(Messages.getString("CommonSettingsDialog.pathFiderTimeLimit"));
maxPathfinderTime = new JTextField(5);
maxPathfinderTime.setMaximumSize(new Dimension(150, 40));
Expand Down Expand Up @@ -574,7 +598,9 @@ public void setVisible(boolean visible) {
nagForNoUnJamRAC.setSelected(GUIP.getNagForNoUnJamRAC());
animateMove.setSelected(GUIP.getShowMoveStep());
showWrecks.setSelected(GUIP.getShowWrecks());
soundMute.setSelected(GUIP.getSoundMute());
soundMuteChat.setSelected(GUIP.getSoundMuteChat());
soundMuteMyTurn.setSelected(GUIP.getSoundMuteMyTurn());
soundMuteOthersTurn.setSelected(GUIP.getSoundMuteOthersTurn());
tooltipDelay.setText(Integer.toString(GUIP.getTooltipDelay()));
tooltipDismissDelay.setText(Integer.toString(GUIP.getTooltipDismissDelay()));
tooltipDistSupression.setText(Integer.toString(GUIP.getTooltipDistSuppression()));
Expand All @@ -594,6 +620,10 @@ public void setVisible(boolean visible) {
}
}

tfSoundMuteChatFileName.setText(GUIP.getSoundBingFilenameChat());
tfSoundMuteMyTurntFileName.setText(GUIP.getSoundBingFilenameMyTurn());
tfSoundMuteOthersFileName.setText(GUIP.getSoundBingFilenameOthersTurn());

maxPathfinderTime.setText(Integer.toString(CP.getMaxPathfinderTime()));

keepGameLog.setSelected(CP.keepGameLog());
Expand Down Expand Up @@ -795,7 +825,9 @@ protected void okAction() {
GUIP.setNagForNoUnJamRAC(nagForNoUnJamRAC.isSelected());
GUIP.setShowMoveStep(animateMove.isSelected());
GUIP.setShowWrecks(showWrecks.isSelected());
GUIP.setSoundMute(soundMute.isSelected());
GUIP.setSoundMuteChat(soundMuteChat.isSelected());
GUIP.setSoundMuteMyTurn(soundMuteMyTurn.isSelected());
GUIP.setSoundMuteOthersTurn(soundMuteOthersTurn.isSelected());
GUIP.setShowWpsinTT(showWpsinTT.isSelected());
GUIP.setshowArmorMiniVisTT(showArmorMiniVisTT.isSelected());
GUIP.setshowPilotPortraitTT(showPilotPortraitTT.isSelected());
Expand All @@ -820,6 +852,10 @@ protected void okAction() {
GUIP.setMouseWheelZoom(mouseWheelZoom.isSelected());
GUIP.setMouseWheelZoomFlip(mouseWheelZoomFlip.isSelected());

GUIP.setSoundBingFilenameChat(tfSoundMuteChatFileName.getText());
GUIP.setSoundBingFilenameMyTurn(tfSoundMuteMyTurntFileName.getText());
GUIP.setSoundBingFilenameOthersTurn(tfSoundMuteOthersFileName.getText());

try {
CP.setMaxPathfinderTime(Integer.parseInt(maxPathfinderTime.getText()));
} catch (Exception ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,17 +386,17 @@ public void gameTurnChange(GameTurnChangeEvent e) {

if (clientgui.getClient().isMyTurn()) {
beginMyTurn();
setStatusBarText(Messages
.getString("DeployMinefieldDisplay.its_your_turn"));
setStatusBarText(Messages.getString("DeployMinefieldDisplay.its_your_turn"));
clientgui.bingMyTurn();
} else {
String playerName;
if (e.getPlayer() != null) {
playerName = e.getPlayer().getName();
} else {
playerName = "Unknown";
}
setStatusBarText(Messages.getString("DeployMinefieldDisplay."
+ "its_others_turn", playerName));
setStatusBarText(Messages.getString("DeployMinefieldDisplay.its_others_turn", playerName));
clientgui.bingOthersTurn();
}
}

Expand Down
2 changes: 2 additions & 0 deletions megamek/src/megamek/client/ui/swing/DeploymentDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ public void gameTurnChange(GameTurnChangeEvent e) {
if (clientgui.getClient().isMyTurn()) {
if (cen == Entity.NONE) {
beginMyTurn();
clientgui.bingMyTurn();
}
setStatusBarText(Messages.getString("DeploymentDisplay.its_your_turn"));
} else {
Expand All @@ -416,6 +417,7 @@ public void gameTurnChange(GameTurnChangeEvent e) {
playerName = "Unknown";
}
setStatusBarText(Messages.getString("DeploymentDisplay.its_others_turn", playerName));
clientgui.bingOthersTurn();
}

}
Expand Down
2 changes: 2 additions & 0 deletions megamek/src/megamek/client/ui/swing/FiringDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -2192,6 +2192,7 @@ public void gameTurnChange(GameTurnChangeEvent e) {
beginMyTurn();
}
setStatusBarText(Messages.getString("FiringDisplay.its_your_turn"));
clientgui.bingMyTurn();
} else {
endMyTurn();
String playerName;
Expand All @@ -2201,6 +2202,7 @@ public void gameTurnChange(GameTurnChangeEvent e) {
playerName = "Unknown";
}
setStatusBarText(Messages.getString("FiringDisplay.its_others_turn", playerName));
clientgui.bingOthersTurn();
}
}
}
Expand Down
61 changes: 49 additions & 12 deletions megamek/src/megamek/client/ui/swing/GUIPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,12 @@ public class GUIPreferences extends PreferenceStoreProxy {
public static final String SHOW_PILOT_PORTRAIT_TT = "showPilotPortraitTT";
public static final String SHOW_MOVE_STEP = "ShowMoveStep";
public static final String SHOW_WRECKS = "ShowWrecks";
public static final String SOUND_BING_FILENAME = "SoundBingFilename";
public static final String SOUND_MUTE = "SoundMute";
public static final String SOUND_BING_FILENAME_CHAT = "SoundBingFilenameChat";
public static final String SOUND_BING_FILENAME_MY_TURN = "SoundBingFilenameMyTurn";
public static final String SOUND_BING_FILENAME_OTHERS_TURN = "SoundBingFilenameOthersTurn";
public static final String SOUND_MUTE_CHAT = "SoundMuteChat";
public static final String SOUND_MUTE_MY_TURN = "SoundMuteMyTurn";
public static final String SOUND_MUTE_OTHERS_TURN = "SoundMuteOthersTurn";
public static final String TOOLTIP_DELAY = "TooltipDelay";
public static final String TOOLTIP_DISMISS_DELAY = "TooltipDismissDelay";
public static final String TOOLTIP_DIST_SUPRESSION = "TooltipDistSupression";
Expand Down Expand Up @@ -557,8 +561,12 @@ protected GUIPreferences() {
store.setDefault(SHOW_MAPHEX_POPUP, true);
store.setDefault(SHOW_MOVE_STEP, true);
store.setDefault(SHOW_WRECKS, true);
store.setDefault(SOUND_BING_FILENAME, "data/sounds/call.wav");
store.setDefault(SOUND_MUTE, true);
store.setDefault(SOUND_BING_FILENAME_CHAT, "data/sounds/call.wav");
store.setDefault(SOUND_BING_FILENAME_MY_TURN, "data/sounds/call.wav");
store.setDefault(SOUND_BING_FILENAME_OTHERS_TURN, "data/sounds/call.wav");
store.setDefault(SOUND_MUTE_CHAT, true);
store.setDefault(SOUND_MUTE_MY_TURN, false);
store.setDefault(SOUND_MUTE_OTHERS_TURN, true);

store.setDefault(TOOLTIP_DELAY, 1000);
store.setDefault(TOOLTIP_DISMISS_DELAY, -1);
Expand Down Expand Up @@ -1135,14 +1143,31 @@ public boolean getShowWrecks() {
return store.getBoolean(SHOW_WRECKS);
}

public String getSoundBingFilename() {
return store.getString(SOUND_BING_FILENAME);
public String getSoundBingFilenameChat() {
return store.getString(SOUND_BING_FILENAME_CHAT);
}

public boolean getSoundMute() {
return store.getBoolean(SOUND_MUTE);
public String getSoundBingFilenameMyTurn() {
return store.getString(SOUND_BING_FILENAME_MY_TURN);
}

public String getSoundBingFilenameOthersTurn() {
return store.getString(SOUND_BING_FILENAME_OTHERS_TURN);
}

public boolean getSoundMuteChat() {
return store.getBoolean(SOUND_MUTE_CHAT);
}

public boolean getSoundMuteMyTurn() {
return store.getBoolean(SOUND_MUTE_MY_TURN);
}

public boolean getSoundMuteOthersTurn() {
return store.getBoolean(SOUND_MUTE_OTHERS_TURN);
}

kuronekochomusuke marked this conversation as resolved.
Show resolved Hide resolved

public int getTooltipDelay() {
return store.getInt(TOOLTIP_DELAY);
}
Expand Down Expand Up @@ -1730,12 +1755,24 @@ public void setShowWrecks(boolean state) {
store.setValue(SHOW_WRECKS, state);
}

public void setSoundBingFilename(String name) {
store.setValue(SOUND_BING_FILENAME, name);
public void setSoundBingFilenameChat(String name) {
store.setValue(SOUND_BING_FILENAME_CHAT, name);
}
public void setSoundBingFilenameMyTurn(String name) {
store.setValue(SOUND_BING_FILENAME_MY_TURN, name);
}
public void setSoundBingFilenameOthersTurn(String name) {
kuronekochomusuke marked this conversation as resolved.
Show resolved Hide resolved
store.setValue(SOUND_BING_FILENAME_OTHERS_TURN, name);
}

public void setSoundMute(boolean state) {
store.setValue(SOUND_MUTE, state);
public void setSoundMuteChat(boolean state) {
store.setValue(SOUND_MUTE_CHAT, state);
}
public void setSoundMuteMyTurn(boolean state) {
store.setValue(SOUND_MUTE_MY_TURN, state);
}
public void setSoundMuteOthersTurn(boolean state) {
kuronekochomusuke marked this conversation as resolved.
Show resolved Hide resolved
store.setValue(SOUND_MUTE_OTHERS_TURN, state);
}

public void setTooltipDelay(int i) {
Expand Down
Loading