train_gui.c
changeset 919 544f374ee392
parent 914 4359607898f7
child 968 84a870c7a585
equal deleted inserted replaced
918:c092add72215 919:544f374ee392
    88 	Vehicle *v;
    88 	Vehicle *v;
    89 
    89 
    90 	if (!success)
    90 	if (!success)
    91 		return;
    91 		return;
    92 
    92 
    93 	v = &_vehicles[_new_train_id];
    93 	v = GetVehicle(_new_train_id);
    94 	if (tile == _backup_orders_tile) {
    94 	if (tile == _backup_orders_tile) {
    95 		_backup_orders_tile = 0;
    95 		_backup_orders_tile = 0;
    96 		RestoreVehicleOrders(v, _backup_orders_data);
    96 		RestoreVehicleOrders(v, _backup_orders_data);
    97 	}
    97 	}
    98 	ShowTrainViewWindow(v);
    98 	ShowTrainViewWindow(v);
   456 
   456 
   457 static void TrainDepotMoveVehicle(Vehicle *wagon, int sel, Vehicle *head)
   457 static void TrainDepotMoveVehicle(Vehicle *wagon, int sel, Vehicle *head)
   458 {
   458 {
   459 	Vehicle *v;
   459 	Vehicle *v;
   460 
   460 
   461 	v = &_vehicles[sel];
   461 	v = GetVehicle(sel);
   462 
   462 
   463 	if (/*v->subtype == 0 ||*/ v == wagon)
   463 	if (/*v->subtype == 0 ||*/ v == wagon)
   464 		return;
   464 		return;
   465 
   465 
   466 	if (wagon == NULL) {
   466 	if (wagon == NULL) {
   551 				return;
   551 				return;
   552 
   552 
   553 			if (WP(w,traindepot_d).sel == INVALID_VEHICLE)
   553 			if (WP(w,traindepot_d).sel == INVALID_VEHICLE)
   554 				return;
   554 				return;
   555 
   555 
   556 			v = &_vehicles[WP(w,traindepot_d).sel];
   556 			v = GetVehicle(WP(w,traindepot_d).sel);
   557 
   557 
   558 			WP(w,traindepot_d).sel = INVALID_VEHICLE;
   558 			WP(w,traindepot_d).sel = INVALID_VEHICLE;
   559 			SetWindowDirty(w);
   559 			SetWindowDirty(w);
   560 
   560 
   561 			HandleButtonClick(w, e->click.widget);
   561 			HandleButtonClick(w, e->click.widget);
   656 
   656 
   657 static void RailVehicleRefitWndProc(Window *w, WindowEvent *e)
   657 static void RailVehicleRefitWndProc(Window *w, WindowEvent *e)
   658 {
   658 {
   659 	switch(e->event) {
   659 	switch(e->event) {
   660 	case WE_PAINT: {
   660 	case WE_PAINT: {
   661 		Vehicle *v = &_vehicles[w->window_number];
   661 		Vehicle *v = GetVehicle(w->window_number);
   662 		const byte *b;
   662 		const byte *b;
   663 		int sel;
   663 		int sel;
   664 		int x,y;
   664 		int x,y;
   665 		byte color;
   665 		byte color;
   666 		int cargo;
   666 		int cargo;
   732 				SetWindowDirty(w);
   732 				SetWindowDirty(w);
   733 			}
   733 			}
   734 		} break;
   734 		} break;
   735 		case 4: /* refit button */
   735 		case 4: /* refit button */
   736 			if (WP(w,refit_d).cargo != 0xFF) {
   736 			if (WP(w,refit_d).cargo != 0xFF) {
   737 				Vehicle *v = &_vehicles[w->window_number];
   737 				Vehicle *v = GetVehicle(w->window_number);
   738 				if (DoCommandP(v->tile, v->index, WP(w,refit_d).cargo, NULL, CMD_REFIT_RAIL_VEHICLE | CMD_MSG(STR_RAIL_CAN_T_REFIT_VEHICLE)))
   738 				if (DoCommandP(v->tile, v->index, WP(w,refit_d).cargo, NULL, CMD_REFIT_RAIL_VEHICLE | CMD_MSG(STR_RAIL_CAN_T_REFIT_VEHICLE)))
   739 					DeleteWindow(w);
   739 					DeleteWindow(w);
   740 			}
   740 			}
   741 			break;
   741 			break;
   742 		}
   742 		}
   795 	switch(e->event) {
   795 	switch(e->event) {
   796 	case WE_PAINT: {
   796 	case WE_PAINT: {
   797 		Vehicle *v;
   797 		Vehicle *v;
   798 		StringID str;
   798 		StringID str;
   799 
   799 
   800 		v = &_vehicles[w->window_number];
   800 		v = GetVehicle(w->window_number);
   801 
   801 
   802 		w->disabled_state = (v->owner == _local_player) ? 0 : 0x380;
   802 		w->disabled_state = (v->owner == _local_player) ? 0 : 0x380;
   803 
   803 
   804 
   804 
   805 		/* draw widgets & caption */
   805 		/* draw widgets & caption */
   862 		DrawWindowViewport(w);
   862 		DrawWindowViewport(w);
   863 	}	break;
   863 	}	break;
   864 
   864 
   865 	case WE_CLICK: {
   865 	case WE_CLICK: {
   866 		int wid = e->click.widget;
   866 		int wid = e->click.widget;
   867 		Vehicle *v = &_vehicles[w->window_number];
   867 		Vehicle *v = GetVehicle(w->window_number);
   868 
   868 
   869 		switch(wid) {
   869 		switch(wid) {
   870 		case 5: /* start/stop train */
   870 		case 5: /* start/stop train */
   871 			DoCommandP(v->tile, v->index, 0, NULL, CMD_START_STOP_TRAIN | CMD_MSG(STR_883B_CAN_T_STOP_START_TRAIN));
   871 			DoCommandP(v->tile, v->index, 0, NULL, CMD_START_STOP_TRAIN | CMD_MSG(STR_883B_CAN_T_STOP_START_TRAIN));
   872 			break;
   872 			break;
   903 
   903 
   904 	case WE_MOUSELOOP: {
   904 	case WE_MOUSELOOP: {
   905 		Vehicle *v;
   905 		Vehicle *v;
   906 		uint32 h;
   906 		uint32 h;
   907 
   907 
   908 		v = &_vehicles[w->window_number];
   908 		v = GetVehicle(w->window_number);
   909 		assert(v->type == VEH_Train);
   909 		assert(v->type == VEH_Train);
   910 		h = CheckStoppedInDepot(v) >= 0 ? (1 << 9) : (1 << 12);
   910 		h = CheckStoppedInDepot(v) >= 0 ? (1 << 9) : (1 << 12);
   911 		if (h != w->hidden_state) {
   911 		if (h != w->hidden_state) {
   912 			w->hidden_state = h;
   912 			w->hidden_state = h;
   913 			SetWindowDirty(w);
   913 			SetWindowDirty(w);
  1001 
  1001 
  1002 	// det_tab == 3 <-- Total Cargo tab
  1002 	// det_tab == 3 <-- Total Cargo tab
  1003 	if (det_tab == 3)	// reset tot_cargo array to 0 values
  1003 	if (det_tab == 3)	// reset tot_cargo array to 0 values
  1004 		memset(tot_cargo, 0, sizeof(tot_cargo));
  1004 		memset(tot_cargo, 0, sizeof(tot_cargo));
  1005 
  1005 
  1006 	u = v = &_vehicles[w->window_number];
  1006 	u = v = GetVehicle(w->window_number);
  1007 	do {
  1007 	do {
  1008 		if (det_tab != 3)
  1008 		if (det_tab != 3)
  1009 			num++;
  1009 			num++;
  1010 		else {
  1010 		else {
  1011 			tot_cargo[u->cargo_type][0] += u->cargo_count;
  1011 			tot_cargo[u->cargo_type][0] += u->cargo_count;
  1112 	case WE_CLICK: {
  1112 	case WE_CLICK: {
  1113 		int mod;
  1113 		int mod;
  1114 		Vehicle *v;
  1114 		Vehicle *v;
  1115 		switch(e->click.widget) {
  1115 		switch(e->click.widget) {
  1116 		case 2: /* name train */
  1116 		case 2: /* name train */
  1117 			v = &_vehicles[w->window_number];
  1117 			v = GetVehicle(w->window_number);
  1118 			SetDParam(0, v->unitnumber);
  1118 			SetDParam(0, v->unitnumber);
  1119 			ShowQueryString(v->string_id, STR_8865_NAME_TRAIN, 31, 150, w->window_class, w->window_number);
  1119 			ShowQueryString(v->string_id, STR_8865_NAME_TRAIN, 31, 150, w->window_class, w->window_number);
  1120 			break;
  1120 			break;
  1121 		case 6:	/* inc serv interval */
  1121 		case 6:	/* inc serv interval */
  1122 			mod = _ctrl_pressed? 5 : 10;
  1122 			mod = _ctrl_pressed? 5 : 10;
  1123 			goto do_change_service_int;
  1123 			goto do_change_service_int;
  1124 
  1124 
  1125 		case 7: /* dec serv interval */
  1125 		case 7: /* dec serv interval */
  1126 			mod = _ctrl_pressed? -5 : -10;
  1126 			mod = _ctrl_pressed? -5 : -10;
  1127 do_change_service_int:
  1127 do_change_service_int:
  1128 			v = &_vehicles[w->window_number];
  1128 			v = GetVehicle(w->window_number);
  1129 			mod += v->service_interval;
  1129 			mod += v->service_interval;
  1130 
  1130 
  1131 				/*	%-based service interval max 5%-90%
  1131 				/*	%-based service interval max 5%-90%
  1132 						day-based service interval max 30-800 days */
  1132 						day-based service interval max 30-800 days */
  1133 				mod = _patches.servint_ispercent ? clamp(mod, MIN_SERVINT_PERCENT, MAX_SERVINT_PERCENT) : clamp(mod, MIN_SERVINT_DAYS, MAX_SERVINT_DAYS+1);
  1133 				mod = _patches.servint_ispercent ? clamp(mod, MIN_SERVINT_PERCENT, MAX_SERVINT_PERCENT) : clamp(mod, MIN_SERVINT_DAYS, MAX_SERVINT_DAYS+1);
  1274 				SetDParam(1, p->name_2);
  1274 				SetDParam(1, p->name_2);
  1275 				SetDParam(2, w->vscroll.count);
  1275 				SetDParam(2, w->vscroll.count);
  1276 				w->widget[1].unkA = STR_881B_TRAINS;
  1276 				w->widget[1].unkA = STR_881B_TRAINS;
  1277 			} else {
  1277 			} else {
  1278 				/* Station Name -- (###) Trains */
  1278 				/* Station Name -- (###) Trains */
  1279 				SetDParam(0, DEREF_STATION(station)->index);
  1279 				SetDParam(0, GetStation(station)->index);
  1280 				SetDParam(1, w->vscroll.count);
  1280 				SetDParam(1, w->vscroll.count);
  1281 				w->widget[1].unkA = STR_SCHEDULED_TRAINS;
  1281 				w->widget[1].unkA = STR_SCHEDULED_TRAINS;
  1282 			}
  1282 			}
  1283 			DrawWindowWidgets(w);
  1283 			DrawWindowWidgets(w);
  1284 		}
  1284 		}
  1288 		DoDrawString(
  1288 		DoDrawString(
  1289 			vl->flags & VL_DESC ? "\xAA" : "\xA0", 69, 15, 0x10);
  1289 			vl->flags & VL_DESC ? "\xAA" : "\xA0", 69, 15, 0x10);
  1290 
  1290 
  1291 		max = min(w->vscroll.pos + w->vscroll.cap, vl->list_length);
  1291 		max = min(w->vscroll.pos + w->vscroll.cap, vl->list_length);
  1292 		for (i = w->vscroll.pos; i < max; ++i) {
  1292 		for (i = w->vscroll.pos; i < max; ++i) {
  1293 			Vehicle *v = DEREF_VEHICLE(vl->sort_list[i].index);
  1293 			Vehicle *v = GetVehicle(vl->sort_list[i].index);
  1294 			StringID str;
  1294 			StringID str;
  1295 
  1295 
  1296 			assert(v->type == VEH_Train && v->owner == owner);
  1296 			assert(v->type == VEH_Train && v->owner == owner);
  1297 
  1297 
  1298 			DrawTrainImage(
  1298 			DrawTrainImage(
  1342 			{
  1342 			{
  1343 				Vehicle *v;
  1343 				Vehicle *v;
  1344 
  1344 
  1345 				if (id_v >= vl->list_length) return; // click out of list bound
  1345 				if (id_v >= vl->list_length) return; // click out of list bound
  1346 
  1346 
  1347 				v	= DEREF_VEHICLE(vl->sort_list[id_v].index);
  1347 				v = GetVehicle(vl->sort_list[id_v].index);
  1348 
  1348 
  1349 				assert(v->type == VEH_Train && v->subtype == 0 && v->owner == owner);
  1349 				assert(v->type == VEH_Train && v->subtype == 0 && v->owner == owner);
  1350 
  1350 
  1351 				ShowTrainViewWindow(v);
  1351 				ShowTrainViewWindow(v);
  1352 			}
  1352 			}