Project Alice
Loading...
Searching...
No Matches
gui_invest_brow_window.hpp
Go to the documentation of this file.
1#pragma once
2
5
6namespace ui {
7
9public:
10 void on_update(sys::state& state) noexcept override {
11 auto for_nation = retrieve<dcon::nation_id>(state, parent);
12
13 auto for_rules = state.world.nation_get_combined_issue_rules(for_nation);
14
15 if(!nations::is_great_power(state, state.local_player_nation)) {
16 disabled = true;
17 return;
18 }
19 if(nations::is_great_power(state, for_nation) || !state.world.nation_get_is_civilized(for_nation)) {
20 disabled = true;
21 return;
22 }
23 if((for_rules & issue_rule::allow_foreign_investment) == 0) {
24 disabled = true;
25 return;
26 }
27 disabled = false;
28 }
29
30 void button_action(sys::state& state) noexcept override {
31 auto for_nation = retrieve<dcon::nation_id>(state, parent);
32 open_foreign_investment(state, for_nation);
33 }
34};
35
37private:
38 flag_button* country_flag = nullptr;
39
40public:
41 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
42 if(name == "country_select") {
43 return make_element_by_type<production_investment_country_select>(state, id);
44 } else if(name == "country_flag") {
45 auto ptr = make_element_by_type<flag_button>(state, id);
46 ptr->base_data.position.y -= 2; // Nudge
47 country_flag = ptr.get();
48 return ptr;
49 } else if(name == "country_name") {
50 return make_element_by_type<generic_name_text<dcon::nation_id>>(state, id);
51 } else if(name == "invest") {
52 auto ptr = make_element_by_type<nation_player_investment_text>(state, id);
53 ptr->base_data.position.x -= 4;
54 return ptr;
55 } else if(name == "factories") {
56 return make_element_by_type<nation_industries_text>(state, id);
57 } else if(name == "country_boss_flag") {
58 auto ptr = make_element_by_type<nation_overlord_flag>(state, id);
59 ptr->base_data.position.y -= 2; // Nudge
60 return ptr;
61 } else if(name == "country_prestige") {
62 return make_element_by_type<nation_prestige_rank_text>(state, id);
63 } else if(name == "country_economic") {
64 return make_element_by_type<nation_industry_rank_text>(state, id);
65 } else if(name == "country_military") {
66 return make_element_by_type<nation_military_rank_text>(state, id);
67 } else if(name == "country_total") {
68 return make_element_by_type<nation_rank_text>(state, id);
69 } else if(name == "country_opinion") {
70 return make_element_by_type<nation_player_opinion_text>(state, id);
71 } else if(name == "country_relation") {
72 return make_element_by_type<nation_player_relations_text>(state, id);
73 } else if(name.substr(0, 10) == "country_gp") {
74 auto ptr = make_element_by_type<nation_gp_investment_text>(state, id);
75 ptr->rank = uint16_t(std::stoi(std::string{name.substr(10)}));
76 ptr->base_data.position.x -= 4;
77 return ptr;
78 } else {
79 return nullptr;
80 }
81 }
82
83 message_result get(sys::state& state, Cyto::Any& payload) noexcept override {
84 if(payload.holds_type<dcon::nation_id>()) {
85 payload.emplace<dcon::nation_id>(content);
87 } else if(payload.holds_type<button_press_notification>()) {
88 Cyto::Any new_payload = content;
89 return parent->impl_get(state, new_payload);
90 } else {
92 }
93 }
94};
95
96class production_country_listbox : public listbox_element_base<production_investment_country_info, dcon::nation_id> {
97protected:
98 std::string_view get_row_element_name() override {
99 return "investment_country_entry";
100 }
101
102 void on_update(sys::state& state) noexcept override {
103 auto current_filter = retrieve< country_filter_setting>(state, parent);
104 auto current_sort = retrieve<country_sort_setting>(state, parent);
105 row_contents.clear();
106 state.world.for_each_nation([&](dcon::nation_id id) {
107 if(state.world.nation_get_owned_province_count(id) != 0) {
108 bool passes_filter = country_category_filter_check(state, current_filter.general_category, state.local_player_nation, id);
109 bool right_continent = !current_filter.continent || state.world.nation_get_capital(id).get_continent() == current_filter.continent;
110
111 if(passes_filter && right_continent)
112 row_contents.push_back(id);
113 }
114 });
115 sort_countries(state, row_contents, current_sort.sort, current_sort.sort_ascend);
116 update(state);
117 }
118};
119
121public:
122 void button_action(sys::state& state) noexcept override {
124 }
125};
126
128public:
129 dcon::national_identity_id get_current_nation(sys::state& state) noexcept override {
130 return state.world.nation_get_identity_from_identity_holder(state.local_player_nation);
131 }
134 }
135 void button_action(sys::state& state) noexcept override { }
136};
137
139 production_country_listbox* country_listbox = nullptr;
142
143public:
144 void on_create(sys::state& state) noexcept override {
146 set_visible(state, false);
147 country_listbox->list_scrollbar->base_data.position.x += 13;
148 }
149
150 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
151 if(name == "country_listbox") {
152 auto ptr = make_element_by_type<production_country_listbox>(state, id);
153 ptr->base_data.position.x -= 8 + 5; // Nudge
154 country_listbox = ptr.get();
155 return ptr;
156 } else if(name == "sort_by_my_flag") {
157 auto ptr = make_element_by_type<production_sort_my_nation_flag>(state, id);
158 ptr->base_data.position.y -= 2; // Nudge
159 return ptr;
160 } else if(name == "sort_by_country") {
161 auto ptr = make_element_by_type<country_sort_button<country_list_sort::country>>(state, id);
162 ptr->base_data.position.y -= 1; // Nudge
163 return ptr;
164 } else if(name == "sort_by_boss") {
165 auto ptr = make_element_by_type<country_sort_button<country_list_sort::boss>>(state, id);
166 ptr->base_data.position.y -= 1; // Nudge
167 return ptr;
168 } else if(name == "sort_by_prestige") {
169 auto ptr = make_element_by_type<country_sort_button<country_list_sort::prestige_rank>>(state, id);
170 ptr->base_data.position.y -= 1; // Nudge
171 return ptr;
172 } else if(name == "sort_by_economic") {
173 auto ptr = make_element_by_type<country_sort_button<country_list_sort::economic_rank>>(state, id);
174 ptr->base_data.position.y -= 1; // Nudge
175 return ptr;
176 } else if(name == "sort_by_military") {
177 auto ptr = make_element_by_type<country_sort_button<country_list_sort::military_rank>>(state, id);
178 ptr->base_data.position.y -= 1; // Nudge
179 return ptr;
180 } else if(name == "sort_by_total") {
181 auto ptr = make_element_by_type<country_sort_button<country_list_sort::total_rank>>(state, id);
182 ptr->base_data.position.y -= 1; // Nudge
183 return ptr;
184 } else if(name == "sort_by_relation") {
185 auto ptr = make_element_by_type<country_sort_button<country_list_sort::relation>>(state, id);
186 ptr->base_data.position.y -= 1; // Nudge
187 return ptr;
188 } else if(name == "sort_by_opinion") {
189 return make_element_by_type<country_sort_button<country_list_sort::opinion>>(state, id);
190 } else if(name == "sort_by_prio") {
191 return make_element_by_type<country_sort_button<country_list_sort::priority>>(state, id);
192 } else if(name == "filter_all") {
193 return make_element_by_type<category_filter_button<country_list_filter::all>>(state, id);
194 } else if(name == "filter_enemies") {
195 return make_element_by_type<category_filter_button<country_list_filter::enemies>>(state, id);
196 } else if(name == "filter_allies") {
197 return make_element_by_type<category_filter_button<country_list_filter::allies>>(state, id);
198 } else if(name == "filter_neighbours") {
199 return make_element_by_type<category_filter_button<country_list_filter::neighbors>>(state, id);
200 } else if(name == "filter_sphere") {
201 return make_element_by_type<category_filter_button<country_list_filter::sphere>>(state, id);
202 } else if(name == "sort_by_invest_factories") {
203 auto ptr = make_element_by_type<country_sort_button<country_list_sort::factories>>(state, id);
204 ptr->base_data.position.y -= 1; // Nudge
205 return ptr;
206 } else if(name.length() >= 7 && name.substr(0, 7) == "filter_") {
207 auto const filter_name = name.substr(7);
208 auto ptr = make_element_by_type<continent_filter_button>(state, id);
209 auto k = state.lookup_key(name);
210 if(k) {
211 for(auto m : state.world.in_modifier) {
212 if(m.get_name() == k) {
213 ptr->continent = m;
214 break;
215 }
216 }
217 }
218 return ptr;
219 } else if(name.substr(0, 14) == "sort_by_gpflag") {
220 auto ptr = make_element_by_type<production_sort_nation_gp_flag>(state, id);
221 ptr->rank = uint16_t(std::stoi(std::string{name.substr(14)}));
222 ptr->base_data.position.y -= 2; // Nudge
223 return ptr;
224 } else if(name.substr(0, 10) == "sort_by_gp") {
225 auto ptr = make_element_by_type<country_sort_button<country_list_sort::gp_investment>>(state, id);
226 ptr->offset = uint8_t(std::stoi(std::string{name.substr(10)}));
227 return ptr;
228 } else if(name == "sort_by_my_invest") {
229 return make_element_by_type<country_sort_by_player_investment>(state, id);
230 } else {
231 return nullptr;
232 }
233 }
234
235 message_result get(sys::state& state, Cyto::Any& payload) noexcept override {
236 if(payload.holds_type<country_sort_setting>()) {
237 payload.emplace<country_sort_setting>(sort);
239 } else if(payload.holds_type< country_filter_setting>()) {
240 payload.emplace<country_filter_setting>(filter);
242 } else if(payload.holds_type<element_selection_wrapper<country_list_sort>>()) {
243 auto new_sort = any_cast<element_selection_wrapper<country_list_sort>>(payload).data;
244 sort.sort_ascend = (new_sort == sort.sort) ? !sort.sort_ascend : true;
245 sort.sort = new_sort;
246 country_listbox->impl_on_update(state);
248 } else if(payload.holds_type<country_list_filter>()) {
249 auto temp = any_cast<country_list_filter>(payload);
250 filter.general_category = filter.general_category != temp ? temp : country_list_filter::all;
251 country_listbox->impl_on_update(state);
253 } else if(payload.holds_type<dcon::modifier_id>()) {
254 auto temp_c = any_cast<dcon::modifier_id>(payload);
255 filter.continent = filter.continent == temp_c ? dcon::modifier_id{} : temp_c;
256 country_listbox->impl_on_update(state);
258 }
260 }
261};
262
263} // 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
message_result impl_get(sys::state &state, Cyto::Any &payload) noexcept
element_data base_data
void set_visible(sys::state &state, bool vis)
message_result get(sys::state &state, Cyto::Any &payload) noexcept override
void on_create(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
standard_listbox_scrollbar< RowWinT, RowConT > * list_scrollbar
message_result get(sys::state &state, Cyto::Any &payload) noexcept override
void on_update(sys::state &state) noexcept override
std::string_view get_row_element_name() 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 button_action(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
dcon::national_identity_id get_current_nation(sys::state &state) noexcept override
void button_action(sys::state &state) noexcept override
void on_create(sys::state &state) noexcept override
constexpr uint32_t allow_foreign_investment
Definition: culture.hpp:26
bool is_great_power(sys::state const &state, dcon::nation_id id)
Definition: nations.cpp:503
void sort_countries(sys::state &state, std::vector< dcon::nation_id > &list, country_list_sort sort, bool sort_ascend)
tooltip_behavior
void send(sys::state &state, element_base *parent, T value)
message_result
void open_foreign_investment(sys::state &state, dcon::nation_id n)
uchar uint8_t