(svn r23827) -Feature [FS#4992]: [NoGo] Allow to chose the goal question window's title from a (small) set of options

This commit is contained in:
rubidium
2012-01-21 12:03:55 +00:00
parent 464d51905a
commit d79328ec86
37 changed files with 74 additions and 42 deletions

View File

@@ -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);

View File

@@ -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)

View File

@@ -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.

View File

@@ -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; }