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

Feature - Add audio tab and master volume setting #4661

Merged
merged 7 commits into from
Aug 8, 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
3 changes: 3 additions & 0 deletions megamek/i18n/megamek/client/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1209,6 +1209,7 @@ CommonSettingsDialog.locale.Spanish=Español
CommonSettingsDialog.locale=Language/Sprache/\u042f\u0437\u044b\u043a:
CommonSettingsDialog.logFileName=Game log filename:
CommonSettingsDialog.main=Main
CommonSettingsDialog.audio=Audio
CommonSettingsDialog.miniMap=Mini Map
CommonSettingsDialog.mmSymbol=Use StratOps unit symbols in the Minimap
CommonSettingsDialog.mouseWheelZoom=Mouse wheel zooms map.
Expand Down Expand Up @@ -1262,6 +1263,8 @@ CommonSettingsDialog.showWrecks=Show wrecks.
CommonSettingsDialog.skinFile=Skin File:
CommonSettingsDialog.skinFileFail.msg=Error parsing skin specification file, reverting to previous skin!
CommonSettingsDialog.skinFileFail.title=Failed to load skin!
CommonSettingsDialog.masterVolume=Master Volume
CommonSettingsDialog.masterVolumeTT=Adjusts the volume of all audio output from the application.
CommonSettingsDialog.soundMuteChat=Mute chat notification sound.
CommonSettingsDialog.soundMuteMyTurn=Mute my turn notification sound
CommonSettingsDialog.soundMuteOthersTurn=Mute others turn notification sound
Expand Down
54 changes: 16 additions & 38 deletions megamek/src/megamek/client/ui/swing/ClientGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
import megamek.client.ui.dialogs.helpDialogs.AbstractHelpDialog;
import megamek.client.ui.dialogs.helpDialogs.MMReadMeHelpDialog;
import megamek.client.ui.enums.DialogResult;
import megamek.client.ui.swing.audio.AudioService;
import megamek.client.ui.swing.audio.SoundManager;
import megamek.client.ui.swing.audio.SoundType;
import megamek.client.ui.swing.boardview.BoardView;
import megamek.client.ui.swing.dialog.AbstractUnitSelectorDialog;
import megamek.client.ui.swing.dialog.MegaMekUnitSelectorDialog;
Expand Down Expand Up @@ -263,13 +266,6 @@ public class ClientGUI extends JPanel implements BoardViewListener,
private File curfileBoardImage;
private File curfileBoard;

/**
* Cache for the "bing" soundclip.
*/
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 @@ -328,6 +324,12 @@ public class ClientGUI extends JPanel implements BoardViewListener,
* shot.
*/
private int pointblankEID = Entity.NONE;

/**
* Audio system
*/
private final AudioService audioService = new SoundManager();

//endregion Variable Declarations

/**
Expand All @@ -341,31 +343,14 @@ public ClientGUI(Client client, MegaMekController c) {
this.addComponentListener(this);
this.client = client;
controller = c;
loadSoundFiles();
panMain.setLayout(cardsMain);
panSecondary.setLayout(cardsSecondary);
JPanel panDisplay = new JPanel(new BorderLayout());
panDisplay.add(panMain, BorderLayout.CENTER);
panDisplay.add(panSecondary, BorderLayout.SOUTH);
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());
audioService.loadSoundFiles();
}

public BoardView getBoardView() {
Expand Down Expand Up @@ -2154,24 +2139,15 @@ public void loadPreviewImage(JLabel bp, Entity entity, Player player) {
* Make a "bing" sound.
*/
public void bingChat() {
if (!GUIP.getSoundMuteChat() && (bingClipMyTurn != null)) {
bingClipChat.setFramePosition(0);
bingClipChat.start();
}
audioService.playSound(SoundType.BING_CHAT);
}

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

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

private void setWeaponOrderPrefs(boolean prefChange) {
Expand Down Expand Up @@ -2899,7 +2875,9 @@ public void preferenceChange(PreferenceChangeEvent e) {
} 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();
audioService.loadSoundFiles();
} else if (e.getName().equals(GUIPreferences.MASTER_VOLUME)) {
audioService.setVolume();
}
}
}
120 changes: 85 additions & 35 deletions megamek/src/megamek/client/ui/swing/CommonSettingsDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,6 @@ 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 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 chkHighQualityGraphics = new JCheckBox(Messages.getString("CommonSettingsDialog.highQualityGraphics"));
private final JCheckBox showWpsinTT = new JCheckBox(Messages.getString("CommonSettingsDialog.showWpsinTT"));
private final JCheckBox showWpsLocinTT = new JCheckBox(Messages.getString("CommonSettingsDialog.showWpsLocinTT"));
Expand All @@ -157,6 +151,16 @@ private <T> void moveElement(DefaultListModel<T> srcModel, int srcIndex, int trg
private final JCheckBox getFocus = new JCheckBox(Messages.getString("CommonSettingsDialog.getFocus"));
private JSlider guiScale;

// Audio Tab
private final JLabel masterVolumeLabel = new JLabel(Messages.getString("CommonSettingsDialog.masterVolume"));
private JSlider masterVolumeSlider;
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 tfSoundMuteMyTurnFileName;
private final JCheckBox soundMuteOthersTurn = new JCheckBox(Messages.getString("CommonSettingsDialog.soundMuteOthersTurn"));
private JTextField tfSoundMuteOthersFileName;

private final JCheckBox keepGameLog = new JCheckBox(Messages.getString("CommonSettingsDialog.keepGameLog"));
private JTextField gameLogFilename;
private final JCheckBox stampFilenames = new JCheckBox(Messages.getString("CommonSettingsDialog.stampFilenames"));
Expand Down Expand Up @@ -411,6 +415,8 @@ public void windowClosing(WindowEvent e) {

JScrollPane settingsPane = new JScrollPane(getSettingsPanel());
settingsPane.getVerticalScrollBar().setUnitIncrement(16);
JScrollPane audioPane = new JScrollPane(getAudioPanel());
audioPane.getVerticalScrollBar().setUnitIncrement(16);
JScrollPane keyBindPane = new JScrollPane(getKeyBindPanel());
keyBindPane.getVerticalScrollBar().setUnitIncrement(16);
JScrollPane advancedSettingsPane = new JScrollPane(getAdvancedSettingsPanel());
Expand All @@ -429,6 +435,7 @@ public void windowClosing(WindowEvent e) {
autoDisplayPane.getVerticalScrollBar().setUnitIncrement(16);

panTabs.add(Messages.getString("CommonSettingsDialog.main"), settingsPane);
panTabs.add(Messages.getString("CommonSettingsDialog.audio"), audioPane);
panTabs.add(Messages.getString("CommonSettingsDialog.keyBinds"), keyBindPane);
panTabs.add(Messages.getString("CommonSettingsDialog.gameBoard"), gameBoardPane);
panTabs.add(Messages.getString("CommonSettingsDialog.unitDisplay"), unitDisplayPane);
Expand All @@ -444,6 +451,67 @@ public void windowClosing(WindowEvent e) {
return panTabs;
}

private JPanel getAudioPanel() {
List<List<Component>> comps = new ArrayList<>();
ArrayList<Component> row;

row = new ArrayList<>();
row.add(masterVolumeLabel);
comps.add(row);

masterVolumeSlider = new JSlider();
masterVolumeSlider.setMinorTickSpacing(5);
masterVolumeSlider.setMajorTickSpacing(25);
masterVolumeSlider.setMinimum(0);
masterVolumeSlider.setMaximum(100);
Hashtable<Integer, JComponent> table = new Hashtable<>();
table.put(0, new JLabel("0%"));
table.put(25, new JLabel("25%"));
table.put(50, new JLabel("50%"));
table.put(75, new JLabel("75%"));
table.put(100, new JLabel("100%"));
masterVolumeSlider.setLabelTable(table);
masterVolumeSlider.setPaintTicks(true);
masterVolumeSlider.setPaintLabels(true);
masterVolumeSlider.setMaximumSize(new Dimension(250, 100));
masterVolumeSlider.setToolTipText(Messages.getString("CommonSettingsDialog.masterVolumeTT"));
row = new ArrayList<>();
row.add(masterVolumeSlider);
comps.add(row);

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);

addLineSpacer(comps);

comps.add(checkboxEntry(soundMuteMyTurn, null));

tfSoundMuteMyTurnFileName = new JTextField(5);
tfSoundMuteMyTurnFileName.setMaximumSize(new Dimension(450, 40));
row = new ArrayList<>();
row.add(tfSoundMuteMyTurnFileName);
comps.add(row);

addLineSpacer(comps);

comps.add(checkboxEntry(soundMuteOthersTurn, null));

tfSoundMuteOthersFileName = new JTextField(5);
tfSoundMuteOthersFileName.setMaximumSize(new Dimension(450, 40));
row = new ArrayList<>();
row.add(tfSoundMuteOthersFileName);
comps.add(row);

return createSettingsPanel(comps);
}

private JPanel getGameBoardPanel() {
List<List<Component>> comps = new ArrayList<>();
ArrayList<Component> row;
Expand Down Expand Up @@ -1377,27 +1445,6 @@ private JPanel getSettingsPanel() {

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);

JLabel unitStartCharLabel = new JLabel(Messages.getString("CommonSettingsDialog.protoMechUnitCodes"));
unitStartChar = new JComboBox<>();
// Add option for "A, B, C, D..."
Expand Down Expand Up @@ -1492,9 +1539,6 @@ public void setVisible(boolean visible) {
nagForNoUnJamRAC.setSelected(GUIP.getNagForNoUnJamRAC());
animateMove.setSelected(GUIP.getShowMoveStep());
showWrecks.setSelected(GUIP.getShowWrecks());
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 @@ -1517,8 +1561,12 @@ public void setVisible(boolean visible) {
}
}

masterVolumeSlider.setValue(GUIP.getMasterVolume());
soundMuteChat.setSelected(GUIP.getSoundMuteChat());
soundMuteMyTurn.setSelected(GUIP.getSoundMuteMyTurn());
soundMuteOthersTurn.setSelected(GUIP.getSoundMuteOthersTurn());
tfSoundMuteChatFileName.setText(GUIP.getSoundBingFilenameChat());
tfSoundMuteMyTurntFileName.setText(GUIP.getSoundBingFilenameMyTurn());
tfSoundMuteMyTurnFileName.setText(GUIP.getSoundBingFilenameMyTurn());
tfSoundMuteOthersFileName.setText(GUIP.getSoundBingFilenameOthersTurn());

maxPathfinderTime.setText(Integer.toString(CP.getMaxPathfinderTime()));
Expand Down Expand Up @@ -1834,9 +1882,6 @@ protected void okAction() {
GUIP.setNagForNoUnJamRAC(nagForNoUnJamRAC.isSelected());
GUIP.setShowMoveStep(animateMove.isSelected());
GUIP.setShowWrecks(showWrecks.isSelected());
GUIP.setSoundMuteChat(soundMuteChat.isSelected());
GUIP.setSoundMuteMyTurn(soundMuteMyTurn.isSelected());
GUIP.setSoundMuteOthersTurn(soundMuteOthersTurn.isSelected());
GUIP.setShowWpsinTT(showWpsinTT.isSelected());
GUIP.setShowWpsLocinTT(showWpsLocinTT.isSelected());
GUIP.setshowArmorMiniVisTT(showArmorMiniVisTT.isSelected());
Expand Down Expand Up @@ -1928,8 +1973,13 @@ protected void okAction() {

GUIP.setMoveDefaultClimbMode(moveDefaultClimbMode.isSelected());

GUIP.setMasterVolume(masterVolumeSlider.getValue());
GUIP.setSoundMuteChat(soundMuteChat.isSelected());
GUIP.setSoundMuteMyTurn(soundMuteMyTurn.isSelected());
GUIP.setSoundMuteOthersTurn(soundMuteOthersTurn.isSelected());

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

try {
Expand Down
11 changes: 11 additions & 0 deletions megamek/src/megamek/client/ui/swing/GUIPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ public class GUIPreferences extends PreferenceStoreProxy {
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 MASTER_VOLUME = "MasterVolume";
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";
Expand Down Expand Up @@ -653,6 +654,8 @@ protected GUIPreferences() {
store.setDefault(SHOW_MAPHEX_POPUP, true);
store.setDefault(SHOW_MOVE_STEP, true);
store.setDefault(SHOW_WRECKS, true);

store.setDefault(MASTER_VOLUME, 100);
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");
Expand Down Expand Up @@ -1343,6 +1346,10 @@ public boolean getShowWrecks() {
return store.getBoolean(SHOW_WRECKS);
}

public int getMasterVolume() {
return store.getInt(MASTER_VOLUME);
}

public String getSoundBingFilenameChat() {
return store.getString(SOUND_BING_FILENAME_CHAT);
}
Expand Down Expand Up @@ -2112,6 +2119,10 @@ public void setSoundBingFilenameOthersTurn(String name) {
store.setValue(SOUND_BING_FILENAME_OTHERS_TURN, name);
}

public void setMasterVolume(int state) {
store.setValue(MASTER_VOLUME, state);
}

public void setSoundMuteChat(boolean state) {
store.setValue(SOUND_MUTE_CHAT, state);
}
Expand Down
26 changes: 26 additions & 0 deletions megamek/src/megamek/client/ui/swing/audio/AudioService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright (c) 2023 - The MegaMek Team. All Rights Reserved.
*
* This file is part of MegaMek.
*
* MegaMek is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MegaMek is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MegaMek. If not, see <http://www.gnu.org/licenses/>.
*/

package megamek.client.ui.swing.audio;

public interface AudioService {
void loadSoundFiles();
void playSound(SoundType id);
void setVolume();
}
Loading