The Battle for Wesnoth  1.19.2+dev
mp_ui_alerts.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 - 2024
3  by Chris Beck <render787@gmail.com>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 /**
17  * This namespace provides handlers which play the sounds / notifications
18  * for various mp server events, depending on the preference configuration.
19  */
20 
21 #include "mp_ui_alerts.hpp"
22 
24 #include "formula/string_utils.hpp"
25 #include "game_config.hpp"
26 #include "gettext.hpp"
28 #include "sound.hpp"
29 
30 #include <string>
31 #include <vector>
32 
33 namespace mp::ui_alerts
34 {
35 void game_created(const std::string& scenario, const std::string& name)
36 {
37  if(!prefs::get().game_created_lobby()) {
38  return;
39  }
40 
41  if(prefs::get().game_created_sound()) {
43  }
44 
45  if(prefs::get().game_created_notif()) {
46  const std::string message = VGETTEXT("A game ($name|, $scenario|) has been created", {{"name", name}, {"scenario", scenario}});
48  }
49 }
50 
51 void player_joins(bool is_lobby)
52 {
53  if(is_lobby && !prefs::get().player_joins_lobby()) {
54  return;
55  }
56 
57  if(prefs::get().player_joins_sound()) {
59  }
60 
61  if(prefs::get().player_joins_notif()) {
62  desktop::notifications::send(_("Wesnoth"), _("A player has joined"), desktop::notifications::OTHER);
63  }
64 }
65 
66 void player_leaves(bool is_lobby)
67 {
68  if(is_lobby && !prefs::get().player_leaves_lobby()) {
69  return;
70  }
71 
72  if(prefs::get().player_leaves_sound()) {
74  }
75 
76  if(prefs::get().player_leaves_notif()) {
77  desktop::notifications::send(_("Wesnoth"), _("A player has left"), desktop::notifications::OTHER);
78  }
79 }
80 
81 void public_message(bool is_lobby, const std::string& sender, const std::string& message)
82 {
83  if(is_lobby && !prefs::get().public_message_lobby()) {
84  return;
85  }
86 
87  if(prefs::get().public_message_sound()) {
89  }
90 
91  if(prefs::get().public_message_notif()) {
93  }
94 }
95 
96 void friend_message(bool is_lobby, const std::string& sender, const std::string& message)
97 {
98  if(is_lobby && !prefs::get().friend_message_lobby()) {
99  return;
100  }
101 
102  if(prefs::get().friend_message_sound()) {
104  }
105 
106  if(prefs::get().friend_message_notif()) {
108  }
109 }
110 
111 void private_message(bool is_lobby, const std::string& sender, const std::string& message)
112 {
113  if(is_lobby && !prefs::get().private_message_lobby()) {
114  return;
115  }
116 
117  if(prefs::get().private_message_sound()) {
119  }
120 
121  if(prefs::get().private_message_notif()) {
123  }
124 }
125 
126 void server_message(bool is_lobby, const std::string& sender, const std::string& message)
127 {
128  if(is_lobby && !prefs::get().server_message_lobby()) {
129  return;
130  }
131 
132  if(prefs::get().server_message_sound()) {
134  }
135 
136  if(prefs::get().server_message_notif()) {
138  }
139 }
140 
142 {
143  if(prefs::get().ready_for_start_sound()) {
144  if(prefs::get().ui_sound_on()) {
145  // this is play_bell instead of play_UI_sound to economize on sound channels. UI only has two
146  // sounds, and turn bell has a dedicated channel.
148  }
149  }
150 
151  if(prefs::get().ready_for_start_notif()) {
152  desktop::notifications::send(_("Wesnoth"), _("Ready to start!"), desktop::notifications::OTHER);
153  }
154 }
155 
157 {
158  if(prefs::get().game_has_begun_sound()) {
160  }
161 
162  if(prefs::get().game_has_begun_notif()) {
163  desktop::notifications::send(_("Wesnoth"), _("Game has begun!"), desktop::notifications::OTHER);
164  }
165 }
166 
167 void turn_changed(const std::string& player_name)
168 {
169  if(prefs::get().turn_changed_notif()) {
170  utils::string_map player;
171  player["name"] = player_name;
172  desktop::notifications::send(_("Turn changed"), VGETTEXT("$name has taken control", player), desktop::notifications::TURN_CHANGED);
173  }
174 }
175 
176 } // end namespace mp_ui_alerts
static prefs & get()
#define VGETTEXT(msgid,...)
Handy wrappers around interpolate_variables_into_string and gettext.
static std::string _(const char *str)
Definition: gettext.hpp:93
void send(const std::string &, const std::string &, type)
Displays a desktop notification message, from owner, of type t.
std::string public_message
std::string private_message
std::string player_leaves
std::string server_message
std::string friend_message
std::string ready_for_start
std::string game_has_begun
std::string game_created
std::string player_joins
static bool ui_sound_on()
This namespace provides handlers which play the sounds / notifications for various mp server events,...
void turn_changed(const std::string &player_name)
void public_message(bool is_lobby, const std::string &sender, const std::string &message)
void game_created(const std::string &scenario, const std::string &name)
void private_message(bool is_lobby, const std::string &sender, const std::string &message)
void player_joins(bool is_lobby)
void game_has_begun()
void friend_message(bool is_lobby, const std::string &sender, const std::string &message)
void ready_for_start()
void server_message(bool is_lobby, const std::string &sender, const std::string &message)
void player_leaves(bool is_lobby)
void play_UI_sound(const std::string &files)
Definition: sound.cpp:1066
void play_bell(const std::string &files)
Definition: sound.cpp:1050
std::map< std::string, t_string > string_map