From f5864a03c676ab975036ec7961987c495831ad4c Mon Sep 17 00:00:00 2001 From: Alexander Guryanov Date: Tue, 12 Mar 2024 15:01:30 +0300 Subject: [PATCH 1/4] Key interface for GPX build --- Source/Game/CameraManager.cpp | 20 ++++++++++---------- Source/UserInterface/Controls.h | 4 ++-- Source/UserInterface/HistorySceneCamera.cpp | 12 ++++++------ Source/UserInterface/controls.cpp | 5 +++++ 4 files changed, 23 insertions(+), 18 deletions(-) diff --git a/Source/Game/CameraManager.cpp b/Source/Game/CameraManager.cpp index a46a7c73f..4d3651315 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; } diff --git a/Source/UserInterface/Controls.h b/Source/UserInterface/Controls.h index 68914f844..a19613e71 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/HistorySceneCamera.cpp b/Source/UserInterface/HistorySceneCamera.cpp index e4c608d05..006c4c76c 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 750185d0b..d3a651b0f 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 From 5f64b9b7147391573df0c57290689287be849820 Mon Sep 17 00:00:00 2001 From: Alexander Guryanov Date: Tue, 19 Mar 2024 11:48:42 +0300 Subject: [PATCH 2/4] Map SCANCODE_GRAVE to VK_TILDE --- Source/Util/SystemUtil.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Source/Util/SystemUtil.cpp b/Source/Util/SystemUtil.cpp index 368fb3d80..a3663f77d 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: From 810569bc74e19fec8187b06c8bc7b6b93d62cc57 Mon Sep 17 00:00:00 2001 From: Alexander Guryanov Date: Tue, 19 Mar 2024 13:11:53 +0300 Subject: [PATCH 3/4] Support drag to move map (with ~) --- Source/Game/CameraManager.h | 7 ++++++- Source/UserInterface/GameShell.cpp | 18 +++++++++++++----- Source/UserInterface/GameShell.h | 6 ++++-- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/Source/Game/CameraManager.h b/Source/Game/CameraManager.h index cc2cb7516..2e9474c5f 100644 --- a/Source/Game/CameraManager.h +++ b/Source/Game/CameraManager.h @@ -53,7 +53,12 @@ class terCameraType void reset(); void setFocus(float focus); - void setCoordinate(const CameraCoordinate& coord) { coordinate_ = coord; update(); } + void setCoordinate(const CameraCoordinate& coord, bool doUpdate = true) { + coordinate_ = coord; + if (doUpdate) { + update(); + } + } float focus() const { return focus_; } const CameraCoordinate& coordinate() const { return coordinate_; } diff --git a/Source/UserInterface/GameShell.cpp b/Source/UserInterface/GameShell.cpp index 3ce08779f..ec343c404 100644 --- a/Source/UserInterface/GameShell.cpp +++ b/Source/UserInterface/GameShell.cpp @@ -1745,8 +1745,8 @@ void GameShell::ControlPressed(int key) if(!cameraMouseShift){ cameraMouseShift = true; _shellCursorManager.HideCursor(); - - terCamera->cursorTrace(mousePosition(), mapMoveStartPoint_); + + mapMoveCenter_ = terCamera->coordinate().position(); } break; @@ -1928,6 +1928,12 @@ void GameShell::MouseLeftPressed(const Vect2f& pos) mousePositionDelta_ = pos - mousePosition(); mousePosition_= pos; + if (cameraMouseShift) { + mapMoveCursorStartPoint_ = mousePosition(); + terCamera->cursorTrace(mousePosition(), mapMoveStartPoint_); + setCursorPosition(mapMoveStartPoint_); + } + if(!cameraMouseZoom && !cameraMouseShift && !cameraMouseTrack && !toolzerSizeTrack) { if(_shellIconManager.IsInterface()) @@ -2217,9 +2223,11 @@ void GameShell::CameraQuant() } //смещение вслед за мышью - if(cameraMouseShift && MouseMoveFlag){ - terCamera->shift(mousePositionDelta()); - setCursorPosition(mapMoveStartPoint()); + if(cameraMouseShift && MouseMoveFlag && mouseLeftPressed_){ + terCamera->setCoordinate(CameraCoordinate(mapMoveCenter_, + terCamera->coordinate().psi(), terCamera->coordinate().theta(), + terCamera->coordinate().distance()), false); + terCamera->shift(mousePosition() - mapMoveCursorStartPoint_); MousePositionLock = 1; } diff --git a/Source/UserInterface/GameShell.h b/Source/UserInterface/GameShell.h index 588fd9758..ee4bb2330 100644 --- a/Source/UserInterface/GameShell.h +++ b/Source/UserInterface/GameShell.h @@ -315,9 +315,11 @@ class GameShell bool showWireFrame_; int activePlayerID_; + Vect3f mapMoveCenter_; Vect3f mapMoveStartPoint_; - - float game_speed; + Vect2f mapMoveCursorStartPoint_; + + float game_speed; float game_speed_to_resume; //MeasurementTimer gameTimer_; From 0d22e33f318afc64100e8e0e4cf0fa0edf272f81 Mon Sep 17 00:00:00 2001 From: Alexander Guryanov Date: Wed, 20 Mar 2024 17:12:58 +0300 Subject: [PATCH 4/4] Improved support for drag to move map (with ~) --- Source/Game/CameraManager.cpp | 31 ++++++++-------- Source/Game/CameraManager.h | 9 +++-- Source/UserInterface/GameShell.cpp | 57 +++++++++++++++++++----------- Source/UserInterface/GameShell.h | 5 ++- 4 files changed, 62 insertions(+), 40 deletions(-) diff --git a/Source/Game/CameraManager.cpp b/Source/Game/CameraManager.cpp index 4d3651315..535243c7a 100644 --- a/Source/Game/CameraManager.cpp +++ b/Source/Game/CameraManager.cpp @@ -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 2e9474c5f..938212ee6 100644 --- a/Source/Game/CameraManager.h +++ b/Source/Game/CameraManager.h @@ -53,11 +53,9 @@ class terCameraType void reset(); void setFocus(float focus); - void setCoordinate(const CameraCoordinate& coord, bool doUpdate = true) { + void setCoordinate(const CameraCoordinate& coord) { coordinate_ = coord; - if (doUpdate) { - update(); - } + update(); } float focus() const { return focus_; } @@ -79,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/GameShell.cpp b/Source/UserInterface/GameShell.cpp index ec343c404..a06715945 100644 --- a/Source/UserInterface/GameShell.cpp +++ b/Source/UserInterface/GameShell.cpp @@ -1742,12 +1742,7 @@ void GameShell::ControlPressed(int key) break; case CTRL_CAMERA_MAP_SHIFT: - if(!cameraMouseShift){ - cameraMouseShift = true; - _shellCursorManager.HideCursor(); - - mapMoveCenter_ = terCamera->coordinate().position(); - } + setCameraMouseShift(true); break; case CTRL_CAMERA_TO_EVENT: @@ -1930,6 +1925,7 @@ void GameShell::MouseLeftPressed(const Vect2f& pos) if (cameraMouseShift) { mapMoveCursorStartPoint_ = mousePosition(); + mapMoveOrigin_ = terCamera->coordinate(); terCamera->cursorTrace(mousePosition(), mapMoveStartPoint_); setCursorPosition(mapMoveStartPoint_); } @@ -2223,17 +2219,27 @@ void GameShell::CameraQuant() } //смещение вслед за мышью - if(cameraMouseShift && MouseMoveFlag && mouseLeftPressed_){ - terCamera->setCoordinate(CameraCoordinate(mapMoveCenter_, - terCamera->coordinate().psi(), terCamera->coordinate().theta(), - terCamera->coordinate().distance()), false); - terCamera->shift(mousePosition() - mapMoveCursorStartPoint_); - 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; @@ -2697,12 +2703,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(); @@ -2914,3 +2915,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 ee4bb2330..9a945722f 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; @@ -289,6 +290,8 @@ class GameShell return startedWithMainmenu; } + void setCameraMouseShift(bool cameraMouseShift); + private: class CChaos* chaos; @@ -315,7 +318,7 @@ class GameShell bool showWireFrame_; int activePlayerID_; - Vect3f mapMoveCenter_; + CameraCoordinate mapMoveOrigin_; Vect3f mapMoveStartPoint_; Vect2f mapMoveCursorStartPoint_;