Skip to content

Commit

Permalink
Merge pull request KD-lab-Open-Source#124 from caiiiycuk/html5
Browse files Browse the repository at this point in the history
Key interface for GPX build and map dragging mode
  • Loading branch information
IonAgorria authored Mar 22, 2024
2 parents 7af0f3a + 0d22e33 commit 182d69d
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 54 deletions.
51 changes: 27 additions & 24 deletions Source/Game/CameraManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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)
Expand Down
8 changes: 6 additions & 2 deletions Source/Game/CameraManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_; }
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions Source/UserInterface/Controls.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ enum eGameKeysControl
CTRL_MAX
};

class ControlsConverter
class ControlsConverter
{
unsigned char KeyToCtrl[2048]; // таблица перехода от кнопок в команды
sKey CtrlToKey[CTRL_MAX]; // таблица перехода от команд к кнопкам
Expand All @@ -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;
Expand Down
61 changes: 43 additions & 18 deletions Source/UserInterface/GameShell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
}
}
}
9 changes: 7 additions & 2 deletions Source/UserInterface/GameShell.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "../Network/P2P_interface.h"
#include "LogicUpdater.h"
#include "ReelManager.h"
#include "CameraManager.h"
#include <SDL_events.h>

struct LocalizedText;
Expand Down Expand Up @@ -292,6 +293,8 @@ class GameShell
return startedWithMainmenu;
}

void setCameraMouseShift(bool cameraMouseShift);

private:
class CChaos* chaos;

Expand All @@ -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_;

Expand Down
12 changes: 6 additions & 6 deletions Source/UserInterface/HistorySceneCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 5 additions & 0 deletions Source/UserInterface/controls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,8 @@ void ControlsConverter::LoadCtrlTable(const char *strMain)
}
}

#ifndef GPX
bool ControlsConverter::pressed(int ctrl) const {
return CtrlToKey[ctrl].pressed();
}
#endif
3 changes: 3 additions & 0 deletions Source/Util/SystemUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 182d69d

Please sign in to comment.