train_gui.c
changeset 1790 47963a0cfca3
parent 1658 ed5d679c5122
child 1802 da61740cc1e7
equal deleted inserted replaced
1789:a777d9da053f 1790:47963a0cfca3
   278 		w->caption_color = _local_player;
   278 		w->caption_color = _local_player;
   279 		WP(w,buildtrain_d).railtype = DEREF_PLAYER(_local_player)->max_railtype - 1;
   279 		WP(w,buildtrain_d).railtype = DEREF_PLAYER(_local_player)->max_railtype - 1;
   280 	}
   280 	}
   281 }
   281 }
   282 
   282 
   283 static void DrawTrainImage(Vehicle *v, int x, int y, int count, int skip, VehicleID selection)
   283 static void DrawTrainImage(const Vehicle *v, int x, int y, int count, int skip, VehicleID selection)
   284 {
   284 {
   285 	do {
   285 	do {
   286 		if (--skip < 0) {
   286 		if (--skip < 0) {
   287 			int image = GetTrainImage(v, 6);
   287 			int image = GetTrainImage(v, 6);
   288 			uint32 ormod = SPRITE_PALETTE(PLAYER_SPRITE_COLOR(v->owner));
   288 			uint32 ormod = SPRITE_PALETTE(PLAYER_SPRITE_COLOR(v->owner));
   978 		w->caption_color = v->owner;
   978 		w->caption_color = v->owner;
   979 		AssignWindowViewport(w, 3, 17, 0xE2, 0x66, w->window_number | (1 << 31), 0);
   979 		AssignWindowViewport(w, 3, 17, 0xE2, 0x66, w->window_number | (1 << 31), 0);
   980 	}
   980 	}
   981 }
   981 }
   982 
   982 
   983 static void TrainDetailsCargoTab(Vehicle *v, int x, int y)
   983 static void TrainDetailsCargoTab(const Vehicle *v, int x, int y)
   984 {
   984 {
   985 	int num;
   985 	int num;
   986 	StringID str;
   986 	StringID str;
   987 
   987 
   988 	if (v->cargo_cap != 0) {
   988 	if (v->cargo_cap != 0) {
   996 		}
   996 		}
   997 		DrawString(x, y, str, 0);
   997 		DrawString(x, y, str, 0);
   998 	}
   998 	}
   999 }
   999 }
  1000 
  1000 
  1001 static void TrainDetailsInfoTab(Vehicle *v, int x, int y)
  1001 static void TrainDetailsInfoTab(const Vehicle *v, int x, int y)
  1002 {
  1002 {
  1003 	const RailVehicleInfo *rvi = RailVehInfo(v->engine_type);
  1003 	const RailVehicleInfo *rvi = RailVehInfo(v->engine_type);
  1004 
  1004 
  1005 	if (!(rvi->flags & RVI_WAGON)) {
  1005 	if (!(rvi->flags & RVI_WAGON)) {
  1006 		SetDParam(0, GetCustomEngineName(v->engine_type));
  1006 		SetDParam(0, GetCustomEngineName(v->engine_type));
  1012 		SetDParam(1, v->value);
  1012 		SetDParam(1, v->value);
  1013 		DrawString(x, y, STR_882D_VALUE, 0x10);
  1013 		DrawString(x, y, STR_882D_VALUE, 0x10);
  1014 	}
  1014 	}
  1015 }
  1015 }
  1016 
  1016 
  1017 static void TrainDetailsCapacityTab(Vehicle *v, int x, int y)
  1017 static void TrainDetailsCapacityTab(const Vehicle *v, int x, int y)
  1018 {
  1018 {
  1019 	if (v->cargo_cap != 0) {
  1019 	if (v->cargo_cap != 0) {
  1020 		SetDParam(1, v->cargo_cap);
  1020 		SetDParam(1, v->cargo_cap);
  1021 		SetDParam(0, _cargoc.names_long_p[v->cargo_type]);
  1021 		SetDParam(0, _cargoc.names_long_p[v->cargo_type]);
  1022 		DrawString(x, y, STR_013F_CAPACITY, 0);
  1022 		DrawString(x, y, STR_013F_CAPACITY, 0);
  1023 	}
  1023 	}
  1024 }
  1024 }
  1025 
  1025 
  1026 typedef void TrainDetailsDrawerProc(Vehicle *v, int x, int y);
  1026 typedef void TrainDetailsDrawerProc(const Vehicle *v, int x, int y);
  1027 
  1027 
  1028 static TrainDetailsDrawerProc * const _train_details_drawer_proc[3] = {
  1028 static TrainDetailsDrawerProc * const _train_details_drawer_proc[3] = {
  1029 	TrainDetailsCargoTab,
  1029 	TrainDetailsCargoTab,
  1030 	TrainDetailsInfoTab,
  1030 	TrainDetailsInfoTab,
  1031 	TrainDetailsCapacityTab,
  1031 	TrainDetailsCapacityTab,
  1032 };
  1032 };
  1033 
  1033 
  1034 static void DrawTrainDetailsWindow(Window *w)
  1034 static void DrawTrainDetailsWindow(Window *w)
  1035 {
  1035 {
  1036 	Vehicle *v, *u;
  1036 	const Vehicle *v, *u;
  1037 	uint16 tot_cargo[NUM_CARGO][2];	// count total cargo ([0]-actual cargo, [1]-total cargo)
  1037 	uint16 tot_cargo[NUM_CARGO][2];	// count total cargo ([0]-actual cargo, [1]-total cargo)
  1038 	int max_speed = 0xFFFF;
  1038 	int max_speed = 0xFFFF;
  1039 	int i,num,x,y,sel;
  1039 	int i,num,x,y,sel;
  1040 	StringID str;
  1040 	StringID str;
  1041 	byte det_tab = WP(w, traindetails_d).tab;
  1041 	byte det_tab = WP(w, traindetails_d).tab;
  1149 	}
  1149 	}
  1150 }
  1150 }
  1151 
  1151 
  1152 static void TrainDetailsWndProc(Window *w, WindowEvent *e)
  1152 static void TrainDetailsWndProc(Window *w, WindowEvent *e)
  1153 {
  1153 {
  1154 	switch(e->event) {
  1154 	switch (e->event) {
  1155 	case WE_PAINT:
  1155 	case WE_PAINT:
  1156 		DrawTrainDetailsWindow(w);
  1156 		DrawTrainDetailsWindow(w);
  1157 		break;
  1157 		break;
  1158 	case WE_CLICK: {
  1158 	case WE_CLICK: {
  1159 		int mod;
  1159 		int mod;
  1160 		Vehicle *v;
  1160 		const Vehicle *v;
  1161 		switch(e->click.widget) {
  1161 		switch (e->click.widget) {
  1162 		case 2: /* name train */
  1162 		case 2: /* name train */
  1163 			v = GetVehicle(w->window_number);
  1163 			v = GetVehicle(w->window_number);
  1164 			SetDParam(0, v->unitnumber);
  1164 			SetDParam(0, v->unitnumber);
  1165 			ShowQueryString(v->string_id, STR_8865_NAME_TRAIN, 31, 150, w->window_class, w->window_number);
  1165 			ShowQueryString(v->string_id, STR_8865_NAME_TRAIN, 31, 150, w->window_class, w->window_number);
  1166 			break;
  1166 			break;
  1170 
  1170 
  1171 		case 7: /* dec serv interval */
  1171 		case 7: /* dec serv interval */
  1172 			mod = _ctrl_pressed? -5 : -10;
  1172 			mod = _ctrl_pressed? -5 : -10;
  1173 do_change_service_int:
  1173 do_change_service_int:
  1174 			v = GetVehicle(w->window_number);
  1174 			v = GetVehicle(w->window_number);
  1175 			mod += v->service_interval;
  1175 
  1176 
  1176 			mod = GetServiceIntervalClamped(mod + v->service_interval);
  1177 				/*	%-based service interval max 5%-90%
  1177 			if (mod == v->service_interval) return;
  1178 						day-based service interval max 30-800 days */
       
  1179 				mod = _patches.servint_ispercent ? clamp(mod, MIN_SERVINT_PERCENT, MAX_SERVINT_PERCENT) : clamp(mod, MIN_SERVINT_DAYS, MAX_SERVINT_DAYS+1);
       
  1180 				if (mod == v->service_interval)
       
  1181 					return;
       
  1182 
  1178 
  1183 			DoCommandP(v->tile, v->index, mod, NULL, CMD_CHANGE_TRAIN_SERVICE_INT | CMD_MSG(STR_018A_CAN_T_CHANGE_SERVICING));
  1179 			DoCommandP(v->tile, v->index, mod, NULL, CMD_CHANGE_TRAIN_SERVICE_INT | CMD_MSG(STR_018A_CAN_T_CHANGE_SERVICING));
  1184 			break;
  1180 			break;
  1185 		/* details buttons*/
  1181 		/* details buttons*/
  1186 		case 9:		// Cargo
  1182 		case 9:		// Cargo