ship_gui.c
changeset 4408 db2afc41002a
parent 4389 18d6ccfb5335
child 4412 cae52239a576
equal deleted inserted replaced
4407:685c613f3fec 4408:db2afc41002a
   950 {   WIDGETS_END},
   950 {   WIDGETS_END},
   951 };
   951 };
   952 
   952 
   953 static void PlayerShipsWndProc(Window *w, WindowEvent *e)
   953 static void PlayerShipsWndProc(Window *w, WindowEvent *e)
   954 {
   954 {
   955 	StationID station = GB(w->window_number, 16, 16);
   955 	uint16 order = GB(w->window_number, 16, 16);
       
   956 	/* Sorting a shared order list relies on station being set to INVALID_STATION */
       
   957 	/* If station is not INVALID_STATION, then order is never used and we don't care what it contains */
       
   958 	StationID station = HASBIT(w->window_number, 8) ? INVALID_STATION : order;
   956 	PlayerID owner = GB(w->window_number, 0, 8);
   959 	PlayerID owner = GB(w->window_number, 0, 8);
   957 	vehiclelist_d *vl = &WP(w, vehiclelist_d);
   960 	vehiclelist_d *vl = &WP(w, vehiclelist_d);
   958 
   961 
   959 	switch (e->event) {
   962 	switch (e->event) {
   960 	case WE_PAINT: {
   963 	case WE_PAINT: {
   961 		int x = 2;
   964 		int x = 2;
   962 		int y = PLY_WND_PRC__OFFSET_TOP_WIDGET;
   965 		int y = PLY_WND_PRC__OFFSET_TOP_WIDGET;
   963 		int max;
   966 		int max;
   964 		int i;
   967 		int i;
   965 
   968 
   966 		BuildVehicleList(vl, VEH_Ship, owner, station);
   969 		BuildVehicleList(vl, VEH_Ship, owner, station, order);
   967 		SortVehicleList(vl);
   970 		SortVehicleList(vl);
   968 
       
   969 		SetVScrollCount(w, vl->list_length);
   971 		SetVScrollCount(w, vl->list_length);
   970 
   972 
   971 		// disable 'Sort By' tooltip on Unsorted sorting criteria
   973 		// disable 'Sort By' tooltip on Unsorted sorting criteria
   972 		if (vl->sort_type == SORT_BY_UNSORTED)
   974 		if (vl->sort_type == SORT_BY_UNSORTED)
   973 			w->disabled_state |= (1 << 3);
   975 			w->disabled_state |= (1 << 3);
   974 
   976 
   975 		/* draw the widgets */
   977 		/* draw the widgets */
   976 		{
   978 		{
   977 			const Player *p = GetPlayer(owner);
   979 			const Player *p = GetPlayer(owner);
   978 			if (station == INVALID_STATION) {
   980 			if (order != INVALID_ORDER) {
   979 				/* Company Name -- (###) Trains */
   981 				/* Shared Orders -- (###) Ships */
       
   982 				SetDParam(0, w->vscroll.count);
       
   983 				w->widget[1].unkA  = STR_VEH_WITH_SHARED_ORDERS_LIST;
       
   984 				w->widget[9].unkA  = STR_EMPTY;
       
   985 				w->widget[10].unkA = STR_EMPTY;
       
   986 				SETBIT(w->disabled_state, 9);
       
   987 				SETBIT(w->disabled_state, 10);
       
   988 			} else if (station == INVALID_STATION) {
       
   989 				/* Company Name -- (###) Ships */
   980 				SetDParam(0, p->name_1);
   990 				SetDParam(0, p->name_1);
   981 				SetDParam(1, p->name_2);
   991 				SetDParam(1, p->name_2);
   982 				SetDParam(2, w->vscroll.count);
   992 				SetDParam(2, w->vscroll.count);
   983 				w->widget[1].unkA = STR_9805_SHIPS;
   993 				w->widget[1].unkA = STR_9805_SHIPS;
   984 			} else {
   994 			} else {
   985 				/* Station Name -- (###) Trains */
   995 				/* Station Name -- (###) Ships */
   986 				SetDParam(0, station);
   996 				SetDParam(0, station);
   987 				SetDParam(1, w->vscroll.count);
   997 				SetDParam(1, w->vscroll.count);
   988 				w->widget[1].unkA = STR_SCHEDULED_SHIPS;
   998 				w->widget[1].unkA = STR_SCHEDULED_SHIPS;
   989 			}
   999 			}
   990 			DrawWindowWidgets(w);
  1000 			DrawWindowWidgets(w);
  1126 	_other_player_ships_widgets,
  1136 	_other_player_ships_widgets,
  1127 	PlayerShipsWndProc
  1137 	PlayerShipsWndProc
  1128 };
  1138 };
  1129 
  1139 
  1130 
  1140 
  1131 void ShowPlayerShips(PlayerID player, StationID station)
  1141 static void ShowPlayerShipsLocal(PlayerID player, StationID station, uint16 order, bool show_shared)
  1132 {
  1142 {
  1133 	Window *w;
  1143 	Window *w;
  1134 
  1144 
  1135 	if (player == _local_player) {
  1145 	if (show_shared) {
  1136 		w = AllocateWindowDescFront(&_player_ships_desc, (station << 16) | player);
  1146 		w = AllocateWindowDescFront(&_player_ships_desc, (order << 16) | (1 << 8));
  1137 	} else  {
  1147 	} else {
  1138 		w = AllocateWindowDescFront(&_other_player_ships_desc, (station << 16) | player);
  1148 		if (player == _local_player) {
  1139 	}
  1149 			w = AllocateWindowDescFront(&_player_ships_desc, (station << 16) | player);
       
  1150 		} else  {
       
  1151 			w = AllocateWindowDescFront(&_other_player_ships_desc, (station << 16) | player);
       
  1152 		}
       
  1153 	}
       
  1154 
  1140 	if (w != NULL) {
  1155 	if (w != NULL) {
  1141 		w->caption_color = w->window_number;
  1156 		w->caption_color = player;
  1142 		w->vscroll.cap = 4;
  1157 		w->vscroll.cap = 4;
  1143 		w->widget[7].unkA = (w->vscroll.cap << 8) + 1;
  1158 		w->widget[7].unkA = (w->vscroll.cap << 8) + 1;
  1144 		w->resize.step_height = PLY_WND_PRC__SIZE_OF_ROW_BIG;
  1159 		w->resize.step_height = PLY_WND_PRC__SIZE_OF_ROW_BIG;
  1145 	}
  1160 	}
  1146 }
  1161 }
       
  1162 
       
  1163 void ShowPlayerShips(PlayerID player, StationID station)
       
  1164 {
       
  1165 	ShowPlayerShipsLocal(player, station, 0, false);
       
  1166 }
       
  1167 
       
  1168 void ShowVehWithSharedOrdersShips(Vehicle *v)
       
  1169 {
       
  1170 	if (v->orders == NULL) return;	// no shared list to show
       
  1171 	ShowPlayerShipsLocal(v->owner, INVALID_STATION, v->orders->index, true);
       
  1172 }