diff options
Diffstat (limited to 'src/script')
-rw-r--r-- | src/script/api/game/game_goal.hpp.sq | 6 | ||||
-rw-r--r-- | src/script/api/script_goal.cpp | 6 | ||||
-rw-r--r-- | src/script/api/script_goal.hpp | 14 | ||||
-rw-r--r-- | src/script/api/template/template_goal.hpp.sq | 2 |
4 files changed, 24 insertions, 4 deletions
diff --git a/src/script/api/game/game_goal.hpp.sq b/src/script/api/game/game_goal.hpp.sq index 22ed685b6..765cc779e 100644 --- a/src/script/api/game/game_goal.hpp.sq +++ b/src/script/api/game/game_goal.hpp.sq @@ -27,6 +27,10 @@ void SQGSGoal_Register(Squirrel *engine) SQGSGoal.DefSQConst(engine, ScriptGoal::GT_INDUSTRY, "GT_INDUSTRY"); SQGSGoal.DefSQConst(engine, ScriptGoal::GT_TOWN, "GT_TOWN"); SQGSGoal.DefSQConst(engine, ScriptGoal::GT_COMPANY, "GT_COMPANY"); + SQGSGoal.DefSQConst(engine, ScriptGoal::QT_QUESTION, "QT_QUESTION"); + SQGSGoal.DefSQConst(engine, ScriptGoal::QT_INFORMATION, "QT_INFORMATION"); + SQGSGoal.DefSQConst(engine, ScriptGoal::QT_WARNING, "QT_WARNING"); + SQGSGoal.DefSQConst(engine, ScriptGoal::QT_ERROR, "QT_ERROR"); SQGSGoal.DefSQConst(engine, ScriptGoal::BUTTON_CANCEL, "BUTTON_CANCEL"); SQGSGoal.DefSQConst(engine, ScriptGoal::BUTTON_OK, "BUTTON_OK"); SQGSGoal.DefSQConst(engine, ScriptGoal::BUTTON_NO, "BUTTON_NO"); @@ -49,7 +53,7 @@ void SQGSGoal_Register(Squirrel *engine) SQGSGoal.DefSQStaticMethod(engine, &ScriptGoal::IsValidGoal, "IsValidGoal", 2, ".i"); SQGSGoal.DefSQStaticMethod(engine, &ScriptGoal::New, "New", 5, ".i.ii"); SQGSGoal.DefSQStaticMethod(engine, &ScriptGoal::Remove, "Remove", 2, ".i"); - SQGSGoal.DefSQStaticMethod(engine, &ScriptGoal::Question, "Question", 5, ".ii.i"); + SQGSGoal.DefSQStaticMethod(engine, &ScriptGoal::Question, "Question", 6, ".ii.ii"); SQGSGoal.DefSQStaticMethod(engine, &ScriptGoal::CloseQuestion, "CloseQuestion", 2, ".i"); SQGSGoal.PostRegister(engine); diff --git a/src/script/api/script_goal.cpp b/src/script/api/script_goal.cpp index 88369cf04..8e9dcbff8 100644 --- a/src/script/api/script_goal.cpp +++ b/src/script/api/script_goal.cpp @@ -51,7 +51,7 @@ return ScriptObject::DoCommand(0, goal_id, 0, CMD_REMOVE_GOAL); } -/* static */ bool ScriptGoal::Question(uint16 uniqueid, ScriptCompany::CompanyID company, Text *question, int buttons) +/* static */ bool ScriptGoal::Question(uint16 uniqueid, ScriptCompany::CompanyID company, Text *question, QuestionType type, int buttons) { CCountedPtr<Text> counter(question); @@ -60,11 +60,13 @@ EnforcePrecondition(false, !StrEmpty(question->GetEncodedText())); EnforcePrecondition(false, company == ScriptCompany::COMPANY_INVALID || ScriptCompany::ResolveCompanyID(company) != ScriptCompany::COMPANY_INVALID); EnforcePrecondition(false, CountBits(buttons) >= 1 && CountBits(buttons) <= 3); + EnforcePrecondition(false, buttons < (1 << ::GOAL_QUESTION_BUTTON_COUNT)); + EnforcePrecondition(false, type < ::GOAL_QUESTION_TYPE_COUNT); uint8 c = company; if (company == ScriptCompany::COMPANY_INVALID) c = INVALID_COMPANY; - return ScriptObject::DoCommand(0, uniqueid | (c << 16), buttons, CMD_GOAL_QUESTION, question->GetEncodedText()); + return ScriptObject::DoCommand(0, uniqueid | (c << 16) | (type << 24), buttons, CMD_GOAL_QUESTION, question->GetEncodedText()); } /* static */ bool ScriptGoal::CloseQuestion(uint16 uniqueid) diff --git a/src/script/api/script_goal.hpp b/src/script/api/script_goal.hpp index 781b9bc07..5ad89666d 100644 --- a/src/script/api/script_goal.hpp +++ b/src/script/api/script_goal.hpp @@ -41,6 +41,17 @@ public: GT_COMPANY = ::GT_COMPANY, ///< Destination is a company. }; + /** + * Types of queries we could do to the user. + * 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. + }; + enum QuestionButton { /* Note: these values represent part of the string list starting with STR_GOAL_QUESTION_BUTTON_CANCEL */ BUTTON_CANCEL = (1 << 0), ///< Cancel button. @@ -97,6 +108,7 @@ public: * @param uniqueid Your unique id to distinguish results of multiple questions in the returning event. * @param company The company to ask the question, or ScriptCompany::COMPANY_INVALID for all. * @param question The question to ask (can be either a raw string, or a ScriptText object). + * @param type The type of question that is being asked. * @param buttons Any combinations (at least 1, up to 3) of buttons defined in QuestionButton. Like BUTTON_YES + BUTTON_NO. * @return True if the action succeeded. * @pre No ScriptCompanyMode may be in scope. @@ -106,7 +118,7 @@ public: * @note Replies to the question are given by you via the event ScriptEvent_GoalQuestionAnswer. * @note There is no guarantee you ever get a reply on your question. */ - static bool Question(uint16 uniqueid, ScriptCompany::CompanyID company, Text *question, int buttons); + static bool Question(uint16 uniqueid, ScriptCompany::CompanyID company, Text *question, QuestionType type, int buttons); /** * Close the question on all clients. diff --git a/src/script/api/template/template_goal.hpp.sq b/src/script/api/template/template_goal.hpp.sq index 881f05b7e..6aa3014ee 100644 --- a/src/script/api/template/template_goal.hpp.sq +++ b/src/script/api/template/template_goal.hpp.sq @@ -17,6 +17,8 @@ namespace SQConvert { template <> inline int Return<ScriptGoal::GoalID>(HSQUIRRELVM vm, ScriptGoal::GoalID res) { sq_pushinteger(vm, (int32)res); return 1; } template <> inline ScriptGoal::GoalType GetParam(ForceType<ScriptGoal::GoalType>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (ScriptGoal::GoalType)tmp; } template <> inline int Return<ScriptGoal::GoalType>(HSQUIRRELVM vm, ScriptGoal::GoalType res) { sq_pushinteger(vm, (int32)res); return 1; } + template <> inline ScriptGoal::QuestionType GetParam(ForceType<ScriptGoal::QuestionType>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (ScriptGoal::QuestionType)tmp; } + template <> inline int Return<ScriptGoal::QuestionType>(HSQUIRRELVM vm, ScriptGoal::QuestionType res) { sq_pushinteger(vm, (int32)res); return 1; } template <> inline ScriptGoal::QuestionButton GetParam(ForceType<ScriptGoal::QuestionButton>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQInteger tmp; sq_getinteger(vm, index, &tmp); return (ScriptGoal::QuestionButton)tmp; } template <> inline int Return<ScriptGoal::QuestionButton>(HSQUIRRELVM vm, ScriptGoal::QuestionButton res) { sq_pushinteger(vm, (int32)res); return 1; } |