Refactor - Move UI mouse particles generation to a new class. (#1308)

* Move UI mouse particles generation to a new class.

* refactoring

* refactor - change variable name

* change backslashes to forward slashes in include directives

* remove & from variable

* Refactoring - fix linter issues

* Refactoring - fix linter issues

* refactoring - fix linter issues
1164-fix
MrJohn10 2020-07-07 20:48:52 +02:00 committed by GitHub
parent 6efc977286
commit 35b22f7a7f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 169 additions and 88 deletions

View File

@ -585,6 +585,8 @@ set(BASE_SOURCES
ui/screen/screen_welcome.h ui/screen/screen_welcome.h
ui/studio.cpp ui/studio.cpp
ui/studio.h ui/studio.h
ui/particlesGenerator.cpp
ui/particlesGenerator.h
) )
set(MAIN_SOURCES set(MAIN_SOURCES

View File

@ -34,23 +34,23 @@
CSettings::CSettings() CSettings::CSettings()
{ {
m_tooltips = true; m_tooltips = true;
m_interfaceGlint = true; m_interfaceGlint = true;
m_interfaceRain = true; m_mouseParticlesEnabled = true;
m_soluce4 = true; m_soluce4 = true;
m_movies = true; m_movies = true;
m_focusLostPause = 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_windowPos = Math::Point(0.15f, 0.17f);
m_windowDim = Math::Point(0.70f, 0.66f); m_windowDim = Math::Point(0.70f, 0.66f);
m_windowMax = false; m_windowMax = false;
m_IOPublic = false; m_IOPublic = false;
m_IODim = Math::Point(320.0f/640.0f, (121.0f+18.0f*8)/480.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.x = (1.0f - m_IODim.x) / 2.0f; // in the middle
m_IOPos.y = (1.0f-m_IODim.y)/2.0f; m_IOPos.y = (1.0f - m_IODim.y) / 2.0f;
m_language = LANGUAGE_ENV; m_language = LANGUAGE_ENV;
} }
@ -76,7 +76,7 @@ void CSettings::SaveSettings()
GetConfigFile().SetBoolProperty("Setup", "Tooltips", m_tooltips); GetConfigFile().SetBoolProperty("Setup", "Tooltips", m_tooltips);
GetConfigFile().SetBoolProperty("Setup", "InterfaceGlint", m_interfaceGlint); 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", "Soluce4", m_soluce4);
GetConfigFile().SetBoolProperty("Setup", "Movies", m_movies); GetConfigFile().SetBoolProperty("Setup", "Movies", m_movies);
GetConfigFile().SetBoolProperty("Setup", "FocusLostPause", m_focusLostPause); GetConfigFile().SetBoolProperty("Setup", "FocusLostPause", m_focusLostPause);
@ -110,7 +110,7 @@ void CSettings::SaveSettings()
GetConfigFile().SetBoolProperty("Setup", "ShadowMapping", engine->GetShadowMapping()); GetConfigFile().SetBoolProperty("Setup", "ShadowMapping", engine->GetShadowMapping());
GetConfigFile().SetBoolProperty("Setup", "ShadowMappingQuality", engine->GetShadowMappingQuality()); GetConfigFile().SetBoolProperty("Setup", "ShadowMappingQuality", engine->GetShadowMappingQuality());
GetConfigFile().SetIntProperty("Setup", "ShadowMappingResolution", GetConfigFile().SetIntProperty("Setup", "ShadowMappingResolution",
engine->GetShadowMappingOffscreen() ? engine->GetShadowMappingOffscreenResolution() : 0); engine->GetShadowMappingOffscreen() ? engine->GetShadowMappingOffscreenResolution() : 0);
// Experimental settings // Experimental settings
GetConfigFile().SetBoolProperty("Experimental", "TerrainShadows", engine->GetTerrainShadows()); GetConfigFile().SetBoolProperty("Experimental", "TerrainShadows", engine->GetTerrainShadows());
@ -125,7 +125,7 @@ void CSettings::SaveSettings()
GetConfigFile().SetFloatProperty("Edit", "WindowPosY", m_windowPos.y); GetConfigFile().SetFloatProperty("Edit", "WindowPosY", m_windowPos.y);
GetConfigFile().SetFloatProperty("Edit", "WindowDimX", m_windowDim.x); GetConfigFile().SetFloatProperty("Edit", "WindowDimX", m_windowDim.x);
GetConfigFile().SetFloatProperty("Edit", "WindowDimY", m_windowDim.y); 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().SetBoolProperty("Edit", "IOPublic", m_IOPublic);
GetConfigFile().SetFloatProperty("Edit", "IOPosX", m_IOPos.x); GetConfigFile().SetFloatProperty("Edit", "IOPosX", m_IOPos.x);
@ -155,7 +155,7 @@ void CSettings::LoadSettings()
GetConfigFile().GetBoolProperty("Setup", "Tooltips", m_tooltips); GetConfigFile().GetBoolProperty("Setup", "Tooltips", m_tooltips);
GetConfigFile().GetBoolProperty("Setup", "InterfaceGlint", m_interfaceGlint); 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", "Soluce4", m_soluce4);
GetConfigFile().GetBoolProperty("Setup", "Movies", m_movies); GetConfigFile().GetBoolProperty("Setup", "Movies", m_movies);
GetConfigFile().GetBoolProperty("Setup", "FocusLostPause", m_focusLostPause); GetConfigFile().GetBoolProperty("Setup", "FocusLostPause", m_focusLostPause);
@ -202,7 +202,7 @@ void CSettings::LoadSettings()
if (iValue >= 0) if (iValue >= 0)
{ {
auto joysticks = app->GetJoystickList(); auto joysticks = app->GetJoystickList();
for(const auto& joystick : joysticks) for (const auto& joystick : joysticks)
{ {
if (joystick.index == iValue) if (joystick.index == iValue)
{ {
@ -287,18 +287,18 @@ void CSettings::LoadSettings()
GetConfigFile().GetFloatProperty("Edit", "FontSize", m_fontSize); GetConfigFile().GetFloatProperty("Edit", "FontSize", m_fontSize);
GetConfigFile().GetFloatProperty("Edit", "WindowPosX", m_windowPos.x); GetConfigFile().GetFloatProperty("Edit", "WindowPosX", m_windowPos.x);
GetConfigFile().GetFloatProperty("Edit", "WindowPosY", m_windowPos.y); GetConfigFile().GetFloatProperty("Edit", "WindowPosY", m_windowPos.y);
GetConfigFile().GetFloatProperty("Edit", "WindowDimX", m_windowDim.x); GetConfigFile().GetFloatProperty("Edit", "WindowDimX", m_windowDim.x);
GetConfigFile().GetFloatProperty("Edit", "WindowDimY", m_windowDim.y); GetConfigFile().GetFloatProperty("Edit", "WindowDimY", m_windowDim.y);
GetConfigFile().GetBoolProperty ("Edit", "WindowMaximized", m_windowMax); GetConfigFile().GetBoolProperty("Edit", "WindowMaximized", m_windowMax);
GetConfigFile().GetBoolProperty ("Edit", "IOPublic", m_IOPublic); GetConfigFile().GetBoolProperty("Edit", "IOPublic", m_IOPublic);
GetConfigFile().GetFloatProperty("Edit", "IOPosX", m_IOPos.x); GetConfigFile().GetFloatProperty("Edit", "IOPosX", m_IOPos.x);
GetConfigFile().GetFloatProperty("Edit", "IOPosY", m_IOPos.y); GetConfigFile().GetFloatProperty("Edit", "IOPosY", m_IOPos.y);
GetConfigFile().GetFloatProperty("Edit", "IODimX", m_IODim.x); GetConfigFile().GetFloatProperty("Edit", "IODimX", m_IODim.x);
GetConfigFile().GetFloatProperty("Edit", "IODimY", m_IODim.y); GetConfigFile().GetFloatProperty("Edit", "IODimY", m_IODim.y);
m_language = LANGUAGE_ENV; m_language = LANGUAGE_ENV;
if (GetConfigFile().GetStringProperty("Language", "Lang", sValue)) if (GetConfigFile().GetStringProperty("Language", "Lang", sValue))
@ -306,7 +306,7 @@ void CSettings::LoadSettings()
if (!sValue.empty() && !ParseLanguage(sValue, m_language)) if (!sValue.empty() && !ParseLanguage(sValue, m_language))
{ {
GetLogger()->Error("Failed to parse language '%s' from config file. Default language will be used.\n", 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); app->SetLanguage(m_language);
@ -330,13 +330,13 @@ bool CSettings::GetInterfaceGlint()
return m_interfaceGlint; 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) void CSettings::SetSoluce4(bool soluce4)

View File

@ -26,7 +26,7 @@
namespace Gfx namespace Gfx
{ {
struct DeviceConfig; struct DeviceConfig;
} }
class CSettings : public CSingleton<CSettings> class CSettings : public CSingleton<CSettings>
@ -44,8 +44,8 @@ public:
void SetInterfaceGlint(bool interfaceGlint); void SetInterfaceGlint(bool interfaceGlint);
bool GetInterfaceGlint(); bool GetInterfaceGlint();
void SetInterfaceRain(bool interfaceRain); void SetMouseParticlesEnabled(bool mouseParticlesEnabled);
bool GetInterfaceRain(); bool GetMouseParticlesEnabled();
void SetSoluce4(bool soluce4); void SetSoluce4(bool soluce4);
bool GetSoluce4(); bool GetSoluce4();
@ -95,7 +95,7 @@ public:
protected: protected:
bool m_tooltips; bool m_tooltips;
bool m_interfaceGlint; bool m_interfaceGlint;
bool m_interfaceRain; bool m_mouseParticlesEnabled;
bool m_soluce4; bool m_soluce4;
bool m_movies; bool m_movies;
bool m_focusLostPause; bool m_focusLostPause;

View File

@ -35,6 +35,8 @@
#include "ui/maindialog.h" #include "ui/maindialog.h"
#include "ui/particlesGenerator.h"
#include "ui/controls/group.h" #include "ui/controls/group.h"
#include "ui/controls/interface.h" #include "ui/controls/interface.h"
#include "ui/controls/label.h" #include "ui/controls/label.h"
@ -66,7 +68,7 @@ CMainUserInterface::CMainUserInterface()
m_app = CApplication::GetInstancePointer(); m_app = CApplication::GetInstancePointer();
m_main = CRobotMain::GetInstancePointer(); m_main = CRobotMain::GetInstancePointer();
m_engine = Gfx::CEngine::GetInstancePointer(); m_engine = Gfx::CEngine::GetInstancePointer();
m_particle = m_engine->GetParticle(); m_particleManager = m_engine->GetParticle();
m_interface = m_main->GetInterface(); m_interface = m_main->GetInterface();
m_sound = m_app->GetSound(); m_sound = m_app->GetSound();
m_settings = CSettings::GetInstancePointer(); m_settings = CSettings::GetInstancePointer();
@ -87,6 +89,7 @@ CMainUserInterface::CMainUserInterface()
m_screenPlayerSelect = MakeUnique<CScreenPlayerSelect>(m_dialog.get()); m_screenPlayerSelect = MakeUnique<CScreenPlayerSelect>(m_dialog.get());
m_screenQuit = MakeUnique<CScreenQuit>(); m_screenQuit = MakeUnique<CScreenQuit>();
m_screenWelcome = MakeUnique<CScreenWelcome>(); m_screenWelcome = MakeUnique<CScreenWelcome>();
m_mouseParticlesGenerator = MakeUnique<UI::CParticlesGenerator>();
m_currentScreen = nullptr; m_currentScreen = nullptr;
@ -132,7 +135,6 @@ CScreenLoading* CMainUserInterface::GetLoadingScreen()
return m_screenLoading.get(); return m_screenLoading.get();
} }
// Changes phase. // Changes phase.
CScreenSetup* CMainUserInterface::GetSetupScreen(Phase phase) CScreenSetup* CMainUserInterface::GetSetupScreen(Phase phase)
@ -255,7 +257,7 @@ bool CMainUserInterface::EventProcess(const Event &event)
if ( event.type == EVENT_MOUSE_MOVE ) if ( event.type == EVENT_MOUSE_MOVE )
{ {
m_glintMouse = event.mousePos; 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; if (!m_dialog->EventProcess(event)) return false;
@ -520,7 +522,7 @@ void CMainUserInterface::FrameParticle(float rTime)
279.0f, 18.0f, 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 ) if ( m_phase == PHASE_MAIN_MENU )
{ {
@ -584,7 +586,7 @@ void CMainUserInterface::FrameParticle(float rTime)
speed.z = 0.0f; speed.z = 0.0f;
dim.x = 0.04f+Math::Rand()*0.04f; dim.x = 0.04f+Math::Rand()*0.04f;
dim.y = dim.x/0.75f; dim.y = dim.x/0.75f;
m_particle->CreateParticle(pos, speed, dim, m_particleManager->CreateParticle(pos, speed, dim,
rand()%2?Gfx::PARTIGLINT:Gfx::PARTICONTROL, rand()%2?Gfx::PARTIGLINT:Gfx::PARTICONTROL,
Math::Rand()*0.4f+0.4f, 0.0f, 0.0f, Math::Rand()*0.4f+0.4f, 0.0f, 0.0f,
Gfx::SH_INTERFACE); Gfx::SH_INTERFACE);
@ -650,7 +652,7 @@ void CMainUserInterface::FrameParticle(float rTime)
speed.z = 0.0f; speed.z = 0.0f;
dim.x = 0.005f+Math::Rand()*0.005f; dim.x = 0.005f+Math::Rand()*0.005f;
dim.y = dim.x/0.75f; 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, Math::Rand()*0.2f+0.2f, 0.0f, 0.0f,
Gfx::SH_INTERFACE); Gfx::SH_INTERFACE);
pos.x = m_particles[i].pos.x; pos.x = m_particles[i].pos.x;
@ -661,7 +663,7 @@ void CMainUserInterface::FrameParticle(float rTime)
speed.z = 0.0f; speed.z = 0.0f;
dim.x = 0.01f+Math::Rand()*0.01f; dim.x = 0.01f+Math::Rand()*0.01f;
dim.y = dim.x/0.75f; dim.y = dim.x/0.75f;
m_particle->CreateParticle(pos, speed, dim, m_particleManager->CreateParticle(pos, speed, dim,
static_cast<Gfx::ParticleType>(Gfx::PARTILENS1+rand()%3), static_cast<Gfx::ParticleType>(Gfx::PARTILENS1+rand()%3),
Math::Rand()*0.5f+0.5f, 2.0f, 0.0f, Math::Rand()*0.5f+0.5f, 2.0f, 0.0f,
Gfx::SH_INTERFACE); Gfx::SH_INTERFACE);
@ -678,7 +680,7 @@ void CMainUserInterface::FrameParticle(float rTime)
speed.z = 0.0f; speed.z = 0.0f;
dim.x = 0.005f+Math::Rand()*0.005f; dim.x = 0.005f+Math::Rand()*0.005f;
dim.y = dim.x/0.75f; 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, Math::Rand()*0.2f+0.2f, 0.0f, 0.0f,
Gfx::SH_INTERFACE); Gfx::SH_INTERFACE);
pos.x = m_particles[i].pos.x; pos.x = m_particles[i].pos.x;
@ -689,7 +691,7 @@ void CMainUserInterface::FrameParticle(float rTime)
speed.z = 0.0f; speed.z = 0.0f;
dim.x = 0.005f+Math::Rand()*0.005f; dim.x = 0.005f+Math::Rand()*0.005f;
dim.y = dim.x/0.75f; 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, Math::Rand()*0.5f+0.5f, 2.0f, 0.0f,
Gfx::SH_INTERFACE); Gfx::SH_INTERFACE);
} }
@ -705,7 +707,7 @@ void CMainUserInterface::FrameParticle(float rTime)
speed.z = 0.0f; speed.z = 0.0f;
dim.x = 0.03f+Math::Rand()*0.07f; dim.x = 0.03f+Math::Rand()*0.07f;
dim.y = dim.x/0.75f; 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, Math::Rand()*0.4f+0.4f, 0.0f, 0.0f,
Gfx::SH_INTERFACE); Gfx::SH_INTERFACE);
} }
@ -719,50 +721,20 @@ void CMainUserInterface::FrameParticle(float rTime)
} }
} }
// Some nice particles following the mouse. void CMainUserInterface::CreateMouseParticles(Math::Point mousePosition, bool buttonPressed)
void CMainUserInterface::NiceParticle(Math::Point mouse, bool bPress)
{ {
Math::Vector pos, speed; if (isAllowedToCreateMouseParticles())
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 )
{ {
pos.x = mouse.x; m_mouseParticlesGenerator->GenerateMouseParticles(Math::Point(mousePosition.x, mousePosition.y), buttonPressed);
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::ParticleType>(Gfx::PARTILENS1+rand()%3),
Math::Rand()*0.5f+0.5f, 2.0f, 0.0f,
Gfx::SH_INTERFACE);
} }
} }
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. // Updates the lists according to the cheat code.
void CMainUserInterface::AllMissionUpdate() void CMainUserInterface::AllMissionUpdate()

View File

@ -21,6 +21,8 @@
#include "level/robotmain.h" #include "level/robotmain.h"
#include "ui/particlesGenerator.h"
#include <array> #include <array>
#include <string> #include <string>
#include <vector> #include <vector>
@ -91,15 +93,14 @@ public:
protected: protected:
void GlintMove(); void GlintMove();
void FrameParticle(float rTime); void FrameParticle(float rTime);
void NiceParticle(Math::Point mouse, bool bPress); void CreateMouseParticles(Math::Point mousePosition, bool buttonPressed);
CScreenSetup* GetSetupScreen(Phase phase); CScreenSetup* GetSetupScreen(Phase phase);
protected: protected:
CApplication* m_app; CApplication* m_app;
CRobotMain* m_main; CRobotMain* m_main;
Gfx::CEngine* m_engine; Gfx::CEngine* m_engine;
Gfx::CParticle* m_particle; Gfx::CParticle* m_particleManager;
CInterface* m_interface; CInterface* m_interface;
CSoundInterface* m_sound; CSoundInterface* m_sound;
CSettings* m_settings; CSettings* m_settings;
@ -137,6 +138,10 @@ protected:
Math::Point pos; Math::Point pos;
}; };
std::array<Particle, 10> m_particles; std::array<Particle, 10> m_particles;
private:
std::unique_ptr<UI::CParticlesGenerator> m_mouseParticlesGenerator;
bool isAllowedToCreateMouseParticles();
}; };
} // namespace Ui } // namespace Ui

View File

@ -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;
}
}

View File

@ -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();
};
}

View File

@ -173,7 +173,7 @@ bool CScreenSetupGame::EventProcess(const Event &event)
break; break;
case EVENT_INTERFACE_RAIN: case EVENT_INTERFACE_RAIN:
m_settings->SetInterfaceRain(!m_settings->GetInterfaceRain()); m_settings->SetMouseParticlesEnabled(!m_settings->GetMouseParticlesEnabled());
ChangeSetupButtons(); ChangeSetupButtons();
UpdateSetupButtons(); UpdateSetupButtons();
break; break;
@ -291,7 +291,7 @@ void CScreenSetupGame::UpdateSetupButtons()
pc = static_cast<CCheck*>(pw->SearchControl(EVENT_INTERFACE_RAIN)); pc = static_cast<CCheck*>(pw->SearchControl(EVENT_INTERFACE_RAIN));
if ( pc != nullptr ) if ( pc != nullptr )
{ {
pc->SetState(STATE_CHECK, m_settings->GetInterfaceRain()); pc->SetState(STATE_CHECK, m_settings->GetMouseParticlesEnabled());
} }
pc = static_cast<CCheck*>(pw->SearchControl(EVENT_INTERFACE_BGPAUSE)); pc = static_cast<CCheck*>(pw->SearchControl(EVENT_INTERFACE_BGPAUSE));