Project Alice
Loading...
Searching...
No Matches
gui_end_window.hpp
Go to the documentation of this file.
1#pragma once
2#include "dcon_generated.hpp"
6
7namespace ui {
8
9
11public:
12 dcon::nation_id n;
13
14 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
15 if(name == "country_flag") {
16 return make_element_by_type<flag_button>(state, id);
17 } else if(name == "country_flag_overlay") {
18 return make_element_by_type<nation_flag_frame>(state, id);
19 } else if(name == "score") {
20 return make_element_by_type<nation_total_score_text>(state, id);
21 } else if(name == "country_name") {
22 return make_element_by_type<generic_name_text<dcon::nation_id>>(state, id);
23 }
24 return nullptr;
25 }
26
27 message_result get(sys::state& state, Cyto::Any& payload) noexcept override {
28 if(payload.holds_type<dcon::nation_id>()) {
29 payload.emplace<dcon::nation_id>(n);
31 }
32 return window_element_base::get(state, payload);
33 }
34};
35
37 void on_update(sys::state& state) noexcept override {
38 auto n = retrieve<dcon::nation_id>(state, parent);
39 auto amount = state.world.nation_get_stockpiles(n, economy::money);
41 }
42};
43
45 void on_update(sys::state& state) noexcept override {
46 auto n = retrieve<dcon::nation_id>(state, parent);
47 int32_t total = state.world.nation_get_owned_province_count(n);
48 set_text(state, std::to_string(total));
49 }
50};
51
53 void on_update(sys::state& state) noexcept override {
54 auto n = retrieve<dcon::nation_id>(state, parent);
55 int32_t total = 0;
56 for(auto p : state.world.nation_get_province_ownership(n)) {
57 auto frange = p.get_province().get_factory_location();
58 total += int32_t(frange.end() - frange.begin());
59 }
60 set_text(state, std::to_string(total));
61 }
62};
63
65 void on_update(sys::state& state) noexcept override {
66 auto n = retrieve<dcon::nation_id>(state, parent);
67 int32_t total = 0;
68 for(auto p : state.world.nation_get_army_control(n)) {
69 auto frange = p.get_army().get_army_membership();
70 total += int32_t(frange.end() - frange.begin());
71 }
72 set_text(state, std::to_string(total));
73 }
74};
75
77 void on_update(sys::state& state) noexcept override {
78 auto n = retrieve<dcon::nation_id>(state, parent);
79 int32_t total = 0;
80 for(auto p : state.world.nation_get_navy_control(n)) {
81 auto frange = p.get_navy().get_navy_membership();
82 total += int32_t(frange.end() - frange.begin());
83 }
84 set_text(state, std::to_string(total));
85 }
86};
87
89 void on_update(sys::state& state) noexcept override {
90 auto n = retrieve<dcon::nation_id>(state, parent);
91 int32_t total = 0;
92 for(auto t : state.world.in_technology) {
93 if(state.world.nation_get_active_technologies(n, t))
94 ++total;
95 }
96 set_text(state, std::to_string(total));
97 }
98};
99
101 void on_update(sys::state& state) noexcept override {
102 auto n = retrieve<dcon::nation_id>(state, parent);
103 int32_t total = 0;
104 for(auto t : state.world.in_invention) {
105 if(state.world.nation_get_active_inventions(n, t))
106 ++total;
107 }
108 set_text(state, std::to_string(total));
109 }
110};
111
112class end_window_ideologies : public piechart<dcon::ideology_id> {
113protected:
114 void on_update(sys::state& state) noexcept override {
115 distribution.clear();
116
117 auto n = retrieve<dcon::nation_id>(state, parent);
118
119 for(auto pt : state.world.in_ideology) {
120 auto amount = state.world.nation_get_demographics(n, demographics::to_key(state, pt));
121 distribution.emplace_back(pt.id, amount);
122 }
123
125 }
126};
127
129public:
130 void render(sys::state& state, int32_t x, int32_t y) noexcept override {
131 dcon::gfx_object_id gid;
136 }
137 if(gid && flag_texture_handle > 0) {
138 auto& gfx_def = state.ui_defs.gfx[gid];
139 auto mask_handle = ogl::get_texture_handle(state, dcon::texture_id(gfx_def.type_dependent - 1), true);
140 auto& mask_tex = state.open_gl.asset_textures[dcon::texture_id(gfx_def.type_dependent - 1)];
142 float(y), float(base_data.size.x), float(base_data.size.y), flag_texture_handle, mask_handle, base_data.get_rotation(),
143 gfx_def.is_vertically_flipped(),
144 false);
145 }
147 }
148
149 void on_create(sys::state& state) noexcept override {
150 std::swap(base_data.size.x, base_data.size.y);
151 base_data.position.x += int16_t(24);
152 base_data.position.y -= int16_t(25);
154 }
155 dcon::national_identity_id get_current_nation(sys::state& state) noexcept override {
156 auto n = retrieve<dcon::nation_id>(state, parent);
157 return state.world.nation_get_identity_from_identity_holder(n);
158 }
159 void button_action(sys::state& state) noexcept override {
160
161 }
162};
163
165public:
166
167 void render(sys::state& state, int32_t x, int32_t y) noexcept override {
168 dcon::gfx_object_id gid;
173 }
174 if(gid && flag_texture_handle > 0) {
175 auto& gfx_def = state.ui_defs.gfx[gid];
176 auto mask_handle = ogl::get_texture_handle(state, dcon::texture_id(gfx_def.type_dependent - 1), true);
177 auto& mask_tex = state.open_gl.asset_textures[dcon::texture_id(gfx_def.type_dependent - 1)];
179 float(y), float(base_data.size.x), float(base_data.size.y), flag_texture_handle, mask_handle,
180 ui::rotation::r90_right, false, false);
182 float(x), float(y), float(base_data.size.x), float(base_data.size.y),
183 ogl::get_texture_handle(state, gfx_def.primary_texture_handle, gfx_def.is_partially_transparent()),
184 ui::rotation::r90_right, false, false);
185 }
186 }
187
188 void on_create(sys::state& state) noexcept override {
189 std::swap(base_data.size.x, base_data.size.y);
190 base_data.position.x += int16_t(21);
191 base_data.position.y -= int16_t(25);
193 }
194 dcon::national_identity_id get_current_nation(sys::state& state) noexcept override {
195 auto n = retrieve<dcon::nation_id>(state, parent);
196 return state.world.nation_get_identity_from_identity_holder(n);
197 }
198 void button_action(sys::state& state) noexcept override {
199
200 }
201};
202
204public:
205 void button_action(sys::state& state) noexcept override {
206 if(!state.ui_state.r_ledger_window) {
207 auto window = make_element_by_type<ledger_window>(state, "ledger");
208 state.ui_state.r_ledger_window = window.get();
209 state.ui_state.end_screen->add_child_to_front(std::move(window));
210 } else if(state.ui_state.r_ledger_window->is_visible()) {
211 state.ui_state.r_ledger_window->set_visible(state, false);
212 } else {
213 state.ui_state.r_ledger_window->set_visible(state, true);
214 state.ui_state.end_screen->move_child_to_front(state.ui_state.r_ledger_window);
215 }
216 }
217
220 }
221
222 void update_tooltip(sys::state& state, int32_t x, int32_t t, text::columnar_layout& contents) noexcept override {
223 auto box = text::open_layout_box(contents, 0);
224 text::localised_format_box(state, contents, box, std::string_view("m_ledger_button"));
225 text::close_layout_box(contents, box);
226 }
227};
228
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 == "country_flag1") {
233 return make_element_by_type<end_left_flag>(state, id);
234 } else if(name == "country_flag2") {
235 return make_element_by_type<end_right_flag>(state, id);
236 } else if(name == "country_name") {
237 return make_element_by_type<generic_name_text<dcon::nation_id>>(state, id);
238 } else if(name == "country_class") {
239 return make_element_by_type<nation_status_text>(state, id);
240 } else if(name == "total_score") {
241 return make_element_by_type<nation_total_score_text>(state, id);
242 } else if(name == "country_rank") {
243 return make_element_by_type<nation_rank_text>(state, id);
244 } else if(name == "country_prestige") {
245 return make_element_by_type<nation_prestige_text>(state, id);
246 } else if(name == "country_economic") {
247 return make_element_by_type<nation_industry_score_text>(state, id);
248 } else if(name == "country_military") {
249 return make_element_by_type<nation_military_score_text>(state, id);
250 } else if(name == "country_money") {
251 return make_element_by_type<national_treasury_text>(state, id);
252 } else if(name == "population_value") {
253 return make_element_by_type<nation_population_text>(state, id);
254 } else if(name == "provinces_value") {
255 return make_element_by_type<national_province_count>(state, id);
256 } else if(name == "factories_value") {
257 return make_element_by_type<national_factory_count>(state, id);
258 } else if(name == "literacy_value") {
259 return make_element_by_type<nation_literacy_text>(state, id);
260 } else if(name == "army_value") {
261 return make_element_by_type<national_regiment_count>(state, id);
262 } else if(name == "navy_value") {
263 return make_element_by_type<national_ship_count>(state, id);
264 } else if(name == "gov_type_value") {
265 return make_element_by_type<nation_government_type_text>(state, id);
266 } else if(name == "politics_party_icon") {
267 return make_element_by_type<nation_ruling_party_ideology_plupp>(state, id);
268 } else if(name == "party_value") {
269 return make_element_by_type<nation_ruling_party_text>(state, id);
270 } else if(name == "technologies_value") {
271 return make_element_by_type<national_tech_count>(state, id);
272 } else if(name == "inventions_value") {
273 return make_element_by_type<national_invention_count>(state, id);
274 } else if(name == "ideology_chart") {
275 return make_element_by_type<end_window_ideologies>(state, id);
276 } else if(name == "workforce_chart") {
277 return make_element_by_type<nation_picker_poptypes_chart>(state, id);
278 } else if(name == "ledger_button") {
279 return make_element_by_type<invisible_element>(state, id);
280 }
281 return nullptr;
282 }
283};
284
285class end_top_four_gp : public overlapping_listbox_element_base<end_nation_window, dcon::nation_id> {
286public:
287 std::string_view get_row_element_name() override {
288 return "great_power_entry";
289 }
290 void update_subwindow(sys::state& state, end_nation_window& subwindow, dcon::nation_id content) override {
291 subwindow.n = content;
292 }
293 void on_update(sys::state& state) noexcept override {
294 row_contents.clear();
295
296 for(uint32_t i = 0; i < 4; ++i) {
297 if(i < state.great_nations.size())
298 row_contents.push_back(state.great_nations[i].nation);
299 }
300 update(state);
301 }
302};
303
304class end_bottom_four_gp : public overlapping_listbox_element_base<end_nation_window, dcon::nation_id> {
305public:
306 std::string_view get_row_element_name() override {
307 return "great_power_entry";
308 }
309 void update_subwindow(sys::state& state, end_nation_window& subwindow, dcon::nation_id content) override {
310 subwindow.n = content;
311 }
312 void on_update(sys::state& state) noexcept override {
313 row_contents.clear();
314
315 for(uint32_t i = 4; i < 8; ++i) {
316 if(i < state.great_nations.size())
317 row_contents.push_back(state.great_nations[i].nation);
318 }
319 update(state);
320 }
321};
322
323class end_secondary_powers : public overlapping_listbox_element_base<end_nation_window, dcon::nation_id> {
324public:
325 std::string_view get_row_element_name() override {
326 return "second_rank_entry";
327 }
328 void update_subwindow(sys::state& state, end_nation_window& subwindow, dcon::nation_id content) override {
329 subwindow.n = content;
330 }
331 void on_update(sys::state& state) noexcept override {
332 row_contents.clear();
333
334 auto total_num = int32_t(state.defines.colonial_rank - state.defines.great_nations_count);
335
336 for(int32_t i = 0; i < int32_t(state.defines.colonial_rank); ++i) {
337 auto n = state.nations_by_rank[i];
338 if(!nations::is_great_power(state, n) && total_num > 0) {
339 row_contents.push_back(n);
340 --total_num;
341 }
342 }
343 update(state);
344 }
345};
346
348public:
349 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
350 if(name == "year_text") {
351 return make_element_by_type<date_label>(state, id);
352 } else if(name == "great_powers_list") {
353 return make_element_by_type<end_top_four_gp>(state, id);
354 } else if(name == "great_powers_list2") {
355 return make_element_by_type<end_bottom_four_gp>(state, id);
356 } else if(name == "second_rank_list") {
357 return make_element_by_type<end_secondary_powers>(state, id);
358 } else if(name == "exit") {
359 return make_element_by_type<quit_game_button>(state, id);
360 } else if(name == "player_window") {
361 return make_element_by_type<end_window_player>(state, id);
362 }
363 return nullptr;
364 }
365
366 message_result get(sys::state& state, Cyto::Any& payload) noexcept override {
367 if(payload.holds_type<dcon::nation_id>()) {
368 payload.emplace<dcon::nation_id>(state.local_player_nation);
370 }
371 return window_element_base::get(state, payload);
372 }
373};
374
375}
element_base * parent
virtual message_result get(sys::state &state, Cyto::Any &payload) noexcept
bool is_visible() const
element_data base_data
void set_visible(sys::state &state, bool vis)
void update_subwindow(sys::state &state, end_nation_window &subwindow, dcon::nation_id content) override
void on_update(sys::state &state) noexcept override
std::string_view get_row_element_name() override
void on_create(sys::state &state) noexcept override
dcon::national_identity_id get_current_nation(sys::state &state) noexcept override
void button_action(sys::state &state) noexcept override
void render(sys::state &state, int32_t x, int32_t y) 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
dcon::national_identity_id get_current_nation(sys::state &state) noexcept override
void on_create(sys::state &state) noexcept override
void button_action(sys::state &state) noexcept override
void render(sys::state &state, int32_t x, int32_t y) noexcept override
void update_subwindow(sys::state &state, end_nation_window &subwindow, dcon::nation_id content) override
void on_update(sys::state &state) noexcept override
std::string_view get_row_element_name() override
void update_subwindow(sys::state &state, end_nation_window &subwindow, dcon::nation_id content) override
void on_update(sys::state &state) noexcept override
std::string_view get_row_element_name() override
void on_update(sys::state &state) noexcept override
void button_action(sys::state &state) noexcept override
void update_tooltip(sys::state &state, int32_t x, int32_t t, text::columnar_layout &contents) noexcept override
tooltip_behavior has_tooltip(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::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_create(sys::state &state) noexcept override
void render(sys::state &state, int32_t x, int32_t y) noexcept override
void set_text(sys::state &state, std::string const &new_text)
dcon::demographics_key to_key(sys::state const &state, dcon::pop_type_id v)
constexpr dcon::commodity_id money(0)
bool is_great_power(sys::state const &state, dcon::nation_id id)
Definition: nations.cpp:503
void render_masked_rect(sys::state const &state, color_modification enabled, float x, float y, float width, float height, GLuint texture_handle, GLuint mask_texture_handle, ui::rotation r, bool flipped, bool rtl)
void render_textured_rect(sys::state const &state, color_modification enabled, float x, float y, float width, float height, GLuint texture_handle, ui::rotation r, bool flipped, bool rtl)
GLuint get_texture_handle(sys::state &state, dcon::texture_id id, bool keep_data)
Definition: texture.cpp:665
std::string format_money(float num)
Definition: text.cpp:1029
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 close_layout_box(columnar_layout &dest, layout_box &box)
Definition: text.cpp:1807
tooltip_behavior
message_result
ogl::color_modification get_color_modification(bool is_under_mouse, bool is_disabled, bool is_interactable)
uint uint32_t
dcon::gfx_object_id button_image
element_type get_element_type() const
rotation get_rotation() const
union ui::element_data::internal_data data
dcon::gfx_object_id gfx_object
element_base * r_ledger_window
std::unique_ptr< element_base > end_screen
element_base * under_mouse