Changeset - r5745:711848d18034
[Not reviewed]
master
0 6 0
bjarni - 18 years ago 2007-01-21 00:01:47
bjarni@openttd.org
(svn r8293) -Codechange: overloaded ShowVehicleListWindow() so it can open all types of vehicle lists (depending on arguments)
- Also removed some unneeded arguments
- this also allows removing an if-else cascade in ShowVehicleListWindowLocal()
6 files changed with 32 insertions and 35 deletions:
0 comments (0 inline, 0 general)
src/depot_gui.cpp
Show inline comments
 
@@ -784,25 +784,25 @@ static void DepotWndProc(Window *w, Wind
 

	
 
						SetDParam(0, (vehtype == VEH_Aircraft) ? GetStationIndex(tile) : GetDepotByTile(tile)->town_index);
 
						ShowQuery(
 
							confirm_captions[vehtype - VEH_Train],
 
							STR_DEPOT_SELL_CONFIRMATION_TEXT,
 
							w,
 
							DepotSellAllConfirmationCallback
 
						);
 
					}
 
					break;
 

	
 
				case DEPOT_WIDGET_VEHICLE_LIST:
 
					ShowVehDepotOrders(GetTileOwner(w->window_number), WP(w, depot_d).type, w->window_number);
 
					ShowVehicleListWindow(GetTileOwner(w->window_number), WP(w, depot_d).type, (TileIndex)w->window_number);
 
					break;
 

	
 
				case DEPOT_WIDGET_AUTOREPLACE:
 
					DoCommandP(w->window_number, WP(w, depot_d).type, 0, NULL, CMD_DEPOT_MASS_AUTOREPLACE);
 
					break;
 

	
 
			}
 
			break;
 

	
 
		case WE_PLACE_OBJ: {
 
			ClonePlaceObj(w);
 
		} break;
src/main_gui.cpp
Show inline comments
 
@@ -254,40 +254,40 @@ static void MenuClickLeague(int index)
 
}
 

	
 
static void MenuClickIndustry(int index)
 
{
 
	switch (index) {
 
		case 0: ShowIndustryDirectory();   break;
 
		case 1: ShowBuildIndustryWindow(); break;
 
	}
 
}
 

	
 
static void MenuClickShowTrains(int index)
 
{
 
	ShowVehicleListWindow((PlayerID)index, INVALID_STATION, VEH_Train);
 
	ShowVehicleListWindow((PlayerID)index, VEH_Train);
 
}
 

	
 
static void MenuClickShowRoad(int index)
 
{
 
	ShowVehicleListWindow((PlayerID)index, INVALID_STATION, VEH_Road);
 
	ShowVehicleListWindow((PlayerID)index, VEH_Road);
 
}
 

	
 
static void MenuClickShowShips(int index)
 
{
 
	ShowVehicleListWindow((PlayerID)index, INVALID_STATION, VEH_Ship);
 
	ShowVehicleListWindow((PlayerID)index, VEH_Ship);
 
}
 

	
 
static void MenuClickShowAir(int index)
 
{
 
	ShowVehicleListWindow((PlayerID)index, INVALID_STATION, VEH_Aircraft);
 
	ShowVehicleListWindow((PlayerID)index, VEH_Aircraft);
 
}
 

	
 
static void MenuClickBuildRail(int index)
 
{
 
	_last_built_railtype = (RailType)index;
 
	ShowBuildRailToolbar(_last_built_railtype, -1);
 
}
 

	
 
static void MenuClickBuildRoad(int index)
 
{
 
	ShowBuildRoadToolbar();
 
}
 
@@ -1793,28 +1793,28 @@ static void MainToolbarWndProc(Window *w
 
		case WKC_F1: case WKC_PAUSE: ToolbarPauseClick(w); break;
 
		case WKC_F2: ShowGameOptions(); break;
 
		case WKC_F3: MenuClickSaveLoad(0); break;
 
		case WKC_F4: ShowSmallMap(); break;
 
		case WKC_F5: ShowTownDirectory(); break;
 
		case WKC_F6: ShowSubsidiesList(); break;
 
		case WKC_F7: ShowPlayerStations(_local_player); break;
 
		case WKC_F8: ShowPlayerFinances(_local_player); break;
 
		case WKC_F9: ShowPlayerCompany(_local_player); break;
 
		case WKC_F10:ShowOperatingProfitGraph(); break;
 
		case WKC_F11: ShowCompanyLeagueTable(); break;
 
		case WKC_F12: ShowBuildIndustryWindow(); break;
 
		case WKC_SHIFT | WKC_F1: ShowVehicleListWindow(_local_player, INVALID_STATION, VEH_Train); break;
 
		case WKC_SHIFT | WKC_F2: ShowVehicleListWindow(_local_player, INVALID_STATION, VEH_Road); break;
 
		case WKC_SHIFT | WKC_F3: ShowVehicleListWindow(_local_player, INVALID_STATION, VEH_Ship); break;
 
		case WKC_SHIFT | WKC_F4: ShowVehicleListWindow(_local_player, INVALID_STATION, VEH_Aircraft); break;
 
		case WKC_SHIFT | WKC_F1: ShowVehicleListWindow(_local_player, VEH_Train); break;
 
		case WKC_SHIFT | WKC_F2: ShowVehicleListWindow(_local_player, VEH_Road); break;
 
		case WKC_SHIFT | WKC_F3: ShowVehicleListWindow(_local_player, VEH_Ship); break;
 
		case WKC_SHIFT | WKC_F4: ShowVehicleListWindow(_local_player, VEH_Aircraft); break;
 
		case WKC_SHIFT | WKC_F5: ToolbarZoomInClick(w); break;
 
		case WKC_SHIFT | WKC_F6: ToolbarZoomOutClick(w); break;
 
		case WKC_SHIFT | WKC_F7: ShowBuildRailToolbar(_last_built_railtype, -1); break;
 
		case WKC_SHIFT | WKC_F8: ShowBuildRoadToolbar(); break;
 
		case WKC_SHIFT | WKC_F9: ShowBuildDocksToolbar(); break;
 
		case WKC_SHIFT | WKC_F10:ShowBuildAirToolbar(); break;
 
		case WKC_SHIFT | WKC_F11: ShowBuildTreesToolbar(); break;
 
		case WKC_SHIFT | WKC_F12: ShowMusicWindow(); break;
 
		case WKC_CTRL  | 'S': MenuClickSmallScreenshot(); break;
 
		case WKC_CTRL  | 'G': MenuClickWorldScreenshot(); break;
 
		case WKC_CTRL | WKC_ALT | 'C': if (!_networking) ShowCheatWindow(); break;
 
		case 'A': ShowBuildRailToolbar(_last_built_railtype, 4); break; /* Invoke Autorail */
src/order_gui.cpp
Show inline comments
 
@@ -473,25 +473,25 @@ static void OrdersWndProc(Window *w, Win
 

	
 
		case 8: /* full load button */
 
			OrderClick_FullLoad(w, v);
 
			break;
 

	
 
		case 9: /* unload button */
 
			OrderClick_Unload(w, v);
 
			break;
 
		case 10: /* transfer button */
 
			OrderClick_Transfer(w, v);
 
			break;
 
		case 11: /* Vehicle with same shared Orders button */
 
			ShowVehWithSharedOrders(v, v->type);
 
			ShowVehicleListWindow(v);
 
			break;
 
		case 12:
 
			OrderClick_Refit(w, v);
 
			break;
 
		}
 
	} break;
 

	
 
	case WE_KEYPRESS: {
 
		Vehicle *v = GetVehicle(w->window_number);
 
		uint i;
 

	
 
		if (v->owner != _local_player) break;
src/station_gui.cpp
Show inline comments
 
@@ -753,47 +753,47 @@ static void StationViewWndProc(Window *w
 
			}
 

	
 
			SetWindowDirty(w);
 
			break;
 

	
 
		case 9: {
 
			SetDParam(0, w->window_number);
 
			ShowQueryString(STR_STATION, STR_3030_RENAME_STATION_LOADING, 31, 180, w, CS_ALPHANUMERAL);
 
		} break;
 

	
 
		case 10: { /* Show a list of scheduled trains to this station */
 
			const Station *st = GetStation(w->window_number);
 
			ShowVehicleListWindow(st->owner, w->window_number, VEH_Train);
 
			ShowVehicleListWindow(st->owner, VEH_Train, (StationID)w->window_number);
 
			break;
 
		}
 

	
 
		case 11: { /* Show a list of scheduled road-vehicles to this station */
 
			const Station *st = GetStation(w->window_number);
 
			ShowVehicleListWindow(st->owner, w->window_number, VEH_Road);
 
			ShowVehicleListWindow(st->owner, VEH_Road, (StationID)w->window_number);
 
			break;
 
		}
 

	
 
		case 12: { /* Show a list of scheduled aircraft to this station */
 
			const Station *st = GetStation(w->window_number);
 
			/* Since oilrigs have no owners, show the scheduled aircraft of current player */
 
			PlayerID owner = (st->owner == OWNER_NONE) ? _current_player : st->owner;
 
			ShowVehicleListWindow(owner, w->window_number, VEH_Aircraft);
 
			ShowVehicleListWindow(owner, VEH_Aircraft, (StationID)w->window_number);
 
			break;
 
		}
 

	
 
		case 13: { /* Show a list of scheduled ships to this station */
 
			const Station *st = GetStation(w->window_number);
 
			/* Since oilrigs/bouys have no owners, show the scheduled ships of current player */
 
			PlayerID owner = (st->owner == OWNER_NONE) ? _current_player : st->owner;
 
			ShowVehicleListWindow(owner, w->window_number, VEH_Ship);
 
			ShowVehicleListWindow(owner, VEH_Ship, (StationID)w->window_number);
 
			break;
 
		}
 
		}
 
		break;
 

	
 
	case WE_ON_EDIT_TEXT:
 
		if (e->we.edittext.str[0] != '\0') {
 
			_cmd_text = e->we.edittext.str;
 
			DoCommandP(0, w->window_number, 0, NULL,
 
				CMD_RENAME_STATION | CMD_MSG(STR_3031_CAN_T_RENAME_STATION));
 
		}
 
		break;
src/vehicle_gui.cpp
Show inline comments
 
@@ -1865,82 +1865,78 @@ static const WindowDesc _player_vehicle_
 
	_vehicle_list_widgets,
 
	PlayerVehWndProc
 
};
 

	
 
static const WindowDesc _player_vehicle_list_aircraft_desc = {
 
	WDP_AUTO, WDP_AUTO, 260, 182,
 
	WC_AIRCRAFT_LIST,0,
 
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
 
	_vehicle_list_widgets,
 
	PlayerVehWndProc
 
};
 

	
 
static void ShowVehicleListWindowLocal(PlayerID player, byte vehicle_type, StationID station, OrderID order, uint16 depot_airport_index)
 
static void ShowVehicleListWindowLocal(PlayerID player, uint16 VLW_flag, byte vehicle_type, uint16 unique_number)
 
{
 
	Window *w;
 
	WindowNumber num;
 

	
 
	if (!IsValidPlayer(player)) return;
 

	
 
	num = (vehicle_type << 11) | player;
 
	if (order != INVALID_ORDER) {
 
		num |= (order << 16) | VLW_SHARED_ORDERS;
 
	} else if (depot_airport_index != INVALID_STATION) {
 
		num |= (depot_airport_index << 16) | VLW_DEPOT_LIST;
 
	} else if (station == INVALID_STATION) {
 
		num |= VLW_STANDARD;
 
	} else {
 
		num |= (station << 16) | VLW_STATION_LIST;
 
	}
 
	num = (unique_number << 16) | (vehicle_type << 11) | VLW_flag | player;
 

	
 
	/* The vehicle list windows have been unified. Just some strings need
 
	 * to be changed which happens in the WE_CREATE event and resizing
 
	 * some of the windows to the correct size */
 
	switch (vehicle_type) {
 
		default: NOT_REACHED();
 
		case VEH_Train:
 
			w = AllocateWindowDescFront(&_player_vehicle_list_train_desc, num);
 
			if (w != NULL) ResizeWindow(w, 65, 38);
 
			break;
 
		case VEH_Road:
 
			w = AllocateWindowDescFront(&_player_vehicle_list_road_veh_desc, num);
 
			if (w != NULL) ResizeWindow(w, 0, 38);
 
			break;
 
		case VEH_Ship:
 
			w = AllocateWindowDescFront(&_player_vehicle_list_ship_desc, num);
 
			break;
 
		case VEH_Aircraft:
 
			w = AllocateWindowDescFront(&_player_vehicle_list_aircraft_desc, num);
 
			break;
 
		default: NOT_REACHED(); return;
 
	}
 

	
 
	if (w != NULL) {
 
		/* Set the minimum window size to the current window size */
 
		w->resize.width = w->width;
 
		w->resize.height = w->height;
 
	}
 
}
 

	
 
void ShowVehicleListWindow(PlayerID player, StationID station, byte vehicle_type)
 
void ShowVehicleListWindow(PlayerID player, byte vehicle_type)
 
{
 
	ShowVehicleListWindowLocal(player, vehicle_type, station, INVALID_ORDER, INVALID_STATION);
 
	ShowVehicleListWindowLocal(player, VLW_STANDARD, vehicle_type, 0);
 
}
 

	
 
void ShowVehWithSharedOrders(Vehicle *v, byte vehicle_type)
 
void ShowVehicleListWindow(const Vehicle *v)
 
{
 
	if (v->orders == NULL) return; // no shared list to show
 
	ShowVehicleListWindowLocal(v->owner, vehicle_type, INVALID_STATION, v->orders->index, INVALID_STATION);
 
	ShowVehicleListWindowLocal(v->owner, VLW_SHARED_ORDERS, v->type, v->orders->index);
 
}
 

	
 
void ShowVehDepotOrders(PlayerID player, byte vehicle_type, TileIndex depot_tile)
 
void ShowVehicleListWindow(PlayerID player, byte vehicle_type, StationID station)
 
{
 
	ShowVehicleListWindowLocal(player, VLW_STATION_LIST, vehicle_type, station);
 
}
 

	
 
void ShowVehicleListWindow(PlayerID player, byte vehicle_type, TileIndex depot_tile)
 
{
 
	uint16 depot_airport_index;
 

	
 
	if (vehicle_type == VEH_Aircraft) {
 
		depot_airport_index = GetStationIndex(depot_tile);
 
	} else {
 
		Depot *depot = GetDepotByTile(depot_tile);
 
		if (depot == NULL) return; // no depot to show
 
		depot_airport_index = depot->index;
 
	}
 
	ShowVehicleListWindowLocal(player, vehicle_type, INVALID_STATION, INVALID_ORDER, depot_airport_index);
 
	ShowVehicleListWindowLocal(player, VLW_DEPOT_LIST, vehicle_type, depot_airport_index);
 
}
src/vehicle_gui.h
Show inline comments
 
@@ -44,27 +44,28 @@ void DrawShipImage(const Vehicle *v, int
 
void DrawAircraftImage(const Vehicle *v, int x, int y, VehicleID selection);
 

	
 
void ShowBuildTrainWindow(TileIndex tile);
 
void ShowBuildRoadVehWindow(TileIndex tile);
 
void ShowBuildShipWindow(TileIndex tile);
 
void ShowBuildVehicleWindow(TileIndex tile, byte type);
 

	
 
void ChangeVehicleViewWindow(const Vehicle *from_v, const Vehicle *to_v);
 

	
 
uint ShowAdditionalText(int x, int y, uint w, EngineID engine);
 
uint ShowRefitOptionsList(int x, int y, uint w, EngineID engine);
 

	
 
void ShowVehicleListWindow(PlayerID player, StationID station, byte vehicle_type);
 
void ShowVehWithSharedOrders(Vehicle *v, byte vehicle_type);
 
void ShowVehDepotOrders(PlayerID player, byte vehicle_type, TileIndex depot_tile);
 
void ShowVehicleListWindow(const Vehicle *v);
 
void ShowVehicleListWindow(PlayerID player, byte vehicle_type);
 
void ShowVehicleListWindow(PlayerID player, byte vehicle_type, StationID station);
 
void ShowVehicleListWindow(PlayerID player, byte vehicle_type, TileIndex depot_tile);
 

	
 

	
 
static inline void DrawVehicleImage(const Vehicle *v, int x, int y, int count, int skip, VehicleID selection)
 
{
 
	switch (v->type) {
 
		case VEH_Train:    DrawTrainImage(v, x, y, count, skip, selection); break;
 
		case VEH_Road:     DrawRoadVehImage(v, x, y, selection);            break;
 
		case VEH_Ship:     DrawShipImage(v, x, y, selection);               break;
 
		case VEH_Aircraft: DrawAircraftImage(v, x, y, selection);           break;
 
		default: NOT_REACHED();
 
	}
 
}
0 comments (0 inline, 0 general)