The Battle for Wesnoth 1.21.0-dev
 
Loading...
Searching...
No Matches
mp_alerts_options.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#define GETTEXT_DOMAIN "wesnoth-lib"
17
19
22#include "gui/widgets/label.hpp"
25
26#include "mp_ui_alerts.hpp"
28
29#include <functional>
30
31#include "gettext.hpp"
32
33namespace gui2::dialogs
34{
35
36/**
37 * Sets up the toggle buttons for a set of three MP lobby alerts
38 *
39 * @param pref_item_sound prefs_list constant for the sound preference
40 * @param pref_item_notif prefs_list constant for the notification preference
41 * @param pref_item_lobby prefs_list constant for the lobby preference
42 */
43#define SETUP_ITEMS(pref_item_sound, pref_item_notif, pref_item_lobby) \
44{ \
45toggle_button* sound = find_widget<toggle_button>(prefs_list::pref_item_sound, false, true); \
46sound->set_value(prefs::get().pref_item_sound()); \
47connect_signal_mouse_left_click(*sound, [sound](auto&&...) { prefs::get().set_##pref_item_sound(sound->get_value_bool()); }); \
48\
49toggle_button* notif = find_widget<toggle_button>(prefs_list::pref_item_notif, false, true); \
50\
51if (!desktop::notifications::available()) { \
52 notif->set_value(false); \
53 notif->set_active(false); \
54 prefs::get().set_##pref_item_notif(false); \
55} else { \
56 notif->set_active(true); \
57 notif->set_value(prefs::get().pref_item_notif()); \
58 connect_signal_mouse_left_click(*notif, [notif](auto&&...) { prefs::get().set_##pref_item_notif(notif->get_value_bool()); });\
59} \
60\
61toggle_button* lobby = find_widget<toggle_button>(prefs_list::pref_item_lobby, false, true); \
62lobby->set_value(prefs::get().pref_item_lobby()); \
63connect_signal_mouse_left_click(*lobby, [lobby](auto&&...) { prefs::get().set_##pref_item_lobby(lobby->get_value_bool()); }); \
64}
65
66/**
67 * Set the defaults on the UI after clearing the preferences.
68 *
69 * @param pref_item_sound prefs_list constant for the sound preference
70 * @param pref_item_notif prefs_list constant for the notification preference
71 * @param pref_item_lobby prefs_list constant for the lobby preference
72 */
73#define RESET_DEFAULT(pref_item_sound, pref_item_notif, pref_item_lobby) \
74window.find_widget<toggle_button>(prefs_list::pref_item_sound).set_value(prefs::get().pref_item_sound()); \
75window.find_widget<toggle_button>(prefs_list::pref_item_notif).set_value(prefs::get().pref_item_notif()); \
76window.find_widget<toggle_button>(prefs_list::pref_item_lobby).set_value(prefs::get().pref_item_lobby());
77
78
80{
81 // clear existing preferences for MP alerts
83
84 // each preference knows its own default, so after clearing you get the default by just using the getter
85 RESET_DEFAULT(player_joins_sound, player_joins_notif, player_joins_lobby)
86 RESET_DEFAULT(player_leaves_sound, player_leaves_notif, player_leaves_lobby)
87 RESET_DEFAULT(private_message_sound, private_message_notif, private_message_lobby)
88 RESET_DEFAULT(friend_message_sound, friend_message_notif, friend_message_lobby)
89 RESET_DEFAULT(public_message_sound, public_message_notif, public_message_lobby)
90 RESET_DEFAULT(server_message_sound, server_message_notif, server_message_lobby)
91 RESET_DEFAULT(ready_for_start_sound, ready_for_start_notif, ready_for_start_lobby)
92 RESET_DEFAULT(game_has_begun_sound, game_has_begun_notif, game_has_begun_lobby)
93 RESET_DEFAULT(turn_changed_notif, turn_changed_notif, turn_changed_lobby)
94 RESET_DEFAULT(game_created_sound, game_created_notif, game_created_lobby)
95}
96
98
100 : modal_dialog(window_id())
101{
102}
103
105{
106 SETUP_ITEMS(player_joins_sound, player_joins_notif, player_joins_lobby)
107 SETUP_ITEMS(player_leaves_sound, player_leaves_notif, player_leaves_lobby)
108 SETUP_ITEMS(private_message_sound, private_message_notif, private_message_lobby)
109 SETUP_ITEMS(friend_message_sound, friend_message_notif, friend_message_lobby)
110 SETUP_ITEMS(public_message_sound, public_message_notif, public_message_lobby)
111 SETUP_ITEMS(server_message_sound, server_message_notif, server_message_lobby)
112 SETUP_ITEMS(ready_for_start_sound, ready_for_start_notif, ready_for_start_lobby)
113 SETUP_ITEMS(game_has_begun_sound, game_has_begun_notif, game_has_begun_lobby)
114 SETUP_ITEMS(turn_changed_notif, turn_changed_notif, turn_changed_lobby)
115 SETUP_ITEMS(game_created_sound, game_created_notif, game_created_lobby)
116
118 label* nlabel = find_widget<label>("notification_label", false, true);
119 nlabel->set_tooltip(_("This build of wesnoth does not include support for desktop notifications, contact your package manager"));
120 }
121
122 toggle_button* in_lobby;
123 in_lobby = find_widget<toggle_button>(prefs_list::ready_for_start_lobby, false, true);
125
126 in_lobby = find_widget<toggle_button>(prefs_list::game_has_begun_lobby, false, true);
128
129 in_lobby = find_widget<toggle_button>(prefs_list::turn_changed_sound, false, true); // If we get a sound for this then don't remove this button
131
132 in_lobby = find_widget<toggle_button>(prefs_list::turn_changed_lobby, false, true);
134
135 button& defaults = find_widget<button>("revert_to_defaults");
136 connect_signal_mouse_left_click(defaults, [this](auto&&...) { revert_to_default_pref_values(*this); });
137}
138
142
143} // namespace dialogs
Simple push button.
Definition button.hpp:36
Abstract base class for all modal dialogs.
virtual void post_show() override
Actions to be taken after the window has been shown.
virtual void pre_show() override
Actions to be taken before showing the window.
void set_tooltip(const t_string &tooltip)
void set_visible(const visibility visible)
Definition widget.cpp:479
@ invisible
The user set the widget invisible, that means:
base class of top level items, the only item which needs to store the final canvases to draw on.
Definition window.hpp:59
static prefs & get()
void clear_mp_alert_prefs()
The most recently selected add-on id from the editor.
static std::string _(const char *str)
Definition gettext.hpp:100
This file contains the window object, this object is a top level container which has the event manage...
#define REGISTER_DIALOG(window_id)
Wrapper for REGISTER_DIALOG2.
#define RESET_DEFAULT(pref_item_sound, pref_item_notif, pref_item_lobby)
Set the defaults on the UI after clearing the preferences.
#define SETUP_ITEMS(pref_item_sound, pref_item_notif, pref_item_lobby)
Sets up the toggle buttons for a set of three MP lobby alerts.
bool available()
Returns whether we were compiled with support for desktop notifications.
static void revert_to_default_pref_values(window &window)