Project Alice
Loading...
Searching...
No Matches
gui_movements_window.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "cyto_any.hpp"
4#include "dcon_generated.hpp"
7#include "gui_graphics.hpp"
8#include "system_state.hpp"
9#include "text.hpp"
10
11namespace ui {
12
14
16public:
18
20 void button_action(sys::state& state) noexcept override {
22 }
23};
24
26public:
27 void on_update(sys::state& state) noexcept override {
28 dcon::nation_id nation_id = retrieve<dcon::nation_id>(state, parent);
29 dcon::movement_id movement_id = retrieve<dcon::movement_id>(state, parent);
30 disabled = !command::can_suppress_movement(state, nation_id, movement_id);
31 }
32
33 void button_action(sys::state& state) noexcept override {
34 dcon::nation_id nation_id = retrieve<dcon::nation_id>(state, parent);
35 dcon::movement_id movement_id = retrieve<dcon::movement_id>(state, parent);
36 command::suppress_movement(state, nation_id, movement_id);
37 }
38};
39
40class movements_option : public listbox_row_element_base<dcon::movement_id> {
41private:
42 flag_button* nationalist_flag = nullptr;
43public:
44 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
45 if(name == "name") {
46 return make_element_by_type<movement_issue_name_text>(state, id);
47 } else if(name == "nationalist_name") {
48 return make_element_by_type<movement_nationalist_name_text>(state, id);
49 } else if(name == "flag") {
50 auto ptr = make_element_by_type<flag_button>(state, id);
51 nationalist_flag = ptr.get();
52 return ptr;
53 } else if(name == "size") {
54 return make_element_by_type<movement_size_text>(state, id);
55 } else if(name == "radical_val") {
56 return make_element_by_type<movement_radicalism_text>(state, id);
57 } else if(name == "suppress_button") {
58 return make_element_by_type<movement_suppress_button>(state, id);
59 } else {
60 return nullptr;
61 }
62 }
63
64 void on_update(sys::state& state) noexcept override {
65 if(state.world.movement_get_associated_independence(content)) {
66 nationalist_flag->set_visible(state, true);
67 } else {
68 nationalist_flag->set_visible(state, false);
69 }
70 }
71
72 message_result get(sys::state& state, Cyto::Any& payload) noexcept override {
73 if(payload.holds_type<dcon::national_identity_id>()) {
74 payload.emplace<dcon::national_identity_id>(state.world.movement_get_associated_independence(content));
76 } else {
78 }
79 }
80};
81
82class movements_list : public listbox_element_base<movements_option, dcon::movement_id> {
83protected:
84 std::string_view get_row_element_name() override {
85 return "movement_entry";
86 }
87
88public:
90
91 void on_update(sys::state& state) noexcept override {
92 row_contents.clear();
93 for(auto movement : state.world.nation_get_movement_within(state.local_player_nation)) {
94 if (movement.get_movement().get_pop_support() >= 1.0f) {
95 row_contents.push_back(movement.get_movement().id);
96 }
97 }
98
99 switch(order) {
101 std::sort(row_contents.begin(), row_contents.end(),
102 [&](dcon::movement_id a, dcon::movement_id b) {
103 auto a_size = state.world.movement_get_pop_support(a);
104 auto b_size = state.world.movement_get_pop_support(b);
105 return a_size > b_size;
106 });
107 break;
109 std::sort(row_contents.begin(), row_contents.end(),
110 [&](dcon::movement_id a, dcon::movement_id b) {
111 auto a_rad = state.world.movement_get_radicalism(a);
112 auto b_rad = state.world.movement_get_radicalism(b);
113 return a_rad > b_rad;
114 });
115 break;
117 std::sort(row_contents.begin(), row_contents.end(),
118 [&](dcon::movement_id a, dcon::movement_id b) {
119 auto fat_a = dcon::fatten(state.world, a);
120 std::string a_name;
121 if(fat_a.get_associated_independence()) {
122 a_name = text::get_name_as_string(state, fat_a.get_associated_independence());
123 } else {
124 a_name = text::produce_simple_string(state, fat_a.get_associated_issue_option().get_movement_name());
125 }
126 auto fat_b = dcon::fatten(state.world, b);
127 std::string b_name;
128 if(fat_b.get_associated_independence()) {
129 b_name = text::get_name_as_string(state, fat_b.get_associated_independence());
130 } else {
131 b_name = text::produce_simple_string(state, fat_b.get_associated_issue_option().get_movement_name());
132 }
133 return a_name < b_name;
134 });
135 break;
136 default:
137 break;
138 }
139 update(state);
140 }
141};
142
144public:
145 std::string get_text(sys::state& state, dcon::rebel_faction_id rebel_faction_id) noexcept override {
146 float total = 0.f;
147 for(auto member : state.world.rebel_faction_get_pop_rebellion_membership(rebel_faction_id)) {
148 total += member.get_pop().get_size();
149 }
150 return text::prettify(int64_t(total));
151 }
152};
153
155public:
156 std::string get_text(sys::state& state, dcon::rebel_faction_id rebel_faction_id) noexcept override {
157 auto count = rebel::get_faction_brigades_active(state, rebel_faction_id);
158 return text::prettify(count);
159 }
160};
161
163public:
164 std::string get_text(sys::state& state, dcon::rebel_faction_id rebel_faction_id) noexcept override {
165 auto count = rebel::get_faction_brigades_ready(state, rebel_faction_id);
166 return text::prettify(count);
167 }
168};
169
171public:
172 std::string get_text(sys::state& state, dcon::rebel_faction_id rebel_faction_id) noexcept override {
173 auto org = rebel::get_faction_organization(state, rebel_faction_id);
174 return text::format_percentage(org, 1);
175 }
176};
177
179public:
180 std::string get_text(sys::state& state, dcon::rebel_faction_id rebel_faction_id) noexcept override {
181 auto risk = rebel::get_faction_revolt_risk(state, rebel_faction_id);
182 return text::format_percentage(risk, 1);
183 }
184};
185
187public:
188 void on_update(sys::state& state) noexcept override {
189 auto reb = retrieve<dcon::rebel_faction_id>(state, parent);
190 set_text(state, rebel::rebel_name(state, reb));
191 }
192
194 return tooltip_behavior::variable_tooltip;
195 }
196
197 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
198 auto n = state.local_player_nation;
199 auto reb = retrieve<dcon::rebel_faction_id>(state, parent);
200 auto type = state.world.rebel_faction_get_type(reb);
201 if(auto k = state.world.rebel_type_get_demands_enforced_trigger(type); k) {
202 text::add_line(state, contents, "alice_rf_demands_enforced_trigger");
203 ui::trigger_description(state, contents, k, trigger::to_generic(n), trigger::to_generic(state.local_player_nation), -1);
204 }
205 if(auto k = state.world.rebel_type_get_demands_enforced_effect(type); k) {
206 text::add_line(state, contents, "alice_rf_demands_enforced_effect");
207 ui::effect_description(state, contents, k, trigger::to_generic(n), trigger::to_generic(state.local_player_nation), -1, uint32_t(state.current_date.value), uint32_t(n.index() ^ (reb.index() << 4)));
208 }
209 auto prov = state.world.nation_get_capital(n);
210 if(auto k = state.world.rebel_type_get_siege_won_trigger(type); k) {
211 text::add_line(state, contents, "alice_rf_siege_won_trigger", text::variable_type::x, prov);
213 }
214 if(auto k = state.world.rebel_type_get_siege_won_effect(type); k) {
215 text::add_line(state, contents, "alice_rf_siege_won_effect", text::variable_type::x, prov);
216 ui::effect_description(state, contents, k, trigger::to_generic(prov), trigger::to_generic(prov), trigger::to_generic(reb), uint32_t(state.current_date.value), uint32_t(reb.index() ^ (reb.index() << 4)));
217 }
218 }
219};
220
222public:
223 void on_update(sys::state& state) noexcept override {
224 auto content = retrieve<dcon::rebel_faction_id>(state, parent);
225 frame = int32_t(state.world.rebel_type_get_icon(state.world.rebel_faction_get_type(content)) - 1);
226 }
227};
228
229class movements_rebel_option : public listbox_row_element_base<dcon::rebel_faction_id> {
230public:
231 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
232 if(name == "size") {
233 return make_element_by_type<rebel_faction_size_text>(state, id);
234 } else if(name == "name") {
235 return make_element_by_type<rebel_faction_name_text>(state, id);
236 } else if(name == "type") {
237 return make_element_by_type<rebel_faction_type_icon>(state, id);
238 } else if(name == "brigades_ready") {
239 return make_element_by_type<rebel_faction_ready_brigade_count_text>(state, id);
240 } else if(name == "brigades_active") {
241 return make_element_by_type<rebel_faction_active_brigade_count_text>(state, id);
242 } else if(name == "organization") {
243 return make_element_by_type<rebel_faction_organization_text>(state, id);
244 } else if(name == "revolt_risk") {
245 return make_element_by_type<rebel_faction_revolt_risk_text>(state, id);
246 } else {
247 return nullptr;
248 }
249 }
250};
251
252class movements_rebel_list : public listbox_element_base<movements_rebel_option, dcon::rebel_faction_id> {
253protected:
254 std::string_view get_row_element_name() override {
255 return "rebel_window";
256 }
257
258public:
259 void on_update(sys::state& state) noexcept override {
260 row_contents.clear();
261 for(auto rebellion : state.world.nation_get_rebellion_within(state.local_player_nation)) {
262 row_contents.push_back(rebellion.get_rebels().id);
263 }
264 update(state);
265 }
266};
267
269private:
270 movements_list* movements_listbox = nullptr;
271
272public:
273 void on_create(sys::state& state) noexcept override {
274 window_element_base::on_create(state);
275 set_visible(state, false);
276 }
277
278 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
279 if(name == "sortby_size_button") {
280 auto ptr = make_element_by_type<movements_sort_order_button>(state, id, movements_sort_order::size);
281 ptr->base_data.position.y -= 1; // Nudge
282 return ptr;
283 } else if(name == "sortby_radical_button") {
284 auto ptr = make_element_by_type<movements_sort_order_button>(state, id, movements_sort_order::radicalism);
285 ptr->base_data.position.y -= 1; // Nudge
286 return ptr;
287 } else if(name == "sortby_name_button") {
288 return make_element_by_type<movements_sort_order_button>(state, id, movements_sort_order::name);
289 } else if(name == "rebel_listbox") {
290 return make_element_by_type<movements_rebel_list>(state, id);
291 } else if(name == "movements_listbox") {
292 auto ptr = make_element_by_type<movements_list>(state, id);
293 movements_listbox = ptr.get();
294 return ptr;
295 } else if(name == "suppression_value") {
296 return make_element_by_type<nation_suppression_points_text>(state, id);
297 } else {
298 return nullptr;
299 }
300 }
301
302 message_result get(sys::state& state, Cyto::Any& payload) noexcept override {
303 if(payload.holds_type<movements_sort_order>()) {
304 auto enum_val = any_cast<movements_sort_order>(payload);
305 movements_listbox->order = enum_val;
306 movements_listbox->impl_on_update(state);
307 return message_result::consumed;
308 } else {
309 return message_result::unseen;
310 }
311 }
312};
313
314} // namespace ui
void impl_on_update(sys::state &state) noexcept override
element_base * parent
virtual message_result get(sys::state &state, Cyto::Any &payload) noexcept
void set_visible(sys::state &state, bool vis)
message_result get(sys::state &state, Cyto::Any &payload) noexcept override
void button_action(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept override
std::string_view get_row_element_name() override
movements_sort_order order
void on_update(sys::state &state) noexcept override
void on_update(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
std::unique_ptr< element_base > make_child(sys::state &state, std::string_view name, dcon::gui_def_id id) noexcept override
void button_action(sys::state &state) noexcept override
movements_sort_order_button(movements_sort_order order)
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_create(sys::state &state) noexcept override
std::string get_text(sys::state &state, dcon::rebel_faction_id rebel_faction_id) noexcept override
tooltip_behavior has_tooltip(sys::state &state) noexcept 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
std::string get_text(sys::state &state, dcon::rebel_faction_id rebel_faction_id) noexcept override
std::string get_text(sys::state &state, dcon::rebel_faction_id rebel_faction_id) noexcept override
std::string get_text(sys::state &state, dcon::rebel_faction_id rebel_faction_id) noexcept override
std::string get_text(sys::state &state, dcon::rebel_faction_id rebel_faction_id) noexcept override
void on_update(sys::state &state) noexcept override
bool can_suppress_movement(sys::state &state, dcon::nation_id source, dcon::movement_id m)
Definition: commands.cpp:1779
pop_satisfaction_wrapper_fat fatten(data_container const &c, pop_satisfaction_wrapper_id id) noexcept
int32_t get_faction_brigades_active(sys::state &state, dcon::rebel_faction_id r)
Definition: rebels.cpp:1016
float get_faction_organization(sys::state &state, dcon::rebel_faction_id r)
Definition: rebels.cpp:1025
std::string rebel_name(sys::state &state, dcon::rebel_faction_id reb)
Definition: rebels.cpp:1274
float get_faction_revolt_risk(sys::state &state, dcon::rebel_faction_id r)
Definition: rebels.cpp:1029
int32_t get_faction_brigades_ready(sys::state &state, dcon::rebel_faction_id r)
Definition: rebels.cpp:1012
std::string prettify(int64_t num)
Definition: text.cpp:762
void add_line(sys::state &state, layout_base &dest, dcon::text_key txt, int32_t indent)
Definition: text.cpp:1899
std::string format_percentage(float num, size_t digits)
Definition: text.cpp:977
int32_t to_generic(dcon::province_id v)
Definition: triggers.hpp:12
void effect_description(sys::state &state, text::layout_base &layout, dcon::effect_key k, int32_t primary_slot, int32_t this_slot, int32_t from_slot, uint32_t r_lo, uint32_t r_hi)
tooltip_behavior
void send(sys::state &state, element_base *parent, T value)
void trigger_description(sys::state &state, text::layout_base &layout, dcon::trigger_key k, int32_t primary_slot=-1, int32_t this_slot=-1, int32_t from_slot=-1)
message_result
uint uint32_t