Project Alice
Loading...
Searching...
No Matches
gui_leaders_window.hpp
Go to the documentation of this file.
1#pragma once
2
4#include "prng.hpp"
6
7namespace ui {
8
10 void on_update(sys::state& state) noexcept override {
11 auto pculture = state.world.nation_get_primary_culture(state.local_player_nation);
12 auto ltype = pculture.get_group_from_culture_group_membership().get_leader();
13 if(ltype) {
14 auto lid = retrieve<dcon::leader_id>(state, parent);
15 auto admiral = state.world.leader_get_is_admiral(lid);
16 if(admiral) {
17 auto arange = ltype.get_admirals();
18 if(arange.size() > 0) {
19 auto rval = rng::get_random(state, uint32_t(state.world.leader_get_since(lid).value), uint32_t(lid.value));
20 auto in_range = rng::reduce(uint32_t(rval), arange.size());
21 base_data.data.image.gfx_object = arange[in_range];
22 }
23 } else {
24 auto grange = ltype.get_generals();
25 if(grange.size() > 0) {
26 auto rval = rng::get_random(state, uint32_t(state.world.leader_get_since(lid).value), uint32_t(lid.value));
27 auto in_range = rng::reduce(uint32_t(rval), grange.size());
28 base_data.data.image.gfx_object = grange[in_range];
29 }
30 }
31 }
32
33 }
34
35 tooltip_behavior has_tooltip(sys::state& state) noexcept override {
37 }
38
39 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
40 display_leader_attributes(state, retrieve<dcon::leader_id>(state, parent), contents, 0);
41 }
42 };
43
44class military_leaders : public listbox_row_element_base<dcon::leader_id> {
45public:
52
53 void on_create(sys::state& state) noexcept override {
56 }
57
58 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
59 if(name == "name") {
60 auto ptr = make_element_by_type<simple_text_element_base>(state, id);
61 leader_name = ptr.get();
62 return ptr;
63 } else if (name == "leader") {
64 return make_element_by_type<leader_portrait>(state, id);
65 } else if(name == "background") {
66 auto ptr = make_element_by_type<simple_text_element_base>(state, id);
67 background = ptr.get();
68 return ptr;
69
70 } else if(name == "personality") {
71 auto ptr = make_element_by_type<simple_text_element_base>(state, id);
72 personality = ptr.get();
73 return ptr;
74
75 } else if(name == "use_leader") {
76 return make_element_by_type<invisible_element>(state, id);
77
78 } else if(name == "army") {
79 auto ptr = make_element_by_type<simple_text_element_base>(state, id);
80 army = ptr.get();
81 return ptr;
82
83 } else if(name == "location") {
84 auto ptr = make_element_by_type<simple_text_element_base>(state, id);
85 location = ptr.get();
86 return ptr;
87 }
88 else if(name == "leader_prestige_bar") {
89 auto ptr = make_element_by_type<leader_prestige_progress_bar<dcon::leader_id>>(state, id);
90 prestige = ptr.get();
91 return ptr;
92 }
93 else if(name == "prestige_bar_frame") {
94 return make_element_by_type<image_element_base>(state, id);
95 }
96 else {
97 return nullptr;
98 }
99 }
100
101 void on_update(sys::state& state) noexcept override {
102 if(leader_name) {
103 auto name_id = state.world.leader_get_name(content);
104 auto name_content = state.to_string_view(name_id);
105 leader_name->set_text(state, std::string(name_content));
106 }
107
108 if(background) {
109 auto background_id = state.world.leader_get_background(content).get_name();
110 auto background_content = text::produce_simple_string(state, background_id);
111 background->set_text(state, background_content);
112 }
113
114 if(personality) {
115 auto personality_id = state.world.leader_get_personality(content).get_name();
116 auto personality_content = text::produce_simple_string(state, personality_id);
117 personality->set_text(state, personality_content);
118 }
119
120 auto army_id = state.world.leader_get_army_from_army_leadership(content);
121 if(army_id.value == 0) {
122 if(army) {
124 }
125 if(location) {
126 location->set_text(state, "");
127 }
128 } else {
129 if(army) {
130 auto army_content = state.to_string_view(state.world.army_get_name(army_id));
131 army->set_text(state, std::string(army_content));
132 //army->set_text(state, "");
133 }
134 if(location) {
135 auto location_content = text::produce_simple_string(state, state.world.province_get_name(state.world.army_location_get_location(state.world.army_get_army_location(army_id))));
136 location->set_text(state, std::string(location_content));
137 }
138 }
139
140 Cyto::Any payload = content;
141 impl_set(state, payload);
142 }
143};
144
145class military_leaders_listbox : public listbox_element_base<military_leaders, dcon::leader_id> {
146protected:
147 std::string_view get_row_element_name() override {
148 return "milview_leader_entry";
149 }
150
151public:
152 void on_update(sys::state& state) noexcept override {
153 row_contents.clear();
154 for(auto const fat_id : state.world.nation_get_leader_loyalty(state.local_player_nation))
155 row_contents.push_back(fat_id.get_leader());
156 update(state);
157 }
158};
159
160template<bool B>
162public:
163 void on_create(sys::state& state) noexcept override {
165 if(B) {
167 } else {
169 }
170 }
171 void on_update(sys::state& state) noexcept override {
172 disabled = !command::can_make_leader(state, state.local_player_nation, B);
173 }
174 void button_action(sys::state& state) noexcept override {
175 command::make_leader(state, state.local_player_nation, B);
176 }
177 void button_right_action(sys::state& state) noexcept override {
178 auto lp = state.world.nation_get_leadership_points(state.local_player_nation);
179 int32_t count = int32_t(lp / state.defines.leader_recruit_cost);
180 for(; count > 0; count--) {
181 command::make_leader(state, state.local_player_nation, B);
182 }
183 }
184
187 }
188 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
189 text::add_line(state, contents, "alice_mw_create_lp", text::variable_type::x, text::fp_two_places{ state.defines.leader_recruit_cost });
190 text::add_line(state, contents, "alice_mw_create_lpb");
191 if(B) {
192 text::add_line(state, contents, "alice_mw_controls_1");
193 } else {
194 text::add_line(state, contents, "alice_mw_controls_2");
195 }
196 }
197};
198
200public:
203 }
204
205 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
206 auto box = text::open_layout_box(contents, 0);
207 text::localised_format_box(state, contents, box, std::string_view("sort_by_prestige"));
208 text::close_layout_box(contents, box);
209 }
210};
211
213public:
216 }
217
218 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
219 auto box = text::open_layout_box(contents, 0);
220 text::localised_format_box(state, contents, box, std::string_view("military_sort_by_type_tooltip"));
221 text::close_layout_box(contents, box);
222 }
223};
224
226public:
229 }
230
231 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
232 auto box = text::open_layout_box(contents, 0);
233 text::localised_format_box(state, contents, box, std::string_view("military_sort_by_name_tooltip"));
234 text::close_layout_box(contents, box);
235 }
236};
237
239public:
242 }
243
244 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
245 auto box = text::open_layout_box(contents, 0);
246 text::localised_format_box(state, contents, box, std::string_view("military_sort_by_assignment_tooltip"));
247 text::close_layout_box(contents, box);
248 }
249};
250
252public:
253 void on_update(sys::state& state) noexcept override {
254 auto general_count = 0;
255 for(auto const fat_id : state.world.nation_get_leader_loyalty(state.local_player_nation)) {
256 auto leader_id = fat_id.get_leader();
257 if(!state.world.leader_get_is_admiral(leader_id)) {
258 ++general_count;
259 }
260 }
261 set_text(state, std::to_string(general_count));
262 }
263};
264
266public:
267 void on_update(sys::state& state) noexcept override {
268 auto admiral_count = 0;
269 for(auto const fat_id : state.world.nation_get_leader_loyalty(state.local_player_nation)) {
270 auto leader_id = fat_id.get_leader();
271 if(state.world.leader_get_is_admiral(leader_id)) {
272 ++admiral_count;
273 }
274 }
275 set_text(state, std::to_string(admiral_count));
276 }
277};
278
280public:
281 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
282 if(name == "sort_leader_prestige") {
283 return make_element_by_type<leaders_sortby_prestige>(state, id);
284 } else if(name == "sort_prestige_icon") {
285 return make_element_by_type<image_element_base>(state, id);
286 } else if(name == "sort_leader_type") {
287 return make_element_by_type<leaders_sortby_type>(state, id);
288 } else if(name == "sort_leader_name") {
289 return make_element_by_type<leaders_sortby_name>(state, id);
290 } else if(name == "sort_leader_army") {
291 return make_element_by_type<leaders_sortby_army>(state, id);
292 } else if(name == "leader_listbox") {
293 return make_element_by_type<military_leaders_listbox>(state, id);
294 } else if(name == "new_general") {
295 return make_element_by_type<military_make_leader_button<true>>(state, id);
296 } else if(name == "new_admiral") {
297 return make_element_by_type<military_make_leader_button<false>>(state, id);
298 } else if(name == "generals") {
299 return make_element_by_type<military_general_count>(state, id);
300 } else if(name == "admirals") {
301 return make_element_by_type<military_admiral_count>(state, id);
302 } else if(name == "auto_create") {
303 return make_element_by_type<invisible_element>(state, id);
304 } else if(name == "auto_create_text") {
305 return make_element_by_type<invisible_element>(state, id);
306 } else if(name == "auto_assign") {
307 return make_element_by_type<invisible_element>(state, id);
308 } else if(name == "auto_assign_text") {
309 return make_element_by_type<invisible_element>(state, id);
310 } else {
311 return nullptr;
312 }
313 }
314};
315
316} // namespace ui
void set_button_text(sys::state &state, std::string const &new_text)
message_result impl_set(sys::state &state, Cyto::Any &payload) noexcept final
element_base * parent
virtual message_result get(sys::state &state, Cyto::Any &payload) noexcept
virtual void on_create(sys::state &state) noexcept
element_data base_data
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
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
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
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
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 on_update(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept override
std::string_view get_row_element_name() override
ui::simple_text_element_base * leader_name
ui::simple_text_element_base * background
std::unique_ptr< element_base > make_child(sys::state &state, std::string_view name, dcon::gui_def_id id) noexcept override
ui::simple_text_element_base * location
void on_create(sys::state &state) noexcept override
ui::simple_text_element_base * personality
ui::simple_text_element_base * army
void on_update(sys::state &state) noexcept override
ui::leader_prestige_progress_bar< dcon::leader_id > * prestige
tooltip_behavior has_tooltip(sys::state &state) noexcept override
void button_right_action(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_create(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept override
void button_action(sys::state &state) noexcept override
void set_text(sys::state &state, std::string const &new_text)
#define B(name, bit)
Definition: cpu.h:216
bool can_make_leader(sys::state &state, dcon::nation_id source, bool general)
Definition: commands.cpp:222
uint32_t reduce(uint32_t value_in, uint32_t upper_bound)
Definition: prng.cpp:46
uint64_t get_random(sys::state const &state, uint32_t value_in)
Definition: prng.cpp:8
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
void display_leader_attributes(sys::state &state, dcon::leader_id lid, text::layout_base &contents, int32_t indent)
tooltip_behavior
@ count
Definition: gui_event.hpp:126
uint uint32_t
union ui::element_data::internal_data data
dcon::gfx_object_id gfx_object