Mercurial > hg > openttd
changeset 18777:693e2f94cbd1 draft
(svn r23625) -Add: ScriptViewport::ScrollTo, for SinglePlayer only (GameScript only)
author | truebrain <truebrain@openttd.org> |
---|---|
date | Mon, 19 Dec 2011 21:00:48 +0000 |
parents | 3fdd053baa35 |
children | 153e9c1e0d36 |
files | projects/openttd_vs100.vcxproj projects/openttd_vs100.vcxproj.filters projects/openttd_vs80.vcproj projects/openttd_vs90.vcproj source.list src/game/game_instance.cpp src/script/api/game/game_viewport.hpp.sq src/script/api/script_viewport.cpp src/script/api/script_viewport.hpp src/script/api/template/template_viewport.hpp.sq |
diffstat | 10 files changed, 134 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/projects/openttd_vs100.vcxproj +++ b/projects/openttd_vs100.vcxproj @@ -978,6 +978,7 @@ <ClInclude Include="..\src\script\api\script_types.hpp" /> <ClInclude Include="..\src\script\api\script_vehicle.hpp" /> <ClInclude Include="..\src\script\api\script_vehiclelist.hpp" /> + <ClInclude Include="..\src\script\api\script_viewport.hpp" /> <ClInclude Include="..\src\script\api\script_waypoint.hpp" /> <ClInclude Include="..\src\script\api\script_waypointlist.hpp" /> <ClCompile Include="..\src\script\api\script_accounting.cpp" /> @@ -1031,6 +1032,7 @@ <ClCompile Include="..\src\script\api\script_tunnel.cpp" /> <ClCompile Include="..\src\script\api\script_vehicle.cpp" /> <ClCompile Include="..\src\script\api\script_vehiclelist.cpp" /> + <ClCompile Include="..\src\script\api\script_viewport.cpp" /> <ClCompile Include="..\src\script\api\script_waypoint.cpp" /> <ClCompile Include="..\src\script\api\script_waypointlist.cpp" /> <ClCompile Include="..\src\blitter\32bpp_anim.cpp" />
--- a/projects/openttd_vs100.vcxproj.filters +++ b/projects/openttd_vs100.vcxproj.filters @@ -2163,6 +2163,9 @@ <ClInclude Include="..\src\script\api\script_vehiclelist.hpp"> <Filter>Script API</Filter> </ClInclude> + <ClInclude Include="..\src\script\api\script_viewport.hpp"> + <Filter>Script API</Filter> + </ClInclude> <ClInclude Include="..\src\script\api\script_waypoint.hpp"> <Filter>Script API</Filter> </ClInclude> @@ -2322,6 +2325,9 @@ <ClCompile Include="..\src\script\api\script_vehiclelist.cpp"> <Filter>Script API Implementation</Filter> </ClCompile> + <ClCompile Include="..\src\script\api\script_viewport.cpp"> + <Filter>Script API Implementation</Filter> + </ClCompile> <ClCompile Include="..\src\script\api\script_waypoint.cpp"> <Filter>Script API Implementation</Filter> </ClCompile>
--- a/projects/openttd_vs80.vcproj +++ b/projects/openttd_vs80.vcproj @@ -3247,6 +3247,10 @@ > </File> <File + RelativePath=".\..\src\script\api\script_viewport.hpp" + > + </File> + <File RelativePath=".\..\src\script\api\script_waypoint.hpp" > </File> @@ -3463,6 +3467,10 @@ > </File> <File + RelativePath=".\..\src\script\api\script_viewport.cpp" + > + </File> + <File RelativePath=".\..\src\script\api\script_waypoint.cpp" > </File>
--- a/projects/openttd_vs90.vcproj +++ b/projects/openttd_vs90.vcproj @@ -3244,6 +3244,10 @@ > </File> <File + RelativePath=".\..\src\script\api\script_viewport.hpp" + > + </File> + <File RelativePath=".\..\src\script\api\script_waypoint.hpp" > </File> @@ -3460,6 +3464,10 @@ > </File> <File + RelativePath=".\..\src\script\api\script_viewport.cpp" + > + </File> + <File RelativePath=".\..\src\script\api\script_waypoint.cpp" > </File>
--- a/source.list +++ b/source.list @@ -756,6 +756,7 @@ script/api/script_types.hpp script/api/script_vehicle.hpp script/api/script_vehiclelist.hpp +script/api/script_viewport.hpp script/api/script_waypoint.hpp script/api/script_waypointlist.hpp @@ -811,6 +812,7 @@ script/api/script_tunnel.cpp script/api/script_vehicle.cpp script/api/script_vehiclelist.cpp +script/api/script_viewport.cpp script/api/script_waypoint.cpp script/api/script_waypointlist.cpp
--- a/src/game/game_instance.cpp +++ b/src/game/game_instance.cpp @@ -70,6 +70,7 @@ #include "../script/api/game/game_tunnel.hpp.sq" #include "../script/api/game/game_vehicle.hpp.sq" #include "../script/api/game/game_vehiclelist.hpp.sq" +#include "../script/api/game/game_viewport.hpp.sq" #include "../script/api/game/game_waypoint.hpp.sq" #include "../script/api/game/game_waypointlist.hpp.sq" @@ -165,6 +166,7 @@ SQGSVehicleList_Depot_Register(this->engine); SQGSVehicleList_SharedOrders_Register(this->engine); SQGSVehicleList_Station_Register(this->engine); + SQGSViewport_Register(this->engine); SQGSWaypoint_Register(this->engine); SQGSWaypointList_Register(this->engine); SQGSWaypointList_Vehicle_Register(this->engine);
new file mode 100644 --- /dev/null +++ b/src/script/api/game/game_viewport.hpp.sq @@ -0,0 +1,27 @@ +/* $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 <http://www.gnu.org/licenses/>. + */ + +/* THIS FILE IS AUTO-GENERATED; PLEASE DO NOT ALTER MANUALLY */ + +#include "../script_viewport.hpp" +#include "../template/template_viewport.hpp.sq" + + +template <> const char *GetClassName<ScriptViewport, ST_GS>() { return "GSViewport"; } + +void SQGSViewport_Register(Squirrel *engine) +{ + DefSQClass<ScriptViewport, ST_GS> SQGSViewport("GSViewport"); + SQGSViewport.PreRegister(engine); + SQGSViewport.AddConstructor<void (ScriptViewport::*)(), 1>(engine, "x"); + + SQGSViewport.DefSQStaticMethod(engine, &ScriptViewport::ScrollTo, "ScrollTo", 2, ".i"); + + SQGSViewport.PostRegister(engine); +}
new file mode 100644 --- /dev/null +++ b/src/script/api/script_viewport.cpp @@ -0,0 +1,24 @@ +/* $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 <http://www.gnu.org/licenses/>. + */ + +/** @file script_viewport.cpp Implementation of ScriptViewport. */ + +#include "../../stdafx.h" +#include "script_viewport.hpp" +#include "script_game.hpp" +#include "script_map.hpp" +#include "../../viewport_func.h" + +/* static */ void ScriptViewport::ScrollTo(TileIndex tile) +{ + if (ScriptGame::IsMultiplayer()) return; + if (!ScriptMap::IsValidTile(tile)) return; + + ScrollMainWindowToTile(tile); +}
new file mode 100644 --- /dev/null +++ b/src/script/api/script_viewport.hpp @@ -0,0 +1,34 @@ +/* $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 <http://www.gnu.org/licenses/>. + */ + +/** @file script_viewport.hpp Everything to manipulate the users viewport. */ + +#ifndef SCRIPT_VIEWPORT_HPP +#define SCRIPT_VIEWPORT_HPP + +#include <string> +#include "script_object.hpp" + +/** + * Class that manipultes the users viewport. + * @api game + */ +class ScriptViewport : public ScriptObject { +public: + /** + * Scroll the viewport to the given tile, where the tile will be in the + * center of the screen. + * @param tile The tile to put in the center of the screen. + * @pre !ScriptGame::IsMultiplayer(). + * @pre ScriptMap::IsValidTile(tile). + */ + static void ScrollTo(TileIndex tile); +}; + +#endif /* SCRIPT_ADMIN_HPP */
new file mode 100644 --- /dev/null +++ b/src/script/api/template/template_viewport.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 <http://www.gnu.org/licenses/>. + */ + +/* THIS FILE IS AUTO-GENERATED; PLEASE DO NOT ALTER MANUALLY */ + +#include "../script_viewport.hpp" + +namespace SQConvert { + /* Allow ScriptViewport to be used as Squirrel parameter */ + template <> inline ScriptViewport *GetParam(ForceType<ScriptViewport *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (ScriptViewport *)instance; } + template <> inline ScriptViewport &GetParam(ForceType<ScriptViewport &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(ScriptViewport *)instance; } + template <> inline const ScriptViewport *GetParam(ForceType<const ScriptViewport *>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (ScriptViewport *)instance; } + template <> inline const ScriptViewport &GetParam(ForceType<const ScriptViewport &>, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(ScriptViewport *)instance; } + template <> inline int Return<ScriptViewport *>(HSQUIRRELVM vm, ScriptViewport *res) { if (res == NULL) { sq_pushnull(vm); return 1; } res->AddRef(); Squirrel::CreateClassInstanceVM(vm, "Viewport", res, NULL, DefSQDestructorCallback<ScriptViewport>, true); return 1; } +} // namespace SQConvert