From 5d20bf1a9edc259f3c75e9167df6de43bc7f93d1 Mon Sep 17 00:00:00 2001 From: Rampoina Date: Tue, 2 Aug 2022 11:21:06 +0200 Subject: [PATCH] Add camera location hotkeys --- mk/shared/glestkeys.ini | 12 ++++++++---- source/glest_game/game/game.cpp | 12 ++++++++++++ source/glest_game/game/game_camera.h | 5 +++++ 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/mk/shared/glestkeys.ini b/mk/shared/glestkeys.ini index a3018425a..16f62a196 100644 --- a/mk/shared/glestkeys.ini +++ b/mk/shared/glestkeys.ini @@ -26,6 +26,10 @@ GroupUnitsKey7='6' GroupUnitsKey8='7' GroupUnitsKey9='8' GroupUnitsKey10='9' +CameraLocationKey1=f1 +CameraLocationKey2=f2 +CameraLocationKey3=f3 +CameraLocationKey4=f4 CameraRotateLeft=A CameraRotateRight=D CameraRotateUp=S @@ -47,11 +51,11 @@ ToggleMusic=K SaveGUILayout=f10 SetMarker=X ReloadINI=f5 -TogglePhotoMode=f8 +TogglePhotoMode=f6 SwitchLanguage=L SaveGame=f11 -BookmarkAdd=f2 -BookmarkRemove=f3 -CameraFollowSelectedUnit=f4 +BookmarkAdd=f7 +BookmarkRemove=f8 +CameraFollowSelectedUnit=f9 ; === propertyMap File === diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index 178f68b4e..8ea92dd47 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -4890,6 +4890,18 @@ void Game::keyDown(SDL_KeyboardEvent key) { //hotkeys if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] gameCamera.getState() = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,gameCamera.getState()); + for (int i = 0; i < 4; i++) { + string keyName = "CameraLocationKey" + intToStr(i+1); + + if (isKeyPressed(configKeys.getSDLKey(keyName.c_str()),key) == true) { + if (isKeyDown(vkControl)) { + gameCamera.saveLocation(i); + } else { + gameCamera.restoreLocation(i); + } + } + } + if(gameCamera.getState() != GameCamera::sFree){ if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] key = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,key); diff --git a/source/glest_game/game/game_camera.h b/source/glest_game/game/game_camera.h index 68a3cd88f..866f0b749 100644 --- a/source/glest_game/game/game_camera.h +++ b/source/glest_game/game/game_camera.h @@ -60,6 +60,7 @@ class GameCamera { }; private: + map locations; Vec3f pos; Vec3f destPos; Vec2f shakeOffset; @@ -175,6 +176,9 @@ class GameCamera { void saveGame(XmlNode *rootNode); void loadGame(const XmlNode *rootNode); + void restoreLocation(int i) { try { setPos(locations.at(i)); } catch (const std::out_of_range& oor) {} } + void saveLocation(int i) { locations[i] = Vec2f(getPos().x,getPos().z); } + private: //void setClampBounds(bool value) { clampBounds = value; } void resetPosition(); @@ -185,6 +189,7 @@ class GameCamera { void moveUp(float dist); void rotateHV(float h, float v); void shakeCamera(); + }; }} //end namespace