Merge branch 'master' into jgrpp

# Conflicts:
#	src/3rdparty/fmt/core.h
#	src/command_type.h
#	src/console_cmds.cpp
#	src/core/overflowsafe_type.hpp
#	src/landscape.cpp
#	src/network/network.cpp
#	src/newgrf_object.h
#	src/object_cmd.cpp
#	src/order_gui.cpp
#	src/saveload/vehicle_sl.cpp
#	src/script/api/script_industrytype.cpp
#	src/script/api/script_object.hpp
#	src/script/api/script_town.cpp
#	src/table/object_land.h
#	src/timetable_cmd.cpp
#	src/tree_cmd.cpp
#	src/vehicle_gui.cpp
#	src/window.cpp
This commit is contained in:
Jonathan G Rennison
2023-01-15 19:28:37 +00:00
64 changed files with 442 additions and 310 deletions

View File

@@ -1191,6 +1191,18 @@ Window *FindWindowByClass(WindowClass cls)
return nullptr;
}
/**
* Get the main window, i.e. FindWindowById(WC_MAIN_WINDOW, 0).
* If the main window is not available, this function will trigger an assert.
* @return Pointer to the main window.
*/
Window *GetMainWindow()
{
Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
assert(w != nullptr);
return w;
}
/**
* Delete a window by its class and window number (if it is open).
* @param cls Window class
@@ -2550,7 +2562,7 @@ static EventState HandleViewportScroll()
return ES_NOT_HANDLED;
}
if (_last_scroll_window == FindWindowById(WC_MAIN_WINDOW, 0) && _last_scroll_window->viewport->follow_vehicle != INVALID_VEHICLE) {
if (_last_scroll_window == GetMainWindow() && _last_scroll_window->viewport->follow_vehicle != INVALID_VEHICLE) {
/* If the main window is following a vehicle, then first let go of it! */
const Vehicle *veh = Vehicle::Get(_last_scroll_window->viewport->follow_vehicle);
ScrollMainWindowTo(veh->x_pos, veh->y_pos, veh->z_pos, true); // This also resets follow_vehicle
@@ -2922,7 +2934,7 @@ const std::chrono::milliseconds TIME_BETWEEN_DOUBLE_CLICK(500); ///< Time betwee
static void ScrollMainViewport(int x, int y)
{
if (_game_mode != GM_MENU && _game_mode != GM_BOOTSTRAP) {
Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
Window *w = GetMainWindow();
assert(w);
w->viewport->dest_scrollpos_x += ScaleByZoom(x, w->viewport->zoom);