train_gui.c
changeset 4408 84ec2899adfa
parent 4389 e4555522d257
child 4412 945e8a9bb89a
equal deleted inserted replaced
4407:d639dd97eff0 4408:84ec2899adfa
  1400 {   WIDGETS_END},
  1400 {   WIDGETS_END},
  1401 };
  1401 };
  1402 
  1402 
  1403 static void PlayerTrainsWndProc(Window *w, WindowEvent *e)
  1403 static void PlayerTrainsWndProc(Window *w, WindowEvent *e)
  1404 {
  1404 {
  1405 	StationID station = GB(w->window_number, 16, 16);
  1405 	uint16 order = GB(w->window_number, 16, 16);
       
  1406 	/* Sorting a shared order list relies on station being set to INVALID_STATION */
       
  1407 	/* If station is not INVALID_STATION, then order is never used and we don't care what it contains */
       
  1408 	StationID station = HASBIT(w->window_number, 8) ? INVALID_STATION : order;
  1406 	PlayerID owner = GB(w->window_number, 0, 8);
  1409 	PlayerID owner = GB(w->window_number, 0, 8);
  1407 	vehiclelist_d *vl = &WP(w, vehiclelist_d);
  1410 	vehiclelist_d *vl = &WP(w, vehiclelist_d);
  1408 
  1411 
  1409 	switch (e->event) {
  1412 	switch (e->event) {
  1410 	case WE_PAINT: {
  1413 	case WE_PAINT: {
  1411 		int x = 2;
  1414 		int x = 2;
  1412 		int y = PLY_WND_PRC__OFFSET_TOP_WIDGET;
  1415 		int y = PLY_WND_PRC__OFFSET_TOP_WIDGET;
  1413 		int max;
  1416 		int max;
  1414 		int i;
  1417 		int i;
  1415 
  1418 
  1416 		BuildVehicleList(vl, VEH_Train, owner, station);
  1419 		BuildVehicleList(vl, VEH_Train, owner, station, order);
  1417 		SortVehicleList(vl);
  1420 		SortVehicleList(vl);
  1418 
       
  1419 		SetVScrollCount(w, vl->list_length);
  1421 		SetVScrollCount(w, vl->list_length);
  1420 
  1422 
  1421 		// disable 'Sort By' tooltip on Unsorted sorting criteria
  1423 		// disable 'Sort By' tooltip on Unsorted sorting criteria
  1422 		if (vl->sort_type == SORT_BY_UNSORTED) w->disabled_state |= (1 << 3);
  1424 		if (vl->sort_type == SORT_BY_UNSORTED) w->disabled_state |= (1 << 3);
  1423 
  1425 
  1424 		/* draw the widgets */
  1426 		/* draw the widgets */
  1425 		{
  1427 		{
  1426 			const Player *p = GetPlayer(owner);
  1428 			if (order != INVALID_ORDER) {
  1427 			if (station == INVALID_STATION) {
  1429 				/* Shared Orders -- (###) Trains */
       
  1430 				SetDParam(0, w->vscroll.count);
       
  1431 				w->widget[1].unkA  = STR_VEH_WITH_SHARED_ORDERS_LIST;
       
  1432 				w->widget[9].unkA  = STR_EMPTY;
       
  1433 				w->widget[10].unkA = STR_EMPTY;
       
  1434 				SETBIT(w->disabled_state, 9);
       
  1435 				SETBIT(w->disabled_state, 10);
       
  1436 			} else if (station == INVALID_STATION) {
       
  1437 				const Player *p = GetPlayer(owner);
  1428 				/* Company Name -- (###) Trains */
  1438 				/* Company Name -- (###) Trains */
  1429 				SetDParam(0, p->name_1);
  1439 				SetDParam(0, p->name_1);
  1430 				SetDParam(1, p->name_2);
  1440 				SetDParam(1, p->name_2);
  1431 				SetDParam(2, w->vscroll.count);
  1441 				SetDParam(2, w->vscroll.count);
  1432 				w->widget[1].unkA = STR_881B_TRAINS;
  1442 				w->widget[1].unkA = STR_881B_TRAINS;
  1575 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
  1585 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
  1576 	_other_player_trains_widgets,
  1586 	_other_player_trains_widgets,
  1577 	PlayerTrainsWndProc
  1587 	PlayerTrainsWndProc
  1578 };
  1588 };
  1579 
  1589 
  1580 void ShowPlayerTrains(PlayerID player, StationID station)
  1590 static void ShowPlayerTrainsLocal(PlayerID player, StationID station, uint16 order, bool show_shared)
  1581 {
  1591 {
  1582 	Window *w;
  1592 	Window *w;
  1583 
  1593 
  1584 	if (player == _local_player) {
  1594 	if (show_shared) {
  1585 		w = AllocateWindowDescFront(&_player_trains_desc, (station << 16) | player);
  1595 		w = AllocateWindowDescFront(&_player_trains_desc, (order << 16) | (1 << 8));
  1586 	} else {
  1596 	} else {
  1587 		w = AllocateWindowDescFront(&_other_player_trains_desc, (station << 16) | player);
  1597 		if (player == _local_player) {
       
  1598 			w = AllocateWindowDescFront(&_player_trains_desc, (station << 16) | player);
       
  1599 		} else {
       
  1600 			w = AllocateWindowDescFront(&_other_player_trains_desc, (station << 16) | player);
       
  1601 		}
  1588 	}
  1602 	}
  1589 	if (w != NULL) {
  1603 	if (w != NULL) {
  1590 		w->caption_color = player;
  1604 		w->caption_color = player;
  1591 		w->hscroll.cap = 10 * 29;
  1605 		w->hscroll.cap = 10 * 29;
  1592 		w->vscroll.cap = 7; // maximum number of vehicles shown
  1606 		w->vscroll.cap = 7; // maximum number of vehicles shown
  1594 		w->resize.step_height = PLY_WND_PRC__SIZE_OF_ROW_SMALL;
  1608 		w->resize.step_height = PLY_WND_PRC__SIZE_OF_ROW_SMALL;
  1595 		w->resize.step_width = 1;
  1609 		w->resize.step_width = 1;
  1596 		w->resize.height = 220 - (PLY_WND_PRC__SIZE_OF_ROW_SMALL * 3); /* Minimum of 4 vehicles */
  1610 		w->resize.height = 220 - (PLY_WND_PRC__SIZE_OF_ROW_SMALL * 3); /* Minimum of 4 vehicles */
  1597 	}
  1611 	}
  1598 }
  1612 }
       
  1613 
       
  1614 void ShowPlayerTrains(PlayerID player, StationID station)
       
  1615 {
       
  1616 	ShowPlayerTrainsLocal(player, station, INVALID_ORDER, false);
       
  1617 }
       
  1618 
       
  1619 void ShowVehWithSharedOrdersTrains(Vehicle *v)
       
  1620 {
       
  1621 	if (v->orders == NULL) return;	// no shared list to show
       
  1622 
       
  1623 	ShowPlayerTrainsLocal(v->owner, INVALID_STATION, v->orders->index, true);
       
  1624 }