Codechange: Use dynamic_cast instead of C-cast after FindWindowById. (#12448)

dynamic_cast was used in most places, but not all.
This commit is contained in:
Peter Nelson 2024-04-08 13:26:19 +01:00 committed by GitHub
parent 4e6d4fcf32
commit 74e09abf76
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 6 additions and 6 deletions

View File

@ -348,7 +348,7 @@ void ShowFirstError()
*/
void UnshowCriticalError()
{
ErrmsgWindow *w = (ErrmsgWindow*)FindWindowById(WC_ERRMSG, 0);
ErrmsgWindow *w = dynamic_cast<ErrmsgWindow *>(FindWindowById(WC_ERRMSG, 0));
if (_window_system_initialized && w != nullptr) {
if (w->IsCritical()) _error_list.push_front(*w);
_window_system_initialized = false;
@ -414,7 +414,7 @@ void ShowErrorMessage(StringID summary_msg, StringID detailed_msg, WarningLevel
ErrorMessageData data(summary_msg, detailed_msg, is_critical, x, y, textref_stack_grffile, textref_stack_size, textref_stack, extra_msg);
data.CopyOutDParams();
ErrmsgWindow *w = (ErrmsgWindow*)FindWindowById(WC_ERRMSG, 0);
ErrmsgWindow *w = dynamic_cast<ErrmsgWindow *>(FindWindowById(WC_ERRMSG, 0));
if (w != nullptr) {
if (w->IsCritical()) {
/* A critical error is currently shown. */
@ -438,7 +438,7 @@ void ShowErrorMessage(StringID summary_msg, StringID detailed_msg, WarningLevel
*/
bool HideActiveErrorMessage()
{
ErrmsgWindow *w = (ErrmsgWindow*)FindWindowById(WC_ERRMSG, 0);
ErrmsgWindow *w = dynamic_cast<ErrmsgWindow *>(FindWindowById(WC_ERRMSG, 0));
if (w == nullptr) return false;
w->Close();
return true;

View File

@ -1169,7 +1169,7 @@ void ShowCompanyGroupForVehicle(const Vehicle *v)
*/
static inline VehicleGroupWindow *FindVehicleGroupWindow(VehicleType vt, Owner owner)
{
return (VehicleGroupWindow *)FindWindowById(GetWindowClassForVehicleType(vt), VehicleListIdentifier(VL_GROUP_LIST, vt, owner).Pack());
return dynamic_cast<VehicleGroupWindow *>(FindWindowById(GetWindowClassForVehicleType(vt), VehicleListIdentifier(VL_GROUP_LIST, vt, owner).Pack()));
}
/**

View File

@ -2234,7 +2234,7 @@ void ShowJoinStatusWindow()
void ShowNetworkNeedPassword(NetworkPasswordType npt, std::shared_ptr<NetworkAuthenticationPasswordRequest> request)
{
NetworkJoinStatusWindow *w = (NetworkJoinStatusWindow *)FindWindowById(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_JOIN);
NetworkJoinStatusWindow *w = dynamic_cast<NetworkJoinStatusWindow *>(FindWindowById(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_JOIN));
if (w == nullptr) return;
w->request = request;

View File

@ -1017,7 +1017,7 @@ static void ShowNewsMessage(NewsIterator ni)
*/
bool HideActiveNewsMessage()
{
NewsWindow *w = (NewsWindow*)FindWindowById(WC_NEWS_WINDOW, 0);
NewsWindow *w = dynamic_cast<NewsWindow *>(FindWindowById(WC_NEWS_WINDOW, 0));
if (w == nullptr) return false;
w->Close();
return true;