Skip to content

Commit

Permalink
make all lobbies, mp ui screens, and chat handlers use the new code
Browse files Browse the repository at this point in the history
This commit replaces all appearance of `game_config::sounds::...`
where ... is an mp ui specific sound, with an appropriate call to
the mp_ui_sounds code. This makes sure that the preferences are
checked appropriately and notifications are distributed in all cases
appropriate.

This also obsoletes the "lobby sounds" advanced preference, it
doesn't do anything anymore. Its removal is pending.
  • Loading branch information
cbeck88 committed Oct 12, 2014
1 parent a2ed0df commit 3a5eec0
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 35 deletions.
10 changes: 5 additions & 5 deletions src/display_chat_manager.cpp
Expand Up @@ -22,7 +22,7 @@
#include "game_preferences.hpp"
#include "log.hpp"
#include "marked-up_text.hpp"
#include "sound.hpp"
#include "mp_ui_sounds.hpp"
#include "serialization/string_utils.hpp"

#include <boost/cstdint.hpp>
Expand Down Expand Up @@ -74,13 +74,13 @@ void display_chat_manager::add_chat_message(const time_t& time, const std::strin
if (bell) {
if ((type == events::chat_handler::MESSAGE_PRIVATE && (!is_observer || whisper))
|| utils::word_match(message, preferences::login())) {
sound::play_UI_sound(game_config::sounds::receive_message_highlight);
mp_ui_sounds::private_message(false);
} else if (preferences::is_friend(sender)) {
sound::play_UI_sound(game_config::sounds::receive_message_friend);
mp_ui_sounds::friend_message(false);
} else if (sender == "server") {
sound::play_UI_sound(game_config::sounds::receive_message_server);
mp_ui_sounds::server_message(false);
} else {
sound::play_UI_sound(game_config::sounds::receive_message);
mp_ui_sounds::public_message(false);
}
}

Expand Down
16 changes: 7 additions & 9 deletions src/gui/dialogs/lobby_main.cpp
Expand Up @@ -45,7 +45,7 @@
#include "network.hpp"
#include "playmp_controller.hpp"
#include "preferences_display.hpp"
#include "sound.hpp"
#include "mp_ui_sounds.hpp"

#include <boost/bind.hpp>
#include <boost/foreach.hpp>
Expand Down Expand Up @@ -323,24 +323,22 @@ void tlobby_main::do_notify(t_notify_mode mode)
case NOTIFY_WHISPER:
case NOTIFY_WHISPER_OTHER_WINDOW:
case NOTIFY_OWN_NICK:
sound::play_UI_sound(
game_config::sounds::receive_message_highlight);
mp_ui_sounds::private_message(true);
break;
case NOTIFY_FRIEND_MESSAGE:
sound::play_UI_sound(
game_config::sounds::receive_message_friend);
mp_ui_sounds::friend_message(true);
break;
case NOTIFY_SERVER_MESSAGE:
sound::play_UI_sound(
game_config::sounds::receive_message_server);
mp_ui_sounds::server_message(true);
break;
case NOTIFY_LOBBY_QUIT:
sound::play_UI_sound(game_config::sounds::user_leave);
mp_ui_sounds::player_leaves(true);
break;
case NOTIFY_LOBBY_JOIN:
sound::play_UI_sound(game_config::sounds::user_arrive);
mp_ui_sounds::player_joins(true);
break;
case NOTIFY_MESSAGE:
mp_ui_sounds::public_message(true);
break;
default:
break;
Expand Down
2 changes: 1 addition & 1 deletion src/mp_ui_sounds.cpp
Expand Up @@ -55,7 +55,7 @@ bool notif_pref(std::string id)
// Note: This list must agree with data/gui/.../lobby_sound_options.cfg
const std::vector<std::string> items = boost::assign::list_of("player_joins")("player_leaves")("private_message")("friend_message")("public_message")("server_message")("ready_to_start")("game_has_begun");

void player_enters(bool is_lobby)
void player_joins(bool is_lobby)
{
std::string id = "player_enters";
if (is_lobby && !lobby_pref(id)) {
Expand Down
2 changes: 1 addition & 1 deletion src/mp_ui_sounds.hpp
Expand Up @@ -26,7 +26,7 @@
namespace mp_ui_sounds {

// Functions called when such an event occurs
void player_enters(bool is_lobby);
void player_joins(bool is_lobby);
void player_leaves(bool is_lobby);
void public_message(bool is_lobby);
void friend_message(bool is_lobby);
Expand Down
8 changes: 2 additions & 6 deletions src/multiplayer_connect.cpp
Expand Up @@ -19,7 +19,6 @@
#include "multiplayer_connect.hpp"

#include "ai/configuration.hpp"
#include "desktop/notifications.hpp"
#include "dialogs.hpp"
#include "display_chat_manager.hpp"
#include "game_display.hpp"
Expand All @@ -28,7 +27,7 @@
#include "log.hpp"
#include "map.hpp"
#include "wml_separators.hpp"
#include "sound.hpp"
#include "mp_ui_sounds.hpp"

#include <boost/foreach.hpp>

Expand Down Expand Up @@ -560,10 +559,7 @@ void connect::process_network_data(const config& data,
update_playerlist_state(result.second); //result.second is the silent flag
if (!was_able_to_start && engine_.can_start_game()) {
DBG_MP << "play party full sound" << std::endl;
if(preferences::UI_sound_on()) {
sound::play_bell(game_config::sounds::party_full_bell); //this is play_bell instead of play_UI_sound to economize on sound channels. UI only has two sounds, and turn bell has a dedicated channel.
}
desktop::notifications::send(_("Wesnoth"), _ ("Ready to start!"), desktop::notifications::OTHER);
mp_ui_sounds::ready_for_start();
}
}

Expand Down
21 changes: 12 additions & 9 deletions src/multiplayer_ui.cpp
Expand Up @@ -26,7 +26,7 @@
#include "multiplayer.hpp"
#include "multiplayer_ui.hpp"
#include "multiplayer_lobby.hpp" //needed for dynamic cast when implementing the lobby_sounds preference
#include "sound.hpp"
#include "mp_ui_sounds.hpp"
#include "wml_separators.hpp"
#include "formula_string_utils.hpp"

Expand Down Expand Up @@ -413,15 +413,16 @@ void ui::process_message(const config& msg, const bool whisper) {

preferences::parse_admin_authentication(sender, message);

bool is_lobby = dynamic_cast<mp::lobby*>(this) != NULL;

if (whisper || utils::word_match(message, preferences::login())) {
sound::play_UI_sound(game_config::sounds::receive_message_highlight);
mp_ui_sounds::private_message(is_lobby);
} else if (preferences::is_friend(sender)) {
sound::play_UI_sound(game_config::sounds::receive_message_friend);
mp_ui_sounds::friend_message(is_lobby);
} else if (sender == "server") {
sound::play_UI_sound(game_config::sounds::receive_message_server);
mp_ui_sounds::server_message(is_lobby);
} else {
// too annoying and probably not any helpful
//sound::play_UI_sound(game_config::sounds::receive_message);
mp_ui_sounds::public_message(is_lobby);
}

std::string prefix;
Expand Down Expand Up @@ -690,11 +691,13 @@ void ui::set_user_menu_items(const std::vector<std::string>& list)

void ui::set_user_list(const std::vector<std::string>& list, bool silent)
{
if(!silent && (!dynamic_cast<mp::lobby*>(this) || preferences::lobby_sounds())) {
if(!silent) {
bool is_lobby = dynamic_cast<mp::lobby*>(this) != NULL;

if(list.size() < user_list_.size()) {
sound::play_UI_sound(game_config::sounds::user_leave);
mp_ui_sounds::player_leaves(is_lobby);
} else if(list.size() > user_list_.size()) {
sound::play_UI_sound(game_config::sounds::user_arrive);
mp_ui_sounds::player_joins(is_lobby);
}
}

Expand Down
6 changes: 2 additions & 4 deletions src/multiplayer_wait.cpp
Expand Up @@ -14,7 +14,6 @@

#include "global.hpp"

#include "desktop/notifications.hpp"
#include "dialogs.hpp"
#include "gettext.hpp"
#include "game_config_manager.hpp"
Expand All @@ -28,7 +27,7 @@
#include "resources.hpp"
#include "statistics.hpp"
#include "saved_game.hpp"
#include "sound.hpp"
#include "mp_ui_sounds.hpp"
#include "unit_types.hpp"
#include "wml_exception.hpp"
#include "wml_separators.hpp"
Expand Down Expand Up @@ -408,8 +407,7 @@ void wait::start_game()
level_to_gamestate(level_, state_);

LOG_NW << "starting game\n";
sound::play_UI_sound(game_config::sounds::mp_game_begins);
desktop::notifications::send(_("Wesnoth"), _ ("Game has begun!"), desktop::notifications::OTHER);
mp_ui_sounds::game_has_begun();
}

void wait::layout_children(const SDL_Rect& rect)
Expand Down

0 comments on commit 3a5eec0

Please sign in to comment.