From 894216083d3f0b7c01ad705c253723e948297138 Mon Sep 17 00:00:00 2001 From: truebrain Date: Mon, 19 Dec 2011 21:00:48 +0000 Subject: (svn r23625) -Add: ScriptViewport::ScrollTo, for SinglePlayer only (GameScript only) --- projects/openttd_vs100.vcxproj | 2 ++ projects/openttd_vs100.vcxproj.filters | 6 +++++ projects/openttd_vs80.vcproj | 8 ++++++ projects/openttd_vs90.vcproj | 8 ++++++ source.list | 2 ++ src/game/game_instance.cpp | 2 ++ src/script/api/game/game_viewport.hpp.sq | 27 +++++++++++++++++++ src/script/api/script_viewport.cpp | 24 +++++++++++++++++ src/script/api/script_viewport.hpp | 34 ++++++++++++++++++++++++ src/script/api/template/template_viewport.hpp.sq | 21 +++++++++++++++ 10 files changed, 134 insertions(+) create mode 100644 src/script/api/game/game_viewport.hpp.sq create mode 100644 src/script/api/script_viewport.cpp create mode 100644 src/script/api/script_viewport.hpp create mode 100644 src/script/api/template/template_viewport.hpp.sq diff --git a/projects/openttd_vs100.vcxproj b/projects/openttd_vs100.vcxproj index e1371b22c..a6cbf696e 100644 --- a/projects/openttd_vs100.vcxproj +++ b/projects/openttd_vs100.vcxproj @@ -978,6 +978,7 @@ + @@ -1031,6 +1032,7 @@ + diff --git a/projects/openttd_vs100.vcxproj.filters b/projects/openttd_vs100.vcxproj.filters index 6299a1ae7..66ac17eef 100644 --- a/projects/openttd_vs100.vcxproj.filters +++ b/projects/openttd_vs100.vcxproj.filters @@ -2163,6 +2163,9 @@ Script API + + Script API + Script API @@ -2322,6 +2325,9 @@ Script API Implementation + + Script API Implementation + Script API Implementation diff --git a/projects/openttd_vs80.vcproj b/projects/openttd_vs80.vcproj index 7b1b4cc77..b07dcdd43 100644 --- a/projects/openttd_vs80.vcproj +++ b/projects/openttd_vs80.vcproj @@ -3246,6 +3246,10 @@ RelativePath=".\..\src\script\api\script_vehiclelist.hpp" > + + @@ -3462,6 +3466,10 @@ RelativePath=".\..\src\script\api\script_vehiclelist.cpp" > + + diff --git a/projects/openttd_vs90.vcproj b/projects/openttd_vs90.vcproj index 2805a759d..465f3658e 100644 --- a/projects/openttd_vs90.vcproj +++ b/projects/openttd_vs90.vcproj @@ -3243,6 +3243,10 @@ RelativePath=".\..\src\script\api\script_vehiclelist.hpp" > + + @@ -3459,6 +3463,10 @@ RelativePath=".\..\src\script\api\script_vehiclelist.cpp" > + + diff --git a/source.list b/source.list index 3578314a2..8b83002a9 100644 --- a/source.list +++ b/source.list @@ -756,6 +756,7 @@ script/api/script_tunnel.hpp 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_townlist.cpp 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 diff --git a/src/game/game_instance.cpp b/src/game/game_instance.cpp index 872c4829c..998788b61 100644 --- 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 @@ void GameInstance::RegisterAPI() 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); diff --git a/src/script/api/game/game_viewport.hpp.sq b/src/script/api/game/game_viewport.hpp.sq new file mode 100644 index 000000000..d313f0d75 --- /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 . + */ + +/* THIS FILE IS AUTO-GENERATED; PLEASE DO NOT ALTER MANUALLY */ + +#include "../script_viewport.hpp" +#include "../template/template_viewport.hpp.sq" + + +template <> const char *GetClassName() { return "GSViewport"; } + +void SQGSViewport_Register(Squirrel *engine) +{ + DefSQClass SQGSViewport("GSViewport"); + SQGSViewport.PreRegister(engine); + SQGSViewport.AddConstructor(engine, "x"); + + SQGSViewport.DefSQStaticMethod(engine, &ScriptViewport::ScrollTo, "ScrollTo", 2, ".i"); + + SQGSViewport.PostRegister(engine); +} diff --git a/src/script/api/script_viewport.cpp b/src/script/api/script_viewport.cpp new file mode 100644 index 000000000..139edb029 --- /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 . + */ + +/** @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); +} diff --git a/src/script/api/script_viewport.hpp b/src/script/api/script_viewport.hpp new file mode 100644 index 000000000..1d66c09b3 --- /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 . + */ + +/** @file script_viewport.hpp Everything to manipulate the users viewport. */ + +#ifndef SCRIPT_VIEWPORT_HPP +#define SCRIPT_VIEWPORT_HPP + +#include +#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 */ diff --git a/src/script/api/template/template_viewport.hpp.sq b/src/script/api/template/template_viewport.hpp.sq new file mode 100644 index 000000000..8a187ae81 --- /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 . + */ + +/* 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, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (ScriptViewport *)instance; } + template <> inline ScriptViewport &GetParam(ForceType, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(ScriptViewport *)instance; } + template <> inline const ScriptViewport *GetParam(ForceType, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (ScriptViewport *)instance; } + template <> inline const ScriptViewport &GetParam(ForceType, HSQUIRRELVM vm, int index, SQAutoFreePointers *ptr) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(ScriptViewport *)instance; } + template <> inline int Return(HSQUIRRELVM vm, ScriptViewport *res) { if (res == NULL) { sq_pushnull(vm); return 1; } res->AddRef(); Squirrel::CreateClassInstanceVM(vm, "Viewport", res, NULL, DefSQDestructorCallback, true); return 1; } +} // namespace SQConvert -- cgit v1.2.3-54-g00ecf