SQC-15_online #1
| @@ -715,10 +715,6 @@ void Engine::DisplaySplashScreen() { | |||||||
| } | } | ||||||
|  |  | ||||||
| void Engine::DisplayLobbyMenu(float elapsedTime) { | void Engine::DisplayLobbyMenu(float elapsedTime) { | ||||||
| 	static float lobbyTime = 0.0f; |  | ||||||
| 	lobbyTime += elapsedTime; |  | ||||||
| 	float onInterval = 0.5f; |  | ||||||
| 	float offInterval = 1.0f; |  | ||||||
|  |  | ||||||
| 	GLint viewport[4]; | 	GLint viewport[4]; | ||||||
| 	glGetIntegerv(GL_VIEWPORT, viewport); | 	glGetIntegerv(GL_VIEWPORT, viewport); | ||||||
| @@ -745,49 +741,12 @@ void Engine::DisplayLobbyMenu(float elapsedTime) { | |||||||
|  |  | ||||||
| 	glColor4f(1.0f, 1.0f, 1.0f, 1.0f); | 	glColor4f(1.0f, 1.0f, 1.0f, 1.0f); | ||||||
|  |  | ||||||
| 	m_textureLobbyIdentify.Bind(); | 	if (m_settingUsername) { | ||||||
| 	glBegin(GL_QUADS); | 		SetPlayerUsername(elapsedTime); | ||||||
| 	glTexCoord2f(0, 0); glVertex2i(Width() * 0.6, Height() * 0.75); |  | ||||||
| 	glTexCoord2f(1, 0); glVertex2i(Width() * 0.975, Height() * 0.75); |  | ||||||
| 	glTexCoord2f(1, 1); glVertex2i(Width() * 0.975, Height() * 0.95); |  | ||||||
| 	glTexCoord2f(0, 1); glVertex2i(Width() * 0.6, Height() * 0.95); |  | ||||||
| 	glEnd(); |  | ||||||
|  |  | ||||||
| 	glBlendFunc(GL_SRC_ALPHA, GL_ONE); |  | ||||||
|  |  | ||||||
| 	m_textureFont.Bind(); |  | ||||||
| 	std::ostringstream ss; |  | ||||||
| 	glColor4f(1.0f, 1.0f, 1.0f, 1.0f); |  | ||||||
|  |  | ||||||
| 	if (m_charChanged) { |  | ||||||
| 		if (m_keyBackspace) { |  | ||||||
| 			if (!m_currentInputString.empty()) { |  | ||||||
| 				m_currentInputString.pop_back(); |  | ||||||
| 	} | 	} | ||||||
| 			m_keyBackspace = false; | 	else if (m_settingServer) { | ||||||
|  | 		SetServerAddress(elapsedTime); | ||||||
| 	} | 	} | ||||||
| 		else if (m_currentInputString.size() < 26) { |  | ||||||
| 			m_currentInputString += m_inputChar; |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	ss << m_currentInputString; |  | ||||||
| 	m_charChanged = false; |  | ||||||
|  |  | ||||||
| 	if (lobbyTime < onInterval) { |  | ||||||
| 		ss << "_"; |  | ||||||
| 	} |  | ||||||
| 	else if (lobbyTime > onInterval && lobbyTime < offInterval) { |  | ||||||
| 		ss << " "; |  | ||||||
| 	} |  | ||||||
| 	else { |  | ||||||
| 		lobbyTime -= offInterval; |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	PrintText(Width() * 0.6f, Height() * 0.4f, ss.str(), 2.0f); |  | ||||||
|  |  | ||||||
| 	glDisable(GL_BLEND); |  | ||||||
| 	glColor4f(1.0f, 1.0f, 1.0f, 1.0f); |  | ||||||
|  |  | ||||||
| 	glViewport(viewport[0], viewport[1], viewport[2], viewport[3]); | 	glViewport(viewport[0], viewport[1], viewport[2], viewport[3]); | ||||||
|  |  | ||||||
| @@ -798,11 +757,38 @@ void Engine::DisplayLobbyMenu(float elapsedTime) { | |||||||
|  |  | ||||||
| 	glMatrixMode(GL_MODELVIEW); | 	glMatrixMode(GL_MODELVIEW); | ||||||
| 	glPopMatrix(); | 	glPopMatrix(); | ||||||
|  |  | ||||||
| } | } | ||||||
|  |  | ||||||
| void Engine::SetLobbyUsername() { | void Engine::SetPlayerUsername(float elapsedTime) { | ||||||
|  | 	m_textureLobbyIdentify.Bind(); | ||||||
|  | 	glBegin(GL_QUADS); | ||||||
|  | 	glTexCoord2f(0, 0); glVertex2i(Width() * 0.6, Height() * 0.75); | ||||||
|  | 	glTexCoord2f(1, 0); glVertex2i(Width() * 0.975, Height() * 0.75); | ||||||
|  | 	glTexCoord2f(1, 1); glVertex2i(Width() * 0.975, Height() * 0.95); | ||||||
|  | 	glTexCoord2f(0, 1); glVertex2i(Width() * 0.6, Height() * 0.95); | ||||||
|  | 	glEnd(); | ||||||
|  |  | ||||||
|  | 	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) { | ||||||
|  | 	m_textureLobbyServer.Bind(); | ||||||
|  | 	glBegin(GL_QUADS); | ||||||
|  | 	glTexCoord2f(0, 0); glVertex2i(Width() * 0.6, Height() * 0.75); | ||||||
|  | 	glTexCoord2f(1, 0); glVertex2i(Width() * 0.975, Height() * 0.75); | ||||||
|  | 	glTexCoord2f(1, 1); glVertex2i(Width() * 0.975, Height() * 0.95); | ||||||
|  | 	glTexCoord2f(0, 1); glVertex2i(Width() * 0.6, Height() * 0.95); | ||||||
|  | 	glEnd(); | ||||||
|  |  | ||||||
|  | 	glBlendFunc(GL_SRC_ALPHA, GL_ONE); | ||||||
|  | 	HandlePlayerInput(elapsedTime); | ||||||
|  | 	glDisable(GL_BLEND); | ||||||
|  |  | ||||||
|  | 	glColor4f(1.0f, 1.0f, 1.0f, 1.0f); | ||||||
| } | } | ||||||
|  |  | ||||||
| void Engine::DisplayMainMenu() { | void Engine::DisplayMainMenu() { | ||||||
| @@ -1890,6 +1876,68 @@ char Engine::SimulateKeyboard(unsigned char key) { | |||||||
| 	return m_inputChar; | 	return m_inputChar; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | void Engine::HandlePlayerInput(float elapsedTime) { | ||||||
|  | 	static float lobbyTime = 0.0f; | ||||||
|  | 	lobbyTime += elapsedTime; | ||||||
|  | 	float onInterval = 0.5f; | ||||||
|  | 	float offInterval = 1.0f; | ||||||
|  |  | ||||||
|  | 	m_textureFont.Bind(); | ||||||
|  | 	std::ostringstream ss; | ||||||
|  |  | ||||||
|  | 	glColor4f(1.0f, 1.0f, 1.0f, 1.0f); | ||||||
|  |  | ||||||
|  | 	if (m_charChanged) { | ||||||
|  | 		if (m_keyBackspace) { | ||||||
|  | 			if (!m_currentInputString.empty()) { | ||||||
|  | 				m_currentInputString.pop_back(); | ||||||
|  | 			} | ||||||
|  | 			m_keyBackspace = false; | ||||||
|  | 		} | ||||||
|  | 		else if (m_keyEnter) { | ||||||
|  | 			if (m_settingUsername) { | ||||||
|  | 				if (!m_currentInputString.empty() && | ||||||
|  | 					m_currentInputString.size() > 1 && | ||||||
|  | 					m_currentInputString.size() < 26) { | ||||||
|  | 					m_username = m_currentInputString; | ||||||
|  | 					m_currentInputString = ""; | ||||||
|  | 					m_settingUsername = false; | ||||||
|  | 					m_settingServer = true; | ||||||
|  | 				} | ||||||
|  | 			} | ||||||
|  | 			else if (m_settingServer) { | ||||||
|  | 				if (!m_currentInputString.empty()) { | ||||||
|  | 					m_serverAddr = m_currentInputString; | ||||||
|  | 					m_currentInputString = ""; | ||||||
|  | 					m_settingServer = false; | ||||||
|  | 				} | ||||||
|  | 			} | ||||||
|  | 			m_keyEnter = false; | ||||||
|  | 		} | ||||||
|  | 		else if (m_settingUsername && m_currentInputString.size() < 26) { | ||||||
|  | 			m_currentInputString += m_inputChar; | ||||||
|  | 		} | ||||||
|  | 		else if (m_settingServer && m_currentInputString.size() < 15) { | ||||||
|  | 			m_currentInputString += m_inputChar; | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	ss << m_currentInputString; | ||||||
|  | 	m_charChanged = false; | ||||||
|  |  | ||||||
|  | 	if (lobbyTime < onInterval) { | ||||||
|  | 		ss << "_"; | ||||||
|  | 	} | ||||||
|  | 	else if (lobbyTime > onInterval && lobbyTime < offInterval) { | ||||||
|  | 		ss << " "; | ||||||
|  | 	} | ||||||
|  | 	else { | ||||||
|  | 		lobbyTime = 0.0f; | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	PrintText(Width() * 0.6f, Height() * 0.4f, ss.str(), 2.0f); | ||||||
|  | } | ||||||
|  |  | ||||||
|  |  | ||||||
| void Engine::MouseMoveEvent(int x, int y) { | void Engine::MouseMoveEvent(int x, int y) { | ||||||
| 	if (m_gamestate == GameState::PLAY) { | 	if (m_gamestate == GameState::PLAY) { | ||||||
| @@ -1979,7 +2027,7 @@ void Engine::MousePressEvent(const MOUSE_BUTTON& button, int x, int y) { | |||||||
| 		else if (x > leftButton && x < rightButton && y > bottomSecond && y < topSecond) { | 		else if (x > leftButton && x < rightButton && y > bottomSecond && y < topSecond) { | ||||||
| 			if (m_selectedPlayOptions) { | 			if (m_selectedPlayOptions) { | ||||||
| 				m_gamestate = GameState::LOBBY; | 				m_gamestate = GameState::LOBBY; | ||||||
| 				StartMultiplayerGame(); | 				m_settingUsername = true; | ||||||
| 			} | 			} | ||||||
| 			else { | 			else { | ||||||
| 				m_gamestate = GameState::OPTIONS; | 				m_gamestate = GameState::OPTIONS; | ||||||
|   | |||||||
| @@ -69,8 +69,8 @@ private: | |||||||
|     void DrawSingleMultiButtons(float centerX, float centerY); |     void DrawSingleMultiButtons(float centerX, float centerY); | ||||||
|  |  | ||||||
|     void DisplayLobbyMenu(float elapsedTime); |     void DisplayLobbyMenu(float elapsedTime); | ||||||
|     void SetLobbyUsername(); |     void SetPlayerUsername(float elapsedTime); | ||||||
|     void SetLobbyServerAddress(); |     void SetServerAddress(float elapsedTime); | ||||||
|  |  | ||||||
|     void DisplayOptionsMenu(); |     void DisplayOptionsMenu(); | ||||||
|     void DisplayAudioMenu(float centerX, float centerY); |     void DisplayAudioMenu(float centerX, float centerY); | ||||||
| @@ -83,6 +83,7 @@ private: | |||||||
|     void PrintText(float x, float y, const std::string& t, float charSizeMultiplier = 1.0f); |     void PrintText(float x, float y, const std::string& t, float charSizeMultiplier = 1.0f); | ||||||
|     void ProcessNotificationQueue(); |     void ProcessNotificationQueue(); | ||||||
|     char SimulateKeyboard(unsigned char key); |     char SimulateKeyboard(unsigned char key); | ||||||
|  |     void HandlePlayerInput(float elapsedTime); | ||||||
|  |  | ||||||
|     Connector m_conn; |     Connector m_conn; | ||||||
|  |  | ||||||
| @@ -206,6 +207,8 @@ private: | |||||||
|     bool m_selectedQuit = false; |     bool m_selectedQuit = false; | ||||||
|  |  | ||||||
|     std::string m_currentInputString; |     std::string m_currentInputString; | ||||||
|  |     std::string m_username; | ||||||
|  |     std::string m_serverAddr; | ||||||
|     char m_inputChar = 0; |     char m_inputChar = 0; | ||||||
|     bool m_invalidChar = false; |     bool m_invalidChar = false; | ||||||
|     bool m_charChanged = false; |     bool m_charChanged = false; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user