Move the MP alerts preferences to prefs_list

This commit is contained in:
pentarctagon 2024-06-12 22:09:48 -05:00 committed by Pentarctagon
parent 80fe9ba84d
commit 54ab301343
6 changed files with 555 additions and 176 deletions

View file

@ -34,56 +34,65 @@
namespace gui2::dialogs
{
static toggle_button* setup_pref_toggle_button(const std::string& id, const std::string& type, bool def, window& window)
{
//ensure we have yes / no for the toggle button, so that the preference matches the toggle button for sure.
if (!prefs::get().has_mp_alert_option(id, type)) {
prefs::get().set_mp_alert_option(id, type, def);
}
toggle_button* b = find_widget<toggle_button>(&window, id+"_"+type, false, true);
b->set_value(prefs::get().mp_alert_option(id, type, def));
connect_signal_mouse_left_click(*b, std::bind([b, id, type]() { prefs::get().set_mp_alert_option(id, type, b->get_value_bool()); }));
return b;
/**
* Sets up the toggle buttons for a set of three MP lobby alerts
*
* @param pref_item_sound prefs_list constant for the sound preference
* @param pref_item_notif prefs_list constant for the notification preference
* @param pref_item_lobby prefs_list constant for the lobby preference
*/
#define SETUP_ITEMS(pref_item_sound, pref_item_notif, pref_item_lobby) \
{ \
toggle_button* sound = find_widget<toggle_button>(&window, prefs_list::pref_item_sound, false, true); \
sound->set_value(prefs::get().pref_item_sound()); \
connect_signal_mouse_left_click(*sound, std::bind([sound]() { prefs::get().set_##pref_item_sound(sound->get_value_bool()); })); \
\
toggle_button* notif = find_widget<toggle_button>(&window, prefs_list::pref_item_notif, false, true); \
\
if (!desktop::notifications::available()) { \
notif->set_value(false); \
notif->set_active(false); \
prefs::get().set_##pref_item_notif(false); \
} else { \
notif->set_active(true); \
notif->set_value(prefs::get().pref_item_notif()); \
connect_signal_mouse_left_click(*notif, std::bind([notif]() { prefs::get().set_##pref_item_notif(notif->get_value_bool()); }));\
} \
\
toggle_button* lobby = find_widget<toggle_button>(&window, prefs_list::pref_item_lobby, false, true); \
lobby->set_value(prefs::get().pref_item_lobby()); \
connect_signal_mouse_left_click(*lobby, std::bind([lobby]() { prefs::get().set_##pref_item_lobby(lobby->get_value_bool()); })); \
}
static void setup_item(const std::string& item, window& window)
{
// Set up the sound checkbox
setup_pref_toggle_button(item, "sound", mp::ui_alerts::get_def_pref_sound(item), window);
/**
* Set the defaults on the UI after clearing the preferences.
*
* @param pref_item_sound prefs_list constant for the sound preference
* @param pref_item_notif prefs_list constant for the notification preference
* @param pref_item_lobby prefs_list constant for the lobby preference
*/
#define RESET_DEFAULT(pref_item_sound, pref_item_notif, pref_item_lobby) \
find_widget<toggle_button>(&window, prefs_list::pref_item_sound, false, true)->set_value(prefs::get().pref_item_sound()); \
find_widget<toggle_button>(&window, prefs_list::pref_item_notif, false, true)->set_value(prefs::get().pref_item_notif()); \
find_widget<toggle_button>(&window, prefs_list::pref_item_lobby, false, true)->set_value(prefs::get().pref_item_lobby());
// Set up the notification checkbox
toggle_button* notif = setup_pref_toggle_button(item, "notif", mp::ui_alerts::get_def_pref_notif(item), window);
// Check if desktop notifications are available
if (!desktop::notifications::available()) {
notif->set_value(false);
notif->set_active(false);
prefs::get().set_mp_alert_option(item, "notif", false);
} else {
notif->set_active(true);
}
// Set up the in_lobby checkbox
setup_pref_toggle_button(item, "lobby", mp::ui_alerts::get_def_pref_lobby(item), window);
}
static void set_pref_and_button(const std::string& id, const std::string& type, bool value, window& window)
{
prefs::get().set_mp_alert_option(id, type, value);
toggle_button* button = find_widget<toggle_button>(&window, id+"_"+type, false, true);
button->set_value(value);
}
static void revert_to_default_pref_values(window& window)
{
for (const std::string& i : mp::ui_alerts::items) {
set_pref_and_button(i, "sound", mp::ui_alerts::get_def_pref_sound(i), window);
set_pref_and_button(i, "notif", mp::ui_alerts::get_def_pref_notif(i), window);
set_pref_and_button(i, "lobby", mp::ui_alerts::get_def_pref_lobby(i), window);
}
// clear existing preferences for MP alerts
prefs::get().clear_mp_alert_prefs();
// each preference knows its own default, so after clearing you get the default by just using the getter
RESET_DEFAULT(player_joins_sound, player_joins_notif, player_joins_lobby)
RESET_DEFAULT(player_leaves_sound, player_leaves_notif, player_leaves_lobby)
RESET_DEFAULT(private_message_sound, private_message_notif, private_message_lobby)
RESET_DEFAULT(friend_message_sound, friend_message_notif, friend_message_lobby)
RESET_DEFAULT(public_message_sound, public_message_notif, public_message_lobby)
RESET_DEFAULT(server_message_sound, server_message_notif, server_message_lobby)
RESET_DEFAULT(ready_for_start_sound, ready_for_start_notif, ready_for_start_lobby)
RESET_DEFAULT(game_has_begun_sound, game_has_begun_notif, game_has_begun_lobby)
RESET_DEFAULT(turn_changed_notif, turn_changed_notif, turn_changed_lobby)
RESET_DEFAULT(game_created_sound, game_created_notif, game_created_lobby)
}
REGISTER_DIALOG(mp_alerts_options)
@ -95,9 +104,16 @@ mp_alerts_options::mp_alerts_options()
void mp_alerts_options::pre_show(window& window)
{
for (const std::string& i : mp::ui_alerts::items) {
setup_item(i, window);
}
SETUP_ITEMS(player_joins_sound, player_joins_notif, player_joins_lobby)
SETUP_ITEMS(player_leaves_sound, player_leaves_notif, player_leaves_lobby)
SETUP_ITEMS(private_message_sound, private_message_notif, private_message_lobby)
SETUP_ITEMS(friend_message_sound, friend_message_notif, friend_message_lobby)
SETUP_ITEMS(public_message_sound, public_message_notif, public_message_lobby)
SETUP_ITEMS(server_message_sound, server_message_notif, server_message_lobby)
SETUP_ITEMS(ready_for_start_sound, ready_for_start_notif, ready_for_start_lobby)
SETUP_ITEMS(game_has_begun_sound, game_has_begun_notif, game_has_begun_lobby)
SETUP_ITEMS(turn_changed_notif, turn_changed_notif, turn_changed_lobby)
SETUP_ITEMS(game_created_sound, game_created_notif, game_created_lobby)
if (!desktop::notifications::available()) {
label* nlabel = find_widget<label>(&window, "notification_label", false, true);
@ -105,16 +121,16 @@ void mp_alerts_options::pre_show(window& window)
}
toggle_button* in_lobby;
in_lobby = find_widget<toggle_button>(&window,"ready_for_start_lobby", false, true);
in_lobby = find_widget<toggle_button>(&window, prefs_list::ready_for_start_lobby, false, true);
in_lobby->set_visible(widget::visibility::invisible);
in_lobby = find_widget<toggle_button>(&window,"game_has_begun_lobby", false, true);
in_lobby = find_widget<toggle_button>(&window, prefs_list::game_has_begun_lobby, false, true);
in_lobby->set_visible(widget::visibility::invisible);
in_lobby = find_widget<toggle_button>(&window,"turn_changed_sound", false, true); // If we get a sound for this then don't remove this button
in_lobby = find_widget<toggle_button>(&window, prefs_list::turn_changed_sound, false, true); // If we get a sound for this then don't remove this button
in_lobby->set_visible(widget::visibility::invisible);
in_lobby = find_widget<toggle_button>(&window,"turn_changed_lobby", false, true);
in_lobby = find_widget<toggle_button>(&window, prefs_list::turn_changed_lobby, false, true);
in_lobby->set_visible(widget::visibility::invisible);
button* defaults;

View file

@ -32,48 +32,17 @@
namespace mp::ui_alerts
{
namespace
{
bool lobby_pref(const std::string& id)
{
return prefs::get().mp_alert_option(id, "lobby", get_def_pref_lobby(id));
}
bool sound_pref(const std::string& id)
{
return prefs::get().mp_alert_option(id, "sound", get_def_pref_sound(id));
}
bool notif_pref(const std::string& id)
{
return prefs::get().mp_alert_option(id, "notif", get_def_pref_notif(id));
}
} // end anonymous namespace
const std::vector<std::string> items{
pref_constants::player_joins,
pref_constants::player_leaves,
pref_constants::private_message,
pref_constants::friend_message,
pref_constants::public_message,
pref_constants::server_message,
pref_constants::ready_for_start,
pref_constants::game_has_begun,
pref_constants::turn_changed,
pref_constants::game_created,
};
void game_created(const std::string& scenario, const std::string& name)
{
if(!lobby_pref(pref_constants::game_created)) {
if(!prefs::get().game_created_lobby()) {
return;
}
if(sound_pref(pref_constants::game_created)) {
if(prefs::get().game_created_sound()) {
sound::play_UI_sound(game_config::sounds::game_created);
}
if(notif_pref(pref_constants::game_created)) {
if(prefs::get().game_created_notif()) {
const std::string message = VGETTEXT("A game ($name|, $scenario|) has been created", {{"name", name}, {"scenario", scenario}});
desktop::notifications::send(_("Wesnoth"), message, desktop::notifications::OTHER);
}
@ -81,97 +50,97 @@ void game_created(const std::string& scenario, const std::string& name)
void player_joins(bool is_lobby)
{
if(is_lobby && !lobby_pref(pref_constants::player_joins)) {
if(is_lobby && !prefs::get().player_joins_lobby()) {
return;
}
if(sound_pref(pref_constants::player_joins)) {
if(prefs::get().player_joins_sound()) {
sound::play_UI_sound(game_config::sounds::player_joins);
}
if(notif_pref(pref_constants::player_joins)) {
if(prefs::get().player_joins_notif()) {
desktop::notifications::send(_("Wesnoth"), _("A player has joined"), desktop::notifications::OTHER);
}
}
void player_leaves(bool is_lobby)
{
if(is_lobby && !lobby_pref(pref_constants::player_leaves)) {
if(is_lobby && !prefs::get().player_leaves_lobby()) {
return;
}
if(sound_pref(pref_constants::player_leaves)) {
if(prefs::get().player_leaves_sound()) {
sound::play_UI_sound(game_config::sounds::player_leaves);
}
if(notif_pref(pref_constants::player_leaves)) {
if(prefs::get().player_leaves_notif()) {
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)
{
if(is_lobby && !lobby_pref(pref_constants::public_message)) {
if(is_lobby && !prefs::get().public_message_lobby()) {
return;
}
if(sound_pref(pref_constants::public_message)) {
if(prefs::get().public_message_sound()) {
sound::play_UI_sound(game_config::sounds::public_message);
}
if(notif_pref(pref_constants::public_message)) {
if(prefs::get().public_message_notif()) {
desktop::notifications::send(sender, message, desktop::notifications::CHAT);
}
}
void friend_message(bool is_lobby, const std::string& sender, const std::string& message)
{
if(is_lobby && !lobby_pref(pref_constants::friend_message)) {
if(is_lobby && !prefs::get().friend_message_lobby()) {
return;
}
if(sound_pref(pref_constants::friend_message)) {
if(prefs::get().friend_message_sound()) {
sound::play_UI_sound(game_config::sounds::friend_message);
}
if(notif_pref(pref_constants::friend_message)) {
if(prefs::get().friend_message_notif()) {
desktop::notifications::send(sender, message, desktop::notifications::CHAT);
}
}
void private_message(bool is_lobby, const std::string& sender, const std::string& message)
{
if(is_lobby && !lobby_pref(pref_constants::private_message)) {
if(is_lobby && !prefs::get().private_message_lobby()) {
return;
}
if(sound_pref(pref_constants::private_message)) {
if(prefs::get().private_message_sound()) {
sound::play_UI_sound(game_config::sounds::private_message);
}
if(notif_pref(pref_constants::private_message)) {
if(prefs::get().private_message_notif()) {
desktop::notifications::send(sender, message, desktop::notifications::CHAT);
}
}
void server_message(bool is_lobby, const std::string& sender, const std::string& message)
{
if(is_lobby && !lobby_pref(pref_constants::server_message)) {
if(is_lobby && !prefs::get().server_message_lobby()) {
return;
}
if(sound_pref(pref_constants::server_message)) {
if(prefs::get().server_message_sound()) {
sound::play_UI_sound(game_config::sounds::server_message);
}
if(notif_pref(pref_constants::server_message)) {
if(prefs::get().server_message_notif()) {
desktop::notifications::send(sender, message, desktop::notifications::CHAT);
}
}
void ready_for_start()
{
if(sound_pref(pref_constants::ready_for_start)) {
if(prefs::get().ready_for_start_sound()) {
if(prefs::get().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.
@ -179,50 +148,29 @@ void ready_for_start()
}
}
if(notif_pref(pref_constants::ready_for_start)) {
if(prefs::get().ready_for_start_notif()) {
desktop::notifications::send(_("Wesnoth"), _("Ready to start!"), desktop::notifications::OTHER);
}
}
void game_has_begun()
{
if(sound_pref(pref_constants::game_has_begun)) {
if(prefs::get().game_has_begun_sound()) {
sound::play_UI_sound(game_config::sounds::game_has_begun);
}
if(notif_pref(pref_constants::game_has_begun)) {
if(prefs::get().game_has_begun_notif()) {
desktop::notifications::send(_("Wesnoth"), _("Game has begun!"), desktop::notifications::OTHER);
}
}
void turn_changed(const std::string& player_name)
{
if(notif_pref(pref_constants::turn_changed)) {
if(prefs::get().turn_changed_notif()) {
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 != pref_constants::public_message && id != pref_constants::friend_message);
}
bool get_def_pref_notif(const std::string& id)
{
return (desktop::notifications::available() && (
id == pref_constants::private_message ||
id == pref_constants::ready_for_start ||
id == pref_constants::game_has_begun ||
id == pref_constants::turn_changed ||
id == pref_constants::game_created
));
}
bool get_def_pref_lobby(const std::string& id)
{
return (id == pref_constants::private_message || id == pref_constants::server_message || id == pref_constants::game_created);
}
} // end namespace mp_ui_alerts

View file

@ -37,12 +37,4 @@ namespace mp::ui_alerts {
void game_has_begun();
void turn_changed(const std::string & player);
// Functions to calculate what the default preference should be
bool get_def_pref_sound(const std::string &);
bool get_def_pref_notif(const std::string &);
bool get_def_pref_lobby(const std::string &);
// Note, this list of items must match those ids defined in data/gui/dialogs/mp_alerts_options.cfg
extern const std::vector<std::string> items;
}

View file

@ -22,6 +22,7 @@
#include "preferences/preferences.hpp"
#include "cursor.hpp"
#include "desktop/notifications.hpp"
#include "game_board.hpp"
#include "game_display.hpp"
#include "formula/string_utils.hpp"
@ -1185,7 +1186,7 @@ void prefs::set_selected_achievement_group(const std::string& content_for)
bool prefs::achievement(const std::string& content_for, const std::string& id)
{
for(config& ach : preferences_.child_range("achievements"))
for(config& ach : preferences_.child_range(prefs_list::achievements))
{
if(ach["content_for"].str() == content_for)
{
@ -1198,7 +1199,7 @@ bool prefs::achievement(const std::string& content_for, const std::string& id)
void prefs::set_achievement(const std::string& content_for, const std::string& id)
{
for(config& ach : preferences_.child_range("achievements"))
for(config& ach : preferences_.child_range(prefs_list::achievements))
{
// if achievements already exist for this content and the achievement has not already been set, add it
if(ach["content_for"].str() == content_for)
@ -1222,7 +1223,7 @@ void prefs::set_achievement(const std::string& content_for, const std::string& i
config ach;
ach["content_for"] = content_for;
ach["ids"] = id;
preferences_.add_child("achievements", ach);
preferences_.add_child(prefs_list::achievements, ach);
}
int prefs::progress_achievement(const std::string& content_for, const std::string& id, int limit, int max_progress, int amount)
@ -1232,7 +1233,7 @@ int prefs::progress_achievement(const std::string& content_for, const std::strin
return -1;
}
for(config& ach : preferences_.child_range("achievements"))
for(config& ach : preferences_.child_range(prefs_list::achievements))
{
// if achievements already exist for this content and the achievement has not already been set, add it
if(ach["content_for"].str() == content_for)
@ -1280,7 +1281,7 @@ int prefs::progress_achievement(const std::string& content_for, const std::strin
ach["ids"] = "";
config& child = ach.add_child("in_progress", set_progress);
preferences_.add_child("achievements", ach);
preferences_.add_child(prefs_list::achievements, ach);
return child["progress_at"].to_int();
}
return 0;
@ -1294,7 +1295,7 @@ bool prefs::sub_achievement(const std::string& content_for, const std::string& i
return true;
}
for(config& ach : preferences_.child_range("achievements"))
for(config& ach : preferences_.child_range(prefs_list::achievements))
{
if(ach["content_for"].str() == content_for)
{
@ -1320,7 +1321,7 @@ void prefs::set_sub_achievement(const std::string& content_for, const std::strin
return;
}
for(config& ach : preferences_.child_range("achievements"))
for(config& ach : preferences_.child_range(prefs_list::achievements))
{
// if achievements already exist for this content and the achievement has not already been set, add it
if(ach["content_for"].str() == content_for)
@ -1364,7 +1365,7 @@ void prefs::set_sub_achievement(const std::string& content_for, const std::strin
ach["ids"] = "";
ach.add_child("in_progress", set_progress);
preferences_.add_child("achievements", ach);
preferences_.add_child(prefs_list::achievements, ach);
}
void prefs::set_editor_chosen_addon(const std::string& addon_id)
@ -1377,19 +1378,6 @@ std::string prefs::editor_chosen_addon()
return preferences_[prefs_list::editor_chosen_addon].str();
}
void prefs::set_mp_alert_option(const std::string& id, const std::string& type, bool value)
{
preferences_[id+"_"+type] = value;
}
bool prefs::mp_alert_option(const std::string& id, const std::string& type, bool def)
{
return preferences_[id+"_"+type].to_bool(def);
}
bool prefs::has_mp_alert_option(const std::string& id, const std::string& type)
{
return preferences_.has_attribute(id+"_"+type);
}
void prefs::set_last_cache_cleared_version(const std::string& version)
{
preferences_[prefs_list::_last_cache_cleaned_ver] = version;
@ -2506,6 +2494,290 @@ void prefs::encounter_all_content(const game_board& gameboard_)
encounter_map_terrain(gameboard_.map());
}
bool prefs::player_joins_sound()
{
return preferences_[prefs_list::player_joins_sound].to_bool(true);
}
void prefs::set_player_joins_sound(bool val)
{
preferences_[prefs_list::player_joins_sound] = val;
}
bool prefs::player_joins_notif()
{
return preferences_[prefs_list::player_joins_notif].to_bool(false);
}
void prefs::set_player_joins_notif(bool val)
{
preferences_[prefs_list::player_joins_notif] = val;
}
bool prefs::player_joins_lobby()
{
return preferences_[prefs_list::player_joins_lobby].to_bool(false);
}
void prefs::set_player_joins_lobby(bool val)
{
preferences_[prefs_list::player_joins_lobby] = val;
}
bool prefs::player_leaves_sound()
{
return preferences_[prefs_list::player_leaves_sound].to_bool(true);
}
void prefs::set_player_leaves_sound(bool val)
{
preferences_[prefs_list::player_leaves_sound] = val;
}
bool prefs::player_leaves_notif()
{
return preferences_[prefs_list::player_leaves_notif].to_bool(false);
}
void prefs::set_player_leaves_notif(bool val)
{
preferences_[prefs_list::player_leaves_notif] = val;
}
bool prefs::player_leaves_lobby()
{
return preferences_[prefs_list::player_leaves_lobby].to_bool(false);
}
void prefs::set_player_leaves_lobby(bool val)
{
preferences_[prefs_list::player_leaves_lobby] = val;
}
bool prefs::private_message_sound()
{
return preferences_[prefs_list::private_message_sound].to_bool(true);
}
void prefs::set_private_message_sound(bool val)
{
preferences_[prefs_list::private_message_sound] = val;
}
bool prefs::private_message_notif()
{
return preferences_[prefs_list::private_message_notif].to_bool(desktop::notifications::available());
}
void prefs::set_private_message_notif(bool val)
{
preferences_[prefs_list::private_message_notif] = val;
}
bool prefs::private_message_lobby()
{
return preferences_[prefs_list::private_message_lobby].to_bool(true);
}
void prefs::set_private_message_lobby(bool val)
{
preferences_[prefs_list::private_message_lobby] = val;
}
bool prefs::friend_message_sound()
{
return preferences_[prefs_list::friend_message_sound].to_bool(false);
}
void prefs::set_friend_message_sound(bool val)
{
preferences_[prefs_list::friend_message_sound] = val;
}
bool prefs::friend_message_notif()
{
return preferences_[prefs_list::friend_message_notif].to_bool(false);
}
void prefs::set_friend_message_notif(bool val)
{
preferences_[prefs_list::friend_message_notif] = val;
}
bool prefs::friend_message_lobby()
{
return preferences_[prefs_list::friend_message_lobby].to_bool(false);
}
void prefs::set_friend_message_lobby(bool val)
{
preferences_[prefs_list::friend_message_lobby] = val;
}
bool prefs::public_message_sound()
{
return preferences_[prefs_list::public_message_sound].to_bool(false);
}
void prefs::set_public_message_sound(bool val)
{
preferences_[prefs_list::public_message_sound] = val;
}
bool prefs::public_message_notif()
{
return preferences_[prefs_list::public_message_notif].to_bool(false);
}
void prefs::set_public_message_notif(bool val)
{
preferences_[prefs_list::public_message_notif] = val;
}
bool prefs::public_message_lobby()
{
return preferences_[prefs_list::public_message_lobby].to_bool(false);
}
void prefs::set_public_message_lobby(bool val)
{
preferences_[prefs_list::public_message_lobby] = val;
}
bool prefs::server_message_sound()
{
return preferences_[prefs_list::server_message_sound].to_bool(true);
}
void prefs::set_server_message_sound(bool val)
{
preferences_[prefs_list::server_message_sound] = val;
}
bool prefs::server_message_notif()
{
return preferences_[prefs_list::server_message_notif].to_bool(false);
}
void prefs::set_server_message_notif(bool val)
{
preferences_[prefs_list::server_message_notif] = val;
}
bool prefs::server_message_lobby()
{
return preferences_[prefs_list::server_message_lobby].to_bool(true);
}
void prefs::set_server_message_lobby(bool val)
{
preferences_[prefs_list::server_message_lobby] = val;
}
bool prefs::ready_for_start_sound()
{
return preferences_[prefs_list::ready_for_start_sound].to_bool(true);
}
void prefs::set_ready_for_start_sound(bool val)
{
preferences_[prefs_list::ready_for_start_sound] = val;
}
bool prefs::ready_for_start_notif()
{
return preferences_[prefs_list::ready_for_start_notif].to_bool(desktop::notifications::available());
}
void prefs::set_ready_for_start_notif(bool val)
{
preferences_[prefs_list::ready_for_start_notif] = val;
}
bool prefs::ready_for_start_lobby()
{
return preferences_[prefs_list::ready_for_start_lobby].to_bool(false);
}
void prefs::set_ready_for_start_lobby(bool val)
{
preferences_[prefs_list::ready_for_start_lobby] = val;
}
bool prefs::game_has_begun_sound()
{
return preferences_[prefs_list::game_has_begun_sound].to_bool(true);
}
void prefs::set_game_has_begun_sound(bool val)
{
preferences_[prefs_list::game_has_begun_sound] = val;
}
bool prefs::game_has_begun_notif()
{
return preferences_[prefs_list::game_has_begun_notif].to_bool(desktop::notifications::available());
}
void prefs::set_game_has_begun_notif(bool val)
{
preferences_[prefs_list::game_has_begun_notif] = val;
}
bool prefs::game_has_begun_lobby()
{
return preferences_[prefs_list::game_has_begun_lobby].to_bool(false);
}
void prefs::set_game_has_begun_lobby(bool val)
{
preferences_[prefs_list::game_has_begun_lobby] = val;
}
bool prefs::turn_changed_sound()
{
return preferences_[prefs_list::turn_changed_sound].to_bool(true);
}
void prefs::set_turn_changed_sound(bool val)
{
preferences_[prefs_list::turn_changed_sound] = val;
}
bool prefs::turn_changed_notif()
{
return preferences_[prefs_list::turn_changed_notif].to_bool(desktop::notifications::available());
}
void prefs::set_turn_changed_notif(bool val)
{
preferences_[prefs_list::turn_changed_notif] = val;
}
bool prefs::turn_changed_lobby()
{
return preferences_[prefs_list::turn_changed_lobby].to_bool(false);
}
void prefs::set_turn_changed_lobby(bool val)
{
preferences_[prefs_list::turn_changed_lobby] = val;
}
bool prefs::game_created_sound()
{
return preferences_[prefs_list::game_created_sound].to_bool(true);
}
void prefs::set_game_created_sound(bool val)
{
preferences_[prefs_list::game_created_sound] = val;
}
bool prefs::game_created_notif()
{
return preferences_[prefs_list::game_created_notif].to_bool(desktop::notifications::available());
}
void prefs::set_game_created_notif(bool val)
{
preferences_[prefs_list::game_created_notif] = val;
}
bool prefs::game_created_lobby()
{
return preferences_[prefs_list::game_created_lobby].to_bool(true);
}
void prefs::set_game_created_lobby(bool val)
{
preferences_[prefs_list::game_created_lobby] = val;
}
void prefs::clear_mp_alert_prefs()
{
erase(prefs_list::player_joins_sound);
erase(prefs_list::player_joins_notif);
erase(prefs_list::player_joins_lobby);
erase(prefs_list::player_leaves_sound);
erase(prefs_list::player_leaves_notif);
erase(prefs_list::player_leaves_lobby);
erase(prefs_list::private_message_sound);
erase(prefs_list::private_message_notif);
erase(prefs_list::private_message_lobby);
erase(prefs_list::friend_message_sound);
erase(prefs_list::friend_message_notif);
erase(prefs_list::friend_message_lobby);
erase(prefs_list::public_message_sound);
erase(prefs_list::public_message_notif);
erase(prefs_list::public_message_lobby);
erase(prefs_list::server_message_sound);
erase(prefs_list::server_message_notif);
erase(prefs_list::server_message_lobby);
erase(prefs_list::ready_for_start_sound);
erase(prefs_list::ready_for_start_notif);
erase(prefs_list::ready_for_start_lobby);
erase(prefs_list::game_has_begun_sound);
erase(prefs_list::game_has_begun_notif);
erase(prefs_list::game_has_begun_lobby);
erase(prefs_list::turn_changed_sound);
erase(prefs_list::turn_changed_notif);
erase(prefs_list::turn_changed_lobby);
erase(prefs_list::game_created_sound);
erase(prefs_list::game_created_notif);
erase(prefs_list::game_created_lobby);
}
std::string prefs::get_system_username()
{
std::string res;

View file

@ -59,19 +59,6 @@ const int INFINITE_AUTO_SAVES = 61;
const std::string default_addons_server = "add-ons.wesnoth.org";
// preferences for MP alerts
// all listed here have three variants with the suffixes: _lobby, _sound, _notif
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";
enum class lobby_joins { show_none, show_friends, show_all };
enum PREFERENCE_VIEW { VIEW_DEFAULT, VIEW_FRIENDS };
@ -478,10 +465,6 @@ class prefs
*/
std::string editor_chosen_addon();
void set_mp_alert_option(const std::string& id, const std::string& type, bool value);
bool mp_alert_option(const std::string& id, const std::string& type, bool def = false);
bool has_mp_alert_option(const std::string& id, const std::string& type);
void set_last_cache_cleared_version(const std::string& version);
std::string last_cache_cleared_version();
@ -730,6 +713,78 @@ class prefs
// Calls all of the above functions on the current game board
void encounter_all_content(const game_board& gb);
bool player_joins_sound();
void set_player_joins_sound(bool val);
bool player_joins_lobby();
void set_player_joins_lobby(bool val);
bool player_joins_notif();
void set_player_joins_notif(bool val);
bool player_leaves_sound();
void set_player_leaves_sound(bool val);
bool player_leaves_lobby();
void set_player_leaves_lobby(bool val);
bool player_leaves_notif();
void set_player_leaves_notif(bool val);
bool private_message_sound();
void set_private_message_sound(bool val);
bool private_message_lobby();
void set_private_message_lobby(bool val);
bool private_message_notif();
void set_private_message_notif(bool val);
bool friend_message_sound();
void set_friend_message_sound(bool val);
bool friend_message_lobby();
void set_friend_message_lobby(bool val);
bool friend_message_notif();
void set_friend_message_notif(bool val);
bool public_message_sound();
void set_public_message_sound(bool val);
bool public_message_lobby();
void set_public_message_lobby(bool val);
bool public_message_notif();
void set_public_message_notif(bool val);
bool server_message_sound();
void set_server_message_sound(bool val);
bool server_message_lobby();
void set_server_message_lobby(bool val);
bool server_message_notif();
void set_server_message_notif(bool val);
bool ready_for_start_sound();
void set_ready_for_start_sound(bool val);
bool ready_for_start_lobby();
void set_ready_for_start_lobby(bool val);
bool ready_for_start_notif();
void set_ready_for_start_notif(bool val);
bool game_has_begun_sound();
void set_game_has_begun_sound(bool val);
bool game_has_begun_lobby();
void set_game_has_begun_lobby(bool val);
bool game_has_begun_notif();
void set_game_has_begun_notif(bool val);
bool turn_changed_sound();
void set_turn_changed_sound(bool val);
bool turn_changed_lobby();
void set_turn_changed_lobby(bool val);
bool turn_changed_notif();
void set_turn_changed_notif(bool val);
bool game_created_sound();
void set_game_created_sound(bool val);
bool game_created_lobby();
void set_game_created_lobby(bool val);
bool game_created_notif();
void set_game_created_notif(bool val);
void clear_mp_alert_prefs();
bool remember_password();
void set_remember_password(bool remember);

View file

@ -26,6 +26,8 @@ struct preferences_list_defines
//
/** wesnoth version string when cache files were last deleted */
static constexpr const char* const _last_cache_cleaned_ver = "_last_cache_cleaned_ver";
/** achievements completed for add-ons/UMC, are not steam achievements */
static constexpr const char* const achievements = "achievements";
/** the sort direction, ie: ascending */
static constexpr const char* const addon_manager_saved_order_direction = "addon_manager_saved_order_direction";
/** the name of the column in the add-ons manager to use by default to sort results */
@ -270,6 +272,69 @@ struct preferences_list_defines
static constexpr const char* const xresolution = "xresolution";
/** height of the wesnoth window */
static constexpr const char* const yresolution = "yresolution";
//
// MP alert preferences
//
/** whether to play a sound when a player joins the game you're in */
static constexpr const char* const player_joins_sound = "player_joins_sound";
/** whether to show a notification when a player joins the game you're in */
static constexpr const char* const player_joins_notif = "player_joins_notif";
/** whether to show the enabled player join sound or notification in the lobby as well */
static constexpr const char* const player_joins_lobby = "player_joins_lobby";
/** whether to play a sound when a player leaves the game you're in */
static constexpr const char* const player_leaves_sound = "player_leaves_sound";
/** whether to show a notification when a player leaves the game you're in */
static constexpr const char* const player_leaves_notif = "player_leaves_notif";
/** whether to show the enabled player leave sound or notification in the lobby as well */
static constexpr const char* const player_leaves_lobby = "player_leaves_lobby";
/** whether to play a sound when receiving a private message aka whisper */
static constexpr const char* const private_message_sound = "private_message_sound";
/** whether to show a notification when receiving a private message aka whisper */
static constexpr const char* const private_message_notif = "private_message_notif";
/** whether to show the enabled private message aka whisper join sound or notification in the lobby as well */
static constexpr const char* const private_message_lobby = "private_message_lobby";
/** whether to play a sound when a friend messages you while in game */
static constexpr const char* const friend_message_sound = "friend_message_sound";
/** whether to show a notification when a friend messages you while in game */
static constexpr const char* const friend_message_notif = "friend_message_notif";
/** whether to show the enabled friend message sound or notification in the lobby as well */
static constexpr const char* const friend_message_lobby = "friend_message_lobby";
/** whether to play a sound when a public message is sent */
static constexpr const char* const public_message_sound = "public_message_sound";
/** whether to show a notification when a public message is sent */
static constexpr const char* const public_message_notif = "public_message_notif";
/** whether to show the enabled public message sound or notification in the lobby as well */
static constexpr const char* const public_message_lobby = "public_message_lobby";
/** whether to play a sound when a server message is sent */
static constexpr const char* const server_message_sound = "server_message_sound";
/** whether to show a notification when a server message is sent */
static constexpr const char* const server_message_notif = "server_message_notif";
/** whether to show the enabled server message sound or notification in the lobby as well */
static constexpr const char* const server_message_lobby = "server_message_lobby";
/** whether to play a sound when the game is ready to be started */
static constexpr const char* const ready_for_start_sound = "ready_for_start_sound";
/** whether to show a notification when the game is ready to be started */
static constexpr const char* const ready_for_start_notif = "ready_for_start_notif";
/** used to make a UI element invisible in the mp alerts options dialog */
static constexpr const char* const ready_for_start_lobby = "ready_for_start_lobby";
/** whether to play a sound when the game has started */
static constexpr const char* const game_has_begun_sound = "game_has_begun_sound";
/** whether to show a notification when the game has started */
static constexpr const char* const game_has_begun_notif = "game_has_begun_notif";
/** used to make a UI element invisible in the mp alerts options dialog */
static constexpr const char* const game_has_begun_lobby = "game_has_begun_lobby";
/** used to make a UI element invisible in the mp alerts options dialog */
static constexpr const char* const turn_changed_sound = "turn_changed_sound";
/** whether to show a notification when the turn changes */
static constexpr const char* const turn_changed_notif = "turn_changed_notif";
/** used to make a UI element invisible in the mp alerts options dialog */
static constexpr const char* const turn_changed_lobby = "turn_changed_lobby";
/** whether to play a sound when a new game is created */
static constexpr const char* const game_created_sound = "game_created_sound";
/** whether to show a notification when a new game is created */
static constexpr const char* const game_created_notif = "game_created_notif";
/** whether to show the new game creation message sound or notification in the lobby as well */
static constexpr const char* const game_created_lobby = "game_created_lobby";
//
// advanced preferences
@ -314,6 +379,7 @@ struct preferences_list_defines
ENUM_AND_ARRAY(
_last_cache_cleaned_ver,
achievements,
addon_manager_saved_order_direction,
addon_manager_saved_order_name,
alias,
@ -450,7 +516,37 @@ struct preferences_list_defines
show_all_units_in_help,
show_combat,
show_deprecation,
use_twelve_hour_clock_format
use_twelve_hour_clock_format,
player_joins_sound,
player_joins_notif,
player_joins_lobby,
player_leaves_sound,
player_leaves_notif,
player_leaves_lobby,
private_message_sound,
private_message_notif,
private_message_lobby,
friend_message_sound,
friend_message_notif,
friend_message_lobby,
public_message_sound,
public_message_notif,
public_message_lobby,
server_message_sound,
server_message_notif,
server_message_lobby,
ready_for_start_sound,
ready_for_start_notif,
ready_for_start_lobby,
game_has_begun_sound,
game_has_begun_notif,
game_has_begun_lobby,
turn_changed_sound,
turn_changed_notif,
turn_changed_lobby,
game_created_sound,
game_created_notif,
game_created_lobby
)
};
using prefs_list = string_enums::enum_base<preferences_list_defines>;