diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 69b1b66b..5b717c52 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -585,6 +585,8 @@ set(BASE_SOURCES ui/screen/screen_welcome.h ui/studio.cpp ui/studio.h + ui/particlesGenerator.cpp + ui/particlesGenerator.h ) set(MAIN_SOURCES diff --git a/src/common/settings.cpp b/src/common/settings.cpp index 44c63b97..021fa37c 100644 --- a/src/common/settings.cpp +++ b/src/common/settings.cpp @@ -34,23 +34,23 @@ CSettings::CSettings() { - m_tooltips = true; + m_tooltips = true; m_interfaceGlint = true; - m_interfaceRain = true; - m_soluce4 = true; - m_movies = true; + m_mouseParticlesEnabled = true; + m_soluce4 = true; + m_movies = true; m_focusLostPause = true; - m_focusLostMute = true; + m_focusLostMute = true; - m_fontSize = 19.0f; + m_fontSize = 19.0f; m_windowPos = Math::Point(0.15f, 0.17f); m_windowDim = Math::Point(0.70f, 0.66f); m_windowMax = false; m_IOPublic = false; - m_IODim = Math::Point(320.0f/640.0f, (121.0f+18.0f*8)/480.0f); - m_IOPos.x = (1.0f-m_IODim.x)/2.0f; // in the middle - m_IOPos.y = (1.0f-m_IODim.y)/2.0f; + m_IODim = Math::Point(320.0f / 640.0f, (121.0f + 18.0f * 8) / 480.0f); + m_IOPos.x = (1.0f - m_IODim.x) / 2.0f; // in the middle + m_IOPos.y = (1.0f - m_IODim.y) / 2.0f; m_language = LANGUAGE_ENV; } @@ -76,7 +76,7 @@ void CSettings::SaveSettings() GetConfigFile().SetBoolProperty("Setup", "Tooltips", m_tooltips); GetConfigFile().SetBoolProperty("Setup", "InterfaceGlint", m_interfaceGlint); - GetConfigFile().SetBoolProperty("Setup", "InterfaceRain", m_interfaceRain); + GetConfigFile().SetBoolProperty("Setup", "MouseParticlesEnabled", m_mouseParticlesEnabled); GetConfigFile().SetBoolProperty("Setup", "Soluce4", m_soluce4); GetConfigFile().SetBoolProperty("Setup", "Movies", m_movies); GetConfigFile().SetBoolProperty("Setup", "FocusLostPause", m_focusLostPause); @@ -110,7 +110,7 @@ void CSettings::SaveSettings() GetConfigFile().SetBoolProperty("Setup", "ShadowMapping", engine->GetShadowMapping()); GetConfigFile().SetBoolProperty("Setup", "ShadowMappingQuality", engine->GetShadowMappingQuality()); GetConfigFile().SetIntProperty("Setup", "ShadowMappingResolution", - engine->GetShadowMappingOffscreen() ? engine->GetShadowMappingOffscreenResolution() : 0); + engine->GetShadowMappingOffscreen() ? engine->GetShadowMappingOffscreenResolution() : 0); // Experimental settings GetConfigFile().SetBoolProperty("Experimental", "TerrainShadows", engine->GetTerrainShadows()); @@ -125,7 +125,7 @@ void CSettings::SaveSettings() GetConfigFile().SetFloatProperty("Edit", "WindowPosY", m_windowPos.y); GetConfigFile().SetFloatProperty("Edit", "WindowDimX", m_windowDim.x); GetConfigFile().SetFloatProperty("Edit", "WindowDimY", m_windowDim.y); - GetConfigFile().SetBoolProperty ("Edit", "WindowMaximized", m_windowMax); + GetConfigFile().SetBoolProperty("Edit", "WindowMaximized", m_windowMax); GetConfigFile().SetBoolProperty("Edit", "IOPublic", m_IOPublic); GetConfigFile().SetFloatProperty("Edit", "IOPosX", m_IOPos.x); @@ -155,7 +155,7 @@ void CSettings::LoadSettings() GetConfigFile().GetBoolProperty("Setup", "Tooltips", m_tooltips); GetConfigFile().GetBoolProperty("Setup", "InterfaceGlint", m_interfaceGlint); - GetConfigFile().GetBoolProperty("Setup", "InterfaceRain", m_interfaceRain); + GetConfigFile().GetBoolProperty("Setup", "MouseParticlesEnabled", m_mouseParticlesEnabled); GetConfigFile().GetBoolProperty("Setup", "Soluce4", m_soluce4); GetConfigFile().GetBoolProperty("Setup", "Movies", m_movies); GetConfigFile().GetBoolProperty("Setup", "FocusLostPause", m_focusLostPause); @@ -202,7 +202,7 @@ void CSettings::LoadSettings() if (iValue >= 0) { auto joysticks = app->GetJoystickList(); - for(const auto& joystick : joysticks) + for (const auto& joystick : joysticks) { if (joystick.index == iValue) { @@ -287,18 +287,18 @@ void CSettings::LoadSettings() - GetConfigFile().GetFloatProperty("Edit", "FontSize", m_fontSize); - GetConfigFile().GetFloatProperty("Edit", "WindowPosX", m_windowPos.x); - GetConfigFile().GetFloatProperty("Edit", "WindowPosY", m_windowPos.y); - GetConfigFile().GetFloatProperty("Edit", "WindowDimX", m_windowDim.x); - GetConfigFile().GetFloatProperty("Edit", "WindowDimY", m_windowDim.y); - GetConfigFile().GetBoolProperty ("Edit", "WindowMaximized", m_windowMax); + GetConfigFile().GetFloatProperty("Edit", "FontSize", m_fontSize); + GetConfigFile().GetFloatProperty("Edit", "WindowPosX", m_windowPos.x); + GetConfigFile().GetFloatProperty("Edit", "WindowPosY", m_windowPos.y); + GetConfigFile().GetFloatProperty("Edit", "WindowDimX", m_windowDim.x); + GetConfigFile().GetFloatProperty("Edit", "WindowDimY", m_windowDim.y); + GetConfigFile().GetBoolProperty("Edit", "WindowMaximized", m_windowMax); - GetConfigFile().GetBoolProperty ("Edit", "IOPublic", m_IOPublic); - GetConfigFile().GetFloatProperty("Edit", "IOPosX", m_IOPos.x); - GetConfigFile().GetFloatProperty("Edit", "IOPosY", m_IOPos.y); - GetConfigFile().GetFloatProperty("Edit", "IODimX", m_IODim.x); - GetConfigFile().GetFloatProperty("Edit", "IODimY", m_IODim.y); + GetConfigFile().GetBoolProperty("Edit", "IOPublic", m_IOPublic); + GetConfigFile().GetFloatProperty("Edit", "IOPosX", m_IOPos.x); + GetConfigFile().GetFloatProperty("Edit", "IOPosY", m_IOPos.y); + GetConfigFile().GetFloatProperty("Edit", "IODimX", m_IODim.x); + GetConfigFile().GetFloatProperty("Edit", "IODimY", m_IODim.y); m_language = LANGUAGE_ENV; if (GetConfigFile().GetStringProperty("Language", "Lang", sValue)) @@ -306,7 +306,7 @@ void CSettings::LoadSettings() if (!sValue.empty() && !ParseLanguage(sValue, m_language)) { GetLogger()->Error("Failed to parse language '%s' from config file. Default language will be used.\n", - sValue.c_str()); + sValue.c_str()); } } app->SetLanguage(m_language); @@ -330,13 +330,13 @@ bool CSettings::GetInterfaceGlint() return m_interfaceGlint; } -void CSettings::SetInterfaceRain(bool interfaceRain) +void CSettings::SetMouseParticlesEnabled(bool mouseParticlesEnabled) { - m_interfaceRain = interfaceRain; + m_mouseParticlesEnabled = mouseParticlesEnabled; } -bool CSettings::GetInterfaceRain() +bool CSettings::GetMouseParticlesEnabled() { - return m_interfaceRain; + return m_mouseParticlesEnabled; } void CSettings::SetSoluce4(bool soluce4) diff --git a/src/common/settings.h b/src/common/settings.h index b5a183b8..6ebf6e22 100644 --- a/src/common/settings.h +++ b/src/common/settings.h @@ -26,7 +26,7 @@ namespace Gfx { -struct DeviceConfig; + struct DeviceConfig; } class CSettings : public CSingleton @@ -44,8 +44,8 @@ public: void SetInterfaceGlint(bool interfaceGlint); bool GetInterfaceGlint(); - void SetInterfaceRain(bool interfaceRain); - bool GetInterfaceRain(); + void SetMouseParticlesEnabled(bool mouseParticlesEnabled); + bool GetMouseParticlesEnabled(); void SetSoluce4(bool soluce4); bool GetSoluce4(); @@ -95,7 +95,7 @@ public: protected: bool m_tooltips; bool m_interfaceGlint; - bool m_interfaceRain; + bool m_mouseParticlesEnabled; bool m_soluce4; bool m_movies; bool m_focusLostPause; diff --git a/src/ui/mainui.cpp b/src/ui/mainui.cpp index 7f4b20d9..2c65239a 100644 --- a/src/ui/mainui.cpp +++ b/src/ui/mainui.cpp @@ -35,6 +35,8 @@ #include "ui/maindialog.h" +#include "ui/particlesGenerator.h" + #include "ui/controls/group.h" #include "ui/controls/interface.h" #include "ui/controls/label.h" @@ -66,7 +68,7 @@ CMainUserInterface::CMainUserInterface() m_app = CApplication::GetInstancePointer(); m_main = CRobotMain::GetInstancePointer(); m_engine = Gfx::CEngine::GetInstancePointer(); - m_particle = m_engine->GetParticle(); + m_particleManager = m_engine->GetParticle(); m_interface = m_main->GetInterface(); m_sound = m_app->GetSound(); m_settings = CSettings::GetInstancePointer(); @@ -87,6 +89,7 @@ CMainUserInterface::CMainUserInterface() m_screenPlayerSelect = MakeUnique(m_dialog.get()); m_screenQuit = MakeUnique(); m_screenWelcome = MakeUnique(); + m_mouseParticlesGenerator = MakeUnique(); m_currentScreen = nullptr; @@ -132,7 +135,6 @@ CScreenLoading* CMainUserInterface::GetLoadingScreen() return m_screenLoading.get(); } - // Changes phase. CScreenSetup* CMainUserInterface::GetSetupScreen(Phase phase) @@ -255,7 +257,7 @@ bool CMainUserInterface::EventProcess(const Event &event) if ( event.type == EVENT_MOUSE_MOVE ) { m_glintMouse = event.mousePos; - NiceParticle(event.mousePos, event.mouseButtonsState & MOUSE_BUTTON_LEFT); + CreateMouseParticles(event.mousePos, event.mouseButtonsState & MOUSE_BUTTON_LEFT); } if (!m_dialog->EventProcess(event)) return false; @@ -520,7 +522,7 @@ void CMainUserInterface::FrameParticle(float rTime) 279.0f, 18.0f, }; - if ( m_dialog->IsDialog() || !m_settings->GetInterfaceRain() ) return; + if (m_dialog->IsDialog() || !m_settings->GetMouseParticlesEnabled()) return; if ( m_phase == PHASE_MAIN_MENU ) { @@ -584,7 +586,7 @@ void CMainUserInterface::FrameParticle(float rTime) speed.z = 0.0f; dim.x = 0.04f+Math::Rand()*0.04f; dim.y = dim.x/0.75f; - m_particle->CreateParticle(pos, speed, dim, + m_particleManager->CreateParticle(pos, speed, dim, rand()%2?Gfx::PARTIGLINT:Gfx::PARTICONTROL, Math::Rand()*0.4f+0.4f, 0.0f, 0.0f, Gfx::SH_INTERFACE); @@ -650,7 +652,7 @@ void CMainUserInterface::FrameParticle(float rTime) speed.z = 0.0f; dim.x = 0.005f+Math::Rand()*0.005f; dim.y = dim.x/0.75f; - m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIBLITZ, + m_particleManager->CreateParticle(pos, speed, dim, Gfx::PARTIBLITZ, Math::Rand()*0.2f+0.2f, 0.0f, 0.0f, Gfx::SH_INTERFACE); pos.x = m_particles[i].pos.x; @@ -661,7 +663,7 @@ void CMainUserInterface::FrameParticle(float rTime) speed.z = 0.0f; dim.x = 0.01f+Math::Rand()*0.01f; dim.y = dim.x/0.75f; - m_particle->CreateParticle(pos, speed, dim, + m_particleManager->CreateParticle(pos, speed, dim, static_cast(Gfx::PARTILENS1+rand()%3), Math::Rand()*0.5f+0.5f, 2.0f, 0.0f, Gfx::SH_INTERFACE); @@ -678,7 +680,7 @@ void CMainUserInterface::FrameParticle(float rTime) speed.z = 0.0f; dim.x = 0.005f+Math::Rand()*0.005f; dim.y = dim.x/0.75f; - m_particle->CreateParticle(pos, speed, dim, Gfx::PARTIBLITZ, + m_particleManager->CreateParticle(pos, speed, dim, Gfx::PARTIBLITZ, Math::Rand()*0.2f+0.2f, 0.0f, 0.0f, Gfx::SH_INTERFACE); pos.x = m_particles[i].pos.x; @@ -689,7 +691,7 @@ void CMainUserInterface::FrameParticle(float rTime) speed.z = 0.0f; dim.x = 0.005f+Math::Rand()*0.005f; dim.y = dim.x/0.75f; - m_particle->CreateParticle(pos, speed, dim, Gfx::PARTISCRAPS, + m_particleManager->CreateParticle(pos, speed, dim, Gfx::PARTISCRAPS, Math::Rand()*0.5f+0.5f, 2.0f, 0.0f, Gfx::SH_INTERFACE); } @@ -705,7 +707,7 @@ void CMainUserInterface::FrameParticle(float rTime) speed.z = 0.0f; dim.x = 0.03f+Math::Rand()*0.07f; dim.y = dim.x/0.75f; - m_particle->CreateParticle(pos, speed, dim, Gfx::PARTICRASH, + m_particleManager->CreateParticle(pos, speed, dim, Gfx::PARTICRASH, Math::Rand()*0.4f+0.4f, 0.0f, 0.0f, Gfx::SH_INTERFACE); } @@ -719,50 +721,20 @@ void CMainUserInterface::FrameParticle(float rTime) } } -// Some nice particles following the mouse. - -void CMainUserInterface::NiceParticle(Math::Point mouse, bool bPress) +void CMainUserInterface::CreateMouseParticles(Math::Point mousePosition, bool buttonPressed) { - Math::Vector pos, speed; - Math::Point dim; - - if ( !m_settings->GetInterfaceRain() ) return; - if ( (m_phase == PHASE_SIMUL || - m_phase == PHASE_WIN || - m_phase == PHASE_LOST ) && - !m_dialog->IsDialog() ) return; - - if ( bPress ) + if (isAllowedToCreateMouseParticles()) { - pos.x = mouse.x; - pos.y = mouse.y; - pos.z = 0.0f; - speed.x = (Math::Rand()-0.5f)*0.5f; - speed.y = (0.3f+Math::Rand()*0.3f); - speed.z = 0.0f; - dim.x = 0.005f+Math::Rand()*0.005f; - dim.y = dim.x/0.75f; - m_particle->CreateParticle(pos, speed, dim, Gfx::PARTISCRAPS, - Math::Rand()*0.5f+0.5f, 2.0f, 0.0f, - Gfx::SH_INTERFACE); - } - else - { - pos.x = mouse.x; - pos.y = mouse.y; - pos.z = 0.0f; - speed.x = (Math::Rand()-0.5f)*0.5f; - speed.y = (0.3f+Math::Rand()*0.3f); - speed.z = 0.0f; - dim.x = 0.01f+Math::Rand()*0.01f; - dim.y = dim.x/0.75f; - m_particle->CreateParticle(pos, speed, dim, - static_cast(Gfx::PARTILENS1+rand()%3), - Math::Rand()*0.5f+0.5f, 2.0f, 0.0f, - Gfx::SH_INTERFACE); + m_mouseParticlesGenerator->GenerateMouseParticles(Math::Point(mousePosition.x, mousePosition.y), buttonPressed); } } +bool CMainUserInterface::isAllowedToCreateMouseParticles() +{ + return m_settings->GetMouseParticlesEnabled() && + !((m_phase == PHASE_SIMUL || m_phase == PHASE_WIN || m_phase == PHASE_LOST) && !m_dialog->IsDialog()); +} + // Updates the lists according to the cheat code. void CMainUserInterface::AllMissionUpdate() diff --git a/src/ui/mainui.h b/src/ui/mainui.h index 14a9a16c..805ab01c 100644 --- a/src/ui/mainui.h +++ b/src/ui/mainui.h @@ -21,6 +21,8 @@ #include "level/robotmain.h" +#include "ui/particlesGenerator.h" + #include #include #include @@ -91,15 +93,14 @@ public: protected: void GlintMove(); void FrameParticle(float rTime); - void NiceParticle(Math::Point mouse, bool bPress); - + void CreateMouseParticles(Math::Point mousePosition, bool buttonPressed); CScreenSetup* GetSetupScreen(Phase phase); protected: CApplication* m_app; CRobotMain* m_main; Gfx::CEngine* m_engine; - Gfx::CParticle* m_particle; + Gfx::CParticle* m_particleManager; CInterface* m_interface; CSoundInterface* m_sound; CSettings* m_settings; @@ -137,6 +138,10 @@ protected: Math::Point pos; }; std::array m_particles; + +private: + std::unique_ptr m_mouseParticlesGenerator; + bool isAllowedToCreateMouseParticles(); }; } // namespace Ui diff --git a/src/ui/particlesGenerator.cpp b/src/ui/particlesGenerator.cpp new file mode 100644 index 00000000..52d94f87 --- /dev/null +++ b/src/ui/particlesGenerator.cpp @@ -0,0 +1,55 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2020, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://gnu.org/licenses + */ + +#include "ui/particlesGenerator.h" + +#include "graphics/engine/particle.h" + +namespace UI +{ + CParticlesGenerator::CParticlesGenerator() + { + m_particleManager = Gfx::CEngine::GetInstancePointer()->GetParticle(); + } + + void CParticlesGenerator::GenerateMouseParticles(Math::Point mousePosition, bool buttonPressed) + { + Gfx::ParticleType particleType = buttonPressed ? Gfx::ParticleType::PARTISCRAPS : Gfx::ParticleType::PARTILENS1; + m_particleManager->CreateParticle(Math::Vector(mousePosition.x, mousePosition.y, 0), CreateRandomSpeedForMouseParticles(), + CreateRandomDimensionsForMouseParticles(buttonPressed), particleType, + CreateRandomDurationForMouseParticles(), 2.0f, 0.0f, Gfx::SH_INTERFACE); + } + + Math::Point CParticlesGenerator::CreateRandomDimensionsForMouseParticles(bool buttonPressed) + { + float dimensionX = buttonPressed ? (0.005f + Math::Rand() * 0.005f) : (0.01f + Math::Rand() * 0.01f); + return Math::Point(dimensionX, dimensionX / 0.75f); + } + + Math::Vector CParticlesGenerator::CreateRandomSpeedForMouseParticles() + { + return Math::Vector((Math::Rand() - 0.5f) * 0.5f, 0.3f + Math::Rand() * 0.3f, 0.0f); + } + + float CParticlesGenerator::CreateRandomDurationForMouseParticles() + { + return Math::Rand() * 0.5f + 0.5f; + } + +} diff --git a/src/ui/particlesGenerator.h b/src/ui/particlesGenerator.h new file mode 100644 index 00000000..e96b6c04 --- /dev/null +++ b/src/ui/particlesGenerator.h @@ -0,0 +1,47 @@ +/* + * This file is part of the Colobot: Gold Edition source code + * Copyright (C) 2001-2020, Daniel Roux, EPSITEC SA & TerranovaTeam + * http://epsitec.ch; http://colobot.info; http://github.com/colobot + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://gnu.org/licenses + */ + +#pragma once + +#include "graphics/engine/particle.h" + +#include "math/point.h" +#include "math/vector.h" + +namespace UI +{ + /** + * \brief class for generating particles in the menu + */ + class CParticlesGenerator + { + public: + CParticlesGenerator(); + /** + * \brief generates particles after mouse cursor movement + */ + void GenerateMouseParticles(Math::Point mousePosition, bool buttonPressed); + private: + Gfx::CParticle* m_particleManager; + Math::Point CreateRandomDimensionsForMouseParticles(bool buttonPressed); + Math::Vector CreateRandomSpeedForMouseParticles(); + float CreateRandomDurationForMouseParticles(); + }; + +} diff --git a/src/ui/screen/screen_setup_game.cpp b/src/ui/screen/screen_setup_game.cpp index 70929bb7..5a519b54 100644 --- a/src/ui/screen/screen_setup_game.cpp +++ b/src/ui/screen/screen_setup_game.cpp @@ -173,7 +173,7 @@ bool CScreenSetupGame::EventProcess(const Event &event) break; case EVENT_INTERFACE_RAIN: - m_settings->SetInterfaceRain(!m_settings->GetInterfaceRain()); + m_settings->SetMouseParticlesEnabled(!m_settings->GetMouseParticlesEnabled()); ChangeSetupButtons(); UpdateSetupButtons(); break; @@ -291,7 +291,7 @@ void CScreenSetupGame::UpdateSetupButtons() pc = static_cast(pw->SearchControl(EVENT_INTERFACE_RAIN)); if ( pc != nullptr ) { - pc->SetState(STATE_CHECK, m_settings->GetInterfaceRain()); + pc->SetState(STATE_CHECK, m_settings->GetMouseParticlesEnabled()); } pc = static_cast(pw->SearchControl(EVENT_INTERFACE_BGPAUSE));