Changeset - r20339:ff8e383cfb7d
[Not reviewed]
master
0 8 0
zuu - 11 years ago 2013-06-09 12:57:22
zuu@openttd.org
(svn r25352) -Feature: GameScript API for selecting a story page to view
8 files changed with 55 insertions and 3 deletions:
0 comments (0 inline, 0 general)
src/command.cpp
Show inline comments
 
@@ -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
src/command_type.h
Show inline comments
 
@@ -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
 

	
src/gui.h
Show inline comments
 
@@ -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);
 

	
src/script/api/game/game_story_page.hpp.sq
Show inline comments
 
@@ -33,6 +33,7 @@ void SQGSStoryPage_Register(Squirrel *en
 
	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);
src/script/api/script_story_page.cpp
Show inline comments
 
@@ -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);
src/script/api/script_story_page.hpp
Show inline comments
 
@@ -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.
src/story.cpp
Show inline comments
 
@@ -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(TileInd
 
}
 

	
 
/**
 
 * 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
src/story_gui.cpp
Show inline comments
 
@@ -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);
 
	}
 
}
0 comments (0 inline, 0 general)