summaryrefslogtreecommitdiff
path: root/src/script
diff options
context:
space:
mode:
authorzuu <zuu@openttd.org>2013-05-26 19:54:43 +0000
committerzuu <zuu@openttd.org>2013-05-26 19:54:43 +0000
commita4cddc3e082e2bba80644792b2f6623979328e65 (patch)
tree803c694f123792d7b54f45fdd2d3f83dc3bcc8a5 /src/script
parent05c472f08afdfc6d56fa45f941c17657358d0733 (diff)
downloadopenttd-a4cddc3e082e2bba80644792b2f6623979328e65.tar.xz
(svn r25296) -Feature: Goals can now have a progress text and/or be marked as completed.
Diffstat (limited to 'src/script')
-rw-r--r--src/script/api/game/game_goal.hpp.sq4
-rw-r--r--src/script/api/game/game_window.hpp.sq3
-rw-r--r--src/script/api/game_changelog.hpp4
-rw-r--r--src/script/api/script_goal.cpp44
-rw-r--r--src/script/api/script_goal.hpp44
-rw-r--r--src/script/api/script_window.hpp5
6 files changed, 101 insertions, 3 deletions
diff --git a/src/script/api/game/game_goal.hpp.sq b/src/script/api/game/game_goal.hpp.sq
index 765cc779e..1833bb182 100644
--- a/src/script/api/game/game_goal.hpp.sq
+++ b/src/script/api/game/game_goal.hpp.sq
@@ -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");
diff --git a/src/script/api/game/game_window.hpp.sq b/src/script/api/game/game_window.hpp.sq
index bed536259..62681f246 100644
--- a/src/script/api/game/game_window.hpp.sq
+++ b/src/script/api/game/game_window.hpp.sq
@@ -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");
diff --git a/src/script/api/game_changelog.hpp b/src/script/api/game_changelog.hpp
index 9ad1a3faf..fad71b7fa 100644
--- a/src/script/api/game_changelog.hpp
+++ b/src/script/api/game_changelog.hpp
@@ -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
*
diff --git a/src/script/api/script_goal.cpp b/src/script/api/script_goal.cpp
index 2b9afc5ee..b5d6112fc 100644
--- a/src/script/api/script_goal.cpp
+++ b/src/script/api/script_goal.cpp
@@ -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);
diff --git a/src/script/api/script_goal.hpp b/src/script/api/script_goal.hpp
index a8511e0d6..5416fadf3 100644
--- a/src/script/api/script_goal.hpp
+++ b/src/script/api/script_goal.hpp
@@ -109,6 +109,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.
* @param company The company to ask the question, or ScriptCompany::COMPANY_INVALID for all.
diff --git a/src/script/api/script_window.hpp b/src/script/api/script_window.hpp
index 0972fee9c..954d9300f 100644
--- a/src/script/api/script_window.hpp
+++ b/src/script/api/script_window.hpp
@@ -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. */