Skip to content

Commit

Permalink
Merge pull request #4151 from kuronekochomusuke/turnSounds
Browse files Browse the repository at this point in the history
turn sounds
  • Loading branch information
SJuliez authored Feb 15, 2023
2 parents 0a94ad0 + f74e770 commit 3ec34ed
Show file tree
Hide file tree
Showing 12 changed files with 180 additions and 44 deletions.
4 changes: 3 additions & 1 deletion megamek/i18n/megamek/client/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1195,7 +1195,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
74 changes: 55 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,24 @@ 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();
}

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

public BoardView getBoardView() {
return bv;
}
Expand Down Expand Up @@ -402,27 +422,25 @@ public void setPlayerListDialog(final PlayerListDialog playerListDialog) {
/**
* Try to load the "bing" sound clip.
*/
private void loadSoundClip() {
if (GUIP.getSoundBingFilename() == null) {
return;
private @Nullable Clip loadSoundClip(@Nullable String filename) {
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 clip = AudioSystem.getClip();
try (AudioInputStream ais = AudioSystem.getAudioInputStream(file)) {
bingClip.open(ais);
clip.open(ais);
return clip;
}
} catch (Exception ex) {
LogManager.getLogger().error("", ex);
bingClip = null;
return null;
}
}

Expand Down Expand Up @@ -2126,10 +2144,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)) {
bingClipChat.setFramePosition(0);
bingClipChat.start();
}
}

public void bingMyTurn() {
if (!GUIP.getSoundMuteMyTurn() && (bingClipMyTurn != null)) {
bingClipMyTurn.setFramePosition(0);
bingClipMyTurn.start();
}
}

public void bingOthersTurn() {
if (!GUIP.getSoundMuteOthersTurn() && (bingClipMyTurn != null)) {
bingClipOthersTurn.setFramePosition(0);
bingClipOthersTurn.start();
}
}

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

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

@Override
Expand Down Expand Up @@ -2837,6 +2869,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
4 changes: 4 additions & 0 deletions megamek/src/megamek/client/ui/swing/DeploymentDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -407,17 +407,21 @@ public void gameTurnChange(GameTurnChangeEvent e) {
if (clientgui.getClient().isMyTurn()) {
if (cen == Entity.NONE) {
beginMyTurn();
clientgui.bingMyTurn();
}
setStatusBarText(Messages.getString("DeploymentDisplay.its_your_turn") + s);
} else {
endMyTurn();
String playerName;

if (e.getPlayer() != null) {
playerName = e.getPlayer().getName();
} else {
playerName = "Unknown";
}

setStatusBarText(Messages.getString("DeploymentDisplay.its_others_turn", playerName) + s);
clientgui.bingOthersTurn();
}

}
Expand Down
5 changes: 5 additions & 0 deletions megamek/src/megamek/client/ui/swing/FiringDisplay.java
Original file line number Diff line number Diff line change
Expand Up @@ -2196,16 +2196,21 @@ public void gameTurnChange(GameTurnChangeEvent e) {
if (cen == Entity.NONE) {
beginMyTurn();
}

setStatusBarText(Messages.getString("FiringDisplay.its_your_turn") + s);
clientgui.bingMyTurn();
} else {
endMyTurn();
String playerName;

if (e.getPlayer() != null) {
playerName = e.getPlayer().getName();
} else {
playerName = "Unknown";
}

setStatusBarText(Messages.getString("FiringDisplay.its_others_turn", playerName) + s);
clientgui.bingOthersTurn();
}
}
}
Expand Down
64 changes: 52 additions & 12 deletions megamek/src/megamek/client/ui/swing/GUIPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,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 @@ -563,8 +567,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 @@ -1149,12 +1157,28 @@ 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);
}

public int getTooltipDelay() {
Expand Down Expand Up @@ -1752,12 +1776,28 @@ 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) {
store.setValue(SOUND_BING_FILENAME_OTHERS_TURN, name);
}

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 setSoundMute(boolean state) {
store.setValue(SOUND_MUTE, state);
public void setSoundMuteOthersTurn(boolean state) {
store.setValue(SOUND_MUTE_OTHERS_TURN, state);
}

public void setTooltipDelay(int i) {
Expand Down
Loading

0 comments on commit 3ec34ed

Please sign in to comment.