From 6f3a0e1378766b15bd0030dd1dbbd9a201d0ae3e Mon Sep 17 00:00:00 2001 From: alpha123 Date: Sun, 9 Jun 2013 20:21:19 +0000 Subject: [PATCH] Implement location hotkeys. Fix #1882. This was SVN commit r13463. --- binaries/data/config/default.cfg | 23 ++++++ .../data/mods/public/gui/manual/intro.txt | 2 + .../data/mods/public/gui/session/input.js | 27 +++++++ .../data/mods/public/gui/session/session.xml | 81 +++++++++++++++++++ source/graphics/GameView.cpp | 14 ++++ source/graphics/GameView.h | 2 + source/gui/scripting/ScriptFunctions.cpp | 22 +++++ 7 files changed, 171 insertions(+) diff --git a/binaries/data/config/default.cfg b/binaries/data/config/default.cfg index e01335c2e1..7249308c9b 100644 --- a/binaries/data/config/default.cfg +++ b/binaries/data/config/default.cfg @@ -151,6 +151,9 @@ view.fov = 45.0 ; Field of view (degrees), lower is view.height.smoothness = 0.5 view.height.min = 16 +; How close do we have to be to the actual location in order to jump back to the previous one? +camerajump.threshold = 40 + ; HOTKEY MAPPINGS: ; Each one of the specified keys will trigger the action on the left @@ -194,6 +197,26 @@ hotkey.camera.rotate.speed.increase = "Ctrl+Shift+R" ; Increase rotation hotkey.camera.rotate.speed.decrease = "Ctrl+Alt+R" ; Decrease rotation speed hotkey.camera.zoom.speed.increase = "Ctrl+Shift+Z" ; Increase zoom speed hotkey.camera.zoom.speed.decrease = "Ctrl+Alt+Z" ; Decrease zoom speed +hotkey.camera.jump.1 = F5 ; Jump to position N +hotkey.camera.jump.2 = F6 +hotkey.camera.jump.3 = F7 +hotkey.camera.jump.4 = F8 +;hotkey.camera.jump.5 = +;hotkey.camera.jump.6 = +;hotkey.camera.jump.7 = +;hotkey.camera.jump.8 = +;hotkey.camera.jump.9 = +;hotkey.camera.jump.10 = +hotkey.camera.jump.set.1 = "Ctrl+F5" ; Set jump position N +hotkey.camera.jump.set.2 = "Ctrl+F6" +hotkey.camera.jump.set.3 = "Ctrl+F7" +hotkey.camera.jump.set.4 = "Ctrl+F8" +;hotkey.camera.jump.set.5 = +;hotkey.camera.jump.set.6 = +;hotkey.camera.jump.set.7 = +;hotkey.camera.jump.set.8 = +;hotkey.camera.jump.set.9 = +;hotkey.camera.jump.set.10 = ; > CONSOLE SETTINGS hotkey.console.toggle = BackQuote, F9 ; Open/close console diff --git a/binaries/data/mods/public/gui/manual/intro.txt b/binaries/data/mods/public/gui/manual/intro.txt index b7e3f79a70..2a31b9a5b2 100644 --- a/binaries/data/mods/public/gui/manual/intro.txt +++ b/binaries/data/mods/public/gui/manual/intro.txt @@ -66,6 +66,8 @@ H: Stop (halt) the currently selected units. Ctrl + 1 (and so on up to Ctrl + 0): Create control group 1 (to 0) from the selected units/buildings 1 (and so on up to 0): Select the units/buildings in control group 1 (to 0) Shift + 1 (to 0): Add selected units/buildings to control group 1 (to 0) +Ctrl + F5 (and so on up to F8): Mark the current camera position, for jumping back to later. +F5, F6, F7, and F8: Move the camera to a marked position. Jump back to the last location if the camera is already over the marked position. Z, X, C, V, B, N, M: With training buildings selected. Add the 1st, 2nd, ... unit shown to the training queue for all the selected buildings. [font="serif-bold-14"]Modify mouse action diff --git a/binaries/data/mods/public/gui/session/input.js b/binaries/data/mods/public/gui/session/input.js index 6b4518f48d..6f0c173f7f 100644 --- a/binaries/data/mods/public/gui/session/input.js +++ b/binaries/data/mods/public/gui/session/input.js @@ -1508,6 +1508,33 @@ function exchangeResources(command) Engine.PostNetworkCommand({"type": "barter", "sell": command.sell, "buy": command.buy, "amount": command.amount}); } +// Camera jumping: when the user presses a hotkey the current camera location is marked. +// When they press another hotkey the camera jumps back to that position. If the camera is already roughly at that location, +// jump back to where it was previously. +var jumpCameraPositions = [], jumpCameraLast; + +function jumpCamera(index) +{ + var position = jumpCameraPositions[index], distanceThreshold = g_ConfigDB.system["camerajump.threshold"]; + if (position) + { + if (jumpCameraLast && + Math.abs(Engine.CameraGetX() - position.x) < distanceThreshold && + Math.abs(Engine.CameraGetZ() - position.z) < distanceThreshold) + Engine.CameraMoveTo(jumpCameraLast.x, jumpCameraLast.z); + else + { + jumpCameraLast = {x: Engine.CameraGetX(), z: Engine.CameraGetZ()}; + Engine.CameraMoveTo(position.x, position.z); + } + } +} + +function setJumpCamera(index) +{ + jumpCameraPositions[index] = {x: Engine.CameraGetX(), z: Engine.CameraGetZ()}; +} + // Batch training: // When the user shift-clicks, we set these variables and switch to INPUT_BATCHTRAINING // When the user releases shift, or clicks on a different training button, we create the batched units diff --git a/binaries/data/mods/public/gui/session/session.xml b/binaries/data/mods/public/gui/session/session.xml index be259646de..e2a17068c7 100644 --- a/binaries/data/mods/public/gui/session/session.xml +++ b/binaries/data/mods/public/gui/session/session.xml @@ -96,6 +96,87 @@ setCameraFollow(g_Selection.toList()[0]); + + + + jumpCamera(1); + + + + jumpCamera(2); + + + + jumpCamera(3); + + + + jumpCamera(4); + + + + jumpCamera(5); + + + + jumpCamera(6); + + + + jumpCamera(7); + + + + jumpCamera(8); + + + + jumpCamera(9); + + + + jumpCamera(10); + + + + setJumpCamera(1); + + + + setJumpCamera(2); + + + + setJumpCamera(3); + + + + setJumpCamera(4); + + + + setJumpCamera(5); + + + + setJumpCamera(6); + + + + setJumpCamera(7); + + + + setJumpCamera(8); + + + + setJumpCamera(9); + + + + setJumpCamera(10); + diff --git a/source/graphics/GameView.cpp b/source/graphics/GameView.cpp index e36a3d3cf1..ed5909afa9 100644 --- a/source/graphics/GameView.cpp +++ b/source/graphics/GameView.cpp @@ -954,6 +954,20 @@ void CGameView::Update(const float deltaRealTime) m->ViewCamera.UpdateFrustum(); } +float CGameView::GetCameraX() +{ + CCamera targetCam = m->ViewCamera; + CVector3D pivot = GetSmoothPivot(targetCam); + return pivot.X; +} + +float CGameView::GetCameraZ() +{ + CCamera targetCam = m->ViewCamera; + CVector3D pivot = GetSmoothPivot(targetCam); + return pivot.Z; +} + void CGameView::MoveCameraTarget(const CVector3D& target) { // Maintain the same orientation and level of zoom, if we can diff --git a/source/graphics/GameView.h b/source/graphics/GameView.h index 9f214ab501..c64f799f84 100644 --- a/source/graphics/GameView.h +++ b/source/graphics/GameView.h @@ -82,6 +82,8 @@ public: InReaction HandleEvent(const SDL_Event_* ev); + float GetCameraX(); + float GetCameraZ(); void MoveCameraTarget(const CVector3D& target); void ResetCameraTarget(const CVector3D& target); void ResetCameraAngleZoom(); diff --git a/source/gui/scripting/ScriptFunctions.cpp b/source/gui/scripting/ScriptFunctions.cpp index 9cea68ec9e..dd530cb689 100644 --- a/source/gui/scripting/ScriptFunctions.cpp +++ b/source/gui/scripting/ScriptFunctions.cpp @@ -421,6 +421,26 @@ CScriptVal GetMapSettings(void* cbdata) g_Game->GetSimulation2()->GetMapSettings().get()); } +/** + * Get the current X coordinate of the camera. + */ +float CameraGetX(void* UNUSED(cbdata)) +{ + if (g_Game && g_Game->GetView()) + return g_Game->GetView()->GetCameraX(); + return -1; +} + +/** + * Get the current Z coordinate of the camera. + */ +float CameraGetZ(void* UNUSED(cbdata)) +{ + if (g_Game && g_Game->GetView()) + return g_Game->GetView()->GetCameraZ(); + return -1; +} + /** * Start / stop camera following mode * @param entityid unit id to follow. If zero, stop following mode @@ -665,6 +685,8 @@ void GuiScriptingInit(ScriptInterface& scriptInterface) scriptInterface.RegisterFunction("IsAtlasRunning"); scriptInterface.RegisterFunction("LoadMapSettings"); scriptInterface.RegisterFunction("GetMapSettings"); + scriptInterface.RegisterFunction("CameraGetX"); + scriptInterface.RegisterFunction("CameraGetZ"); scriptInterface.RegisterFunction("CameraFollow"); scriptInterface.RegisterFunction("CameraFollowFPS"); scriptInterface.RegisterFunction("CameraMoveTo");