Changeset - r14928:db3712149038
[Not reviewed]
master
0 1 0
terkhen - 15 years ago 2010-04-02 12:28:08
terkhen@openttd.org
(svn r19541) -Feature: Sort the list of refit options by cargo class / name.
1 file changed with 35 insertions and 1 deletions:
0 comments (0 inline, 0 general)
src/vehicle_gui.cpp
Show inline comments
 
@@ -231,12 +231,17 @@ struct RefitOption {
 
	EngineID engine;  ///< Engine for which to resolve #value
 

	
 
	FORCEINLINE bool operator != (const RefitOption &other) const
 
	{
 
		return other.cargo != this->cargo || other.value != this->value;
 
	}
 

	
 
	FORCEINLINE bool operator == (const RefitOption &other) const
 
	{
 
		return other.cargo == this->cargo && other.value == this->value;
 
	}
 
};
 

	
 
typedef SmallVector<RefitOption, 32> RefitList;
 

	
 
/**
 
 * Collects all (cargo, subcargo) refit-options of a vehicle chain
 
@@ -255,13 +260,13 @@ static void BuildRefitList(const Vehicle
 

	
 
		/* Skip this engine if it does not carry anything */
 
		if (!e->CanCarryCargo()) continue;
 

	
 
		/* Loop through all cargos in the refit mask */
 
		const CargoSpec *cs;
 
		FOR_ALL_CARGOSPECS(cs) {
 
		FOR_ALL_SORTED_CARGOSPECS(cs) {
 
			CargoID cid = cs->Index();
 
			/* Skip cargo type if it's not listed */
 
			if (!HasBit(cmask, cid)) continue;
 

	
 
			/* Check the vehicle's callback mask for cargo suffixes */
 
			if (HasBit(callback_mask, CBM_VEHICLE_CARGO_SUFFIX)) {
 
@@ -377,12 +382,41 @@ struct RefitWindow : public Window {
 
		this->sel  = -1;
 
		BuildRefitList(v, &this->list);
 
		if (v->type == VEH_TRAIN) this->length = CountVehiclesInChain(v);
 
		this->vscroll.SetCount(this->list.Length());
 
	}
 

	
 
	virtual void OnInit()
 
	{
 
		if (this->cargo != NULL) {
 
			/* Store the RefitOption currently in use. */
 
			RefitOption current_refit_option = *(this->cargo);
 

	
 
			/* Rebuild the refit list */
 
			BuildRefitList(Vehicle::Get(this->window_number), &this->list);
 
			this->vscroll.SetCount(this->list.Length());
 
			this->sel = -1;
 
			this->cargo = NULL;
 
			for (uint i = 0; i < this->list.Length(); i++) {
 
				if (this->list[i] == current_refit_option) {
 
					this->sel = i;
 
					this->cargo = &this->list[i];
 
					this->vscroll.ScrollTowards(i);
 
					break;
 
				}
 
			}
 

	
 
			/* If the selected refit option was not found, scroll the window to the initial position. */
 
			if (this->sel == -1) this->vscroll.ScrollTowards(0);
 
		} else {
 
			/* Rebuild the refit list */
 
			BuildRefitList(Vehicle::Get(this->window_number), &this->list);
 
			this->vscroll.SetCount(this->list.Length());
 
		}
 
	}
 

	
 
	virtual void OnPaint()
 
	{
 
		Vehicle *v = Vehicle::Get(this->window_number);
 

	
 
		if (v->type == VEH_TRAIN) {
 
			uint length = CountVehiclesInChain(v);
0 comments (0 inline, 0 general)