46 auto window = make_element_by_type<province_search_window>(
state,
"goto_box");
72 auto window = make_element_by_type<ledger_window>(
state,
"ledger");
118 for(dcon::unit_type_id::value_base_t i = 0; i <
state.military_definitions.unit_base_definitions.size(); i++) {
125 auto const utid = dcon::unit_type_id(i);
127 std::string padding = i < 10 ?
"0" :
"";
131 std::string description =
"@*" + padding + std::to_string(i);
162 return make_element_by_type<macro_builder_template_name>(
state,
id);
163 }
else if(
name ==
"background") {
164 return make_element_by_type<macro_builder_template_select>(
state,
id);
173 return "alice_macro_builder_template_entry";
182 if(contents.file_size > 0) {
185 if(num_templates >= 8192 * 4)
186 num_templates = 8192 * 4;
203 auto content = retrieve<dcon::unit_type_id>(
state,
parent);
212 auto content = retrieve<dcon::unit_type_id>(
state,
parent);
219 auto content = retrieve<dcon::unit_type_id>(
state,
parent);
230 return make_element_by_type<macro_builder_unit_name>(
state,
id);
231 }
else if(
name ==
"background") {
232 return make_element_by_type<macro_builder_unit_button>(
state,
id);
244 return "alice_macro_builder_unit_entry";
249 bool is_land = retrieve<macro_builder_state>(
state,
parent).is_land;
250 for(dcon::unit_type_id::value_base_t i = 0; i <
state.military_definitions.unit_base_definitions.size(); i++) {
251 auto const utid = dcon::unit_type_id(i);
252 auto const& ut =
state.military_definitions.unit_base_definitions[utid];
253 if(ut.is_land == is_land && (ut.active ||
state.world.nation_get_active_unit(
state.local_player_nation, utid))) {
274 bool overwrite =
false;
310 state.game_state_updated.store(
true, std::memory_order::release);
317 auto is_land = retrieve<macro_builder_state>(
state,
parent).is_land;
342 base_data.data.text.font_handle, 0, text::alignment::left,
343 text::is_black_from_font_id(base_data.data.text.font_handle) ? text::text_color::black : text::text_color::white, false });
344 auto is_land = retrieve<macro_builder_state>(
state,
parent).is_land;
347 float reconnaissance_or_fire_range = 0.f;
348 float siege_or_torpedo_attack = 0.f;
349 float attack_or_gun_power = 0.f;
350 float defence_or_hull = 0.f;
351 float discipline_or_evasion = std::numeric_limits<float>::max();
353 float supply_consumption = 0.f;
354 float maximum_speed = std::numeric_limits<float>::max();
355 float maneuver = std::numeric_limits<float>::max();
356 int32_t supply_consumption_score = 0;
357 bool warn_overseas =
false;
358 bool warn_culture =
false;
359 bool warn_active =
false;
361 if(t.amounts[i] == 0)
363 dcon::unit_type_id utid = dcon::unit_type_id(i);
364 if(is_land !=
state.military_definitions.unit_base_definitions[utid].is_land)
367 if(!
state.military_definitions.unit_base_definitions[utid].active && !
state.world.nation_get_active_unit(
state.local_player_nation, utid))
369 if(
state.military_definitions.unit_base_definitions[utid].primary_culture)
371 if(
state.military_definitions.unit_base_definitions[utid].can_build_overseas)
372 warn_overseas =
true;
374 reconnaissance_or_fire_range +=
state.world.nation_get_unit_stats(
state.local_player_nation, utid).reconnaissance_or_fire_range * float(t.amounts[i]);
375 siege_or_torpedo_attack +=
state.world.nation_get_unit_stats(
state.local_player_nation, utid).siege_or_torpedo_attack * float(t.amounts[i]);
376 attack_or_gun_power +=
state.world.nation_get_unit_stats(
state.local_player_nation, utid).attack_or_gun_power * float(t.amounts[i]);
377 defence_or_hull +=
state.world.nation_get_unit_stats(
state.local_player_nation, utid).defence_or_hull * float(t.amounts[i]);
378 discipline_or_evasion += std::min(discipline_or_evasion,
state.world.nation_get_unit_stats(
state.local_player_nation, utid).discipline_or_evasion);
379 supply_consumption +=
state.world.nation_get_unit_stats(
state.local_player_nation, utid).supply_consumption * float(t.amounts[i]);
380 maximum_speed = std::min(maximum_speed,
state.world.nation_get_unit_stats(
state.local_player_nation, utid).maximum_speed);
382 support +=
state.world.nation_get_unit_stats(
state.local_player_nation, utid).support * float(t.amounts[i]);
383 maneuver += std::min(maneuver,
state.military_definitions.unit_base_definitions[utid].maneuver);
385 supply_consumption_score +=
state.military_definitions.unit_base_definitions[utid].supply_consumption_score * int32_t(t.amounts[i]);
397 if(maximum_speed == std::numeric_limits<float>::max()) maximum_speed = 0.f;
398 if(discipline_or_evasion == std::numeric_limits<float>::max()) discipline_or_evasion = 0.f;
399 if(maneuver == std::numeric_limits<float>::max()) maneuver = 0.f;
402 if(reconnaissance_or_fire_range > 0.f) {
405 if(siege_or_torpedo_attack > 0.f) {
420 if(siege_or_torpedo_attack > 0.f) {
425 if(discipline_or_evasion > 0.f) {
435 if(t.amounts[i] == 0)
437 dcon::unit_type_id utid = dcon::unit_type_id(i);
438 if(is_land !=
state.military_definitions.unit_base_definitions[utid].is_land)
442 if(
state.world.nation_get_unit_stats(
state.local_player_nation, utid).reconnaissance_or_fire_range > 0) {
445 if(
state.world.nation_get_unit_stats(
state.local_player_nation, utid).siege_or_torpedo_attack > 0) {
451 if(
state.military_definitions.unit_base_definitions[utid].support > 0.f) {
460 if(
state.world.nation_get_unit_stats(
state.local_player_nation, utid).siege_or_torpedo_attack > 0) {
465 if(
state.military_definitions.unit_base_definitions[utid].discipline_or_evasion > 0.f) {
477 std::vector<dcon::province_id> provinces;
493 auto is_land = retrieve<macro_builder_state>(
state,
parent).is_land;
495 const auto template_province =
state.map_state.selected_province;
497 state.fill_vector_of_connected_provinces(
state.map_state.selected_province, is_land,
provinces);
502 std::array<uint8_t, sys::macro_builder_template::max_types> current_distribution;
503 current_distribution.fill(0);
504 state.build_up_to_template_land(
506 state.map_state.selected_province,
512 std::memcpy(rem_to_build, t.amounts,
sizeof(rem_to_build));
515 auto ab = state.world.province_get_province_naval_construction_as_province(a);
516 auto bb = state.world.province_get_province_naval_construction_as_province(b);
517 int32_t asz = int32_t(ab.end() - ab.begin());
518 int32_t bsz = int32_t(bb.end() - bb.begin());
520 return a.index() < b.index();
524 dcon::unit_type_id utid = dcon::unit_type_id(i);
525 if(rem_to_build[i] > 0
526 && is_land ==
state.military_definitions.unit_base_definitions[utid].is_land
527 && (
state.military_definitions.unit_base_definitions[utid].active ||
state.world.nation_get_active_unit(
state.local_player_nation, utid))) {
530 if(port_level >=
state.military_definitions.unit_base_definitions[utid].min_port_level
534 if(rem_to_build[i] == 0)
540 auto ab = state.world.province_get_province_naval_construction_as_province(a);
541 auto bb = state.world.province_get_province_naval_construction_as_province(b);
542 int32_t asz = int32_t(ab.end() - ab.begin());
543 int32_t bsz = int32_t(bb.end() - bb.begin());
545 return a.index() < b.index();
551 state.game_state_updated.store(
true, std::memory_order::release);
558 if(
state.map_state.selected_province == dcon::province_id{}) {
562 auto is_land = retrieve<macro_builder_state>(
state,
parent).is_land;
564 const auto template_province =
state.map_state.selected_province;
566 std::memcpy(rem_to_build, t.amounts,
sizeof(rem_to_build));
567 state.fill_vector_of_connected_provinces(
state.map_state.selected_province, is_land,
provinces);
576 for(
const auto p :
state.world.province_get_pop_location_as_province(prov)) {
577 if(p.get_pop().get_poptype() !=
state.culture_definitions.soldiers)
580 int32_t used = int32_t(p.get_pop().get_regiment_source().end() - p.get_pop().get_regiment_source().begin());
581 used += int32_t(p.get_pop().get_province_land_construction_as_pop().end() - p.get_pop().get_province_land_construction_as_pop().begin());
582 int32_t avail = possible - used;
583 if(possible > 0 && avail > 0) {
585 dcon::unit_type_id utid = dcon::unit_type_id(i);
586 if(rem_to_build[i] > 0
587 && is_land ==
state.military_definitions.unit_base_definitions[utid].is_land
589 for(int32_t j = 0; j < int32_t(rem_to_build[i]) && j < avail; j++) {
592 if(rem_to_build[i] == 0)
602 auto ab = state.world.province_get_province_naval_construction_as_province(a);
603 auto bb = state.world.province_get_province_naval_construction_as_province(b);
604 int32_t asz = int32_t(ab.end() - ab.begin());
605 int32_t bsz = int32_t(bb.end() - bb.begin());
607 return a.index() < b.index();
611 dcon::unit_type_id utid = dcon::unit_type_id(i);
612 if(rem_to_build[i] > 0
613 && is_land ==
state.military_definitions.unit_base_definitions[utid].is_land
614 && (
state.military_definitions.unit_base_definitions[utid].active ||
state.world.nation_get_active_unit(
state.local_player_nation, utid))) {
617 if(port_level >=
state.military_definitions.unit_base_definitions[utid].min_port_level
620 if(rem_to_build[i] == 0)
626 auto ab = state.world.province_get_province_naval_construction_as_province(a);
627 auto bb = state.world.province_get_province_naval_construction_as_province(b);
628 int32_t asz = int32_t(ab.end() - ab.begin());
629 int32_t bsz = int32_t(bb.end() - bb.begin());
631 return a.index() < b.index();
639 if(rem_to_build[i] > 0) {
640 dcon::unit_type_id utid = dcon::unit_type_id(i);
662 if(
name ==
"background") {
663 return make_element_by_type<draggable_target>(
state,
id);
664 }
else if(
name ==
"close") {
665 return make_element_by_type<generic_close_button>(
state,
id);
666 }
else if(
name ==
"input") {
667 auto ptr = make_element_by_type<macro_builder_name_input>(
state,
id);
668 name_input = ptr.
get();
670 }
else if(
name ==
"template_listbox") {
671 return make_element_by_type<macro_builder_template_listbox>(
state,
id);
672 }
else if(
name ==
"unit_listbox") {
673 return make_element_by_type<macro_builder_unit_listbox>(
state,
id);
674 }
else if(
name ==
"new_template") {
675 return make_element_by_type<macro_builder_new_template_button>(
state,
id);
676 }
else if(
name ==
"save_template") {
677 return make_element_by_type<macro_builder_save_template_button>(
state,
id);
678 }
else if(
name ==
"remove_template") {
679 return make_element_by_type<macro_builder_remove_template_button>(
state,
id);
680 }
else if(
name ==
"set_main") {
681 return make_element_by_type<macro_builder_set_main_template_button>(
state,
id);
682 }
else if(
name ==
"switch_type") {
683 return make_element_by_type<macro_builder_switch_type_button>(
state,
id);
684 }
else if(
name ==
"apply") {
685 return make_element_by_type<macro_builder_apply_button>(
state,
id);
686 }
else if(
name ==
"details") {
687 return make_element_by_type<macro_builder_details>(
state,
id);
704 auto s = std::string(sv);
720 auto window = make_element_by_type<macro_builder_window>(
state,
"alice_macro_builder");
760 auto window = make_element_by_type<message_filters_window>(
state,
"message_filters");
864 auto window = make_element_by_type<main_menu_window>(
state,
"alice_main_menu");
920 const std::string_view mapmode_btn_prefix{
"mapmode_"};
924 if(
name ==
"messagelog_window") {
925 auto ptr = make_element_by_type<message_log_window>(
state,
id);
926 ptr->base_data.position.y += 1;
928 ptr->set_visible(
state,
false);
930 }
else if(
name ==
"minimap_bg") {
931 return make_element_by_type<opaque_element_base>(
state,
id);
932 }
else if(
name ==
"openbutton") {
933 auto ptr = make_element_by_type<minimap_open_message_log_button>(
state,
id);
934 ptr->base_data.position.y += 1;
935 open_btn = ptr.
get();
937 }
else if(
name ==
"menu_button") {
938 return make_element_by_type<minimap_menu_button>(
state,
id);
939 }
else if(
name ==
"button_macro") {
940 return make_element_by_type<minimap_macro_builder_button>(
state,
id);
941 }
else if(
name ==
"button_console") {
942 return make_element_by_type<minimap_console_button>(
state,
id);
943 }
else if(
name ==
"button_goto") {
944 return make_element_by_type<minimap_goto_button>(
state,
id);
945 }
else if(
name ==
"ledger_button") {
946 return make_element_by_type<minimap_ledger_button>(
state,
id);
947 }
else if(
name ==
"map_zoom_in") {
948 return make_element_by_type<minimap_zoom_in_button>(
state,
id);
949 }
else if(
name ==
"map_zoom_out") {
950 return make_element_by_type<minimap_zoom_out_button>(
state,
id);
951 }
else if(
name ==
"menubar_bg") {
953 }
else if(
name ==
"chat_window"
954 ||
name ==
"menubar_mail_bg"
955 ||
name ==
"menubar_msg_settings"
956 ||
name ==
"menubar_msg_combat"
957 ||
name ==
"menubar_msg_diplo"
958 ||
name ==
"menubar_msg_unit"
959 ||
name ==
"menubar_msg_province"
960 ||
name ==
"menubar_msg_event"
961 ||
name ==
"menubar_msg_other"
962 ||
name ==
"menubar_plans_toggle"
963 ||
name ==
"menubar_plans_open") {
964 return make_element_by_type<invisible_element>(
state,
id);
965 }
else if(
name.starts_with(mapmode_btn_prefix)) {
966 auto ptr = make_element_by_type<minimap_mapmode_button>(
state,
id);
967 size_t num_index =
name.rfind(
"_") + 1;
969 for(
size_t i = num_index; i <
name.size(); i++) {
971 num +=
name[i] -
'0';
1014 state.map_state.set_pos(glm::vec2(x, y) / minimap_size);
static void show_toggle(sys::state &state)
void impl_on_update(sys::state &state) noexcept override
virtual void edit_index_position(sys::state &state, int32_t index) noexcept
virtual void render(sys::state &state, int32_t x, int32_t y) noexcept
virtual message_result get(sys::state &state, Cyto::Any &payload) noexcept
void set_visible(sys::state &state, bool vis)
std::vector< uint32_t > row_contents
void update(sys::state &state)
void on_create(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept override
void button_action(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 on_update(sys::state &state) noexcept override
std::string_view get_row_element_name() 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 button_action(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 on_update(sys::state &state) 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 on_create(sys::state &state) noexcept override
message_result get(sys::state &state, Cyto::Any &payload) noexcept override
void on_update(sys::state &state) noexcept override
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 render(sys::state &state, int32_t x, int32_t y) noexcept override
bool get_horizontal_flip(sys::state &state) noexcept override
void render(sys::state &state, int32_t x, int32_t y) noexcept override
message_result on_scroll(sys::state &state, int32_t x, int32_t y, float amount, sys::key_modifiers mods) noexcept override
message_result on_lbutton_down(sys::state &state, int32_t x, int32_t y, sys::key_modifiers mods) noexcept override
text::layout internal_layout
static std::unique_ptr< partially_transparent_image > make_element_by_type_alias(sys::state &state, dcon::gui_def_id id)
void calibrate_scrollbar(sys::state &state) noexcept
multiline_text_element_base * delegate
void set_text(sys::state &state, std::string const &new_text)
text::layout internal_layout
void on_create(sys::state &state) noexcept override
void start_naval_unit_construction(sys::state &state, dcon::nation_id source, dcon::province_id location, dcon::unit_type_id type, dcon::province_id template_province)
bool can_start_land_unit_construction(sys::state &state, dcon::nation_id source, dcon::province_id location, dcon::culture_id soldier_culture, dcon::unit_type_id type, dcon::province_id template_province)
bool can_start_naval_unit_construction(sys::state &state, dcon::nation_id source, dcon::province_id location, dcon::unit_type_id type, dcon::province_id template_province)
void set_map_mode(sys::state &state, mode mode)
int32_t regiments_possible_from_pop(sys::state &state, dcon::pop_id p)
std::string_view remove_surrounding_whitespace(std::string_view txt)
void write_file(directory const &dir, native_string_view file_name, char const *file_data, uint32_t file_size)
directory get_or_create_templates_directory()
std::optional< file > open_file(directory const &dir, native_string_view file_name)
file_contents view_contents(file const &f)
void add_to_layout_box(sys::state &state, layout_base &dest, layout_box &box, embedded_flag ico)
layout_box open_layout_box(layout_base &dest, int32_t indent)
void add_unparsed_text_to_layout_box(sys::state &state, layout_base &dest, layout_box &box, std::string_view sv, substitution_map const &mp)
void localised_format_box(sys::state &state, layout_base &dest, layout_box &box, std::string_view key, text::substitution_map const &sub)
endless_layout create_endless_layout(sys::state &state, layout &dest, layout_parameters const ¶ms)
std::string format_float(float num, size_t digits)
void add_line(sys::state &state, layout_base &dest, dcon::text_key txt, int32_t indent)
void add_line_break_to_layout(sys::state &state, columnar_layout &dest)
void add_to_substitution_map(substitution_map &mp, variable_type key, substitution value)
ankerl::unordered_dense::map< uint32_t, substitution > substitution_map
std::string produce_simple_string(sys::state const &state, dcon::text_key id)
std::string format_percentage(float num, size_t digits)
void close_layout_box(columnar_layout &dest, layout_box &box)
int32_t ui_height(sys::state const &state)
int32_t ui_width(sys::state const &state)
void send(sys::state &state, element_base *parent, T value)
uint8_t amounts[max_types]
static constexpr uint32_t max_types
union ui::element_data::internal_data data
sys::macro_builder_template main_template
element_base * msg_log_window
element_base * search_window
std::vector< sys::macro_builder_template > templates
std::unique_ptr< element_base > root
element_base * macro_builder_window
element_base * msg_filters_window
element_base * ledger_window
sys::macro_builder_template current_template