Mercurial > hg > openttd
changeset 4449:3c486011c634 draft
(svn r6227) -Codechange: added window type flags to use with PlayerVehWndProc
this makes the list type detection much easier and allowed an if cascade to be turned into a switch case
this also makes it easier to add more list types
author | bjarni <bjarni@openttd.org> |
---|---|
date | Tue, 29 Aug 2006 21:36:39 +0000 |
parents | 1850c4e4f8c5 |
children | ea574bee2030 |
files | aircraft_gui.c order.h roadveh_gui.c ship_gui.c train_gui.c vehicle_gui.c vehicle_gui.h |
diffstat | 7 files changed, 80 insertions(+), 56 deletions(-) [+] |
line wrap: on
line diff
--- a/aircraft_gui.c +++ b/aircraft_gui.c @@ -1028,12 +1028,13 @@ Window *w; if (show_shared) { - w = AllocateWindowDescFront(&_player_aircraft_desc, (order << 16) | (VEH_Aircraft << 11) | SHARE_FLAG); + w = AllocateWindowDescFront(&_player_aircraft_desc, (order << 16) | (VEH_Aircraft << 11) | VLW_SHARED_ORDERS); } else { + uint16 VLW_flag = (station == INVALID_STATION) ? VLW_STANDARD : VLW_STATION_LIST; if (player == _local_player) { - w = AllocateWindowDescFront(&_player_aircraft_desc, (station << 16) | (VEH_Aircraft << 11) | player); + w = AllocateWindowDescFront(&_player_aircraft_desc, (station << 16) | (VEH_Aircraft << 11) | VLW_flag | player); } else { - w = AllocateWindowDescFront(&_other_player_aircraft_desc, (station << 16) | (VEH_Aircraft << 11) | player); + w = AllocateWindowDescFront(&_other_player_aircraft_desc, (station << 16) | (VEH_Aircraft << 11) | VLW_flag | player); } }
--- a/order.h +++ b/order.h @@ -11,7 +11,6 @@ enum { INVALID_ORDER = 0xFFFF, - SHARE_FLAG = 1 << 8, }; /* Order types */
--- a/roadveh_gui.c +++ b/roadveh_gui.c @@ -967,14 +967,16 @@ Window *w; if (show_shared) { - w = AllocateWindowDescFront(&_player_roadveh_desc, (order << 16) | (VEH_Road << 11) | SHARE_FLAG); + w = AllocateWindowDescFront(&_player_roadveh_desc, (order << 16) | (VEH_Road << 11) | VLW_SHARED_ORDERS); } else { - if ( player == _local_player) { - w = AllocateWindowDescFront(&_player_roadveh_desc, (station << 16) | (VEH_Road << 11) | player); + uint16 VLW_flag = (station == INVALID_STATION) ? VLW_STANDARD : VLW_STATION_LIST; + if (player == _local_player) { + w = AllocateWindowDescFront(&_player_roadveh_desc, (station << 16) | (VEH_Road << 11) | VLW_flag | player); } else { - w = AllocateWindowDescFront(&_other_player_roadveh_desc, (station << 16) | (VEH_Road << 11) | player); + w = AllocateWindowDescFront(&_other_player_roadveh_desc, (station << 16) | (VEH_Road << 11) | VLW_flag | player); } } + if (w != NULL) { vehiclelist_d *vl = &WP(w, vehiclelist_d); vl->flags = VL_REBUILD | (_sorting.roadveh.order << (VL_DESC - 1));
--- a/ship_gui.c +++ b/ship_gui.c @@ -970,12 +970,13 @@ Window *w; if (show_shared) { - w = AllocateWindowDescFront(&_player_ships_desc, (order << 16) | VEH_Ship << 11 | SHARE_FLAG); + w = AllocateWindowDescFront(&_player_ships_desc, (order << 16) | (VEH_Ship << 11) | VLW_SHARED_ORDERS); } else { + uint16 VLW_flag = (station == INVALID_STATION) ? VLW_STANDARD : VLW_STATION_LIST; if (player == _local_player) { - w = AllocateWindowDescFront(&_player_ships_desc, (station << 16) | VEH_Ship << 11 | player); + w = AllocateWindowDescFront(&_player_ships_desc, (station << 16) | (VEH_Ship << 11) | VLW_flag | player); } else { - w = AllocateWindowDescFront(&_other_player_ships_desc, (station << 16) | VEH_Ship << 11 | player); + w = AllocateWindowDescFront(&_other_player_ships_desc, (station << 16) | (VEH_Ship << 11) | VLW_flag | player); } }
--- a/train_gui.c +++ b/train_gui.c @@ -1425,14 +1425,16 @@ Window *w; if (show_shared) { - w = AllocateWindowDescFront(&_player_trains_desc, (order << 16) | (VEH_Train << 11) | SHARE_FLAG); + w = AllocateWindowDescFront(&_player_trains_desc, (order << 16) | (VEH_Train << 11) | VLW_SHARED_ORDERS); } else { + uint16 VLW_flag = (station == INVALID_STATION) ? VLW_STANDARD : VLW_STATION_LIST; if (player == _local_player) { - w = AllocateWindowDescFront(&_player_trains_desc, (station << 16) | (VEH_Train << 11) | player); - } else { - w = AllocateWindowDescFront(&_other_player_trains_desc, (station << 16) | (VEH_Train << 11) | player); + w = AllocateWindowDescFront(&_player_trains_desc, (station << 16) | (VEH_Train << 11) | VLW_flag | player); + } else { + w = AllocateWindowDescFront(&_other_player_trains_desc, (station << 16) | (VEH_Train << 11) | VLW_flag | player); } } + if (w != NULL) { vehiclelist_d *vl = &WP(w, vehiclelist_d); vl->flags = VL_REBUILD | (_sorting.train.order << (VL_DESC - 1));
--- a/vehicle_gui.c +++ b/vehicle_gui.c @@ -1207,6 +1207,14 @@ extern const Widget _player_roadveh_widgets[]; extern const Widget _player_trains_widgets[]; +/* + * bitmask for w->window_number + * 0-7 PlayerID (owner) + * 8-10 window type (use flags in vehicle_gui.h) + * 11-15 vehicle type (using VEH_, but can be compressed to fewer bytes if needed) + * 16-31 StationID or OrderID depending on window type (bit 8-10) + **/ + void PlayerVehWndProc(Window *w, WindowEvent *e) { vehiclelist_d *vl = &WP(w, vehiclelist_d); @@ -1221,14 +1229,9 @@ int i; const PlayerID owner = GB(w->window_number, 0, 8); const Player *p = GetPlayer(owner); - OrderID order = INVALID_ORDER; - StationID station = INVALID_STATION; - - if (w->window_number & SHARE_FLAG) { - order = GB(w->window_number, 16, 16); - } else { - station = GB(w->window_number, 16, 16); - } + const uint16 window_type = w->window_number & VLW_FLAGS; + const StationID station = (window_type == VLW_STATION_LIST) ? GB(w->window_number, 16, 16) : INVALID_STATION; + const OrderID order = (window_type == VLW_SHARED_ORDERS) ? GB(w->window_number, 16, 16) : INVALID_ORDER; BuildVehicleList(vl, vehicle_type, owner, station, order); SortVehicleList(vl); @@ -1238,37 +1241,45 @@ if (vl->sort_type == SORT_BY_UNSORTED) SETBIT(w->disabled_state, 3); /* draw the widgets */ - if (order != INVALID_ORDER) { - /* Shared Orders */ - SetDParam(0, w->vscroll.count); - w->widget[1].unkA = STR_VEH_WITH_SHARED_ORDERS_LIST; - w->widget[9].unkA = STR_EMPTY; - w->widget[10].unkA = STR_EMPTY; - SETBIT(w->disabled_state, 9); - SETBIT(w->disabled_state, 10); - } else if (station == INVALID_STATION) { - /* Company Name */ - SetDParam(0, p->name_1); - SetDParam(1, p->name_2); - SetDParam(2, w->vscroll.count); - switch (vehicle_type) { - case VEH_Train: w->widget[1].unkA = STR_881B_TRAINS; break; - case VEH_Road: w->widget[1].unkA = STR_9001_ROAD_VEHICLES; break; - case VEH_Ship: w->widget[1].unkA = STR_9805_SHIPS; break; - case VEH_Aircraft: w->widget[1].unkA = STR_A009_AIRCRAFT; break; - default: NOT_REACHED(); break; - } - } else { - /* Station Name */ - SetDParam(0, station); - SetDParam(1, w->vscroll.count); - switch (vehicle_type) { - case VEH_Train: w->widget[1].unkA = STR_SCHEDULED_TRAINS; break; - case VEH_Road: w->widget[1].unkA = STR_SCHEDULED_ROAD_VEHICLES; break; - case VEH_Ship: w->widget[1].unkA = STR_SCHEDULED_SHIPS; break; - case VEH_Aircraft: w->widget[1].unkA = STR_SCHEDULED_AIRCRAFT; break; - default: NOT_REACHED(); break; - } + switch (window_type) { + case VLW_SHARED_ORDERS: + /* Shared Orders */ + SetDParam(0, w->vscroll.count); + w->widget[1].unkA = STR_VEH_WITH_SHARED_ORDERS_LIST; + w->widget[9].unkA = STR_EMPTY; + w->widget[10].unkA = STR_EMPTY; + SETBIT(w->disabled_state, 9); + SETBIT(w->disabled_state, 10); + break; + + case VLW_STANDARD: + /* Company Name */ + SetDParam(0, p->name_1); + SetDParam(1, p->name_2); + SetDParam(2, w->vscroll.count); + switch (vehicle_type) { + case VEH_Train: w->widget[1].unkA = STR_881B_TRAINS; break; + case VEH_Road: w->widget[1].unkA = STR_9001_ROAD_VEHICLES; break; + case VEH_Ship: w->widget[1].unkA = STR_9805_SHIPS; break; + case VEH_Aircraft: w->widget[1].unkA = STR_A009_AIRCRAFT; break; + default: NOT_REACHED(); break; + } + break; + + case VLW_STATION_LIST: + /* Station Name */ + SetDParam(0, station); + SetDParam(1, w->vscroll.count); + switch (vehicle_type) { + case VEH_Train: w->widget[1].unkA = STR_SCHEDULED_TRAINS; break; + case VEH_Road: w->widget[1].unkA = STR_SCHEDULED_ROAD_VEHICLES; break; + case VEH_Ship: w->widget[1].unkA = STR_SCHEDULED_SHIPS; break; + case VEH_Aircraft: w->widget[1].unkA = STR_SCHEDULED_AIRCRAFT; break; + default: NOT_REACHED(); break; + } + break; + + default: NOT_REACHED(); break; } DrawWindowWidgets(w); @@ -1439,9 +1450,9 @@ case WE_TICK: /* resort the list every 20 seconds orso (10 days) */ if (--vl->resort_timer == 0) { - StationID station = (w->window_number & SHARE_FLAG) ? INVALID_STATION : GB(w->window_number, 16, 16); + StationID station = ((w->window_number & VLW_FLAGS) == VLW_STATION_LIST) ? GB(w->window_number, 16, 16) : INVALID_STATION; PlayerID owner = GB(w->window_number, 0, 8); - DEBUG(misc, 1) ("Periodic resort ships list player %d station %d", owner, station); + DEBUG(misc, 1) ("Periodic resort %d list player %d station %d", vehicle_type, owner, station); vl->resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS; vl->flags |= VL_RESORT; SetWindowDirty(w);
--- a/vehicle_gui.h +++ b/vehicle_gui.h @@ -44,6 +44,14 @@ PLY_WND_PRC__SIZE_OF_ROW_BIG = 36, }; +/* Vehicle List Window type flags */ +enum { + VLW_FLAGS = (1 << 8)|(1 << 9)|(1 << 10), + VLW_STANDARD = 0, + VLW_SHARED_ORDERS = 1 << 8, + VLW_STATION_LIST = 2 << 8, +}; + void PlayerVehWndProc(Window *w, WindowEvent *e); void ShowReplaceVehicleWindow(byte vehicletype);