mirror of https://github.com/OpenTTD/OpenTTD
(svn r19699) -Codechange: Use InvalidateData at the refit window.
parent
f642c01fb4
commit
d9dc4c04f4
|
@ -266,6 +266,7 @@ void Train::ConsistChanged(bool same_length)
|
||||||
if (this->IsFrontEngine()) {
|
if (this->IsFrontEngine()) {
|
||||||
this->UpdateAcceleration();
|
this->UpdateAcceleration();
|
||||||
SetWindowDirty(WC_VEHICLE_DETAILS, this->index);
|
SetWindowDirty(WC_VEHICLE_DETAILS, this->index);
|
||||||
|
InvalidateWindowData(WC_VEHICLE_REFIT, this->index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1144,7 +1145,7 @@ static void NormaliseTrainHead(Train *head)
|
||||||
if (!head->IsFrontEngine()) return;
|
if (!head->IsFrontEngine()) return;
|
||||||
|
|
||||||
/* Update the refit button and window */
|
/* 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);
|
SetWindowWidgetDirty(WC_VEHICLE_VIEW, head->index, VVW_WIDGET_REFIT_VEH);
|
||||||
|
|
||||||
/* If we don't have a unit number yet, set one. */
|
/* If we don't have a unit number yet, set one. */
|
||||||
|
|
|
@ -362,7 +362,6 @@ struct RefitWindow : public Window {
|
||||||
int sel; ///< Index in refit options, \c -1 if nothing is selected.
|
int sel; ///< Index in refit options, \c -1 if nothing is selected.
|
||||||
RefitOption *cargo; ///< Refit option selected by \v sel.
|
RefitOption *cargo; ///< Refit option selected by \v sel.
|
||||||
RefitList list; ///< List of cargo types available for refitting.
|
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).
|
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()
|
RefitWindow(const WindowDesc *desc, const Vehicle *v, VehicleOrderID order) : Window()
|
||||||
|
@ -381,7 +380,6 @@ struct RefitWindow : public Window {
|
||||||
this->order = order;
|
this->order = order;
|
||||||
this->sel = -1;
|
this->sel = -1;
|
||||||
BuildRefitList(v, &this->list);
|
BuildRefitList(v, &this->list);
|
||||||
if (v->type == VEH_TRAIN) this->length = CountVehiclesInChain(v);
|
|
||||||
this->vscroll.SetCount(this->list.Length());
|
this->vscroll.SetCount(this->list.Length());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -409,28 +407,12 @@ struct RefitWindow : public Window {
|
||||||
if (this->sel == -1) this->vscroll.ScrollTowards(0);
|
if (this->sel == -1) this->vscroll.ScrollTowards(0);
|
||||||
} else {
|
} else {
|
||||||
/* Rebuild the refit list */
|
/* Rebuild the refit list */
|
||||||
BuildRefitList(Vehicle::Get(this->window_number), &this->list);
|
this->OnInvalidateData(0);
|
||||||
this->vscroll.SetCount(this->list.Length());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void OnPaint()
|
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();
|
this->DrawWidgets();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -472,6 +454,22 @@ struct RefitWindow : public Window {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
virtual void OnClick(Point pt, int widget, int click_count)
|
||||||
{
|
{
|
||||||
switch (widget) {
|
switch (widget) {
|
||||||
|
@ -479,9 +477,9 @@ struct RefitWindow : public Window {
|
||||||
int y = pt.y - this->GetWidget<NWidgetBase>(VRW_MATRIX)->pos_y;
|
int y = pt.y - this->GetWidget<NWidgetBase>(VRW_MATRIX)->pos_y;
|
||||||
if (y >= 0) {
|
if (y >= 0) {
|
||||||
this->sel = (y / (int)this->resize.step_height) + this->vscroll.GetPosition();
|
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;
|
if (click_count == 1) break;
|
||||||
}
|
}
|
||||||
/* FALL THROUGH */
|
/* FALL THROUGH */
|
||||||
|
|
Loading…
Reference in New Issue