Skip to content

Commit efd20f9

Browse files
committed
ui: improves for farm info window text
1 parent dfd8abc commit efd20f9

File tree

2 files changed

+15
-23
lines changed

2 files changed

+15
-23
lines changed

src/scripts/ui.js

+1
Original file line numberDiff line numberDiff line change
@@ -1115,6 +1115,7 @@ info_window_recruiter = {
11151115
info_window_farm = {
11161116
ui : __baseui(building_info_window, {
11171117
resource : { type : "resource_icon", pos:[10, 10] },
1118+
workers_desc : { type : "text", pos: [70, 116], font: FONT_NORMAL_BLACK_ON_DARK, multiline:true, wrap:px(23) },
11181119
farm_desc : { type : "text", pos: [32, 64], font: FONT_NORMAL_BLACK_ON_LIGHT, wrap:px(27), multiline:true },
11191120
farm_state : { type : "text", pos: [32, 186], font: FONT_NORMAL_BLACK_ON_LIGHT, wrap:px(27), multiline:true },
11201121
flood_info : { type : "text", pos: [32, 206], font: FONT_NORMAL_BLACK_ON_LIGHT },

src/window/window_info_farm.cpp

+14-23
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,16 @@
99
#include "config/config.h"
1010
#include "js/js_game.h"
1111

12-
struct farm_info_window : public building_info_window {
12+
struct info_window_farm : public building_info_window_t<info_window_farm> {
1313
virtual void window_info_background(object_info &c) override;
1414
virtual bool check(object_info &c) override {
1515
return c.building_get()->dcast_farm();
1616
}
1717
};
1818

19-
farm_info_window farm_infow;
19+
info_window_farm farm_infow;
2020

21-
ANK_REGISTER_CONFIG_ITERATOR(config_load_farm_info_window);
22-
void config_load_farm_info_window() {
23-
farm_infow.load("info_window_farm");
24-
}
25-
26-
void farm_info_window::window_info_background(object_info &c) {
21+
void info_window_farm::window_info_background(object_info &c) {
2722
building_info_window::window_info_background(c);
2823

2924
building *b = c.building_get();
@@ -37,23 +32,19 @@ void farm_info_window::window_info_background(object_info &c) {
3732
ui::str(c.group_id, 2), pct_grown, ui::str(c.group_id, 3),
3833
ui::str(c.group_id, 12), pct_fertility, ui::str(c.group_id, 13));
3934

40-
std::pair<int, int> reason = { c.group_id, 0 };
41-
if (!c.has_road_access) { reason = { 69, 25 }; }
42-
else if (city_resource_is_mothballed(b->output_resource_first_id)) { reason.second = 4; }
43-
else if (b->data.industry.curse_days_left > 4) { reason.second = 11; }
44-
else if (b->num_workers <= 0) { reason.second = 5; }
45-
else reason.second = approximate_value(c.worker_percentage / 100.f, make_array(10, 9, 8, 7, 6));
46-
47-
ui["workers_text"] = ui::str(reason.first, reason.second);
35+
textid reason{ c.group_id, 0 };
36+
if (!b->num_workers) {
37+
reason = { 177, 5 };
38+
} else {
39+
if (!c.has_road_access) { reason = { 69, 25 }; }
40+
else if (city_resource_is_mothballed(b->output_resource_first_id)) { reason.id = 4; }
41+
else if (b->data.industry.curse_days_left > 4) { reason.id = 11; }
42+
else if (b->num_workers <= 0) { reason.id = 5; }
43+
else reason.id = approximate_value(c.worker_percentage / 100.f, make_array(10, 9, 8, 7, 6));
44+
}
45+
ui["workers_desc"] = reason;
4846

4947
if (building_is_floodplain_farm(*b)) {
50-
int text_id = 5;
51-
if (b->num_workers >= model_get_building(b->type)->laborers) {
52-
text_id = 6;
53-
}
54-
55-
ui["workers_desc"] = ui::str(177, text_id);
56-
5748
// next flood info
5849
int month_id = 8; // TODO: fetch flood info
5950
ui["flood_info"].text_var("%s %s", ui::str(177, 2), ui::str(160, month_id));

0 commit comments

Comments
 (0)