21 |
21 |
22 /************************/ |
22 /************************/ |
23 /* GENERIC GRAPH DRAWER */ |
23 /* GENERIC GRAPH DRAWER */ |
24 /************************/ |
24 /************************/ |
25 |
25 |
26 enum {GRAPH_NUM = 16}; |
26 enum { |
|
27 GRAPH_MAX_DATASETS = 16, |
|
28 GRAPH_AXIS_LABEL_COLOUR = 16, |
|
29 GRAPH_AXIS_LINE_COLOUR = 215, |
|
30 }; |
27 |
31 |
28 typedef struct GraphDrawer { |
32 typedef struct GraphDrawer { |
29 uint sel; // bitmask of the players *excluded* (e.g. 11111111 means that no players are shown) |
33 uint sel; // bitmask of the players *excluded* (e.g. 11111111 means that no players are shown) |
30 byte num_dataset; |
34 byte num_dataset; |
31 byte num_on_x_axis; |
35 byte num_on_x_axis; |
36 uint16 unk61A; |
40 uint16 unk61A; |
37 uint16 unk61C; |
41 uint16 unk61C; |
38 int left, top; |
42 int left, top; |
39 uint height; |
43 uint height; |
40 StringID format_str_y_axis; |
44 StringID format_str_y_axis; |
41 byte color_3, color_2; |
45 byte colors[GRAPH_MAX_DATASETS]; |
42 byte colors[GRAPH_NUM]; |
46 int64 cost[GRAPH_MAX_DATASETS][24]; // last 2 years |
43 int64 cost[GRAPH_NUM][24]; // last 2 years |
|
44 } GraphDrawer; |
47 } GraphDrawer; |
45 |
48 |
46 static const int64 INVALID_VALUE = 0x80000000; |
49 static const int64 INVALID_VALUE = 0x80000000; |
47 |
50 |
48 static void DrawGraph(const GraphDrawer *gw) |
51 static void DrawGraph(const GraphDrawer *gw) |
60 int64 cur_val; |
63 int64 cur_val; |
61 uint sel; |
64 uint sel; |
62 |
65 |
63 /* the colors and cost array of GraphDrawer must accomodate |
66 /* the colors and cost array of GraphDrawer must accomodate |
64 * both values for cargo and players. So if any are higher, quit */ |
67 * both values for cargo and players. So if any are higher, quit */ |
65 assert(GRAPH_NUM >= (int)NUM_CARGO && GRAPH_NUM >= (int)MAX_PLAYERS); |
68 assert(GRAPH_MAX_DATASETS >= (int)NUM_CARGO && GRAPH_MAX_DATASETS >= (int)MAX_PLAYERS); |
66 |
69 |
67 byte grid_colour = _colour_gradient[14][4]; |
70 byte grid_colour = _colour_gradient[14][4]; |
68 |
71 |
69 /* draw the vertical lines */ |
72 /* draw the vertical lines */ |
70 i = gw->num_vert_lines; assert(i > 0); |
73 i = gw->num_vert_lines; assert(i > 0); |
85 GfxFillRect(x, y, right, y, grid_colour); |
88 GfxFillRect(x, y, right, y, grid_colour); |
86 y -= gw->height >> 3; |
89 y -= gw->height >> 3; |
87 } while (--i); |
90 } while (--i); |
88 |
91 |
89 /* draw vertical edge line */ |
92 /* draw vertical edge line */ |
90 GfxFillRect(x, gw->top, x, bottom, gw->color_2); |
93 GfxFillRect(x, gw->top, x, bottom, GRAPH_AXIS_LINE_COLOUR); |
91 |
94 |
92 adj_height = gw->height; |
95 adj_height = gw->height; |
93 if (gw->include_neg) adj_height >>= 1; |
96 if (gw->include_neg) adj_height >>= 1; |
94 |
97 |
95 /* draw horiz edge line */ |
98 /* draw horiz edge line */ |
96 y = adj_height + gw->top; |
99 y = adj_height + gw->top; |
97 GfxFillRect(x, y, right, y, gw->color_2); |
100 GfxFillRect(x, y, right, y, GRAPH_AXIS_LINE_COLOUR); |
98 |
101 |
99 /* find the max element */ |
102 /* find the max element */ |
100 if (gw->num_on_x_axis == 0) |
103 if (gw->num_on_x_axis == 0) |
101 return; |
104 return; |
102 |
105 |
139 i = 9; |
142 i = 9; |
140 do { |
143 do { |
141 SetDParam(0, gw->format_str_y_axis); |
144 SetDParam(0, gw->format_str_y_axis); |
142 SetDParam64(1, (int64)tmp); |
145 SetDParam64(1, (int64)tmp); |
143 tmp -= (value >> 3); |
146 tmp -= (value >> 3); |
144 DrawStringRightAligned(x, y, STR_0170, gw->color_3); |
147 DrawStringRightAligned(x, y, STR_0170, GRAPH_AXIS_LABEL_COLOUR); |
145 y += gw->height >> 3; |
148 y += gw->height >> 3; |
146 } while (--i); |
149 } while (--i); |
147 |
150 |
148 /* draw strings on the x axis */ |
151 /* draw strings on the x axis */ |
149 if (gw->month != 0xFF) { |
152 if (gw->month != 0xFF) { |
154 i = gw->num_on_x_axis;assert(i>0); |
157 i = gw->num_on_x_axis;assert(i>0); |
155 do { |
158 do { |
156 SetDParam(2, k); |
159 SetDParam(2, k); |
157 SetDParam(0, j + STR_0162_JAN); |
160 SetDParam(0, j + STR_0162_JAN); |
158 SetDParam(1, j + STR_0162_JAN + 2); |
161 SetDParam(1, j + STR_0162_JAN + 2); |
159 DrawString(x, y, j == 0 ? STR_016F : STR_016E, gw->color_3); |
162 DrawString(x, y, j == 0 ? STR_016F : STR_016E, GRAPH_AXIS_LABEL_COLOUR); |
160 |
163 |
161 j += 3; |
164 j += 3; |
162 if (j >= 12) { |
165 if (j >= 12) { |
163 j = 0; |
166 j = 0; |
164 k++; |
167 k++; |
713 gd.left = 2; |
706 gd.left = 2; |
714 gd.top = 24; |
707 gd.top = 24; |
715 gd.height = 104; |
708 gd.height = 104; |
716 gd.include_neg = false; |
709 gd.include_neg = false; |
717 gd.format_str_y_axis = STR_CURRCOMPACT; |
710 gd.format_str_y_axis = STR_CURRCOMPACT; |
718 gd.color_3 = 16; |
|
719 gd.color_2 = 215; |
|
720 gd.num_dataset = NUM_CARGO; |
711 gd.num_dataset = NUM_CARGO; |
721 gd.num_on_x_axis = 20; |
712 gd.num_on_x_axis = 20; |
722 gd.num_vert_lines = 20; |
713 gd.num_vert_lines = 20; |
723 gd.month = 0xFF; |
714 gd.month = 0xFF; |
724 gd.unk61A = 10; |
715 gd.unk61A = 10; |