Codechange: introduce GetMainWindow() to properly account for nullptr checks

Some nullptr checks have been removed as they were not triggered with nullptr
with the null video driver and in dedicated server mode.
This commit is contained in:
Rubidium
2023-01-06 23:24:38 +01:00
committed by rubidium42
parent 9c70c38c5e
commit bcfe0fb076
16 changed files with 47 additions and 40 deletions

View File

@@ -3118,7 +3118,7 @@ public:
if (_ctrl_pressed) {
ShowExtraViewportWindow(TileVirtXY(v->x_pos, v->y_pos));
} else {
const Window *mainwindow = FindWindowById(WC_MAIN_WINDOW, 0);
const Window *mainwindow = GetMainWindow();
if (click_count > 1 && mainwindow->viewport->zoom <= ZOOM_LVL_OUT_4X) {
/* main window 'follows' vehicle */
mainwindow->viewport->follow_vehicle = v->index;
@@ -3176,9 +3176,9 @@ public:
{
/* If the hotkey is not for any widget in the UI (i.e. for honking) */
if (hotkey == WID_VV_HONK_HORN) {
const Window* mainwindow = FindWindowById(WC_MAIN_WINDOW, 0);
const Vehicle* v = Vehicle::Get(window_number);
/*Only play the sound if we're following this vehicle */
const Window *mainwindow = GetMainWindow();
const Vehicle *v = Vehicle::Get(window_number);
/* Only play the sound if we're following this vehicle */
if (mainwindow->viewport->follow_vehicle == v->index) {
v->PlayLeaveStationSound(true);
}
@@ -3342,8 +3342,8 @@ bool VehicleClicked(const GUIVehicleGroup &vehgroup)
void StopGlobalFollowVehicle(const Vehicle *v)
{
Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
if (w != nullptr && w->viewport->follow_vehicle == v->index) {
Window *w = GetMainWindow();
if (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
w->viewport->follow_vehicle = INVALID_VEHICLE;
}