51 auto key = state.lookup_key(
"alice_button_factory_type_priority");
52 auto def = state.ui_state.defs_by_name.find(key)->second.definition;
53 auto& data = state.ui_defs.gui[def];
55 if(state.iui_state.per_market_data.size() != state.world.market_size()) {
56 state.iui_state.per_market_data.resize(state.world.market_size());
59 state.iui_state.input_efficiency_leaders.clear();
60 state.iui_state.input_efficiency_leaders_string.clear();
62 if(state.selected_factory_type) {
63 auto& inputs = state.world.factory_type_get_inputs(state.selected_factory_type);
64 auto& e_inputs = state.world.factory_type_get_efficiency_inputs(state.selected_factory_type);
65 auto ftid = state.selected_factory_type;
67 state.world.for_each_market([&](dcon::market_id market) {
68 auto sid = state.world.market_get_zone_from_local_market(market);
69 auto sdif = state.world.state_instance_get_definition(sid);
70 auto nid = state.world.state_instance_get_nation_from_state_ownership(sid);
73 auto e_input_mult = state.world.nation_get_modifier_values(nid, sys::national_mod_offsets::factory_maintenance) + 1.0f;
78 for(
unsigned i = 0; i < inputs.set_size; i++) {
79 if(inputs.commodity_type[i]) {
80 auto cid = inputs.commodity_type[i];
81 total -= inputs.commodity_amounts[i] * input_mult * state.world.market_get_price(mid, cid);
84 for(
unsigned i = 0; i < e_inputs.set_size; i++) {
85 if(e_inputs.commodity_type[i]) {
86 auto cid = e_inputs.commodity_type[i];
87 total -= e_inputs.commodity_amounts[i] * input_mult * e_input_mult * state.world.market_get_price(mid, cid);
91 auto cid = state.world.factory_type_get_output(ftid).id;
92 total += state.world.factory_type_get_output_amount(ftid) * output_mult * state.world.market_get_price(mid, cid);
93 state.iui_state.per_market_data[market.index()] = total;
96 state.world.for_each_nation([&](dcon::nation_id nid) {
98 state.iui_state.input_efficiency_leaders.push_back(nid);
105 auto icon_size = 20.f;
108 r.
x + 5.f, r.
y + r.
h / 2.f - icon_size / 2.f, icon_size, icon_size
111 state.iui_state.float_2(
112 state, identifier_amount,
116 state.iui_state.price(
117 state, identifier_cost,
123 if(state.iui_state.per_market_data.size() != state.world.market_size()) {
124 state.iui_state.per_market_data.resize(state.world.market_size());
127 state.iui_state.frame_start();
129 if(!state.iui_state.loaded_descriptions) {
130 state.iui_state.load_description(
132 "alice_button_factory_type_priority",
133 state.iui_state.priority_button
135 state.iui_state.load_description(
137 "alice_button_economy_viewer_page",
138 state.iui_state.page_button
140 state.iui_state.load_description(
142 "alice_page_selector_bg",
143 state.iui_state.page_selector_bg
145 state.iui_state.load_description(
147 "alice_button_economy_item_selector",
148 state.iui_state.item_selector_bg
150 state.iui_state.load_description(
152 "alice_factory_type_bg",
153 state.iui_state.factory_type_bg
155 state.iui_state.load_description(
158 state.iui_state.commodity_bg
160 state.iui_state.load_description(
162 "alice_factory_type_name_bg",
163 state.iui_state.factory_type_name_bg
166 state.iui_state.load_description(
168 "alice_factory_type_priority_bg",
169 state.iui_state.factory_type_priority_bg
172 state.iui_state.load_description(
174 "alice_economy_view_close_button",
175 state.iui_state.close_button
178 state.iui_state.load_description(
180 "alice_economy_view_top_bar",
181 state.iui_state.top_bar_button
184 state.iui_state.load_description(
186 "alice_economy_view_map_label",
187 state.iui_state.map_label
191 state.iui_state.loaded_descriptions =
true;
195 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
196 glUseProgram(state.open_gl.ui_shader_program);
197 glUniform1i(state.open_gl.ui_shader_texture_sampler_uniform, 0);
198 glUniform1i(state.open_gl.ui_shader_secondary_texture_sampler_uniform, 1);
199 glUniform1f(state.open_gl.ui_shader_screen_width_uniform,
float(state.x_size) / state.user_settings.ui_scale);
200 glUniform1f(state.open_gl.ui_shader_screen_height_uniform,
float(state.y_size) / state.user_settings.ui_scale);
201 glUniform1f(state.open_gl.ui_shader_gamma_uniform, state.user_settings.gamma);
202 glViewport(0, 0, state.x_size, state.y_size);
203 glDepthRange(-1.0f, 1.0f);
205 auto zoom = state.map_state.zoom;
206 auto screen_size = glm::vec2(state.x_size, state.y_size) / state.user_settings.ui_scale;
212 if(state.iui_state.current_font == 0) {
216 iui::rect market_label_rect{ 0.f, 0.f, state.iui_state.map_label.w, state.iui_state.map_label.h };
217 iui::rect market_label_rect_text = market_label_rect;
219 market_label_rect_text.
w -= 5.f;
221 state.world.for_each_market([&](dcon::market_id mid) {
222 auto sid = state.world.market_get_zone_from_local_market(mid);
223 auto capital = state.world.state_instance_get_capital(sid);
224 auto& midpoint = state.world.province_get_mid_point(capital);
225 auto map_pos = state.map_state.normalize_map_coord(midpoint);
226 glm::vec2 screen_pos{};
227 if(!state.map_state.map_to_screen(state, map_pos, screen_size, screen_pos)) {
231 if(screen_pos.x < -100.f) {
234 if(screen_pos.y < -100.f) {
237 if(screen_pos.x > screen_size.x + 100.f) {
240 if(screen_pos.y > screen_size.y + 100.f) {
246 screen_pos.x - market_label_rect.w / 2.f, screen_pos.y - market_label_rect.h / 2.f
250 market_label_rect_text,
251 screen_pos.
x - market_label_rect.w / 2.f + 5.f, screen_pos.y - market_label_rect.h / 2.f + 2.f
254 state.iui_state.panel_textured(state, market_label_rect, state.iui_state.map_label.texture_handle);
256 if(state.selected_factory_type) {
257 if(mid.index() < (int32_t)(state.iui_state.per_market_data.size())) {
258 state.iui_state.price(
260 market_label_rect_text,
261 state.iui_state.per_market_data[mid.index()]
265 state.iui_state.float_2(
267 market_label_rect_text,
268 state.world.market_get_max_throughput(mid)
275 float tabs_layout_start = 0.f;
276 float tabs_layout_margin = 0.f;
277 float tab_height = state.iui_state.top_bar_button.h;
278 float tab_width = state.iui_state.top_bar_button.w;
280 iui::rect tab_rect{ tabs_layout_start, tabs_layout_margin, tab_width, tab_height };
285 if(
state.iui_state.button_textured(
287 tab_rect, 3,
state.iui_state.top_bar_button.texture_handle,
293 state.iui_state.localized_string(
298 tab_rect.x += tab_width + tabs_layout_margin;
299 tab_name_rect.
x += tab_width + tabs_layout_margin;
301 if(
state.iui_state.button_textured(
303 tab_rect, 3,
state.iui_state.top_bar_button.texture_handle,
309 state.iui_state.localized_string(
319 float size_panel_w = 400.f;
320 float size_panel_h = 500.f;
322 float size_selector_w = 150.f;
323 float size_page_selector_h = 50.f;
324 float top = screen_size.y - size_panel_h;
325 float priority_settings_height = 80.f;
328 float size_view_w = size_panel_w - size_selector_w;
329 iui::rect selector_panel = { margin,
top, size_selector_w, size_panel_h - size_page_selector_h };
330 iui::rect page_selector_rect = { margin,
top + size_panel_h - size_page_selector_h, size_selector_w, size_page_selector_h };
331 iui::rect view_panel = { margin + size_selector_w,
top, size_view_w, size_panel_h };
338 iui::rect selector_button = selector_panel;
339 selector_button.
h = selector_panel.
h / float(factories_on_a_page);
340 auto page =
state.iui_state.page_production_methods;
344 auto icon_size = 20.f;
345 state.iui_state.panel(state, selector_panel);
349 i < factories_on_a_page;
352 auto factory_index = i + factories_on_a_page * page;
353 if(factory_index >=
state.world.factory_type_size()) {
356 dcon::factory_type_id ftid{ (dcon::factory_type_id::value_base_t)factory_index };
357 selector_button.
y = selector_panel.
y + i * selector_button.
h;
358 if(
state.iui_state.button_textured(
361 3,
state.iui_state.item_selector_bg.texture_handle,
362 state.selected_factory_type == ftid
364 if(
state.selected_factory_type == ftid) {
365 state.selected_factory_type = { };
367 state.selected_factory_type = ftid;
371 state.iui_state.localized_string_r(
373 { selector_button.x + 30.f, selector_button.y, selector_button.w - 30.f, selector_button.h },
377 state,
state.world.factory_type_get_output(ftid),
378 selector_button.
x + 5.f,
379 selector_button.
y + selector_button.
h / 2.f - icon_size / 2.f, icon_size, icon_size
383 state.iui_state.panel_textured(
384 state, page_selector_rect,
state.iui_state.page_selector_bg.texture_handle
387 int pages = (
state.world.factory_type_size() - 1) / factories_on_a_page + 1;
391 page_selector_rect.
y -
state.iui_state.page_button.h / 2.f + page_selector_rect.
h / 2.f,
392 state.iui_state.page_button.w,
393 state.iui_state.page_button.h
396 if(pages *
state.iui_state.page_button.w <= page_selector_rect.
w) {
397 float margin_pages = (page_selector_rect.
w - pages * page_button.w) / (pages + 1);
399 for(
int i = 0; i < pages; i++) {
400 page_button.x = page_selector_rect.
x + (page_button.w + margin_pages) * i + margin_pages;
402 if(
state.iui_state.button_textured(
406 3,
state.iui_state.page_button.texture_handle,
407 state.iui_state.page_production_methods == i
409 state.iui_state.page_production_methods = i;
412 state.iui_state.int_whole(
419 page_button.x = page_selector_rect.
x + margin;
420 if(
state.iui_state.button_textured(
422 page_button, 3,
state.iui_state.page_button.texture_handle, false
424 state.iui_state.page_production_methods = std::max(0,
state.iui_state.page_production_methods - 1);
427 page_button.x = page_selector_rect.
x + page_selector_rect.
w - page_button.w - margin;
428 if(
state.iui_state.button_textured(
430 page_button, 3,
state.iui_state.page_button.texture_handle,
false
432 state.iui_state.page_production_methods = std::min(
433 pages - 1,
state.iui_state.page_production_methods + 1
437 iui::rect page_selector_page_current = page_selector_rect;
438 page_selector_page_current.
x = page_selector_rect.
x + page_selector_rect.
w / 4.f;
439 page_selector_page_current.
w = page_selector_rect.
w / 2.f;
440 page_selector_page_current.
y = page_selector_rect.
y + margin;
441 page_selector_page_current.
h = page_selector_rect.
h - margin * 2.f;
443 page_selector_page_current.
w /= 2.f;
444 state.iui_state.int_whole(
447 page_selector_page_current,
state.iui_state.page_production_methods
450 page_selector_page_current.
x += page_selector_page_current.
w;
451 state.iui_state.int_whole(
454 page_selector_page_current, pages
459 if(
state.selected_factory_type &&
state.map_state.selected_province) {
460 auto ftid =
state.selected_factory_type;
461 auto sid =
state.world.province_get_state_membership(
state.map_state.selected_province);
462 auto sdif =
state.world.state_instance_get_definition(sid);
463 auto nid =
state.world.province_get_nation_from_province_ownership(
state.map_state.selected_province);
464 auto mid =
state.world.state_instance_get_market_from_local_market(sid);
466 auto e_input_mult =
state.world.nation_get_modifier_values(nid, sys::national_mod_offsets::factory_maintenance) + 1.0f;
470 state.iui_state.panel_textured(state, view_panel,
state.iui_state.factory_type_bg.texture_handle);
473 view_panel.
x + 5.f, view_panel.
y + 5.f, 200.f, 40.f
476 state.iui_state.panel_textured(state, name_labels,
state.iui_state.factory_type_name_bg.texture_handle);
478 state.iui_state.localized_string_r(
481 { view_panel.
x + 10.f, view_panel.
y + 7.f, view_panel.
w, 18.f },
485 state.iui_state.localized_string_r(
488 { view_panel.
x + 10.f, view_panel.
y + 25.f, view_panel.
w, 18.f },
493 view_panel.
x + view_panel.
w -
state.iui_state.close_button.w,
495 state.iui_state.close_button.w,
496 state.iui_state.close_button.h
498 if(
state.iui_state.button_textured(
500 3,
state.iui_state.close_button.texture_handle,
false
502 state.selected_factory_type = { };
506 auto& inputs =
state.world.factory_type_get_inputs(ftid);
508 for(
unsigned i = 0; i < inputs.set_size; i++) {
509 if(inputs.commodity_type[i]) {
513 auto& e_inputs =
state.world.factory_type_get_efficiency_inputs(ftid);
514 int e_inputs_size = 0;
515 for(
unsigned i = 0; i < e_inputs.set_size; i++) {
516 if(e_inputs.commodity_type[i]) {
521 float grid_margin = 5.f;
522 int items_per_row = 3;
524 iui::rect commodity_rect{ 0.f, 0.f, (view_panel.
w - grid_margin) /
float(items_per_row) - grid_margin, 40.f };
525 iui::rect commodity_labels{ 0.f, 0.f, ((view_panel.
w - grid_margin) /
float(items_per_row) - grid_margin) - 5.f, 40.f };
527 int rows_input = ((inputs_size - 1) / items_per_row) + 1;
528 int rows_e_input = ((e_inputs_size - 1) / items_per_row) + 1;
535 float current_y = view_panel.
y + 50.f;
537 for(
unsigned i = 0; i < inputs.set_size; i++) {
538 if(inputs.commodity_type[i]) {
539 auto cid = inputs.commodity_type[i];
541 int row = i / items_per_row;
542 int column = i - row * items_per_row;
543 commodity_rect.x = view_panel.
x + grid_margin + column * (grid_margin + commodity_rect.w);
544 commodity_rect.y = current_y + grid_margin + row * (grid_margin + commodity_rect.h);
546 commodity_labels.x = commodity_rect.x;
547 commodity_labels.y = commodity_rect.y;
549 state.iui_state.panel_textured(state, commodity_rect,
state.iui_state.commodity_bg.texture_handle);
555 inputs.commodity_amounts[i] * input_mult,
556 state.world.market_get_price(mid, cid),
560 total -= inputs.commodity_amounts[i] * input_mult *
state.world.market_get_price(mid, cid);
564 current_y += grid_margin + rows_input * (grid_margin + commodity_rect.h) + 10.f;
568 for(
unsigned i = 0; i < e_inputs.set_size; i++) {
569 if(e_inputs.commodity_type[i]) {
570 auto cid = e_inputs.commodity_type[i];
572 int row = i / items_per_row;
573 int column = i - row * items_per_row;
574 commodity_rect.x = view_panel.
x + grid_margin + column * (grid_margin + commodity_rect.w);
575 commodity_rect.y = current_y + grid_margin + row * (grid_margin + commodity_rect.h);
577 commodity_labels.x = commodity_rect.x;
578 commodity_labels.y = commodity_rect.y;
580 state.iui_state.panel_textured(state, commodity_rect,
state.iui_state.commodity_bg.texture_handle);
586 e_inputs.commodity_amounts[i] * input_mult * e_input_mult,
587 state.world.market_get_price(mid, cid),
591 total -= e_inputs.commodity_amounts[i] * input_mult * e_input_mult *
state.world.market_get_price(mid, cid);
595 current_y += grid_margin + rows_e_input * (grid_margin + commodity_rect.h) + 10.f;
597 commodity_rect.x = view_panel.
x + grid_margin;
598 commodity_rect.y = current_y;
601 auto cid =
state.world.factory_type_get_output(ftid).id;
603 commodity_labels.x = commodity_rect.x;
604 commodity_labels.y = commodity_rect.y;
606 state.iui_state.panel_textured(state, commodity_rect,
state.iui_state.commodity_bg.texture_handle);
612 state.world.factory_type_get_output_amount(ftid) * output_mult,
613 state.world.market_get_price(mid, cid),
617 commodity_rect.x += commodity_rect.w + grid_margin;
618 commodity_labels.x = commodity_rect.x;
619 commodity_labels.y = commodity_rect.y;
621 total +=
state.world.factory_type_get_output_amount(ftid) * output_mult *
state.world.market_get_price(mid, cid);
622 state.iui_state.panel_textured(state, commodity_rect,
state.iui_state.commodity_bg.texture_handle);
623 state.iui_state.price(
625 commodity_labels, total
628 iui::rect leader_rect{ view_panel.
x + margin, commodity_labels.y + commodity_labels.h + 5.f, 20.f, 20.f };
632 auto& current_font =
state.font_collection.get_font(state, font_index);
634 for(
unsigned i = 0; i <
state.iui_state.input_efficiency_leaders.size(); i++) {
635 auto leader =
state.iui_state.input_efficiency_leaders[i];
638 {
state.world.nation_get_identity_from_identity_holder(leader) },
645 leader_rect.x += leader_rect.w;
647 if(leader_rect.x + leader_rect.w > view_panel.
x + view_panel.
w - margin) {
648 leader_rect.y += leader_rect.h;
649 leader_rect.x = view_panel.
x + margin;
654 iui::rect priority_settings{ view_panel.
x, view_panel.
y + view_panel.
h - priority_settings_height - 30.f, view_panel.
w, priority_settings_height };
656 state.iui_state.panel_textured(state, priority_settings,
state.iui_state.factory_type_priority_bg.texture_handle);
659 iui::rect priority_description{ priority_settings.
x, priority_settings.y, priority_settings.w - 10.f, 20.f };
661 state.iui_state.localized_string(
664 priority_description,
668 priority_description.y += 15.f;
669 state.iui_state.localized_string(
672 priority_description,
675 state.iui_state.float_2(
681 priority_description.y += 15.f;
682 state.iui_state.localized_string(
685 priority_description,
688 state.iui_state.float_2(
694 priority_description.y += 15.f;
695 state.iui_state.localized_string(
698 priority_description,
701 state.iui_state.float_2(
704 priority_description,
709 view_panel.
x + 7.f, view_panel.
y + view_panel.
h - 30.f,
710 state.iui_state.priority_button.w,
state.iui_state.priority_button.h
713 auto current_priority =
state.world.nation_get_factory_type_experience_priority_national(
714 state.local_player_nation, ftid
717 for(
int i = 0; i < 9; i++) {
718 if(
state.iui_state.button_textured(
721 3,
state.iui_state.priority_button.texture_handle,
722 current_priority >= (
float)(i) * 100.f
726 button_priority.x += button_priority.w;
732 state.iui_state.frame_end();
@ set_factory_type_priority
constexpr dcon::demographics_key total(0)
void commodity_panel(sys::state &state, int32_t identifier_amount, int32_t identifier_cost, dcon::commodity_id cid, float amount, float price, iui::rect &r)
void update(sys::state &state)
@ factory_type_priority_button
@ commodities_e_inputs_cost
@ commodities_inputs_amount
@ priority_value_national
@ commodities_e_inputs_amount
@ commodities_inputs_cost
@ commodities_output_amount
@ factory_type_page_number
@ close_factory_type_description
@ commodities_output_cost
@ input_efficiency_leaders
@ tab_name_production_chain
void render(sys::state &state)
float nation_factory_output_multiplier(sys::state const &state, dcon::factory_type_id fac_type, dcon::nation_id n)
float nation_factory_input_multiplier(sys::state const &state, dcon::factory_type_id fac_type, dcon::nation_id n)
float priority_multiplier(sys::state const &state, dcon::factory_type_id fac_type, dcon::nation_id n)
void shrink(rect &rectangle, float value)
void move_to(rect &rectangle, float x, float y)
constexpr float zoom_close
float priority_national(sys::state &state, dcon::nation_id n, dcon::factory_type_id ftid)
float priority_private(sys::state &state, dcon::nation_id n, dcon::factory_type_id ftid)
void render_text_flag(sys::state &state, text::embedded_flag ico, float x, float baseline_y, float font_size, text::font &f, ogl::color_modification cmod)
void render_commodity_icon(sys::state &state, dcon::commodity_id cid, float x, float y, float w, float h)
int32_t size_from_font_id(uint16_t id)
uint32_t font_index(std::string_view txt)
uint16_t name_into_font_id(sys::state &state, std::string_view txt)
std::string produce_simple_string(sys::state const &state, dcon::text_key id)
font_selection font_index_from_font_id(sys::state &state, uint16_t id)
uint32_t font_size(std::string_view txt)
ogl::color3f get_text_color(sys::state &state, text::text_color text_color)
Holds important data about the game world, state, and other data regarding windowing,...