diff --git a/Source/Game/CameraManager.cpp b/Source/Game/CameraManager.cpp index a46a7c73..535243c7 100644 --- a/Source/Game/CameraManager.cpp +++ b/Source/Game/CameraManager.cpp @@ -280,35 +280,35 @@ void terCameraType::controlQuant() // cameraMouseZoom = isPressed(VK_LBUTTON) && isPressed(VK_RBUTTON); if(!unit_follow){ - if(g_controls_converter.key(CTRL_CAMERA_MOVE_DOWN).pressed()) + if(g_controls_converter.pressed(CTRL_CAMERA_MOVE_DOWN)) cameraPositionForce.y = CAMERA_SCROLL_SPEED_DELTA; - if(g_controls_converter.key(CTRL_CAMERA_MOVE_UP).pressed()) + if(g_controls_converter.pressed(CTRL_CAMERA_MOVE_UP)) cameraPositionForce.y = -CAMERA_SCROLL_SPEED_DELTA; - if(g_controls_converter.key(CTRL_CAMERA_MOVE_RIGHT).pressed()) + if(g_controls_converter.pressed(CTRL_CAMERA_MOVE_RIGHT)) cameraPositionForce.x = CAMERA_SCROLL_SPEED_DELTA; - if(g_controls_converter.key(CTRL_CAMERA_MOVE_LEFT).pressed()) + if(g_controls_converter.pressed(CTRL_CAMERA_MOVE_LEFT)) cameraPositionForce.x = -CAMERA_SCROLL_SPEED_DELTA; } - if(g_controls_converter.key(CTRL_CAMERA_ROTATE_UP).pressed()) + if(g_controls_converter.pressed(CTRL_CAMERA_ROTATE_UP)) cameraThetaForce = -CAMERA_KBD_ANGLE_SPEED_DELTA; - if(g_controls_converter.key(CTRL_CAMERA_ROTATE_DOWN).pressed()) + if(g_controls_converter.pressed(CTRL_CAMERA_ROTATE_DOWN)) cameraThetaForce = CAMERA_KBD_ANGLE_SPEED_DELTA; - if(g_controls_converter.key(CTRL_CAMERA_ROTATE_LEFT).pressed()) + if(g_controls_converter.pressed(CTRL_CAMERA_ROTATE_LEFT)) cameraPsiForce = CAMERA_KBD_ANGLE_SPEED_DELTA; - if(g_controls_converter.key(CTRL_CAMERA_ROTATE_RIGHT).pressed()) + if(g_controls_converter.pressed(CTRL_CAMERA_ROTATE_RIGHT)) cameraPsiForce = -CAMERA_KBD_ANGLE_SPEED_DELTA; - if(g_controls_converter.key(CTRL_CAMERA_ZOOM_INC).pressed()) + if(g_controls_converter.pressed(CTRL_CAMERA_ZOOM_INC)) cameraZoomForce = -CAMERA_ZOOM_SPEED_DELTA; - if(g_controls_converter.key(CTRL_CAMERA_ZOOM_DEC).pressed()) + if(g_controls_converter.pressed(CTRL_CAMERA_ZOOM_DEC)) cameraZoomForce = CAMERA_ZOOM_SPEED_DELTA; } @@ -401,22 +401,25 @@ bool terCameraType::cursorTrace(const Vect2f& pos2, Vect3f& v) return terScene->Trace(pos,pos+dir,&v); } -void terCameraType::shift(const Vect2f& mouseDelta) +bool terCameraType::shift(const Vect2f& mouseDelta) { - if (gameShell->isCutSceneMode()) { - return; - } - if(interpolationTimer_ || unit_follow) - return; + return shift(Vect2f::ZERO, mouseDelta); +} - Vect2f delta = mouseDelta; - Vect3f v1, v2; - if(cursorTrace(Vect2f::ZERO, v1) && cursorTrace(delta, v2)) - delta = v2 - v1; - else - delta = Vect2f::ZERO; - - coordinate().position() -= to3D(delta, 0); +bool terCameraType::shift(const Vect2f& pos1, const Vect2f pos2) { + if (gameShell->isCutSceneMode()) { + return false; + } + if(interpolationTimer_ || unit_follow) + return false; + + Vect3f v1, v2; + if (cursorTrace(pos1, v1) && cursorTrace(pos2, v2)) { + auto delta = v2 - v1; + coordinate().position() -= to3D(delta, 0); + return true; + } + return false; } void terCameraType::mouseWheel(int delta) diff --git a/Source/Game/CameraManager.h b/Source/Game/CameraManager.h index cc2cb751..938212ee 100644 --- a/Source/Game/CameraManager.h +++ b/Source/Game/CameraManager.h @@ -53,7 +53,10 @@ class terCameraType void reset(); void setFocus(float focus); - void setCoordinate(const CameraCoordinate& coord) { coordinate_ = coord; update(); } + void setCoordinate(const CameraCoordinate& coord) { + coordinate_ = coord; + update(); + } float focus() const { return focus_; } const CameraCoordinate& coordinate() const { return coordinate_; } @@ -74,7 +77,8 @@ class terCameraType void mouseQuant(const Vect2f& mousePos); void tilt(Vect2f mouseDelta); - void shift(const Vect2f& mouseDelta); + bool shift(const Vect2f& mouseDelta); + bool shift(const Vect2f& pos1, const Vect2f pos2); void controlQuant(); void mouseWheel(int delta); void quant(float mouseDeltaX, float mouseDeltaY, float delta_time, bool tilting); diff --git a/Source/UserInterface/Controls.h b/Source/UserInterface/Controls.h index 68914f84..a19613e7 100644 --- a/Source/UserInterface/Controls.h +++ b/Source/UserInterface/Controls.h @@ -45,7 +45,7 @@ enum eGameKeysControl CTRL_MAX }; -class ControlsConverter +class ControlsConverter { unsigned char KeyToCtrl[2048]; // таблица перехода от кнопок в команды sKey CtrlToKey[CTRL_MAX]; // таблица перехода от команд к кнопкам @@ -61,7 +61,7 @@ class ControlsConverter const std::string& declaration(int ctrl) const { return CtrlToDeclaration[ctrl]; } const std::string& name(int key) const { return KeyToName[key]; } unsigned char control(int key) const { return KeyToCtrl[key]; } - const sKey& key(int ctrl) const { return CtrlToKey[ctrl]; } + bool pressed(int ctrl) const; }; extern ControlsConverter g_controls_converter; diff --git a/Source/UserInterface/GameShell.cpp b/Source/UserInterface/GameShell.cpp index 6102e918..342e38b2 100644 --- a/Source/UserInterface/GameShell.cpp +++ b/Source/UserInterface/GameShell.cpp @@ -1762,12 +1762,7 @@ void GameShell::ControlPressed(int key) break; case CTRL_CAMERA_MAP_SHIFT: - if(!cameraMouseShift){ - cameraMouseShift = true; - _shellCursorManager.HideCursor(); - - terCamera->cursorTrace(mousePosition(), mapMoveStartPoint_); - } + setCameraMouseShift(true); break; case CTRL_CAMERA_TO_EVENT: @@ -1948,6 +1943,13 @@ void GameShell::MouseLeftPressed(const Vect2f& pos) mousePositionDelta_ = pos - mousePosition(); mousePosition_= pos; + if (cameraMouseShift) { + mapMoveCursorStartPoint_ = mousePosition(); + mapMoveOrigin_ = terCamera->coordinate(); + terCamera->cursorTrace(mousePosition(), mapMoveStartPoint_); + setCursorPosition(mapMoveStartPoint_); + } + if(!cameraMouseZoom && !cameraMouseShift && !cameraMouseTrack && !toolzerSizeTrack) { if(_shellIconManager.IsInterface()) @@ -2237,15 +2239,27 @@ void GameShell::CameraQuant() } //смещение вслед за мышью - if(cameraMouseShift && MouseMoveFlag){ - terCamera->shift(mousePositionDelta()); - setCursorPosition(mapMoveStartPoint()); - MousePositionLock = 1; + if(cameraMouseShift && mouseLeftPressed_){ + if (MouseMoveFlag) { + auto delta = mousePosition_ - mapMoveCursorStartPoint_; + static Vect2f prevDelta = Vect2f::ZERO; + auto deltaDiff = prevDelta - delta; + if (abs(deltaDiff.x) > 0.01 || abs(deltaDiff.y) > 0.01) { + CameraCoordinate coordinate = terCamera->coordinate(); + terCamera->setCoordinate(mapMoveOrigin_); + if (terCamera->shift(mapMoveCursorStartPoint_, mousePosition_)) { + terCamera->coordinate().check(terCamera->restricted()); + } else { + terCamera->setCoordinate(coordinate); + } + prevDelta = delta; + } + } } float delta = frame_time.delta() / 1000.0f;// * PerimeterCameraControlFPS / 1000.0f; - terCamera->quant(mousePositionDelta().x, mousePositionDelta().y, delta, cameraMouseTrack && MouseMoveFlag); - + terCamera->quant(mousePositionDelta().x, mousePositionDelta().y, delta, cameraMouseTrack && MouseMoveFlag); + // mousePositionDelta_ = Vect2f::ZERO; MouseMoveFlag = 0; @@ -2709,12 +2723,7 @@ void GameShell::prepareForInGameMenu() { if(_shellIconManager.IsInterface()) _shellCursorManager.ShowCursor(); } - if (cameraMouseShift) { - cameraMouseShift = false; - - if(_shellIconManager.IsInterface()) - _shellCursorManager.ShowCursor(); - } + setCameraMouseShift(false); CancelEditWorkarea(); _shellCursorManager.m_bShowSideArrows=0; _shellCursorManager.ShowCursor(); @@ -2926,3 +2935,19 @@ void GameShell::editParameters() SDL_ShowCursor(SDL_FALSE); RestoreFocus(); } + +void GameShell::setCameraMouseShift(bool _cameraMouseShift) { + if (cameraMouseShift == _cameraMouseShift) { + return; + } + + cameraMouseShift = _cameraMouseShift; + + if (cameraMouseShift){ + _shellCursorManager.HideCursor(); + } else { + if (_shellIconManager.IsInterface()) { + _shellCursorManager.ShowCursor(); + } + } +} diff --git a/Source/UserInterface/GameShell.h b/Source/UserInterface/GameShell.h index 1b2344b0..76df7232 100644 --- a/Source/UserInterface/GameShell.h +++ b/Source/UserInterface/GameShell.h @@ -9,6 +9,7 @@ #include "../Network/P2P_interface.h" #include "LogicUpdater.h" #include "ReelManager.h" +#include "CameraManager.h" #include struct LocalizedText; @@ -292,6 +293,8 @@ class GameShell return startedWithMainmenu; } + void setCameraMouseShift(bool cameraMouseShift); + private: class CChaos* chaos; @@ -318,9 +321,11 @@ class GameShell bool showWireFrame_; int activePlayerID_; + CameraCoordinate mapMoveOrigin_; Vect3f mapMoveStartPoint_; - - float game_speed; + Vect2f mapMoveCursorStartPoint_; + + float game_speed; float game_speed_to_resume; //MeasurementTimer gameTimer_; diff --git a/Source/UserInterface/HistorySceneCamera.cpp b/Source/UserInterface/HistorySceneCamera.cpp index e4c608d0..006c4c76 100644 --- a/Source/UserInterface/HistorySceneCamera.cpp +++ b/Source/UserInterface/HistorySceneCamera.cpp @@ -190,38 +190,38 @@ void HistorySceneCamera::quant(const Vect2f& mousePos, float dt) { // } if ( - g_controls_converter.key(CTRL_CAMERA_MOVE_UP).pressed() + g_controls_converter.pressed(CTRL_CAMERA_MOVE_UP) || xm::abs(mousePos.y + 0.5f) < CAMERA_BORDER_SCROLL_AREA_UP ) { position.theta -= HISTORY_CAMERA_ANGLE_SPEED_DELTA * dt; } if ( - g_controls_converter.key(CTRL_CAMERA_MOVE_DOWN).pressed() + g_controls_converter.pressed(CTRL_CAMERA_MOVE_DOWN) || xm::abs(mousePos.y - 0.5f) < CAMERA_BORDER_SCROLL_AREA_DN ) { position.theta += HISTORY_CAMERA_ANGLE_SPEED_DELTA * dt; } if ( - g_controls_converter.key(CTRL_CAMERA_MOVE_LEFT).pressed() + g_controls_converter.pressed(CTRL_CAMERA_MOVE_LEFT) || xm::abs(mousePos.x - 0.5f) < CAMERA_BORDER_SCROLL_AREA_HORZ ) { position.psi += HISTORY_CAMERA_ANGLE_SPEED_DELTA * dt; } if ( - g_controls_converter.key(CTRL_CAMERA_MOVE_RIGHT).pressed() + g_controls_converter.pressed(CTRL_CAMERA_MOVE_RIGHT) || xm::abs(mousePos.x + 0.5f) < CAMERA_BORDER_SCROLL_AREA_HORZ ) { position.psi -= HISTORY_CAMERA_ANGLE_SPEED_DELTA * dt; } - if ( g_controls_converter.key(CTRL_CAMERA_ZOOM_INC).pressed() ) { + if ( g_controls_converter.pressed(CTRL_CAMERA_ZOOM_INC) ) { position.distanceToPivot -= CAMERA_ZOOM_SPEED_DELTA * dt; } - if ( g_controls_converter.key(CTRL_CAMERA_ZOOM_DEC).pressed() ) { + if ( g_controls_converter.pressed(CTRL_CAMERA_ZOOM_DEC) ) { position.distanceToPivot += CAMERA_ZOOM_SPEED_DELTA * dt; } if (position.distanceToPivot < HISTORY_SCENE_CAMERA_MIN_DISTANCE) { diff --git a/Source/UserInterface/controls.cpp b/Source/UserInterface/controls.cpp index 750185d0..d3a651b0 100644 --- a/Source/UserInterface/controls.cpp +++ b/Source/UserInterface/controls.cpp @@ -53,3 +53,8 @@ void ControlsConverter::LoadCtrlTable(const char *strMain) } } +#ifndef GPX +bool ControlsConverter::pressed(int ctrl) const { + return CtrlToKey[ctrl].pressed(); +} +#endif diff --git a/Source/Util/SystemUtil.cpp b/Source/Util/SystemUtil.cpp index 368fb3d8..a3663f77 100644 --- a/Source/Util/SystemUtil.cpp +++ b/Source/Util/SystemUtil.cpp @@ -132,6 +132,9 @@ bool isPressed(uint32_t key) { sKey::sKey(SDL_Keysym keysym, bool set_by_async_funcs) { key = 0; + if (keysym.scancode == SDL_SCANCODE_GRAVE) { + keysym.sym = SDLK_BACKQUOTE; + } switch (keysym.sym) { case SDLK_LGUI: case SDLK_RGUI: