Codechange: make GoalQuestionType a scoped enum

Ensure ScriptGoal::QuestionType values match GoalQuestionType.
This commit is contained in:
Peter Nelson
2026-06-09 22:33:13 +01:00
committed by Peter Nelson
parent 0021d5d6bd
commit 3e880e8cd4
10 changed files with 45 additions and 24 deletions
+1
View File
@@ -209,6 +209,7 @@ add_files(
goal_base.h
goal_cmd.h
goal_gui.cpp
goal_gui.h
goal_type.h
graph_gui.cpp
graph_gui.h
+3 -3
View File
@@ -19,7 +19,7 @@
#include "company_base.h"
#include "story_base.h"
#include "string_func.h"
#include "gui.h"
#include "goal_gui.h"
#include "network/network.h"
#include "network/network_base.h"
#include "network/network_func.h"
@@ -260,9 +260,9 @@ CommandCost CmdGoalQuestion(DoCommandFlags flags, uint16_t uniqueid, uint32_t ta
} else {
if (company != CompanyID::Invalid() && !Company::IsValidID(company)) return CMD_ERROR;
}
uint min_buttons = (type == GQT_QUESTION ? 1 : 0);
uint min_buttons = (type == GoalQuestionType::Question ? 1 : 0);
if (CountBits(button_mask) < min_buttons || CountBits(button_mask) > 3) return CMD_ERROR;
if (type >= GQT_END) return CMD_ERROR;
if (type >= GoalQuestionType::End) return CMD_ERROR;
if (flags.Test(DoCommandFlag::Execute)) {
if (is_client) {
+6 -5
View File
@@ -15,6 +15,7 @@
#include "viewport_func.h"
#include "gui.h"
#include "goal_base.h"
#include "goal_gui.h"
#include "core/geometry_func.hpp"
#include "company_func.h"
#include "company_base.h"
@@ -439,7 +440,7 @@ static constexpr auto _nested_goal_question_widgets_warning = NestedGoalWidgets
static constexpr auto _nested_goal_question_widgets_error = NestedGoalWidgets<Colours::Red, Colours::Yellow, STR_GOAL_QUESTION_CAPTION_ERROR>::widgetparts;
/** Window definitions for the goal question windows. */
static WindowDesc _goal_question_list_desc[] = {
static EnumIndexArray<WindowDesc, GoalQuestionType, GoalQuestionType::End> _goal_question_list_desc{{{
{
WindowPosition::Center, {}, 0, 0,
WindowClass::GoalQuestion, WindowClass::None,
@@ -464,7 +465,7 @@ static WindowDesc _goal_question_list_desc[] = {
WindowDefaultFlag::Construction,
_nested_goal_question_widgets_error,
},
};
}}};
/**
* Display a goal question.
@@ -473,8 +474,8 @@ static WindowDesc _goal_question_list_desc[] = {
* @param button_mask Buttons to display.
* @param question Question to ask.
*/
void ShowGoalQuestion(uint16_t id, uint8_t type, uint32_t button_mask, const EncodedString &question)
void ShowGoalQuestion(uint16_t id, GoalQuestionType type, uint32_t button_mask, const EncodedString &question)
{
assert(type < GQT_END);
new GoalQuestionWindow(_goal_question_list_desc[type], id, type == 3 ? TextColour::White : TextColour::Black, button_mask, question);
assert(type < GoalQuestionType::End);
new GoalQuestionWindow(_goal_question_list_desc[type], id, type == GoalQuestionType::Error ? TextColour::White : TextColour::Black, button_mask, question);
}
+20
View File
@@ -0,0 +1,20 @@
/*
* This file is part of OpenTTD.
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
*/
/** @file goal_gui.h Goal GUI functions. */
#ifndef GOAL_GUI_H
#define GOAL_GUI_H
#include "company_type.h"
#include "goal_type.h"
#include "strings_type.h"
void ShowGoalsList(CompanyID company);
void ShowGoalQuestion(uint16_t id, GoalQuestionType type, uint32_t button_mask, const EncodedString &question);
#endif /* GOAL_TYPE_H */
+7 -6
View File
@@ -14,12 +14,13 @@
static const uint32_t GOAL_QUESTION_BUTTON_COUNT = 18; ///< Amount of buttons available.
enum GoalQuestionType : uint8_t {
GQT_QUESTION = 0,
GQT_INFORMATION = 1,
GQT_WARNING = 2,
GQT_ERROR = 3,
GQT_END = 4,
/** Types of goal questions. */
enum class GoalQuestionType : uint8_t {
Question = 0, ///< Asking a simple question; title: Question.
Information = 1, ///< Showing an informational message; title: Information.
Warning = 2, ///< Showing a warning; title: Warning.
Error = 3, ///< Showing an error; title: Error.
End, ///< End marker.
};
/** Types of goal destinations */
-4
View File
@@ -62,10 +62,6 @@ void ShowBuildIndustryWindow();
/* subsidy_gui.cpp */
void ShowSubsidiesList();
/* goal_gui.cpp */
void ShowGoalsList(CompanyID company);
void ShowGoalQuestion(uint16_t id, uint8_t type, uint32_t button_mask, const EncodedString &question);
/* story_gui.cpp */
void ShowStoryBook(CompanyID company, StoryPageID page_id = StoryPageID::Invalid(), bool centered = false);
+2 -2
View File
@@ -136,10 +136,10 @@
uint min_buttons = (type == QT_QUESTION ? 1 : 0);
EnforcePrecondition(false, CountBits<uint64_t>(buttons) >= min_buttons && CountBits<uint64_t>(buttons) <= 3);
EnforcePrecondition(false, buttons >= 0 && buttons < (1 << ::GOAL_QUESTION_BUTTON_COUNT));
EnforcePrecondition(false, (int)type < ::GQT_END);
EnforcePrecondition(false, static_cast<::GoalQuestionType>(type) < ::GoalQuestionType::End);
EnforcePrecondition(false, uniqueid >= 0 && uniqueid <= UINT16_MAX);
return ScriptObject::Command<Commands::GoalQuestion>::Do(uniqueid, target, is_client, buttons, (::GoalQuestionType)type, text);
return ScriptObject::Command<Commands::GoalQuestion>::Do(uniqueid, target, is_client, buttons, static_cast<::GoalQuestionType>(type), text);
}
/* static */ bool ScriptGoal::Question(SQInteger uniqueid, ScriptCompany::CompanyID company, Text *question, QuestionType type, SQInteger buttons)
+4 -4
View File
@@ -45,10 +45,10 @@ public:
* Basically the title of the question window.
*/
enum QuestionType {
QT_QUESTION, ///< Asking a simple question; title: Question.
QT_INFORMATION, ///< Showing an informational message; title: Information.
QT_WARNING, ///< Showing a warning; title: Warning.
QT_ERROR, ///< Showing an error; title: Error.
QT_QUESTION = to_underlying(::GoalQuestionType::Question), ///< Asking a simple question; title: Question.
QT_INFORMATION = to_underlying(::GoalQuestionType::Information), ///< Showing an informational message; title: Information.
QT_WARNING = to_underlying(::GoalQuestionType::Warning), ///< Showing a warning; title: Warning.
QT_ERROR = to_underlying(::GoalQuestionType::Error), ///< Showing an error; title: Error.
};
/**
+1
View File
@@ -19,6 +19,7 @@
#include "dropdown_func.h"
#include "sortlist_type.h"
#include "goal_base.h"
#include "goal_gui.h"
#include "viewport_func.h"
#include "window_func.h"
#include "company_base.h"
+1
View File
@@ -52,6 +52,7 @@
#include "highscore.h"
#include "game/game.hpp"
#include "goal_base.h"
#include "goal_gui.h"
#include "story_base.h"
#include "toolbar_gui.h"
#include "framerate_type.h"