[WorldCreationState] Added placeholder for text input.
This commit is contained in:
parent
377ff452e2
commit
d71bc9e947
@ -35,7 +35,17 @@ TextInput::TextInput() {
|
||||
}
|
||||
|
||||
void TextInput::onEvent(const sf::Event &event) {
|
||||
if (m_hasFocus) {
|
||||
if (event.type == sf::Event::MouseButtonPressed) {
|
||||
gk::FloatRect rect{
|
||||
getPosition().x,
|
||||
getPosition().y,
|
||||
getBackgroundSize().x * getScale().x,
|
||||
getBackgroundSize().y * getScale().y
|
||||
};
|
||||
|
||||
m_hasFocus = rect.contains(event.mouseButton.x, event.mouseButton.y);
|
||||
}
|
||||
else if (m_hasFocus) {
|
||||
if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Backspace && !m_content.empty()) {
|
||||
m_content.erase(m_content.begin() + m_content.length() - 1);
|
||||
|
||||
|
@ -110,31 +110,6 @@ void ServerConnectState::onEvent(const sf::Event &event) {
|
||||
m_connectButton.onEvent(event);
|
||||
m_cancelButton.onEvent(event);
|
||||
}
|
||||
|
||||
if (event.type == sf::Event::MouseButtonPressed) {
|
||||
gk::FloatRect usernameInputRect{
|
||||
m_usernameInput.getPosition().x,
|
||||
m_usernameInput.getPosition().y,
|
||||
m_usernameInput.getBackgroundSize().x * m_usernameInput.getScale().x,
|
||||
m_usernameInput.getBackgroundSize().y * m_usernameInput.getScale().y
|
||||
};
|
||||
|
||||
gk::FloatRect addressInputRect{
|
||||
m_addressInput.getPosition().x,
|
||||
m_addressInput.getPosition().y,
|
||||
m_addressInput.getBackgroundSize().x * m_addressInput.getScale().x,
|
||||
m_addressInput.getBackgroundSize().y * m_addressInput.getScale().y
|
||||
};
|
||||
|
||||
if (usernameInputRect.contains(event.mouseButton.x, event.mouseButton.y)) {
|
||||
m_usernameInput.setFocus(true);
|
||||
m_addressInput.setFocus(false);
|
||||
}
|
||||
else if (addressInputRect.contains(event.mouseButton.x, event.mouseButton.y)) {
|
||||
m_usernameInput.setFocus(false);
|
||||
m_addressInput.setFocus(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ServerConnectState::update() {
|
||||
|
@ -43,6 +43,8 @@ WorldCreationState::WorldCreationState(TitleScreenState *titleScreen, const std:
|
||||
m_textInput.setBackgroundOutline(1, gk::Color::White);
|
||||
m_textInput.setPadding(5, 6);
|
||||
m_textInput.setScale(Config::guiScale, Config::guiScale);
|
||||
m_textInput.setFocus(false);
|
||||
m_textInput.setPlaceholder("World Name");
|
||||
|
||||
m_createButton.setText(originalName.empty() ? "Create" : "Rename");
|
||||
m_createButton.setScale(Config::guiScale, Config::guiScale);
|
||||
|
Loading…
x
Reference in New Issue
Block a user