Changeset - r15063:8f5c4afdb886
[Not reviewed]
master
0 2 0
terkhen - 14 years ago 2010-04-23 17:29:53
terkhen@openttd.org
(svn r19699) -Codechange: Use InvalidateData at the refit window.
2 files changed with 21 insertions and 22 deletions:
0 comments (0 inline, 0 general)
src/train_cmd.cpp
Show inline comments
 
@@ -263,12 +263,13 @@ void Train::ConsistChanged(bool same_len
 
	/* recalculate cached weights and power too (we do this *after* the rest, so it is known which wagons are powered and need extra weight added) */
 
	this->CargoChanged();
 

	
 
	if (this->IsFrontEngine()) {
 
		this->UpdateAcceleration();
 
		SetWindowDirty(WC_VEHICLE_DETAILS, this->index);
 
		InvalidateWindowData(WC_VEHICLE_REFIT, this->index);
 
	}
 
}
 

	
 
/**
 
 * Get the stop location of (the center) of the front vehicle of a train at
 
 * a platform of a station.
 
@@ -1141,13 +1142,13 @@ static void NormaliseTrainHead(Train *he
 
	UpdateTrainGroupID(head);
 

	
 
	/* Not a front engine, i.e. a free wagon chain. No need to do more. */
 
	if (!head->IsFrontEngine()) return;
 

	
 
	/* Update the refit button and window */
 
	SetWindowDirty(WC_VEHICLE_REFIT, head->index);
 
	InvalidateWindowData(WC_VEHICLE_REFIT, head->index);
 
	SetWindowWidgetDirty(WC_VEHICLE_VIEW, head->index, VVW_WIDGET_REFIT_VEH);
 

	
 
	/* If we don't have a unit number yet, set one. */
 
	if (head->unitnumber != 0) return;
 
	head->unitnumber = GetFreeUnitNumber(VEH_TRAIN);
 
}
src/vehicle_gui.cpp
Show inline comments
 
@@ -359,13 +359,12 @@ enum VehicleRefitWidgets {
 

	
 
/** Refit cargo window. */
 
struct RefitWindow : public Window {
 
	int sel;              ///< Index in refit options, \c -1 if nothing is selected.
 
	RefitOption *cargo;   ///< Refit option selected by \v sel.
 
	RefitList list;       ///< List of cargo types available for refitting.
 
	uint length;          ///< For trains, the number of vehicles.
 
	VehicleOrderID order; ///< If not #INVALID_VEH_ORDER_ID, selection is part of a refit order (rather than execute directly).
 

	
 
	RefitWindow(const WindowDesc *desc, const Vehicle *v, VehicleOrderID order) : Window()
 
	{
 
		this->CreateNestedTree(desc);
 

	
 
@@ -378,13 +377,12 @@ struct RefitWindow : public Window {
 
		this->FinishInitNested(desc, v->index);
 
		this->owner = v->owner;
 

	
 
		this->order = order;
 
		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) {
 
@@ -406,34 +404,18 @@ struct RefitWindow : public Window {
 
			}
 

	
 
			/* 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());
 
			this->OnInvalidateData(0);
 
		}
 
	}
 

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

	
 
		if (v->type == VEH_TRAIN) {
 
			uint length = CountVehiclesInChain(v);
 

	
 
			if (length != this->length) {
 
				/* Consist length has changed, so rebuild the refit list */
 
				BuildRefitList(v, &this->list);
 
				this->length = length;
 
			}
 
		}
 

	
 
		this->vscroll.SetCount(this->list.Length());
 

	
 
		this->cargo = (this->sel >= 0 && this->sel < (int)this->list.Length()) ? &this->list[this->sel] : NULL;
 
		this->DrawWidgets();
 
	}
 

	
 
	virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
 
	{
 
		switch (widget) {
 
@@ -469,22 +451,38 @@ struct RefitWindow : public Window {
 
					}
 
				}
 
				break;
 
		}
 
	}
 

	
 
	virtual void OnInvalidateData(int data)
 
	{
 
		switch (data) {
 
			case 0: { // The consist lenght of the vehicle has changed; rebuild the entire list.
 
				Vehicle *v = Vehicle::Get(this->window_number);
 
				BuildRefitList(v, &this->list);
 
				this->vscroll.SetCount(this->list.Length());
 
			}
 
			/* FALLTHROUGH */
 

	
 
			case 1: // A new cargo has been selected.
 
				this->cargo = (this->sel >= 0 && this->sel < (int)this->list.Length()) ? &this->list[this->sel] : NULL;
 
				break;
 
		}
 
	}
 

	
 
	virtual void OnClick(Point pt, int widget, int click_count)
 
	{
 
		switch (widget) {
 
			case VRW_MATRIX: { // listbox
 
				int y = pt.y - this->GetWidget<NWidgetBase>(VRW_MATRIX)->pos_y;
 
				if (y >= 0) {
 
					this->sel = (y / (int)this->resize.step_height) + this->vscroll.GetPosition();
 
					this->SetDirty();
 
					this->InvalidateData(1);
 
				}
 
				/* FIXME We need to call some InvalidateData to make this->cargo valid */
 

	
 
				if (click_count == 1) break;
 
			}
 
			/* FALL THROUGH */
 
			case VRW_REFITBUTTON: // refit button
 
				if (this->cargo != NULL) {
 
					const Vehicle *v = Vehicle::Get(this->window_number);
0 comments (0 inline, 0 general)