Project Alice
Loading...
Searching...
No Matches
gui_message_filters_window.hpp
Go to the documentation of this file.
1#pragma once
2
5
6namespace ui {
7
9public:
10 void on_create(sys::state& state) noexcept override {
13 }
14
15 void on_update(sys::state& state) noexcept override {
16 auto content = retrieve<dcon::nation_id>(state, parent);
17 frame = state.world.nation_get_is_interesting(content) ? 1 : 0;
18 }
19
20 void button_action(sys::state& state) noexcept override {
21 auto content = retrieve<dcon::nation_id>(state, parent);
22 auto fat_id = dcon::fatten(state.world, content);
23 fat_id.set_is_interesting(!fat_id.get_is_interesting());
24 if(parent)
26 }
27};
28
30public:
31 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
32 if(name == "entry_bg") {
33 return make_element_by_type<message_filters_country_button>(state, id);
34 } else if(name == "country_name") {
35 return make_element_by_type<generic_name_text<dcon::nation_id>>(state, id);
36 } else {
37 return nullptr;
38 }
39 }
40
41 message_result get(sys::state& state, Cyto::Any& payload) noexcept override {
42 if(payload.holds_type<dcon::nation_id>()) {
43 payload.emplace<dcon::nation_id>(content);
45 }
47 }
48};
49
50class message_filters_country_listbox : public listbox_element_base<message_filters_country_item, dcon::nation_id> {
51protected:
52 std::string_view get_row_element_name() override {
53 return "message_filters_entry";
54 }
55
56public:
57 void on_create(sys::state& state) noexcept override {
60 }
61
62 void on_update(sys::state& state) noexcept override {
63 row_contents.clear();
64 state.world.for_each_nation([&](dcon::nation_id id) {
65 if(state.world.nation_get_owned_province_count(id) != 0)
66 row_contents.push_back(id);
67 });
69 }
70};
71
73 message_filters_country_listbox* country_listbox = nullptr;
74
75public:
76 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
77 if(name == "close_button") {
78 return make_element_by_type<generic_close_button>(state, id);
79 } else if(name == "background") {
80 return make_element_by_type<draggable_target>(state, id);
81 } else if(name == "countries_listbox") {
82 auto ptr = make_element_by_type<message_filters_country_listbox>(state, id);
83 country_listbox = ptr.get();
84 return ptr;
85 } else if(name == "filter_deselect") {
86 auto ptr = make_element_by_type<generic_tab_button<country_list_filter>>(state, id);
88 return ptr;
89 } else if(name == "filter_bestguess") {
90 state.ui_defs.gui[id].data.button.font_handle = text::name_into_font_id(state, "vic_18_black"); // Nudge font
91 auto ptr = make_element_by_type<generic_tab_button<country_list_filter>>(state, id);
93 return ptr;
94 } else if(name == "filter_enemies") {
95 state.ui_defs.gui[id].data.button.font_handle = text::name_into_font_id(state, "vic_18_black"); // Nudge font
96 auto ptr = make_element_by_type<generic_tab_button<country_list_filter>>(state, id);
97 ptr->target = country_list_filter::enemies;
98 return ptr;
99 } else if(name == "filter_allies") {
100 state.ui_defs.gui[id].data.button.font_handle = text::name_into_font_id(state, "vic_18_black"); // Nudge font
101 auto ptr = make_element_by_type<generic_tab_button<country_list_filter>>(state, id);
102 ptr->target = country_list_filter::allies;
103 return ptr;
104 } else if(name == "filter_neighbours") {
105 state.ui_defs.gui[id].data.button.font_handle = text::name_into_font_id(state, "vic_18_black"); // Nudge font
106 auto ptr = make_element_by_type<generic_tab_button<country_list_filter>>(state, id);
107 ptr->target = country_list_filter::neighbors;
108 return ptr;
109 } else if(name == "filter_sphere") {
110 state.ui_defs.gui[id].data.button.font_handle = text::name_into_font_id(state, "vic_18_black"); // Nudge font
111 auto ptr = make_element_by_type<generic_tab_button<country_list_filter>>(state, id);
112 ptr->target = country_list_filter::sphere;
113 return ptr;
114 } else if(name.length() >= 7 && name.substr(0, 7) == "filter_") {
115 auto const filter_name = name.substr(7);
116 state.ui_defs.gui[id].data.button.font_handle = text::name_into_font_id(state, "vic_18_black"); // Nudge font
117 auto ptr = make_element_by_type<generic_tab_button<dcon::modifier_id>>(state, id);
118 ptr->target = ([&]() {
119 dcon::modifier_id filter_mod_id{0};
120 auto k = state.lookup_key(parsers::lowercase_str(filter_name));
121 if(k)
122 state.world.for_each_modifier([&](dcon::modifier_id mod_id) {
123 auto fat_id = dcon::fatten(state.world, mod_id);
124 if(k == fat_id.get_name())
125 filter_mod_id = mod_id;
126 });
127 return filter_mod_id;
128 })();
129 return ptr;
130 } else {
131 return nullptr;
132 }
133 }
134
135 message_result get(sys::state& state, Cyto::Any& payload) noexcept override {
136 if(payload.holds_type<country_list_filter>()) {
137 auto filter = any_cast<country_list_filter>(payload);
138 switch(filter) {
140 state.world.for_each_nation([&](dcon::nation_id id) {
141 auto rel = state.world.get_diplomatic_relation_by_diplomatic_pair(id, state.local_player_nation);
142 if(state.world.diplomatic_relation_get_are_allied(rel) ||
143 military::are_allied_in_war(state, state.local_player_nation, id) ||
144 military::are_at_war(state, state.local_player_nation, id) ||
145 state.world.nation_get_in_sphere_of(id) == state.local_player_nation ||
146 state.world.get_nation_adjacency_by_nation_adjacency_pair(state.local_player_nation, id))
147 state.world.nation_set_is_interesting(id, true);
148 });
149 break;
151 state.world.for_each_nation([&](dcon::nation_id id) { state.world.nation_set_is_interesting(id, false); });
152 break;
153 default:
154 for(const auto n : state.world.in_nation) {
155 if(country_category_filter_check(state, filter, state.local_player_nation, n)) {
156 n.set_is_interesting(true);
157 }
158 }
159 break;
160 }
161 country_listbox->on_update(state);
163 } else if(payload.holds_type<dcon::modifier_id>()) {
164 auto mod_id = any_cast<dcon::modifier_id>(payload);
165 state.world.for_each_nation([&](dcon::nation_id id) {
166 if(state.world.nation_get_owned_province_count(id) != 0) {
167 dcon::nation_fat_id fat_id = dcon::fatten(state.world, id);
168 if(mod_id == fat_id.get_capital().get_continent().id)
169 state.world.nation_set_is_interesting(id, true);
170 }
171 });
172 country_listbox->on_update(state);
174 }
176 }
177};
178
179} // namespace ui
void set_button_text(sys::state &state, std::string const &new_text)
void on_create(sys::state &state) noexcept override
element_base * parent
virtual message_result get(sys::state &state, Cyto::Any &payload) noexcept
virtual void impl_on_update(sys::state &state) noexcept
void on_create(sys::state &state) noexcept override
message_result get(sys::state &state, Cyto::Any &payload) noexcept override
void on_update(sys::state &state) noexcept override
void button_action(sys::state &state) noexcept override
void on_create(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
message_result get(sys::state &state, Cyto::Any &payload) 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
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
pop_satisfaction_wrapper_fat fatten(data_container const &c, pop_satisfaction_wrapper_id id) noexcept
bool are_allied_in_war(sys::state const &state, dcon::nation_id a, dcon::nation_id b)
Definition: military.cpp:486
bool are_at_war(sys::state const &state, dcon::nation_id a, dcon::nation_id b)
Definition: military.cpp:475
std::string lowercase_str(std::string_view sv)
uint16_t name_into_font_id(sys::state &state, std::string_view txt)
Definition: fonts.cpp:93
message_result
bool country_category_filter_check(sys::state &state, country_list_filter filt, dcon::nation_id a, dcon::nation_id b)