Push menu Lobby pour single player (entree du username seulement)

This commit is contained in:
mduval76 2023-12-14 19:33:25 -05:00
parent e5b0c742dd
commit 58c06f9f84
3 changed files with 40 additions and 7 deletions

View File

@ -271,6 +271,10 @@ Vector3f Player::GetDirection() const { return m_direction; }
std::string Player::GetUsername() const { return m_username; }
void Player::SetUsername(std::string username) {
m_username = username;
}
float Player::GetSensitivity() const {
return m_sensitivity;
}

View File

@ -725,6 +725,7 @@ void Engine::DisplayLobbyMenu(float elapsedTime) {
GLint viewport[4];
glGetIntegerv(GL_VIEWPORT, viewport);
glDisable(GL_STENCIL_TEST);
glDisable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
@ -736,6 +737,7 @@ void Engine::DisplayLobbyMenu(float elapsedTime) {
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
m_textureLobbyMenu.Bind();
glBegin(GL_QUADS);
glTexCoord2f(0, 0); glVertex2i(0, 0);
@ -744,7 +746,6 @@ void Engine::DisplayLobbyMenu(float elapsedTime) {
glTexCoord2f(0, 1); glVertex2i(0, Height());
glEnd();
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
if (m_settingUsername) {
SetPlayerUsername(elapsedTime);
@ -764,7 +765,9 @@ void Engine::DisplayLobbyMenu(float elapsedTime) {
glViewport(viewport[0], viewport[1], viewport[2], viewport[3]);
glEnable(GL_STENCIL_TEST);
glEnable(GL_DEPTH_TEST);
glDisable(GL_BLEND);
glMatrixMode(GL_PROJECTION);
glPopMatrix();
@ -773,6 +776,7 @@ void Engine::DisplayLobbyMenu(float elapsedTime) {
}
void Engine::SetPlayerUsername(float elapsedTime) {
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
m_textureLobbyIdentify.Bind();
glBegin(GL_QUADS);
glTexCoord2f(0, 0); glVertex2i(Width() * 0.6, Height() * 0.75);
@ -784,11 +788,10 @@ void Engine::SetPlayerUsername(float elapsedTime) {
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
HandlePlayerInput(elapsedTime);
glDisable(GL_BLEND);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
}
void Engine::SetServerAddress(float elapsedTime) {
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
m_textureLobbyServer.Bind();
glBegin(GL_QUADS);
glTexCoord2f(0, 0); glVertex2i(Width() * 0.6, Height() * 0.75);
@ -801,7 +804,6 @@ void Engine::SetServerAddress(float elapsedTime) {
HandlePlayerInput(elapsedTime);
glDisable(GL_BLEND);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
}
void Engine::DisplayPauseMenu(float elapsedTime) {
@ -1295,6 +1297,11 @@ void Engine::Render(float elapsedTime) {
m_gamestate = GameState::MAIN_MENU;
}
}
else if (m_singleReady) {
m_gamestate = GameState::PLAY;
m_audio.ToggleMusicState(m_gamestate);
m_startTime = std::chrono::high_resolution_clock::now();
}
return;
}
@ -2102,10 +2109,17 @@ void Engine::HandlePlayerInput(float elapsedTime) {
m_currentInputString.size() > 1 &&
m_currentInputString.size() < 26) {
m_username = m_currentInputString;
m_player.SetUsername(m_username);
m_currentInputString = "";
m_settingUsername = false;
if (m_selectedMultiPlayer) {
m_settingServer = true;
}
else if (m_selectedSinglePlayer) {
m_singleReady = true;
}
}
}
else if (m_settingServer) {
if (!m_currentInputString.empty()) {
@ -2218,8 +2232,12 @@ void Engine::MousePressEvent(const MOUSE_BUTTON& button, int x, int y) {
if (x > leftButton && x < rightButton && y > bottomFirst && y < topFirst) {
m_audio.playSound(AUDIO_PATH "snap.wav", m_sfxvolume);
if (m_selectedPlayOptions) {
m_gamestate = GameState::PLAY;
m_audio.ToggleMusicState(m_gamestate);
m_gamestate = GameState::LOBBY;
m_selectedSinglePlayer = true;
m_selectedMultiPlayer = false;
m_settingUsername = true;
//m_gamestate = GameState::PLAY;
//m_audio.ToggleMusicState(m_gamestate);
}
else {
m_selectedPlayOptions = true;
@ -2229,6 +2247,8 @@ void Engine::MousePressEvent(const MOUSE_BUTTON& button, int x, int y) {
m_audio.playSound(AUDIO_PATH "snap.wav", m_sfxvolume);
if (m_selectedPlayOptions) {
m_gamestate = GameState::LOBBY;
m_selectedMultiPlayer = true;
m_selectedSinglePlayer = false;
m_settingUsername = true;
}
else {
@ -2386,6 +2406,10 @@ void Engine::MousePressEvent(const MOUSE_BUTTON& button, int x, int y) {
m_audio.playSound(AUDIO_PATH "snap.wav", m_sfxvolume);
m_gamestate = GameState::MAIN_MENU;
m_selectedPlayOptions = false;
m_selectedSinglePlayer = false;
m_selectedMultiPlayer = false;
m_singleReady = false;
m_multiReady = false;
m_audio.ToggleMusicState(m_gamestate);
}
}
@ -2396,6 +2420,7 @@ void Engine::MousePressEvent(const MOUSE_BUTTON& button, int x, int y) {
float bottomBack = centerY + Height() * 0.275f;
if (leftBack && x < rightBack && y > bottomBack && y < topBack) {
m_audio.playSound(AUDIO_PATH "snap.wav", m_sfxvolume);
m_gamestate = GameState::MAIN_MENU;
}
}

View File

@ -214,8 +214,12 @@ private:
bool m_charChanged = false;
bool m_settingUsername = false;
bool m_settingServer = false;
bool m_selectedSinglePlayer = false;
bool m_selectedMultiPlayer = false;
bool m_singleReady = false;
bool m_multiReady = false;
bool m_key1 = false;
bool m_key2 = false;
bool m_keyK = false;