From 57a88c9de2c68496c36c5646207541a28a3e31cc Mon Sep 17 00:00:00 2001 From: zuu Date: Thu, 6 Feb 2014 19:41:56 +0000 Subject: (svn r26305) -Add: [nogo] ScriptStoryPageElementList() - a list of all story page elements for a given page --- src/script/api/game/game_story_page.hpp.sq | 1 + .../api/game/game_storypageelementlist.hpp.sq | 25 +++++++++++++++++ src/script/api/game_changelog.hpp | 1 + src/script/api/script_story_page.cpp | 7 +++++ src/script/api/script_story_page.hpp | 11 ++++++++ src/script/api/script_storypageelementlist.cpp | 26 ++++++++++++++++++ src/script/api/script_storypageelementlist.hpp | 32 ++++++++++++++++++++++ .../template/template_storypageelementlist.hpp.sq | 21 ++++++++++++++ 8 files changed, 124 insertions(+) create mode 100644 src/script/api/game/game_storypageelementlist.hpp.sq create mode 100644 src/script/api/script_storypageelementlist.cpp create mode 100644 src/script/api/script_storypageelementlist.hpp create mode 100644 src/script/api/template/template_storypageelementlist.hpp.sq (limited to 'src/script') diff --git a/src/script/api/game/game_story_page.hpp.sq b/src/script/api/game/game_story_page.hpp.sq index dba324eaa..7fc45f2fe 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::GetPageSort, "GetPageSort", 2, ".i"); + SQGSStoryPage.DefSQStaticMethod(engine, &ScriptStoryPage::GetPageElementSort, "GetPageElementSort", 2, ".i"); SQGSStoryPage.DefSQStaticMethod(engine, &ScriptStoryPage::SetTitle, "SetTitle", 3, ".i."); SQGSStoryPage.DefSQStaticMethod(engine, &ScriptStoryPage::Show, "Show", 2, ".i"); SQGSStoryPage.DefSQStaticMethod(engine, &ScriptStoryPage::Remove, "Remove", 2, ".i"); diff --git a/src/script/api/game/game_storypageelementlist.hpp.sq b/src/script/api/game/game_storypageelementlist.hpp.sq new file mode 100644 index 000000000..5ef3e6ed3 --- /dev/null +++ b/src/script/api/game/game_storypageelementlist.hpp.sq @@ -0,0 +1,25 @@ +/* $Id$ */ + +/* + * This file is part of OpenTTD. + * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. + * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see . + */ + +/* THIS FILE IS AUTO-GENERATED; PLEASE DO NOT ALTER MANUALLY */ + +#include "../script_storypageelementlist.hpp" +#include "../template/template_storypageelementlist.hpp.sq" + + +template <> const char *GetClassName() { return "GSStoryPageElementList"; } + +void SQGSStoryPageElementList_Register(Squirrel *engine) +{ + DefSQClass SQGSStoryPageElementList("GSStoryPageElementList"); + SQGSStoryPageElementList.PreRegister(engine, "GSList"); + SQGSStoryPageElementList.AddConstructor(engine, "xi"); + + SQGSStoryPageElementList.PostRegister(engine); +} diff --git a/src/script/api/game_changelog.hpp b/src/script/api/game_changelog.hpp index 0bca40401..20a28edcd 100644 --- a/src/script/api/game_changelog.hpp +++ b/src/script/api/game_changelog.hpp @@ -29,6 +29,7 @@ * \li GSStation::HasCargoRating * \li GSStoryPage * \li GSStoryPageList + * \li GSStoryPageElementList * \li GSTile::GetTerrainType * \li GSTown::FoundTown * \li GSTown::GetFundBuildingsDuration diff --git a/src/script/api/script_story_page.cpp b/src/script/api/script_story_page.cpp index 8382d43d7..c443d67d4 100644 --- a/src/script/api/script_story_page.cpp +++ b/src/script/api/script_story_page.cpp @@ -105,6 +105,13 @@ return StoryPage::Get(story_page_id)->sort_value; } +/* static */ uint32 ScriptStoryPage::GetPageElementSort(StoryPageElementID story_page_element_id) +{ + EnforcePrecondition(false, IsValidStoryPageElement(story_page_element_id)); + + return StoryPageElement::Get(story_page_element_id)->sort_value; +} + /* static */ bool ScriptStoryPage::SetTitle(StoryPageID story_page_id, Text *title) { CCountedPtr counter(title); diff --git a/src/script/api/script_story_page.hpp b/src/script/api/script_story_page.hpp index 2ce74dcbc..315cb2104 100644 --- a/src/script/api/script_story_page.hpp +++ b/src/script/api/script_story_page.hpp @@ -128,6 +128,17 @@ public: */ static uint32 GetPageSort(StoryPageID story_page_id); + /** + * Get story page element sort value. Each page element has a sort value that is internally + * assigned and used to sort the page elements within a page of the story book. OpenTTD + * maintains this number so that the sort order is perceived. This API exist only so that + * you can sort ScriptStoryPageList the same order as in GUI. You should not use this number + * for anything else. + * @param story_page_element_id The story page element to get the sort value of. + * @return Page element sort value. + */ + static uint32 GetPageElementSort(StoryPageElementID story_page_element_id); + /** * Update title of a story page. The title is shown in the page selector drop down. * @param story_page_id The story page to update. diff --git a/src/script/api/script_storypageelementlist.cpp b/src/script/api/script_storypageelementlist.cpp new file mode 100644 index 000000000..5b6b2cd53 --- /dev/null +++ b/src/script/api/script_storypageelementlist.cpp @@ -0,0 +1,26 @@ +/* $Id$ */ + +/* + * This file is part of OpenTTD. + * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. + * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see . + */ + +/** @file script_storypageelementlist.cpp Implementation of ScriptStoryPageElementList and friends. */ + +#include "../../stdafx.h" +#include "script_storypageelementlist.hpp" +#include "../../story_base.h" + +ScriptStoryPageElementList::ScriptStoryPageElementList(ScriptStoryPage::StoryPageID story_page_id) +{ + if (!ScriptStoryPage::IsValidStoryPage(story_page_id)) return; + + StoryPageElement *pe; + FOR_ALL_STORY_PAGE_ELEMENTS(pe) { + if (pe->page == story_page_id) { + this->AddItem(pe->index); + } + } +} diff --git a/src/script/api/script_storypageelementlist.hpp b/src/script/api/script_storypageelementlist.hpp new file mode 100644 index 000000000..6aa2faf2d --- /dev/null +++ b/src/script/api/script_storypageelementlist.hpp @@ -0,0 +1,32 @@ +/* $Id$ */ + +/* + * This file is part of OpenTTD. + * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. + * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see . + */ + +/** @file script_storypageelementlist.hpp List all story page elements. */ + +#ifndef SCRIPT_STORYPAGEELEMENTLIST_HPP +#define SCRIPT_STORYPAGEELEMENTLIST_HPP + +#include "script_list.hpp" +#include "script_company.hpp" +#include "script_story_page.hpp" + +/** + * Create a list of all story page elements. + * @api game + * @ingroup ScriptList + */ +class ScriptStoryPageElementList : public ScriptList { +public: + /** + * @param story_page_id The page id of the story page of which all page elements should be included in the list. + */ + ScriptStoryPageElementList(ScriptStoryPage::StoryPageID story_page_id); +}; + +#endif /* SCRIPT_STORYPAGEELEMENTLIST_HPP */ diff --git a/src/script/api/template/template_storypageelementlist.hpp.sq b/src/script/api/template/template_storypageelementlist.hpp.sq new file mode 100644 index 000000000..34d940f92 --- /dev/null +++ b/src/script/api/template/template_storypageelementlist.hpp.sq @@ -0,0 +1,21 @@ +/* $Id$ */ + +/* + * This file is part of OpenTTD. + * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. + * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see . + */ + +/* THIS FILE IS AUTO-GENERATED; PLEASE DO NOT ALTER MANUALLY */ + +#include "../script_storypageelementlist.hpp" + +namespace SQConvert { + /* Allow ScriptStoryPageElementList to be used as Squirrel parameter */ + template <> inline ScriptStoryPageElementList *GetParam(ForceType, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (ScriptStoryPageElementList *)instance; } + template <> inline ScriptStoryPageElementList &GetParam(ForceType, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(ScriptStoryPageElementList *)instance; } + template <> inline const ScriptStoryPageElementList *GetParam(ForceType, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (ScriptStoryPageElementList *)instance; } + template <> inline const ScriptStoryPageElementList &GetParam(ForceType, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(ScriptStoryPageElementList *)instance; } + template <> inline int Return(HSQUIRRELVM vm, ScriptStoryPageElementList *res) { if (res == NULL) { sq_pushnull(vm); return 1; } res->AddRef(); Squirrel::CreateClassInstanceVM(vm, "StoryPageElementList", res, NULL, DefSQDestructorCallback, true); return 1; } +} // namespace SQConvert -- cgit v1.2.3-70-g09d2