(svn r13165) -Codechange: replace some RebuildXXXList/ResortXXXList+InvalidateWindowXXX with InvalidateWindowXXXData.

This commit is contained in:
rubidium 2008-05-18 16:51:44 +00:00
parent aab9e191f5
commit 9defec7876
16 changed files with 53 additions and 127 deletions

View File

@ -446,7 +446,7 @@ CommandCost CmdBuildAircraft(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
}
InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile);
RebuildVehicleLists();
InvalidateWindowClassesData(WC_AIRCRAFT_LIST, 0);
InvalidateWindow(WC_COMPANY, v->owner);
if (IsLocalPlayer())
InvalidateAutoreplaceWindow(v->engine_type, v->group_id); //updates the replace Aircraft window
@ -461,11 +461,10 @@ CommandCost CmdBuildAircraft(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
static void DoDeleteAircraft(Vehicle *v)
{
DeleteWindowById(WC_VEHICLE_VIEW, v->index);
RebuildVehicleLists();
InvalidateWindow(WC_COMPANY, v->owner);
DeleteDepotHighlightOfVehicle(v);
DeleteVehicleChain(v);
InvalidateWindowClasses(WC_AIRCRAFT_LIST);
InvalidateWindowClassesData(WC_AIRCRAFT_LIST, 0);
}
/** Sell an aircraft.
@ -656,7 +655,7 @@ CommandCost CmdRefitAircraft(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
v->cargo_subtype = new_subtype;
InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
RebuildVehicleLists();
InvalidateWindowClassesData(WC_AIRCRAFT_LIST, 0);
}
return cost;

View File

@ -1781,7 +1781,10 @@ static void DoAcquireCompany(Player *p)
p->is_active = false;
DeletePlayerWindows(pi);
RebuildVehicleLists(); //Updates the open windows to add the newly acquired vehicles to the lists
InvalidateWindowClassesData(WC_TRAINS_LIST, 0);
InvalidateWindowClassesData(WC_SHIPS_LIST, 0);
InvalidateWindowClassesData(WC_ROADVEH_LIST, 0);
InvalidateWindowClassesData(WC_AIRCRAFT_LIST, 0);
}
extern int GetAmountOwnedBy(const Player *p, PlayerID owner);

View File

@ -286,8 +286,8 @@ struct VehicleGroupWindow : public Window, public VehicleListBase {
virtual void OnInvalidateData(int data)
{
this->vehicles.flags |= VL_REBUILD;
this->groups.flags |= VL_REBUILD;
this->vehicles.flags |= (data == 0 ? VL_REBUILD : VL_RESORT);
this->groups.flags |= (data == 0 ? VL_REBUILD : VL_RESORT);
if (!(IsAllGroupID(this->group_sel) || IsDefaultGroupID(this->group_sel) || IsValidGroupID(this->group_sel))) {
this->group_sel = ALL_GROUP;
HideDropDownMenu(this);

View File

@ -546,7 +546,7 @@ CommandCost CmdInsertOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
}
/* Make sure to rebuild the whole list */
RebuildVehicleLists();
InvalidateWindowClassesData(GetWindowClassForVehicleType(v->type), 0);
}
return CommandCost();
@ -561,7 +561,7 @@ static CommandCost DecloneOrder(Vehicle *dst, uint32 flags)
if (flags & DC_EXEC) {
DeleteVehicleOrders(dst);
InvalidateVehicleOrder(dst);
RebuildVehicleLists();
InvalidateWindowClassesData(GetWindowClassForVehicleType(dst->type), 0);
}
return CommandCost();
}
@ -673,7 +673,7 @@ CommandCost CmdDeleteOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
cur_order_id++;
}
RebuildVehicleLists();
InvalidateWindowClassesData(GetWindowClassForVehicleType(v->type), 0);
}
return CommandCost();
@ -811,7 +811,7 @@ CommandCost CmdMoveOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
}
/* Make sure to rebuild the whole list */
RebuildVehicleLists();
InvalidateWindowClassesData(GetWindowClassForVehicleType(v->type), 0);
}
return CommandCost();
@ -1075,7 +1075,7 @@ CommandCost CmdCloneOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
InvalidateVehicleOrder(dst);
InvalidateVehicleOrder(src);
RebuildVehicleLists();
InvalidateWindowClassesData(GetWindowClassForVehicleType(dst->type), 0);
}
} break;
@ -1134,7 +1134,7 @@ CommandCost CmdCloneOrder(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
InvalidateVehicleOrder(dst);
RebuildVehicleLists();
InvalidateWindowClassesData(GetWindowClassForVehicleType(dst->type), 0);
}
} break;

View File

@ -280,7 +280,7 @@ CommandCost CmdBuildRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
VehiclePositionChanged(v);
InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile);
RebuildVehicleLists();
InvalidateWindowClassesData(WC_ROADVEH_LIST, 0);
InvalidateWindow(WC_COMPANY, v->owner);
if (IsLocalPlayer())
InvalidateAutoreplaceWindow(v->engine_type, v->group_id); // updates the replace Road window
@ -381,7 +381,7 @@ CommandCost CmdSellRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
if (flags & DC_EXEC) {
// Invalidate depot
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
RebuildVehicleLists();
InvalidateWindowClassesData(WC_ROADVEH_LIST, 0);
InvalidateWindow(WC_COMPANY, v->owner);
DeleteWindowById(WC_VEHICLE_VIEW, v->index);
DeleteDepotHighlightOfVehicle(v);
@ -574,7 +574,7 @@ static void DeleteLastRoadVeh(Vehicle *v)
DeleteWindowById(WC_VEHICLE_VIEW, v->index);
RebuildVehicleLists();
InvalidateWindowClassesData(WC_ROADVEH_LIST, 0);
InvalidateWindow(WC_COMPANY, v->owner);
if (IsTileType(v->tile, MP_STATION)) ClearCrashedStation(v);
@ -2116,7 +2116,7 @@ CommandCost CmdRefitRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
v->cargo_subtype = new_subtype;
InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
RebuildVehicleLists();
InvalidateWindowClassesData(WC_ROADVEH_LIST, 0);
}
if (only_this) break;

View File

@ -814,7 +814,7 @@ CommandCost CmdBuildShip(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
VehiclePositionChanged(v);
InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile);
RebuildVehicleLists();
InvalidateWindowClassesData(WC_SHIPS_LIST, 0);
InvalidateWindow(WC_COMPANY, v->owner);
if (IsLocalPlayer())
InvalidateAutoreplaceWindow(v->engine_type, v->group_id); // updates the replace Ship window
@ -851,7 +851,7 @@ CommandCost CmdSellShip(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
if (flags & DC_EXEC) {
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
RebuildVehicleLists();
InvalidateWindowClassesData(WC_SHIPS_LIST, 0);
InvalidateWindow(WC_COMPANY, v->owner);
DeleteWindowById(WC_VEHICLE_VIEW, v->index);
DeleteDepotHighlightOfVehicle(v);
@ -997,7 +997,7 @@ CommandCost CmdRefitShip(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
v->cargo_subtype = new_subtype;
InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
RebuildVehicleLists();
InvalidateWindowClassesData(WC_SHIPS_LIST, 0);
}
return cost;

View File

@ -74,8 +74,7 @@ Station::~Station()
}
MarkDirty();
RebuildStationLists();
InvalidateWindowClasses(WC_STATION_LIST);
InvalidateWindowData(WC_STATION_LIST, this->owner, 0);
DeleteWindowById(WC_STATION_VIEW, index);

View File

@ -650,8 +650,7 @@ static void DeleteStationIfEmpty(Station *st)
{
if (st->facilities == 0) {
st->delete_ctr = 0;
RebuildStationLists();
InvalidateWindow(WC_STATION_LIST, st->owner);
InvalidateWindowData(WC_STATION_LIST, st->owner, 0);
}
/* station remains but it probably lost some parts - station sign should stay in the station boundaries */
UpdateStationSignCoord(st);
@ -1051,8 +1050,7 @@ CommandCost CmdBuildRailroadStation(TileIndex tile_org, uint32 flags, uint32 p1,
st->MarkTilesDirty(false);
UpdateStationVirtCoordDirty(st);
UpdateStationAcceptance(st, false);
RebuildStationLists();
InvalidateWindow(WC_STATION_LIST, st->owner);
InvalidateWindowData(WC_STATION_LIST, st->owner, 0);
InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_TRAINS);
}
@ -1410,8 +1408,7 @@ CommandCost CmdBuildRoadStop(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
UpdateStationVirtCoordDirty(st);
UpdateStationAcceptance(st, false);
RebuildStationLists();
InvalidateWindow(WC_STATION_LIST, st->owner);
InvalidateWindowData(WC_STATION_LIST, st->owner, 0);
InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_ROADVEHS);
}
return cost;
@ -1723,8 +1720,7 @@ CommandCost CmdBuildAirport(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
UpdateStationVirtCoordDirty(st);
UpdateStationAcceptance(st, false);
RebuildStationLists();
InvalidateWindow(WC_STATION_LIST, st->owner);
InvalidateWindowData(WC_STATION_LIST, st->owner, 0);
InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_PLANES);
}
@ -1820,8 +1816,7 @@ CommandCost CmdBuildBuoy(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
UpdateStationVirtCoordDirty(st);
UpdateStationAcceptance(st, false);
RebuildStationLists();
InvalidateWindow(WC_STATION_LIST, st->owner);
InvalidateWindowData(WC_STATION_LIST, st->owner, 0);
InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_SHIPS);
}
@ -1979,8 +1974,7 @@ CommandCost CmdBuildDock(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
UpdateStationVirtCoordDirty(st);
UpdateStationAcceptance(st, false);
RebuildStationLists();
InvalidateWindow(WC_STATION_LIST, st->owner);
InvalidateWindowData(WC_STATION_LIST, st->owner, 0);
InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_SHIPS);
}
@ -2637,7 +2631,7 @@ CommandCost CmdRenameStation(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
st->name = strdup(_cmd_text);
UpdateStationVirtCoord(st);
ResortStationLists();
InvalidateWindowData(WC_STATION_LIST, st->owner, 1);
MarkWholeScreenDirty();
}
@ -2858,8 +2852,7 @@ static void ChangeTileOwner_Station(TileIndex tile, PlayerID old_player, PlayerI
SetTileOwner(tile, new_player);
if (!IsBuoy(tile)) st->owner = new_player; // do not set st->owner for buoys
RebuildStationLists();
InvalidateWindowClasses(WC_STATION_LIST);
InvalidateWindowClassesData(WC_STATION_LIST, 0);
} else {
if (IsDriveThroughStopTile(tile)) {
/* Remove the drive-through road stop */

View File

@ -167,39 +167,6 @@ static int CDECL StationRatingMaxSorter(const void *a, const void *b)
typedef GUIList<const Station*> GUIStationList;
/**
* Set the station sort flag for all station-list windows.
* @param sl_flag Sort list flag to set for all station-list windows
*/
static void SetStationListsFlag(SortListFlags sl_flag)
{
Window *const *wz;
FOR_ALL_WINDOWS(wz) {
Window *w = *wz;
if (w->window_class == WC_STATION_LIST) {
dynamic_cast<GUIStationList*>(w)->flags |= sl_flag;
w->SetDirty();
}
}
}
/**
* Set the 'VL_REBUILD' flag for all station lists
*/
void RebuildStationLists()
{
SetStationListsFlag(VL_REBUILD);
}
/**
* Set the 'VL_RESORT' flag for all station lists
*/
void ResortStationLists()
{
SetStationListsFlag(VL_RESORT);
}
/**
* Rebuild station list if the VL_REBUILD flag is set
*
@ -605,6 +572,11 @@ struct PlayerStationsWindow : public Window, public GUIStationList
{
this->vscroll.cap += delta.y / 10;
}
virtual void OnInvalidateData(int data)
{
this->flags |= (data == 0 ? VL_REBUILD : VL_RESORT);
}
};
Listing PlayerStationsWindow::station_sort = {0, 0};

View File

@ -48,10 +48,6 @@ enum StationViewWidgets {
SVW_RESIZE, ///< Resize button
};
/* sorter stuff */
void RebuildStationLists();
void ResortStationLists();
enum StationCoverageType {
SCT_PASSENGERS_ONLY,
SCT_NON_PASSENGERS_ONLY,

View File

@ -803,7 +803,7 @@ CommandCost CmdBuildRailVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32
}
InvalidateWindowData(WC_VEHICLE_DEPOT, v->tile);
RebuildVehicleLists();
InvalidateWindowClassesData(WC_TRAINS_LIST, 0);
InvalidateWindow(WC_COMPANY, v->owner);
if (IsLocalPlayer()) {
InvalidateAutoreplaceWindow(v->engine_type, v->group_id); // updates the replace Train window
@ -1272,7 +1272,7 @@ CommandCost CmdMoveRailVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p
InvalidateWindow(WC_VEHICLE_DEPOT, dst_head->tile);
}
RebuildVehicleLists();
InvalidateWindowClassesData(WC_TRAINS_LIST, 0);
}
return CommandCost();
@ -1353,7 +1353,7 @@ CommandCost CmdSellRailWagon(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
DeleteWindowById(WC_VEHICLE_VIEW, first->index);
}
InvalidateWindow(WC_VEHICLE_DEPOT, first->tile);
RebuildVehicleLists();
InvalidateWindowClassesData(WC_TRAINS_LIST, 0);
}
CommandCost cost(EXPENSES_NEW_VEHICLES);
@ -2001,7 +2001,7 @@ CommandCost CmdRefitRailVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32
v->cargo_subtype = new_subtype;
InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
RebuildVehicleLists();
InvalidateWindowClassesData(WC_TRAINS_LIST, 0);
}
}
}
@ -2805,7 +2805,7 @@ static void SetVehicleCrashed(Vehicle *v)
InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
}
RebuildVehicleLists();
InvalidateWindowClassesData(WC_TRAINS_LIST, 0);
BEGIN_ENUM_WAGONS(v)
v->vehstatus |= VS_CRASHED;
@ -3152,7 +3152,7 @@ static void DeleteLastWagon(Vehicle *v)
}
}
RebuildVehicleLists();
InvalidateWindowClassesData(WC_TRAINS_LIST, 0);
MarkSingleVehicleDirty(v);

View File

@ -18,6 +18,7 @@
#include "order_func.h"
#include "engine_func.h"
#include "engine_base.h"
#include "window_func.h"
#include "table/sprites.h"
#include "table/strings.h"
@ -43,7 +44,7 @@ void CcBuildWagon(bool success, TileIndex tile, uint32 p1, uint32 p2)
found = GetLastVehicleInChain(found);
/* put the new wagon at the end of the loco. */
DoCommandP(0, _new_vehicle_id | (found->index << 16), 0, NULL, CMD_MOVE_RAIL_VEHICLE);
RebuildVehicleLists();
InvalidateWindowClassesData(WC_TRAINS_LIST, 0);
}
}

View File

@ -1733,7 +1733,7 @@ CommandCost CmdNameVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
if (flags & DC_EXEC) {
free(v->name);
v->name = strdup(_cmd_text);
ResortVehicleLists();
InvalidateWindowClassesData(WC_TRAINS_LIST, 1);
MarkWholeScreenDirty();
}

View File

@ -86,47 +86,6 @@ const StringID _vehicle_sort_listing[] = {
INVALID_STRING_ID
};
/**
* Set sort list flag for all vehicle list windows
* @param sl_flag Sort list flag to set
*/
static void SetVehicleListsFlag(SortListFlags sl_flag)
{
Window* const *wz;
FOR_ALL_WINDOWS(wz) {
Window *w = *wz;
switch (w->window_class) {
case WC_TRAINS_LIST:
case WC_ROADVEH_LIST:
case WC_SHIPS_LIST:
case WC_AIRCRAFT_LIST:
dynamic_cast<VehicleListBase*>(w)->vehicles.flags |= sl_flag;
w->SetDirty();
break;
default: break;
}
}
}
/**
* Rebuild all vehicle list windows
*/
void RebuildVehicleLists()
{
SetVehicleListsFlag(VL_REBUILD);
}
/**
* Resort all vehicle list windows
*/
void ResortVehicleLists()
{
SetVehicleListsFlag(VL_RESORT);
}
void BuildVehicleList(VehicleListBase *vl, PlayerID owner, uint16 index, uint16 window_type)
{
if (!(vl->vehicles.flags & VL_REBUILD)) return;
@ -1187,6 +1146,11 @@ struct VehicleListWindow : public Window, public VehicleListBase {
this->vscroll.cap += delta.y / (int)this->resize.step_height;
this->widget[VLW_WIDGET_LIST].data = (this->vscroll.cap << 8) + 1;
}
virtual void OnInvalidateData(int data)
{
this->vehicles.flags |= (data == 0 ? VL_REBUILD : VL_RESORT);
}
};
static const WindowDesc _player_vehicle_list_train_desc = {

View File

@ -133,8 +133,6 @@ struct Sorting {
extern Sorting _sorting;
/* sorter stuff */
void RebuildVehicleLists();
void ResortVehicleLists();
void SortVehicleList(VehicleListBase *vl);
void BuildVehicleList(VehicleListBase *vl, PlayerID owner, uint16 index, uint16 window_type);

View File

@ -838,20 +838,21 @@ static void FloodVehicle(Vehicle *v)
case VEH_TRAIN:
if (IsFrontEngine(v)) pass += 4; // driver
v->u.rail.crash_anim_pos = 4000; // max 4440, disappear pretty fast
InvalidateWindowClassesData(WC_TRAINS_LIST, 0);
break;
case VEH_ROAD:
if (IsRoadVehFront(v)) pass += 1; // driver
v->u.road.crashed_ctr = 2000; // max 2220, disappear pretty fast
InvalidateWindowClassesData(WC_ROADVEH_LIST, 0);
break;
case VEH_AIRCRAFT:
pass += 2; // driver
v->u.air.crashed_counter = 9000; // max 10000, disappear pretty fast
InvalidateWindowClassesData(WC_AIRCRAFT_LIST, 0);
break;
}
RebuildVehicleLists();
} else {
return;
}