diff --git a/src/mp_ui_alerts.cpp b/src/mp_ui_alerts.cpp index de33c7ffbad..c169cf036c3 100644 --- a/src/mp_ui_alerts.cpp +++ b/src/mp_ui_alerts.cpp @@ -14,7 +14,7 @@ */ /** - * This namespace provides handlers which play the sounds / notificaitons + * This namespace provides handlers which play the sounds / notifications * for various mp server events, depending on the preference configuration. */ @@ -30,10 +30,10 @@ #include #include -namespace mp_ui_alerts { - -namespace { - +namespace mp_ui_alerts +{ +namespace +{ bool lobby_pref(const std::string& id) { return preferences::get(id + "_lobby", get_def_pref_lobby(id)); @@ -49,22 +49,42 @@ bool notif_pref(const std::string& id) return preferences::get(id + "_notif", get_def_pref_notif(id)); } +const std::string _player_joins = "player_joins"; +const std::string _player_leaves = "player_leaves"; +const std::string _private_message = "private_message"; +const std::string _friend_message = "friend_message"; +const std::string _public_message = "public_message"; +const std::string _server_message = "server_message"; +const std::string _ready_for_start = "ready_for_start"; +const std::string _game_has_begun = "game_has_begun"; +const std::string _turn_changed = "turn_changed"; +const std::string _game_created = "game_created"; } // end anonymous namespace -const std::vector items {"player_joins", "player_leaves", "private_message", "friend_message", "public_message", "server_message", "ready_for_start", "game_has_begun", "turn_changed", "game_created"}; +const std::vector items{ + _player_joins, + _player_leaves, + _private_message, + _friend_message, + _public_message, + _server_message, + _ready_for_start, + _game_has_begun, + _turn_changed, + _game_created, +}; -void game_created(const std::string & scenario, const std::string & name) +void game_created(const std::string& scenario, const std::string& name) { - std::string id = "game_created"; - if (!lobby_pref(id)) { - return ; + if(!lobby_pref(_game_created)) { + return; } - if (sound_pref(id)) { + if(sound_pref(_game_created)) { sound::play_UI_sound(game_config::sounds::game_created); } - if (notif_pref(id)) { + if(notif_pref(_game_created)) { const std::string message = VGETTEXT("A game ($name|, $scenario|) has been created", {{"name", name}, {"scenario", scenario}}); desktop::notifications::send(_("Wesnoth"), message, desktop::notifications::OTHER); } @@ -72,133 +92,148 @@ void game_created(const std::string & scenario, const std::string & name) void player_joins(bool is_lobby) { - std::string id = "player_enters"; - if (is_lobby && !lobby_pref(id)) { - return ; + if(is_lobby && !lobby_pref(_player_joins)) { + return; } - if (sound_pref(id)) { + + if(sound_pref(_player_joins)) { sound::play_UI_sound(game_config::sounds::player_joins); } - if (notif_pref(id)) { + + if(notif_pref(_player_joins)) { desktop::notifications::send(_("Wesnoth"), _("A player has joined"), desktop::notifications::OTHER); } } void player_leaves(bool is_lobby) { - std::string id = "player_leaves"; - if (is_lobby && !lobby_pref(id)) { - return ; + if(is_lobby && !lobby_pref(_player_leaves)) { + return; } - if (sound_pref(id)) { + + if(sound_pref(_player_leaves)) { sound::play_UI_sound(game_config::sounds::player_leaves); } - if (notif_pref(id)) { + + if(notif_pref(_player_leaves)) { desktop::notifications::send(_("Wesnoth"), _("A player has left"), desktop::notifications::OTHER); } } -void public_message(bool is_lobby, const std::string & sender, const std::string & message) +void public_message(bool is_lobby, const std::string& sender, const std::string& message) { - std::string id = "public_message"; - if (is_lobby && !lobby_pref(id)) { - return ; + if(is_lobby && !lobby_pref(_public_message)) { + return; } - if (sound_pref(id)) { + + if(sound_pref(_public_message)) { sound::play_UI_sound(game_config::sounds::public_message); } - if (notif_pref(id)) { + + if(notif_pref(_public_message)) { desktop::notifications::send(sender, message, desktop::notifications::CHAT); } } -void friend_message(bool is_lobby, const std::string & sender, const std::string & message) +void friend_message(bool is_lobby, const std::string& sender, const std::string& message) { - std::string id = "friend_message"; - if (is_lobby && !lobby_pref(id)) { - return ; + if(is_lobby && !lobby_pref(_friend_message)) { + return; } - if (sound_pref(id)) { + + if(sound_pref(_friend_message)) { sound::play_UI_sound(game_config::sounds::friend_message); } - if (notif_pref(id)) { + + if(notif_pref(_friend_message)) { desktop::notifications::send(sender, message, desktop::notifications::CHAT); } } -void private_message(bool is_lobby, const std::string & sender, const std::string & message) +void private_message(bool is_lobby, const std::string& sender, const std::string& message) { - std::string id = "private_message"; - if (is_lobby && !lobby_pref(id)) { - return ; + if(is_lobby && !lobby_pref(_private_message)) { + return; } - if (sound_pref(id)) { + + if(sound_pref(_private_message)) { sound::play_UI_sound(game_config::sounds::private_message); } - if (notif_pref(id)) { + + if(notif_pref(_private_message)) { desktop::notifications::send(sender, message, desktop::notifications::CHAT); } } -void server_message(bool is_lobby, const std::string & sender, const std::string & message) +void server_message(bool is_lobby, const std::string& sender, const std::string& message) { - std::string id = "server_message"; - if (is_lobby && !lobby_pref(id)) { - return ; + if(is_lobby && !lobby_pref(_server_message)) { + return; } - if (sound_pref(id)) { + + if(sound_pref(_server_message)) { sound::play_UI_sound(game_config::sounds::server_message); } - if (notif_pref(id)) { + + if(notif_pref(_server_message)) { desktop::notifications::send(sender, message, desktop::notifications::CHAT); } } void ready_for_start() { - std::string id = "ready_for_start"; - if (sound_pref(id)) { - if (preferences::UI_sound_on()) { - sound::play_bell(game_config::sounds::ready_for_start); //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. + if(sound_pref(_ready_for_start)) { + if(preferences::UI_sound_on()) { + // 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. + sound::play_bell(game_config::sounds::ready_for_start); } } - if (notif_pref(id)) { + + if(notif_pref(_ready_for_start)) { desktop::notifications::send(_("Wesnoth"), _("Ready to start!"), desktop::notifications::OTHER); } } void game_has_begun() { - std::string id = "game_has_begun"; - if (sound_pref(id)) { + if(sound_pref(_game_has_begun)) { sound::play_UI_sound(game_config::sounds::game_has_begun); } - if (notif_pref(id)) { - desktop::notifications::send(_("Wesnoth"), _ ("Game has begun!"), desktop::notifications::OTHER); + + if(notif_pref(_game_has_begun)) { + desktop::notifications::send(_("Wesnoth"), _("Game has begun!"), desktop::notifications::OTHER); } } -void turn_changed(const std::string & player_name) +void turn_changed(const std::string& player_name) { - std::string id = "turn_changed"; - if (notif_pref(id)) { + if(notif_pref(_turn_changed)) { utils::string_map player; player["name"] = player_name; desktop::notifications::send(_("Turn changed"), VGETTEXT("$name has taken control", player), desktop::notifications::TURN_CHANGED); } } -bool get_def_pref_sound(const std::string & id) { - return (id != "public_message" && id != "friend_message"); +bool get_def_pref_sound(const std::string& id) +{ + return (id != _public_message && id != _friend_message); } -bool get_def_pref_notif(const std::string & id) { - return (desktop::notifications::available() && (id == "private_message" || id == "ready_for_start" || id == "game_has_begun" || id == "turn_changed" || id == "game_created")); +bool get_def_pref_notif(const std::string& id) +{ + return (desktop::notifications::available() && ( + id == _private_message || + id == _ready_for_start || + id == _game_has_begun || + id == _turn_changed || + id == _game_created + )); } -bool get_def_pref_lobby(const std::string & id) { - return (id == "private_message" || id == "server_message" || id == "game_created"); +bool get_def_pref_lobby(const std::string& id) +{ + return (id == _private_message || id == _server_message || id == _game_created); } - } // end namespace mp_ui_alerts