mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-09 23:50:25 +00:00
(svn r13104) -Codechange: make ResetObjectToPlace safe to be called recursively via the OnPlaceObjectAbort callback and use this knowledge to simplify closing some windows.
This commit is contained in:
parent
8fff6e8638
commit
5ae795953a
@ -102,9 +102,7 @@ static void BuildAirToolbWndProc(Window *w, WindowEvent *e)
|
||||
case WE_ABORT_PLACE_OBJ:
|
||||
w->RaiseButtons();
|
||||
|
||||
w = FindWindowById(WC_BUILD_STATION, 0);
|
||||
if (w != 0)
|
||||
WP(w, def_d).close = true;
|
||||
delete FindWindowById(WC_BUILD_STATION, 0);
|
||||
break;
|
||||
|
||||
case WE_DESTROY:
|
||||
@ -171,8 +169,6 @@ static void BuildAirportPickerWndProc(Window *w, WindowEvent *e)
|
||||
uint32 avail_airports;
|
||||
const AirportFTAClass *airport;
|
||||
|
||||
if (WP(w, def_d).close) return;
|
||||
|
||||
avail_airports = GetValidAirports();
|
||||
|
||||
w->RaiseWidget(_selected_airport_type + BAW_SMALL_AIRPORT);
|
||||
@ -230,17 +226,12 @@ static void BuildAirportPickerWndProc(Window *w, WindowEvent *e)
|
||||
}
|
||||
} break;
|
||||
|
||||
case WE_TICK: {
|
||||
if (WP(w, def_d).close) {
|
||||
delete w;
|
||||
return;
|
||||
}
|
||||
|
||||
case WE_TICK:
|
||||
CheckRedrawStationCoverage(w);
|
||||
} break;
|
||||
break;
|
||||
|
||||
case WE_DESTROY:
|
||||
if (!WP(w, def_d).close) ResetObjectToPlace();
|
||||
ResetObjectToPlace();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -175,11 +175,8 @@ static void BuildDocksToolbWndProc(Window *w, WindowEvent *e)
|
||||
case WE_ABORT_PLACE_OBJ:
|
||||
w->RaiseButtons();
|
||||
|
||||
w = FindWindowById(WC_BUILD_STATION, 0);
|
||||
if (w != NULL) WP(w, def_d).close = true;
|
||||
|
||||
w = FindWindowById(WC_BUILD_DEPOT, 0);
|
||||
if (w != NULL) WP(w, def_d).close = true;
|
||||
delete FindWindowById(WC_BUILD_STATION, 0);
|
||||
delete FindWindowById(WC_BUILD_DEPOT, 0);
|
||||
break;
|
||||
|
||||
case WE_PLACE_PRESIZE: {
|
||||
@ -241,7 +238,6 @@ static void BuildDockStationWndProc(Window *w, WindowEvent *e)
|
||||
case WE_PAINT: {
|
||||
int rad = (_patches.modified_catchment) ? CA_DOCK : CA_UNMODIFIED;
|
||||
|
||||
if (WP(w, def_d).close) return;
|
||||
DrawWindowWidgets(w);
|
||||
|
||||
if (_station_show_coverage) {
|
||||
@ -275,16 +271,11 @@ static void BuildDockStationWndProc(Window *w, WindowEvent *e)
|
||||
break;
|
||||
|
||||
case WE_TICK:
|
||||
if (WP(w, def_d).close) {
|
||||
delete w;
|
||||
return;
|
||||
}
|
||||
|
||||
CheckRedrawStationCoverage(w);
|
||||
break;
|
||||
|
||||
case WE_DESTROY:
|
||||
if (!WP(w, def_d).close) ResetObjectToPlace();
|
||||
ResetObjectToPlace();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -349,12 +340,8 @@ static void BuildDocksDepotWndProc(Window *w, WindowEvent *e)
|
||||
}
|
||||
} break;
|
||||
|
||||
case WE_TICK:
|
||||
if (WP(w, def_d).close) delete w;
|
||||
break;
|
||||
|
||||
case WE_DESTROY:
|
||||
if (!WP(w, def_d).close) ResetObjectToPlace();
|
||||
ResetObjectToPlace();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -653,12 +653,9 @@ static void BuildRailToolbWndProc(Window *w, WindowEvent *e)
|
||||
w->DisableWidget(RTW_REMOVE);
|
||||
w->InvalidateWidget(RTW_REMOVE);
|
||||
|
||||
w = FindWindowById(WC_BUILD_SIGNAL, 0);
|
||||
if (w != NULL) WP(w, def_d).close = true;
|
||||
w = FindWindowById(WC_BUILD_STATION, 0);
|
||||
if (w != NULL) WP(w, def_d).close = true;
|
||||
w = FindWindowById(WC_BUILD_DEPOT, 0);
|
||||
if (w != NULL) WP(w, def_d).close = true;
|
||||
delete FindWindowById(WC_BUILD_SIGNAL, 0);
|
||||
delete FindWindowById(WC_BUILD_STATION, 0);
|
||||
delete FindWindowById(WC_BUILD_DEPOT, 0);
|
||||
break;
|
||||
|
||||
case WE_PLACE_PRESIZE: {
|
||||
@ -875,8 +872,6 @@ static void StationBuildWndProc(Window *w, WindowEvent *e)
|
||||
DrawPixelInfo tmp_dpi, *old_dpi;
|
||||
const StationSpec *statspec = newstations ? GetCustomStationSpec(_railstation.station_class, _railstation.station_type) : NULL;
|
||||
|
||||
if (WP(w, def_d).close) return;
|
||||
|
||||
if (_railstation.dragdrop) {
|
||||
SetTileSelectSize(1, 1);
|
||||
} else {
|
||||
@ -1123,15 +1118,11 @@ static void StationBuildWndProc(Window *w, WindowEvent *e)
|
||||
break;
|
||||
|
||||
case WE_TICK:
|
||||
if (WP(w, def_d).close) {
|
||||
delete w;
|
||||
return;
|
||||
}
|
||||
CheckRedrawStationCoverage(w);
|
||||
break;
|
||||
|
||||
case WE_DESTROY:
|
||||
if (!WP(w, def_d).close) ResetObjectToPlace();
|
||||
ResetObjectToPlace();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -1345,12 +1336,8 @@ static void SignalBuildWndProc(Window *w, WindowEvent *e)
|
||||
w->SetDirty();
|
||||
break;
|
||||
|
||||
case WE_TICK:
|
||||
if (WP(w, def_d).close) delete w;
|
||||
return;
|
||||
|
||||
case WE_DESTROY:
|
||||
if (!WP(w, def_d).close) ResetObjectToPlace();
|
||||
ResetObjectToPlace();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -1436,12 +1423,8 @@ static void BuildTrainDepotWndProc(Window *w, WindowEvent *e)
|
||||
}
|
||||
break;
|
||||
|
||||
case WE_TICK:
|
||||
if (WP(w, def_d).close) delete w;
|
||||
return;
|
||||
|
||||
case WE_DESTROY:
|
||||
if (!WP(w, def_d).close) ResetObjectToPlace();
|
||||
ResetObjectToPlace();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -1535,12 +1518,8 @@ static void BuildWaypointWndProc(Window *w, WindowEvent *e)
|
||||
break;
|
||||
}
|
||||
|
||||
case WE_TICK:
|
||||
if (WP(w, def_d).close) delete w;
|
||||
break;
|
||||
|
||||
case WE_DESTROY:
|
||||
if (!WP(w, def_d).close) ResetObjectToPlace();
|
||||
ResetObjectToPlace();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -511,12 +511,9 @@ static void BuildRoadToolbWndProc(Window *w, WindowEvent *e)
|
||||
w->InvalidateWidget(RTW_REMOVE);
|
||||
w->InvalidateWidget(RTW_ONE_WAY);
|
||||
|
||||
w = FindWindowById(WC_BUS_STATION, 0);
|
||||
if (w != NULL) WP(w, def_d).close = true;
|
||||
w = FindWindowById(WC_TRUCK_STATION, 0);
|
||||
if (w != NULL) WP(w, def_d).close = true;
|
||||
w = FindWindowById(WC_BUILD_DEPOT, 0);
|
||||
if (w != NULL) WP(w, def_d).close = true;
|
||||
delete FindWindowById(WC_BUS_STATION, 0);
|
||||
delete FindWindowById(WC_TRUCK_STATION, 0);
|
||||
delete FindWindowById(WC_BUILD_DEPOT, 0);
|
||||
break;
|
||||
|
||||
case WE_PLACE_DRAG:
|
||||
@ -762,12 +759,8 @@ static void BuildRoadDepotWndProc(Window *w, WindowEvent *e)
|
||||
}
|
||||
break;
|
||||
|
||||
case WE_TICK:
|
||||
if (WP(w, def_d).close) delete w;
|
||||
break;
|
||||
|
||||
case WE_DESTROY:
|
||||
if (!WP(w, def_d).close) ResetObjectToPlace();
|
||||
ResetObjectToPlace();
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -856,8 +849,6 @@ static void RoadStationPickerWndProc(Window *w, WindowEvent *e)
|
||||
break;
|
||||
|
||||
case WE_PAINT: {
|
||||
if (WP(w, def_d).close) return;
|
||||
|
||||
DrawWindowWidgets(w);
|
||||
|
||||
if (_station_show_coverage) {
|
||||
@ -920,16 +911,11 @@ static void RoadStationPickerWndProc(Window *w, WindowEvent *e)
|
||||
break;
|
||||
|
||||
case WE_TICK:
|
||||
if (WP(w, def_d).close) {
|
||||
delete w;
|
||||
return;
|
||||
}
|
||||
|
||||
CheckRedrawStationCoverage(w);
|
||||
break;
|
||||
|
||||
case WE_DESTROY:
|
||||
if (!WP(w, def_d).close) ResetObjectToPlace();
|
||||
ResetObjectToPlace();
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -2708,12 +2708,11 @@ void SetObjectToPlaceWnd(CursorID icon, SpriteID pal, ViewportHighlightMode mode
|
||||
|
||||
void SetObjectToPlace(CursorID icon, SpriteID pal, ViewportHighlightMode mode, WindowClass window_class, WindowNumber window_num)
|
||||
{
|
||||
Window *w;
|
||||
Window *w = NULL;
|
||||
|
||||
/* undo clicking on button and drag & drop */
|
||||
if (_thd.place_mode != VHM_NONE || _special_mouse_mode == WSM_DRAGDROP) {
|
||||
w = FindWindowById(_thd.window_class, _thd.window_number);
|
||||
if (w != NULL) w->OnPlaceObjectAbort();
|
||||
}
|
||||
|
||||
SetTileSelectSize(1, 1);
|
||||
@ -2734,10 +2733,16 @@ void SetObjectToPlace(CursorID icon, SpriteID pal, ViewportHighlightMode mode, W
|
||||
if (mode == VHM_SPECIAL) // special tools, like tunnels or docks start with presizing mode
|
||||
VpStartPreSizing();
|
||||
|
||||
if ( (int)icon < 0)
|
||||
if ((int)icon < 0) {
|
||||
SetAnimatedMouseCursor(_animcursors[~icon]);
|
||||
else
|
||||
} else {
|
||||
SetMouseCursor(icon, pal);
|
||||
}
|
||||
|
||||
/* Call the abort function only *after* the window class/number
|
||||
* are reset so one doesn't get into infinite loops when someone
|
||||
* resets the object to place during the abort callback. */
|
||||
if (w != NULL) w->OnPlaceObjectAbort();
|
||||
}
|
||||
|
||||
void ResetObjectToPlace()
|
||||
|
@ -527,7 +527,6 @@ struct menu_d {
|
||||
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(menu_d));
|
||||
|
||||
struct def_d {
|
||||
bool close;
|
||||
int16 data_1, data_2, data_3;
|
||||
};
|
||||
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(def_d));
|
||||
|
Loading…
Reference in New Issue
Block a user