(svn r25296) -Feature: Goals can now have a progress text and/or be marked as completed.

This commit is contained in:
zuu
2013-05-26 19:54:43 +00:00
parent 4518e16da7
commit f23a61e1aa
15 changed files with 256 additions and 28 deletions

View File

@@ -53,6 +53,10 @@ 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::SetText, "SetText", 3, ".i.");
SQGSGoal.DefSQStaticMethod(engine, &ScriptGoal::SetProgress, "SetProgress", 3, ".i.");
SQGSGoal.DefSQStaticMethod(engine, &ScriptGoal::SetCompleted, "SetCompleted", 3, ".ib");
SQGSGoal.DefSQStaticMethod(engine, &ScriptGoal::IsCompleted, "IsCompleted", 2, ".i");
SQGSGoal.DefSQStaticMethod(engine, &ScriptGoal::Question, "Question", 6, ".ii.ii");
SQGSGoal.DefSQStaticMethod(engine, &ScriptGoal::CloseQuestion, "CloseQuestion", 2, ".i");

View File

@@ -493,7 +493,8 @@ void SQGSWindow_Register(Squirrel *engine)
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_GP_PROGRESS_BAR, "WID_GP_PROGRESS_BAR");
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_GP_PROGRESS_TEXT, "WID_GP_PROGRESS_TEXT");
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_GP_ABORT, "WID_GP_ABORT");
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_GL_PANEL, "WID_GL_PANEL");
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_GL_GOAL, "WID_GL_GOAL");
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_GL_PROGRESS, "WID_GL_PROGRESS");
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_GL_SCROLLBAR, "WID_GL_SCROLLBAR");
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_GQ_CAPTION, "WID_GQ_CAPTION");
SQGSWindow.DefSQConst(engine, ScriptWindow::WID_GQ_QUESTION, "WID_GQ_QUESTION");

View File

@@ -20,6 +20,10 @@
* 1.4.0 is not yet released. The following changes are not set in stone yet.
*
* API additions:
* \li GSGoal::IsCompleted
* \li GSGoal::SetCompleted
* \li GSGoal::SetProgress
* \li GSGoal::SetText
* \li GSStation::HasRating
* \li GSTile::GetTerrainType
*

View File

@@ -52,6 +52,50 @@
return ScriptObject::DoCommand(0, goal_id, 0, CMD_REMOVE_GOAL);
}
/* static */ bool ScriptGoal::SetText(GoalID goal_id, Text *goal)
{
CCountedPtr<Text> counter(goal);
EnforcePrecondition(false, IsValidGoal(goal_id));
EnforcePrecondition(false, ScriptObject::GetCompany() == OWNER_DEITY);
EnforcePrecondition(false, goal != NULL);
EnforcePrecondition(false, !StrEmpty(goal->GetEncodedText()));
return ScriptObject::DoCommand(0, goal_id, 0, CMD_SET_GOAL_TEXT, goal->GetEncodedText());
}
/* static */ bool ScriptGoal::SetProgress(GoalID goal_id, Text *progress)
{
CCountedPtr<Text> counter(progress);
EnforcePrecondition(false, IsValidGoal(goal_id));
EnforcePrecondition(false, ScriptObject::GetCompany() == OWNER_DEITY);
/* Ensure null as used for emtpy string. */
if (progress != NULL && StrEmpty(progress->GetEncodedText())) {
progress = NULL;
}
return ScriptObject::DoCommand(0, goal_id, 0, CMD_SET_GOAL_PROGRESS, progress != NULL ? progress->GetEncodedText() : NULL);
}
/* static */ bool ScriptGoal::SetCompleted(GoalID goal_id, bool completed)
{
EnforcePrecondition(false, IsValidGoal(goal_id));
EnforcePrecondition(false, ScriptObject::GetCompany() == OWNER_DEITY);
return ScriptObject::DoCommand(0, goal_id, completed ? 1 : 0, CMD_SET_GOAL_COMPLETED);
}
/* static */ bool ScriptGoal::IsCompleted(GoalID goal_id)
{
EnforcePrecondition(false, IsValidGoal(goal_id));
EnforcePrecondition(false, ScriptObject::GetCompany() == OWNER_DEITY);
Goal *g = Goal::Get(goal_id);
return g != NULL && g->completed;
}
/* static */ bool ScriptGoal::Question(uint16 uniqueid, ScriptCompany::CompanyID company, Text *question, QuestionType type, int buttons)
{
CCountedPtr<Text> counter(question);

View File

@@ -108,6 +108,50 @@ public:
*/
static bool Remove(GoalID goal_id);
/**
* Update goal text of a goal.
* @param goal_id The goal to update.
* @param goal The new goal text (can be either a raw string, or a ScriptText object).
* @return True if the action succeeded.
* @pre No ScriptCompanyMode may be in scope.
* @pre goal != NULL && len(goal) != 0.
* @pre IsValidGoal(goal_id).
*/
static bool SetText(GoalID goal_id, Text *goal);
/**
* Update the progress text of a goal. The progress text is a text that
* is shown adjacent to the goal but in a separate column. Try to keep
* the progress string short.
* @param goal_id The goal to update.
* @param progress The new progress text for the goal (can be either a raw string,
* or a ScriptText object). To clear the progress string you can pass NULL or an
* empty string.
* @return True if the action succeeded.
* @pre No ScriptCompanyMode may be in scope.
* @pre IsValidGoal(goal_id).
*/
static bool SetProgress(GoalID goal_id, Text *progress);
/**
* Update completed status of goal
* @param goal_id The goal to update.
* @param complete The new goal completed status.
* @return True if the action succeeded.
* @pre No ScriptCompanyMode may be in scope.
* @pre IsValidGoal(goal_id).
*/
static bool SetCompleted(GoalID goal_id, bool complete);
/**
* Checks if a given goal have been marked as completed.
* @param goal_id The goal to check complete status.
* @return True if the goal is completed, otherwise false.
* @pre No ScriptCompanyMode may be in scope.
* @pre IsValidGoal(goal_id).
*/
static bool IsCompleted(GoalID goal_id);
/**
* Ask a question.
* @param uniqueid Your unique id to distinguish results of multiple questions in the returning event.

View File

@@ -1326,8 +1326,9 @@ public:
/* automatically generated from ../../widgets/goal_widget.h */
/** Widgets of the #GoalListWindow class. */
enum GoalListWidgets {
WID_GL_PANEL = ::WID_GL_PANEL, ///< Panel of the window.
WID_GL_SCROLLBAR = ::WID_GL_SCROLLBAR, ///< Scrollbar of the panel.
WID_GL_GOAL = ::WID_GL_GOAL, ///< Goal text column of the goal list.
WID_GL_PROGRESS = ::WID_GL_PROGRESS, ///< Goal progress column of the goal list.
WID_GL_SCROLLBAR = ::WID_GL_SCROLLBAR, ///< Scrollbar of the goal list.
};
/** Widgets of the #GoalQuestionWindow class. */