diff --git a/src/main_gui.cpp b/src/main_gui.cpp index 113ce8a864..9b987dcaf1 100644 --- a/src/main_gui.cpp +++ b/src/main_gui.cpp @@ -338,7 +338,7 @@ struct MainWindow : Window break; } - case GHK_RESET_OBJECT_TO_PLACE: ResetObjectToPlace(); break; + case GHK_RESET_OBJECT_TO_PLACE: ResetObjectToPlace(); ToolbarSelectLastTool(); break; case GHK_DELETE_WINDOWS: DeleteNonVitalWindows(); break; case GHK_DELETE_NONVITAL_WINDOWS: DeleteAllNonVitalWindows(); break; case GHK_REFRESH_SCREEN: MarkWholeScreenDirty(); break; diff --git a/src/road_gui.cpp b/src/road_gui.cpp index 8058ed5668..13851e1027 100644 --- a/src/road_gui.cpp +++ b/src/road_gui.cpp @@ -534,6 +534,16 @@ struct BuildRoadToolbarWindow : Window { DeleteWindowByClass(WC_BUILD_BRIDGE); } + virtual void SelectLastTool() + { + // User misplaced something - activate last selected tool again + if (this->last_started_action == WIDGET_LIST_END) + return; + Point dummy = {0, 0}; + this->RaiseWidget(this->last_started_action); + this->OnClick(dummy, this->last_started_action, 0); + } + virtual void OnPlaceDrag(ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt) { /* Here we update the end tile flags diff --git a/src/video/sdl_v.cpp b/src/video/sdl_v.cpp index e70006058b..1cabec456c 100644 --- a/src/video/sdl_v.cpp +++ b/src/video/sdl_v.cpp @@ -621,6 +621,7 @@ int VideoDriver_SDL::PollEvent() // Two-finger click - hacky way to determine if the right mouse button is already pressed without processing the left button event // Cancel whatewer action we were doing, to allow two finger scrolling ResetObjectToPlace(); + SelectLastTool(); } #endif } else if (ev.button.button == SDL_BUTTON_RIGHT) { diff --git a/src/viewport.cpp b/src/viewport.cpp index de4577d962..ade73e3a85 100644 --- a/src/viewport.cpp +++ b/src/viewport.cpp @@ -2941,6 +2941,9 @@ void SetObjectToPlaceWnd(CursorID icon, PaletteID pal, HighLightStyle mode, Wind #include "table/animcursors.h" +static WindowClass _last_selected_window_class; +static WindowNumber _last_selected_window_number; + void SetObjectToPlace(CursorID icon, PaletteID pal, HighLightStyle mode, WindowClass window_class, WindowNumber window_num) { if (_thd.window_class != WC_INVALID) { @@ -2987,9 +2990,20 @@ void SetObjectToPlace(CursorID icon, PaletteID pal, HighLightStyle mode, WindowC void ResetObjectToPlace() { + if (_thd.window_class != WC_INVALID) { + _last_selected_window_class = _thd.window_class; + _last_selected_window_number = _thd.window_number; + } SetObjectToPlace(SPR_CURSOR_MOUSE, PAL_NONE, HT_NONE, WC_MAIN_WINDOW, 0); } +void ToolbarSelectLastTool() +{ + Window *w = FindWindowById(_last_selected_window_class, _last_selected_window_number); + if (w != NULL) w->SelectLastTool(); + _last_selected_window_class = WC_INVALID; +} + Point GetViewportStationMiddle(const ViewPort *vp, const Station *st) { int x = TileX(st->xy) * TILE_SIZE; diff --git a/src/viewport_func.h b/src/viewport_func.h index baa06e48ca..7250c6fa37 100644 --- a/src/viewport_func.h +++ b/src/viewport_func.h @@ -82,4 +82,6 @@ void MarkTileDirtyByTile(TileIndex tile); Point GetViewportStationMiddle(const ViewPort *vp, const Station *st); +void ToolbarSelectLastTool(); + #endif /* VIEWPORT_FUNC_H */ diff --git a/src/window_gui.h b/src/window_gui.h index e03912b12d..a92b0be869 100644 --- a/src/window_gui.h +++ b/src/window_gui.h @@ -747,6 +747,10 @@ public: */ virtual void OnPlaceObjectAbort() {} + /** + * Select the cancelled tool again, this is called after OnPlaceObjectAbort() + */ + virtual void SelectLastTool() {} /** * The user is dragging over the map when the tile highlight mode