Project Alice
Loading...
Searching...
No Matches
gui_military_window.hpp
Go to the documentation of this file.
1#pragma once
2
8
9namespace ui {
10
12public:
13 void button_action(sys::state& state) noexcept override {
14 command::toggle_mobilization(state, state.local_player_nation);
15 }
16
17 void button_right_action(sys::state& state) noexcept override {
18 auto n = retrieve<dcon::nation_id>(state, parent);
21 }
22
23 void on_update(sys::state& state) noexcept override {
24 auto n = retrieve<dcon::nation_id>(state, parent);
25 if(state.world.nation_get_is_mobilized(n)) {
27 } else {
29 }
30 }
31
34 }
35
36 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
37 auto n = retrieve<dcon::nation_id>(state, parent);
38 active_modifiers_description(state, contents, n, 0, sys::national_mod_offsets::mobilization_impact, true);
39 active_modifiers_description(state, contents, n, 0, sys::national_mod_offsets::mobilization_size, true);
40 text::add_line(state, contents, "alice_mob_controls");
41 }
42};
43
45public:
46 void on_update(sys::state& state) noexcept override {
47 auto n = state.local_player_nation;
48 if(state.world.nation_get_is_mobilized(n) == false) {
49 progress = 0.0f;
50 return;
51 }
52 int32_t cur_mobilization = 0;
53 for(const auto ac : state.world.nation_get_army_control_as_controller(n)) {
54 for(const auto am : ac.get_army().get_army_membership()) {
55 auto pop = am.get_regiment().get_pop_from_regiment_source();
56 if(pop.get_poptype() != state.culture_definitions.soldiers
57 && pop.get_poptype() != state.culture_definitions.slaves
58 && pop.get_is_primary_or_accepted_culture()
59 && pop.get_poptype().get_strata() == uint8_t(culture::pop_strata::poor)) {
60 cur_mobilization += int32_t(pop.get_size() * military::mobilization_size(state, n) / state.defines.pop_size_per_regiment);
61 }
62 }
63 }
64 int32_t rem_mobilization = 0;
65 auto schedule_array = state.world.nation_get_mobilization_schedule(n);
66 for(const auto s : schedule_array) {
67 for(const auto pl : state.world.province_get_pop_location(s.where)) {
68 auto pop = pl.get_pop();
69 if(pop.get_poptype() != state.culture_definitions.soldiers
70 && pop.get_poptype() != state.culture_definitions.slaves
71 && pop.get_is_primary_or_accepted_culture()
72 && pop.get_poptype().get_strata() == uint8_t(culture::pop_strata::poor)) {
73 rem_mobilization += int32_t(pop.get_size() * military::mobilization_size(state, n) / state.defines.pop_size_per_regiment);
74 }
75 }
76 }
77 int32_t total_mobilization = cur_mobilization + rem_mobilization;
78 if(total_mobilization == 0) {
79 progress = 1.f;
80 return;
81 }
82 progress = float(cur_mobilization) / float(total_mobilization);
83 }
84};
85
87public:
88 void on_update(sys::state& state) noexcept override {
89 auto n = state.local_player_nation;
90 if(state.world.nation_get_is_mobilized(n) == false) {
91 set_text(state, "0%");
92 return;
93 }
94 int32_t cur_mobilization = 0;
95 for(const auto ac : state.world.nation_get_army_control_as_controller(n)) {
96 for(const auto am : ac.get_army().get_army_membership()) {
97 auto pop = am.get_regiment().get_pop_from_regiment_source();
99 cur_mobilization += int32_t(pop.get_size() * military::mobilization_size(state, n) / state.defines.pop_size_per_regiment);
100 }
101 }
102 }
103 int32_t rem_mobilization = 0;
104 auto schedule_array = state.world.nation_get_mobilization_schedule(n);
105 for(const auto s : schedule_array) {
106 for(const auto pl : state.world.province_get_pop_location(s.where)) {
107 auto pop = pl.get_pop();
109 rem_mobilization += int32_t(pop.get_size() * military::mobilization_size(state, n) / state.defines.pop_size_per_regiment);
110 }
111 }
112 }
113 int32_t total_mobilization = cur_mobilization + rem_mobilization;
114 if(total_mobilization == 0) {
115 set_text(state, "100%");
116 return;
117 }
118 set_text(state, text::format_percentage(float(cur_mobilization) / float(total_mobilization), 0));
119 }
122 }
123
124 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
125 text::add_line(state, contents, "mobilization_progress_not_mobilized");
126 }
127};
128
130public:
131 void on_update(sys::state& state) noexcept override {
132 auto real_regs = std::max(int32_t(state.world.nation_get_recruitable_regiments(state.local_player_nation)), int32_t(state.defines.min_mobilize_limit));
133 auto mob_size = std::min(int32_t(real_regs * state.world.nation_get_modifier_values(state.local_player_nation, sys::national_mod_offsets::mobilization_impact)), military::mobilized_regiments_pop_limit(state, state.local_player_nation));
134 set_text(state, std::to_string(mob_size));
135 }
136
139 }
140
141 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
142 auto n = retrieve<dcon::nation_id>(state, parent);
143 active_modifiers_description(state, contents, n, 0, sys::national_mod_offsets::mobilization_size, false);
144 }
145};
146
148public:
149 void on_update(sys::state& state) noexcept override {
150 auto v = 1.0f - military::mobilization_impact(state, state.local_player_nation);
152 }
153
154 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
155 auto n = retrieve<dcon::nation_id>(state, parent);
156 active_modifiers_description(state, contents, n, 0, sys::national_mod_offsets::mobilization_impact, false);
157 }
158};
159
161public:
162 bool is_active(sys::state& state) noexcept override {
163 return state.world.nation_get_mobilized_is_ai_controlled(state.local_player_nation);
164 }
167 }
168 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
169 text::add_line(state, contents, "alice_mobilized_is_ai_controlled");
170 text::add_line(state, contents, "alice_ai_controlled_unit");
171 }
172 void button_action(sys::state& state) noexcept override {
174 }
175};
176
178public:
179 void on_create(sys::state& state) noexcept override {
181 state.ui_state.military_subwindow = this;
182
183 // Unit information comes first
184 auto win1 = make_element_by_type<military_units_window<dcon::army_id>>(state,
185 state.ui_state.defs_by_name.find(state.lookup_key("unit_window"))->second.definition);
186 win1->base_data.position = state.ui_defs.gui[state.ui_state.defs_by_name.find(state.lookup_key("army_pos"))->second.definition].position;
187 state.ui_state.unit_window_army = win1.get();
188 add_child_to_front(std::move(win1));
189
190 // Navy information is right next to the army information
191 auto win2 = make_element_by_type<military_units_window<dcon::navy_id>>(state,
192 state.ui_state.defs_by_name.find(state.lookup_key("unit_window"))->second.definition);
193 win2->base_data.position = state.ui_defs.gui[state.ui_state.defs_by_name.find(state.lookup_key("navy_pos"))->second.definition].position;
194 state.ui_state.unit_window_navy = win2.get();
195 add_child_to_front(std::move(win2));
196
197 auto miac_btn = make_element_by_type<military_mobilized_is_ai_controlled>(state, state.ui_state.defs_by_name.find(state.lookup_key("alice_military_mobilized_is_ai_controlled"))->second.definition);
198 add_child_to_front(std::move(miac_btn));
199
200 auto build_units_window = make_element_by_type<build_unit_large_window>(state,
201 state.ui_state.defs_by_name.find(state.lookup_key("build_unit_view_large"))->second.definition);
202 build_units_window->base_data.position.y -= 63;
203 build_units_window->base_data.position.x += 1;
204 state.ui_state.build_unit_window = build_units_window.get();
205 build_units_window->set_visible(state, false);
206 add_child_to_front(std::move(build_units_window));
207
208 set_visible(state, false);
209 }
210
211 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
212 if(name == "main_bg") {
213 return make_element_by_type<image_element_base>(state, id);
214 } else if(name == "bg_military") {
215 return make_element_by_type<opaque_element_base>(state, id);
216 } else if(name == "headline_military") {
217 return make_element_by_type<simple_text_element_base>(state, id);
218 } else if(name == "close_button") {
219 return make_element_by_type<generic_close_button>(state, id);
220 } else if(name == "icon_army") {
221 return make_element_by_type<image_element_base>(state, id);
222 } else if(name == "icon_navy") {
223 return make_element_by_type<image_element_base>(state, id);
224 } else if(name == "mobilize") {
225 return make_element_by_type<military_mob_button>(state, id);
226 } else if(name == "demobilize") {
227 return make_element_by_type<invisible_element>(state, id);
228 } else if(name == "mobilize_progress") {
229 return make_element_by_type<military_mob_progress_bar>(state, id);
230 } else if(name == "mobilize_progress_frame") {
231 return make_element_by_type<image_element_base>(state, id);
232 } else if(name == "mobilize_progress_text") {
233 return make_element_by_type<military_mob_progress_bar_text>(state, id);
234 } else if(name == "mob_size_label") {
235 return make_element_by_type<simple_text_element_base>(state, id);
236 } else if(name == "mob_size") {
237 return make_element_by_type<military_mob_size_text>(state, id);
238 } else if(name == "mob_impact_label") {
239 return make_element_by_type<simple_text_element_base>(state, id);
240 } else if(name == "mob_impact") {
241 return make_element_by_type<military_mob_impact_text>(state, id);
242 } else if(name == "leaders") {
243 return make_element_by_type<leaders_window>(state, id);
244 } else if(name == "stats") {
245 return make_element_by_type<stats_window>(state, id);
246 } else {
247 return nullptr;
248 }
249 }
250
251 message_result get(sys::state& state, Cyto::Any& payload) noexcept override {
252 if(payload.holds_type<dcon::nation_id>()) {
253 payload.emplace<dcon::nation_id>(state.local_player_nation);
255 }
257 }
258};
259
260} // namespace ui
void set_button_text(sys::state &state, std::string const &new_text)
void add_child_to_front(std::unique_ptr< element_base > child) noexcept final
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)
tooltip_behavior has_tooltip(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept override
void button_action(sys::state &state) noexcept override
void button_right_action(sys::state &state) noexcept override
void update_tooltip(sys::state &state, int32_t x, int32_t y, text::columnar_layout &contents) noexcept override
void 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
tooltip_behavior has_tooltip(sys::state &state) noexcept override
void update_tooltip(sys::state &state, int32_t x, int32_t y, text::columnar_layout &contents) noexcept override
void on_update(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
tooltip_behavior has_tooltip(sys::state &state) noexcept override
void button_action(sys::state &state) noexcept override
tooltip_behavior has_tooltip(sys::state &state) noexcept override
void update_tooltip(sys::state &state, int32_t x, int32_t y, text::columnar_layout &contents) noexcept override
bool is_active(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 on_create(sys::state &state) noexcept override
void set_text(sys::state &state, std::string const &new_text)
void on_create(sys::state &state) noexcept override
float mobilization_size(sys::state const &state, dcon::nation_id n)
Definition: military.cpp:1156
float mobilization_impact(sys::state const &state, dcon::nation_id n)
Definition: military.cpp:1160
bool pop_eligible_for_mobilization(sys::state &state, dcon::pop_id p)
Definition: military.cpp:7450
int32_t mobilized_regiments_pop_limit(sys::state &state, dcon::nation_id n)
Definition: military.cpp:988
void add_line(sys::state &state, layout_base &dest, dcon::text_key txt, int32_t indent)
Definition: text.cpp:1899
std::string produce_simple_string(sys::state const &state, dcon::text_key id)
Definition: text.cpp:617
std::string format_percentage(float num, size_t digits)
Definition: text.cpp:977
tooltip_behavior
message_result
void active_modifiers_description(sys::state &state, text::layout_base &layout, dcon::nation_id n, int32_t identation, dcon::national_modifier_value nmid, bool header)
uchar uint8_t
element_base * military_subwindow
element_base * unit_window_army
element_base * unit_window_navy
ankerl::unordered_dense::map< dcon::text_key, element_target, hash_text_key > defs_by_name
element_base * build_unit_window