1
0
Fork 0

(svn r22244) -Codechange: Make vehicle windows handle command-/GUI-scope invalidations themself (from autoreplace and refitting).

release/1.2
frosch 2011-03-13 21:33:02 +00:00
parent 0ff4f31723
commit f051a81b4e
4 changed files with 14 additions and 22 deletions

View File

@ -812,7 +812,6 @@ public:
*/ */
virtual void OnInvalidateData(int data = 0, bool gui_scope = true) virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{ {
if (!gui_scope) return;
VehicleOrderID from = INVALID_VEH_ORDER_ID; VehicleOrderID from = INVALID_VEH_ORDER_ID;
VehicleOrderID to = INVALID_VEH_ORDER_ID; VehicleOrderID to = INVALID_VEH_ORDER_ID;
@ -820,7 +819,6 @@ public:
case -666: case -666:
/* Autoreplace replaced the vehicle */ /* Autoreplace replaced the vehicle */
this->vehicle = Vehicle::Get(this->window_number); this->vehicle = Vehicle::Get(this->window_number);
/* This case is _not_ called asynchronously. Get out directly, rest can be done later */
break; break;
case -1: case -1:
@ -837,6 +835,7 @@ public:
break; break;
default: default:
if (!gui_scope) break;
if (data < 0) break; if (data < 0) break;
from = GB(data, 0, 8); from = GB(data, 0, 8);
to = GB(data, 8, 8); to = GB(data, 8, 8);
@ -869,7 +868,7 @@ public:
} }
this->vscroll->SetCount(this->vehicle->GetNumOrders() + 1); this->vscroll->SetCount(this->vehicle->GetNumOrders() + 1);
this->UpdateButtonState(); if (gui_scope) this->UpdateButtonState();
/* Scroll to the new order. */ /* Scroll to the new order. */
if (from == INVALID_VEH_ORDER_ID && to != INVALID_VEH_ORDER_ID && !this->vscroll->IsVisible(to)) { if (from == INVALID_VEH_ORDER_ID && to != INVALID_VEH_ORDER_ID && !this->vscroll->IsVisible(to)) {

View File

@ -250,12 +250,10 @@ struct TimetableWindow : Window {
*/ */
virtual void OnInvalidateData(int data = 0, bool gui_scope = true) virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{ {
if (!gui_scope) return;
switch (data) { switch (data) {
case -666: case -666:
/* Autoreplace replaced the vehicle */ /* Autoreplace replaced the vehicle */
this->vehicle = Vehicle::Get(this->window_number); this->vehicle = Vehicle::Get(this->window_number);
/* This case is _not_ called asynchronously. Get out directly, rest can be done later */
break; break;
case -1: case -1:
@ -267,11 +265,13 @@ struct TimetableWindow : Window {
break; break;
case -2: case -2:
if (!gui_scope) break;
this->UpdateSelectionStates(); this->UpdateSelectionStates();
this->ReInit(); this->ReInit();
break; break;
default: { default: {
if (!gui_scope) break;
/* Moving an order. If one of these is INVALID_VEH_ORDER_ID, then /* Moving an order. If one of these is INVALID_VEH_ORDER_ID, then
* the order is being created / removed */ * the order is being created / removed */
if (this->sel_index == -1) break; if (this->sel_index == -1) break;

View File

@ -264,7 +264,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); // Important, do not invalidate immediately. The refit window tests commands. InvalidateWindowData(WC_VEHICLE_REFIT, this->index);
} }
} }
@ -1092,7 +1092,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 */
InvalidateWindowData(WC_VEHICLE_REFIT, head->index); // Important, do not invalidate immediately. The refit window tests commands. 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. */

View File

@ -690,14 +690,8 @@ struct RefitWindow : public Window {
*/ */
virtual void OnInvalidateData(int data = 0, bool gui_scope = true) virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{ {
if (!gui_scope) return;
switch (data) { switch (data) {
case -666: case -666: // Autoreplace replaced the vehicle; selected_vehicle became invalid.
/* Autoreplace replaced the vehicle.
* Nothing to do though for this window.
* This case is _not_ called asynchronously. Get out directly, rest can be done later */
break;
case 0: { // The consist has changed; rebuild the entire list. case 0: { // The consist has changed; rebuild the entire list.
/* Clear the selection. */ /* Clear the selection. */
Vehicle *v = Vehicle::Get(this->window_number); Vehicle *v = Vehicle::Get(this->window_number);
@ -707,6 +701,7 @@ struct RefitWindow : public Window {
} }
case 2: { // The vehicle selection has changed; rebuild the entire list. case 2: { // The vehicle selection has changed; rebuild the entire list.
if (!gui_scope) break;
this->BuildRefitList(); this->BuildRefitList();
/* The vehicle width has changed too. */ /* The vehicle width has changed too. */
@ -732,6 +727,7 @@ struct RefitWindow : public Window {
} }
case 1: // A new cargo has been selected. case 1: // A new cargo has been selected.
if (!gui_scope) break;
this->cargo = GetRefitOption(); this->cargo = GetRefitOption();
break; break;
} }
@ -1132,8 +1128,8 @@ static inline void ChangeVehicleWindow(WindowClass window_class, VehicleID from_
_thd.window_number = to_index; _thd.window_number = to_index;
} }
/* Notify the window immediately, without scheduling. */ /* Notify the window. */
w->InvalidateData(-666); w->InvalidateData(-666, false);
} }
} }
@ -1806,13 +1802,12 @@ struct VehicleDetailsWindow : Window {
*/ */
virtual void OnInvalidateData(int data = 0, bool gui_scope = true) virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{ {
if (!gui_scope) return;
if (data == -666) { if (data == -666) {
/* Autoreplace replaced the vehicle. /* Autoreplace replaced the vehicle.
* Nothing to do for this window though. * Nothing to do for this window. */
* This case is _not_ called asynchronously. Get out directly, rest can be done later */
return; return;
} }
if (!gui_scope) return;
const Vehicle *v = Vehicle::Get(this->window_number); const Vehicle *v = Vehicle::Get(this->window_number);
if (v->type == VEH_ROAD) { if (v->type == VEH_ROAD) {
const NWidgetBase *nwid_info = this->GetWidget<NWidgetBase>(VLD_WIDGET_MIDDLE_DETAILS); const NWidgetBase *nwid_info = this->GetWidget<NWidgetBase>(VLD_WIDGET_MIDDLE_DETAILS);
@ -2621,11 +2616,9 @@ public:
*/ */
virtual void OnInvalidateData(int data = 0, bool gui_scope = true) virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
{ {
if (!gui_scope) return;
if (data == -666) { if (data == -666) {
/* Autoreplace replaced the vehicle. /* Autoreplace replaced the vehicle.
* Nothing to do for this window though. * Nothing to do for this window. */
* This case is _not_ called asynchronously. Get out directly, rest can be done later */
return; return;
} }
} }