mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r25352) -Feature: GameScript API for selecting a story page to view
This commit is contained in:
parent
a49a4eec6e
commit
33ad9774fb
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -128,6 +128,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.
|
||||
|
|
|
@ -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;
|
||||
|
@ -246,6 +247,28 @@ CommandCost CmdSetStoryPageTitle(TileIndex tile, DoCommandFlag flags, uint32 p1,
|
|||
return CommandCost();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue