File diff r13023:9f6499c8d4fb → r13024:48c81d0b078a
src/bridge_gui.cpp
Show inline comments
 
@@ -76,98 +76,98 @@ private:
 
	static const StringID sorter_names[];
 
	static GUIBridgeList::SortFunction * const sorter_funcs[];
 

	
 
	/* Internal variables */
 
	TileIndex start_tile;
 
	TileIndex end_tile;
 
	uint32 type;
 
	GUIBridgeList *bridges;
 
	int bridgetext_offset; ///< Horizontal offset of the text describing the bridge properties in #BBSW_BRIDGE_LIST relative to the left edge.
 

	
 
	/** Sort the bridges by their index */
 
	static int CDECL BridgeIndexSorter(const BuildBridgeData *a, const BuildBridgeData *b)
 
	{
 
		return a->index - b->index;
 
	}
 

	
 
	/** Sort the bridges by their price */
 
	static int CDECL BridgePriceSorter(const BuildBridgeData *a, const BuildBridgeData *b)
 
	{
 
		return a->cost - b->cost;
 
	}
 

	
 
	/** Sort the bridges by their maximum speed */
 
	static int CDECL BridgeSpeedSorter(const BuildBridgeData *a, const BuildBridgeData *b)
 
	{
 
		return a->spec->speed - b->spec->speed;
 
	}
 

	
 
	void BuildBridge(uint8 i)
 
	{
 
		switch ((TransportType)(this->type >> 15)) {
 
			case TRANSPORT_RAIL: _last_railbridge_type = this->bridges->Get(i)->index; break;
 
			case TRANSPORT_ROAD: _last_roadbridge_type = this->bridges->Get(i)->index; break;
 
			default: break;
 
		}
 
		DoCommandP(this->end_tile, this->start_tile, this->type | this->bridges->Get(i)->index,
 
					CMD_BUILD_BRIDGE | CMD_MSG(STR_ERROR_CAN_T_BUILD_BRIDGE_HERE), CcBuildBridge);
 
	}
 

	
 
	/** Sort the builable bridges */
 
	void SortBridgeList()
 
	{
 
		this->bridges->Sort();
 

	
 
		/* Display the current sort variant */
 
		this->nested_array[BBSW_DROPDOWN_CRITERIA]->widget_data = this->sorter_names[this->bridges->SortType()];
 

	
 
		/* Set the modified widgets dirty */
 
		this->InvalidateWidget(BBSW_DROPDOWN_CRITERIA);
 
		this->InvalidateWidget(BBSW_BRIDGE_LIST);
 
		this->SetWidgetDirty(BBSW_DROPDOWN_CRITERIA);
 
		this->SetWidgetDirty(BBSW_BRIDGE_LIST);
 
	}
 

	
 
public:
 
	BuildBridgeWindow(const WindowDesc *desc, TileIndex start, TileIndex end, uint32 br_type, GUIBridgeList *bl) : Window(),
 
		start_tile(start),
 
		end_tile(end),
 
		type(br_type),
 
		bridges(bl)
 
	{
 
		this->CreateNestedTree(desc);
 
		/* Change the data, or the caption of the gui. Set it to road or rail, accordingly. */
 
		this->nested_array[BBSW_CAPTION]->widget_data = (GB(this->type, 15, 2) == TRANSPORT_ROAD) ? STR_SELECT_ROAD_BRIDGE_CAPTION : STR_SELECT_RAIL_BRIDGE_CAPTION;
 
		this->FinishInitNested(desc, GB(br_type, 15, 2)); // Initializes 'this->bridgetext_offset'.
 

	
 
		this->parent = FindWindowById(WC_BUILD_TOOLBAR, GB(this->type, 15, 2));
 
		this->bridges->SetListing(this->last_sorting);
 
		this->bridges->SetSortFuncs(this->sorter_funcs);
 
		this->bridges->NeedResort();
 
		this->SortBridgeList();
 

	
 
		this->vscroll.SetCount(bl->Length());
 
		this->vscroll.SetCapacity(this->nested_array[BBSW_BRIDGE_LIST]->current_y / this->resize.step_height);
 
		if (this->last_size < this->vscroll.GetCapacity()) this->last_size = this->vscroll.GetCapacity();
 
		if (this->last_size > this->vscroll.GetCount()) this->last_size = this->vscroll.GetCount();
 
		/* Resize the bridge selection window if we used a bigger one the last time. */
 
		if (this->last_size > this->vscroll.GetCapacity()) {
 
			ResizeWindow(this, 0, (this->last_size - this->vscroll.GetCapacity()) * this->resize.step_height);
 
			this->vscroll.SetCapacity(this->last_size);
 
		}
 
		this->nested_array[BBSW_BRIDGE_LIST]->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
 
	}
 

	
 
	~BuildBridgeWindow()
 
	{
 
		this->last_sorting = this->bridges->GetListing();
 

	
 
		delete bridges;
 
	}
 

	
 
	virtual void OnPaint()
 
	{
 
		this->DrawWidgets();
 
	}
 

	
 
	virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *resize)
 
	{
 
		switch (widget) {
 
			case BBSW_DROPDOWN_ORDER: {