src/graph_gui.cpp
changeset 5768 dded34549c8c
parent 5766 1980eef57c7d
child 5771 1b62f1c3b266
equal deleted inserted replaced
5767:37871c29071e 5768:dded34549c8c
    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++;
   170 		y = gw->top + gw->height + 1;
   173 		y = gw->top + gw->height + 1;
   171 		j = gw->unk61A;
   174 		j = gw->unk61A;
   172 		i = gw->num_on_x_axis;assert(i>0);
   175 		i = gw->num_on_x_axis;assert(i>0);
   173 		do {
   176 		do {
   174 			SetDParam(0, j);
   177 			SetDParam(0, j);
   175 			DrawString(x, y, STR_01CB, gw->color_3);
   178 			DrawString(x, y, STR_01CB, GRAPH_AXIS_LABEL_COLOUR);
   176 			j += gw->unk61C;
   179 			j += gw->unk61C;
   177 			x += 22;
   180 			x += 22;
   178 		} while (--i);
   181 		} while (--i);
   179 	}
   182 	}
   180 
   183 
   338 		gd.left = 2;
   341 		gd.left = 2;
   339 		gd.top = 18;
   342 		gd.top = 18;
   340 		gd.height = 136;
   343 		gd.height = 136;
   341 		gd.include_neg = true;
   344 		gd.include_neg = true;
   342 		gd.format_str_y_axis = STR_CURRCOMPACT;
   345 		gd.format_str_y_axis = STR_CURRCOMPACT;
   343 		gd.color_3 = 0x10;
       
   344 		gd.color_2 = 0xD7;
       
   345 
   346 
   346 		SetupGraphDrawerForPlayers(&gd);
   347 		SetupGraphDrawerForPlayers(&gd);
   347 
   348 
   348 		numd = 0;
   349 		numd = 0;
   349 		FOR_ALL_PLAYERS(p) {
   350 		FOR_ALL_PLAYERS(p) {
   411 		gd.left = 2;
   412 		gd.left = 2;
   412 		gd.top = 18;
   413 		gd.top = 18;
   413 		gd.height = 104;
   414 		gd.height = 104;
   414 		gd.include_neg = false;
   415 		gd.include_neg = false;
   415 		gd.format_str_y_axis = STR_CURRCOMPACT;
   416 		gd.format_str_y_axis = STR_CURRCOMPACT;
   416 		gd.color_3 = 0x10;
       
   417 		gd.color_2 = 0xD7;
       
   418 		SetupGraphDrawerForPlayers(&gd);
   417 		SetupGraphDrawerForPlayers(&gd);
   419 
   418 
   420 		numd = 0;
   419 		numd = 0;
   421 		FOR_ALL_PLAYERS(p) {
   420 		FOR_ALL_PLAYERS(p) {
   422 			if (p->is_active) {
   421 			if (p->is_active) {
   483 		gd.left = 2;
   482 		gd.left = 2;
   484 		gd.top = 18;
   483 		gd.top = 18;
   485 		gd.height = 104;
   484 		gd.height = 104;
   486 		gd.include_neg = false;
   485 		gd.include_neg = false;
   487 		gd.format_str_y_axis = STR_7024;
   486 		gd.format_str_y_axis = STR_7024;
   488 		gd.color_3 = 0x10;
       
   489 		gd.color_2 = 0xD7;
       
   490 		SetupGraphDrawerForPlayers(&gd);
   487 		SetupGraphDrawerForPlayers(&gd);
   491 
   488 
   492 		numd = 0;
   489 		numd = 0;
   493 		FOR_ALL_PLAYERS(p) {
   490 		FOR_ALL_PLAYERS(p) {
   494 			if (p->is_active) {
   491 			if (p->is_active) {
   555 		gd.left = 2;
   552 		gd.left = 2;
   556 		gd.top = 18;
   553 		gd.top = 18;
   557 		gd.height = 200;
   554 		gd.height = 200;
   558 		gd.include_neg = false;
   555 		gd.include_neg = false;
   559 		gd.format_str_y_axis = STR_7024;
   556 		gd.format_str_y_axis = STR_7024;
   560 		gd.color_3 = 0x10;
       
   561 		gd.color_2 = 0xD7;
       
   562 		SetupGraphDrawerForPlayers(&gd);
   557 		SetupGraphDrawerForPlayers(&gd);
   563 
   558 
   564 		numd = 0;
   559 		numd = 0;
   565 		FOR_ALL_PLAYERS(p) {
   560 		FOR_ALL_PLAYERS(p) {
   566 			if (p->is_active) {
   561 			if (p->is_active) {
   630 		gd.left = 2;
   625 		gd.left = 2;
   631 		gd.top = 18;
   626 		gd.top = 18;
   632 		gd.height = 200;
   627 		gd.height = 200;
   633 		gd.include_neg = false;
   628 		gd.include_neg = false;
   634 		gd.format_str_y_axis = STR_CURRCOMPACT;
   629 		gd.format_str_y_axis = STR_CURRCOMPACT;
   635 		gd.color_3 = 0x10;
       
   636 		gd.color_2 = 0xD7;
       
   637 		SetupGraphDrawerForPlayers(&gd);
   630 		SetupGraphDrawerForPlayers(&gd);
   638 
   631 
   639 		numd = 0;
   632 		numd = 0;
   640 		FOR_ALL_PLAYERS(p) {
   633 		FOR_ALL_PLAYERS(p) {
   641 			if (p->is_active) {
   634 			if (p->is_active) {
   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;