working main menu
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
#include <Nazara/Network/Enums.hpp>
|
||||
#include <Nazara/Network/IpAddress.hpp>
|
||||
#include <client/states/ConnectingState.h>
|
||||
#include <client/states/JoinServerState.h>
|
||||
|
||||
#include <Nazara/Core/StateMachine.hpp>
|
||||
@@ -12,6 +15,13 @@ JoinServerState::JoinServerState(std::shared_ptr<StateData> a_StateData, std::sh
|
||||
textDrawer.SetTextColor({0.0, 0.0, 0.0, 1.0});
|
||||
textDrawer.SetCharacterSize(75);
|
||||
|
||||
m_InputAddress = CreateWidget<Nz::TextAreaWidget>();
|
||||
m_InputAddress->SetBackgroundColor(Nz::Color::White());
|
||||
m_InputAddress->EnableBackground(true);
|
||||
m_InputAddress->EnableMultiline(false);
|
||||
m_InputAddress->SetTextColor(Nz::Color::Black());
|
||||
m_InputAddress->SetText("localhost");
|
||||
|
||||
m_JoinServerButton = CreateWidget<Nz::ButtonWidget>();
|
||||
textDrawer.SetText("Join Server");
|
||||
m_JoinServerButton->UpdateText(textDrawer);
|
||||
@@ -40,7 +50,7 @@ void JoinServerState::LayoutWidgets() {
|
||||
|
||||
constexpr float padding = 10.f;
|
||||
|
||||
std::array<Nz::BaseWidget*, 2> widgets = {m_JoinServerButton, m_BackButton};
|
||||
std::array<Nz::BaseWidget*, 3> widgets = {m_InputAddress, m_JoinServerButton, m_BackButton};
|
||||
|
||||
float maxWidth = 0.f;
|
||||
float totalSize = padding * (widgets.size() - 1);
|
||||
@@ -62,7 +72,21 @@ void JoinServerState::LayoutWidgets() {
|
||||
}
|
||||
}
|
||||
|
||||
void JoinServerState::OnJoinServerPressed() {}
|
||||
void JoinServerState::OnJoinServerPressed() {
|
||||
std::string address = m_InputAddress->GetText();
|
||||
auto separator = address.find(':');
|
||||
std::string name = address.substr(0, separator);
|
||||
std::uint16_t port = 25565;
|
||||
if (separator != std::string::npos) {
|
||||
try {
|
||||
std::string rawPort = address.substr(separator + 1, std::string::npos);
|
||||
port = std::stoi(rawPort);
|
||||
} catch (std::exception& e) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
m_NextState = std::make_shared<ConnectingState>(GetStateDataPtr(), shared_from_this(), name, port, false);
|
||||
}
|
||||
|
||||
void JoinServerState::OnBackPressed() {
|
||||
m_NextState = std::move(m_PreviousState);
|
||||
|
||||
Reference in New Issue
Block a user