From 3a2509198f4af0b4fc542704dfd9a204014c5904 Mon Sep 17 00:00:00 2001 From: Rubidium Date: Sun, 17 Sep 2023 16:24:29 +0200 Subject: [PATCH] Codechange: use better location for the "invalid" action sentinel value It used to be a random sentinel for end-of-(widget-)list that was used to tell that no action has taken place yet. Since the last action is practically the widget that was pressed, add the sentinel to that enumeration. --- src/airport_gui.cpp | 2 +- src/rail_gui.cpp | 2 +- src/road_gui.cpp | 2 +- src/terraform_gui.cpp | 4 ++-- src/widget_type.h | 2 -- src/widgets/airport_widget.h | 2 ++ src/widgets/rail_widget.h | 2 ++ src/widgets/road_widget.h | 2 ++ src/widgets/terraform_widget.h | 4 ++++ 9 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/airport_gui.cpp b/src/airport_gui.cpp index d474643b74..3386f99d62 100644 --- a/src/airport_gui.cpp +++ b/src/airport_gui.cpp @@ -87,7 +87,7 @@ struct BuildAirToolbarWindow : Window { this->InitNested(window_number); this->OnInvalidateData(); if (_settings_client.gui.link_terraform_toolbar) ShowTerraformToolbar(this); - this->last_user_action = WIDGET_LIST_END; + this->last_user_action = INVALID_WID_AT; } void Close() override diff --git a/src/rail_gui.cpp b/src/rail_gui.cpp index cd9270f11c..675f27b872 100644 --- a/src/rail_gui.cpp +++ b/src/rail_gui.cpp @@ -414,7 +414,7 @@ struct BuildRailToolbarWindow : Window { this->InitNested(TRANSPORT_RAIL); this->SetupRailToolbar(railtype); this->DisableWidget(WID_RAT_REMOVE); - this->last_user_action = WIDGET_LIST_END; + this->last_user_action = INVALID_WID_RAT; if (_settings_client.gui.link_terraform_toolbar) ShowTerraformToolbar(this); } diff --git a/src/road_gui.cpp b/src/road_gui.cpp index 3a2f567aa7..2d7cfa763a 100644 --- a/src/road_gui.cpp +++ b/src/road_gui.cpp @@ -324,7 +324,7 @@ struct BuildRoadToolbarWindow : Window { } this->OnInvalidateData(); - this->last_started_action = WIDGET_LIST_END; + this->last_started_action = INVALID_WID_ROT; if (_settings_client.gui.link_terraform_toolbar) ShowTerraformToolbar(this); } diff --git a/src/terraform_gui.cpp b/src/terraform_gui.cpp index d7c525b3e4..f68e675a11 100644 --- a/src/terraform_gui.cpp +++ b/src/terraform_gui.cpp @@ -161,7 +161,7 @@ struct TerraformToolbarWindow : Window { /* This is needed as we like to have the tree available on OnInit. */ this->CreateNestedTree(); this->FinishInitNested(window_number); - this->last_user_action = WIDGET_LIST_END; + this->last_user_action = INVALID_WID_TT; } ~TerraformToolbarWindow() @@ -542,7 +542,7 @@ struct ScenarioEditorLandscapeGenerationWindow : Window { NWidgetStacked *show_desert = this->GetWidget(WID_ETT_SHOW_PLACE_DESERT); show_desert->SetDisplayedPlane(_settings_game.game_creation.landscape == LT_TROPIC ? 0 : SZSP_NONE); this->FinishInitNested(window_number); - this->last_user_action = WIDGET_LIST_END; + this->last_user_action = INVALID_WID_ETT; } void OnPaint() override diff --git a/src/widget_type.h b/src/widget_type.h index f00577e9c4..ffa8980111 100644 --- a/src/widget_type.h +++ b/src/widget_type.h @@ -17,8 +17,6 @@ #include "gfx_type.h" #include "window_type.h" -static const int WIDGET_LIST_END = -1; ///< indicate the end of widgets' list for vararg functions - /** Bits of the #WWT_MATRIX widget data. */ enum MatrixWidgetValues { /* Number of column bits of the WWT_MATRIX widget data. */ diff --git a/src/widgets/airport_widget.h b/src/widgets/airport_widget.h index 75b805031c..f923512199 100644 --- a/src/widgets/airport_widget.h +++ b/src/widgets/airport_widget.h @@ -14,6 +14,8 @@ enum AirportToolbarWidgets { WID_AT_AIRPORT, ///< Build airport button. WID_AT_DEMOLISH, ///< Demolish button. + + INVALID_WID_AT = -1, }; /** Widgets of the #BuildAirportWindow class. */ diff --git a/src/widgets/rail_widget.h b/src/widgets/rail_widget.h index 4b5b7f41c2..479915cc01 100644 --- a/src/widgets/rail_widget.h +++ b/src/widgets/rail_widget.h @@ -28,6 +28,8 @@ enum RailToolbarWidgets { WID_RAT_BUILD_TUNNEL, ///< Build a tunnel. WID_RAT_REMOVE, ///< Bulldozer to remove rail. WID_RAT_CONVERT_RAIL, ///< Convert other rail to this type. + + INVALID_WID_RAT = -1, }; /** Widgets of the #BuildRailStationWindow class. */ diff --git a/src/widgets/road_widget.h b/src/widgets/road_widget.h index fa23631ba1..58825f1fe2 100644 --- a/src/widgets/road_widget.h +++ b/src/widgets/road_widget.h @@ -26,6 +26,8 @@ enum RoadToolbarWidgets { WID_ROT_BUILD_TUNNEL, ///< Build tunnel. WID_ROT_REMOVE, ///< Remove road. WID_ROT_CONVERT_ROAD, ///< Convert road. + + INVALID_WID_ROT = -1, }; /** Widgets of the #BuildRoadDepotWindow class. */ diff --git a/src/widgets/terraform_widget.h b/src/widgets/terraform_widget.h index 0fd216d721..777a2beb64 100644 --- a/src/widgets/terraform_widget.h +++ b/src/widgets/terraform_widget.h @@ -22,6 +22,8 @@ enum TerraformToolbarWidgets { WID_TT_PLANT_TREES, ///< Plant trees button (note: opens separate window, no place-push-button). WID_TT_PLACE_SIGN, ///< Place sign button. WID_TT_PLACE_OBJECT, ///< Place object button. + + INVALID_WID_TT = -1, }; /** Widgets of the #ScenarioEditorLandscapeGenerationWindow class. */ @@ -42,6 +44,8 @@ enum EditorTerraformToolbarWidgets { WID_ETT_DECREASE_SIZE, ///< Downwards arrow button to decrease terraforming size. WID_ETT_NEW_SCENARIO, ///< Button for generating a new scenario. WID_ETT_RESET_LANDSCAPE, ///< Button for removing all company-owned property. + + INVALID_WID_ETT = -1, }; #endif /* WIDGETS_TERRAFORM_WIDGET_H */