Added ability to change username, handle & avatar in lobby
This commit is contained in:
@@ -68,6 +68,26 @@ LobbyMenu::LobbyMenu(int* const argClientIndex, int* const argAccountIndex):
|
||||
backButton.SetX(50);
|
||||
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
|
||||
//TODO: move this into the UI library?
|
||||
boundingBox = {300, 50, 200, 12};
|
||||
@@ -115,6 +135,11 @@ void LobbyMenu::RenderFrame(SDL_Renderer* renderer) {
|
||||
joinButton.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) ping/delay displayed in the server list
|
||||
for (int i = 0; i < serverVector.size(); i++) {
|
||||
@@ -148,6 +173,19 @@ void LobbyMenu::MouseButtonDown(SDL_MouseButtonEvent const& event) {
|
||||
searchButton.MouseButtonDown(event);
|
||||
joinButton.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) {
|
||||
@@ -182,6 +220,22 @@ void LobbyMenu::KeyDown(SDL_KeyboardEvent const& event) {
|
||||
case SDLK_ESCAPE:
|
||||
SetSceneSignal(SceneSignal::MAINMENU);
|
||||
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
|
||||
//-------------------------
|
||||
@@ -303,13 +372,14 @@ void LobbyMenu::SendBroadcastRequest() {
|
||||
}
|
||||
|
||||
void LobbyMenu::SendJoinRequest() {
|
||||
//BUG: 101 received in LobbyMenu on failed join
|
||||
//pack the packet
|
||||
ClientPacket packet;
|
||||
packet.type = SerialPacketType::JOIN_REQUEST;
|
||||
ClientPacket packet;
|
||||
packet.type = SerialPacketType::JOIN_REQUEST;
|
||||
|
||||
//join the selected server
|
||||
network.SendTo(selection->address, &packet);
|
||||
selection = nullptr;
|
||||
//join the selected server
|
||||
network.SendTo(selection->address, &packet);
|
||||
selection = nullptr;
|
||||
}
|
||||
|
||||
void LobbyMenu::SendLoginRequest() {
|
||||
@@ -318,7 +388,13 @@ void LobbyMenu::SendLoginRequest() {
|
||||
ClientPacket packet;
|
||||
packet.type = SerialPacketType::LOGIN_REQUEST;
|
||||
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);
|
||||
|
||||
//TODO: remove
|
||||
config["client.username"] = username.GetText();
|
||||
config["client.password"] = password.GetText();
|
||||
config["client.handle"] = handle.GetText();
|
||||
config["client.avatar"] = avatar.GetText();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user