summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorzuu <zuu@openttd.org>2013-06-09 12:57:22 +0000
committerzuu <zuu@openttd.org>2013-06-09 12:57:22 +0000
commit33ad9774fb7c51f1ec706851c7a96a7ced5ff622 (patch)
treeaf64b06f63d6168eef04bf09172732f6af896027 /src
parenta49a4eec6e9b9fd7a9520af882a38697dd3a0ed3 (diff)
downloadopenttd-33ad9774fb7c51f1ec706851c7a96a7ced5ff622.tar.xz
(svn r25352) -Feature: GameScript API for selecting a story page to view
Diffstat (limited to 'src')
-rw-r--r--src/command.cpp2
-rw-r--r--src/command_type.h1
-rw-r--r--src/gui.h3
-rw-r--r--src/script/api/game/game_story_page.hpp.sq1
-rw-r--r--src/script/api/script_story_page.cpp8
-rw-r--r--src/script/api/script_story_page.hpp11
-rw-r--r--src/story.cpp23
-rw-r--r--src/story_gui.cpp9
8 files changed, 55 insertions, 3 deletions
diff --git a/src/command.cpp b/src/command.cpp
index 38dc43521..d0d08ca31 100644
--- a/src/command.cpp
+++ b/src/command.cpp
@@ -159,6 +159,7 @@ CommandProc CmdCreateStoryPage;
CommandProc CmdCreateStoryPageElement;
CommandProc CmdUpdateStoryPageElement;
CommandProc CmdSetStoryPageTitle;
+CommandProc CmdShowStoryPage;
CommandProc CmdRemoveStoryPage;
CommandProc CmdLevelLand;
@@ -309,6 +310,7 @@ static const Command _command_proc_table[] = {
DEF_CMD(CmdCreateStoryPageElement, CMD_STR_CTRL | CMD_DEITY, CMDT_OTHER_MANAGEMENT ), // CMD_CREATE_STORY_PAGE_ELEMENT
DEF_CMD(CmdUpdateStoryPageElement, CMD_STR_CTRL | CMD_DEITY, CMDT_OTHER_MANAGEMENT ), // CMD_UPDATE_STORY_PAGE_ELEMENT
DEF_CMD(CmdSetStoryPageTitle, CMD_STR_CTRL | CMD_DEITY, CMDT_OTHER_MANAGEMENT ), // CMD_SET_STORY_PAGE_TITLE
+ DEF_CMD(CmdShowStoryPage, CMD_DEITY, CMDT_OTHER_MANAGEMENT ), // CMD_SHOW_STORY_PAGE
DEF_CMD(CmdRemoveStoryPage, CMD_STR_CTRL | CMD_DEITY, CMDT_OTHER_MANAGEMENT ), // CMD_REMOVE_STORY_PAGE
DEF_CMD(CmdLevelLand, CMD_ALL_TILES | CMD_NO_TEST | CMD_AUTO, CMDT_LANDSCAPE_CONSTRUCTION), // CMD_LEVEL_LAND; test run might clear tiles multiple times, in execution that only happens once
diff --git a/src/command_type.h b/src/command_type.h
index 78e8c188e..f3236f261 100644
--- a/src/command_type.h
+++ b/src/command_type.h
@@ -275,6 +275,7 @@ enum Commands {
CMD_CREATE_STORY_PAGE_ELEMENT, ///< create a new story page element
CMD_UPDATE_STORY_PAGE_ELEMENT, ///< update a story page element
CMD_SET_STORY_PAGE_TITLE, ///< update title of a story page
+ CMD_SHOW_STORY_PAGE, ///< show a story page
CMD_REMOVE_STORY_PAGE, ///< remove a story page
CMD_LEVEL_LAND, ///< level land
diff --git a/src/gui.h b/src/gui.h
index 79c33e0b3..fe14e2d6e 100644
--- a/src/gui.h
+++ b/src/gui.h
@@ -16,6 +16,7 @@
#include "economy_type.h"
#include "tile_type.h"
#include "transport_type.h"
+#include "story_type.h"
struct Window;
@@ -51,7 +52,7 @@ void ShowIndustryCargoesWindow();
void ShowSubsidiesList();
void ShowGoalsList();
void ShowGoalQuestion(uint16 id, byte type, uint32 button_mask, const char *question);
-void ShowStoryBook();
+void ShowStoryBook(uint16 page_id = INVALID_STORY_PAGE);
void ShowEstimatedCostOrIncome(Money cost, int x, int y);
diff --git a/src/script/api/game/game_story_page.hpp.sq b/src/script/api/game/game_story_page.hpp.sq
index abc9500d1..1d0fe6ced 100644
--- a/src/script/api/game/game_story_page.hpp.sq
+++ b/src/script/api/game/game_story_page.hpp.sq
@@ -33,6 +33,7 @@ void SQGSStoryPage_Register(Squirrel *engine)
SQGSStoryPage.DefSQStaticMethod(engine, &ScriptStoryPage::NewElement, "NewElement", 5, ".iii.");
SQGSStoryPage.DefSQStaticMethod(engine, &ScriptStoryPage::UpdateElement, "UpdateElement", 4, ".ii.");
SQGSStoryPage.DefSQStaticMethod(engine, &ScriptStoryPage::SetTitle, "SetTitle", 3, ".i.");
+ SQGSStoryPage.DefSQStaticMethod(engine, &ScriptStoryPage::Show, "Show", 2, ".i");
SQGSStoryPage.DefSQStaticMethod(engine, &ScriptStoryPage::Remove, "Remove", 2, ".i");
SQGSStoryPage.PostRegister(engine);
diff --git a/src/script/api/script_story_page.cpp b/src/script/api/script_story_page.cpp
index e94bc0017..8d6253b3c 100644
--- a/src/script/api/script_story_page.cpp
+++ b/src/script/api/script_story_page.cpp
@@ -109,6 +109,14 @@
return ScriptObject::DoCommand(0, story_page_id, 0, CMD_SET_STORY_PAGE_TITLE, title != NULL? title->GetEncodedText() : NULL);
}
+/* static */ bool ScriptStoryPage::Show(StoryPageID story_page_id)
+{
+ EnforcePrecondition(false, IsValidStoryPage(story_page_id));
+ EnforcePrecondition(false, ScriptObject::GetCompany() == OWNER_DEITY);
+
+ return ScriptObject::DoCommand(0, story_page_id, 0, CMD_SHOW_STORY_PAGE);
+}
+
/* static */ bool ScriptStoryPage::Remove(StoryPageID story_page_id)
{
EnforcePrecondition(false, ScriptObject::GetCompany() == OWNER_DEITY);
diff --git a/src/script/api/script_story_page.hpp b/src/script/api/script_story_page.hpp
index b013f2515..d026650be 100644
--- a/src/script/api/script_story_page.hpp
+++ b/src/script/api/script_story_page.hpp
@@ -129,6 +129,17 @@ public:
static bool SetTitle(StoryPageID story_page_id, Text *title);
/**
+ * Opens the Story Book if not yet open and selects the given page.
+ * @param story_page_id The story page to update. If it is a global page, clients of all
+ * companies are affecetd. Otherwise only the clients of the company which the page belongs
+ * to are affected.
+ * @return True if the action succeeded.
+ * @pre No ScriptCompanyMode may be in scope.
+ * @pre IsValidStoryPage(story_page_id).
+ */
+ static bool Show(StoryPageID story_page_id);
+
+ /**
* Remove a story page from the list.
* @param story_page_id The story page to remove.
* @return True if the action succeeded.
diff --git a/src/story.cpp b/src/story.cpp
index e492ded4d..74cdd1d5c 100644
--- a/src/story.cpp
+++ b/src/story.cpp
@@ -21,6 +21,7 @@
#include "goal_type.h"
#include "goal_base.h"
#include "window_func.h"
+#include "gui.h"
StoryPageElementID _new_story_page_element_id;
@@ -247,6 +248,28 @@ CommandCost CmdSetStoryPageTitle(TileIndex tile, DoCommandFlag flags, uint32 p1,
}
/**
+ * Display a story page for all clients that are allowed to
+ * view the story page.
+ * @param tile unused.
+ * @param flags type of operation
+ * @param p1 StoryPageID to show.
+ * @param p2 unused
+ * @param text unused
+ * @return the cost of this operation or an error
+ */
+CommandCost CmdShowStoryPage(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
+{
+ if (_current_company != OWNER_DEITY) return CMD_ERROR;
+ if (!StoryPage::IsValidID(p1)) return CMD_ERROR;
+
+ if (flags & DC_EXEC) {
+ StoryPage *g = StoryPage::Get(p1);
+ if ((g->company != INVALID_COMPANY && g->company == _local_company) || (g->company == INVALID_COMPANY && Company::IsValidID(_local_company))) ShowStoryBook(p1);
+ }
+
+ return CommandCost();
+}
+/**
* Remove a story page and associated story page elements.
* @param tile unused.
* @param flags type of operation
diff --git a/src/story_gui.cpp b/src/story_gui.cpp
index 62ec3606a..64782b90e 100644
--- a/src/story_gui.cpp
+++ b/src/story_gui.cpp
@@ -23,6 +23,7 @@
#include "sortlist_type.h"
#include "goal_base.h"
#include "viewport_func.h"
+#include "window_func.h"
#include "widgets/story_widget.h"
@@ -725,7 +726,11 @@ static WindowDesc _story_book_desc(
_nested_story_book_widgets, lengthof(_nested_story_book_widgets)
);
-void ShowStoryBook()
+void ShowStoryBook(uint16 page_id)
{
- AllocateWindowDescFront<StoryBookWindow>(&_story_book_desc, 0);
+ StoryBookWindow *w = AllocateWindowDescFront<StoryBookWindow>(&_story_book_desc, 0);
+ if (page_id != INVALID_STORY_PAGE) {
+ if (w == NULL) w = (StoryBookWindow *)FindWindowById(WC_STORY_BOOK, 0);
+ w->SetSelectedPage(page_id);
+ }
}