diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 16215e7f8d..1a4a84fb48 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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 diff --git a/src/goal.cpp b/src/goal.cpp index db07f6c5dc..b7f1ce38aa 100644 --- a/src/goal.cpp +++ b/src/goal.cpp @@ -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) { diff --git a/src/goal_gui.cpp b/src/goal_gui.cpp index b18f73d448..baca68b6f1 100644 --- a/src/goal_gui.cpp +++ b/src/goal_gui.cpp @@ -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::widgetparts; /** Window definitions for the goal question windows. */ -static WindowDesc _goal_question_list_desc[] = { +static EnumIndexArray _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); } diff --git a/src/goal_gui.h b/src/goal_gui.h new file mode 100644 index 0000000000..0be3a8ee9a --- /dev/null +++ b/src/goal_gui.h @@ -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 . + */ + +/** @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 */ diff --git a/src/goal_type.h b/src/goal_type.h index b57daaa377..cce8fb9dd8 100644 --- a/src/goal_type.h +++ b/src/goal_type.h @@ -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 */ diff --git a/src/gui.h b/src/gui.h index 5cf82e39d4..153ca5d55e 100644 --- a/src/gui.h +++ b/src/gui.h @@ -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); diff --git a/src/script/api/script_goal.cpp b/src/script/api/script_goal.cpp index 942d28cc28..fcf959d52d 100644 --- a/src/script/api/script_goal.cpp +++ b/src/script/api/script_goal.cpp @@ -136,10 +136,10 @@ uint min_buttons = (type == QT_QUESTION ? 1 : 0); EnforcePrecondition(false, CountBits(buttons) >= min_buttons && CountBits(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::Do(uniqueid, target, is_client, buttons, (::GoalQuestionType)type, text); + return ScriptObject::Command::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) diff --git a/src/script/api/script_goal.hpp b/src/script/api/script_goal.hpp index eb3427ee20..74de0abb27 100644 --- a/src/script/api/script_goal.hpp +++ b/src/script/api/script_goal.hpp @@ -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. }; /** diff --git a/src/story_gui.cpp b/src/story_gui.cpp index a386e21820..2868a9b800 100644 --- a/src/story_gui.cpp +++ b/src/story_gui.cpp @@ -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" diff --git a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp index c614156a4c..bae8c383d5 100644 --- a/src/toolbar_gui.cpp +++ b/src/toolbar_gui.cpp @@ -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"