Skip to content

Commit

Permalink
Adds a preference item for a sound being played and desktop notificat…
Browse files Browse the repository at this point in the history
…ions in the lobby when a new game is created.

Remove unnecessary blank lines and debugging comments

- Adds a preferences entry in the multiplayer/alerts menu so sounds and desktop notifications can be toggled.

Reformat a few points for consistency

Have desktop notification show name and scenario of new game

Have desktop notification show name and scenario of new game

Update desktop notifications to use VGETTEXT for translations

(cherry picked from commit af71dbf)
  • Loading branch information
lilinitsy authored and Wedge009 committed Aug 26, 2019
1 parent 17ca8c3 commit 5902e11
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 7 deletions.
2 changes: 1 addition & 1 deletion data/gui/window/mp_alerts_options.cfg
Expand Up @@ -197,7 +197,7 @@
{_GUI_LOBBY_SOUNDS_ENTRY "ready_for_start" _"Ready to start:" _"When the game you are hosting is ready to start"}
{_GUI_LOBBY_SOUNDS_ENTRY "game_has_begun" _"Game has begun:" _"When the host (not you) has started the game"}
{_GUI_LOBBY_SOUNDS_ENTRY "turn_changed" _"Turn changed:" _"When a new turn has begun"}

{_GUI_LOBBY_SOUNDS_ENTRY "game_created" _"Game created:" _"When a new game has been created"}
[/grid]

[/column]
Expand Down
4 changes: 3 additions & 1 deletion src/game_config.cpp
Expand Up @@ -262,7 +262,8 @@ std::string
game_user_arrive = "join.wav",
game_user_leave = "leave.wav",
ready_for_start = "bell.wav",
game_has_begun = "gamestart.ogg";
game_has_begun = "gamestart.ogg",
game_created = "chat-highlight.ogg";

const std::string
button_press = "button.wav",
Expand Down Expand Up @@ -440,6 +441,7 @@ void load_config(const config &v)
load_attribute(s, "server_message", server_message);
load_attribute(s, "player_joins", player_joins);
load_attribute(s, "player_leaves", player_leaves);
load_attribute(s, "game_created", game_created);
load_attribute(s, "game_user_arrive", game_user_arrive);
load_attribute(s, "game_user_leave", game_user_leave);
load_attribute(s, "ready_for_start", ready_for_start);
Expand Down
2 changes: 1 addition & 1 deletion src/game_config.hpp
Expand Up @@ -167,7 +167,7 @@ namespace game_config
private_message, friend_message,
server_message, player_joins, player_leaves,
game_user_arrive, game_user_leave, ready_for_start,
game_has_begun;
game_has_begun, game_created;
extern const std::string button_press, checkbox_release, slider_adjust,
menu_expand, menu_contract, menu_select;
namespace status {
Expand Down
3 changes: 3 additions & 0 deletions src/game_initialization/lobby_info.cpp
Expand Up @@ -73,6 +73,9 @@ void do_notify(notify_mode mode, const std::string& sender, const std::string& m
case NOTIFY_MESSAGE:
mp_ui_alerts::public_message(true, sender, message);
break;
case NOTIFY_GAME_CREATED:
mp_ui_alerts::game_created(true, sender, message);
break;
default:
break;
}
Expand Down
3 changes: 2 additions & 1 deletion src/game_initialization/lobby_info.hpp
Expand Up @@ -183,7 +183,8 @@ enum notify_mode {
NOTIFY_WHISPER_OTHER_WINDOW,
NOTIFY_LOBBY_JOIN,
NOTIFY_LOBBY_QUIT,
NOTIFY_COUNT
NOTIFY_COUNT,
NOTIFY_GAME_CREATED
};

void do_notify(notify_mode mode, const std::string& sender = "", const std::string& message = "");
Expand Down
4 changes: 4 additions & 0 deletions src/gui/dialogs/multiplayer/lobby.cpp
Expand Up @@ -304,6 +304,10 @@ void mp_lobby::update_gamelist_diff()
const mp::game_info& game = *lobby_info_.games()[i];

if(game.display_status == mp::game_info::NEW) {
// call void do_notify(notify_mode mode, const std::string& sender, const std::string& message)
// sender will be the game_info.scenario (std::string) and message will be game_info.name (std::string)
do_notify(mp::NOTIFY_GAME_CREATED, game.scenario, game.name);

LOG_LB << "Adding game to listbox " << game.id << "\n";

if(list_i != gamelistbox_->get_item_count()) {
Expand Down
25 changes: 22 additions & 3 deletions src/mp_ui_alerts.cpp
Expand Up @@ -51,7 +51,26 @@ bool notif_pref(const std::string& id)
} // end anonymous namespace

// Note: This list must agree with data/gui/.../lobby_sound_options.cfg
const std::vector<std::string> items {"player_joins", "player_leaves", "private_message", "friend_message", "public_message", "server_message", "ready_for_start", "game_has_begun", "turn_changed"};
// @lilinitsy: As of 1.14, it seems the above comment is not true, but someone could check.
const std::vector<std::string> 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(bool is_lobby, const std::string & scenario, const std::string & name)
{
std::string id = "game_created";
if (is_lobby && !lobby_pref(id)) {
return ;
}

if (sound_pref(id)) {
sound::play_UI_sound(game_config::sounds::game_created);
}

if (notif_pref(id)) {
const std::string message = VGETTEXT("A game ($name|, $scenario|) has been created", {{"name", name}, {"scenario", scenario}});
desktop::notifications::send(_("Wesnoth"), message, desktop::notifications::OTHER);
}

}

void player_joins(bool is_lobby)
{
Expand Down Expand Up @@ -176,11 +195,11 @@ bool get_def_pref_sound(const std::string & id) {
}

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"));
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");
return (id == "private_message" || id == "server_message" || id == "game_created");
}


Expand Down
1 change: 1 addition & 0 deletions src/mp_ui_alerts.hpp
Expand Up @@ -27,6 +27,7 @@ namespace mp_ui_alerts {
// Functions called when such an event occurs
void player_joins(bool is_lobby);
void player_leaves(bool is_lobby);
void game_created(bool is_lobby, const std::string & scenario, const std::string & name);
void public_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);
void private_message(bool is_lobby, const std::string & sender, const std::string & message);
Expand Down

0 comments on commit 5902e11

Please sign in to comment.