Project Alice
Loading...
Searching...
No Matches
gui_trade_window.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "dcon_generated.hpp"
4#include "economy.hpp"
7#include "widgets/table.hpp"
8
9namespace ui {
10
12 dcon::commodity_id commodity_id{};
13};
15 dcon::commodity_id commodity_id{};
16};
17
19public:
20 void on_update(sys::state& state) noexcept override {
21 auto com = retrieve<dcon::commodity_id>(state, parent);
22 if(state.world.nation_get_drawing_on_stockpiles(state.local_player_nation, com)) {
23 if(state.world.nation_get_stockpiles(state.local_player_nation, com) > 0)
24 frame = 2;
25 else
26 frame = 0;
27 } else if(state.world.nation_get_stockpiles(state.local_player_nation, com) < state.world.nation_get_stockpile_targets(state.local_player_nation, com)) {
28 frame = 1;
29 } else {
30 frame = 0;
31 }
32 }
33
35 auto com = retrieve<dcon::commodity_id>(state, parent);
36 if(state.world.nation_get_drawing_on_stockpiles(state.local_player_nation, com)) {
38 } else if(state.world.nation_get_stockpiles(state.local_player_nation, com) < state.world.nation_get_stockpile_targets(state.local_player_nation, com)) {
40 } else {
42 }
43
44 }
45
46 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
47 auto com = retrieve<dcon::commodity_id>(state, parent);
48 if(state.world.nation_get_drawing_on_stockpiles(state.local_player_nation, com)) {
49 if(state.world.nation_get_stockpiles(state.local_player_nation, com) > 0)
50 text::add_line(state, contents, "trade_setting_drawing");
51 } else if(state.world.nation_get_stockpiles(state.local_player_nation, com) < state.world.nation_get_stockpile_targets(state.local_player_nation, com)) {
52 text::add_line(state, contents, "trade_setting_filling");
53 } else {
54
55 }
56 }
57};
58
60public:
61 void on_update(sys::state& state) noexcept override {
62 auto com = retrieve<dcon::commodity_id>(state, parent);
63 auto current_price = state.world.commodity_get_price_record(com, (state.ui_date.value >> 4) % economy::price_history_length);
64 auto previous_price = state.world.commodity_get_price_record(com, ((state.ui_date.value >> 4) + economy::price_history_length - 1) % economy::price_history_length);
65 if(current_price > previous_price) {
66 frame = 0;
67 } else if(current_price < previous_price) {
68 frame = 2;
69 } else {
70 frame = 1;
71 }
72 }
73};
74
76public:
77 dcon::commodity_id trade_good;
78 enum class type : uint8_t {
79 factory,
81 pop,
84 } type{};
86 union {
87 dcon::factory_id factory_id; // factory
88 dcon::province_id province_id; // province
89 dcon::province_id pop_province_id; // pop
90 dcon::army_id army_id; // army
91 dcon::navy_id navy_id; // navy
92 } data{};
93
94 bool operator==(trade_flow_data const& o) const {
95 if(value_type != o.value_type)
96 return false;
97
98 switch(type) {
99 case type::factory:
100 if(o.type != type::factory)
101 return false;
102 return data.factory_id == o.data.factory_id;
103 case type::province:
104 if(o.type != type::province)
105 return false;
106 return data.province_id == o.data.province_id;
107 case type::pop:
108 if(o.type != type::pop)
109 return false;
110 return data.pop_province_id == o.data.pop_province_id;
113 return false;
114 return data.army_id == o.data.army_id;
117 return false;
118 return data.navy_id == o.data.navy_id;
119 default:
120 return true;
121 }
122 }
123 bool operator!=(trade_flow_data const& o) const {
124 return !(*this == o);
125 }
126};
127class trade_flow_entry : public listbox_row_element_base<trade_flow_data> {
128 image_element_base* icon = nullptr;
129 simple_text_element_base* title = nullptr;
130 simple_text_element_base* value = nullptr;
131 image_element_base* output_icon = nullptr;
132
133public:
134 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
135 if(name == "icon") {
136 auto ptr = make_element_by_type<image_element_base>(state, id);
137 icon = ptr.get();
138 return ptr;
139 } else if(name == "title") {
140 auto ptr = make_element_by_type<simple_text_element_base>(state, id);
141 title = ptr.get();
142 return ptr;
143 } else if(name == "value") {
144 auto ptr = make_element_by_type<simple_text_element_base>(state, id);
145 value = ptr.get();
146 return ptr;
147 } else if(name == "output_icon") {
148 auto ptr = make_element_by_type<image_element_base>(state, id);
149 output_icon = ptr.get();
150 return ptr;
151 } else {
152 return nullptr;
153 }
154 }
155
156 void on_update(sys::state& state) noexcept override {
157 auto commodity_id = retrieve<dcon::commodity_id>(state, parent);
158
159 icon->frame = int32_t(content.type);
162
165 float amount = 0.f;
166 switch(content.type) {
168 auto fid = content.data.factory_id;
169 auto ftid = state.world.factory_get_building_type(fid);
170 switch(content.value_type) {
172 amount += state.world.factory_get_actual_production(fid);
173 } break;
175 auto& inputs = state.world.factory_type_get_inputs(ftid);
176 for(uint32_t i = 0; i < inputs.set_size; ++i)
177 if(inputs.commodity_type[i] == commodity_id)
178 amount += inputs.commodity_amounts[i];
179 output_icon->frame = state.world.commodity_get_icon(state.world.factory_type_get_output(ftid));
180 } break;
182 output_icon->frame = state.world.commodity_get_icon(state.world.factory_type_get_output(ftid));
183 break;
184 default:
185 break;
186 }
187 auto name = state.world.factory_type_get_name(ftid);
188 title->set_text(state, text::produce_simple_string(state, name));
189 } break;
191 auto pid = content.data.province_id;
192 switch(content.value_type) {
194 amount += state.world.province_get_rgo_actual_production_per_good(pid, content.trade_good);
195 } break;
198 default:
199 break;
200 }
201 auto name = state.world.province_get_name(pid);
202 title->set_text(state, text::produce_simple_string(state, name));
203 } break;
205 break;
207 break;
209 break;
210 default:
211 break;
212 }
213 if(value->is_visible())
214 value->set_text(state, text::format_float(amount, 2));
215 }
216};
217class trade_flow_listbox_base : public listbox_element_base<trade_flow_entry, trade_flow_data> {
218protected:
219 std::string_view get_row_element_name() override {
220 return "trade_flow_entry";
221 }
222
223 template<typename F>
224 void populate_rows(sys::state& state, F&& factory_func, enum trade_flow_data::value_type vt) {
225 auto commodity_id = retrieve<dcon::commodity_id>(state, parent);
226 for(auto const fat_stown_id : state.world.nation_get_state_ownership(state.local_player_nation)) {
227 province::for_each_province_in_state_instance(state, fat_stown_id.get_state(), [&](dcon::province_id pid) {
228 auto fat_id = dcon::fatten(state.world, pid);
229 fat_id.for_each_factory_location_as_province([&](dcon::factory_location_id flid) {
230 auto fid = state.world.factory_location_get_factory(flid);
231 if(factory_func(fid)) {
232 trade_flow_data td{};
233 td.type = trade_flow_data::type::factory;
234 td.value_type = vt;
235 td.data.factory_id = fid;
236 td.trade_good = commodity_id;
237 row_contents.push_back(td);
238 }
239 });
241 if(state.world.province_get_rgo_actual_production_per_good(pid, commodity_id) > 0.f) {
242 trade_flow_data td{};
244 td.value_type = vt;
245 td.data.province_id = pid;
246 td.trade_good = commodity_id;
247 row_contents.push_back(td);
248 }
249 });
250 }
251 }
252};
253
255public:
256 void on_update(sys::state& state) noexcept override {
257 auto commodity_id = retrieve<dcon::commodity_id>(state, parent);
258
259 row_contents.clear();
260 populate_rows(
261 state,
262 [&](dcon::factory_id fid) -> bool {
263 auto ftid = state.world.factory_get_building_type(fid);
264 return state.world.factory_type_get_output(ftid) == commodity_id;
265 },
266 trade_flow_data::value_type::produced_by);
267 update(state);
268 }
269};
271public:
272 void on_update(sys::state& state) noexcept override {
273 auto commodity_id = retrieve<dcon::commodity_id>(state, parent);
274
275 row_contents.clear();
276 populate_rows(
277 state,
278 [&](dcon::factory_id fid) -> bool {
279 auto ftid = state.world.factory_get_building_type(fid);
280 auto& inputs = state.world.factory_type_get_inputs(ftid);
281 for(uint32_t i = 0; i < inputs.set_size; ++i)
282 if(inputs.commodity_type[i] == commodity_id)
283 return inputs.commodity_amounts[i] > 0.f; // Some inputs taken
284 return false;
285 },
286 trade_flow_data::value_type::used_by);
287 update(state);
288 }
289};
291public:
292 void on_update(sys::state& state) noexcept override {
293 auto commodity_id = retrieve<dcon::commodity_id>(state, parent);
294
295 row_contents.clear();
296 populate_rows(
297 state,
298 [&](dcon::factory_id fid) -> bool {
299 auto ftid = state.world.factory_get_building_type(fid);
300 auto& inputs = state.world.factory_type_get_inputs(ftid);
301 for(uint32_t i = 0; i < inputs.set_size; ++i)
302 if(inputs.commodity_type[i] == commodity_id)
303 return inputs.commodity_amounts[i] == 0.f; // No inputs intaken
304 return false;
305 },
306 trade_flow_data::value_type::may_be_used_by);
307 update(state);
308 }
309};
310
311class trade_flow_producers_piechart : public piechart<dcon::nation_id> {
312public:
313 void on_update(sys::state& state) noexcept override {
314 auto com = retrieve<dcon::commodity_id>(state, parent);
315 distribution.clear();
316 for(auto n : state.world.in_nation)
317 if(n.get_owned_province_count() != 0)
318 distribution.emplace_back(n.id, economy::supply(state, n, com));
319 update_chart(state);
320 }
321};
322
323class trade_flow_consumers_piechart : public piechart<dcon::nation_id> {
324public:
325 void on_update(sys::state& state) noexcept override {
326 auto com = retrieve<dcon::commodity_id>(state, parent);
327 distribution.clear();
328 for(auto n : state.world.in_nation)
329 if(n.get_owned_province_count() != 0)
330 distribution.emplace_back(n.id, economy::demand(state, n, com));
331 update_chart(state);
332 }
333};
334
335
336class trade_flow_workers_piechart : public piechart<dcon::pop_type_id> {
337public:
338 void on_update(sys::state& state) noexcept override {
339 auto com = retrieve<dcon::commodity_id>(state, parent);
340 distribution.clear();
341 float total = 0.f;
342 {
343 float amount = 0.f;
344 for(const auto pc : state.world.nation_get_province_control(state.local_player_nation)) {
345 for(const auto fl : pc.get_province().get_factory_location()) {
346 if(fl.get_factory().get_building_type().get_output() == com)
347 amount += fl.get_factory().get_actual_production();
348 }
349 }
350 total += amount;
351 distribution.emplace_back(state.culture_definitions.primary_factory_worker, amount);
352 }
353
354 float imports = economy::import_volume(state, state.local_player_nation, com);
355 distribution.emplace_back(state.culture_definitions.capitalists, imports);
356 total += imports;
357
358 {
359 float amount = 0.f;
360 for(const auto pc : state.world.nation_get_province_control(state.local_player_nation)) {
361 amount += pc.get_province().get_rgo_actual_production_per_good(com);
362 }
363 total += amount;
364 distribution.emplace_back(state.culture_definitions.aristocrat, amount);
365 }
366 {
367 auto amount = 0.f;
368 state.world.nation_for_each_state_ownership(state.local_player_nation, [&](auto soid) {
369 auto sid = state.world.state_ownership_get_state(soid);
370 auto market = state.world.state_instance_get_market_from_local_market(sid);
371 amount += state.world.market_get_artisan_actual_production(market, com);
372 });
373 total += amount;
374 distribution.emplace_back(state.culture_definitions.artisans, amount);
375 }
376
377 // remaining
378
379 auto produced = economy::supply(state, state.local_player_nation, com);
380
381 if(produced >= total) {
382 distribution.emplace_back(state.culture_definitions.laborers, total - produced);
383 }
384 update_chart(state);
385 }
386};
387
389public:
390 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
391 if(name == "current_price_label") {
392 auto ptr = make_element_by_type<simple_text_element_base>(state, id);
393 ptr->set_text(state, text::produce_simple_string(state, "alice_trade_flow_label"));
394 ptr->base_data.size.x *= 2; // Nudge
395 return ptr;
396 } else if(name == "current_price_value"
397 || name == "price_linechart"
398 || name == "price_chart_low"
399 || name == "price_chart_time") {
400 return make_element_by_type<invisible_element>(state, id);
401 } else if(name == "price_chart_high") {
402 auto ptr = make_element_by_type<invisible_element>(state, id);
403 {
404 auto ov_elm = make_element_by_type<image_element_base>(state, "generic_piechart_overlay");
405 ov_elm->base_data.position.x = ptr->base_data.position.x;
406 ov_elm->base_data.position.y = ptr->base_data.position.y;
407 auto pc_elm = make_element_by_type<trade_flow_producers_piechart>(state, "generic_piechart");
408 pc_elm->base_data.position.x += ov_elm->base_data.position.x;
409 pc_elm->base_data.position.y += ov_elm->base_data.position.y;
410 auto lg_elm = make_element_by_type<simple_text_element_base>(state, id);
411 lg_elm->set_text(state, text::produce_simple_string(state, "alice_trade_flow_piechart_producers"));
412 lg_elm->base_data.position.x = ptr->base_data.position.x;
413 lg_elm->base_data.position.y = ptr->base_data.position.y - 8;
414 add_child_to_front(std::move(lg_elm));
415 add_child_to_front(std::move(pc_elm));
416 add_child_to_front(std::move(ov_elm));
417 }
418 {
419 auto ov_elm = make_element_by_type<image_element_base>(state, "generic_piechart_overlay");
420 ov_elm->base_data.position.x = ptr->base_data.position.x + (ov_elm->base_data.size.x + 20) * 1;
421 ov_elm->base_data.position.y = ptr->base_data.position.y;
422 auto pc_elm = make_element_by_type<trade_flow_consumers_piechart>(state, "generic_piechart");
423 pc_elm->base_data.position.x += ov_elm->base_data.position.x;
424 pc_elm->base_data.position.y += ov_elm->base_data.position.y;
425 auto lg_elm = make_element_by_type<simple_text_element_base>(state, id);
426 lg_elm->set_text(state, text::produce_simple_string(state, "alice_trade_flow_piechart_consumers"));
427 lg_elm->base_data.position.x = ptr->base_data.position.x + (ov_elm->base_data.size.x + 20) * 1;
428 lg_elm->base_data.position.y = ptr->base_data.position.y - 8;
429 add_child_to_front(std::move(lg_elm));
430 add_child_to_front(std::move(pc_elm));
431 add_child_to_front(std::move(ov_elm));
432 }
433 {
434 auto ov_elm = make_element_by_type<image_element_base>(state, "generic_piechart_overlay");
435 ov_elm->base_data.position.x = ptr->base_data.position.x + (ov_elm->base_data.size.x + 20) * 2;
436 ov_elm->base_data.position.y = ptr->base_data.position.y;
437 auto pc_elm = make_element_by_type<trade_flow_workers_piechart>(state, "generic_piechart");
438 pc_elm->base_data.position.x += ov_elm->base_data.position.x;
439 pc_elm->base_data.position.y += ov_elm->base_data.position.y;
440 auto lg_elm = make_element_by_type<simple_text_element_base>(state, id);
441 lg_elm->set_text(state, text::produce_simple_string(state, "alice_trade_flow_piechart_workforce"));
442 lg_elm->base_data.position.x = ptr->base_data.position.x + (ov_elm->base_data.size.x + 20) * 2;
443 lg_elm->base_data.position.y = ptr->base_data.position.y - 8;
444 add_child_to_front(std::move(lg_elm));
445 add_child_to_front(std::move(pc_elm));
446 add_child_to_front(std::move(ov_elm));
447 }
448 return ptr;
449 } else {
450 return nullptr;
451 }
452 }
453};
454
456public:
457 void on_update(sys::state& state) noexcept override {
458 auto commodity_id = retrieve<dcon::commodity_id>(state, parent);
459
460 auto amount = 0.f;
461 for(auto const fat_stown_id : state.world.nation_get_state_ownership(state.local_player_nation)) {
462 province::for_each_province_in_state_instance(state, fat_stown_id.get_state(), [&](dcon::province_id pid) {
463 auto fat_id = dcon::fatten(state.world, pid);
464 fat_id.for_each_factory_location_as_province([&](dcon::factory_location_id flid) {
465 auto fid = state.world.factory_location_get_factory(flid);
466 auto ftid = state.world.factory_get_building_type(fid);
467 if(state.world.factory_type_get_output(ftid) == commodity_id)
468 amount += state.world.factory_get_actual_production(fid);
469 });
470 if(state.world.province_get_rgo(pid) == commodity_id)
471 amount += state.world.province_get_rgo_actual_production_per_good(pid, commodity_id);
472 });
473 }
474
475 set_text(state, text::format_float(amount, 2));
476 }
477};
479public:
480 void on_update(sys::state& state) noexcept override {
481 auto commodity_id = retrieve<dcon::commodity_id>(state, parent);
482 set_text(state, text::format_float(economy::nation_factory_consumption(state, state.local_player_nation, commodity_id), 2));
483 }
484};
485
487public:
488 void on_create(sys::state& state) noexcept override {
489 window_element_base::on_create(state);
490 set_visible(state, false);
491 }
492
493 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
494 if(name == "close_button") {
495 return make_element_by_type<generic_close_button>(state, id);
496 } else if(name == "trade_flow_bg") {
497 return make_element_by_type<draggable_target>(state, id);
498 } else if(name == "material_name") {
499 return make_element_by_type<generic_name_text<dcon::commodity_id>>(state, id);
500 } else if(name == "material_icon_big") {
501 return make_element_by_type<commodity_image>(state, id);
502 } else if(name == "header_produced_by") {
503 auto ptr = make_element_by_type<single_multiline_text_element_base>(state, id);
504 ptr->text_id = text::find_or_add_key(state, "alice_trade_flow_produced", true);
505 return ptr;
506 } else if(name == "header_used_by") {
507 auto ptr = make_element_by_type<single_multiline_text_element_base>(state, id);
508 ptr->text_id = text::find_or_add_key(state, "alice_trade_flow_consumed", true);
509 return ptr;
510 } else if(name == "header_may_be_used_by") {
511 auto ptr = make_element_by_type<single_multiline_text_element_base>(state, id);
512 ptr->text_id = text::find_or_add_key(state, "trade_flow_may_be_used", true);
513 return ptr;
514 } else if(name == "total_produced_text") {
515 auto ptr = make_element_by_type<single_multiline_text_element_base>(state, id);
516 ptr->text_id = text::find_or_add_key(state, "trade_flow_total_produced", true);
517 ptr->base_data.position.x += 48; // Nudge
518 return ptr;
519 } else if(name == "total_used_text") {
520 auto ptr = make_element_by_type<single_multiline_text_element_base>(state, id);
521 ptr->text_id = text::find_or_add_key(state, "trade_flow_total_used", true);
522 ptr->base_data.position.x += 48; // Nudge
523 return ptr;
524 } else if(name == "total_produced_value") {
525 return make_element_by_type<trade_flow_total_produced_text>(state, id);
526 } else if(name == "total_used_value") {
527 return make_element_by_type<trade_flow_total_used_text>(state, id);
528 } else if(name == "price_graph") {
529 return make_element_by_type<trade_flow_price_graph_window>(state, id);
530 } else if(name == "produced_by_listbox") {
531 return make_element_by_type<trade_flow_produced_by_listbox>(state, id);
532 } else if(name == "used_by_listbox") {
533 return make_element_by_type<trade_flow_used_by_listbox>(state, id);
534 } else if(name == "may_be_used_by_listbox") {
535 return make_element_by_type<trade_flow_may_be_used_by_listbox>(state, id);
536 } else {
537 return nullptr;
538 }
539 }
540};
541
542
543std::string name_view_commodity_id(sys::state& state, element_base* container, dcon::commodity_id item) {
544 std::string padding = item.index() < 10 ? "0" : "";
545 std::string description = "@$" + padding + std::to_string(item.index());
546
547 return description + text::get_name_as_string(
548 state,
549 dcon::fatten(state.world, item)
550 );
551};
552
553bool compare_price(sys::state& state, element_base* container, const dcon::commodity_id a, const dcon::commodity_id b) {
554 auto av = economy::price(state, a);
555 auto bv = economy::price(state, b);
556 if(av != bv)
557 return av > bv;
558 else
559 return a.index() < b.index();
560}
561
562std::string price_view_commodity_id(sys::state& state, element_base* container, dcon::commodity_id item) {
564};
565std::string supply_view_commodity_id(sys::state& state, element_base* container, dcon::commodity_id item) {
567};
568std::string demand_view_commodity_id(sys::state& state, element_base* container, dcon::commodity_id item) {
570};
571std::string balance_view_commodity_id(sys::state& state, element_base* container, dcon::commodity_id item) {
572 auto supply = economy::supply(state, item);
573 auto demand = economy::demand(state, item);
574 auto balance = supply - demand;
576};
577std::string stockpile_market_view_commodity_id(sys::state& state, element_base* container, dcon::commodity_id item) {
579};
580std::string stockpile_player_view_commodity_id(sys::state& state, element_base* container, dcon::commodity_id item) {
581 return text::format_float(state.world.nation_get_stockpiles(state.local_player_nation, item));
582};
583std::string stockpile_target_player_view_commodity_id(sys::state& state, element_base* container, dcon::commodity_id item) {
584 return text::format_float(state.world.nation_get_stockpile_targets(state.local_player_nation, item));
585};
586
587bool compare_name(sys::state& state, element_base* container, dcon::commodity_id a, dcon::commodity_id b) {
588 auto value_a = text::get_name_as_string(
589 state,
590 dcon::fatten(state.world, a)
591 );
592 auto value_b = text::get_name_as_string(
593 state,
594 dcon::fatten(state.world, b)
595 );
596
597 if(value_a != value_b)
598 return value_a > value_b;
599 else
600 return a.index() < b.index();
601}
602bool compare_supply(sys::state& state, element_base* container, dcon::commodity_id a, dcon::commodity_id b) {
603 auto value_a = economy::supply(state, a);
604 auto value_b = economy::supply(state, b);
605 if(value_a != value_b)
606 return value_a > value_b;
607 else
608 return a.index() < b.index();
609}
610bool compare_demand(sys::state& state, element_base* container, dcon::commodity_id a, dcon::commodity_id b) {
611 auto value_a = economy::demand(state, a);
612 auto value_b = economy::demand(state, b);
613 if(value_a != value_b)
614 return value_a > value_b;
615 else
616 return a.index() < b.index();
617}
618bool compare_balance(sys::state& state, element_base* container, dcon::commodity_id a, dcon::commodity_id b) {
619 auto supply_a = economy::supply(state, a);
620 auto demand_a = economy::demand(state, a);
621 auto balance_a = supply_a - demand_a;
622
623 auto supply_b = economy::supply(state, b);
624 auto demand_b = economy::demand(state, b);
625 auto balance_b = supply_b - demand_b;
626
627 if(balance_a != balance_b)
628 return balance_a > balance_b;
629 else
630 return a.index() < b.index();
631}
632bool compare_stockpile_market(sys::state& state, element_base* container, dcon::commodity_id a, dcon::commodity_id b) {
633 auto value_a = economy::market_pool(state, a);
634 auto value_b = economy::market_pool(state, b);
635 if(value_a != value_b)
636 return value_a > value_b;
637 else
638 return a.index() < b.index();
639}
640bool compare_stockpile_player(sys::state& state, element_base* container, dcon::commodity_id a, dcon::commodity_id b) {
641 auto value_a = state.world.nation_get_stockpiles(state.local_player_nation, a);
642 auto value_b = state.world.nation_get_stockpiles(state.local_player_nation, b);
643 if(value_a != value_b)
644 return value_a > value_b;
645 else
646 return a.index() < b.index();
647}
648
650 .sortable = true,
651 .header = "trade_good_name_header",
652 .compare = compare_name,
654 .cell_definition_string = "thin_cell_name",
655 .header_definition_string = "thin_cell_name"
656};
658 .sortable = true,
659 .header = "price",
660 .compare = compare_price,
662 .cell_definition_string = "thin_cell_number"
663};
664
666 .sortable = true,
667 .header = "supply",
668 .compare = compare_supply,
670 .cell_definition_string = "thin_cell_number"
671};
673 .sortable = true,
674 .header = "demand",
675 .compare = compare_demand,
677 .cell_definition_string = "thin_cell_number"
678};
680 .sortable = true,
681 .header = "balance",
682 .compare = compare_balance,
684 .cell_definition_string = "thin_cell_number"
685};
687 .sortable = true,
688 .header = "market_stockpiles",
689 .compare = compare_stockpile_market,
691 .cell_definition_string = "thin_cell_number"
692};
694 .sortable = true,
695 .header = "national_stockpile",
696 .compare = compare_stockpile_player,
698 .cell_definition_string = "thin_cell_number"
699};
700
701
703 .sortable = true,
704 .header = "government_need",
705 .compare = [](sys::state& state, element_base* container, dcon::commodity_id a, dcon::commodity_id b) {
706 auto av = economy::government_consumption(state, state.local_player_nation, a);
707 auto bv = economy::government_consumption(state, state.local_player_nation, b);
708 if(av != bv)
709 return av > bv;
710 else
711 return a.index() < b.index();
712 },
713 .view = [](sys::state& state, element_base* container, dcon::commodity_id id) {
714 auto value = economy::government_consumption(state, state.local_player_nation, id);
715 return text::format_float(value);
716 }
717};
718
720 .sortable = true,
721 .header = "price_nation",
722 .compare = [](sys::state& state, element_base* container, dcon::commodity_id a, dcon::commodity_id b) {
723 auto av = economy::price(state, state.local_player_nation, a);
724 auto bv = economy::price(state, state.local_player_nation, b);
725 if(av != bv)
726 return av > bv;
727 else
728 return a.index() < b.index();
729 },
730 .view = [](sys::state& state, element_base* container, dcon::commodity_id id) {
731 auto value = economy::price(state, state.local_player_nation, id);
732 return text::format_float(value);
733 }
734};
735
737 .sortable = true,
738 .header = "factory_need",
739 .compare = [](sys::state& state, element_base* container, dcon::commodity_id a, dcon::commodity_id b) {
740 auto av = economy::nation_factory_consumption(state, state.local_player_nation, a);
741 auto bv = economy::nation_factory_consumption(state, state.local_player_nation, b);
742 if(av != bv)
743 return av > bv;
744 else
745 return a.index() < b.index();
746 },
747 .view = [](sys::state& state, element_base* container, dcon::commodity_id id) {
748 auto value = economy::nation_factory_consumption(state, state.local_player_nation, id);
749 return text::format_float(value);
750 }
751};
752
754 .sortable = true,
755 .header = "pop_need",
756 .compare = [](sys::state& state, element_base* container, dcon::commodity_id a, dcon::commodity_id b) {
757 auto av = economy::nation_pop_consumption(state, state.local_player_nation, a);
758 auto bv = economy::nation_pop_consumption(state, state.local_player_nation, b);
759 if(av != bv)
760 return av > bv;
761 else
762 return a.index() < b.index();
763 },
764 .view = [](sys::state& state, element_base* container, dcon::commodity_id id) {
765 auto value = economy::nation_pop_consumption(state, state.local_player_nation, id);
766 return text::format_float(value);
767 }
768};
769
771 .sortable = true,
772 .header = "rgo_production",
773 .compare = [](sys::state& state, element_base* container, dcon::commodity_id a, dcon::commodity_id b) {
774 auto av = 0.f;
775 auto bv = 0.f;
776 for(auto p : state.world.in_province) {
777 if(p.get_nation_from_province_ownership()) {
778 av += p.get_rgo_actual_production_per_good(a);
779 }
780 }
781 for(auto p : state.world.in_province) {
782 if(p.get_nation_from_province_ownership()) {
783 bv += p.get_rgo_actual_production_per_good(b);
784 }
785 }
786 if(av != bv)
787 return av > bv;
788 else
789 return a.index() < b.index();
790 },
791 .view = [](sys::state& state, element_base* container, dcon::commodity_id id) {
792 auto value = 0.f;
793 for(auto p : state.world.in_province) {
794 if(p.get_nation_from_province_ownership()) {
795 value += p.get_rgo_actual_production_per_good(id);
796 }
797 }
798 return text::format_float(value);
799 }
800};
801
803 .sortable = true,
804 .header = "artisan_production",
805 .compare = [](sys::state& state, element_base* container, dcon::commodity_id a, dcon::commodity_id b) {
806 auto av = 0.f;
807 auto bv = 0.f;
808 for(auto n : state.world.in_market) {
809 av += n.get_artisan_actual_production(a);
810 }
811 for(auto n : state.world.in_market) {
812 bv += n.get_artisan_actual_production(b);
813 }
814 if(av != bv)
815 return av > bv;
816 else
817 return a.index() < b.index();
818 },
819 .view = [](sys::state& state, element_base* container, dcon::commodity_id id) {
820 auto value = 0.f;
821 for(auto n : state.world.in_market) {
822 value += n.get_artisan_actual_production(id);
823 }
824 return text::format_float(value);
825 }
826};
827
829 .sortable = true,
830 .header = "factory_production",
831 .compare = [](sys::state& state, element_base* container, dcon::commodity_id a, dcon::commodity_id b) {
832 auto av = 0.f;
833 auto bv = 0.f;
834 for(auto f : state.world.in_factory) {
835 if(f.get_building_type().get_output() == a)
836 av += f.get_actual_production();
837 }
838 for(auto f : state.world.in_factory) {
839 if(f.get_building_type().get_output() == b)
840 bv += f.get_actual_production();
841 }
842 if(av != bv)
843 return av > bv;
844 else
845 return a.index() < b.index();
846 },
847 .view = [](sys::state& state, element_base* container, dcon::commodity_id id) {
848 auto value = 0.f;
849 for(auto f : state.world.in_factory) {
850 if(f.get_building_type().get_output() == id)
851 value += f.get_actual_production();
852 }
853 return text::format_float(value);
854 }
855};
856
857/*
858table::column<dcon::commodity_id> trade_good_artisan_distribution = {
859inline table::column<dcon::commodity_id> trade_good_artisan_distribution = {
860 .sortable = true,
861 .header = "artisan_distribution",
862 .compare = [](sys::state& state, element_base* container, dcon::commodity_id a, dcon::commodity_id b) {
863 auto av = economy::get_artisan_distribution_slow(state, state.local_player_nation, a);
864 auto bv = economy::get_artisan_distribution_slow(state, state.local_player_nation, b);
865 if(av != bv)
866 return av > bv;
867 else
868 return a.index() < b.index();
869 },
870 .view = [](sys::state& state, element_base* container, dcon::commodity_id id) {
871 auto value = economy::get_artisan_distribution_slow(state, state.local_player_nation, id) * 1000.f;
872 return text::format_float(value, 4);
873 }
874};
875*/
876
878 .sortable = true,
879 .header = "artisan_distribution",
880 .compare = [](sys::state& state, element_base* container, dcon::commodity_id a, dcon::commodity_id b) {
881 auto av = economy::demand_satisfaction(state, state.local_player_nation, a);
882 auto bv = economy::demand_satisfaction(state, state.local_player_nation, b);
883 if(av != bv)
884 return av > bv;
885 else
886 return a.index() < b.index();
887 },
888 .view = [](sys::state& state, element_base* container, dcon::commodity_id id) {
889 auto value = economy::demand_satisfaction(state, state.local_player_nation, id);
890 return text::format_percentage(value, 1);
891 }
892};
893
895 .sortable = true,
896 .header = "produced_nation",
897 .compare = [](sys::state& state, element_base* container, dcon::commodity_id a, dcon::commodity_id b) {
898 auto av = economy::supply(state, state.local_player_nation, a);
899 auto bv = economy::supply(state, state.local_player_nation, b);
900 if(av != bv)
901 return av > bv;
902 else
903 return a.index() < b.index();
904 },
905 .view = [](sys::state& state, element_base* container, dcon::commodity_id id) {
906 auto value = economy::supply(state, state.local_player_nation, id);
907 return text::format_float(value, 1);
908 }
909};
910
912 .sortable = true,
913 .header = "consumed_nation",
914 .compare = [](sys::state& state, element_base* container, dcon::commodity_id a, dcon::commodity_id b) {
915 auto av = economy::consumption(state, state.local_player_nation, a);
916 auto bv = economy::consumption(state, state.local_player_nation, b);
917 if(av != bv)
918 return av > bv;
919 else
920 return a.index() < b.index();
921 },
922 .view = [](sys::state& state, element_base* container, dcon::commodity_id id) {
923 auto value = economy::consumption(state, state.local_player_nation, id);
924 return text::format_float(value, 1);
925 }
926};
927
929 .sortable = true,
930 .header = "price_nation",
931 .compare = [](sys::state& state, element_base* container, dcon::nation_id a, dcon::nation_id b) {
932 dcon::commodity_id good = retrieve<dcon::commodity_id>(state, container);
933 auto av = economy::price(state, a, good);
934 auto bv = economy::price(state, b, good);
935 if(av != bv)
936 return av > bv;
937 else
938 return a.index() < b.index();
939 },
940 .view = [](sys::state& state, element_base* container, dcon::nation_id id) {
941 dcon::commodity_id good = retrieve<dcon::commodity_id>(state, container);
942 auto value = economy::price(state, id, good);
943 return text::format_float(value, 1);
944 }
945};
946
948 .sortable = true,
949 .header = "nation_name",
950 .compare = [](sys::state& state, element_base* container, dcon::nation_id a, dcon::nation_id b) {
953 if(av != bv)
954 return av > bv;
955 else
956 return a.index() < b.index();
957 },
958 .view = [](sys::state& state, element_base* container, dcon::nation_id id) {
959 auto niid = state.world.nation_get_identity_from_identity_holder(id);
960 auto ii = state.world.national_identity_get_identifying_int(niid);
961 auto tag = nations::int_to_tag(ii);
962 auto prefix = "@" + tag;
963
964 auto value = prefix + text::produce_simple_string(state, text::get_name(state, id));
965 return value;
966 },
967 .cell_definition_string = "thin_cell_name",
968 .header_definition_string = "thin_cell_name"
969};
970
972 .sortable = true,
973 .header = "produced_nation",
974 .compare = [](sys::state& state, element_base* container, dcon::nation_id a, dcon::nation_id b) {
975 dcon::commodity_id good = retrieve<dcon::commodity_id>(state, container);
976 auto av = economy::supply(state, a, good);
977 auto bv = economy::supply(state, b, good);
978 if(av != bv)
979 return av > bv;
980 else
981 return a.index() < b.index();
982 },
983 .view = [](sys::state& state, element_base* container, dcon::nation_id id) {
984 dcon::commodity_id good = retrieve<dcon::commodity_id>(state, container);
985 auto value = economy::supply(state, id, good);
986 return text::format_float(value, 1);
987 }
988};
989
991 .sortable = true,
992 .header = "demanded_nation",
993 .compare = [](sys::state& state, element_base* container, dcon::nation_id a, dcon::nation_id b) {
994 dcon::commodity_id good = retrieve<dcon::commodity_id>(state, container);
995 auto av = economy::demand(state, a, good);
996 auto bv = economy::demand(state, b, good);
997 if(av != bv)
998 return av > bv;
999 else
1000 return a.index() < b.index();
1001 },
1002 .view = [](sys::state& state, element_base* container, dcon::nation_id id) {
1003 dcon::commodity_id good = retrieve<dcon::commodity_id>(state, container);
1004 auto value = economy::demand(state, id, good);
1005 return text::format_float(value, 1);
1006 }
1007};
1008
1010 .sortable = true,
1011 .header = "consumed_nation",
1012 .compare = [](sys::state& state, element_base* container, dcon::nation_id a, dcon::nation_id b) {
1013 dcon::commodity_id good = retrieve<dcon::commodity_id>(state, container);
1014 auto av = economy::consumption(state, a, good);
1015 auto bv = economy::consumption(state, b, good);
1016 if(av != bv)
1017 return av > bv;
1018 else
1019 return a.index() < b.index();
1020 },
1021 .view = [](sys::state& state, element_base* container, dcon::nation_id id) {
1022 dcon::commodity_id good = retrieve<dcon::commodity_id>(state, container);
1023 auto value = economy::consumption(state, id, good);
1024 return text::format_float(value, 1);
1025 }
1026};
1027
1028
1030 .sortable = true,
1031 .header = "market_name",
1032 .compare = [](sys::state& state, element_base* container, dcon::market_id a, dcon::market_id b) {
1033 auto sa = state.world.market_get_zone_from_local_market(a);
1034 auto sb = state.world.market_get_zone_from_local_market(b);
1035
1036 auto pa = state.world.state_instance_get_capital(sa);
1037 auto pb = state.world.state_instance_get_capital(sb);
1038
1039 auto av = text::produce_simple_string(state, pa.get_name());
1040 auto bv = text::produce_simple_string(state, pb.get_name());
1041 if(av != bv)
1042 return av > bv;
1043 else
1044 return a.index() < b.index();
1045 },
1046 .view = [](sys::state& state, element_base* container, dcon::market_id id) {
1047 auto s = state.world.market_get_zone_from_local_market(id);
1048 auto p = state.world.state_instance_get_capital(s);
1049 auto value = text::produce_simple_string(state, p.get_name());
1050 return value;
1051 },
1052 .cell_definition_string = "thin_cell_name",
1053 .header_definition_string = "thin_cell_name"
1054};
1055
1057 .sortable = true,
1058 .header = "produced_nation",
1059 .compare = [](sys::state& state, element_base* container, dcon::market_id a, dcon::market_id b) {
1060 dcon::commodity_id good = retrieve<dcon::commodity_id>(state, container);
1061 auto av = economy::supply(state, a, good);
1062 auto bv = economy::supply(state, b, good);
1063 if(av != bv)
1064 return av > bv;
1065 else
1066 return a.index() < b.index();
1067 },
1068 .view = [](sys::state& state, element_base* container, dcon::market_id id) {
1069 dcon::commodity_id good = retrieve<dcon::commodity_id>(state, container);
1070 auto value = economy::supply(state, id, good);
1071 return text::format_float(value, 1);
1072 }
1073};
1074
1076 .sortable = true,
1077 .header = "demanded_nation",
1078 .compare = [](sys::state& state, element_base* container, dcon::market_id a, dcon::market_id b) {
1079 dcon::commodity_id good = retrieve<dcon::commodity_id>(state, container);
1080 auto av = economy::demand(state, a, good);
1081 auto bv = economy::demand(state, b, good);
1082 if(av != bv)
1083 return av > bv;
1084 else
1085 return a.index() < b.index();
1086 },
1087 .view = [](sys::state& state, element_base* container, dcon::market_id id) {
1088 dcon::commodity_id good = retrieve<dcon::commodity_id>(state, container);
1089 auto value = economy::demand(state, id, good);
1090 return text::format_float(value, 1);
1091 }
1092};
1093
1095 .sortable = true,
1096 .header = "consumed_nation",
1097 .compare = [](sys::state& state, element_base* container, dcon::market_id a, dcon::market_id b) {
1098 dcon::commodity_id good = retrieve<dcon::commodity_id>(state, container);
1099 auto av = economy::consumption(state, a, good);
1100 auto bv = economy::consumption(state, b, good);
1101 if(av != bv)
1102 return av > bv;
1103 else
1104 return a.index() < b.index();
1105 },
1106 .view = [](sys::state& state, element_base* container, dcon::market_id id) {
1107 dcon::commodity_id good = retrieve<dcon::commodity_id>(state, container);
1108 auto value = economy::consumption(state, id, good);
1109 return text::format_float(value, 1);
1110 }
1111};
1112
1114 .sortable = true,
1115 .header = "stockpile_market",
1116 .compare = [](sys::state& state, element_base* container, dcon::market_id a, dcon::market_id b) {
1117 dcon::commodity_id good = retrieve<dcon::commodity_id>(state, container);
1118 auto av = state.world.market_get_stockpile(a, good);
1119 auto bv = state.world.market_get_stockpile(b, good);
1120 if(av != bv)
1121 return av > bv;
1122 else
1123 return a.index() < b.index();
1124 },
1125 .view = [](sys::state& state, element_base* container, dcon::market_id id) {
1126 dcon::commodity_id good = retrieve<dcon::commodity_id>(state, container);
1127 auto value = state.world.market_get_stockpile(id, good);
1128 return text::format_float(value, 1);
1129 }
1130};
1131
1133 .sortable = true,
1134 .header = "price_market",
1135 .compare = [](sys::state& state, element_base* container, dcon::market_id a, dcon::market_id b) {
1136 dcon::commodity_id good = retrieve<dcon::commodity_id>(state, container);
1137 auto av = economy::price(state, a, good);
1138 auto bv = economy::price(state, b, good);
1139 if(av != bv)
1140 return av > bv;
1141 else
1142 return a.index() < b.index();
1143 },
1144 .view = [](sys::state& state, element_base* container, dcon::market_id id) {
1145 dcon::commodity_id good = retrieve<dcon::commodity_id>(state, container);
1146 auto value = economy::price(state, id, good);
1147 return text::format_float(value, 1);
1148 }
1149};
1150
1152 .sortable = true,
1153 .header = "w_artisan_profit",
1154 .compare = [](sys::state& state, element_base* container, dcon::market_id a, dcon::market_id b) {
1155 dcon::commodity_id good = retrieve<dcon::commodity_id>(state, container);
1156 auto av = economy::base_artisan_profit(state, a, good);
1157 auto bv = economy::base_artisan_profit(state, b, good);
1158 if(av != bv)
1159 return av > bv;
1160 else
1161 return a.index() < b.index();
1162 },
1163 .view = [](sys::state& state, element_base* container, dcon::market_id id) {
1164 dcon::commodity_id good = retrieve<dcon::commodity_id>(state, container);
1165 auto value = economy::base_artisan_profit(state, id, good);
1166 return text::format_float(value, 3);
1167 }
1168};
1169
1171 .sortable = true,
1172 .header = "w_artisan_distribution",
1173 .compare = [](sys::state& state, element_base* container, dcon::market_id a, dcon::market_id b) {
1174 dcon::commodity_id good = retrieve<dcon::commodity_id>(state, container);
1175 auto av = state.world.market_get_artisan_score(a, good);
1176 auto bv = state.world.market_get_artisan_score(b, good);
1177 if(av != bv)
1178 return av > bv;
1179 else
1180 return a.index() < b.index();
1181 },
1182 .view = [](sys::state& state, element_base* container, dcon::market_id id) {
1183 dcon::commodity_id good = retrieve<dcon::commodity_id>(state, container);
1184 auto value = state.world.market_get_artisan_score(id, good);
1185 return text::format_float(value, 3);
1186 }
1187};
1188
1189/*
1190* MOVE TO PRODUCTION METHODS TABLE
1191text::add_line(state, contents, "w_artisan_profit", text::variable_type::x, text::fp_one_place{ economy::base_artisan_profit(state, state.local_player_nation, com) * economy::artisan_scale_limit(state, state.local_player_nation, com) });
1192*/
1193
1195public:
1196 void button_action(sys::state& state) noexcept override {
1197 auto commodity_id = retrieve<dcon::commodity_id>(state, parent);
1198 Cyto::Any dt_payload = trade_details_open_window{commodity_id};
1199 state.ui_state.trade_subwindow->impl_get(state, dt_payload);
1200 }
1201};
1202
1204public:
1205 void button_action(sys::state& state) noexcept override {
1206 // TODO: change stockpile settings option?
1207 //float famount = retrieve<float>(state, parent);
1208 //auto cid = retrieve<dcon::commodity_id>(state, parent);
1209 //command::change_stockpile_settings(state, state.local_player_nation, cid, famount, false);
1210 }
1211};
1212
1214public:
1216 : line_graph(32) { }
1217
1218 void on_create(sys::state& state) noexcept override {
1219 line_graph::on_create(state);
1220 }
1221
1222 void on_update(sys::state& state) noexcept override {
1223 auto com = retrieve<dcon::commodity_id>(state, parent);
1224
1226
1227 std::vector<float> datapoints(32);
1229 for(uint32_t i = 0; i < 32; ++i) {
1230 datapoints[i] = state.world.commodity_get_price_record(com, (newest_index + i + economy::price_history_length - 32) % economy::price_history_length);
1231 }
1232 set_data_points(state, datapoints);
1233 }
1234 void render(sys::state& state, int32_t x, int32_t y) noexcept override {
1235 auto com = retrieve<dcon::commodity_id>(state, parent);
1236 line_graph::render(state, x, y);
1237 }
1238};
1239
1241public:
1242 void on_update(sys::state& state) noexcept override {
1243 auto com = retrieve<dcon::commodity_id>(state, parent);
1244
1246 float max_price = state.world.commodity_get_price_record(com, newest_index);
1247
1248 for(int32_t i = 1; i < 32; ++i) {
1249 max_price = std::max(state.world.commodity_get_price_record(com, (newest_index + i + economy::price_history_length - 32) % economy::price_history_length), max_price);
1250 }
1251 set_text(state, text::format_money(max_price));
1252 }
1253};
1254
1256public:
1257 void on_update(sys::state& state) noexcept override {
1258 auto com = retrieve<dcon::commodity_id>(state, parent);
1259
1261 float min_price = state.world.commodity_get_price_record(com, newest_index);
1262
1263 for(int32_t i = 1; i < 32; ++i) {
1264 min_price = std::min(state.world.commodity_get_price_record(com, (newest_index + i + economy::price_history_length - 32) % economy::price_history_length), min_price);
1265 }
1266 set_text(state, text::format_money(min_price));
1267 }
1268};
1269
1271public:
1272 void on_update(sys::state& state) noexcept override {
1273 auto com = retrieve<dcon::commodity_id>(state, parent);
1274 if(state.world.nation_get_drawing_on_stockpiles(state.local_player_nation, com)) {
1275 frame = 1;
1276 } else {
1277 frame = 0;
1278 }
1279 }
1280
1281 void render(sys::state& state, int32_t x, int32_t y) noexcept override {
1282 auto com = retrieve<dcon::commodity_id>(state, parent);
1283 button_element_base::render(state, x, y);
1284 }
1285
1286 void button_action(sys::state& state) noexcept override {
1287 auto com = retrieve<dcon::commodity_id>(state, parent);
1288 command::change_stockpile_settings(state, state.local_player_nation, com, state.world.nation_get_stockpile_targets(state.local_player_nation, com), !state.world.nation_get_drawing_on_stockpiles(state.local_player_nation, com));
1289 }
1290};
1291
1293public:
1294 void on_update(sys::state& state) noexcept override {
1295 auto com = retrieve<dcon::commodity_id>(state, parent);
1296 set_text(state, text::produce_simple_string(state, state.world.nation_get_drawing_on_stockpiles(state.local_player_nation, com) ? "trade_use" : "trade_fill"));
1297 }
1298};
1299
1301public:
1302 void on_create(sys::state& state) noexcept override {
1303 set_text(state, text::produce_simple_string(state, "trade_stockpile_target"));
1304 }
1305 void render(sys::state& state, int32_t x, int32_t y) noexcept override {
1306 auto com = retrieve<dcon::commodity_id>(state, parent);
1307 simple_text_element_base::render(state, x, y);
1308 }
1309};
1310
1312public:
1313 void on_create(sys::state& state) noexcept override {
1314
1315 }
1316 void on_update(sys::state& state) noexcept override {
1317 auto com = retrieve<dcon::commodity_id>(state, parent);
1318 set_text(state, text::produce_simple_string(state, "trade_stockpile_current") + text::format_float(state.world.nation_get_stockpiles(state.local_player_nation, com), 1));
1319 }
1320};
1321
1323public:
1324 void on_update(sys::state& state) noexcept override {
1325 auto com = retrieve<dcon::commodity_id>(state, parent);
1328 set_text(state, text::resolve_string_substitution(state, "produced_detail_remove", m));
1329 }
1330};
1331
1333 float value;
1334};
1336 float value;
1337};
1338
1339class trade_slider : public scrollbar {
1340public:
1341 void on_value_change(sys::state& state, int32_t v) noexcept final {
1342 float a = std::pow(10.0f, float(v) * (6.0f / 2000.0f)) - 1.0f;
1343 send(state, parent, stockpile_target_change{a});
1344 if(state.ui_state.drag_target != slider)
1345 commit_changes(state);
1346 }
1347
1348 void on_update(sys::state& state) noexcept final {
1349 auto com = retrieve<dcon::commodity_id>(state, parent);
1350 if(!com)
1351 return;
1352
1353 if(state.ui_state.drag_target == slider) {
1354
1355 } else {
1356 auto value = state.world.nation_get_stockpile_targets(state.local_player_nation, com);
1357 auto a = std::log10(value + 1.0f);
1358 auto b = a * (2000.0f / 6.0f);
1359 update_raw_value(state, int32_t(b));
1360
1361 send(state, parent, stockpile_target_change{value});
1362 }
1363 }
1364 void impl_render(sys::state& state, int32_t x, int32_t y) noexcept override {
1365 auto com = retrieve<dcon::commodity_id>(state, parent);
1366 scrollbar::impl_render(state, x, y);
1367 }
1368 void on_drag_finish(sys::state& state) noexcept override {
1369 commit_changes(state);
1370 }
1372 auto com = retrieve<dcon::commodity_id>(state, parent);
1373 float v = std::pow(10.0f, float(raw_value()) * (6.0f / 2000.0f)) - 1.0f;
1374 command::change_stockpile_settings(state, state.local_player_nation, com, v, state.world.nation_get_drawing_on_stockpiles(state.local_player_nation, com));
1375 }
1376};
1377
1379public:
1380 void on_update(sys::state& state) noexcept override {
1381 auto com = retrieve<dcon::commodity_id>(state, parent);
1382 auto val = retrieve<get_stockpile_target>(state, parent);
1383 set_text(state, text::prettify(int64_t(val.value)));
1384 }
1385};
1386
1388public:
1389 void on_update(sys::state& state) noexcept override {
1390 auto commodity_id = retrieve<dcon::commodity_id>(state, parent);
1391 set_text(state, text::format_money(economy::price(state, commodity_id)));
1392 }
1393};
1394
1396 simple_text_element_base* slider_value_display = nullptr;
1397
1398public:
1399 float trade_amount = 0.0f;
1400
1401 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
1402 if(name == "trade_flow_bg") {
1403 return make_element_by_type<image_element_base>(state, id);
1404 } else if(name == "goods_icon") {
1405 return make_element_by_type<commodity_image>(state, id);
1406 } else if(name == "goods_title") {
1407 return make_element_by_type<generic_name_text<dcon::commodity_id>>(state, id);
1408 } else if(name == "goods_price") {
1409 return make_element_by_type<commodity_price_text>(state, id);
1410 } else if(name == "automate_label") {
1411 return make_element_by_type<invisible_element>(state, id);
1412 } else if(name == "automate") {
1413 return make_element_by_type<invisible_element>(state, id);
1414 } else if(name == "price_linechart") {
1415 return make_element_by_type<prices_line_graph>(state, id);
1416 } else if(name == "price_chart_low") {
1417 return make_element_by_type<price_chart_low>(state, id);
1418 } else if(name == "price_chart_high") {
1419 return make_element_by_type<price_chart_high>(state, id);
1420 } else if(name == "price_chart_time") {
1421 return make_element_by_type<invisible_element>(state, id);
1422 } else if(name == "sell_stockpile") {
1423 return make_element_by_type<stockpile_sell_button>(state, id);
1424 } else if(name == "sell_stockpile_label") {
1425 return make_element_by_type<stockpile_sell_label>(state, id);
1426 } else if(name == "sell_slidier_desc") {
1427 return make_element_by_type<stockpile_slider_label>(state, id);
1428 } else if(name == "sell_slider") {
1429 return make_element_by_type<trade_slider>(state, id);
1430 } else if(name == "slider_value") {
1431 auto ptr = make_element_by_type<trade_slider_amount>(state, id);
1432 slider_value_display = ptr.get();
1433 return ptr;
1434 } else if(name == "confirm_trade") {
1435 return make_element_by_type<stockpile_amount_label>(state, id);
1436 } else if(name == "goods_details") {
1437 return make_element_by_type<trade_details_button>(state, id);
1438 } else if(name == "goods_need_gov_desc") {
1439 return make_element_by_type<invisible_element>(state, id);
1440 } else if(name == "goods_need_factory_desc") {
1441 return make_element_by_type<invisible_element>(state, id);
1442 } else if(name == "produced_detail_desc") {
1443 return make_element_by_type<detail_domestic_production>(state, id);
1444 } else if(name == "goods_need_pop_desc") {
1445 return make_element_by_type<invisible_element>(state, id);
1446 } else {
1447 return nullptr;
1448 }
1449 }
1450
1451 message_result get(sys::state& state, Cyto::Any& payload) noexcept override {
1452 if(payload.holds_type<get_stockpile_target>()) {
1453 payload = get_stockpile_target{trade_amount};
1454 return message_result::consumed;
1455 } else if(payload.holds_type<stockpile_target_change>()) {
1456 trade_amount = any_cast<stockpile_target_change>(payload).value;
1457 slider_value_display->impl_on_update(state);
1458 return message_result::consumed;
1459 }
1460
1461 return message_result::unseen;
1462 }
1463};
1464
1466 uint8_t index = 0;
1467 uint8_t subindex = 0;
1468 uint8_t click_amount = 0;
1469public:
1470 void on_create(sys::state& state) noexcept override {
1471 button_element_base::on_create(state);
1472 subindex = 0;
1473 if(state.network_mode != sys::network_mode_type::single_player) {
1474 index = 3;
1475 } else {
1476 index = uint8_t(state.game_seed % 3);
1477 }
1478 }
1479
1480 void on_update(sys::state& state) noexcept override {
1481
1482 }
1483
1484 void render(sys::state& state, int32_t x, int32_t y) noexcept override {
1485 if(index == 1 && subindex == 2) {
1486 return; //no render
1487 }
1488 button_element_base::render(state, x, y);
1489 }
1490
1491 void button_action(sys::state& state) noexcept override {
1492 if(index == 1) {
1493 click_amount++;
1494 if(click_amount >= 10)
1495 subindex = 1;
1496 if(click_amount >= 15)
1497 subindex = 2;
1498 }
1499 }
1500
1502 return tooltip_behavior::variable_tooltip;
1503 }
1504
1505 void update_tooltip(sys::state& state, int32_t x, int32_t y, text::columnar_layout& contents) noexcept override {
1506 std::string key = "alice_stockpile_button_" + std::to_string(index) + "_" + std::to_string(subindex);
1507 text::add_line(state, contents, key);
1508 }
1509};
1510
1515
1517 void button_action(sys::state& state) noexcept override {
1518 signal_global_table signal{};
1519 send<signal_global_table>(state, parent, signal);
1520 }
1521};
1522
1524 void button_action(sys::state& state) noexcept override {
1525 signal_nation_table signal{};
1526 send<signal_nation_table>(state, parent, signal);
1527 }
1528};
1529
1531 void button_action(sys::state& state) noexcept override {
1532 signal_trade_good_table signal{};
1533 send<signal_trade_good_table>(state, parent, signal);
1534 }
1535};
1536
1538 void button_action(sys::state& state) noexcept override {
1540 send<signal_trade_good_markets_table>(state, parent, signal);
1541 }
1542};
1543
1545 trade_flow_window* trade_flow_win = nullptr;
1546 trade_details_window* details_win = nullptr;
1547 dcon::commodity_id commodity_id{1};
1548
1549 table::display<dcon::commodity_id>* table_nation = nullptr;
1550 table::display<dcon::commodity_id>* table_global = nullptr;
1551 table::display<dcon::nation_id>* table_trade_good_stats = nullptr;
1552 table::display<dcon::market_id>* table_trade_good_stats_market = nullptr;
1553
1554public:
1555 void on_create(sys::state& state) noexcept override {
1556 window_element_base::on_create(state);
1557
1558 auto ptr = make_element_by_type<trade_flow_window>(state, state.ui_state.defs_by_name.find(state.lookup_key("trade_flow"))->second.definition);
1559 trade_flow_win = ptr.get();
1560 add_child_to_front(std::move(ptr));
1561
1562 set_visible(state, false);
1563 }
1564
1565 std::unique_ptr<element_base> make_child(sys::state& state, std::string_view name, dcon::gui_def_id id) noexcept override {
1566 if(name == "main_bg") {
1567 return make_element_by_type<image_element_base>(state, id);
1568 } else if(name == "bg_trade") {
1569 return make_element_by_type<opaque_element_base>(state, id);
1570 } else if(name == "close_button") {
1571 return make_element_by_type<generic_close_button>(state, id);
1572 } else if(name == "commodity_table_nation") {
1573 std::vector<table::column<dcon::commodity_id>> columns = {
1582 //trade_good_artisan_distribution
1583 };
1584 auto ptr = make_element_by_type<table::display<dcon::commodity_id>>(
1585 state,
1586 id,
1587 std::string("commodity_table_body"),
1588 columns
1589 );
1590 table_nation = ptr.get();
1591 table_nation->row_callback = [](sys::state& state, ui::element_base* container, const dcon::commodity_id& a) {
1592 trade_details_select_commodity payload{ a };
1593 send<trade_details_select_commodity>(state, container, payload);
1594 };
1595 state.world.for_each_commodity([&](dcon::commodity_id id) {
1596 table_nation->content.data.push_back(id);
1597 });
1598 table_nation->set_visible(state, false);
1599 return ptr;
1600 } else if(name == "commodity_table_global") {
1601 std::vector<table::column<dcon::commodity_id>> columns = {
1611 };
1612 auto ptr = make_element_by_type<table::display<dcon::commodity_id>>(
1613 state,
1614 id,
1615 std::string("commodity_table_body"),
1616 columns
1617 );
1618 table_global = ptr.get();
1619 table_global->row_callback = [](sys::state& state, ui::element_base* container, const dcon::commodity_id& a) {
1620 trade_details_select_commodity payload{ a };
1621 send<trade_details_select_commodity>(state, container, payload);
1622 };
1623 state.world.for_each_commodity([&](dcon::commodity_id id) {
1624 table_global->content.data.push_back(id);
1625 });
1626 return ptr;
1627 } else if(name == "trade_good_global_stats") {
1628 std::vector<table::column<dcon::nation_id>> columns = {
1630 };
1631 auto ptr = make_element_by_type<table::display<dcon::nation_id>>(
1632 state,
1633 id,
1634 std::string("commodity_table_body"),
1635 columns
1636 );
1637 table_trade_good_stats = ptr.get();
1638 table_trade_good_stats->set_visible(state, false);
1639 state.world.for_each_nation([&](dcon::nation_id id) {
1640 table_trade_good_stats->content.data.push_back(id);
1641 });
1642 return ptr;
1643 } else if(name == "trade_good_markets_stats") {
1644 std::vector<table::column<dcon::market_id>> columns = {
1649 };
1650 auto ptr = make_element_by_type<table::display<dcon::market_id>>(
1651 state,
1652 id,
1653 std::string("commodity_table_body"),
1654 columns
1655 );
1656 table_trade_good_stats_market = ptr.get();
1657 table_trade_good_stats_market->set_visible(state, false);
1658 state.world.for_each_market([&](dcon::market_id id) {
1659 table_trade_good_stats_market->content.data.push_back(id);
1660 });
1661 return ptr;
1662 } else if(name == "market_table_global") {
1663 return make_element_by_type<switch_to_global_button>(state, id);
1664 } else if(name == "market_table_nation") {
1665 return make_element_by_type<switch_to_nation_button>(state, id);
1666 } else if(name == "market_table_trade_good_global") {
1667 return make_element_by_type<switch_to_trade_good_button>(state, id);
1668 } else if(name == "market_table_trade_good_markets") {
1669 return make_element_by_type<switch_to_trade_good_markets_button>(state, id);
1670 } else if(name == "trade_details") {
1671 auto ptr = make_element_by_type<trade_details_window>(state, id);
1672 details_win = ptr.get();
1673 return ptr;
1674 } else {
1675 return nullptr;
1676 }
1677 }
1678
1679 void on_update(sys::state& state) noexcept override {
1680 table_trade_good_stats_market->content.data.clear();
1681 state.world.for_each_market([&](dcon::market_id id) {
1682 auto sid = state.world.market_get_zone_from_local_market(id);
1683 auto nid = state.world.state_instance_get_nation_from_state_ownership(sid);
1684
1685 auto selected_nid = retrieve<dcon::nation_id>(state, this);
1686
1687 if (selected_nid && selected_nid == nid)
1688 table_trade_good_stats_market->content.data.push_back(id);
1689
1690 if (!selected_nid)
1691 table_trade_good_stats_market->content.data.push_back(id);
1692 });
1693 }
1694
1695 message_result get(sys::state& state, Cyto::Any& payload) noexcept override {
1696 // Special message rebroadcasted by the details button from the hierarchy
1697 if(payload.holds_type<signal_nation_table>()) {
1698 table_nation->set_visible(state, true);
1699 table_global->set_visible(state, false);
1700 table_trade_good_stats->set_visible(state, false);
1701 table_trade_good_stats_market->set_visible(state, false);
1702 } else if(payload.holds_type<signal_global_table>()) {
1703 table_nation->set_visible(state, false);
1704 table_global->set_visible(state, true);
1705 table_trade_good_stats->set_visible(state, false);
1706 table_trade_good_stats_market->set_visible(state, false);
1707 } else if(payload.holds_type<signal_trade_good_table>()) {
1708 table_nation->set_visible(state, false);
1709 table_global->set_visible(state, false);
1710 table_trade_good_stats->set_visible(state, true);
1711 table_trade_good_stats_market->set_visible(state, false);
1712 } else if(payload.holds_type<signal_trade_good_markets_table>()) {
1713 table_nation->set_visible(state, false);
1714 table_global->set_visible(state, false);
1715 table_trade_good_stats->set_visible(state, false);
1716 table_trade_good_stats_market->set_visible(state, true);
1717 } else if(payload.holds_type<dcon::commodity_id>()) {
1718 payload.emplace<dcon::commodity_id>(commodity_id);
1719 return message_result::consumed;
1720 } else if(payload.holds_type<trade_details_open_window>()) {
1721 commodity_id = any_cast<trade_details_open_window>(payload).commodity_id;
1722 trade_flow_win->set_visible(state, true);
1723 trade_flow_win->impl_on_update(state);
1724 return message_result::consumed;
1725 } else if(payload.holds_type<trade_details_select_commodity>()) {
1726 commodity_id = any_cast<trade_details_select_commodity>(payload).commodity_id;
1727 if(commodity_id)
1728 details_win->trade_amount = state.world.nation_get_stockpile_targets(state.local_player_nation, commodity_id);
1729 details_win->impl_on_update(state);
1730 return message_result::consumed;
1731 } else if(payload.holds_type<dcon::nation_id>()) {
1732 payload.emplace<dcon::nation_id>(state.local_player_nation);
1733 return message_result::consumed;
1734 }
1735 return message_result::unseen;
1736 }
1737};
1738
1739} // namespace ui
ui::message_result get(sys::state &state, Cyto::Any &payload) noexcept override
Definition: table.hpp:427
data< item_type > content
Definition: table.hpp:346
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 update_tooltip(sys::state &state, int32_t x, int32_t y, text::columnar_layout &contents) noexcept override
tooltip_behavior has_tooltip(sys::state &state) noexcept override
void impl_on_update(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept override
element_base * parent
virtual message_result get(sys::state &state, Cyto::Any &payload) noexcept
virtual void impl_on_update(sys::state &state) noexcept
message_result impl_get(sys::state &state, Cyto::Any &payload) noexcept
void set_visible(sys::state &state, bool vis)
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_create(sys::state &state) noexcept override
void render(sys::state &state, int32_t x, int32_t y) noexcept override
void on_update(sys::state &state) noexcept override
void on_create(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_create(sys::state &state) noexcept override
void render(sys::state &state, int32_t x, int32_t y) noexcept override
void button_action(sys::state &state) noexcept override
tooltip_behavior has_tooltip(sys::state &state) noexcept override
void render(sys::state &state, int32_t x, int32_t y) noexcept override
void button_action(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept override
void on_create(sys::state &state) noexcept override
void render(sys::state &state, int32_t x, int32_t y) noexcept override
void button_action(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
message_result get(sys::state &state, Cyto::Any &payload) noexcept override
void on_update(sys::state &state) noexcept override
bool operator==(trade_flow_data const &o) const
bool operator!=(trade_flow_data const &o) const
dcon::province_id province_id
union ui::trade_flow_data::@4 data
dcon::commodity_id trade_good
dcon::factory_id factory_id
dcon::province_id pop_province_id
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
std::string_view get_row_element_name() override
void populate_rows(sys::state &state, F &&factory_func, enum trade_flow_data::value_type vt)
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_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
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 on_update(sys::state &state) noexcept override
void on_update(sys::state &state) noexcept override
void commit_changes(sys::state &state) noexcept
void impl_render(sys::state &state, int32_t x, int32_t y) noexcept override
void on_update(sys::state &state) noexcept final
void on_drag_finish(sys::state &state) noexcept override
void on_value_change(sys::state &state, int32_t v) noexcept final
void on_create(sys::state &state) 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
#define assert(condition)
Definition: debug.h:74
pop_satisfaction_wrapper_fat fatten(data_container const &c, pop_satisfaction_wrapper_id id) noexcept
float government_consumption(sys::state &state, dcon::nation_id n, dcon::commodity_id c)
Definition: economy.cpp:7524
float consumption(sys::state &state, dcon::market_id s, dcon::commodity_id c)
Definition: economy.cpp:325
float supply(sys::state &state, dcon::market_id s, dcon::commodity_id c)
Definition: economy.cpp:206
float nation_factory_consumption(sys::state &state, dcon::nation_id n, dcon::commodity_id c)
Definition: economy.cpp:7608
float price(sys::state const &state, dcon::state_instance_id s, dcon::commodity_id c)
Definition: economy.cpp:150
constexpr uint32_t price_history_length
Definition: economy.hpp:126
int32_t most_recent_price_record_index(sys::state &state)
Definition: economy.cpp:825
float import_volume(sys::state &state, dcon::market_id s, dcon::commodity_id c)
Definition: economy.cpp:578
float demand_satisfaction(sys::state &state, dcon::market_id s, dcon::commodity_id c)
Definition: economy.cpp:395
float market_pool(sys::state &state, dcon::market_id s, dcon::commodity_id c)
Definition: economy.cpp:360
float demand(sys::state &state, dcon::market_id s, dcon::commodity_id c)
Definition: economy.cpp:283
float nation_pop_consumption(sys::state &state, dcon::nation_id n, dcon::commodity_id c)
Definition: economy.cpp:7688
ve::fp_vector base_artisan_profit(sys::state &state, T markets, S nations, dcon::commodity_id c)
Definition: economy.cpp:1249
std::string int_to_tag(uint32_t v)
Definition: nations.hpp:14
void for_each_province_in_state_instance(sys::state &state, dcon::state_instance_id s, F const &func)
std::string resolve_string_substitution(sys::state &state, dcon::text_key source_text, substitution_map const &mp)
Definition: text.cpp:2137
std::string format_money(float num)
Definition: text.cpp:1029
std::string get_name_as_string(sys::state &state, T t)
Definition: text.hpp:957
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:1923
void add_to_substitution_map(substitution_map &mp, variable_type key, substitution value)
Definition: text.cpp:1068
ankerl::unordered_dense::map< uint32_t, substitution > substitution_map
Definition: text.hpp:797
std::string produce_simple_string(sys::state const &state, dcon::text_key id)
Definition: text.cpp:617
dcon::text_key get_name(sys::state &state, dcon::nation_id id)
Definition: text.cpp:880
std::string format_percentage(float num, size_t digits)
Definition: text.cpp:977
dcon::text_key find_or_add_key(sys::state &state, std::string_view key, bool as_unicode)
Definition: text.cpp:695
table::column< dcon::commodity_id > trade_good_consumed_nation
std::string stockpile_target_player_view_commodity_id(sys::state &state, element_base *container, dcon::commodity_id item)
table::column< dcon::commodity_id > trade_good_satisfaction
table::column< dcon::commodity_id > trade_good_production_artisan
bool compare_stockpile_market(sys::state &state, element_base *container, dcon::commodity_id a, dcon::commodity_id b)
std::string price_view_commodity_id(sys::state &state, element_base *container, dcon::commodity_id item)
table::column< dcon::commodity_id > trade_good_production_factory
std::string stockpile_player_view_commodity_id(sys::state &state, element_base *container, dcon::commodity_id item)
bool compare_name(sys::state &state, element_base *container, dcon::commodity_id a, dcon::commodity_id b)
table::column< dcon::market_id > market_demand
table::column< dcon::nation_id > nation_name
table::column< dcon::market_id > market_production
bool compare_stockpile_player(sys::state &state, element_base *container, dcon::commodity_id a, dcon::commodity_id b)
table::column< dcon::market_id > market_consumption
table::column< dcon::nation_id > nation_price
std::string supply_view_commodity_id(sys::state &state, element_base *container, dcon::commodity_id item)
bool compare_balance(sys::state &state, element_base *container, dcon::commodity_id a, dcon::commodity_id b)
table::column< dcon::commodity_id > trade_good_demand_column
bool compare_demand(sys::state &state, element_base *container, dcon::commodity_id a, dcon::commodity_id b)
table::column< dcon::market_id > market_stockpile
bool compare_supply(sys::state &state, element_base *container, dcon::commodity_id a, dcon::commodity_id b)
table::column< dcon::nation_id > nation_consumption
table::column< dcon::commodity_id > trade_good_player_gov_needs
table::column< dcon::nation_id > nation_demand
tooltip_behavior
void send(sys::state &state, element_base *parent, T value)
table::column< dcon::market_id > market_price
std::string stockpile_market_view_commodity_id(sys::state &state, element_base *container, dcon::commodity_id item)
std::string demand_view_commodity_id(sys::state &state, element_base *container, dcon::commodity_id item)
table::column< dcon::commodity_id > trade_good_player_pop_needs
message_result
std::string name_view_commodity_id(sys::state &state, element_base *container, dcon::commodity_id item)
table::column< dcon::commodity_id > trade_good_market_stockpile_column
table::column< dcon::commodity_id > trade_good_name_column
bool compare_price(sys::state &state, element_base *container, const dcon::commodity_id a, const dcon::commodity_id b)
table::column< dcon::commodity_id > trade_good_production_rgo
table::column< dcon::commodity_id > trade_good_produced_nation
table::column< dcon::commodity_id > trade_good_player_stockpile_column
table::column< dcon::commodity_id > trade_good_player_factory_needs
table::column< dcon::market_id > market_name
table::column< dcon::nation_id > nation_production
table::column< dcon::commodity_id > trade_good_price_column
table::column< dcon::market_id > market_artisan_profit
std::string balance_view_commodity_id(sys::state &state, element_base *container, dcon::commodity_id item)
table::column< dcon::commodity_id > trade_good_player_price
table::column< dcon::commodity_id > trade_good_supply_column
table::column< dcon::commodity_id > trade_good_balance_column
table::column< dcon::market_id > market_artisan_score
uint uint32_t
uchar uint8_t
Holds important data about the game world, state, and other data regarding windowing,...
element_base * trade_subwindow
ankerl::unordered_dense::map< dcon::text_key, element_target, hash_text_key > defs_by_name
element_base * drag_target