Skip to content

Commit 97b2412

Browse files
committed
Fix 540
UI sounds interrupted by others
1 parent c806401 commit 97b2412

3 files changed

Lines changed: 14 additions & 3 deletions

File tree

‎src/Engine/Game.cpp‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ Game::Game(const std::string &title) : _screen(0), _cursor(0), _lang(0), _states
8585
else
8686
{
8787
Mix_AllocateChannels(16);
88-
Mix_ReserveChannels(1);
88+
// Set up UI channels
89+
Mix_ReserveChannels(2);
90+
Mix_GroupChannels(0, 1, 0);
8991
Log(LOG_INFO) << "SDL_mixer initialized successfully.";
9092
}
9193
}
@@ -384,11 +386,18 @@ void Game::setVolume(int sound, int music, int ui)
384386
if (!Options::mute)
385387
{
386388
if (sound >= 0)
389+
{
387390
Mix_Volume(-1, sound);
391+
}
388392
if (music >= 0)
393+
{
389394
Mix_VolumeMusic(music);
395+
}
390396
if (ui >= 0)
397+
{
391398
Mix_Volume(0, ui);
399+
Mix_Volume(1, ui);
400+
}
392401
}
393402
}
394403

‎src/Interface/TextButton.cpp‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919
#include "TextButton.h"
2020
#include <SDL.h>
21+
#include <SDL_mixer.h>
2122
#include "Text.h"
2223
#include "../Engine/Sound.h"
2324
#include "../Engine/Action.h"
@@ -280,7 +281,7 @@ void TextButton::mousePress(Action *action, State *state)
280281
if (soundPress != 0 && _group == 0 &&
281282
action->getDetails()->button.button != SDL_BUTTON_WHEELUP && action->getDetails()->button.button != SDL_BUTTON_WHEELDOWN)
282283
{
283-
soundPress->play(0);
284+
soundPress->play(Mix_GroupAvailable(0));
284285
}
285286

286287
if (_comboBox)

‎src/Interface/Window.cpp‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919
#include "Window.h"
2020
#include <SDL.h>
21+
#include <SDL_mixer.h>
2122
#include "../aresame.h"
2223
#include "../Engine/Timer.h"
2324
#include "../Engine/Sound.h"
@@ -133,7 +134,7 @@ void Window::popup()
133134
int sound = RNG::generate(0, 2);
134135
if (soundPopup[sound] != 0)
135136
{
136-
soundPopup[sound]->play(0);
137+
soundPopup[sound]->play(Mix_GroupAvailable(0));
137138
}
138139
}
139140
if (_popupStep < 1.0)

0 commit comments

Comments
 (0)