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

Disable chat message audio when game is running #658

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions ClientCore/Settings/UserINISettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ protected UserINISettings(IniFile iniFile)
ClientVolume = new DoubleSetting(iniFile, AUDIO, "ClientVolume", 1.0);
PlayMainMenuMusic = new BoolSetting(iniFile, AUDIO, "PlayMainMenuMusic", true);
StopMusicOnMenu = new BoolSetting(iniFile, AUDIO, "StopMusicOnMenu", true);
StopGameLobbyMessageAudio = new BoolSetting(iniFile, AUDIO, "StopGameLobbyMessageAudio", true);
MessageSound = new BoolSetting(iniFile, AUDIO, "ChatMessageSound", true);

ScrollRate = new IntSetting(iniFile, OPTIONS, "ScrollRate", 3);
Expand Down Expand Up @@ -167,6 +168,7 @@ protected UserINISettings(IniFile iniFile)
public DoubleSetting ClientVolume { get; private set; }
public BoolSetting PlayMainMenuMusic { get; private set; }
public BoolSetting StopMusicOnMenu { get; private set; }
public BoolSetting StopGameLobbyMessageAudio { get; private set; }
public BoolSetting MessageSound { get; private set; }

/********/
Expand Down
101 changes: 60 additions & 41 deletions DTAConfig/OptionPanels/AudioOptionsPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@ namespace DTAConfig.OptionPanels
{
class AudioOptionsPanel : XNAOptionsPanel
{
private const int VOLUME_MIN = 0;
private const int VOLUME_MAX = 10;
private const int VOLUME_SCALE = 10;
private const int PADDING_X = 12;
private const int PADDING_Y = 14;
private const int TRACKBAR_X_PADDING = 16;
private const int TRACKBAR_Y_PADDING = 16;
private const int TRACKBAR_Y_OFFSET = 2; //trackbars sit slightly higher than their labels.
private const int TRACKBAR_HEIGHT = 22;
private const int CHECKBOX_SPACING = 4;
private const int GROUP_SPACING = 22;

public AudioOptionsPanel(WindowManager windowManager, UserINISettings iniSettings)
: base(windowManager, iniSettings)
{
Expand All @@ -30,6 +42,7 @@ public AudioOptionsPanel(WindowManager windowManager, UserINISettings iniSetting

private XNAClientCheckBox chkMainMenuMusic;
private XNAClientCheckBox chkStopMusicOnMenu;
private XNAClientCheckBox chkStopGameLobbyMessageAudio;

public override void Initialize()
{
Expand All @@ -39,33 +52,33 @@ public override void Initialize()

var lblScoreVolume = new XNALabel(WindowManager);
lblScoreVolume.Name = "lblScoreVolume";
lblScoreVolume.ClientRectangle = new Rectangle(12, 14, 0, 0);
lblScoreVolume.ClientRectangle = new Rectangle(PADDING_X, PADDING_Y, 0, 0);
lblScoreVolume.Text = "Music Volume:".L10N("Client:DTAConfig:MusicVolume");

lblScoreVolumeValue = new XNALabel(WindowManager);
lblScoreVolumeValue.Name = "lblScoreVolumeValue";
lblScoreVolumeValue.FontIndex = 1;
lblScoreVolumeValue.Text = "0";
lblScoreVolumeValue.ClientRectangle = new Rectangle(
Width - lblScoreVolumeValue.Width - 12,
Width - lblScoreVolumeValue.Width - PADDING_X,
lblScoreVolume.Y, 0, 0);

trbScoreVolume = new XNATrackbar(WindowManager);
trbScoreVolume.Name = "trbScoreVolume";
trbScoreVolume.ClientRectangle = new Rectangle(
lblScoreVolume.Right + 16,
lblScoreVolume.Y - 2,
lblScoreVolumeValue.X - lblScoreVolume.Right - 31,
22);
lblScoreVolume.Right + TRACKBAR_X_PADDING,
lblScoreVolume.Y - TRACKBAR_Y_OFFSET,
lblScoreVolumeValue.X - TRACKBAR_X_PADDING - lblScoreVolume.Right - TRACKBAR_X_PADDING,
TRACKBAR_HEIGHT);
trbScoreVolume.BackgroundTexture = AssetLoader.CreateTexture(new Color(0, 0, 0, 128), 2, 2);
trbScoreVolume.MinValue = 0;
trbScoreVolume.MaxValue = 10;
trbScoreVolume.MinValue = VOLUME_MIN;
trbScoreVolume.MaxValue = VOLUME_MAX;
trbScoreVolume.ValueChanged += TrbScoreVolume_ValueChanged;

var lblSoundVolume = new XNALabel(WindowManager);
lblSoundVolume.Name = "lblSoundVolume";
lblSoundVolume.ClientRectangle = new Rectangle(lblScoreVolume.X,
lblScoreVolume.Bottom + 20, 0, 0);
trbScoreVolume.Bottom + TRACKBAR_Y_PADDING + TRACKBAR_Y_OFFSET, 0, 0);
lblSoundVolume.Text = "Sound Volume:".L10N("Client:DTAConfig:SoundVolume");

lblSoundVolumeValue = new XNALabel(WindowManager);
Expand All @@ -80,18 +93,18 @@ public override void Initialize()
trbSoundVolume.Name = "trbSoundVolume";
trbSoundVolume.ClientRectangle = new Rectangle(
trbScoreVolume.X,
lblSoundVolume.Y - 2,
trbScoreVolume.Bottom + TRACKBAR_Y_PADDING,
trbScoreVolume.Width,
trbScoreVolume.Height);
trbSoundVolume.BackgroundTexture = trbScoreVolume.BackgroundTexture;
trbSoundVolume.MinValue = 0;
trbSoundVolume.MaxValue = 10;
trbSoundVolume.MinValue = VOLUME_MIN;
trbSoundVolume.MaxValue = VOLUME_MAX;
trbSoundVolume.ValueChanged += TrbSoundVolume_ValueChanged;

var lblVoiceVolume = new XNALabel(WindowManager);
lblVoiceVolume.Name = "lblVoiceVolume";
lblVoiceVolume.ClientRectangle = new Rectangle(lblScoreVolume.X,
lblSoundVolume.Bottom + 20, 0, 0);
trbSoundVolume.Bottom + TRACKBAR_Y_PADDING + TRACKBAR_Y_OFFSET, 0, 0);
lblVoiceVolume.Text = "Voice Volume:".L10N("Client:DTAConfig:VoiceVolume");

lblVoiceVolumeValue = new XNALabel(WindowManager);
Expand All @@ -106,25 +119,26 @@ public override void Initialize()
trbVoiceVolume.Name = "trbVoiceVolume";
trbVoiceVolume.ClientRectangle = new Rectangle(
trbScoreVolume.X,
lblVoiceVolume.Y - 2,
trbSoundVolume.Bottom + TRACKBAR_Y_PADDING,
trbScoreVolume.Width,
trbScoreVolume.Height);
trbVoiceVolume.BackgroundTexture = trbScoreVolume.BackgroundTexture;
trbVoiceVolume.MinValue = 0;
trbVoiceVolume.MaxValue = 10;
trbVoiceVolume.MinValue = VOLUME_MIN;
trbVoiceVolume.MaxValue = VOLUME_MAX;
trbVoiceVolume.ValueChanged += TrbVoiceVolume_ValueChanged;

chkScoreShuffle = new XNAClientCheckBox(WindowManager);
chkScoreShuffle.Name = "chkScoreShuffle";
chkScoreShuffle.ClientRectangle = new Rectangle(
lblScoreVolume.X,
trbVoiceVolume.Bottom + 12, 0, 0);
trbVoiceVolume.Bottom + TRACKBAR_Y_PADDING, 0, 0);
chkScoreShuffle.Text = "Shuffle Music".L10N("Client:DTAConfig:ShuffleMusic");
AddChild(chkScoreShuffle);

var lblClientVolume = new XNALabel(WindowManager);
lblClientVolume.Name = "lblClientVolume";
lblClientVolume.ClientRectangle = new Rectangle(lblScoreVolume.X,
chkScoreShuffle.Bottom + 40, 0, 0);
chkScoreShuffle.Bottom + GROUP_SPACING + TRACKBAR_Y_OFFSET, 0, 0);
lblClientVolume.Text = "Client Volume:".L10N("Client:DTAConfig:ClientVolume");

lblClientVolumeValue = new XNALabel(WindowManager);
Expand All @@ -139,27 +153,36 @@ public override void Initialize()
trbClientVolume.Name = "trbClientVolume";
trbClientVolume.ClientRectangle = new Rectangle(
trbScoreVolume.X,
lblClientVolume.Y - 2,
lblClientVolume.Y - TRACKBAR_Y_OFFSET,
trbScoreVolume.Width,
trbScoreVolume.Height);
trbClientVolume.BackgroundTexture = trbScoreVolume.BackgroundTexture;
trbClientVolume.MinValue = 0;
trbClientVolume.MaxValue = 10;
trbClientVolume.MinValue = VOLUME_MIN;
trbClientVolume.MaxValue = VOLUME_MAX;
trbClientVolume.ValueChanged += TrbClientVolume_ValueChanged;

chkMainMenuMusic = new XNAClientCheckBox(WindowManager);
chkMainMenuMusic.Name = "chkMainMenuMusic";
chkMainMenuMusic.Text = "Main menu music".L10N("Client:DTAConfig:MainMenuMusic");
chkMainMenuMusic.ClientRectangle = new Rectangle(
lblScoreVolume.X,
trbClientVolume.Bottom + 12, 0, 0);
chkMainMenuMusic.Text = "Main menu music".L10N("Client:DTAConfig:MainMenuMusic");
trbClientVolume.Bottom + PADDING_Y, 0, 0);
chkMainMenuMusic.CheckedChanged += ChkMainMenuMusic_CheckedChanged;
AddChild(chkMainMenuMusic);

chkStopMusicOnMenu = new XNAClientCheckBox(WindowManager);
chkStopMusicOnMenu.Name = "chkStopMusicOnMenu";
chkStopMusicOnMenu.ClientRectangle = new Rectangle(
lblScoreVolume.X, chkMainMenuMusic.Bottom + 24, 0, 0);
chkStopMusicOnMenu.Text = "Don't play main menu music in lobbies".L10N("Client:DTAConfig:NoLobbiesMusic");
chkStopMusicOnMenu.ClientRectangle = new Rectangle(
lblScoreVolume.X, chkMainMenuMusic.ClientRectangle.Bottom + CHECKBOX_SPACING, 0, 0);
AddChild(chkStopMusicOnMenu);

chkStopGameLobbyMessageAudio = new XNAClientCheckBox(WindowManager);
chkStopGameLobbyMessageAudio.Name = "chkStopGameLobbyMessageAudio";
chkStopGameLobbyMessageAudio.Text = "Don't play lobby message audio when game is running".L10N("Client:DTAConfig:NoGameLobbyMessageAudio");
chkStopGameLobbyMessageAudio.ClientRectangle = new Rectangle(
lblScoreVolume.X, chkStopMusicOnMenu.Bottom + CHECKBOX_SPACING, 0, 0);
AddChild(chkStopGameLobbyMessageAudio);

AddChild(lblScoreVolume);
AddChild(lblScoreVolumeValue);
Expand All @@ -170,17 +193,11 @@ public override void Initialize()
AddChild(lblVoiceVolume);
AddChild(lblVoiceVolumeValue);
AddChild(trbVoiceVolume);

AddChild(chkScoreShuffle);

AddChild(lblClientVolume);
AddChild(lblClientVolumeValue);
AddChild(trbClientVolume);

AddChild(chkMainMenuMusic);
AddChild(chkStopMusicOnMenu);

WindowManager.SoundPlayer.SetVolume(trbClientVolume.Value / 10.0f);
WindowManager.SoundPlayer.SetVolume(trbClientVolume.Value / (float)VOLUME_SCALE);
}

private void ChkMainMenuMusic_CheckedChanged(object sender, EventArgs e)
Expand All @@ -207,39 +224,41 @@ private void TrbVoiceVolume_ValueChanged(object sender, EventArgs e)
private void TrbClientVolume_ValueChanged(object sender, EventArgs e)
{
lblClientVolumeValue.Text = trbClientVolume.Value.ToString();
WindowManager.SoundPlayer.SetVolume(trbClientVolume.Value / 10.0f);
WindowManager.SoundPlayer.SetVolume(trbClientVolume.Value / (float)VOLUME_SCALE);
}

public override void Load()
{
base.Load();

trbScoreVolume.Value = (int)(IniSettings.ScoreVolume * 10);
trbSoundVolume.Value = (int)(IniSettings.SoundVolume * 10);
trbVoiceVolume.Value = (int)(IniSettings.VoiceVolume * 10);
trbScoreVolume.Value = (int)(IniSettings.ScoreVolume * VOLUME_SCALE);
trbSoundVolume.Value = (int)(IniSettings.SoundVolume * VOLUME_SCALE);
trbVoiceVolume.Value = (int)(IniSettings.VoiceVolume * VOLUME_SCALE);

chkScoreShuffle.Checked = IniSettings.IsScoreShuffle;

trbClientVolume.Value = (int)(IniSettings.ClientVolume * 10);
trbClientVolume.Value = (int)(IniSettings.ClientVolume * VOLUME_SCALE);

chkMainMenuMusic.Checked = IniSettings.PlayMainMenuMusic;
chkStopMusicOnMenu.Checked = IniSettings.StopMusicOnMenu;
chkStopGameLobbyMessageAudio.Checked = IniSettings.StopGameLobbyMessageAudio;
}

public override bool Save()
{
bool restartRequired = base.Save();

IniSettings.ScoreVolume.Value = trbScoreVolume.Value / 10.0;
IniSettings.SoundVolume.Value = trbSoundVolume.Value / 10.0;
IniSettings.VoiceVolume.Value = trbVoiceVolume.Value / 10.0;
IniSettings.ScoreVolume.Value = trbScoreVolume.Value / (double)VOLUME_SCALE;
IniSettings.SoundVolume.Value = trbSoundVolume.Value / (double)VOLUME_SCALE;
IniSettings.VoiceVolume.Value = trbVoiceVolume.Value / (double)VOLUME_SCALE;

IniSettings.IsScoreShuffle.Value = chkScoreShuffle.Checked;

IniSettings.ClientVolume.Value = trbClientVolume.Value / 10.0;
IniSettings.ClientVolume.Value = trbClientVolume.Value / (double)VOLUME_SCALE;

IniSettings.PlayMainMenuMusic.Value = chkMainMenuMusic.Checked;
IniSettings.StopMusicOnMenu.Value = chkStopMusicOnMenu.Checked;
IniSettings.StopGameLobbyMessageAudio.Value = chkStopGameLobbyMessageAudio.Checked;

return restartRequired;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,9 @@ protected override void StartGame()
for (int pId = 0; pId < Players.Count; pId++)
Players[pId].IsInGame = true;

if (UserINISettings.Instance.StopGameLobbyMessageAudio)
sndMessageSound.Enabled = false;

base.StartGame();
}

Expand All @@ -280,6 +283,9 @@ protected override void GameProcessExited()
PlayerInfo pInfo = Players.Find(p => p.Name == ProgramConstants.PLAYERNAME);
pInfo.IsInGame = false;

if (UserINISettings.Instance.StopGameLobbyMessageAudio)
sndMessageSound.Enabled = true;

base.GameProcessExited();

if (IsHost)
Expand Down
Loading