Added ability to change username, handle & avatar in lobby
This commit is contained in:
@@ -103,3 +103,7 @@ void BaseScene::KeyDown(SDL_KeyboardEvent const& event) {
|
|||||||
void BaseScene::KeyUp(SDL_KeyboardEvent const& event) {
|
void BaseScene::KeyUp(SDL_KeyboardEvent const& event) {
|
||||||
//EMPTY
|
//EMPTY
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BaseScene::TextInput(SDL_TextInputEvent const& event) {
|
||||||
|
//EMPTY
|
||||||
|
}
|
||||||
|
|||||||
@@ -47,8 +47,9 @@ public:
|
|||||||
virtual void MouseWheel(SDL_MouseWheelEvent const& event);
|
virtual void MouseWheel(SDL_MouseWheelEvent const& event);
|
||||||
virtual void KeyDown(SDL_KeyboardEvent const& event);
|
virtual void KeyDown(SDL_KeyboardEvent const& event);
|
||||||
virtual void KeyUp(SDL_KeyboardEvent const& event);
|
virtual void KeyUp(SDL_KeyboardEvent const& event);
|
||||||
|
virtual void TextInput(SDL_TextInputEvent const& event);
|
||||||
|
|
||||||
//TODO: (9) joystick and controller events
|
//TODO: joystick and controller events
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
//control
|
//control
|
||||||
|
|||||||
@@ -188,6 +188,12 @@ void ClientApplication::Init(int argc, char* argv[]) {
|
|||||||
DEBUG_INTERNAL_VAR(MAX_PACKET_SIZE);
|
DEBUG_INTERNAL_VAR(MAX_PACKET_SIZE);
|
||||||
DEBUG_INTERNAL_VAR(static_cast<int>(SerialPacketType::LAST));
|
DEBUG_INTERNAL_VAR(static_cast<int>(SerialPacketType::LAST));
|
||||||
|
|
||||||
|
//-------------------------
|
||||||
|
//BUGFIX
|
||||||
|
//-------------------------
|
||||||
|
|
||||||
|
SDL_StopTextInput();
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
//finalize the startup
|
//finalize the startup
|
||||||
//-------------------------
|
//-------------------------
|
||||||
@@ -298,6 +304,10 @@ void ClientApplication::ProcessEvents() {
|
|||||||
activeScene->KeyUp(event.key);
|
activeScene->KeyUp(event.key);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case SDL_TEXTINPUT:
|
||||||
|
activeScene->TextInput(event.text);
|
||||||
|
break;
|
||||||
|
|
||||||
//TODO: (9) joystick and controller events
|
//TODO: (9) joystick and controller events
|
||||||
|
|
||||||
//window events are handled internally
|
//window events are handled internally
|
||||||
|
|||||||
@@ -68,6 +68,26 @@ LobbyMenu::LobbyMenu(int* const argClientIndex, int* const argAccountIndex):
|
|||||||
backButton.SetX(50);
|
backButton.SetX(50);
|
||||||
backButton.SetY(90);
|
backButton.SetY(90);
|
||||||
|
|
||||||
|
//setup the text fields
|
||||||
|
username.SetText(GetRenderer(), font, WHITE, config["client.username"]);
|
||||||
|
password.SetText(GetRenderer(), font, WHITE, config["client.password"]);
|
||||||
|
handle.SetText(GetRenderer(), font, WHITE, config["client.handle"]);
|
||||||
|
avatar.SetText(GetRenderer(), font, WHITE, config["client.avatar"]);
|
||||||
|
|
||||||
|
username.SetBounds(BoundingBox{0, 0, 300, 20});
|
||||||
|
password.SetBounds(BoundingBox{0, 0, 300, 20});
|
||||||
|
handle.SetBounds(BoundingBox{0, 0, 300, 20});
|
||||||
|
avatar.SetBounds(BoundingBox{0, 0, 300, 20});
|
||||||
|
|
||||||
|
username.SetX(50);
|
||||||
|
username.SetY(110);
|
||||||
|
password.SetX(50);
|
||||||
|
password.SetY(130);
|
||||||
|
handle.SetX(50);
|
||||||
|
handle.SetY(150);
|
||||||
|
avatar.SetX(50);
|
||||||
|
avatar.SetY(170);
|
||||||
|
|
||||||
//pseudo-list selection
|
//pseudo-list selection
|
||||||
//TODO: move this into the UI library?
|
//TODO: move this into the UI library?
|
||||||
boundingBox = {300, 50, 200, 12};
|
boundingBox = {300, 50, 200, 12};
|
||||||
@@ -115,6 +135,11 @@ void LobbyMenu::RenderFrame(SDL_Renderer* renderer) {
|
|||||||
joinButton.DrawTo(renderer);
|
joinButton.DrawTo(renderer);
|
||||||
backButton.DrawTo(renderer);
|
backButton.DrawTo(renderer);
|
||||||
|
|
||||||
|
username.DrawTo(renderer);
|
||||||
|
password.DrawTo(renderer);
|
||||||
|
handle.DrawTo(renderer);
|
||||||
|
avatar.DrawTo(renderer);
|
||||||
|
|
||||||
//TODO: (3) draw headers for the server list
|
//TODO: (3) draw headers for the server list
|
||||||
//TODO: (3) ping/delay displayed in the server list
|
//TODO: (3) ping/delay displayed in the server list
|
||||||
for (int i = 0; i < serverVector.size(); i++) {
|
for (int i = 0; i < serverVector.size(); i++) {
|
||||||
@@ -148,6 +173,19 @@ void LobbyMenu::MouseButtonDown(SDL_MouseButtonEvent const& event) {
|
|||||||
searchButton.MouseButtonDown(event);
|
searchButton.MouseButtonDown(event);
|
||||||
joinButton.MouseButtonDown(event);
|
joinButton.MouseButtonDown(event);
|
||||||
backButton.MouseButtonDown(event);
|
backButton.MouseButtonDown(event);
|
||||||
|
|
||||||
|
if (username.MouseButtonDown(event)) {
|
||||||
|
SDL_StartTextInput();
|
||||||
|
}
|
||||||
|
if (password.MouseButtonDown(event)) {
|
||||||
|
SDL_StartTextInput();
|
||||||
|
}
|
||||||
|
if (handle.MouseButtonDown(event)) {
|
||||||
|
SDL_StartTextInput();
|
||||||
|
}
|
||||||
|
if (avatar.MouseButtonDown(event)) {
|
||||||
|
SDL_StartTextInput();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LobbyMenu::MouseButtonUp(SDL_MouseButtonEvent const& event) {
|
void LobbyMenu::MouseButtonUp(SDL_MouseButtonEvent const& event) {
|
||||||
@@ -182,6 +220,22 @@ void LobbyMenu::KeyDown(SDL_KeyboardEvent const& event) {
|
|||||||
case SDLK_ESCAPE:
|
case SDLK_ESCAPE:
|
||||||
SetSceneSignal(SceneSignal::MAINMENU);
|
SetSceneSignal(SceneSignal::MAINMENU);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case SDLK_BACKSPACE:
|
||||||
|
//easier than mucking about with SDL_TextEditEvent
|
||||||
|
if (username.GetFocus()) {
|
||||||
|
username.PopChars(GetRenderer(), font, WHITE, 1);
|
||||||
|
}
|
||||||
|
if (password.GetFocus()) {
|
||||||
|
password.PopChars(GetRenderer(), font, WHITE, 1);
|
||||||
|
}
|
||||||
|
if (handle.GetFocus()) {
|
||||||
|
handle.PopChars(GetRenderer(), font, WHITE, 1);
|
||||||
|
}
|
||||||
|
if (avatar.GetFocus()) {
|
||||||
|
avatar.PopChars(GetRenderer(), font, WHITE, 1);
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -189,6 +243,21 @@ void LobbyMenu::KeyUp(SDL_KeyboardEvent const& event) {
|
|||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LobbyMenu::TextInput(SDL_TextInputEvent const& event) {
|
||||||
|
if (username.GetFocus()) {
|
||||||
|
username.PushText(GetRenderer(), font, WHITE, std::string(event.text));
|
||||||
|
}
|
||||||
|
if (password.GetFocus()) {
|
||||||
|
password.PushText(GetRenderer(), font, WHITE, std::string(event.text));
|
||||||
|
}
|
||||||
|
if (handle.GetFocus()) {
|
||||||
|
handle.PushText(GetRenderer(), font, WHITE, std::string(event.text));
|
||||||
|
}
|
||||||
|
if (avatar.GetFocus()) {
|
||||||
|
avatar.PushText(GetRenderer(), font, WHITE, std::string(event.text));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
//Network handlers
|
//Network handlers
|
||||||
//-------------------------
|
//-------------------------
|
||||||
@@ -303,6 +372,7 @@ void LobbyMenu::SendBroadcastRequest() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void LobbyMenu::SendJoinRequest() {
|
void LobbyMenu::SendJoinRequest() {
|
||||||
|
//BUG: 101 received in LobbyMenu on failed join
|
||||||
//pack the packet
|
//pack the packet
|
||||||
ClientPacket packet;
|
ClientPacket packet;
|
||||||
packet.type = SerialPacketType::JOIN_REQUEST;
|
packet.type = SerialPacketType::JOIN_REQUEST;
|
||||||
@@ -318,7 +388,13 @@ void LobbyMenu::SendLoginRequest() {
|
|||||||
ClientPacket packet;
|
ClientPacket packet;
|
||||||
packet.type = SerialPacketType::LOGIN_REQUEST;
|
packet.type = SerialPacketType::LOGIN_REQUEST;
|
||||||
packet.clientIndex = clientIndex;
|
packet.clientIndex = clientIndex;
|
||||||
strncpy(packet.username, config["client.username"].c_str(), PACKET_STRING_SIZE+1);
|
strncpy(packet.username, username.GetText().c_str(), PACKET_STRING_SIZE+1);
|
||||||
|
|
||||||
network.SendTo(Channels::SERVER, &packet);
|
network.SendTo(Channels::SERVER, &packet);
|
||||||
|
|
||||||
|
//TODO: remove
|
||||||
|
config["client.username"] = username.GetText();
|
||||||
|
config["client.password"] = password.GetText();
|
||||||
|
config["client.handle"] = handle.GetText();
|
||||||
|
config["client.avatar"] = avatar.GetText();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
#include "image.hpp"
|
#include "image.hpp"
|
||||||
#include "button.hpp"
|
#include "button.hpp"
|
||||||
#include "bounding_box.hpp"
|
#include "bounding_box.hpp"
|
||||||
|
#include "text_field.hpp"
|
||||||
#include "text_line.hpp"
|
#include "text_line.hpp"
|
||||||
|
|
||||||
#include "SDL2/SDL_ttf.h"
|
#include "SDL2/SDL_ttf.h"
|
||||||
@@ -61,6 +62,7 @@ protected:
|
|||||||
void MouseWheel(SDL_MouseWheelEvent const& event) override;
|
void MouseWheel(SDL_MouseWheelEvent const& event) override;
|
||||||
void KeyDown(SDL_KeyboardEvent const& event) override;
|
void KeyDown(SDL_KeyboardEvent const& event) override;
|
||||||
void KeyUp(SDL_KeyboardEvent const& event) override;
|
void KeyUp(SDL_KeyboardEvent const& event) override;
|
||||||
|
void TextInput(SDL_TextInputEvent const& event) override;
|
||||||
|
|
||||||
//Network handlers
|
//Network handlers
|
||||||
void HandlePacket(SerialPacket* const);
|
void HandlePacket(SerialPacket* const);
|
||||||
@@ -102,6 +104,10 @@ protected:
|
|||||||
Button searchButton;
|
Button searchButton;
|
||||||
Button joinButton;
|
Button joinButton;
|
||||||
Button backButton;
|
Button backButton;
|
||||||
|
TextField username;
|
||||||
|
TextField password;
|
||||||
|
TextField handle;
|
||||||
|
TextField avatar;
|
||||||
|
|
||||||
std::vector<ServerInfo> serverVector;
|
std::vector<ServerInfo> serverVector;
|
||||||
ServerInfo* selection = nullptr;
|
ServerInfo* selection = nullptr;
|
||||||
|
|||||||
Reference in New Issue
Block a user