Skip to content

Commit

Permalink
#5180: Move more camera movement key handling to inner classes
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed May 16, 2020
1 parent c64761c commit 120b2c0
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 16 deletions.
6 changes: 2 additions & 4 deletions install/input.xml
Expand Up @@ -90,16 +90,14 @@
<shortcut command="TogglePreview" key="F3" />
<shortcut command="CameraMoveForward" key="Up" />
<shortcut command="CameraMoveBack" key="Down" />
<shortcut command="CameraLeft" key="Left" />
<shortcut command="CameraRight" key="Right" />
<shortcut command="CameraMoveLeft" key="Left" />
<shortcut command="CameraMoveRight" key="Right" />
<shortcut command="CameraStrafeRight" key="period" />
<shortcut command="CameraStrafeLeft" key="comma" />
<shortcut command="CameraUp" key="D" />
<shortcut command="CameraDown" key="C" />
<shortcut command="CameraAngleUp" key="A" />
<shortcut command="CameraAngleDown" key="Z" />
<shortcut command="CameraFreeMoveLeft" key="Left" />
<shortcut command="CameraFreeMoveRight" key="Right" />
<shortcut command="Brush3Sided" key="3" modifiers="CONTROL" />
<shortcut command="Brush4Sided" key="4" modifiers="CONTROL" />
<shortcut command="Brush5Sided" key="5" modifiers="CONTROL" />
Expand Down
50 changes: 44 additions & 6 deletions radiant/camera/Camera.cpp
Expand Up @@ -350,13 +350,13 @@ void Camera::onForwardKey(ui::KeyEventType eventType)
{
if (eventType == ui::KeyEventType::KeyPressed)
{
if (!freeMoveEnabled)
if (freeMoveEnabled)
{
moveForwardDiscrete();
setMovementFlags(MOVE_FORWARD);
}
else
{
setMovementFlags(MOVE_FORWARD);
moveForwardDiscrete();
}
}
else if (freeMoveEnabled)
Expand All @@ -369,13 +369,13 @@ void Camera::onBackwardKey(ui::KeyEventType eventType)
{
if (eventType == ui::KeyEventType::KeyPressed)
{
if (!freeMoveEnabled)
if (freeMoveEnabled)
{
moveBackDiscrete();
setMovementFlags(MOVE_BACK);
}
else
{
setMovementFlags(MOVE_BACK);
moveBackDiscrete();
}
}
else if (freeMoveEnabled)
Expand All @@ -384,4 +384,42 @@ void Camera::onBackwardKey(ui::KeyEventType eventType)
}
}

void Camera::onLeftKey(ui::KeyEventType eventType)
{
if (eventType == ui::KeyEventType::KeyPressed)
{
if (freeMoveEnabled)
{
setMovementFlags(MOVE_STRAFELEFT);
}
else
{
rotateLeftDiscrete();
}
}
else if (freeMoveEnabled)
{
clearMovementFlags(MOVE_STRAFELEFT);
}
}

void Camera::onRightKey(ui::KeyEventType eventType)
{
if (eventType == ui::KeyEventType::KeyPressed)
{
if (freeMoveEnabled)
{
setMovementFlags(MOVE_STRAFERIGHT);
}
else
{
rotateRightDiscrete();
}
}
else if (freeMoveEnabled)
{
clearMovementFlags(MOVE_STRAFERIGHT);
}
}

} // namespace
2 changes: 2 additions & 0 deletions radiant/camera/Camera.h
Expand Up @@ -114,6 +114,8 @@ class Camera :

void onForwardKey(ui::KeyEventType eventType);
void onBackwardKey(ui::KeyEventType eventType);
void onLeftKey(ui::KeyEventType eventType);
void onRightKey(ui::KeyEventType eventType);

}; // class Camera

Expand Down
18 changes: 12 additions & 6 deletions radiant/camera/GlobalCamera.cpp
Expand Up @@ -81,8 +81,8 @@ void GlobalCameraManager::registerCommands()

GlobalEventManager().addKeyEvent("CameraMoveForward", std::bind(&GlobalCameraManager::onFreelookMoveForwardKey, this, std::placeholders::_1));
GlobalEventManager().addKeyEvent("CameraMoveBack", std::bind(&GlobalCameraManager::onFreelookMoveBackKey, this, std::placeholders::_1));
GlobalEventManager().addKeyEvent("CameraFreeMoveLeft", std::bind(&GlobalCameraManager::onFreelookMoveLeftKey, this, std::placeholders::_1));
GlobalEventManager().addKeyEvent("CameraFreeMoveRight", std::bind(&GlobalCameraManager::onFreelookMoveRightKey, this, std::placeholders::_1));
GlobalEventManager().addKeyEvent("CameraMoveLeft", std::bind(&GlobalCameraManager::onFreelookMoveLeftKey, this, std::placeholders::_1));
GlobalEventManager().addKeyEvent("CameraMoveRight", std::bind(&GlobalCameraManager::onFreelookMoveRightKey, this, std::placeholders::_1));
GlobalEventManager().addKeyEvent("CameraFreeMoveUp", std::bind(&GlobalCameraManager::onFreelookMoveUpKey, this, std::placeholders::_1));
GlobalEventManager().addKeyEvent("CameraFreeMoveDown", std::bind(&GlobalCameraManager::onFreelookMoveDownKey, this, std::placeholders::_1));
}
Expand Down Expand Up @@ -355,9 +355,11 @@ void GlobalCameraManager::onFreelookMoveBackKey(ui::KeyEventType eventType)

void GlobalCameraManager::onFreelookMoveLeftKey(ui::KeyEventType eventType)
{
CamWndPtr camWnd = getActiveCamWnd();
if (camWnd == NULL) return;
auto camWnd = getActiveCamWnd();
if (!camWnd) return;

camWnd->getCamera().onLeftKey(eventType);
#if 0
if (eventType == ui::KeyPressed)
{
camWnd->getCamera().setMovementFlags(MOVE_STRAFELEFT);
Expand All @@ -366,13 +368,16 @@ void GlobalCameraManager::onFreelookMoveLeftKey(ui::KeyEventType eventType)
{
camWnd->getCamera().clearMovementFlags(MOVE_STRAFELEFT);
}
#endif
}

void GlobalCameraManager::onFreelookMoveRightKey(ui::KeyEventType eventType)
{
CamWndPtr camWnd = getActiveCamWnd();
if (camWnd == NULL) return;
auto camWnd = getActiveCamWnd();
if (!camWnd) return;

camWnd->getCamera().onRightKey(eventType);
#if 0
if (eventType == ui::KeyPressed)
{
camWnd->getCamera().setMovementFlags(MOVE_STRAFERIGHT);
Expand All @@ -381,6 +386,7 @@ void GlobalCameraManager::onFreelookMoveRightKey(ui::KeyEventType eventType)
{
camWnd->getCamera().clearMovementFlags(MOVE_STRAFERIGHT);
}
#endif
}

void GlobalCameraManager::onFreelookMoveUpKey(ui::KeyEventType eventType)
Expand Down

0 comments on commit 120b2c0

Please sign in to comment.