station_gui.c
changeset 919 544f374ee392
parent 893 f4698309dec7
child 1093 4fdc46eaf423
equal deleted inserted replaced
918:c092add72215 919:544f374ee392
    43 	if (rating != 0) {
    43 	if (rating != 0) {
    44 		GfxFillRect(x+1, y+8, x+rating, y+8, 0xD0);
    44 		GfxFillRect(x+1, y+8, x+rating, y+8, 0xD0);
    45 	}
    45 	}
    46 }
    46 }
    47 
    47 
    48 static SortStruct _station_sort[lengthof(_stations)];
       
    49 static uint16 _num_station_sort[MAX_PLAYERS];
    48 static uint16 _num_station_sort[MAX_PLAYERS];
    50 
    49 
    51 static char _bufcache[64];
    50 static char _bufcache[64];
    52 static uint16 _last_station_idx;
    51 static uint16 _last_station_idx;
    53 
    52 
    56 	char buf1[64];
    55 	char buf1[64];
    57 	Station *st;
    56 	Station *st;
    58 	const SortStruct *cmp1 = (const SortStruct*)a;
    57 	const SortStruct *cmp1 = (const SortStruct*)a;
    59 	const SortStruct *cmp2 = (const SortStruct*)b;
    58 	const SortStruct *cmp2 = (const SortStruct*)b;
    60 
    59 
    61 	st = DEREF_STATION(cmp1->index);
    60 	st = GetStation(cmp1->index);
    62 	SetDParam(0, st->town->townnametype);
    61 	SetDParam(0, st->town->townnametype);
    63 	SetDParam(1, st->town->townnameparts);
    62 	SetDParam(1, st->town->townnameparts);
    64 	GetString(buf1, st->string_id);
    63 	GetString(buf1, st->string_id);
    65 
    64 
    66 	if ( cmp2->index != _last_station_idx) {
    65 	if ( cmp2->index != _last_station_idx) {
    67 		_last_station_idx = cmp2->index;
    66 		_last_station_idx = cmp2->index;
    68 		st = DEREF_STATION(cmp2->index);
    67 		st = GetStation(cmp2->index);
    69 		SetDParam(0, st->town->townnametype);
    68 		SetDParam(0, st->town->townnametype);
    70 		SetDParam(1, st->town->townnameparts);
    69 		SetDParam(1, st->town->townnameparts);
    71 		GetString(_bufcache, st->string_id);
    70 		GetString(_bufcache, st->string_id);
    72 	}
    71 	}
    73 
    72 
    79 	const Station *st;
    78 	const Station *st;
    80 	uint32 n = 0;
    79 	uint32 n = 0;
    81 	uint16 *i;
    80 	uint16 *i;
    82 
    81 
    83 	// reset #-of stations to 0 because ++ is used for value-assignment
    82 	// reset #-of stations to 0 because ++ is used for value-assignment
    84 	for (i = _num_station_sort; i != endof(_num_station_sort); i++) {*i = 0;}
    83 	for (i = _num_station_sort; i != endof(_num_station_sort); i++)
       
    84 		*i = 0;
       
    85 
       
    86 	/* Create array for sorting */
       
    87 	_station_sort = realloc(_station_sort, _stations_size * sizeof(_station_sort[0]));
       
    88 	if (_station_sort == NULL)
       
    89 		error("Could not allocate memory for the station-sorting-list");
    85 
    90 
    86 	FOR_ALL_STATIONS(st) {
    91 	FOR_ALL_STATIONS(st) {
    87 		if(st->xy && st->owner != OWNER_NONE) {
    92 		if(st->xy && st->owner != OWNER_NONE) {
    88 			_station_sort[n].index = st->index;
    93 			_station_sort[n].index = st->index;
    89 			_station_sort[n++].owner = st->owner;
    94 			_station_sort[n++].owner = st->owner;
   169 
   174 
   170 			i += w->vscroll.pos;	// offset from sorted station list of current player
   175 			i += w->vscroll.pos;	// offset from sorted station list of current player
   171 			assert(i < _num_station_sort[window_number]); // at least one station must exist
   176 			assert(i < _num_station_sort[window_number]); // at least one station must exist
   172 
   177 
   173 			while (i < _num_station_sort[window_number]) {	// do until max number of stations of owner
   178 			while (i < _num_station_sort[window_number]) {	// do until max number of stations of owner
   174 				st = DEREF_STATION(_station_sort[i].index);
   179 				st = GetStation(_station_sort[i].index);
   175 
   180 
   176 				assert(st->xy && st->owner == window_number);
   181 				assert(st->xy && st->owner == window_number);
   177 
   182 
   178 				SetDParam(0, st->index);
   183 				SetDParam(0, st->index);
   179 				SetDParam(1, st->facilities);
   184 				SetDParam(1, st->facilities);
   207 				Station *st;
   212 				Station *st;
   208 				id_v	+= (owner == 0) ? 0 : _num_station_sort[owner - 1]; // first element in list
   213 				id_v	+= (owner == 0) ? 0 : _num_station_sort[owner - 1]; // first element in list
   209 
   214 
   210 				if (id_v >= _num_station_sort[owner]) { return;} // click out of station bound
   215 				if (id_v >= _num_station_sort[owner]) { return;} // click out of station bound
   211 
   216 
   212 				st = DEREF_STATION(_station_sort[id_v].index);
   217 				st = GetStation(_station_sort[id_v].index);
   213 
   218 
   214 				assert(st->xy && st->owner == owner);
   219 				assert(st->xy && st->owner == owner);
   215 
   220 
   216 				ScrollMainWindowToTile(st->xy);
   221 				ScrollMainWindowToTile(st->xy);
   217 			}
   222 			}
   313 	byte *b;
   318 	byte *b;
   314 
   319 
   315 
   320 
   316 	station_id = (byte)w->window_number;
   321 	station_id = (byte)w->window_number;
   317 
   322 
   318 	st = DEREF_STATION(w->window_number);
   323 	st = GetStation(w->window_number);
   319 
   324 
   320 	num = 1;
   325 	num = 1;
   321 	for(i=0; i!=NUM_CARGO; i++) {
   326 	for(i=0; i!=NUM_CARGO; i++) {
   322 		if ((st->goods[i].waiting_acceptance & 0xFFF) != 0) {
   327 		if ((st->goods[i].waiting_acceptance & 0xFFF) != 0) {
   323 			num++;
   328 			num++;
   447 		break;
   452 		break;
   448 
   453 
   449 	case WE_CLICK:
   454 	case WE_CLICK:
   450 		switch(e->click.widget) {
   455 		switch(e->click.widget) {
   451 		case 7:
   456 		case 7:
   452 			ScrollMainWindowToTile(DEREF_STATION(w->window_number)->xy);
   457 			ScrollMainWindowToTile(GetStation(w->window_number)->xy);
   453 			break;
   458 			break;
   454 
   459 
   455 		case 8:
   460 		case 8:
   456 			SetWindowDirty(w);
   461 			SetWindowDirty(w);
   457 
   462 
   466 
   471 
   467 			SetWindowDirty(w);
   472 			SetWindowDirty(w);
   468 			break;
   473 			break;
   469 
   474 
   470 		case 9: {
   475 		case 9: {
   471 			Station *st = DEREF_STATION(w->window_number);
   476 			Station *st = GetStation(w->window_number);
   472 			SetDParam(0, st->town->townnametype);
   477 			SetDParam(0, st->town->townnametype);
   473 			SetDParam(1, st->town->townnameparts);
   478 			SetDParam(1, st->town->townnameparts);
   474 			ShowQueryString(st->string_id, STR_3030_RENAME_STATION_LOADING, 31, 180, w->window_class, w->window_number);
   479 			ShowQueryString(st->string_id, STR_3030_RENAME_STATION_LOADING, 31, 180, w->window_class, w->window_number);
   475 		}	break;
   480 		}	break;
   476 
   481 
   477 		case 10: {
   482 		case 10: {
   478 			const Station *st = DEREF_STATION(w->window_number);
   483 			const Station *st = GetStation(w->window_number);
   479 			ShowPlayerTrains(st->owner, w->window_number);
   484 			ShowPlayerTrains(st->owner, w->window_number);
   480 			break;
   485 			break;
   481 		}
   486 		}
   482 
   487 
   483 		case 11: {
   488 		case 11: {
   484 			const Station *st = DEREF_STATION(w->window_number);
   489 			const Station *st = GetStation(w->window_number);
   485 			ShowPlayerRoadVehicles(st->owner, w->window_number);
   490 			ShowPlayerRoadVehicles(st->owner, w->window_number);
   486 			break;
   491 			break;
   487 		}
   492 		}
   488 
   493 
   489 		case 12: {
   494 		case 12: {
   490 			const Station *st = DEREF_STATION(w->window_number);
   495 			const Station *st = GetStation(w->window_number);
   491 			ShowPlayerAircraft(st->owner, w->window_number);
   496 			ShowPlayerAircraft(st->owner, w->window_number);
   492 			break;
   497 			break;
   493 		}
   498 		}
   494 
   499 
   495 		case 13: {
   500 		case 13: {
   496 			const Station *st = DEREF_STATION(w->window_number);
   501 			const Station *st = GetStation(w->window_number);
   497 			ShowPlayerShips(st->owner, w->window_number);
   502 			ShowPlayerShips(st->owner, w->window_number);
   498 			break;
   503 			break;
   499 		}
   504 		}
   500 		}
   505 		}
   501 		break;
   506 		break;
   505 		byte *b = e->edittext.str;
   510 		byte *b = e->edittext.str;
   506 		if (*b == 0)
   511 		if (*b == 0)
   507 			return;
   512 			return;
   508 		memcpy(_decode_parameters, b, 32);
   513 		memcpy(_decode_parameters, b, 32);
   509 
   514 
   510 		st = DEREF_STATION(w->window_number);
   515 		st = GetStation(w->window_number);
   511 		DoCommandP(st->xy, w->window_number, 0, NULL, CMD_RENAME_STATION | CMD_MSG(STR_3031_CAN_T_RENAME_STATION));
   516 		DoCommandP(st->xy, w->window_number, 0, NULL, CMD_RENAME_STATION | CMD_MSG(STR_3031_CAN_T_RENAME_STATION));
   512 	} break;
   517 	} break;
   513 
   518 
   514 	case WE_DESTROY: {
   519 	case WE_DESTROY: {
   515 		WindowNumber wno =
   520 		WindowNumber wno =
   516 			(w->window_number << 16) | DEREF_STATION(w->window_number)->owner;
   521 			(w->window_number << 16) | GetStation(w->window_number)->owner;
   517 
   522 
   518 		DeleteWindowById(WC_TRAINS_LIST, wno);
   523 		DeleteWindowById(WC_TRAINS_LIST, wno);
   519 		DeleteWindowById(WC_ROADVEH_LIST, wno);
   524 		DeleteWindowById(WC_ROADVEH_LIST, wno);
   520 		DeleteWindowById(WC_SHIPS_LIST, wno);
   525 		DeleteWindowById(WC_SHIPS_LIST, wno);
   521 		DeleteWindowById(WC_AIRCRAFT_LIST, wno);
   526 		DeleteWindowById(WC_AIRCRAFT_LIST, wno);
   538 	Window *w;
   543 	Window *w;
   539 	byte color;
   544 	byte color;
   540 
   545 
   541 	w = AllocateWindowDescFront(&_station_view_desc, station);
   546 	w = AllocateWindowDescFront(&_station_view_desc, station);
   542 	if (w) {
   547 	if (w) {
   543 		color = DEREF_STATION(w->window_number)->owner;
   548 		color = GetStation(w->window_number)->owner;
   544 		if (color != 0x10)
   549 		if (color != 0x10)
   545 			w->caption_color = color;
   550 			w->caption_color = color;
   546 		w->vscroll.cap = 5;
   551 		w->vscroll.cap = 5;
   547 	}
   552 	}
   548 }
   553 }