diff --git a/binaries/data/mods/public/gui/session/input.js b/binaries/data/mods/public/gui/session/input.js index aca2e7b30f..89c3674562 100644 --- a/binaries/data/mods/public/gui/session/input.js +++ b/binaries/data/mods/public/gui/session/input.js @@ -739,6 +739,12 @@ function handleInputAfterGui(ev) var selectedEntity = ents[0]; var now = new Date(); + + // If camera following and we select different unit, stop + if (Engine.GetFollowedEntity() != selectedEntity) + { + Engine.CameraFollow(0); + } if ((now.getTime() - doubleClickTimer < doubleClickTime) && (selectedEntity == prevClickedEntity)) { diff --git a/source/graphics/GameView.cpp b/source/graphics/GameView.cpp index 3027ea97bd..6ae9953c58 100644 --- a/source/graphics/GameView.cpp +++ b/source/graphics/GameView.cpp @@ -958,6 +958,11 @@ void CGameView::CameraFollow(entity_id_t entity, bool firstPerson) m->FollowFirstPerson = firstPerson; } +entity_id_t CGameView::GetFollowedEntity() +{ + return m->FollowEntity; +} + InReaction game_view_handler(const SDL_Event_* ev) { // put any events that must be processed even if inactive here diff --git a/source/graphics/GameView.h b/source/graphics/GameView.h index 9249756793..0549e8f6a4 100644 --- a/source/graphics/GameView.h +++ b/source/graphics/GameView.h @@ -86,6 +86,7 @@ public: void ResetCameraTarget(const CVector3D& target); void ResetCameraAngleZoom(); void CameraFollow(entity_id_t entity, bool firstPerson); + entity_id_t GetFollowedEntity(); CCamera *GetCamera(); CCinemaManager* GetCinema(); diff --git a/source/gui/scripting/ScriptFunctions.cpp b/source/gui/scripting/ScriptFunctions.cpp index 4b8b211f00..0054246f6c 100644 --- a/source/gui/scripting/ScriptFunctions.cpp +++ b/source/gui/scripting/ScriptFunctions.cpp @@ -346,6 +346,14 @@ void CameraFollowFPS(void* UNUSED(cbdata), entity_id_t entityid) g_Game->GetView()->CameraFollow(entityid, true); } +entity_id_t GetFollowedEntity(void* UNUSED(cbdata)) +{ + if (g_Game && g_Game->GetView()) + return g_Game->GetView()->GetFollowedEntity(); + + return INVALID_ENTITY; +} + bool HotkeyIsPressed_(void* UNUSED(cbdata), std::string hotkeyName) { return HotkeyIsPressed(hotkeyName); @@ -491,6 +499,7 @@ void GuiScriptingInit(ScriptInterface& scriptInterface) scriptInterface.RegisterFunction("GetMapSettings"); scriptInterface.RegisterFunction("CameraFollow"); scriptInterface.RegisterFunction("CameraFollowFPS"); + scriptInterface.RegisterFunction("GetFollowedEntity"); scriptInterface.RegisterFunction("HotkeyIsPressed"); scriptInterface.RegisterFunction("DisplayErrorDialog"); scriptInterface.RegisterFunction("GetProfilerState");