From b15666f48e3a53becebaac03765c5ec79c039f6d Mon Sep 17 00:00:00 2001 From: krzys-h Date: Fri, 19 Feb 2016 16:46:33 +0100 Subject: [PATCH] Restored old camera scroll as a config option --- po/colobot.pot | 3 + po/de.po | 9 +- po/fr.po | 10 +- po/pl.po | 10 +- po/ru.po | 6 +- src/common/event.cpp | 1 + src/common/event.h | 1 + src/common/restext.cpp | 5 +- src/common/settings.cpp | 4 + src/graphics/engine/camera.cpp | 139 +++++++++++++++++++--------- src/graphics/engine/camera.h | 7 +- src/ui/screen/screen_setup_game.cpp | 15 +++ 12 files changed, 141 insertions(+), 69 deletions(-) diff --git a/po/colobot.pot b/po/colobot.pot index e8057295..4343aa2a 100644 --- a/po/colobot.pot +++ b/po/colobot.pot @@ -370,6 +370,9 @@ msgstr "" msgid "Film sequences\\Films before and after the missions" msgstr "" +msgid "Scrolling\\Scrolling when the mouse touches right or left border" +msgstr "" + msgid "Mouse inversion X\\Inversion of the scrolling direction on the X axis" msgstr "" diff --git a/po/de.po b/po/de.po index 7ea55498..3ae02cdf 100644 --- a/po/de.po +++ b/po/de.po @@ -1311,6 +1311,10 @@ msgstr "Speichern\\Aktuelle Mission speichern" msgid "Save\\Saves the current mission" msgstr "Speichern\\Speichert die Mission" +msgid "Scrolling\\Scrolling when the mouse touches right or left border" +msgstr "" +"Kameradrehung mit der Maus\\Die Kamera dreht wenn die Maus den Rand erreicht" + msgid "Select the astronaut\\Selects the astronaut" msgstr "Astronauten auswählen\\Astronauten auswählen" @@ -1901,11 +1905,6 @@ msgstr "www.epsitec.com" #~ msgid "Robbie\\Your assistant" #~ msgstr "Robby\\Ihr Assistent" -#~ msgid "Scrolling\\Scrolling when the mouse touches right or left border" -#~ msgstr "" -#~ "Kameradrehung mit der Maus\\Die Kamera dreht wenn die Maus den Rand " -#~ "erreicht" - #~ msgid "Sky\\Clouds and nebulae" #~ msgstr "Himmel\\Himmel und Wolken" diff --git a/po/fr.po b/po/fr.po index 95cda05d..730e849c 100644 --- a/po/fr.po +++ b/po/fr.po @@ -1299,6 +1299,11 @@ msgstr "Enregistrer\\Enregistrer la mission en cours" msgid "Save\\Saves the current mission" msgstr "Enregistrer\\Enregistrer la mission en cours" +msgid "Scrolling\\Scrolling when the mouse touches right or left border" +msgstr "" +"Défilement dans les bords\\Défilement lorsque la souris touches les bords " +"gauche ou droite" + msgid "Select the astronaut\\Selects the astronaut" msgstr "Sélectionner le cosmonaute\\Sélectionner le cosmonaute" @@ -1887,11 +1892,6 @@ msgstr "www.epsitec.com" #~ msgid "Robbie\\Your assistant" #~ msgstr "Robbie\\Votre assistant" -#~ msgid "Scrolling\\Scrolling when the mouse touches right or left border" -#~ msgstr "" -#~ "Défilement dans les bords\\Défilement lorsque la souris touches les bords " -#~ "gauche ou droite" - #~ msgid "Sky\\Clouds and nebulae" #~ msgstr "Ciel\\Ciel et nuages" diff --git a/po/pl.po b/po/pl.po index 9c509fb7..a54a297c 100644 --- a/po/pl.po +++ b/po/pl.po @@ -1307,6 +1307,11 @@ msgstr "Zapisz\\Zapisuje bieżącą misję" msgid "Save\\Saves the current mission" msgstr "Zapisz\\Zapisuje bieżącą misję" +msgid "Scrolling\\Scrolling when the mouse touches right or left border" +msgstr "" +"Przewijanie\\Ekran jest przewijany gdy mysz dotknie prawej lub lewej jego " +"krawędzi" + msgid "Select the astronaut\\Selects the astronaut" msgstr "Zaznacz astronautę\\Zaznacza astronautę" @@ -1880,11 +1885,6 @@ msgstr "www.epsitec.com" #~ msgid "Robbie\\Your assistant" #~ msgstr "Robbie\\Twój asystent" -#~ msgid "Scrolling\\Scrolling when the mouse touches right or left border" -#~ msgstr "" -#~ "Przewijanie\\Ekran jest przewijany gdy mysz dotknie prawej lub lewej jego " -#~ "krawędzi" - #~ msgid "Sky\\Clouds and nebulae" #~ msgstr "Niebo\\Chmury i mgławice" diff --git a/po/ru.po b/po/ru.po index 33838732..1febf458 100644 --- a/po/ru.po +++ b/po/ru.po @@ -1306,6 +1306,9 @@ msgstr "Сохранить\\Сохранить текущую миссию" msgid "Save\\Saves the current mission" msgstr "Сохранить\\Сохранить текущую миссию" +msgid "Scrolling\\Scrolling when the mouse touches right or left border" +msgstr "Прокрутка\\Прокрутка, когда указатель мыши касается граней экрана" + msgid "Select the astronaut\\Selects the astronaut" msgstr "Выбор астронавта\\Выбор астронавта" @@ -1893,9 +1896,6 @@ msgstr "www.epsitec.com" #~ msgid "Robbie\\Your assistant" #~ msgstr "Робби\\Ваш помощник" -#~ msgid "Scrolling\\Scrolling when the mouse touches right or left border" -#~ msgstr "Прокрутка\\Прокрутка, когда указатель мыши касается граней экрана" - #~ msgid "Sky\\Clouds and nebulae" #~ msgstr "Небо\\Облака и туманности" diff --git a/src/common/event.cpp b/src/common/event.cpp index b1fb6093..ccd7fe8a 100644 --- a/src/common/event.cpp +++ b/src/common/event.cpp @@ -208,6 +208,7 @@ void InitializeEventTypeTexts() EVENT_TYPE_TEXT[EVENT_INTERFACE_GLINT] = "EVENT_INTERFACE_GLINT"; EVENT_TYPE_TEXT[EVENT_INTERFACE_TOOLTIP] = "EVENT_INTERFACE_TOOLTIP"; EVENT_TYPE_TEXT[EVENT_INTERFACE_MOVIES] = "EVENT_INTERFACE_MOVIES"; + EVENT_TYPE_TEXT[EVENT_INTERFACE_SCROLL] = "EVENT_INTERFACE_SCROLL"; EVENT_TYPE_TEXT[EVENT_INTERFACE_INVERTX] = "EVENT_INTERFACE_INVERTX"; EVENT_TYPE_TEXT[EVENT_INTERFACE_INVERTY] = "EVENT_INTERFACE_INVERTY"; EVENT_TYPE_TEXT[EVENT_INTERFACE_EFFECT] = "EVENT_INTERFACE_EFFECT"; diff --git a/src/common/event.h b/src/common/event.h index f211ba1b..50fb0c98 100644 --- a/src/common/event.h +++ b/src/common/event.h @@ -237,6 +237,7 @@ enum EventType EVENT_INTERFACE_GLINT = 463, EVENT_INTERFACE_TOOLTIP = 464, EVENT_INTERFACE_MOVIES = 465, + EVENT_INTERFACE_SCROLL = 467, EVENT_INTERFACE_INVERTX = 468, EVENT_INTERFACE_INVERTY = 469, EVENT_INTERFACE_EFFECT = 470, diff --git a/src/common/restext.cpp b/src/common/restext.cpp index 62a929ef..5d3ed298 100644 --- a/src/common/restext.cpp +++ b/src/common/restext.cpp @@ -20,8 +20,6 @@ #include "common/restext.h" -#include "common/config.h" - #include "CBot/CBot.h" #include "app/input.h" @@ -190,6 +188,7 @@ void InitializeRestext() stringsEvent[EVENT_INTERFACE_GLINT] = TR("Reflections on the buttons \\Shiny buttons"); stringsEvent[EVENT_INTERFACE_TOOLTIP] = TR("Help balloons\\Explain the function of the buttons"); stringsEvent[EVENT_INTERFACE_MOVIES] = TR("Film sequences\\Films before and after the missions"); + stringsEvent[EVENT_INTERFACE_SCROLL] = TR("Camera border scrolling\\Scrolling when the mouse touches right or left border"); stringsEvent[EVENT_INTERFACE_INVERTX] = TR("Mouse inversion X\\Inversion of the scrolling direction on the X axis"); stringsEvent[EVENT_INTERFACE_INVERTY] = TR("Mouse inversion Y\\Inversion of the scrolling direction on the Y axis"); stringsEvent[EVENT_INTERFACE_EFFECT] = TR("Quake at explosions\\The screen shakes at explosions"); @@ -764,7 +763,7 @@ void PutKeyName(std::string& dst, const char* src) src[s+3] == 'y' && src[s+4] == ' ' ) { - int count; + unsigned int count; for(count = 0; src[s+5+count] != ';'; count++); CInput* input = CInput::GetInstancePointer(); InputSlot key = input->SearchKeyById(std::string(&src[s+5], count)); diff --git a/src/common/settings.cpp b/src/common/settings.cpp index 2f6ef2cb..63258ce7 100644 --- a/src/common/settings.cpp +++ b/src/common/settings.cpp @@ -80,6 +80,7 @@ void CSettings::SaveSettings() GetConfigFile().SetBoolProperty("Setup", "Soluce4", m_soluce4); GetConfigFile().SetBoolProperty("Setup", "Movies", m_movies); GetConfigFile().SetBoolProperty("Setup", "FocusLostPause", m_focusLostPause); + GetConfigFile().SetBoolProperty("Setup", "OldCameraScroll", camera->GetOldCameraScroll()); GetConfigFile().SetBoolProperty("Setup", "CameraInvertX", camera->GetCameraInvertX()); GetConfigFile().SetBoolProperty("Setup", "CameraInvertY", camera->GetCameraInvertY()); GetConfigFile().SetBoolProperty("Setup", "InterfaceEffect", camera->GetEffect()); @@ -151,6 +152,9 @@ void CSettings::LoadSettings() GetConfigFile().GetBoolProperty("Setup", "Movies", m_movies); GetConfigFile().GetBoolProperty("Setup", "FocusLostPause", m_focusLostPause); + if (GetConfigFile().GetBoolProperty("Setup", "OldCameraScroll", bValue)) + camera->SetOldCameraScroll(bValue); + if (GetConfigFile().GetBoolProperty("Setup", "CameraInvertX", bValue)) camera->SetCameraInvertX(bValue); diff --git a/src/graphics/engine/camera.cpp b/src/graphics/engine/camera.cpp index cc1f24d3..9c1a76a6 100644 --- a/src/graphics/engine/camera.cpp +++ b/src/graphics/engine/camera.cpp @@ -50,6 +50,7 @@ namespace Gfx { +const float MOUSE_EDGE_MARGIN = 0.01f; //! Changes the level of transparency of an object and objects transported (battery & cargo) void SetTransparency(CObject* obj, float value) @@ -152,6 +153,7 @@ CCamera::CCamera() m_effect = true; m_blood = true; + m_oldCameraScroll = false; m_cameraInvertX = false; m_cameraInvertY = false; } @@ -180,6 +182,16 @@ bool CCamera::GetBlood() return m_blood; } +void CCamera::SetOldCameraScroll(bool scroll) +{ + m_oldCameraScroll = scroll; +} + +bool CCamera::GetOldCameraScroll() +{ + return m_oldCameraScroll; +} + void CCamera::SetCameraInvertX(bool invert) { m_cameraInvertX = invert; @@ -1068,16 +1080,62 @@ bool CCamera::EventProcess(const Event &event) bool CCamera::EventMouseMove(const Event &event) { - m_mouseDelta += (event.mousePos - m_mousePos); - if (m_cameraInvertX) - m_mouseDelta.x = -m_mouseDelta.x; - if (m_cameraInvertY) - m_mouseDelta.y = -m_mouseDelta.y; + if (m_engine->GetMouseType() == ENG_MOUSE_SCROLLR || + m_engine->GetMouseType() == ENG_MOUSE_SCROLLL || + m_engine->GetMouseType() == ENG_MOUSE_SCROLLU || + m_engine->GetMouseType() == ENG_MOUSE_SCROLLD || + m_engine->GetMouseType() == ENG_MOUSE_MOVE ) + { + m_engine->SetMouseType(ENG_MOUSE_NORM); + } + + if ((event.mouseButtonsState & MOUSE_BUTTON_RIGHT) != 0) + { + Math::Point newDelta = event.mousePos - m_mousePos; + if (m_cameraInvertX) + newDelta.x = -newDelta.x; + if (m_cameraInvertY) + newDelta.y = -newDelta.y; + m_mouseDelta += newDelta; + + m_engine->SetMouseType(ENG_MOUSE_MOVE); + } + + m_mouseDeltaEdge.LoadZero(); + if (m_oldCameraScroll) + { + if (event.mousePos.x < MOUSE_EDGE_MARGIN) + m_mouseDeltaEdge.x = event.mousePos.x / MOUSE_EDGE_MARGIN - 1.0f; + if (event.mousePos.x > 1.0f - MOUSE_EDGE_MARGIN) + m_mouseDeltaEdge.x = 1.0f - (1.0f - event.mousePos.x) / MOUSE_EDGE_MARGIN; + if (event.mousePos.y < MOUSE_EDGE_MARGIN) + m_mouseDeltaEdge.y = event.mousePos.y / MOUSE_EDGE_MARGIN - 1.0f; + if (event.mousePos.y > 1.0f - MOUSE_EDGE_MARGIN) + m_mouseDeltaEdge.y = 1.0f - (1.0f - event.mousePos.y) / MOUSE_EDGE_MARGIN; + + if (m_type == CAM_TYPE_FREE || + m_type == CAM_TYPE_EDIT || + m_type == CAM_TYPE_BACK || + m_type == CAM_TYPE_FIX || + m_type == CAM_TYPE_PLANE || + m_type == CAM_TYPE_EXPLO ) + { + if (m_mouseDeltaEdge.x > 0.0f) + m_engine->SetMouseType(ENG_MOUSE_SCROLLR); + if (m_mouseDeltaEdge.x < 0.0f) + m_engine->SetMouseType(ENG_MOUSE_SCROLLL); + } + if (m_type == CAM_TYPE_FREE || + m_type == CAM_TYPE_EDIT ) + { + if (m_mouseDeltaEdge.y > 0.0f) + m_engine->SetMouseType(ENG_MOUSE_SCROLLU); + if (m_mouseDeltaEdge.y < 0.0f) + m_engine->SetMouseType(ENG_MOUSE_SCROLLD); + } + } m_mousePos = event.mousePos; - - if (m_mouseRightDown) - m_engine->SetMouseType(ENG_MOUSE_MOVE); return true; } @@ -1120,13 +1178,10 @@ void CCamera::EventMouseButton(const Event &event) { if (event.type == EVENT_MOUSE_BUTTON_DOWN) { - m_mouseRightDown = true; - m_mouseDelta.LoadZero(); m_engine->SetMouseType(ENG_MOUSE_MOVE); } else { - m_mouseRightDown = false; m_engine->SetMouseType(ENG_MOUSE_NORM); } } @@ -1134,6 +1189,13 @@ void CCamera::EventMouseButton(const Event &event) bool CCamera::EventFrame(const Event &event) { + Math::Point newDelta = m_mouseDeltaEdge * m_speed * event.rTime; + if (m_cameraInvertX) + newDelta.x = -newDelta.x; + if (m_cameraInvertY) + newDelta.y = -newDelta.y; + m_mouseDelta += newDelta; + EffectFrame(event); OverFrame(event); @@ -1181,12 +1243,9 @@ bool CCamera::EventFrameFree(const Event &event) float factor = m_heightEye * 0.5f + 30.0f; - if ( m_mouseRightDown ) - { - m_directionH -= m_mouseDelta.x * 2*Math::PI; - m_eyePt = Math::LookatPoint(m_eyePt, m_directionH, m_directionV, m_mouseDelta.y * factor * m_speed); - m_mouseDelta.LoadZero(); - } + m_directionH -= m_mouseDelta.x * 2*Math::PI; + m_eyePt = Math::LookatPoint(m_eyePt, m_directionH, m_directionV, m_mouseDelta.y * factor * m_speed); + m_mouseDelta.LoadZero(); // Up/Down m_eyePt = Math::LookatPoint(m_eyePt, m_directionH, m_directionV, cameraInput.y * event.rTime * factor * m_speed); @@ -1256,12 +1315,10 @@ bool CCamera::EventFrameEdit(const Event &event) { float factor = m_editHeight * 0.5f + 30.0f; - if (m_mouseRightDown) - { - m_directionH -= m_mouseDelta.x * 2*Math::PI; - m_eyePt = Math::LookatPoint(m_eyePt, m_directionH, m_directionV, m_mouseDelta.y * factor * m_speed); - m_mouseDelta.LoadZero(); - } + m_directionH -= m_mouseDelta.x * 2*Math::PI; + m_eyePt = Math::LookatPoint(m_eyePt, m_directionH, m_directionV, m_mouseDelta.y * factor * m_speed); + m_mouseDelta.LoadZero(); + m_fixDirectionH = Math::NormAngle(m_fixDirectionH); m_terrain->AdjustToBounds(m_eyePt, 10.0f); @@ -1315,13 +1372,11 @@ bool CCamera::EventFrameBack(const Event &event) if (m_backDist > 200.0f) m_backDist = 200.0f; } - if (m_mouseRightDown) - { - m_addDirectionH -= m_mouseDelta.x * 2*Math::PI; - m_addDirectionH = Math::NormAngle(m_addDirectionH); - m_mouseDelta.LoadZero(); + m_addDirectionH -= m_mouseDelta.x * 2*Math::PI; + m_addDirectionH = Math::NormAngle(m_addDirectionH); + if (m_mouseDelta.Length() > 0) AbortCentering(); // special stops framing - } + m_mouseDelta.LoadZero(); // Increase the special framework float centeringH = 0.0f; @@ -1454,12 +1509,10 @@ bool CCamera::EventFrameFix(const Event &event) if (m_fixDist > 200.0f) m_fixDist = 200.0f; } - if (m_mouseRightDown) - { - m_fixDirectionH -= m_mouseDelta.x * 2*Math::PI; - m_mouseDelta.LoadZero(); + m_fixDirectionH -= m_mouseDelta.x * 2*Math::PI; + if (m_mouseDelta.Length() > 0) AbortCentering(); // special stops framing - } + m_mouseDelta.LoadZero(); // Left/Right m_fixDirectionH += event.cameraInput.x * event.rTime * 0.7f * m_speed; @@ -1493,11 +1546,8 @@ bool CCamera::EventFrameFix(const Event &event) bool CCamera::EventFrameExplo(const Event &event) { - if (m_mouseRightDown) - { - m_directionH -= m_mouseDelta.x * 2*Math::PI; - m_mouseDelta.LoadZero(); - } + m_directionH -= m_mouseDelta.x * 2*Math::PI; + m_mouseDelta.LoadZero(); m_terrain->AdjustToBounds(m_eyePt, 10.0f); @@ -1578,13 +1628,10 @@ bool CCamera::EventFrameVisit(const Event &event) if (m_visitDirectionV > 0.0f ) m_visitDirectionV = 0.0f; } - if (m_mouseRightDown) - { - m_visitDist -= m_mouseDelta.y * 100.0f * m_speed; - m_mouseDelta.LoadZero(); - if (m_visitDist < 20.0f) m_visitDist = 20.0f; - if (m_visitDist > 200.0f) m_visitDist = 200.0f; - } + m_visitDist -= m_mouseDelta.y * 100.0f * m_speed; + m_mouseDelta.LoadZero(); + if (m_visitDist < 20.0f) m_visitDist = 20.0f; + if (m_visitDist > 200.0f) m_visitDist = 200.0f; float angleH = (m_visitTime / 10.0f) * (Math::PI * 2.0f); float angleV = m_visitDirectionV; diff --git a/src/graphics/engine/camera.h b/src/graphics/engine/camera.h index 1cb990e2..f00332a0 100644 --- a/src/graphics/engine/camera.h +++ b/src/graphics/engine/camera.h @@ -204,6 +204,8 @@ public: bool GetEffect(); void SetBlood(bool enable); bool GetBlood(); + void SetOldCameraScroll(bool scroll); + bool GetOldCameraScroll(); void SetCameraInvertX(bool invert); bool GetCameraInvertX(); void SetCameraInvertY(bool invert); @@ -342,9 +344,10 @@ protected: float m_remotePan; - bool m_mouseRightDown = false; + //! Last known mouse position, used to calculate change since last frame Math::Point m_mousePos = Math::Point(0.5f, 0.5f); Math::Point m_mouseDelta = Math::Point(0.0f, 0.0f); + Math::Point m_mouseDeltaEdge = Math::Point(0.0f, 0.0f); CenteringPhase m_centeringPhase; float m_centeringAngleH; @@ -378,7 +381,7 @@ protected: //! Blood? bool m_blood; //! Scroll in the edges? - bool m_cameraScroll; + bool m_oldCameraScroll; //! X inversion in the edges? bool m_cameraInvertX; //! Y inversion in the edges? diff --git a/src/ui/screen/screen_setup_game.cpp b/src/ui/screen/screen_setup_game.cpp index c1bce9e2..d28a5b68 100644 --- a/src/ui/screen/screen_setup_game.cpp +++ b/src/ui/screen/screen_setup_game.cpp @@ -69,6 +69,9 @@ void CScreenSetupGame::CreateInterface() pc = pw->CreateCheck(pos, ddim, -1, EVENT_INTERFACE_MOVIES); pc->SetState(STATE_SHADOW); pos.y -= 0.048f; + pc = pw->CreateCheck(pos, ddim, -1, EVENT_INTERFACE_SCROLL); + pc->SetState(STATE_SHADOW); + pos.y -= 0.048f; pc = pw->CreateCheck(pos, ddim, -1, EVENT_INTERFACE_INVERTX); pc->SetState(STATE_SHADOW); pos.y -= 0.048f; @@ -210,6 +213,12 @@ bool CScreenSetupGame::EventProcess(const Event &event) UpdateSetupButtons(); break; + case EVENT_INTERFACE_SCROLL: + m_camera->SetOldCameraScroll(!m_camera->GetOldCameraScroll()); + ChangeSetupButtons(); + UpdateSetupButtons(); + break; + case EVENT_INTERFACE_INVERTX: m_camera->SetCameraInvertX(!m_camera->GetCameraInvertX()); ChangeSetupButtons(); @@ -313,6 +322,12 @@ void CScreenSetupGame::UpdateSetupButtons() pc->SetState(STATE_CHECK, m_settings->GetMovies()); } + pc = static_cast(pw->SearchControl(EVENT_INTERFACE_SCROLL)); + if ( pc != nullptr ) + { + pc->SetState(STATE_CHECK, m_camera->GetOldCameraScroll()); + } + pc = static_cast(pw->SearchControl(EVENT_INTERFACE_INVERTX)); if ( pc != nullptr ) {