Fix asserts due to main window not existing yet
Partial revert of https://github.com/OpenTTD/OpenTTD/pull/10327
This commit is contained in:
@@ -338,7 +338,9 @@ void GenerateWorld(GenWorldMode mode, uint size_x, uint size_y, bool reset_setti
|
|||||||
ShowGenerateWorldProgress();
|
ShowGenerateWorldProgress();
|
||||||
|
|
||||||
/* Centre the view on the map */
|
/* Centre the view on the map */
|
||||||
ScrollMainWindowToTile(TileXY(MapSizeX() / 2, MapSizeY() / 2), true);
|
if (FindWindowById(WC_MAIN_WINDOW, 0) != nullptr) {
|
||||||
|
ScrollMainWindowToTile(TileXY(MapSizeX() / 2, MapSizeY() / 2), true);
|
||||||
|
}
|
||||||
|
|
||||||
_GenerateWorld();
|
_GenerateWorld();
|
||||||
}
|
}
|
||||||
|
@@ -36,11 +36,13 @@ ZoomLevel _saved_scrollpos_zoom;
|
|||||||
|
|
||||||
void SaveViewportBeforeSaveGame()
|
void SaveViewportBeforeSaveGame()
|
||||||
{
|
{
|
||||||
const Window *w = GetMainWindow();
|
const Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
|
||||||
|
|
||||||
_saved_scrollpos_x = w->viewport->scrollpos_x;
|
if (w != nullptr) {
|
||||||
_saved_scrollpos_y = w->viewport->scrollpos_y;
|
_saved_scrollpos_x = w->viewport->scrollpos_x;
|
||||||
_saved_scrollpos_zoom = w->viewport->zoom;
|
_saved_scrollpos_y = w->viewport->scrollpos_y;
|
||||||
|
_saved_scrollpos_zoom = w->viewport->zoom;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResetViewportAfterLoadGame()
|
void ResetViewportAfterLoadGame()
|
||||||
|
@@ -2196,7 +2196,8 @@ struct MainToolbarWindow : Window {
|
|||||||
void OnInvalidateData(int data = 0, bool gui_scope = true) override
|
void OnInvalidateData(int data = 0, bool gui_scope = true) override
|
||||||
{
|
{
|
||||||
if (!gui_scope) return;
|
if (!gui_scope) return;
|
||||||
HandleZoomMessage(this, GetMainWindow()->viewport, WID_TN_ZOOM_IN, WID_TN_ZOOM_OUT);
|
Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
|
||||||
|
if (w != nullptr) HandleZoomMessage(this, w->viewport, WID_TN_ZOOM_IN, WID_TN_ZOOM_OUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
static HotkeyList hotkeys;
|
static HotkeyList hotkeys;
|
||||||
@@ -2577,7 +2578,8 @@ struct ScenarioEditorToolbarWindow : Window {
|
|||||||
void OnInvalidateData(int data = 0, bool gui_scope = true) override
|
void OnInvalidateData(int data = 0, bool gui_scope = true) override
|
||||||
{
|
{
|
||||||
if (!gui_scope) return;
|
if (!gui_scope) return;
|
||||||
HandleZoomMessage(this, GetMainWindow()->viewport, WID_TE_ZOOM_IN, WID_TE_ZOOM_OUT);
|
Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
|
||||||
|
if (w != nullptr) HandleZoomMessage(this, w->viewport, WID_TE_ZOOM_IN, WID_TE_ZOOM_OUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnQueryTextFinished(char *str) override
|
void OnQueryTextFinished(char *str) override
|
||||||
|
@@ -4185,8 +4185,8 @@ bool VehicleClicked(const GUIVehicleGroup &vehgroup)
|
|||||||
|
|
||||||
void StopGlobalFollowVehicle(const Vehicle *v)
|
void StopGlobalFollowVehicle(const Vehicle *v)
|
||||||
{
|
{
|
||||||
Window *w = GetMainWindow();
|
Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
|
||||||
if (w->viewport->follow_vehicle == v->index) {
|
if (w != nullptr && w->viewport->follow_vehicle == v->index) {
|
||||||
ScrollMainWindowTo(v->x_pos, v->y_pos, v->z_pos, true); // lock the main view on the vehicle's last position
|
ScrollMainWindowTo(v->x_pos, v->y_pos, v->z_pos, true); // lock the main view on the vehicle's last position
|
||||||
w->viewport->follow_vehicle = INVALID_VEHICLE;
|
w->viewport->follow_vehicle = INVALID_VEHICLE;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user