Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add camera location hotkeys #227

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions mk/shared/glestkeys.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 ===

12 changes: 12 additions & 0 deletions source/glest_game/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
5 changes: 5 additions & 0 deletions source/glest_game/game/game_camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class GameCamera {
};

private:
map <int,Vec2f> locations;
Vec3f pos;
Vec3f destPos;
Vec2f shakeOffset;
Expand Down Expand Up @@ -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();
Expand All @@ -185,6 +189,7 @@ class GameCamera {
void moveUp(float dist);
void rotateHV(float h, float v);
void shakeCamera();

};

}} //end namespace
Expand Down