From ff10207257cbb893cc667963c9385ae43773daee Mon Sep 17 00:00:00 2001 From: mduval76 <9343789@etu.cegepsth.qc.ca> Date: Fri, 8 Dec 2023 23:06:33 -0500 Subject: [PATCH] Push backspace fonctionnel --- SQCSim2021/engine.cpp | 106 ++++++++++++++++++++++++++---------------- SQCSim2021/engine.h | 9 +++- 2 files changed, 72 insertions(+), 43 deletions(-) diff --git a/SQCSim2021/engine.cpp b/SQCSim2021/engine.cpp index fcdd44f..258480e 100644 --- a/SQCSim2021/engine.cpp +++ b/SQCSim2021/engine.cpp @@ -759,14 +759,21 @@ void Engine::DisplayLobbyMenu(float elapsedTime) { std::ostringstream ss; glColor4f(1.0f, 1.0f, 1.0f, 1.0f); - if (m_charChanged && m_currentInputString.size() < 26) { - m_currentInputString += m_inputChar; + if (m_charChanged) { + if (m_keyBackspace) { + if (!m_currentInputString.empty()) { + m_currentInputString.pop_back(); + } + m_keyBackspace = false; + } + else if (m_currentInputString.size() < 26) { + m_currentInputString += m_inputChar; + } } ss << m_currentInputString; m_charChanged = false; - if (lobbyTime < onInterval) { ss << "_"; } @@ -794,6 +801,10 @@ void Engine::DisplayLobbyMenu(float elapsedTime) { } +void Engine::SetLobbyUsername() { + +} + void Engine::DisplayMainMenu() { GLint viewport[4]; glGetIntegerv(GL_VIEWPORT, viewport); @@ -1691,50 +1702,19 @@ void Engine::KeyReleaseEvent(unsigned char key) { case 57: // Espace - Stop sauter m_keySpace = false; break; - } -} - -void Engine::MouseMoveEvent(int x, int y) { - if (m_gamestate == GameState::PLAY) { - m_player.TurnLeftRight(x - (Width() / 2)); - m_player.TurnTopBottom(y - (Height() / 2)); - - // Centrer la souris seulement si elle n'est pas d�j� centr�e - // Il est n�cessaire de faire la v�rification pour �viter de tomber - // dans une boucle infinie o� l'appel � CenterMouse g�n�re un - // MouseMoveEvent, qui rapelle CenterMouse qui rapelle un autre - // MouseMoveEvent, etc - if (x == (Width() / 2) && y == (Height() / 2)) - return; - } - else if (m_gamestate == GameState::MAIN_MENU) { - DisplayMainMenu(); - } - 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_selectedOptAudioMainBar) { - m_volPrincipal = x - leftBar; - } - else if (m_selectedOption == 0 && m_selectedOptAudioMusicBar) { - m_volMusique = x - leftBar; - } - else if (m_selectedOption == 0 && m_selectedOptAudioSfxBar) { - m_volEffets = x - leftBar; - } - else if (m_selectedOption == 2 && m_selectedGameplaySensitivityBar) { - m_volSensible = x - leftBar; - } + case 58: // Enter - comfirm input + m_keyEnter = false; + break; + case 59: // backspace - remove char + m_keyBackspace = false; + break; } } char Engine::SimulateKeyboard(unsigned char key) { switch (key) { case 0: // A - if (!m_keyShift) { m_inputChar = 'a'; } + if (!m_keyShift) { m_inputChar = 'a'; } else { m_inputChar = 'A'; } break; case 1: // B @@ -1890,6 +1870,12 @@ char Engine::SimulateKeyboard(unsigned char key) { case 57: // SPACE m_inputChar = ' '; break; + case 58: // ENTER + m_keyEnter = true; + break; + case 59: // BACKSPACE + m_keyBackspace = true; + break; default: m_invalidChar = true; break; @@ -1904,6 +1890,44 @@ char Engine::SimulateKeyboard(unsigned char key) { return m_inputChar; } + +void Engine::MouseMoveEvent(int x, int y) { + if (m_gamestate == GameState::PLAY) { + m_player.TurnLeftRight(x - (Width() / 2)); + m_player.TurnTopBottom(y - (Height() / 2)); + + // Centrer la souris seulement si elle n'est pas d�j� centr�e + // Il est n�cessaire de faire la v�rification pour �viter de tomber + // dans une boucle infinie o� l'appel � CenterMouse g�n�re un + // MouseMoveEvent, qui rapelle CenterMouse qui rapelle un autre + // MouseMoveEvent, etc + if (x == (Width() / 2) && y == (Height() / 2)) + return; + } + else if (m_gamestate == GameState::MAIN_MENU) { + DisplayMainMenu(); + } + 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_selectedOptAudioMainBar) { + m_volPrincipal = x - leftBar; + } + else if (m_selectedOption == 0 && m_selectedOptAudioMusicBar) { + m_volMusique = x - leftBar; + } + else if (m_selectedOption == 0 && m_selectedOptAudioSfxBar) { + m_volEffets = x - leftBar; + } + else if (m_selectedOption == 2 && m_selectedGameplaySensitivityBar) { + m_volSensible = x - leftBar; + } + } +} + void Engine::MousePressEvent(const MOUSE_BUTTON& button, int x, int y) { m_mousemx = x; m_mousemy = y; diff --git a/SQCSim2021/engine.h b/SQCSim2021/engine.h index 1f8363f..31b60ec 100644 --- a/SQCSim2021/engine.h +++ b/SQCSim2021/engine.h @@ -62,13 +62,16 @@ private: void DisplayInfo(float elapsedTime, BlockType bloc); void DisplaySplashScreen(); - void DisplayLobbyMenu(float elapsedTime); void DisplayMainMenu(); void DrawButtonBackgrounds(float centerX, float centerY, int iterations); void DrawMainMenuButtons(float centerX, float centerY); void DrawSingleMultiButtons(float centerX, float centerY); + void DisplayLobbyMenu(float elapsedTime); + void SetLobbyUsername(); + void SetLobbyServerAddress(); + void DisplayOptionsMenu(); void DisplayAudioMenu(float centerX, float centerY); void DisplayGraphicsMenu(float centerX, float centerY); @@ -77,7 +80,6 @@ private: void DisplayBarPercentValue(float centerX, float centerY, float posX, float posY, float minVal, float maxVal, float value); void DrawSlider(float centerX, float centerY, float value, float minVal, float maxVal, float bottomSideValue, float topSideValue); - void PrintText(float x, float y, const std::string& t, float charSizeMultiplier = 1.0f); void ProcessNotificationQueue(); char SimulateKeyboard(unsigned char key); @@ -207,6 +209,8 @@ private: char m_inputChar = 0; bool m_invalidChar = false; bool m_charChanged = false; + bool m_settingUsername = false; + bool m_settingServer = false; bool m_key1 = false; bool m_key2 = false; @@ -219,6 +223,7 @@ private: bool m_keyEnter = false; bool m_keySpace = false; bool m_keyShift = false; + bool m_keyBackspace = false; bool m_mouseL = false; bool m_mouseR = false;