graph_gui.c
changeset 2952 6a26eeda9679
parent 2869 5cf9acd29edd
child 3027 43ffdf4d6a1f
equal deleted inserted replaced
2951:2db3adee7736 2952:6a26eeda9679
   219 
   219 
   220 static void GraphLegendWndProc(Window *w, WindowEvent *e)
   220 static void GraphLegendWndProc(Window *w, WindowEvent *e)
   221 {
   221 {
   222 	const Player* p;
   222 	const Player* p;
   223 
   223 
   224 	switch(e->event) {
   224 	switch (e->event) {
   225 	case WE_PAINT:
   225 	case WE_PAINT:
   226 		FOR_ALL_PLAYERS(p) {
   226 		FOR_ALL_PLAYERS(p) {
   227 			if (!p->is_active) SETBIT(_legend_excludebits, p->index);
   227 			if (!p->is_active) SETBIT(_legend_excludebits, p->index);
   228 		}
   228 		}
   229 		w->click_state = (~_legend_excludebits) << 3;
   229 		w->click_state = (~_legend_excludebits) << 3;
   318 	gd->month = mo;
   318 	gd->month = mo;
   319 }
   319 }
   320 
   320 
   321 static void OperatingProfitWndProc(Window *w, WindowEvent *e)
   321 static void OperatingProfitWndProc(Window *w, WindowEvent *e)
   322 {
   322 {
   323 	switch(e->event) {
   323 	switch (e->event) {
   324 	case WE_PAINT: {
   324 	case WE_PAINT: {
   325 		GraphDrawer gd;
   325 		GraphDrawer gd;
   326 		const Player* p;
   326 		const Player* p;
   327 		int i,j;
   327 		int i,j;
   328 		int numd;
   328 		int numd;
   342 
   342 
   343 		numd = 0;
   343 		numd = 0;
   344 		FOR_ALL_PLAYERS(p) {
   344 		FOR_ALL_PLAYERS(p) {
   345 			if (p->is_active) {
   345 			if (p->is_active) {
   346 				gd.colors[numd] = _color_list[p->player_color].window_color_bgb;
   346 				gd.colors[numd] = _color_list[p->player_color].window_color_bgb;
   347 				for(j=gd.num_on_x_axis,i=0; --j >= 0;) {
   347 				for (j = gd.num_on_x_axis, i = 0; --j >= 0;) {
   348 					gd.cost[numd][i] = (j >= p->num_valid_stat_ent) ? INVALID_VALUE : (uint64)(p->old_economy[j].income + p->old_economy[j].expenses);
   348 					gd.cost[numd][i] = (j >= p->num_valid_stat_ent) ? INVALID_VALUE : (uint64)(p->old_economy[j].income + p->old_economy[j].expenses);
   349 					i++;
   349 					i++;
   350 				}
   350 				}
   351 			}
   351 			}
   352 			numd++;
   352 			numd++;
   392 /* INCOME GRAPH */
   392 /* INCOME GRAPH */
   393 /****************/
   393 /****************/
   394 
   394 
   395 static void IncomeGraphWndProc(Window *w, WindowEvent *e)
   395 static void IncomeGraphWndProc(Window *w, WindowEvent *e)
   396 {
   396 {
   397 	switch(e->event) {
   397 	switch (e->event) {
   398 	case WE_PAINT: {
   398 	case WE_PAINT: {
   399 		GraphDrawer gd;
   399 		GraphDrawer gd;
   400 		const Player* p;
   400 		const Player* p;
   401 		int i,j;
   401 		int i,j;
   402 		int numd;
   402 		int numd;
   415 
   415 
   416 		numd = 0;
   416 		numd = 0;
   417 		FOR_ALL_PLAYERS(p) {
   417 		FOR_ALL_PLAYERS(p) {
   418 			if (p->is_active) {
   418 			if (p->is_active) {
   419 				gd.colors[numd] = _color_list[p->player_color].window_color_bgb;
   419 				gd.colors[numd] = _color_list[p->player_color].window_color_bgb;
   420 				for(j=gd.num_on_x_axis,i=0; --j >= 0;) {
   420 				for (j = gd.num_on_x_axis, i = 0; --j >= 0;) {
   421 					gd.cost[numd][i] = (j >= p->num_valid_stat_ent) ? INVALID_VALUE : (uint64)p->old_economy[j].income;
   421 					gd.cost[numd][i] = (j >= p->num_valid_stat_ent) ? INVALID_VALUE : (uint64)p->old_economy[j].income;
   422 					i++;
   422 					i++;
   423 				}
   423 				}
   424 			}
   424 			}
   425 			numd++;
   425 			numd++;
   465 /* DELIVERED CARGO */
   465 /* DELIVERED CARGO */
   466 /*******************/
   466 /*******************/
   467 
   467 
   468 static void DeliveredCargoGraphWndProc(Window *w, WindowEvent *e)
   468 static void DeliveredCargoGraphWndProc(Window *w, WindowEvent *e)
   469 {
   469 {
   470 	switch(e->event) {
   470 	switch (e->event) {
   471 	case WE_PAINT: {
   471 	case WE_PAINT: {
   472 		GraphDrawer gd;
   472 		GraphDrawer gd;
   473 		const Player* p;
   473 		const Player* p;
   474 		int i,j;
   474 		int i,j;
   475 		int numd;
   475 		int numd;
   488 
   488 
   489 		numd = 0;
   489 		numd = 0;
   490 		FOR_ALL_PLAYERS(p) {
   490 		FOR_ALL_PLAYERS(p) {
   491 			if (p->is_active) {
   491 			if (p->is_active) {
   492 				gd.colors[numd] = _color_list[p->player_color].window_color_bgb;
   492 				gd.colors[numd] = _color_list[p->player_color].window_color_bgb;
   493 				for(j=gd.num_on_x_axis,i=0; --j >= 0;) {
   493 				for (j = gd.num_on_x_axis, i = 0; --j >= 0;) {
   494 					gd.cost[numd][i] = (j >= p->num_valid_stat_ent) ? INVALID_VALUE : (uint64)p->old_economy[j].delivered_cargo;
   494 					gd.cost[numd][i] = (j >= p->num_valid_stat_ent) ? INVALID_VALUE : (uint64)p->old_economy[j].delivered_cargo;
   495 					i++;
   495 					i++;
   496 				}
   496 				}
   497 			}
   497 			}
   498 			numd++;
   498 			numd++;
   538 /* PERFORMANCE HISTORY */
   538 /* PERFORMANCE HISTORY */
   539 /***********************/
   539 /***********************/
   540 
   540 
   541 static void PerformanceHistoryWndProc(Window *w, WindowEvent *e)
   541 static void PerformanceHistoryWndProc(Window *w, WindowEvent *e)
   542 {
   542 {
   543 	switch(e->event) {
   543 	switch (e->event) {
   544 	case WE_PAINT: {
   544 	case WE_PAINT: {
   545 		GraphDrawer gd;
   545 		GraphDrawer gd;
   546 		const Player* p;
   546 		const Player* p;
   547 		int i,j;
   547 		int i,j;
   548 		int numd;
   548 		int numd;
   561 
   561 
   562 		numd = 0;
   562 		numd = 0;
   563 		FOR_ALL_PLAYERS(p) {
   563 		FOR_ALL_PLAYERS(p) {
   564 			if (p->is_active) {
   564 			if (p->is_active) {
   565 				gd.colors[numd] = _color_list[p->player_color].window_color_bgb;
   565 				gd.colors[numd] = _color_list[p->player_color].window_color_bgb;
   566 				for(j=gd.num_on_x_axis,i=0; --j >= 0;) {
   566 				for (j = gd.num_on_x_axis, i = 0; --j >= 0;) {
   567 					gd.cost[numd][i] = (j >= p->num_valid_stat_ent) ? INVALID_VALUE : (uint64)p->old_economy[j].performance_history;
   567 					gd.cost[numd][i] = (j >= p->num_valid_stat_ent) ? INVALID_VALUE : (uint64)p->old_economy[j].performance_history;
   568 					i++;
   568 					i++;
   569 				}
   569 				}
   570 			}
   570 			}
   571 			numd++;
   571 			numd++;
   614 /* COMPANY VALUE */
   614 /* COMPANY VALUE */
   615 /*****************/
   615 /*****************/
   616 
   616 
   617 static void CompanyValueGraphWndProc(Window *w, WindowEvent *e)
   617 static void CompanyValueGraphWndProc(Window *w, WindowEvent *e)
   618 {
   618 {
   619 	switch(e->event) {
   619 	switch (e->event) {
   620 	case WE_PAINT: {
   620 	case WE_PAINT: {
   621 		GraphDrawer gd;
   621 		GraphDrawer gd;
   622 		const Player* p;
   622 		const Player* p;
   623 		int i,j;
   623 		int i,j;
   624 		int numd;
   624 		int numd;
   637 
   637 
   638 		numd = 0;
   638 		numd = 0;
   639 		FOR_ALL_PLAYERS(p) {
   639 		FOR_ALL_PLAYERS(p) {
   640 			if (p->is_active) {
   640 			if (p->is_active) {
   641 				gd.colors[numd] = _color_list[p->player_color].window_color_bgb;
   641 				gd.colors[numd] = _color_list[p->player_color].window_color_bgb;
   642 				for(j=gd.num_on_x_axis,i=0; --j >= 0;) {
   642 				for (j = gd.num_on_x_axis, i = 0; --j >= 0;) {
   643 					gd.cost[numd][i] = (j >= p->num_valid_stat_ent) ? INVALID_VALUE : (uint64)p->old_economy[j].company_value;
   643 					gd.cost[numd][i] = (j >= p->num_valid_stat_ent) ? INVALID_VALUE : (uint64)p->old_economy[j].company_value;
   644 					i++;
   644 					i++;
   645 				}
   645 				}
   646 			}
   646 			}
   647 			numd++;
   647 			numd++;
   689 
   689 
   690 static const byte _cargo_legend_colors[12] = {152, 32, 15, 174, 208, 194, 191, 84, 184, 10, 202, 215};
   690 static const byte _cargo_legend_colors[12] = {152, 32, 15, 174, 208, 194, 191, 84, 184, 10, 202, 215};
   691 
   691 
   692 static void CargoPaymentRatesWndProc(Window *w, WindowEvent *e)
   692 static void CargoPaymentRatesWndProc(Window *w, WindowEvent *e)
   693 {
   693 {
   694 	switch(e->event) {
   694 	switch (e->event) {
   695 	case WE_PAINT: {
   695 	case WE_PAINT: {
   696 		int i, j, x, y;
   696 		int i, j, x, y;
   697 		GraphDrawer gd;
   697 		GraphDrawer gd;
   698 
   698 
   699 		gd.sel = _legend_cargobits;
   699 		gd.sel = _legend_cargobits;
   701 		DrawWindowWidgets(w);
   701 		DrawWindowWidgets(w);
   702 
   702 
   703 		x = 495;
   703 		x = 495;
   704 		y = 25;
   704 		y = 25;
   705 
   705 
   706 		for(i=0; i!=NUM_CARGO; i++) {
   706 		for (i = 0; i != NUM_CARGO; i++) {
   707 			GfxFillRect(x, y, x+8, y+5, 0);
   707 			GfxFillRect(x, y, x+8, y+5, 0);
   708 			GfxFillRect(x+1, y+1, x+7, y+4, _cargo_legend_colors[i]);
   708 			GfxFillRect(x+1, y+1, x+7, y+4, _cargo_legend_colors[i]);
   709 			SetDParam(0, _cargoc.names_s[i]);
   709 			SetDParam(0, _cargoc.names_s[i]);
   710 			DrawString(x+14, y, STR_7065, 0);
   710 			DrawString(x+14, y, STR_7065, 0);
   711 			y += 8;
   711 			y += 8;
   724 		gd.num_vert_lines = 20;
   724 		gd.num_vert_lines = 20;
   725 		gd.month = 0xFF;
   725 		gd.month = 0xFF;
   726 		gd.unk61A = 10;
   726 		gd.unk61A = 10;
   727 		gd.unk61C = 10;
   727 		gd.unk61C = 10;
   728 
   728 
   729 		for(i=0; i!=NUM_CARGO; i++) {
   729 		for (i = 0; i != NUM_CARGO; i++) {
   730 			gd.colors[i] = _cargo_legend_colors[i];
   730 			gd.colors[i] = _cargo_legend_colors[i];
   731 			for(j=0; j!=20; j++) {
   731 			for (j = 0; j != 20; j++) {
   732 				gd.cost[i][j] = (uint64)GetTransportedGoodsIncome(10, 20, j*6+6,i);
   732 				gd.cost[i][j] = (uint64)GetTransportedGoodsIncome(10, 20, j * 6 + 6, i);
   733 			}
   733 			}
   734 		}
   734 		}
   735 
   735 
   736 		DrawGraph(&gd);
   736 		DrawGraph(&gd);
   737 
   737 
   738 		DrawString(2 + 46, 24 + gd.height + 7, STR_7062_DAYS_IN_TRANSIT, 0);
   738 		DrawString(2 + 46, 24 + gd.height + 7, STR_7062_DAYS_IN_TRANSIT, 0);
   739 		DrawString(2 + 84, 24 - 9, STR_7063_PAYMENT_FOR_DELIVERING, 0);
   739 		DrawString(2 + 84, 24 - 9, STR_7063_PAYMENT_FOR_DELIVERING, 0);
   740 	} break;
   740 	} break;
   741 
   741 
   742 	case WE_CLICK: {
   742 	case WE_CLICK: {
   743 		switch(e->click.widget) {
   743 		switch (e->click.widget) {
   744 		case 3: case 4: case 5: case 6:
   744 		case 3: case 4: case 5: case 6:
   745 		case 7: case 8: case 9: case 10:
   745 		case 7: case 8: case 9: case 10:
   746 		case 11: case 12: case 13: case 14:
   746 		case 11: case 12: case 13: case 14:
   747 			_legend_cargobits ^= 1 << (e->click.widget - 3);
   747 			_legend_cargobits ^= 1 << (e->click.widget - 3);
   748 			SetWindowDirty(w);
   748 			SetWindowDirty(w);
   880 /* PERFORMANCE RATING DETAIL */
   880 /* PERFORMANCE RATING DETAIL */
   881 /*****************************/
   881 /*****************************/
   882 
   882 
   883 static void PerformanceRatingDetailWndProc(Window *w, WindowEvent *e)
   883 static void PerformanceRatingDetailWndProc(Window *w, WindowEvent *e)
   884 {
   884 {
   885 	switch(e->event) {
   885 	switch (e->event) {
   886 	case WE_PAINT: {
   886 	case WE_PAINT: {
   887 		int val, needed, score, i;
   887 		int val, needed, score, i;
   888 		byte owner, x;
   888 		byte owner, x;
   889 		uint16 y=14;
   889 		uint16 y=14;
   890 		int total_score = 0;
   890 		int total_score = 0;
  1132 	_sign_sort = realloc(_sign_sort, GetSignPoolSize() * sizeof(_sign_sort[0]));
  1132 	_sign_sort = realloc(_sign_sort, GetSignPoolSize() * sizeof(_sign_sort[0]));
  1133 	if (_sign_sort == NULL)
  1133 	if (_sign_sort == NULL)
  1134 		error("Could not allocate memory for the sign-sorting-list");
  1134 		error("Could not allocate memory for the sign-sorting-list");
  1135 
  1135 
  1136 	FOR_ALL_SIGNS(ss) {
  1136 	FOR_ALL_SIGNS(ss) {
  1137 		if(ss->str != STR_NULL) {
  1137 		if (ss->str != STR_NULL) {
  1138 			_sign_sort[n++] = ss->index;
  1138 			_sign_sort[n++] = ss->index;
  1139 			_num_sign_sort++;
  1139 			_num_sign_sort++;
  1140 		}
  1140 		}
  1141 	}
  1141 	}
  1142 
  1142