Fix #13645: "Follow vehicle" button not raised when following stopped. (#13746)

This commit is contained in:
2025-03-06 00:00:57 +00:00
committed by GitHub
parent 47ae285c9d
commit 274b7a0195
4 changed files with 30 additions and 7 deletions

View File

@@ -94,6 +94,8 @@
#include <forward_list>
#include <stack>
#include "widgets/vehicle_widget.h"
#include "table/strings.h"
#include "table/string_colours.h"
@@ -2530,7 +2532,7 @@ bool ScrollWindowTo(int x, int y, int z, Window *w, bool instant)
}
Point pt = MapXYZToViewport(w->viewport, x, y, z);
w->viewport->follow_vehicle = VehicleID::Invalid();
w->viewport->CancelFollow(*w);
if (w->viewport->dest_scrollpos_x == pt.x && w->viewport->dest_scrollpos_y == pt.y) return false;
@@ -3717,3 +3719,21 @@ void SetViewportCatchmentTown(const Town *t, bool sel)
}
if (_viewport_highlight_town != nullptr) SetWindowDirty(WC_TOWN_VIEW, _viewport_highlight_town->index);
}
/**
* Cancel viewport vehicle following, and raise follow location widget if needed.
* @param viewport_window Window of this viewport.
*/
void ViewportData::CancelFollow(const Window &viewport_window)
{
if (this->follow_vehicle == VehicleID::Invalid()) return;
if (viewport_window.window_class == WC_MAIN_WINDOW) {
/* We're cancelling follow in the main viewport, so we need to check for a vehicle view window
* to raise the location follow widget. */
Window *vehicle_window = FindWindowById(WC_VEHICLE_VIEW, this->follow_vehicle);
if (vehicle_window != nullptr) vehicle_window->RaiseWidgetWhenLowered(WID_VV_LOCATION);
}
this->follow_vehicle = VehicleID::Invalid();
}