Changeset - r11653:0d202a3535b8
[Not reviewed]
master
0 1 0
frosch - 15 years ago 2009-04-12 14:12:17
frosch@openttd.org
(svn r16038) -Codechange: Remove BuildVehicleWindow::regenerate_list in favor of the GUIList flag.
1 file changed with 11 insertions and 9 deletions:
0 comments (0 inline, 0 general)
src/build_vehicle_gui.cpp
Show inline comments
 
@@ -713,13 +713,12 @@ struct BuildVehicleWindow : Window {
 
		RailTypeByte railtype;
 
		AirportFTAClass::Flags flags;
 
		RoadTypes roadtypes;
 
	} filter;
 
	bool descending_sort_order;
 
	byte sort_criteria;
 
	bool regenerate_list;
 
	bool listview_mode;
 
	EngineID sel_engine;
 
	EngineID rename_engine;
 
	GUIEngineList eng_list;
 

	
 
	BuildVehicleWindow(const WindowDesc *desc, TileIndex tile, VehicleType type) : Window(desc, tile == INVALID_TILE ? (int)type : tile)
 
@@ -735,13 +734,12 @@ struct BuildVehicleWindow : Window {
 
		this->resize.width  = this->width;
 
		this->resize.height = this->height;
 

	
 
		this->owner = (tile != INVALID_TILE) ? GetTileOwner(tile) : _local_company;
 

	
 
		this->sel_engine      = INVALID_ENGINE;
 
		this->regenerate_list = false;
 

	
 
		this->sort_criteria         = _last_sort_criteria[type];
 
		this->descending_sort_order = _last_sort_order[type];
 

	
 
		switch (type) {
 
			default: NOT_REACHED();
 
@@ -767,12 +765,13 @@ struct BuildVehicleWindow : Window {
 
			this->widget[BUILD_VEHICLE_WIDGET_RENAME].left = this->widget[BUILD_VEHICLE_WIDGET_BUILD].left;
 
		} else {
 
			/* Both are visible, adjust the size of each */
 
			ResizeButtons(this, BUILD_VEHICLE_WIDGET_BUILD, BUILD_VEHICLE_WIDGET_RENAME);
 
		}
 

	
 
		this->eng_list.ForceRebuild();
 
		this->GenerateBuildList(); // generate the list, since we need it in the next line
 
		/* Select the first engine in the list as default when opening the window */
 
		if (this->eng_list.Length() > 0) this->sel_engine = this->eng_list[0];
 

	
 
		this->FindWindowPlacementAndResize(desc);
 
	}
 
@@ -932,16 +931,19 @@ struct BuildVehicleWindow : Window {
 
		this->sel_engine = sel_id;
 
	}
 

	
 
	/* Generate the list of vehicles */
 
	void GenerateBuildList()
 
	{
 
		if (!this->eng_list.NeedRebuild()) return;
 
		switch (this->vehicle_type) {
 
			default: NOT_REACHED();
 
			case VEH_TRAIN:
 
				this->GenerateBuildTrainList();
 
				this->eng_list.Compact();
 
				this->eng_list.RebuildDone();
 
				return; // trains should not reach the last sorting
 
			case VEH_ROAD:
 
				this->GenerateBuildRoadVehList();
 
				break;
 
			case VEH_SHIP:
 
				this->GenerateBuildShipList();
 
@@ -949,21 +951,24 @@ struct BuildVehicleWindow : Window {
 
			case VEH_AIRCRAFT:
 
				this->GenerateBuildAircraftList();
 
				break;
 
		}
 
		_internal_sort_order = this->descending_sort_order;
 
		EngList_Sort(&this->eng_list, _sorter[this->vehicle_type][this->sort_criteria]);
 

	
 
		this->eng_list.Compact();
 
		this->eng_list.RebuildDone();
 
	}
 

	
 
	void OnClick(Point pt, int widget)
 
	{
 
		switch (widget) {
 
			case BUILD_VEHICLE_WIDGET_SORT_ASSENDING_DESCENDING:
 
				this->descending_sort_order ^= true;
 
				_last_sort_order[this->vehicle_type] = this->descending_sort_order;
 
				this->regenerate_list = true;
 
				this->eng_list.ForceRebuild();
 
				this->SetDirty();
 
				break;
 

	
 
			case BUILD_VEHICLE_WIDGET_LIST: {
 
				uint i = (pt.y - this->widget[BUILD_VEHICLE_WIDGET_LIST].top) / GetVehicleListHeight(this->vehicle_type) + this->vscroll.pos;
 
				size_t num_items = this->eng_list.Length();
 
@@ -1020,21 +1025,18 @@ struct BuildVehicleWindow : Window {
 
			}
 
		}
 
	}
 

	
 
	virtual void OnInvalidateData(int data)
 
	{
 
		this->regenerate_list = true;
 
		this->eng_list.ForceRebuild();
 
	}
 

	
 
	virtual void OnPaint()
 
	{
 
		if (this->regenerate_list) {
 
			this->regenerate_list = false;
 
			this->GenerateBuildList();
 
		}
 
		this->GenerateBuildList();
 

	
 
		uint max = min(this->vscroll.pos + this->vscroll.cap, this->eng_list.Length());
 

	
 
		SetVScrollCount(this, this->eng_list.Length());
 
		if (this->vehicle_type == VEH_TRAIN) {
 
			if (this->filter.railtype == RAILTYPE_END) {
 
@@ -1091,13 +1093,13 @@ struct BuildVehicleWindow : Window {
 

	
 
	virtual void OnDropdownSelect(int widget, int index)
 
	{
 
		if (this->sort_criteria != index) {
 
			this->sort_criteria = index;
 
			_last_sort_criteria[this->vehicle_type] = this->sort_criteria;
 
			this->regenerate_list = true;
 
			this->eng_list.ForceRebuild();
 
		}
 
		this->SetDirty();
 
	}
 

	
 
	virtual void OnResize(Point delta)
 
	{
0 comments (0 inline, 0 general)