Project Alice
Loading...
Searching...
No Matches
gui_naval_combat.hpp
Go to the documentation of this file.
1#pragma once
2
4#include "military.hpp"
5#include "gui_land_combat.hpp"
6
7namespace ui {
8
9
11 dcon::gfx_object_id def;
12
13 void on_update(sys::state& state) noexcept override {
14 if(!def)
16
17 auto b = retrieve<dcon::naval_battle_id>(state, parent);
18 auto lid = state.world.naval_battle_get_admiral_from_attacking_admiral(b);
19
20 if(!lid) {
22 return;
23 }
24
25 auto owner = state.world.leader_get_nation_from_leader_loyalty(lid);
26 auto pculture = state.world.nation_get_primary_culture(owner);
27 auto ltype = pculture.get_group_from_culture_group_membership().get_leader();
28
29 if(ltype) {
30 auto grange = ltype.get_admirals();
31 if(grange.size() > 0) {
32 auto rval = rng::get_random(state, uint32_t(state.world.leader_get_since(lid).value), uint32_t(lid.value));
33 auto in_range = rng::reduce(uint32_t(rval), grange.size());
34 base_data.data.image.gfx_object = grange[in_range];
35 }
36 }
37 }
38
39 tooltip_behavior has_tooltip(sys::state& state) noexcept override {
41 }
42
43 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
44 auto b = retrieve<dcon::naval_battle_id>(state, parent);
45 auto lid = state.world.naval_battle_get_admiral_from_attacking_admiral(b);
46
47 if(lid)
48 display_leader_attributes(state, lid, contents, 0);
49 else
50 text::add_line(state, contents, "no_leader");
51 }
52};
54 dcon::gfx_object_id def;
55
56 void on_update(sys::state& state) noexcept override {
57 if(!def)
59
60 auto b = retrieve<dcon::naval_battle_id>(state, parent);
61 auto lid = state.world.naval_battle_get_admiral_from_defending_admiral(b);
62
63 if(!lid) {
65 return;
66 }
67
68 auto owner = state.world.leader_get_nation_from_leader_loyalty(lid);
69 auto pculture = state.world.nation_get_primary_culture(owner);
70 auto ltype = pculture.get_group_from_culture_group_membership().get_leader();
71
72 if(ltype) {
73 auto grange = ltype.get_admirals();
74 if(grange.size() > 0) {
75 auto rval = rng::get_random(state, uint32_t(state.world.leader_get_since(lid).value), uint32_t(lid.value));
76 auto in_range = rng::reduce(uint32_t(rval), grange.size());
77 base_data.data.image.gfx_object = grange[in_range];
78 }
79 }
80 }
81
82 tooltip_behavior has_tooltip(sys::state& state) noexcept override {
84 }
85
86 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
87 auto b = retrieve<dcon::naval_battle_id>(state, parent);
88 auto lid = state.world.naval_battle_get_admiral_from_defending_admiral(b);
89
90 if(lid)
91 display_leader_attributes(state, lid, contents, 0);
92 else
93 text::add_line(state, contents, "no_leader");
94 }
95};
96
98public:
99 void on_update(sys::state& state) noexcept override {
100 auto b = retrieve<dcon::naval_battle_id>(state, parent);
101 auto lid = state.world.naval_battle_get_admiral_from_attacking_admiral(b);
102
103 if(lid) {
104 auto name = state.to_string_view(state.world.leader_get_name(lid));
105 set_text(state, std::string(name));
106 } else {
107 set_text(state, "");
108 }
109 }
110};
112public:
113 void on_update(sys::state& state) noexcept override {
114 auto b = retrieve<dcon::naval_battle_id>(state, parent);
115 auto lid = state.world.naval_battle_get_admiral_from_defending_admiral(b);
116
117 if(lid) {
118 auto name = state.to_string_view(state.world.leader_get_name(lid));
119 set_text(state, std::string(name));
120 } else {
121 set_text(state, "");
122 }
123 }
124};
125
126
128public:
129
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(4);
153 }
154 dcon::national_identity_id get_current_nation(sys::state& state) noexcept override {
155 auto b = retrieve<dcon::naval_battle_id>(state, parent);
157 return state.world.nation_get_identity_from_identity_holder(n);
158 }
159};
161public:
162 void render(sys::state& state, int32_t x, int32_t y) noexcept override {
163 dcon::gfx_object_id gid;
168 }
169 if(gid && flag_texture_handle > 0) {
170 auto& gfx_def = state.ui_defs.gfx[gid];
171 auto mask_handle = ogl::get_texture_handle(state, dcon::texture_id(gfx_def.type_dependent - 1), true);
172 auto& mask_tex = state.open_gl.asset_textures[dcon::texture_id(gfx_def.type_dependent - 1)];
174 float(y), float(base_data.size.x), float(base_data.size.y), flag_texture_handle, mask_handle, base_data.get_rotation(),
175 gfx_def.is_vertically_flipped(),
176 false);
177 }
179 }
180
181 void on_create(sys::state& state) noexcept override {
182 std::swap(base_data.size.x, base_data.size.y);
183 base_data.position.x += int16_t(4);
185 }
186 dcon::national_identity_id get_current_nation(sys::state& state) noexcept override {
187 auto b = retrieve<dcon::naval_battle_id>(state, parent);
189 return state.world.nation_get_identity_from_identity_holder(n);
190 }
191};
192
193
195public:
196 void on_update(sys::state& state) noexcept override {
197 auto b = retrieve<dcon::naval_battle_id>(state, parent);
198 auto w = state.world.naval_battle_get_war_from_naval_battle_in_war(b);
199 float count = 0.0f;
200 float total = 0.0f;
201 for(auto a : state.world.naval_battle_get_navy_battle_participation(b)) {
202 auto owner = a.get_navy().get_controller_from_navy_control();
203 bool battle_attacker = (military::get_role(state, w, owner) == military::war_role::attacker) == state.world.naval_battle_get_war_attacker_is_attacker(b);
204 if(battle_attacker == false) {
205 for(auto r : a.get_navy().get_navy_membership()) {
206 ++count;
207 total += r.get_ship().get_org();
208 }
209 }
210 }
211 progress = count > 0 ? total / count : 0.0f;
212 }
213};
215public:
216 void on_update(sys::state& state) noexcept override {
217 auto b = retrieve<dcon::naval_battle_id>(state, parent);
218 auto w = state.world.naval_battle_get_war_from_naval_battle_in_war(b);
219 float count = 0.0f;
220 float total = 0.0f;
221 for(auto a : state.world.naval_battle_get_navy_battle_participation(b)) {
222 auto owner = a.get_navy().get_controller_from_navy_control();
223 bool battle_attacker = (military::get_role(state, w, owner) == military::war_role::attacker) == state.world.naval_battle_get_war_attacker_is_attacker(b);
224 if(battle_attacker == false) {
225 for(auto r : a.get_navy().get_navy_membership()) {
226 ++count;
227 total += r.get_ship().get_strength();
228 }
229 }
230 }
231 progress = count > 0 ? total / count : 0.0f;
232 }
233};
235public:
236 void on_update(sys::state& state) noexcept override {
237 auto b = retrieve<dcon::naval_battle_id>(state, parent);
238 auto w = state.world.naval_battle_get_war_from_naval_battle_in_war(b);
239 float count = 0.0f;
240 float total = 0.0f;
241 for(auto a : state.world.naval_battle_get_navy_battle_participation(b)) {
242 auto owner = a.get_navy().get_controller_from_navy_control();
243 bool battle_attacker = (military::get_role(state, w, owner) == military::war_role::attacker) == state.world.naval_battle_get_war_attacker_is_attacker(b);
244 if(battle_attacker == true) {
245 for(auto r : a.get_navy().get_navy_membership()) {
246 ++count;
247 total += r.get_ship().get_org();
248 }
249 }
250 }
251 progress = count > 0 ? total / count : 0.0f;
252 }
253};
255public:
256 void on_update(sys::state& state) noexcept override {
257 auto b = retrieve<dcon::naval_battle_id>(state, parent);
258 auto w = state.world.naval_battle_get_war_from_naval_battle_in_war(b);
259 float count = 0.0f;
260 float total = 0.0f;
261 for(auto a : state.world.naval_battle_get_navy_battle_participation(b)) {
262 auto owner = a.get_navy().get_controller_from_navy_control();
263 bool battle_attacker = (military::get_role(state, w, owner) == military::war_role::attacker) == state.world.naval_battle_get_war_attacker_is_attacker(b);
264 if(battle_attacker == true) {
265 for(auto r : a.get_navy().get_navy_membership()) {
266 ++count;
267 total += r.get_ship().get_strength();
268 }
269 }
270 }
271 progress = count > 0 ? total / count : 0.0f;
272 }
273};
274
275
277public:
278 void on_update(sys::state& state) noexcept override {
279 auto b = retrieve<dcon::naval_battle_id>(state, parent);
280 auto w = state.world.naval_battle_get_war_from_naval_battle_in_war(b);
281 float count = 0.0f;
282 float total = 0.0f;
283 for(auto a : state.world.naval_battle_get_navy_battle_participation(b)) {
284 auto owner = a.get_navy().get_controller_from_navy_control();
285 bool battle_attacker = (military::get_role(state, w, owner) == military::war_role::attacker) == state.world.naval_battle_get_war_attacker_is_attacker(b);
286 if(battle_attacker == false) {
287 for(auto r : a.get_navy().get_navy_membership()) {
288 ++count;
289 total += r.get_ship().get_org();
290 }
291 }
292 }
293 set_text(state, text::format_percentage(count > 0 ? total / count : 0.0f, 1));
294 }
295};
297public:
298 void on_update(sys::state& state) noexcept override {
299 auto b = retrieve<dcon::naval_battle_id>(state, parent);
300 auto w = state.world.naval_battle_get_war_from_naval_battle_in_war(b);
301 float count = 0.0f;
302 float total = 0.0f;
303 for(auto a : state.world.naval_battle_get_navy_battle_participation(b)) {
304 auto owner = a.get_navy().get_controller_from_navy_control();
305 bool battle_attacker = (military::get_role(state, w, owner) == military::war_role::attacker) == state.world.naval_battle_get_war_attacker_is_attacker(b);
306 if(battle_attacker == false) {
307 for(auto r : a.get_navy().get_navy_membership()) {
308 ++count;
309 total += r.get_ship().get_strength();
310 }
311 }
312 }
313 set_text(state, text::format_percentage(count > 0 ? total / count : 0.0f, 1));
314 }
315};
317public:
318 void on_update(sys::state& state) noexcept override {
319 auto b = retrieve<dcon::naval_battle_id>(state, parent);
320 auto w = state.world.naval_battle_get_war_from_naval_battle_in_war(b);
321 float count = 0.0f;
322 float total = 0.0f;
323 for(auto a : state.world.naval_battle_get_navy_battle_participation(b)) {
324 auto owner = a.get_navy().get_controller_from_navy_control();
325 bool battle_attacker = (military::get_role(state, w, owner) == military::war_role::attacker) == state.world.naval_battle_get_war_attacker_is_attacker(b);
326 if(battle_attacker == true) {
327 for(auto r : a.get_navy().get_navy_membership()) {
328 ++count;
329 total += r.get_ship().get_org();
330 }
331 }
332 }
333 set_text(state, text::format_percentage(count > 0 ? total / count : 0.0f, 1));
334 }
335};
337public:
338 void on_update(sys::state& state) noexcept override {
339 auto b = retrieve<dcon::naval_battle_id>(state, parent);
340 auto w = state.world.naval_battle_get_war_from_naval_battle_in_war(b);
341 float count = 0.0f;
342 float total = 0.0f;
343 for(auto a : state.world.naval_battle_get_navy_battle_participation(b)) {
344 auto owner = a.get_navy().get_controller_from_navy_control();
345 bool battle_attacker = (military::get_role(state, w, owner) == military::war_role::attacker) == state.world.naval_battle_get_war_attacker_is_attacker(b);
346 if(battle_attacker == true) {
347 for(auto r : a.get_navy().get_navy_membership()) {
348 ++count;
349 total += r.get_ship().get_strength();
350 }
351 }
352 }
353 set_text(state, text::format_percentage(count > 0 ? total / count : 0.0f, 1));
354 }
355};
356
358public:
359 void on_update(sys::state& state) noexcept override {
360 auto b = retrieve<dcon::naval_battle_id>(state, parent);
361 auto w = state.world.naval_battle_get_war_from_naval_battle_in_war(b);
362 int32_t count = 0;
363 for(auto a : state.world.naval_battle_get_navy_battle_participation(b)) {
364 auto owner = a.get_navy().get_controller_from_navy_control();
365 bool battle_attacker = (military::get_role(state, w, owner) == military::war_role::attacker) == state.world.naval_battle_get_war_attacker_is_attacker(b);
366 if(battle_attacker == false) {
367 for(auto r : a.get_navy().get_navy_membership()) {
368 auto type = r.get_ship().get_type();
369 if(type && state.military_definitions.unit_base_definitions[type].type == military::unit_type::big_ship)
370 ++count;
371 }
372 }
373 }
375 }
376};
378public:
379 void on_update(sys::state& state) noexcept override {
380 auto b = retrieve<dcon::naval_battle_id>(state, parent);
381 auto w = state.world.naval_battle_get_war_from_naval_battle_in_war(b);
382 int32_t count = 0;
383 for(auto a : state.world.naval_battle_get_navy_battle_participation(b)) {
384 auto owner = a.get_navy().get_controller_from_navy_control();
385 bool battle_attacker = (military::get_role(state, w, owner) == military::war_role::attacker) == state.world.naval_battle_get_war_attacker_is_attacker(b);
386 if(battle_attacker == false) {
387 for(auto r : a.get_navy().get_navy_membership()) {
388 auto type = r.get_ship().get_type();
389 if(type && state.military_definitions.unit_base_definitions[type].type == military::unit_type::light_ship)
390 ++count;
391 }
392 }
393 }
395 }
396};
398public:
399 void on_update(sys::state& state) noexcept override {
400 auto b = retrieve<dcon::naval_battle_id>(state, parent);
401 auto w = state.world.naval_battle_get_war_from_naval_battle_in_war(b);
402 int32_t count = 0;
403 for(auto a : state.world.naval_battle_get_navy_battle_participation(b)) {
404 auto owner = a.get_navy().get_controller_from_navy_control();
405 bool battle_attacker = (military::get_role(state, w, owner) == military::war_role::attacker) == state.world.naval_battle_get_war_attacker_is_attacker(b);
406 if(battle_attacker == false) {
407 for(auto r : a.get_navy().get_navy_membership()) {
408 auto type = r.get_ship().get_type();
409 if(type && state.military_definitions.unit_base_definitions[type].type == military::unit_type::transport)
410 ++count;
411 }
412 }
413 }
415 }
416};
418public:
419 void on_update(sys::state& state) noexcept override {
420 auto b = retrieve<dcon::naval_battle_id>(state, parent);
421 auto w = state.world.naval_battle_get_war_from_naval_battle_in_war(b);
422 int32_t count = 0;
423 for(auto a : state.world.naval_battle_get_navy_battle_participation(b)) {
424 auto owner = a.get_navy().get_controller_from_navy_control();
425 bool battle_attacker = (military::get_role(state, w, owner) == military::war_role::attacker) == state.world.naval_battle_get_war_attacker_is_attacker(b);
426 if(battle_attacker == true) {
427 for(auto r : a.get_navy().get_navy_membership()) {
428 auto type = r.get_ship().get_type();
429 if(type && state.military_definitions.unit_base_definitions[type].type == military::unit_type::big_ship)
430 ++count;
431 }
432 }
433 }
435 }
436};
438public:
439 void on_update(sys::state& state) noexcept override {
440 auto b = retrieve<dcon::naval_battle_id>(state, parent);
441 auto w = state.world.naval_battle_get_war_from_naval_battle_in_war(b);
442 int32_t count = 0;
443 for(auto a : state.world.naval_battle_get_navy_battle_participation(b)) {
444 auto owner = a.get_navy().get_controller_from_navy_control();
445 bool battle_attacker = (military::get_role(state, w, owner) == military::war_role::attacker) == state.world.naval_battle_get_war_attacker_is_attacker(b);
446 if(battle_attacker == true) {
447 for(auto r : a.get_navy().get_navy_membership()) {
448 auto type = r.get_ship().get_type();
449 if(type && state.military_definitions.unit_base_definitions[type].type == military::unit_type::light_ship)
450 ++count;
451 }
452 }
453 }
455 }
456};
458public:
459 void on_update(sys::state& state) noexcept override {
460 auto b = retrieve<dcon::naval_battle_id>(state, parent);
461 auto w = state.world.naval_battle_get_war_from_naval_battle_in_war(b);
462 int32_t count = 0;
463 for(auto a : state.world.naval_battle_get_navy_battle_participation(b)) {
464 auto owner = a.get_navy().get_controller_from_navy_control();
465 bool battle_attacker = (military::get_role(state, w, owner) == military::war_role::attacker) == state.world.naval_battle_get_war_attacker_is_attacker(b);
466 if(battle_attacker == true) {
467 for(auto r : a.get_navy().get_navy_membership()) {
468 auto type = r.get_ship().get_type();
469 if(type && state.military_definitions.unit_base_definitions[type].type == military::unit_type::transport)
470 ++count;
471 }
472 }
473 }
475 }
476};
477
478class nc_defender_combat_modifiers : public overlapping_listbox_element_base<lc_modifier, lc_modifier_data> {
479 std::string_view get_row_element_name() override {
480 return "alice_combat_modifier";
481 }
482 void update_subwindow(sys::state& state, lc_modifier& subwindow, lc_modifier_data content) override {
483 subwindow.data = content;
484 }
485 void on_update(sys::state& state) noexcept override {
486 row_contents.clear();
487
488 auto b = retrieve<dcon::naval_battle_id>(state, parent);
489 auto both_dice = state.world.naval_battle_get_dice_rolls(b);
490
491 auto defender_dice = (both_dice >> 4) & 0x0F;
492
493 auto defender_per = state.world.leader_get_personality(state.world.naval_battle_get_admiral_from_defending_admiral(b));
494 auto defender_bg = state.world.leader_get_background(state.world.naval_battle_get_admiral_from_defending_admiral(b));
495
496 auto defence_bonus =
497 int32_t(state.world.leader_trait_get_defense(defender_per) + state.world.leader_trait_get_defense(defender_bg));
498
499 row_contents.push_back(lc_modifier_data{ lc_mod_type::dice, defender_dice });
500 if(defence_bonus != 0)
501 row_contents.push_back(lc_modifier_data{ lc_mod_type::leader, defence_bonus });
502
503 update(state);
504 }
505};
506class nc_attacker_combat_modifiers : public overlapping_listbox_element_base<lc_modifier, lc_modifier_data> {
507 std::string_view get_row_element_name() override {
508 return "alice_combat_modifier";
509 }
510 void update_subwindow(sys::state& state, lc_modifier& subwindow, lc_modifier_data content) override {
511 subwindow.data = content;
512 }
513 void on_update(sys::state& state) noexcept override {
514 row_contents.clear();
515
516 auto b = retrieve<dcon::naval_battle_id>(state, parent);
517 auto both_dice = state.world.naval_battle_get_dice_rolls(b);
518 auto attacker_dice = both_dice & 0x0F;
519
520 auto attacker_per = state.world.leader_get_personality(state.world.naval_battle_get_admiral_from_attacking_admiral(b));
521 auto attacker_bg = state.world.leader_get_background(state.world.naval_battle_get_admiral_from_attacking_admiral(b));
522
523 auto attack_bonus =
524 int32_t(state.world.leader_trait_get_attack(attacker_per) + state.world.leader_trait_get_attack(attacker_bg));
525
526 row_contents.push_back(lc_modifier_data{ lc_mod_type::dice, attacker_dice });
527 if(attack_bonus != 0)
528 row_contents.push_back(lc_modifier_data{ lc_mod_type::leader, attack_bonus });
529
530 update(state);
531 }
532};
533
534
536public:
537 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
538 if(name == "shield") {
539 return make_element_by_type<nc_attacker_flag>(state, id);
540 } else if(name == "leader_icon") {
541 return make_element_by_type<nc_attacker_leader_img>(state, id);
542 } else if(name == "leader_name") {
543 return make_element_by_type<nc_attacking_leader_name>(state, id);
544 } else if(name == "morale") {
545 return make_element_by_type<nc_attacker_org>(state, id);
546 } else if(name == "strength") {
547 return make_element_by_type<nc_attacker_str>(state, id);
548 } else if(name == "morale_text") {
549 return make_element_by_type<nc_attacker_org_txt>(state, id);
550 } else if(name == "strength_text") {
551 return make_element_by_type<nc_attacker_str_txt>(state, id);
552 } else if(name == "big_ship_icon") {
553 return make_element_by_type<lc_static_icon<0>>(state, id);
554 } else if(name == "small_ship_icon") {
555 return make_element_by_type<lc_static_icon<1>>(state, id);
556 } else if(name == "trade_ship_icon") {
557 return make_element_by_type<lc_static_icon<2>>(state, id);
558 } else if(name == "big_ship_value") {
559 return make_element_by_type<nc_attacker_bs_txt>(state, id);
560 } else if(name == "small_ship_value") {
561 return make_element_by_type<nc_attacker_ss_txt>(state, id);
562 } else if(name == "trade_ship_value") {
563 return make_element_by_type<nc_attacker_ts_txt>(state, id);
564 } else if(name == "modifiers") {
565 return make_element_by_type<nc_attacker_combat_modifiers>(state, id);
566 } else {
567 return nullptr;
568 }
569 }
570};
571
573public:
574 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
575 if(name == "shield") {
576 return make_element_by_type<nc_defender_flag>(state, id);
577 } else if(name == "leader_icon") {
578 return make_element_by_type<nc_defending_leader_img>(state, id);
579 } else if(name == "leader_name") {
580 return make_element_by_type<nc_defending_leader_name>(state, id);
581 } else if(name == "morale") {
582 return make_element_by_type<nc_defender_org>(state, id);
583 } else if(name == "strength") {
584 return make_element_by_type<nc_defender_str>(state, id);
585 } else if(name == "morale_text") {
586 return make_element_by_type<nc_defender_org_txt>(state, id);
587 } else if(name == "strength_text") {
588 return make_element_by_type<nc_defender_str_txt>(state, id);
589 } else if(name == "big_ship_icon") {
590 return make_element_by_type<lc_static_icon<0>>(state, id);
591 } else if(name == "small_ship_icon") {
592 return make_element_by_type<lc_static_icon<1>>(state, id);
593 } else if(name == "trade_ship_icon") {
594 return make_element_by_type<lc_static_icon<2>>(state, id);
595 } else if(name == "big_ship_value") {
596 return make_element_by_type<nc_defender_bs_txt>(state, id);
597 } else if(name == "small_ship_value") {
598 return make_element_by_type<nc_defender_ss_txt>(state, id);
599 } else if(name == "trade_ship_value") {
600 return make_element_by_type<nc_defender_ts_txt>(state, id);
601 } else if(name == "modifiers") {
602 return make_element_by_type<nc_defender_combat_modifiers>(state, id);
603 } else {
604 return nullptr;
605 }
606 }
607};
608
610public:
611 void on_update(sys::state& state) noexcept override {
612 disabled = !command::can_retreat_from_naval_battle(state, state.local_player_nation, retrieve<dcon::naval_battle_id>(state, parent));
613 }
614 void button_action(sys::state& state) noexcept override {
615 command::retreat_from_naval_battle(state, state.local_player_nation, retrieve<dcon::naval_battle_id>(state, parent));
616 }
619 }
620 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
621 auto b = retrieve<dcon::naval_battle_id>(state, parent);
622 text::add_line(state, contents, "alice_retreat");
623 text::add_line_with_condition(state, contents, "alice_retreat_1",
624 state.world.naval_battle_get_start_date(b) + military::days_before_retreat < state.current_date,
626 text::add_line_with_condition(state, contents, "alice_retreat_2",
627 state.local_player_nation == military::get_naval_battle_lead_attacker(state, b)
628 || state.local_player_nation == military::get_naval_battle_lead_defender(state, b));
629 }
630};
631
633public:
634 void on_update(sys::state& state) noexcept override {
635 auto b = retrieve<dcon::naval_battle_id>(state, parent);
636 auto loc = state.world.naval_battle_get_location_from_naval_battle_location(b);
637 auto name = state.world.province_get_name(loc);
639 set_text(state, txt);
640 }
641};
642
644public:
645 dcon::naval_battle_id battle;
646
647 void on_create(sys::state& state) noexcept override {
649 state.ui_state.naval_combat_window = this;
650 }
651
652 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
653 if(name == "combat_bg") {
654 return make_element_by_type<opaque_element_base>(state, id);
655 } else if(name == "label_battlename") {
656 return make_element_by_type<nbattle_name>(state, id);
657 } else if(name == "combat_retreat") {
658 return make_element_by_type<nc_retreat_button>(state, id);
659 } else if(name == "closebutton") {
660 return make_element_by_type<generic_close_button>(state, id);
661 } else if(name == "attacker") {
662 return make_element_by_type<naval_combat_attacker_window>(state, id);
663 } else if(name == "defender") {
664 return make_element_by_type<naval_combat_defender_window>(state, id);
665 } else {
666 return nullptr;
667 }
668 }
669
670 void on_update(sys::state& state) noexcept override {
671 if(!state.world.naval_battle_is_valid(battle)) {
672 set_visible(state, false);
673 battle = dcon::naval_battle_id{};
674 }
675 sound::play_effect(state, sound::get_random_naval_battle_sound(state), state.user_settings.effects_volume * state.user_settings.master_volume);
676 }
677
678 message_result get(sys::state& state, Cyto::Any& payload) noexcept override {
679 if(payload.holds_type<dcon::naval_battle_id>()) {
680 payload.emplace<dcon::naval_battle_id>(battle);
682 } else if(payload.holds_type<dcon::province_id>()) {
683 payload.emplace<dcon::province_id>(state.world.naval_battle_get_location_from_naval_battle_location(battle));
685 }
686 return window_element_base::get(state, payload);
687 }
688};
689
690//===============================================================================================================================
691
693 bool visible = true;
694 void on_update(sys::state& state) noexcept override {
695 visible = !(retrieve< military::naval_battle_report*>(state, parent)->player_on_winning_side);
696 }
697 void render(sys::state& state, int32_t x, int32_t y) noexcept override {
698 if(visible)
700 }
701};
703 bool visible = true;
704 void on_update(sys::state& state) noexcept override {
705 visible = (retrieve< military::naval_battle_report*>(state, parent)->player_on_winning_side);
706 }
707 void render(sys::state& state, int32_t x, int32_t y) noexcept override {
708 if(visible)
710 }
711};
713 void on_update(sys::state& state) noexcept override {
714 auto loc = retrieve< military::naval_battle_report*>(state, parent)->location;
715 auto name = state.world.province_get_name(loc);
717 set_text(state, txt);
718 }
719};
720
722 dcon::gfx_object_id def;
723
724 void on_update(sys::state& state) noexcept override {
725 if(!def)
727
728 military::naval_battle_report* report = retrieve< military::naval_battle_report*>(state, parent);
729 bool we_are_attacker = (report->attacker_won == report->player_on_winning_side);
730 dcon::leader_id lid = we_are_attacker ? report->attacking_admiral : report->defending_admiral;
731
732 if(!lid) {
734 return;
735 }
736
737 auto owner = state.world.leader_get_nation_from_leader_loyalty(lid);
738 auto pculture = state.world.nation_get_primary_culture(owner);
739 auto ltype = pculture.get_group_from_culture_group_membership().get_leader();
740
741 if(ltype) {
742 auto grange = ltype.get_admirals();
743 if(grange.size() > 0) {
744 auto rval = rng::get_random(state, uint32_t(state.world.leader_get_since(lid).value), uint32_t(lid.value));
745 auto in_range = rng::reduce(uint32_t(rval), grange.size());
746 base_data.data.image.gfx_object = grange[in_range];
747 }
748 }
749 }
750
751 tooltip_behavior has_tooltip(sys::state& state) noexcept override {
753 }
754
755 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
756 military::naval_battle_report* report = retrieve< military::naval_battle_report*>(state, parent);
757 bool we_are_attacker = (report->attacker_won == report->player_on_winning_side);
758 dcon::leader_id lid = we_are_attacker ? report->attacking_admiral : report->defending_admiral;
759
760 if(lid)
761 display_leader_attributes(state, lid, contents, 0);
762 else
763 text::add_line(state, contents, "no_leader");
764 }
765};
767public:
768 void on_update(sys::state& state) noexcept override {
769 military::naval_battle_report* report = retrieve< military::naval_battle_report*>(state, parent);
770 bool we_are_attacker = (report->attacker_won == report->player_on_winning_side);
771 dcon::leader_id lid = we_are_attacker ? report->attacking_admiral : report->defending_admiral;
772
773 if(lid) {
774 auto name = state.to_string_view(state.world.leader_get_name(lid));
775 set_text(state, std::string(name));
776 } else {
778 }
779 }
780};
782 dcon::gfx_object_id def;
783
784 void on_update(sys::state& state) noexcept override {
785 if(!def)
787
788 military::naval_battle_report* report = retrieve< military::naval_battle_report*>(state, parent);
789 bool we_are_attacker = (report->attacker_won == report->player_on_winning_side);
790 dcon::leader_id lid = !we_are_attacker ? report->attacking_admiral : report->defending_admiral;
791
792 if(!lid) {
794 return;
795 }
796
797 auto owner = state.world.leader_get_nation_from_leader_loyalty(lid);
798 auto pculture = state.world.nation_get_primary_culture(owner);
799 auto ltype = pculture.get_group_from_culture_group_membership().get_leader();
800
801 if(ltype) {
802 auto grange = ltype.get_admirals();
803 if(grange.size() > 0) {
804 auto rval = rng::get_random(state, uint32_t(state.world.leader_get_since(lid).value), uint32_t(lid.value));
805 auto in_range = rng::reduce(uint32_t(rval), grange.size());
806 base_data.data.image.gfx_object = grange[in_range];
807 }
808 }
809 }
810
811 tooltip_behavior has_tooltip(sys::state& state) noexcept override {
813 }
814
815 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
816 military::naval_battle_report* report = retrieve< military::naval_battle_report*>(state, parent);
817 bool we_are_attacker = (report->attacker_won == report->player_on_winning_side);
818 dcon::leader_id lid = !we_are_attacker ? report->attacking_admiral : report->defending_admiral;
819
820 if(lid)
821 display_leader_attributes(state, lid, contents, 0);
822 else
823 text::add_line(state, contents, "no_leader");
824 }
825};
827public:
828 void on_update(sys::state& state) noexcept override {
829 military::naval_battle_report* report = retrieve< military::naval_battle_report*>(state, parent);
830 bool we_are_attacker = (report->attacker_won == report->player_on_winning_side);
831 dcon::leader_id lid = !we_are_attacker ? report->attacking_admiral : report->defending_admiral;
832
833 if(lid) {
834 auto name = state.to_string_view(state.world.leader_get_name(lid));
835 set_text(state, std::string(name));
836 } else {
838 }
839 }
840};
842public:
843 void on_update(sys::state& state) noexcept override {
844 military::naval_battle_report* report = retrieve< military::naval_battle_report*>(state, parent);
845 auto prestige_value = report->prestige_effect;
846 set_text(state, text::format_float(prestige_value, 2));
847 if(prestige_value > 0) {
849 } else if(prestige_value < 0) {
851 } else {
853 }
854 }
855};
857public:
858 void on_update(sys::state& state) noexcept override {
859 military::naval_battle_report* report = retrieve< military::naval_battle_report*>(state, parent);
860 auto prestige_value = -report->prestige_effect;
861 set_text(state, text::format_float(prestige_value, 2));
862 if(prestige_value > 0) {
864 } else if(prestige_value < 0) {
866 } else {
868 }
869 }
870};
872 void on_update(sys::state& state) noexcept override {
873 military::naval_battle_report* report = retrieve< military::naval_battle_report*>(state, parent);
874 bool we_are_attacker = (report->attacker_won == report->player_on_winning_side);
875 auto value = we_are_attacker ? report->attacker_big_ships : report->defender_big_ships;
876 set_text(state, text::prettify(int64_t(value)));
877 }
878};
880 void on_update(sys::state& state) noexcept override {
881 military::naval_battle_report* report = retrieve< military::naval_battle_report*>(state, parent);
882 bool we_are_attacker = (report->attacker_won == report->player_on_winning_side);
883 auto value = we_are_attacker ? report->attacker_small_ships : report->defender_small_ships;
884 set_text(state, text::prettify(int64_t(value)));
885 }
886};
888 void on_update(sys::state& state) noexcept override {
889 military::naval_battle_report* report = retrieve< military::naval_battle_report*>(state, parent);
890 bool we_are_attacker = (report->attacker_won == report->player_on_winning_side);
891 auto value = we_are_attacker ? report->attacker_transport_ships : report->defender_transport_ships;
892 set_text(state, text::prettify(int64_t(value)));
893 }
894};
896 void on_update(sys::state& state) noexcept override {
897 military::naval_battle_report* report = retrieve< military::naval_battle_report*>(state, parent);
898 bool we_are_attacker = (report->attacker_won == report->player_on_winning_side);
899 auto value = !we_are_attacker ? report->attacker_big_ships : report->defender_big_ships;
900 set_text(state, text::prettify(int64_t(value)));
901 }
902};
904 void on_update(sys::state& state) noexcept override {
905 military::naval_battle_report* report = retrieve< military::naval_battle_report*>(state, parent);
906 bool we_are_attacker = (report->attacker_won == report->player_on_winning_side);
907 auto value = !we_are_attacker ? report->attacker_small_ships : report->defender_small_ships;
908 set_text(state, text::prettify(int64_t(value)));
909 }
910};
912 void on_update(sys::state& state) noexcept override {
913 military::naval_battle_report* report = retrieve< military::naval_battle_report*>(state, parent);
914 bool we_are_attacker = (report->attacker_won == report->player_on_winning_side);
915 auto value = !we_are_attacker ? report->attacker_transport_ships : report->defender_transport_ships;
916 set_text(state, text::prettify(int64_t(value)));
917 }
918};
920 void on_update(sys::state& state) noexcept override {
921 military::naval_battle_report* report = retrieve< military::naval_battle_report*>(state, parent);
922 bool we_are_attacker = (report->attacker_won == report->player_on_winning_side);
923 auto value = we_are_attacker ? std::min(report->attacker_big_ships, report->attacker_big_losses) : std::min(report->defender_big_ships, report->defender_big_losses);
924 set_text(state, text::prettify(-int64_t(value)));
925 }
926};
928 void on_update(sys::state& state) noexcept override {
929 military::naval_battle_report* report = retrieve< military::naval_battle_report*>(state, parent);
930 bool we_are_attacker = (report->attacker_won == report->player_on_winning_side);
931 auto value = we_are_attacker ? std::min(report->attacker_small_ships, report->attacker_small_losses) : std::min(report->defender_small_ships, report->defender_small_losses);
932 set_text(state, text::prettify(-int64_t(value)));
933 }
934};
936 void on_update(sys::state& state) noexcept override {
937 military::naval_battle_report* report = retrieve< military::naval_battle_report*>(state, parent);
938 bool we_are_attacker = (report->attacker_won == report->player_on_winning_side);
939 auto value = we_are_attacker ? std::min(report->attacker_transport_ships, report->attacker_transport_losses) : std::min(report->defender_transport_ships, report->defender_transport_losses);
940 set_text(state, text::prettify(-int64_t(value)));
941 }
942};
944 void on_update(sys::state& state) noexcept override {
945 military::naval_battle_report* report = retrieve< military::naval_battle_report*>(state, parent);
946 bool we_are_attacker = (report->attacker_won == report->player_on_winning_side);
947 auto value = !we_are_attacker ? std::min(report->attacker_big_ships, report->attacker_big_losses) : std::min(report->defender_big_ships, report->defender_big_losses);
948 set_text(state, text::prettify(-int64_t(value)));
949 }
950};
952 void on_update(sys::state& state) noexcept override {
953 military::naval_battle_report* report = retrieve< military::naval_battle_report*>(state, parent);
954 bool we_are_attacker = (report->attacker_won == report->player_on_winning_side);
955 auto value = !we_are_attacker ? std::min(report->attacker_small_ships, report->attacker_small_losses) : std::min(report->defender_small_ships, report->defender_small_losses);
956 set_text(state, text::prettify(-int64_t(value)));
957 }
958};
960 void on_update(sys::state& state) noexcept override {
961 military::naval_battle_report* report = retrieve< military::naval_battle_report*>(state, parent);
962 bool we_are_attacker = (report->attacker_won == report->player_on_winning_side);
963 auto value = !we_are_attacker ? std::min(report->attacker_transport_ships, report->attacker_transport_losses) : std::min(report->defender_transport_ships, report->defender_transport_losses);
964 set_text(state, text::prettify(-int64_t(value)));
965 }
966};
968 void on_update(sys::state& state) noexcept override {
969 military::naval_battle_report* report = retrieve< military::naval_battle_report*>(state, parent);
970 bool we_are_attacker = (report->attacker_won == report->player_on_winning_side);
971 auto value = we_are_attacker ? std::max(report->attacker_big_ships - report->attacker_big_losses, 0) : std::max(report->defender_big_ships - report->defender_big_losses, 0);
972 set_text(state, text::prettify(int64_t(value)));
973 }
974};
976 void on_update(sys::state& state) noexcept override {
977 military::naval_battle_report* report = retrieve< military::naval_battle_report*>(state, parent);
978 bool we_are_attacker = (report->attacker_won == report->player_on_winning_side);
979 auto value = we_are_attacker ? std::max(report->attacker_small_ships - report->attacker_small_losses, 0) : std::max(report->defender_small_ships - report->defender_small_losses, 0);
980 set_text(state, text::prettify(int64_t(value)));
981 }
982};
984 void on_update(sys::state& state) noexcept override {
985 military::naval_battle_report* report = retrieve< military::naval_battle_report*>(state, parent);
986 bool we_are_attacker = (report->attacker_won == report->player_on_winning_side);
987 auto value = we_are_attacker ? std::max(report->attacker_transport_ships - report->attacker_transport_losses, 0) : std::max(report->defender_transport_ships - report->defender_transport_losses, 0);
988 set_text(state, text::prettify(int64_t(value)));
989 }
990};
992 void on_update(sys::state& state) noexcept override {
993 military::naval_battle_report* report = retrieve< military::naval_battle_report*>(state, parent);
994 bool we_are_attacker = (report->attacker_won == report->player_on_winning_side);
995 auto value = !we_are_attacker ? std::max(report->attacker_big_ships - report->attacker_big_losses, 0) : std::max(report->defender_big_ships - report->defender_big_losses, 0);
996 set_text(state, text::prettify(int64_t(value)));
997 }
998};
1000 void on_update(sys::state& state) noexcept override {
1001 military::naval_battle_report* report = retrieve< military::naval_battle_report*>(state, parent);
1002 bool we_are_attacker = (report->attacker_won == report->player_on_winning_side);
1003 auto value = !we_are_attacker ? std::max(report->attacker_small_ships - report->attacker_small_losses, 0) : std::max(report->defender_small_ships - report->defender_small_losses, 0);
1004 set_text(state, text::prettify(int64_t(value)));
1005 }
1006};
1008 void on_update(sys::state& state) noexcept override {
1009 military::naval_battle_report* report = retrieve< military::naval_battle_report*>(state, parent);
1010 bool we_are_attacker = (report->attacker_won == report->player_on_winning_side);
1011 auto value = !we_are_attacker ? std::max(report->attacker_transport_ships - report->attacker_transport_losses, 0) : std::max(report->defender_transport_ships - report->defender_transport_losses, 0);
1012 set_text(state, text::prettify(int64_t(value)));
1013 }
1014};
1015
1017 void on_update(sys::state& state) noexcept override {
1018 military::naval_battle_report* report = retrieve< military::naval_battle_report*>(state, parent);
1019 bool we_are_attacker = (report->attacker_won == report->player_on_winning_side);
1020 auto value = we_are_attacker ? report->attacker_big_ships + report->attacker_small_ships + report->attacker_transport_ships : report->defender_big_ships + report->defender_small_ships + report->defender_transport_ships;
1021 set_text(state, text::prettify(int64_t(value)));
1022 }
1023};
1025 void on_update(sys::state& state) noexcept override {
1026 military::naval_battle_report* report = retrieve< military::naval_battle_report*>(state, parent);
1027 bool we_are_attacker = (report->attacker_won == report->player_on_winning_side);
1028 auto value = we_are_attacker ? std::min(report->attacker_big_ships + report->attacker_small_ships + report->attacker_transport_ships, report->attacker_big_losses + report->attacker_small_losses + report->attacker_transport_losses) : std::min(report->defender_big_ships + report->defender_small_ships + report->defender_transport_ships, report->defender_big_losses + report->defender_small_losses + report->defender_transport_losses);
1029 set_text(state, text::prettify(-int64_t(value)));
1030 }
1031};
1033 void on_update(sys::state& state) noexcept override {
1034 military::naval_battle_report* report = retrieve< military::naval_battle_report*>(state, parent);
1035 bool we_are_attacker = (report->attacker_won == report->player_on_winning_side);
1036 auto value = we_are_attacker ? std::max(report->attacker_big_ships + report->attacker_small_ships + report->attacker_transport_ships - (report->attacker_big_losses + report->attacker_small_losses + report->attacker_transport_losses), 0) : std::max(report->defender_big_ships + report->defender_small_ships + report->defender_transport_ships - (report->defender_big_losses + report->defender_small_losses + report->defender_transport_losses), 0);
1037 set_text(state, text::prettify(int64_t(value)));
1038 }
1039};
1041 void on_update(sys::state& state) noexcept override {
1042 military::naval_battle_report* report = retrieve< military::naval_battle_report*>(state, parent);
1043 bool we_are_attacker = (report->attacker_won == report->player_on_winning_side);
1044 auto value = !we_are_attacker ? report->attacker_big_ships + report->attacker_small_ships + report->attacker_transport_ships : report->defender_big_ships + report->defender_small_ships + report->defender_transport_ships;
1045 set_text(state, text::prettify(int64_t(value)));
1046 }
1047};
1049 void on_update(sys::state& state) noexcept override {
1050 military::naval_battle_report* report = retrieve< military::naval_battle_report*>(state, parent);
1051 bool we_are_attacker = (report->attacker_won == report->player_on_winning_side);
1052 auto value = !we_are_attacker ? std::min(report->attacker_big_ships + report->attacker_small_ships + report->attacker_transport_ships, report->attacker_big_losses + report->attacker_small_losses + report->attacker_transport_losses) : std::min(report->defender_big_ships + report->defender_small_ships + report->defender_transport_ships, report->defender_big_losses + report->defender_small_losses + report->defender_transport_losses);
1053 set_text(state, text::prettify(-int64_t(value)));
1054 }
1055};
1057 void on_update(sys::state& state) noexcept override {
1058 military::naval_battle_report* report = retrieve< military::naval_battle_report*>(state, parent);
1059 bool we_are_attacker = (report->attacker_won == report->player_on_winning_side);
1060 auto value = !we_are_attacker ? std::max(report->attacker_big_ships + report->attacker_small_ships + report->attacker_transport_ships - (report->attacker_big_losses + report->attacker_small_losses + report->attacker_transport_losses), 0) : std::max(report->defender_big_ships + report->defender_small_ships + report->defender_transport_ships - (report->defender_big_losses + report->defender_small_losses + report->defender_transport_losses), 0);
1061 set_text(state, text::prettify(int64_t(value)));
1062 }
1063};
1065 void button_action(sys::state& state) noexcept override {
1066 military::naval_battle_report* report = retrieve< military::naval_battle_report*>(state, parent);
1067 auto prov = report->location;
1068 if(prov && prov.value < state.province_definitions.first_sea_province.value) {
1069 state.map_state.set_selected_province(prov);
1070 static_cast<ui::province_view_window*>(state.ui_state.province_window)->set_active_province(state, prov);
1071 if(state.map_state.get_zoom() < map::zoom_very_close)
1072 state.map_state.zoom = map::zoom_very_close;
1073 state.map_state.center_map_on_province(state, prov);
1074 }
1075 }
1076};
1077
1079 void button_action(sys::state& state) noexcept override;
1080};
1082 void on_update(sys::state& state) noexcept override {
1083 military::naval_battle_report* report = retrieve< military::naval_battle_report*>(state, parent);
1084 if(report->player_on_winning_side) {
1087 } else {
1090 }
1091 }
1092};
1094 void on_update(sys::state& state) noexcept override {
1095 military::naval_battle_report* report = retrieve< military::naval_battle_report*>(state, parent);
1096 if(report->player_on_winning_side) {
1097 set_text(state, std::string("+") + text::format_float(report->warscore_effect, 1));
1099 } else {
1102 }
1103 }
1104};
1105
1107public:
1109 static std::vector<std::unique_ptr<ui::naval_combat_end_popup>> naval_reports_pool;
1110
1111
1112 message_result get(sys::state& state, Cyto::Any& payload) noexcept override;
1114 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override;
1115};
1116
1117inline std::vector<std::unique_ptr<ui::naval_combat_end_popup>> naval_combat_end_popup::naval_reports_pool;
1118
1120 if(payload.holds_type<military::naval_battle_report*>()) {
1121 payload.emplace<military::naval_battle_report*>(&report);
1123 }
1124 return window_element_base::get(state, payload);
1125}
1126
1128 if(naval_reports_pool.empty()) {
1129 auto new_elm = ui::make_element_by_type<ui::naval_combat_end_popup>(state, "endofnavalcombatpopup");
1130 auto ptr = new_elm.get();
1131 naval_combat_end_popup* actual = static_cast<naval_combat_end_popup*>(ptr);
1132 actual->report = r;
1133 actual->impl_on_update(state);
1134 state.ui_state.root->add_child_to_front(std::move(new_elm));
1135 } else {
1136 std::unique_ptr<naval_combat_end_popup> ptr = std::move(naval_reports_pool.back());
1137 naval_reports_pool.pop_back();
1138 ptr->report = r;
1139 ptr->set_visible(state, true);
1140 state.ui_state.root->add_child_to_front(std::move(ptr));
1141 }
1142}
1143
1144inline std::unique_ptr<element_base> naval_combat_end_popup::make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept {
1145 if(name == "background") {
1146 return make_element_by_type<draggable_target>(state, id);
1147 } else if(name == "combat_end_naval_lost") {
1148 return make_element_by_type<nc_loss_image>(state, id);
1149 } else if(name == "combat_end_naval_won") {
1150 return make_element_by_type<nc_win_image>(state, id);
1151 } else if(name == "line1") {
1152 return make_element_by_type<nc_result_battle_name>(state, id);
1153 } else if(name == "ourleader_photo") {
1154 return make_element_by_type<nc_our_leader_img>(state, id);
1155 } else if(name == "ourleader") {
1156 return make_element_by_type<nc_our_leader_name>(state, id);
1157 } else if(name == "prestige_number") {
1158 return make_element_by_type<nc_our_prestige>(state, id);
1159 } else if(name == "we_number") {
1160 return make_element_by_type<lc_empty_text>(state, id);
1161 } else if(name == "enemyleader_photo") {
1162 return make_element_by_type<nc_their_leader_img>(state, id);
1163 } else if(name == "enemyleader") {
1164 return make_element_by_type<nc_their_leader_name>(state, id);
1165 } else if(name == "prestige_number2") {
1166 return make_element_by_type<nc_their_prestige>(state, id);
1167 } else if(name == "we_number2") {
1168 return make_element_by_type<lc_empty_text>(state, id);
1169 } else if(name == "our_unit_type_1") {
1170 return make_element_by_type<lc_static_icon<3>>(state, id);
1171 } else if(name == "our_unit_type_1_1_text") {
1172 return make_element_by_type<nc_o_initial_bs>(state, id);
1173 } else if(name == "our_unit_type_1_2_text") {
1174 return make_element_by_type<nc_o_loss_bs>(state, id);
1175 } else if(name == "our_unit_type_1_3_text") {
1176 return make_element_by_type<nc_o_rem_bs>(state, id);
1177 } else if(name == "our_unit_type_2") {
1178 return make_element_by_type<lc_static_icon<4>>(state, id);
1179 } else if(name == "our_unit_type_2_1_text") {
1180 return make_element_by_type<nc_o_initial_ss>(state, id);
1181 } else if(name == "our_unit_type_2_2_text") {
1182 return make_element_by_type<nc_o_loss_ss>(state, id);
1183 } else if(name == "our_unit_type_2_3_text") {
1184 return make_element_by_type<nc_o_rem_ss>(state, id);
1185 } else if(name == "our_unit_type_3") {
1186 return make_element_by_type<lc_static_icon<5>>(state, id);
1187 } else if(name == "our_unit_type_3_1_text") {
1188 return make_element_by_type<nc_o_initial_ts>(state, id);
1189 } else if(name == "our_unit_type_3_2_text") {
1190 return make_element_by_type<nc_o_loss_ts>(state, id);
1191 } else if(name == "our_unit_type_3_3_text") {
1192 return make_element_by_type<nc_o_rem_ts>(state, id);
1193 } else if(name == "enemy_unit_type_1") {
1194 return make_element_by_type<lc_static_icon<3>>(state, id);
1195 } else if(name == "enemy_unit_type_1_1_text") {
1196 return make_element_by_type<nc_t_initial_bs>(state, id);
1197 } else if(name == "enemy_unit_type_1_2_text") {
1198 return make_element_by_type<nc_t_loss_bs>(state, id);
1199 } else if(name == "enemy_unit_type_1_3_text") {
1200 return make_element_by_type<nc_t_rem_bs>(state, id);
1201 } else if(name == "enemy_unit_type_2") {
1202 return make_element_by_type<lc_static_icon<4>>(state, id);
1203 } else if(name == "enemy_unit_type_2_1_text") {
1204 return make_element_by_type<nc_t_initial_ss>(state, id);
1205 } else if(name == "enemy_unit_type_2_2_text") {
1206 return make_element_by_type<nc_t_loss_ss>(state, id);
1207 } else if(name == "enemy_unit_type_2_3_text") {
1208 return make_element_by_type<nc_t_rem_ss>(state, id);
1209 } else if(name == "enemy_unit_type_3") {
1210 return make_element_by_type<lc_static_icon<5>>(state, id);
1211 } else if(name == "enemy_unit_type_3_1_text") {
1212 return make_element_by_type<nc_t_initial_ts>(state, id);
1213 } else if(name == "enemy_unit_type_3_2_text") {
1214 return make_element_by_type<nc_t_loss_ts>(state, id);
1215 } else if(name == "enemy_unit_type_3_3_text") {
1216 return make_element_by_type<nc_t_rem_ts>(state, id);
1217 } else if(name == "our_total_armies") {
1218 return make_element_by_type<nc_o_initial_total>(state, id);
1219 } else if(name == "our_total_loss") {
1220 return make_element_by_type<nc_o_loss_total>(state, id);
1221 } else if(name == "our_total_left") {
1222 return make_element_by_type<nc_o_rem_total>(state, id);
1223 } else if(name == "enemy_total_armies") {
1224 return make_element_by_type<nc_t_initial_total>(state, id);
1225 } else if(name == "enemy_total_loss") {
1226 return make_element_by_type<nc_t_loss_total>(state, id);
1227 } else if(name == "enemy_total_left") {
1228 return make_element_by_type<nc_t_rem_total>(state, id);
1229 } else if(name == "agreebutton") {
1230 auto ptr = make_element_by_type<nc_close_button>(state, id);
1231 ptr->base_data.position.y += 146; // Nudge
1232 return ptr;
1233 } else if(name == "declinebutton") {
1234 auto ptr = make_element_by_type<nc_goto_location_button>(state, id);
1235 ptr->base_data.position.y += 146; // Nudge
1236 ptr->set_button_text(state, text::produce_simple_string(state, "landbattleover_btn3"));
1237 return ptr;
1238 } else if(name == "centerok") {
1239 return make_element_by_type<invisible_element>(state, id);
1240 } else if(name == "warscore") {
1241 return make_element_by_type<nc_warscore>(state, id);
1242 } else if(name == "winorlose") {
1243 return make_element_by_type<nc_win_lose>(state, id);
1244 } else {
1245 return nullptr;
1246 }
1247}
1248
1249inline void nc_close_button::button_action(sys::state& state) noexcept {
1250 parent->set_visible(state, false);
1251 auto uptr = state.ui_state.root->remove_child(parent);
1252 assert(uptr);
1253 std::unique_ptr<naval_combat_end_popup> ptr(static_cast<naval_combat_end_popup*>(uptr.release()));
1254 naval_combat_end_popup::naval_reports_pool.push_back(std::move(ptr));
1255}
1256
1257} // 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
element_data base_data
void set_visible(sys::state &state, bool vis)
void on_create(sys::state &state) noexcept override
void render(sys::state &state, int32_t x, int32_t y) noexcept override
lc_modifier_data data
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
std::unique_ptr< element_base > make_child(sys::state &state, std::string_view name, dcon::gui_def_id id) noexcept override
military::naval_battle_report report
static void make_new_report(sys::state &state, military::naval_battle_report const &r)
static std::vector< std::unique_ptr< ui::naval_combat_end_popup > > naval_reports_pool
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 on_update(sys::state &state) noexcept override
dcon::naval_battle_id battle
void on_update(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept override
dcon::national_identity_id get_current_nation(sys::state &state) noexcept override
void render(sys::state &state, int32_t x, int32_t y) noexcept override
void on_create(sys::state &state) 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
void on_update(sys::state &state) 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
void on_update(sys::state &state) noexcept override
void render(sys::state &state, int32_t x, int32_t y) noexcept override
void on_create(sys::state &state) noexcept override
dcon::national_identity_id get_current_nation(sys::state &state) 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
void on_update(sys::state &state) 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
void on_update(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept override
tooltip_behavior has_tooltip(sys::state &state) noexcept override
void button_action(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
void on_update(sys::state &state) 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
#define assert(condition)
Definition: debug.h:74
void retreat_from_naval_battle(sys::state &state, dcon::nation_id source, dcon::naval_battle_id b)
Definition: commands.cpp:4201
bool can_retreat_from_naval_battle(sys::state &state, dcon::nation_id source, dcon::naval_battle_id b)
Definition: commands.cpp:4209
constexpr float zoom_very_close
Definition: constants.hpp:606
dcon::nation_id get_naval_battle_lead_defender(sys::state &state, dcon::naval_battle_id b)
Definition: military.cpp:4259
war_role get_role(sys::state const &state, dcon::war_id w, dcon::nation_id n)
Definition: military.cpp:2242
dcon::nation_id get_naval_battle_lead_attacker(sys::state &state, dcon::naval_battle_id b)
Definition: military.cpp:4239
constexpr int32_t days_before_retreat
Definition: military.hpp:257
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)
GLuint get_texture_handle(sys::state &state, dcon::texture_id id, bool keep_data)
Definition: texture.cpp:665
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
void play_effect(sys::state &state, audio_instance &s, float volume)
Definition: sound_nix.cpp:198
audio_instance & get_random_naval_battle_sound(sys::state &state)
Definition: sound_nix.cpp:400
std::string prettify(int64_t num)
Definition: text.cpp:762
std::string format_float(float num, size_t digits)
Definition: text.cpp:981
void add_line(sys::state &state, layout_base &dest, dcon::text_key txt, int32_t indent)
Definition: text.cpp:1899
void add_line_with_condition(sys::state &state, layout_base &dest, std::string_view key, bool condition_met, int32_t indent)
Definition: text.cpp:1955
std::string produce_simple_string(sys::state const &state, dcon::text_key id)
Definition: text.cpp:617
std::string format_percentage(float num, size_t digits)
Definition: text.cpp:977
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
message_result
ogl::color_modification get_color_modification(bool is_under_mouse, bool is_disabled, bool is_interactable)
uint uint32_t
dcon::leader_id defending_admiral
Definition: military.hpp:214
dcon::leader_id attacking_admiral
Definition: military.hpp:213
dcon::province_id location
Definition: military.hpp:219
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
std::unique_ptr< element_base > root
element_base * naval_combat_window
element_base * province_window
element_base * under_mouse