The Battle for Wesnoth
1.21.0-dev
Loading...
Searching...
No Matches
mp_ui_alerts.cpp
Go to the documentation of this file.
1
/*
2
Copyright (C) 2014 - 2025
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
23
#include "
desktop/notifications.hpp
"
24
#include "
formula/string_utils.hpp
"
25
#include "
game_config.hpp
"
26
#include "
gettext.hpp
"
27
#include "
preferences/preferences.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()) {
42
sound::play_UI_sound
(
game_config::sounds::game_created
);
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}});
47
desktop::notifications::send
(
_
(
"Wesnoth"
),
message
,
desktop::notifications::OTHER
);
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()) {
58
sound::play_UI_sound
(
game_config::sounds::player_joins
);
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()) {
73
sound::play_UI_sound
(
game_config::sounds::player_leaves
);
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()) {
88
sound::play_UI_sound
(
game_config::sounds::public_message
);
89
}
90
91
if
(
prefs::get
().public_message_notif()) {
92
desktop::notifications::send
(sender,
message
,
desktop::notifications::CHAT
);
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()) {
103
sound::play_UI_sound
(
game_config::sounds::friend_message
);
104
}
105
106
if
(
prefs::get
().friend_message_notif()) {
107
desktop::notifications::send
(sender,
message
,
desktop::notifications::CHAT
);
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()) {
118
sound::play_UI_sound
(
game_config::sounds::private_message
);
119
}
120
121
if
(
prefs::get
().private_message_notif()) {
122
desktop::notifications::send
(sender,
message
,
desktop::notifications::CHAT
);
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()) {
133
sound::play_UI_sound
(
game_config::sounds::server_message
);
134
}
135
136
if
(
prefs::get
().server_message_notif()) {
137
desktop::notifications::send
(sender,
message
,
desktop::notifications::CHAT
);
138
}
139
}
140
141
void
ready_for_start
()
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.
147
sound::play_bell
(
game_config::sounds::ready_for_start
);
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
156
void
game_has_begun
()
157
{
158
if
(
prefs::get
().game_has_begun_sound()) {
159
sound::play_UI_sound
(
game_config::sounds::game_has_begun
);
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
prefs::get
static prefs & get()
Definition
preferences.hpp:201
string_utils.hpp
VGETTEXT
#define VGETTEXT(msgid,...)
Handy wrappers around interpolate_variables_into_string and gettext.
Definition
string_utils.hpp:106
game_config.hpp
gettext.hpp
_
static std::string _(const char *str)
Definition
gettext.hpp:100
mp_ui_alerts.hpp
desktop::notifications::CHAT
@ CHAT
Definition
notifications.hpp:24
desktop::notifications::TURN_CHANGED
@ TURN_CHANGED
Definition
notifications.hpp:24
desktop::notifications::OTHER
@ OTHER
Definition
notifications.hpp:24
desktop::notifications::send
void send(const std::string &, const std::string &, type)
Displays a desktop notification message, from owner, of type t.
Definition
notifications.cpp:42
game_config::sounds::public_message
std::string public_message
Definition
game_config.cpp:236
game_config::sounds::private_message
std::string private_message
Definition
game_config.cpp:237
game_config::sounds::player_leaves
std::string player_leaves
Definition
game_config.cpp:241
game_config::sounds::server_message
std::string server_message
Definition
game_config.cpp:239
game_config::sounds::friend_message
std::string friend_message
Definition
game_config.cpp:238
game_config::sounds::ready_for_start
std::string ready_for_start
Definition
game_config.cpp:244
game_config::sounds::game_has_begun
std::string game_has_begun
Definition
game_config.cpp:245
game_config::sounds::game_created
std::string game_created
Definition
game_config.cpp:246
game_config::sounds::player_joins
std::string player_joins
Definition
game_config.cpp:240
mp::ui_alerts
This namespace provides handlers which play the sounds / notifications for various mp server events,...
Definition
mp_ui_alerts.cpp:34
mp::ui_alerts::turn_changed
void turn_changed(const std::string &player_name)
Definition
mp_ui_alerts.cpp:167
mp::ui_alerts::public_message
void public_message(bool is_lobby, const std::string &sender, const std::string &message)
Definition
mp_ui_alerts.cpp:81
mp::ui_alerts::private_message
void private_message(bool is_lobby, const std::string &sender, const std::string &message)
Definition
mp_ui_alerts.cpp:111
mp::ui_alerts::player_joins
void player_joins(bool is_lobby)
Definition
mp_ui_alerts.cpp:51
mp::ui_alerts::game_has_begun
void game_has_begun()
Definition
mp_ui_alerts.cpp:156
mp::ui_alerts::ready_for_start
void ready_for_start()
Definition
mp_ui_alerts.cpp:141
mp::ui_alerts::player_leaves
void player_leaves(bool is_lobby)
Definition
mp_ui_alerts.cpp:66
mp::notify_mode::game_created
@ game_created
mp::notify_mode::message
@ message
mp::notify_mode::friend_message
@ friend_message
mp::notify_mode::server_message
@ server_message
sound::play_UI_sound
void play_UI_sound(const std::string &files)
Definition
sound.cpp:1006
sound::play_bell
void play_bell(const std::string &files)
Definition
sound.cpp:990
utils::string_map
std::map< std::string, t_string > string_map
Definition
string_utils.hpp:35
notifications.hpp
preferences.hpp
sound.hpp
Generated by
1.9.8