Push sliders fonctionnels (x4)

This commit is contained in:
mduval76 2023-12-01 17:55:25 -05:00
parent 90e736a14c
commit def1ab284e
2 changed files with 96 additions and 95 deletions

View File

@ -572,10 +572,10 @@ void Engine::DrawOption()
}
void Engine::DisplayAudioMenu(float centerX, float centerY) {
glColor4f(1.0f, 0.5f, 0.0f, 1.0f);
float minBar = centerX - Width() * 0.15;
float maxBar = centerX + Width() * 0.3;
glColor4f(1.0f, 0.5f, 0.0f, 1.0f);
m_texturePrincipal.Bind();
glBegin(GL_QUADS);
glTexCoord2f(0, 0); glVertex2i(centerX - Width() * 0.15, centerY + Height() * 0.215);
@ -584,22 +584,11 @@ void Engine::DisplayAudioMenu(float centerX, float centerY) {
glTexCoord2f(0, 1); glVertex2i(centerX - Width() * 0.15, centerY + Height() * 0.25);
glEnd();
glColor4f(0.0f, 0.0f, 0.0f, 1.0f);
glBindTexture(GL_TEXTURE_2D, 0);
glBegin(GL_QUADS);
glTexCoord2f(0, 0); glVertex2i(minBar, centerY + Height() * 0.165);
glTexCoord2f(1, 0); glVertex2i(maxBar, centerY + Height() * 0.165);
glTexCoord2f(1, 1); glVertex2i(maxBar, centerY + Height() * 0.2);
glTexCoord2f(0, 1); glVertex2i(minBar, centerY + Height() * 0.2);
glEnd();
float principalBottom = centerY + Height() * 0.165f;
float principalTop = centerY + Height() * 0.2f;
glColor4f(0.0f, 1.0f, 0.0f, 1.0f);
glBegin(GL_QUADS);
glTexCoord2f(0, 0); glVertex2i(minBar, centerY + Height() * 0.165);
glTexCoord2f(1, 0); glVertex2i(minBar + m_volMain, centerY + Height() * 0.165);
glTexCoord2f(1, 1); glVertex2i(minBar + m_volMain, centerY + Height() * 0.2);
glTexCoord2f(0, 1); glVertex2i(minBar, centerY + Height() * 0.2);
glEnd();
DrawSliderBackground(centerX, centerY, minBar, maxBar, principalBottom, principalTop);
RedrawSlider(centerX, centerY, m_volPrincipal, minBar, maxBar, principalBottom, principalTop);
glColor4f(1.0f, 0.5f, 0.0f, 1.0f);
m_textureMusique.Bind();
@ -610,22 +599,11 @@ void Engine::DisplayAudioMenu(float centerX, float centerY) {
glTexCoord2f(0, 1); glVertex2i(centerX - Width() * 0.15, centerY + Height() * 0.125);
glEnd();
glColor4f(0.0f, 0.0f, 0.0f, 1.0f);
glBindTexture(GL_TEXTURE_2D, 0);
glBegin(GL_QUADS);
glTexCoord2f(0, 0); glVertex2i(minBar, centerY + Height() * 0.04);
glTexCoord2f(1, 0); glVertex2i(maxBar, centerY + Height() * 0.04);
glTexCoord2f(1, 1); glVertex2i(maxBar, centerY + Height() * 0.075);
glTexCoord2f(0, 1); glVertex2i(minBar, centerY + Height() * 0.075);
glEnd();
float musiqueBottom = centerY + Height() * 0.04f;
float musiqueTop = centerY + Height() * 0.075f;
glColor4f(0.0f, 1.0f, 0.0f, 1.0f);
glBegin(GL_QUADS);
glTexCoord2f(0, 0); glVertex2i(minBar, centerY + Height() * 0.04);
glTexCoord2f(1, 0); glVertex2i(minBar + m_volMusic, centerY + Height() * 0.04);
glTexCoord2f(1, 1); glVertex2i(minBar + m_volMusic, centerY + Height() * 0.075);
glTexCoord2f(0, 1); glVertex2i(minBar, centerY + Height() * 0.075);
glEnd();
DrawSliderBackground(centerX, centerY, minBar, maxBar, musiqueBottom, musiqueTop);
RedrawSlider(centerX, centerY, m_volMusique, minBar, maxBar, musiqueBottom, musiqueTop);
glColor4f(1.0f, 0.5f, 0.0f, 1.0f);
m_textureEffets.Bind();
@ -636,22 +614,11 @@ void Engine::DisplayAudioMenu(float centerX, float centerY) {
glTexCoord2f(0, 1); glVertex2i(centerX - Width() * 0.15, centerY - Height() * 0.00001);
glEnd();
glColor4f(0.0f, 0.0f, 0.0f, 1.0f);
glBindTexture(GL_TEXTURE_2D, 0);
glBegin(GL_QUADS);
glTexCoord2f(0, 0); glVertex2i(minBar, centerY - Height() * 0.085);
glTexCoord2f(1, 0); glVertex2i(maxBar, centerY - Height() * 0.085);
glTexCoord2f(1, 1); glVertex2i(maxBar, centerY - Height() * 0.05);
glTexCoord2f(0, 1); glVertex2i(minBar, centerY - Height() * 0.05);
glEnd();
float effectsBottom = centerY - Height() * 0.085f;
float effectsTop = centerY - Height() * 0.05f;
glColor4f(0.0f, 1.0f, 0.0f, 1.0f);
glBegin(GL_QUADS);
glTexCoord2f(0, 0); glVertex2i(minBar, centerY - Height() * 0.085);
glTexCoord2f(1, 0); glVertex2i(minBar + m_volEffects, centerY - Height() * 0.085);
glTexCoord2f(1, 1); glVertex2i(minBar + m_volEffects, centerY - Height() * 0.05);
glTexCoord2f(0, 1); glVertex2i(minBar, centerY - Height() * 0.05);
glEnd();
DrawSliderBackground(centerX, centerY, minBar, maxBar, effectsBottom, effectsTop);
RedrawSlider(centerX, centerY, m_volEffets, minBar, maxBar, effectsBottom, effectsTop);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
}
@ -704,6 +671,7 @@ void Engine::DisplayGraphicsMenu(float centerX, float centerY) {
float heightRatioBottom = 0.125f;
float heightRatioTop = 0.15;
// Checkboxes
for (int i = 0; i < 4; i++) {
if (static_cast<int>(m_resolution) == i) {
m_textureChecked.Bind();
@ -739,24 +707,43 @@ void Engine::DisplayGameplayMenu(float centerX, float centerY) {
glTexCoord2f(0, 1); glVertex2i(centerX - Width() * 0.15, centerY + Height() * 0.25);
glEnd();
float sensibleBottom = centerY + Height() * 0.165f;
float sensibleTop = centerY + Height() * 0.2f;
DrawSliderBackground(centerX, centerY, minBar, maxBar, sensibleBottom, sensibleTop);
RedrawSlider(centerX, centerY, m_volSensible, minBar, maxBar, sensibleBottom, sensibleTop);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
}
void Engine::DrawSliderBackground(float centerX, float centerY, float minVal, float maxVal, float bottomSideValue, float topSideValue) {
glColor4f(0.0f, 0.0f, 0.0f, 1.0f);
glBindTexture(GL_TEXTURE_2D, 0);
glBegin(GL_QUADS);
glTexCoord2f(0, 0); glVertex2i(centerX - Width() * 0.15, centerY + Height() * 0.165);
glTexCoord2f(1, 0); glVertex2i(centerX + Width() * 0.3, centerY + Height() * 0.165);
glTexCoord2f(1, 1); glVertex2i(centerX + Width() * 0.3, centerY + Height() * 0.2);
glTexCoord2f(0, 1); glVertex2i(centerX - Width() * 0.15, centerY + Height() * 0.2);
glTexCoord2f(0, 0); glVertex2i(minVal, bottomSideValue);
glTexCoord2f(1, 0); glVertex2i(maxVal, bottomSideValue);
glTexCoord2f(1, 1); glVertex2i(maxVal, topSideValue);
glTexCoord2f(0, 1); glVertex2i(minVal, topSideValue);
glEnd();
}
void Engine::RedrawSlider(float centerX, float centerY, float value, float minVal, float maxVal, float bottomSideValue, float topSideValue) {
if (value < 0.0f) {
value = 0.0f;
}
else if (value > (maxVal - minVal)) {
value = (maxVal - minVal);
}
if (value >= 0.0f && value <= (maxVal - minVal)) {
glColor4f(0.0f, 1.0f, 0.0f, 1.0f);
glBegin(GL_QUADS);
glTexCoord2f(0, 0); glVertex2i(minBar, centerY + Height() * 0.165);
glTexCoord2f(1, 0); glVertex2i(minBar + m_volSensible, centerY + Height() * 0.165);
glTexCoord2f(1, 1); glVertex2i(minBar + m_volSensible, centerY + Height() * 0.2);
glTexCoord2f(0, 1); glVertex2i(minBar, centerY + Height() * 0.2);
glTexCoord2f(0, 0); glVertex2i(minVal, bottomSideValue);
glTexCoord2f(1, 0); glVertex2i(minVal + value, bottomSideValue);
glTexCoord2f(1, 1); glVertex2i(minVal + value, topSideValue);
glTexCoord2f(0, 1); glVertex2i(minVal, topSideValue);
glEnd();
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
}
}
void Engine::InstantDamage()
@ -1700,6 +1687,7 @@ void Engine::KeyReleaseEvent(unsigned char key) {
}
void Engine::MouseMoveEvent(int x, int y) {
if (m_gamestate == GameState::PLAY) {
m_player.TurnLeftRight(x - (Width() / 2));
m_player.TurnTopBottom(y - (Height() / 2));
@ -1710,7 +1698,26 @@ void Engine::MouseMoveEvent(int x, int y) {
// MouseMoveEvent, etc
if (x == (Width() / 2) && y == (Height() / 2))
return;
}
else if (m_gamestate == GameState::OPTIONS) {
float centerX = Width() * 0.5f;
float centerY = Height() * 0.5f;
float leftBar = centerX - Width() * 0.15f;
float rightBar = centerX + Width() * 0.3f;
if (m_selectedOption == 0 && m_selectedPrincipalBar) {
m_volPrincipal = x - leftBar;
}
else if (m_selectedOption == 0 && m_selectedMusiqueBar) {
m_volMusique = x - leftBar;
}
else if (m_selectedOption == 0 && m_selectedEffetsBar) {
m_volEffets = x - leftBar;
}
else if (m_selectedOption == 2 && m_selectedSensibleBar) {
m_volSensible = x - leftBar;
}
}
}
void Engine::MousePressEvent(const MOUSE_BUTTON& button, int x, int y) {
@ -1790,19 +1797,16 @@ void Engine::MousePressEvent(const MOUSE_BUTTON& button, int x, int y) {
float bottomBarEffets = centerY + Height() * 0.05f;
if (m_selectedOption == 0 && x > leftBar && x < rightBar && y > bottomBarPrincipal && y < topBarPrincipal) {
std::cout << "Hit PRINCIPAL BAR" << std::endl;
m_volMain = x - leftBar;
m_volPrincipal = x - leftBar;
m_selectedPrincipalBar = true;
}
else if (m_selectedOption == 0 && x > leftBar && x < rightBar && y > bottomBarMusique && y < topBarMusique) {
std::cout << "Hit MUSIQUE BAR" << std::endl;
m_volMusic = x - leftBar;
m_selectedMusicBar = true;
m_volMusique = x - leftBar;
m_selectedMusiqueBar = true;
}
else if (m_selectedOption == 0 && x > leftBar && x < rightBar && y > bottomBarEffets && y < topBarEffets) {
std::cout << "Hit EFFETS BAR" << std::endl;
m_volEffects = x - leftBar;
m_selectedEffectsBar = true;
m_volEffets = x - leftBar;
m_selectedEffetsBar = true;
}
// Resolution
@ -1822,27 +1826,22 @@ void Engine::MousePressEvent(const MOUSE_BUTTON& button, int x, int y) {
float bottomChkUHD = centerY;
if (m_selectedOption == 1 && leftChk && x < rightChk && y > bottomChkHD && y < topChkHD) {
std::cout << "HD" << std::endl;
m_resolution = HD;
}
else if (m_selectedOption == 1 && x > leftChk && x < rightChk && y > bottomChkFHD && y < topChkFHD) {
std::cout << "FHD" << std::endl;
m_resolution = FHD;
}
else if (m_selectedOption == 1 && x > leftChk && x < rightChk && y > bottomChkQHD && y < topChkQHD) {
std::cout << "QHD" << std::endl;
m_resolution = QHD;
}
else if (m_selectedOption == 1 && x > leftChk && x < rightChk && y > bottomChkUHD && y < topChkUHD) {
std::cout << "UHD" << std::endl;
m_resolution = UHD;
}
// Gameplay
if (m_selectedOption == 2 && x > leftBar && x < rightBar && y > bottomBarPrincipal && y < topBarPrincipal) {
std::cout << "Hit SENSIBILITE BAR" << std::endl;
m_volSensible = x - leftBar;
m_selectedSensibilityBar = true;
m_selectedSensibleBar = true;
}
}
else if (m_gamestate == GameState::SINGLEMULTI)
@ -1882,9 +1881,9 @@ void Engine::MouseReleaseEvent(const MOUSE_BUTTON& button, int x, int y) {
m_mouseL = false;
m_block = false;
m_selectedPrincipalBar = false;
m_selectedMusicBar = false;
m_selectedEffectsBar = false;
m_selectedSensibilityBar = false;
m_selectedMusiqueBar = false;
m_selectedEffetsBar = false;
m_selectedSensibleBar = false;
break;
case MOUSE_BUTTON_RIGHT:
m_mouseR = false;

View File

@ -64,6 +64,8 @@ private:
void DisplayAudioMenu(float centerX, float centerY);
void DisplayGraphicsMenu(float centerX, float centerY);
void DisplayGameplayMenu(float centerX, float centerY);
void DrawSliderBackground(float centerX, float centerY, float minVal, float maxVal, float bottomSideValue, float topSideValue);
void RedrawSlider(float centerX, float centerY, float value, float minVal, float maxVal, float bottomSideValue, float topSideValue);
void DrawHud(float elapsedTime, BlockType bloc);
void PrintText(float x, float y, const std::string& t, float charSizeMultiplier = 1.0f);
void ProcessNotificationQueue();
@ -152,17 +154,17 @@ private:
int m_nbReductionChunk = 4;
int m_timerReductionChunk = 30;
float m_volMain = 50.0f;
float m_volMusic = 50.0f;
float m_volEffects = 50.0f;
float m_volSensible = 50.0f;
float m_volPrincipal = 0.0f;
float m_volMusique = 0.0f;
float m_volEffets = 0.0f;
float m_volSensible = 0.0f;
int m_selectedOption = 0;
bool m_selectedPrincipalBar = false;
bool m_selectedMusicBar = false;
bool m_selectedEffectsBar = false;
bool m_selectedSensibilityBar = false;
bool m_selectedMusiqueBar = false;
bool m_selectedEffetsBar = false;
bool m_selectedSensibleBar = false;
bool m_damage = false;