25 #include "eng3d/string.hpp"
26 #include "eng3d/ui/div.hpp"
27 #include "eng3d/ui/label.hpp"
28 #include "eng3d/ui/image.hpp"
29 #include "eng3d/ui/scrollbar.hpp"
30 #include "eng3d/ui/table.hpp"
31 #include "eng3d/string.hpp"
41 std::vector<int> sizes;
42 if(provinces.size() > 1) sizes.push_back(150);
43 sizes.insert(sizes.end(), { 150, 80, 80, 100, 80, 80, 80, 32 });
45 std::vector<std::string> header;
46 if(provinces.size() > 1) header.push_back(
"Province");
47 header.insert(header.end(), {
"Type",
"Workers",
"Budget",
"Inputs",
"Output",
"Scale",
"Profit",
"" });
51 table.set_on_each_tick([&gs, &table, provinces](
UI::Widget&) {
53 for(
const auto province_id : provinces) {
54 const auto& province = gs.
world->provinces[province_id];
55 for(
size_t i = 0; i < province.buildings.size(); i++) {
56 const auto&
type = gs.
world->building_types[i];
57 const auto& building = province.buildings[i];
58 auto& row = table.get_row(row_num++);
61 if(provinces.size() > 1) {
62 auto* prov_name = row.get_element(row_index++);
63 prov_name->set_text(province.name);
64 prov_name->set_key(province.name);
67 auto* name = row.get_element(row_index++);
68 name->set_text(
type.name);
69 name->set_key(
type.name);
71 auto* workers = row.get_element(row_index++);
73 workers->set_key(building.workers);
75 auto* budget = row.get_element(row_index++);
77 budget->set_key(building.budget);
82 auto* scale = row.get_element(row_index++);
83 scale->set_text(
string_format(
"%.2f", building.production_scale));
84 scale->set_key(building.production_scale);
85 scale->set_tooltip(
translate_format(
"Production scale %.2f, level %.2f", building.production_scale, building.level));
87 auto* profit = row.get_element(row_index++);
88 profit->set_text(
string_format(
"%.2f", building.get_profit()));
89 profit->set_key(building.get_profit());
90 profit->set_tooltip(
translate_format(
"Profit: %.2f\nInputs cost: %.2f\nWages: %.2f\nState taxes: %.2f\n\nDividends: %.2f (%.2f to state, %.2f to pops, %.2f to private investors)\nTotal expenses: %.2f\nOutputs revenue: %.2f\nTotal revenue: %.2f", building.get_profit(), building.expenses.inputs_cost, building.expenses.wages, building.expenses.state_taxes, building.expenses.get_dividends(), building.expenses.state_dividends, building.expenses.pop_dividends, building.expenses.private_dividends, building.expenses.get_total(), building.revenue.outputs, building.revenue.get_total()));
92 auto* upgrade = row.get_element(row_index++);
93 upgrade->set_text(
"+");
94 upgrade->set_tooltip(
translate_format(
"Upgrade building to level %.2f", building.level));
96 upgrade->set_on_click([&gs, province_id, type_id =
type.get_id()](
UI::Widget&) {
97 gs.client->send(Action::BuildingAdd::form_packet(gs.world->provinces[province_id], gs.world->building_types[type_id]));
102 table.on_each_tick(table);
105 for(
const auto province_id : provinces) {
106 const auto& province = gs.
world->provinces[province_id];
107 for(
size_t i = 0; i < province.buildings.size(); i++) {
108 const auto&
type = gs.
world->building_types[i];
109 auto& row = table.get_row(row_num++);
111 size_t row_index = 0;
113 if(provinces.size() > 1) row_index++;
119 auto* inputs = row.get_element(row_index++);
120 inputs->set_key(
type.input_ids.size());
123 for(
auto good_id :
type.input_ids) {
124 auto& commodity = gs.
world->commodities[good_id];
125 auto& input_img = inputs->make_widget<
UI::Image>(0, 0, 35, 35, commodity.get_icon_path(),
true);
129 auto* outputs = row.get_element(row_index++);
130 outputs->set_key(
type.output_id);
134 auto& output = gs.
world->commodities[
type.output_id];
135 auto& output_img = outputs->make_widget<
UI::Image>(0, 0, 35, 35, output.get_icon_path(),
true);
143 :
UI::Window(-400, -400, 800, 800),
IndustryWindow(GameState &gs)
static UI::Table< uint32_t > * new_table(GameState &gs, int _x, int _y, int _w, int _h, std::vector< ProvinceId > provinces, UI::Widget *parent)
std::vector< ProvinceId > owned_provinces
Image widget, can display pictures or effects on the screen.
A dynamic/smart table that can sort elements by ascending/descending order.
void reserve(size_t _size)
void set_close_btn_function(std::function< void(Widget &)> on_click)
std::string translate(const std::string_view str)
std::string string_format(const std::string_view format, Args &&... args)
String formatter.
std::string translate_format(const std::string_view format, Args &&... args)
String formatter, with translation.