Auto-select last used tool when user cancels build action, only for roads now

This commit is contained in:
pelya
2014-11-12 03:25:09 +02:00
parent 557da46dcb
commit fc39f895bc
6 changed files with 32 additions and 1 deletions

View File

@@ -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;

View File

@@ -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

View File

@@ -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) {

View File

@@ -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;

View File

@@ -82,4 +82,6 @@ void MarkTileDirtyByTile(TileIndex tile);
Point GetViewportStationMiddle(const ViewPort *vp, const Station *st);
void ToolbarSelectLastTool();
#endif /* VIEWPORT_FUNC_H */

View File

@@ -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