Project Alice
Loading...
Searching...
No Matches
gui_message_settings_window.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "constants.hpp"
6
7namespace ui {
8
9inline std::string get_setting_text_key(int32_t type) {
10 static char const* key_str[] = {
11 "amsg_revolt", // revolt
12 "amsg_war_on_nation", // war_on_nation
13 "amsg_war_by_nation", // war_by_nation
14 "amsg_wargoal_added", // wargoal_added
15 "amsg_siegeover_by_nation", // siegeover_by_nation
16 "amsg_siegeover_on_nation", // siegeover_on_nation
17 "amsg_colony_finished", // colony_finished
18 "amsg_reform_gained", // reform_gained
19 "amsg_reform_lost", // reform_lost
20 "amsg_ruling_party_change", // ruling_party_change
21 "amsg_upperhouse", // upperhouse
22 "amsg_electionstart", // electionstart
23 "amsg_electiondone", // electiondone
24 "amsg_breakcountry", // breakcountry
25 "amsg_peace_accepted_from_nation", // peace_accepted_from_nation
26 "amsg_peace_rejected_from_nation", // peace_rejected_from_nation
27 "amsg_peace_accepted_by_nation", // peace_accepted_by_nation
28 "amsg_peace_rejected_by_nation", // peace_rejected_by_nation
29 "amsg_mobilization_start", // mobilization_start
30 "amsg_mobilization_end", // mobilization_end
31 "amsg_factory_complete", // factory_complete
32 "amsg_rr_complete", // rr_complete
33 "amsg_fort_complete", // fort_complete
34 "amsg_naval_base_complete", // naval_base_complete
35 "amsg_province_event", // province_event
36 "amsg_national_event", // national_event
37 "amsg_major_event", // major_event
38 "amsg_invention", // invention
39 "amsg_tech", // tech
40 "amsg_leader_dies", // leader_dies
41 "amsg_land_combat_starts_on_nation", // land_combat_starts_on_nation
42 "amsg_naval_combat_starts_on_nation", // naval_combat_starts_on_nation
43 "amsg_land_combat_starts_by_nation", // land_combat_starts_by_nation
44 "amsg_naval_combat_starts_by_nation", // naval_combat_starts_by_nation
45 "amsg_movement_finishes", // movement_finishes
46 "amsg_decision", // decision
47 "amsg_lose_great_power", // lose_great_power
48 "amsg_become_great_power", // become_great_power
49 "amsg_war_subsidies_start_by_nation", // war_subsidies_start_by_nation
50 "amsg_war_subsidies_start_on_nation", // war_subsidies_start_on_nation
51 "amsg_war_subsidies_end_by_nation", // war_subsidies_end_by_nation
52 "amsg_war_subsidies_end_on_nation", // war_subsidies_end_on_nation
53 "amsg_reparations_start_by_nation", // reparations_start_by_nation
54 "amsg_reparations_start_on_nation", // reparations_start_on_nation
55 "amsg_reparations_end_by_nation", // reparations_end_by_nation
56 "amsg_reparations_end_on_nation", // reparations_end_on_nation
57 "amsg_mil_access_start_by_nation", // mil_access_start_by_nation
58 "amsg_mil_access_start_on_nation", // mil_access_start_on_nation
59 "amsg_mil_access_end_by_nation", // mil_access_end_by_nation
60 "amsg_mil_access_end_on_nation", // mil_access_end_on_nation
61 "amsg_mil_access_declined_by_nation", // mil_access_declined_by_nation
62 "amsg_mil_access_declined_on_nation", // mil_access_declined_on_nation
63 "amsg_alliance_starts", // alliance_starts
64 "amsg_alliance_ends", // alliance_ends
65 "amsg_alliance_declined_by_nation", // alliance_declined_by_nation
66 "amsg_alliance_declined_on_nation", // alliance_declined_on_nation
67 "amsg_ally_called_accepted_by_nation", // ally_called_accepted_by_nation
68 "amsg_ally_called_declined_by_nation", // ally_called_declined_by_nation
69 "amsg_discredit_by_nation", // discredit_by_nation
70 "amsg_ban_by_nation", // ban_by_nation
71 "amsg_expell_by_nation", // expell_by_nation
72 "amsg_discredit_on_nation", // discredit_on_nation
73 "amsg_ban_on_nation", // ban_on_nation
74 "amsg_expell_on_nation", // expell_on_nation
75 "amsg_increase_opinion", // increase_opinion
76 "amsg_decrease_opinion_by_nation", // decrease_opinion_by_nation
77 "amsg_decrease_opinion_on_nation", // decrease_opinion_on_nation
78 "amsg_rem_sphere_by_nation", // rem_sphere_by_nation
79 "amsg_rem_sphere_on_nation", // rem_sphere_on_nation
80 "amsg_removed_from_sphere", // removed_from_sphere
81 "amsg_add_sphere", // add_sphere
82 "amsg_added_to_sphere", // added_to_sphere
83 "amsg_increase_relation_by_nation", // increase_relation_by_nation
84 "amsg_increase_relation_on_nation", // increase_relation_on_nation
85 "amsg_decrease_relation_by_nation", // decrease_relation_by_nation
86 "amsg_decrease_relation_on_nation", // decrease_relation_on_nation
87 "amsg_join_war_by_nation", // join_war_by_nation
88 "amsg_join_war_on_nation", // join_war_on_nation
89 "amsg_gw_unlocked", // gw_unlocked
90 "amsg_war_becomes_great", // war_becomes_great
91 "amsg_cb_detected_on_nation", // cb_detected_on_nation
92 "amsg_cb_detected_by_nation", // cb_detected_by_nation
93 "amsg_crisis_join_offer_accepted_by_nation", // crisis_join_offer_accepted_by_nation
94 "amsg_crisis_join_offer_declined_by_nation", // crisis_join_offer_declined_by_nation
95 "amsg_crisis_join_offer_accepted_from_nation", // crisis_join_offer_accepted_from_nation
96 "amsg_crisis_join_offer_declined_from_nation", // crisis_join_offer_declined_from_nation
97 "amsg_crisis_resolution_accepted", // crisis_resolution_accepted
98 "amsg_crisis_becomes_war", // crisis_becomes_war
99 "amsg_crisis_resolution_declined_from_nation", // crisis_resolution_declined_from_nation
100 "amsg_crisis_starts", // crisis_starts
101 "amsg_crisis_attacker_backer", // crisis_attacker_backer
102 "amsg_crisis_defender_backer", // crisis_defender_backer
103 "amsg_crisis_fizzle", // crisis_fizzle
104 "amsg_war_join_by", // war_join_by
105 "amsg_war_join_on", // war_join_on
106 "amsg_cb_fab_finished", // cb_fab_finished
107 "amsg_cb_fab_cancelled", // cb_fab_cancelled
108 "amsg_crisis_voluntary_join", // crisis_voluntary_join
109 "amsg_army_built", // army_built
110 "amsg_navy_built", // navy_built
111 "amsg_bankruptcy", //bankruptcy
112 "amsg_entered_automatic_alliance",//entered_automatic_alliance
113 "amsg_chat_message",//chat_message
114 };
115 return std::string{key_str[type]};
116}
117
119
120template<int32_t category>
122public:
123 void on_update(sys::state& state) noexcept override {
124 auto base_index = retrieve<int32_t>(state, parent);
126 if constexpr(category == 0) {
127 current = state.user_settings.self_message_settings[base_index];
128 } else if constexpr(category == 1) {
129 current = state.user_settings.interesting_message_settings[base_index];
130 } else if constexpr(category == 2) {
131 current = state.user_settings.other_message_settings[base_index];
132 }
133
134 if((current & sys::message_response::pause) != 0) {
135 frame = 3;
136 } else if((current & sys::message_response::popup) != 0) {
137 frame = 2;
138 } else if((current & sys::message_response::log) != 0) {
139 frame = 1;
140 } else if((current & sys::message_response::sound) != 0) {
141 frame = 4;
142 } else {
143 frame = 0;
144 }
145 }
146 void button_action(sys::state& state) noexcept override {
147 auto base_index = retrieve<int32_t>(state, parent);
149 if constexpr(category == 0) {
150 current = state.user_settings.self_message_settings[base_index];
151 } else if constexpr(category == 1) {
152 current = state.user_settings.interesting_message_settings[base_index];
153 } else if constexpr(category == 2) {
154 current = state.user_settings.other_message_settings[base_index];
155 }
156
157 if((current & sys::message_response::pause) != 0) {
159 } else if((current & sys::message_response::popup) != 0) {
161 } else if((current & sys::message_response::log) != 0) {
163 } else if((current & sys::message_response::sound) != 0) {
165 } else {
167 }
168
169 if constexpr(category == 0) {
170 state.user_settings.self_message_settings[base_index] = current;
171 } else if constexpr(category == 1) {
172 state.user_settings.interesting_message_settings[base_index] = current;
173 } else if constexpr(category == 2) {
174 state.user_settings.other_message_settings[base_index] = current;
175 }
176
178 state.game_state_updated.store(true, std::memory_order::release);
179 }
180 void button_right_action(sys::state& state) noexcept override {
181 auto base_index = retrieve<int32_t>(state, parent);
183 if constexpr(category == 0) {
184 current = state.user_settings.self_message_settings[base_index];
185 } else if constexpr(category == 1) {
186 current = state.user_settings.interesting_message_settings[base_index];
187 } else if constexpr(category == 2) {
188 current = state.user_settings.other_message_settings[base_index];
189 }
190
191 if((current & sys::message_response::pause) != 0) {
193 } else if((current & sys::message_response::popup) != 0) {
195 } else if((current & sys::message_response::log) != 0) {
197 } else if((current & sys::message_response::sound) != 0) {
199 } else {
201 }
202
203 if constexpr(category == 0) {
204 state.user_settings.self_message_settings[base_index] = current;
205 } else if constexpr(category == 1) {
206 state.user_settings.interesting_message_settings[base_index] = current;
207 } else if constexpr(category == 2) {
208 state.user_settings.other_message_settings[base_index] = current;
209 }
210
212 state.game_state_updated.store(true, std::memory_order::release);
213 }
216 }
217
218 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
219 auto base_index = retrieve<int32_t>(state, parent);
221 if constexpr(category == 0) {
222 current = state.user_settings.self_message_settings[base_index];
223 } else if constexpr(category == 1) {
224 current = state.user_settings.interesting_message_settings[base_index];
225 } else if constexpr(category == 2) {
226 current = state.user_settings.other_message_settings[base_index];
227 }
228
229 if((current & sys::message_response::pause) != 0) {
230 text::add_line(state, contents, "msg_handling_pause");
231 } else if((current & sys::message_response::popup) != 0) {
232 text::add_line(state, contents, "msg_handling_popup");
233 } else if((current & sys::message_response::log) != 0) {
234 text::add_line(state, contents, "msg_handling_log");
235 } else if((current & sys::message_response::sound) != 0) {
236 text::add_line(state, contents, "msg_handling_sound");
237 } else {
238 text::add_line(state, contents, "msg_handling_ignore");
239 }
240 }
241};
242
244public:
245 void on_update(sys::state& state) noexcept override {
246 auto base_index = retrieve<int32_t>(state, parent);
248 }
249};
250
252public:
253 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
254 if(name == "entry_text") {
255 return make_element_by_type<message_type_name>(state, id);
256 } else if(name == "us_button") {
257 return make_element_by_type<message_handling_buton<0>>(state, id);
258 } else if(name == "interesting_button") {
259 return make_element_by_type<message_handling_buton<1>>(state, id);
260 } else if(name == "other_button") {
261 return make_element_by_type<message_handling_buton<2>>(state, id);
262 } else {
263 return nullptr;
264 }
265 }
266};
267
268class message_settings_listbox : public listbox_element_base<message_settings_item, int32_t> {
269protected:
270 std::string_view get_row_element_name() override {
271 return "alice_message_setting_item";
272 }
273
274public:
275 void on_update(sys::state& state) noexcept override {
276 row_contents.clear();
277 for(uint32_t i = 0; i <= 102; ++i)
278 row_contents.push_back(i);
279 update(state);
280 }
281};
282
283
285public:
286 void button_action(sys::state& state) noexcept override {
288 std::memcpy(state.user_settings.self_message_settings, d.self_message_settings, sizeof(d.self_message_settings));
289 std::memcpy(state.user_settings.other_message_settings, d.other_message_settings, sizeof(d.other_message_settings));
290 std::memcpy(state.user_settings.interesting_message_settings, d.interesting_message_settings, sizeof(d.interesting_message_settings));
292 state.game_state_updated.store(true, std::memory_order::release);
293 }
294};
295
297public:
298 void button_action(sys::state& state) noexcept override {
300 state.user_settings.self_message_settings[i] = sys::message_response::log;
301 state.user_settings.other_message_settings[i] = sys::message_response::ignore;
302 state.user_settings.interesting_message_settings[i] = sys::message_response::ignore;
303 }
305 state.game_state_updated.store(true, std::memory_order::release);
306 }
307};
308
310public:
311 bool is_active(sys::state& state) noexcept override {
312 return state.user_settings.notify_rebels_defeat;
313 }
314 void button_action(sys::state& state) noexcept override {
315 state.user_settings.notify_rebels_defeat = !state.user_settings.notify_rebels_defeat;
316 }
317};
318
320public:
321 bool settings_changed = false;
322
323 void on_create(sys::state& state) noexcept override {
325 set_visible(state, false);
326 }
327
328 void on_hide(sys::state& state) noexcept override {
329 if(settings_changed) {
330 settings_changed = false;
331 state.save_user_settings();
332 }
333 }
334
335 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
336 if(name == "close") {
337 return make_element_by_type<generic_close_button>(state, id);
338 } else if(name == "messagesettings_bg") {
339 return make_element_by_type<opaque_element_base>(state, id);
340 } else if(name == "message_settings_items") {
341 return make_element_by_type<message_settings_listbox>(state, id);
342 } else if(name == "message_reset") {
343 return make_element_by_type<message_preset_reset>(state, id);
344 } else if(name == "message_spectator") {
345 return make_element_by_type<message_preset_ai_only>(state, id);
346 } else if(name == "message_notify_rebels_defeat_checkbox") {
347 return make_element_by_type<message_notify_rebels_defeat>(state, id);
348 } else {
349 return nullptr;
350 }
351 }
352
353 message_result get(sys::state& state, Cyto::Any& payload) noexcept override {
354 if(payload.holds_type<message_setting_changed_notification>()) {
355 settings_changed = true;
357 }
359 }
360};
361
362
364public:
365 void on_update(sys::state& state) noexcept override;
368 }
369 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override;
370};
371
373public:
374 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
375 if(name == "messagelogbutton") {
376 return make_element_by_type<message_log_text>(state, id);
377 } else {
378 return nullptr;
379 }
380 }
381};
382
383class message_log_listbox : public listbox_element_base<message_log_entry, int32_t> {
384protected:
385 std::string_view get_row_element_name() override {
386 return "logtext";
387 }
388
389 bool is_reversed() override {
390 return false;
391 }
392};
393
396};
397
399public:
400 void button_action(sys::state& state) noexcept override {
401 if(state.ui_state.menubar_window)
404 }
405};
406
407template<message_settings_category Filter>
409 static std::string_view get_filter_text_key(message_settings_category f) noexcept {
410 switch(f) {
412 return "messagesettings_all";
414 return "messagesettings_combat";
416 return "messagesettings_diplomacy";
418 return "messagesettings_units";
420 return "messagesettings_provinces";
422 return "messagesettings_events";
424 return "messagesettings_other";
425 default:
426 return "???";
427 }
428 }
429
430public:
431 bool is_active(sys::state& state) noexcept override {
432 if(parent) {
433 Cyto::Any payload = Filter;
434 parent->impl_get(state, payload);
435 return any_cast<bool>(payload);
436 }
437 return false;
438 }
439
440 void button_action(sys::state& state) noexcept override {
442 }
443
446 }
447
448 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
449 auto box = text::open_layout_box(contents, 0);
450 text::localised_format_box(state, contents, box, get_filter_text_key(Filter));
451 text::close_layout_box(contents, box);
452 }
453};
454
456 std::vector<bool> cat_filters;
457 message_log_listbox* log_list = nullptr;
458
459public:
460 std::vector<notification::message> messages;
461
462 void on_create(sys::state& state) noexcept override;
463 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override;
464 void on_update(sys::state& state) noexcept override;
465 message_result get(sys::state& state, Cyto::Any& payload) noexcept override;
466};
467
468#undef MSG_SETTING_LIST
469} // namespace ui
element_base * parent
virtual void impl_on_update(sys::state &state) noexcept
message_result impl_get(sys::state &state, Cyto::Any &payload) noexcept
void set_visible(sys::state &state, bool vis)
void button_action(sys::state &state) noexcept override
tooltip_behavior has_tooltip(sys::state &state) noexcept override
void update_tooltip(sys::state &state, int32_t x, int32_t y, text::columnar_layout &contents) noexcept override
void on_update(sys::state &state) noexcept override
void button_right_action(sys::state &state) noexcept override
void button_action(sys::state &state) noexcept override
void button_action(sys::state &state) noexcept override
std::unique_ptr< element_base > make_child(sys::state &state, std::string_view name, dcon::gui_def_id id) noexcept override
tooltip_behavior has_tooltip(sys::state &state) noexcept override
bool is_active(sys::state &state) noexcept override
void button_action(sys::state &state) noexcept override
void update_tooltip(sys::state &state, int32_t x, int32_t y, text::columnar_layout &contents) noexcept override
std::string_view get_row_element_name() override
void on_update(sys::state &state) noexcept override
void update_tooltip(sys::state &state, int32_t x, int32_t y, text::columnar_layout &contents) noexcept override
tooltip_behavior has_tooltip(sys::state &state) noexcept override
std::vector< notification::message > messages
std::unique_ptr< element_base > make_child(sys::state &state, std::string_view name, dcon::gui_def_id id) noexcept override
message_result get(sys::state &state, Cyto::Any &payload) noexcept override
void on_update(sys::state &state) noexcept override
void on_create(sys::state &state) noexcept override
void button_action(sys::state &state) noexcept override
bool is_active(sys::state &state) noexcept override
void button_action(sys::state &state) noexcept override
void button_action(sys::state &state) noexcept override
std::unique_ptr< element_base > make_child(sys::state &state, std::string_view name, dcon::gui_def_id id) noexcept override
std::string_view get_row_element_name() override
void on_update(sys::state &state) noexcept override
void on_create(sys::state &state) noexcept override
void on_hide(sys::state &state) noexcept override
message_result get(sys::state &state, Cyto::Any &payload) noexcept override
std::unique_ptr< element_base > make_child(sys::state &state, std::string_view name, dcon::gui_def_id id) noexcept override
void on_update(sys::state &state) noexcept override
void set_text(sys::state &state, std::string const &new_text)
void on_create(sys::state &state) noexcept override
constexpr uint8_t standard_popup
Definition: constants.hpp:543
constexpr uint8_t popup
Definition: constants.hpp:537
constexpr uint8_t pause
Definition: constants.hpp:538
constexpr uint8_t log
Definition: constants.hpp:536
constexpr uint8_t standard_log
Definition: constants.hpp:542
constexpr uint8_t standard_pause
Definition: constants.hpp:544
constexpr uint8_t sound
Definition: constants.hpp:539
constexpr uint8_t standard_sound
Definition: constants.hpp:541
constexpr uint8_t ignore
Definition: constants.hpp:535
layout_box open_layout_box(layout_base &dest, int32_t indent)
Definition: text.cpp:1799
void localised_format_box(sys::state &state, layout_base &dest, layout_box &box, std::string_view key, text::substitution_map const &sub)
Definition: text.cpp:1880
void add_line(sys::state &state, layout_base &dest, dcon::text_key txt, int32_t indent)
Definition: text.cpp:1899
std::string produce_simple_string(sys::state const &state, dcon::text_key id)
Definition: text.cpp:617
void close_layout_box(columnar_layout &dest, layout_box &box)
Definition: text.cpp:1807
std::string get_setting_text_key(int32_t type)
tooltip_behavior
void send(sys::state &state, element_base *parent, T value)
@ count
Definition: gui_event.hpp:126
message_result
uint uint32_t
uchar uint8_t
element_base * menubar_window