Project Alice
Loading...
Searching...
No Matches
gui_foreign_investment_window.hpp
Go to the documentation of this file.
1#pragma once
2
6
7namespace ui {
8
10 void on_update(sys::state& state) noexcept override {
11 auto to_nation = retrieve<dcon::nation_id>(state, parent);
12
13 auto ul = state.world.get_unilateral_relationship_by_unilateral_pair(to_nation, state.local_player_nation);
14 auto player_investment = state.world.unilateral_relationship_get_foreign_investment(ul);
15 float total_investment = nations::get_foreign_investment(state, to_nation);
20 text::add_line(state, container, "production_our_invest", text::variable_type::amount, text::pretty_integer{int64_t(player_investment)}, text::variable_type::percentage, text::fp_one_place{total_investment > 0.f ? 100.0f * player_investment / total_investment : 0.0f});
21 }
22
23 tooltip_behavior has_tooltip(sys::state& state) noexcept override {
25 }
26
27 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
28
29 auto to_nation = retrieve<dcon::nation_id>(state, parent);
30
31 if(auto sl = state.world.nation_get_in_sphere_of(to_nation); sl) {
32
33 auto ul = state.world.get_unilateral_relationship_by_unilateral_pair(to_nation, sl);
34 auto sl_investment = state.world.unilateral_relationship_get_foreign_investment(ul);
35
36 float total_investment = nations::get_foreign_investment(state, to_nation);
37 float base = state.world.nation_get_rank(to_nation) <= state.defines.colonial_rank
38 ? state.defines.second_rank_base_share_factor
39 : state.defines.civ_base_share_factor;
40 float investment_fraction = total_investment > 0.0001f ? sl_investment / total_investment : 0.0f;
41 auto share = base + (1.0f - base) * investment_fraction;
42
43 if(!state.world.nation_get_is_civilized(to_nation)) {
44 text::add_line(state, contents, "sphere_share_unciv", text::variable_type::percentage,
45 int64_t(100.0f * state.defines.unciv_base_share_factor));
46 } else if(state.world.nation_get_rank(to_nation) <= state.defines.colonial_rank) {
47 text::add_line(state, contents, "sphere_share_2ndrank", text::variable_type::percentage, int64_t(100.0f * share),
48 text::variable_type::base_percentage, int64_t(100.0f * state.defines.second_rank_base_share_factor));
49 } else {
50 text::add_line(state, contents, "sphere_share_civ", text::variable_type::percentage, int64_t(100.0f * share),
51 text::variable_type::base_percentage, int64_t(100.0f * state.defines.civ_base_share_factor));
52 }
53 } else {
54 text::add_line(state, contents, "sphere_share_not_in_sphere");
55 }
56 }
57};
58
60 void button_action(sys::state& state) noexcept override {
62 }
63};
64
66public:
67 uint16_t rank = 0;
68 void on_update(sys::state& state) noexcept override {
70 auto to_nation = retrieve<dcon::nation_id>(state, parent);
71
72 auto ul = state.world.get_unilateral_relationship_by_unilateral_pair(to_nation, nat_id);
73 auto investment = state.world.unilateral_relationship_get_foreign_investment(ul);
74
75 set_text(state, text::format_money(investment));
76 }
77 void render(sys::state& state, int32_t x, int32_t y) noexcept override {
79 }
80};
81
82
84public:
85 dcon::nation_id curr_nation{};
86
87public:
88 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
89 if(name == "prod_investment_bg") {
90 return make_element_by_type<image_element_base>(state, id);
91 } else if(name == "country_flag") {
92 return make_element_by_type<flag_button>(state, id);
93 } else if(name == "country_flag_overlay") {
94 return make_element_by_type<nation_flag_frame>(state, id);
95 } else if(name == "country_name") {
96 return make_element_by_type<generic_name_text<dcon::nation_id>>(state, id);
97 } else if(name == "country_investment") {
98 return make_element_by_type<player_investement_text>(state, id);
99 } else if(name == "invest_country_browse") {
100 return make_element_by_type<close_investments>(state, id);
101 } else if(name == "select_all") {
102 return make_element_by_type<factory_select_all_button>(state, id);
103 } else if(name == "deselect_all") {
104 return make_element_by_type<factory_deselect_all_button>(state, id);
105 } else if(name == "show_empty_states") {
106 return make_element_by_type<factory_show_empty_states_button>(state, id);
107 } else if(name == "sort_by_name") {
108 return make_element_by_type<button_element_base>(state, id);
109 } else if(name == "sort_by_factories") {
110 return make_element_by_type<button_element_base>(state, id);
111 } else if(name == "sort_by_infra") {
112 return make_element_by_type<button_element_base>(state, id);
113 } else if(name == "filter_bounds") {
114 return make_element_by_type<commodity_filters_window>(state, id);
115 } else {
116 return nullptr;
117 }
118 }
119
120 // 134 x 50
121 // 450 x x-off
122 // nation_gp_flag
123 /*
124
125 if(subwindow_width <= 0) {
126 subwindow_width = ptr->base_data.size.x;
127 }
128 windows.push_back(static_cast<ItemWinT*>(ptr.get()));
129 add_child_to_front(std::move(ptr));
130 */
131 //"flag_list_flag";
132 void on_create(sys::state& state) noexcept override {
133 for(int32_t i = 0; i < 4; ++i) {
134 {
135 auto ptr = make_element_by_type<nation_gp_flag>(state, "flag_list_flag");
136 static_cast<nation_gp_flag*>(ptr.get())->rank = uint16_t(i);
137 ptr->base_data.position.x = int16_t(134 * i + 460);
138 ptr->base_data.position.y = int16_t(15 + 55);
139 add_child_to_back(std::move(ptr));
140 }
141 {
142 auto ptr = make_element_by_type<gp_investment_text>(state, "alice_investment_text");
143 static_cast<gp_investment_text*>(ptr.get())->rank = uint16_t(i);
144 ptr->base_data.position.x = int16_t(134 * i + 460 + 25);
145 ptr->base_data.position.y = int16_t(15 + 55);
146 add_child_to_back(std::move(ptr));
147 }
148 }
149 for(int32_t i = 4; i < 8; ++i) {
150 {
151 auto ptr = make_element_by_type<nation_gp_flag>(state, "flag_list_flag");
152 static_cast<nation_gp_flag*>(ptr.get())->rank = uint16_t(i);
153 ptr->base_data.position.x = int16_t(134 * (i - 4) + 460);
154 ptr->base_data.position.y = int16_t(15 + 50 + 55);
155 add_child_to_back(std::move(ptr));
156 }
157 {
158 auto ptr = make_element_by_type<gp_investment_text>(state, "alice_investment_text");
159 static_cast<gp_investment_text*>(ptr.get())->rank = uint16_t(i);
160 ptr->base_data.position.x = int16_t(134 * (i - 4) + 460 + 25);
161 ptr->base_data.position.y = int16_t(15 + 50 + 55);
162 add_child_to_back(std::move(ptr));
163 }
164 }
165
166
167 xy_pair base_sort_template_offset =
168 state.ui_defs.gui[state.ui_state.defs_by_name.find(state.lookup_key("sort_by_pop_template_offset"))->second.definition].position;
169 xy_pair sort_template_offset = base_sort_template_offset;
170 sort_template_offset.y += 233;
171
172 auto ptr = make_element_by_type<button_element_base>(state,
173 state.ui_state.defs_by_name.find(state.lookup_key("sort_by_pop_template"))->second.definition);
174 ptr->set_button_text(state,
175 text::produce_simple_string(state, state.world.pop_type_get_name(state.culture_definitions.primary_factory_worker)));
176 sort_template_offset.x = 478 + base_sort_template_offset.x * 0;
177 ptr->base_data.position = sort_template_offset;
178 add_child_to_back(std::move(ptr));
179
180 auto ptr2 = make_element_by_type<button_element_base>(state,
181 state.ui_state.defs_by_name.find(state.lookup_key("sort_by_pop_template"))->second.definition);
182 ptr2->set_button_text(state,
183 text::produce_simple_string(state, state.world.pop_type_get_name(state.culture_definitions.secondary_factory_worker)));
184 sort_template_offset.x = 478 + base_sort_template_offset.x * 1;
185 ptr2->base_data.position = sort_template_offset;
186 add_child_to_back(std::move(ptr2));
187
188 auto ptr3 = make_element_by_type<button_element_base>(state,
189 state.ui_state.defs_by_name.find(state.lookup_key("sort_by_pop_template"))->second.definition);
190 ptr3->set_button_text(state,
191 text::produce_simple_string(state, state.world.pop_type_get_name(state.culture_definitions.capitalists)));
192 sort_template_offset.x = 478 + base_sort_template_offset.x * 2;
193 ptr3->base_data.position = sort_template_offset;
194 add_child_to_back(std::move(ptr3));
195
197 }
198
199 message_result get(sys::state& state, Cyto::Any& payload) noexcept override {
200 if(payload.holds_type<element_selection_wrapper<dcon::nation_id>>()) {
201 curr_nation = any_cast<element_selection_wrapper<dcon::nation_id>>(payload).data;
203 } else if(payload.holds_type<dcon::nation_id>()) {
204 payload = curr_nation;
206 }
208 }
209};
210
211} // namespace ui
void add_child_to_back(std::unique_ptr< element_base > child) noexcept final
element_base * parent
element_data base_data
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
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 render(sys::state &state, int32_t x, int32_t y) noexcept override
void set_text(sys::state &state, std::string const &new_text)
void on_create(sys::state &state) noexcept override
float get_foreign_investment(sys::state &state, dcon::nation_id n)
Definition: nations.cpp:314
dcon::nation_id get_nth_great_power(sys::state const &state, uint16_t n)
Definition: nations.cpp:57
std::string format_money(float num)
Definition: text.cpp:1029
endless_layout create_endless_layout(sys::state &state, layout &dest, layout_parameters const &params)
Definition: text.cpp:1100
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
tooltip_behavior
void send(sys::state &state, element_base *parent, T value)
message_result
union ui::element_data::internal_data data
ankerl::unordered_dense::map< dcon::text_key, element_target, hash_text_key > defs_by_name