[Text|TextInput] 'm_text' renamed to 'm_string'.

This commit is contained in:
Quentin Bazin 2020-06-20 01:24:06 +02:00
parent 00d1cb84d5
commit 1f7d83bebc
16 changed files with 41 additions and 41 deletions

View File

@ -52,7 +52,7 @@ void ItemWidget::update() {
else
updateImage();
m_text.setText(std::to_string(stack().amount()));
m_text.setString(std::to_string(stack().amount()));
m_text.setPosition(16 - 4 - 6 * floor(log10(stack().amount())), 16 - 6, 0);
}

View File

@ -176,12 +176,12 @@ void MouseItemWidget::updateCurrentItem(ItemWidget *currentItemWidget) {
draggingBehaviour(currentItemWidget);
m_currentItemWidget = (currentItemWidget->stack().item().id()) ? currentItemWidget : nullptr;
m_tooltipText.setText(currentItemWidget->stack().item().label() + " [" + std::to_string(currentItemWidget->stack().item().id()) + "]");
m_tooltipText.setString(currentItemWidget->stack().item().label() + " [" + std::to_string(currentItemWidget->stack().item().id()) + "]");
if (currentItemWidget->stack().item().hasGroup("group:om_fuel"))
m_tooltipInfoText.setText("Burn time: " + std::to_string(currentItemWidget->stack().item().getGroupValue("group:om_fuel")) + " ticks");
m_tooltipInfoText.setString("Burn time: " + std::to_string(currentItemWidget->stack().item().getGroupValue("group:om_fuel")) + " ticks");
else
m_tooltipInfoText.setText("");
m_tooltipInfoText.setString("");
}
else {
m_currentItemWidget = nullptr;

View File

@ -34,9 +34,9 @@ Text::Text() : m_font(gk::ResourceHandler::getInstance().get<Font>("font-ascii")
m_background.setFillColor(gk::Color::Transparent);
}
void Text::setText(const std::string &text) {
if (m_text != text) {
m_text = text;
void Text::setString(const std::string &string) {
if (m_string != string) {
m_string = string;
m_isUpdateNeeded = true;
}
}
@ -94,7 +94,7 @@ void Text::updateVertexBuffer() const {
u32 y = 0;
u32 maxX = 0;
gk::Color color = gk::Color{70, 70, 70, 255};
for(char c : m_text) {
for(char c : m_string) {
if (c == '\n' || (m_maxLineLength && x + m_font.getCharWidth(c) >= m_maxLineLength)) {
y += m_font.getTileSize().y + 1;
x = 0;
@ -109,7 +109,7 @@ void Text::updateVertexBuffer() const {
x = 0;
y = 0;
color = m_color;
for(char c : m_text) {
for(char c : m_string) {
if (c == '\n' || (m_maxLineLength && x + m_font.getCharWidth(c) >= m_maxLineLength)) {
maxX = std::max(x, maxX);
y += m_font.getTileSize().y + 1;

View File

@ -40,8 +40,8 @@ class Text : public gk::Drawable, public gk::Transformable {
public:
Text();
const std::string &text() const { return m_text; }
void setText(const std::string &text);
const std::string &string() const { return m_string; }
void setString(const std::string &string);
const gk::Color &color() const { return m_color; }
void setColor(const gk::Color &color);
@ -64,7 +64,7 @@ class Text : public gk::Drawable, public gk::Transformable {
void addCharacter(u32 x, u32 y, const gk::Color &color, u8 c, std::vector<Vertex> &vertices) const;
std::string m_text;
std::string m_string;
Font &m_font;

View File

@ -54,7 +54,7 @@ void TextButton::onEvent(const sf::Event &event) {
}
void TextButton::setText(const std::string &text) {
m_text.setText(text);
m_text.setString(text);
m_text.updateVertexBuffer();
m_text.setPosition(m_width / 2 - m_text.getSize().x / 2,
m_height / 2 - m_text.getSize().y / 2, 0);

View File

@ -46,7 +46,7 @@ class TextButton : public Widget {
void onEvent(const sf::Event &event) override;
const std::string &text() const { return m_text.text(); }
const std::string &text() const { return m_text.string(); }
void setText(const std::string &text);
void setCallback(const CppCallback &callback) { m_cppCallback = callback; }

View File

@ -29,14 +29,14 @@
#include "TextInput.hpp"
TextInput::TextInput() {
m_text.setText(std::string{m_cursor});
m_text.setString(std::string{m_cursor});
}
void TextInput::onEvent(const sf::Event &event) {
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);
m_text.setText(m_content + m_cursor);
m_text.setString(m_content + m_cursor);
}
if (event.type == sf::Event::TextEntered) {
@ -45,7 +45,7 @@ void TextInput::onEvent(const sf::Event &event) {
m_content += c;
}
m_text.setText(m_content + m_cursor);
m_text.setString(m_content + m_cursor);
}
}

View File

@ -37,8 +37,8 @@ class TextInput : public gk::Drawable, public gk::Transformable {
void onEvent(const sf::Event &event);
const std::string &text() const { return m_content; }
void setText(const std::string &text) { m_content = text; m_text.setText(m_content + m_cursor); }
const std::string &string() const { return m_content; }
void setString(const std::string &string) { m_content = string; m_text.setString(m_content + m_cursor); }
gk::Vector2f getBackgroundSize() const { return m_text.getBackgroundSize(); }

View File

@ -48,7 +48,7 @@ void BlockInfoWidget::setCurrentBlock(const Block *block) {
else {
m_isVisible = true;
m_text.setText(block->label());
m_text.setString(block->label());
m_itemWidget.setStack(block->stringID(), 1);
}
}

View File

@ -28,9 +28,9 @@
ChatMessage::ChatMessage(u16 clientID, const std::string &message, u32 posY) {
if (clientID > 0)
m_text.setText("<Client " + std::to_string(clientID) + "> " + message);
m_text.setString("<Client " + std::to_string(clientID) + "> " + message);
else
m_text.setText(message);
m_text.setString(message);
m_text.setPosition(0, posY);
m_text.setBackgroundColor(gk::Color{0, 0, 0, 127});

View File

@ -37,7 +37,7 @@ DebugOverlay::DebugOverlay(const ClientPlayer &player, const ClientWorld &world)
{
setPosition(4, 4, 0);
m_versionText.setText(APP_NAME + std::string(" v0.0.1"));
m_versionText.setString(APP_NAME + std::string(" v0.0.1"));
m_versionText.setColor(gk::Color::White);
m_positionText.setPosition(0, 10, 0);
@ -74,7 +74,7 @@ void DebugOverlay::update() {
stream << '\n';
stream << "Alive entities: " << m_world.scene().registry().alive();
m_positionText.setText(stream.str());
m_positionText.setString(stream.str());
}
void DebugOverlay::draw(gk::RenderTarget &target, gk::RenderStates states) const {

View File

@ -86,7 +86,7 @@ void HUD::update() {
m_hotbar.update();
if (Config::isFpsCounterEnabled)
m_fpsText.setText(std::to_string(gk::GameClock::getInstance().getFpsAverage()) + " FPS");
m_fpsText.setString(std::to_string(gk::GameClock::getInstance().getFpsAverage()) + " FPS");
m_blockCursor.update(m_hotbar);

View File

@ -48,7 +48,7 @@ ChatState::ChatState(ClientCommandHandler &clientCommandHandler, Chat &chat, boo
updateTextInputGeometry();
if (addSlash)
m_textInput.setText("/");
m_textInput.setString("/");
m_chat.setMessageVisibility(true);
}
@ -79,9 +79,9 @@ void ChatState::onEvent(const sf::Event &event) {
}
if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Return) {
if (!m_textInput.text().empty()) {
m_clientCommandHandler.sendChatMessage(m_textInput.text());
m_chat.addHistoryEntry(m_textInput.text());
if (!m_textInput.string().empty()) {
m_clientCommandHandler.sendChatMessage(m_textInput.string());
m_chat.addHistoryEntry(m_textInput.string());
}
gk::Mouse::setCursorGrabbed(true);
@ -97,15 +97,15 @@ void ChatState::onEvent(const sf::Event &event) {
if (event.type == sf::Event::KeyPressed) {
if (event.key.code == sf::Keyboard::Up && m_currentHistoryEntry < (int)m_chat.historySize() - 1) {
if (m_currentHistoryEntry == -1)
m_oldEntry = m_textInput.text();
m_textInput.setText(m_chat.getHistoryEntry(++m_currentHistoryEntry));
m_oldEntry = m_textInput.string();
m_textInput.setString(m_chat.getHistoryEntry(++m_currentHistoryEntry));
}
else if (event.key.code == sf::Keyboard::Down && m_currentHistoryEntry >= 0) {
--m_currentHistoryEntry;
if (m_currentHistoryEntry == -1)
m_textInput.setText(m_oldEntry);
m_textInput.setString(m_oldEntry);
else
m_textInput.setText(m_chat.getHistoryEntry(m_currentHistoryEntry));
m_textInput.setString(m_chat.getHistoryEntry(m_currentHistoryEntry));
}
}
}

View File

@ -42,7 +42,7 @@ ConnectionErrorState::ConnectionErrorState(const std::string &error, const std::
m_texturePack = texturePack;
m_text.setText(error);
m_text.setString(error);
m_text.setColor(gk::Color::Red);
m_text.updateVertexBuffer();
m_text.setScale(Config::guiScale * 1.5, Config::guiScale * 1.5);

View File

@ -31,7 +31,7 @@
#include "ServerLoadingState.hpp"
ServerConnectState::ServerConnectState(gk::ApplicationState *parent) : InterfaceState(parent) {
m_textInput.setText("localhost:4242");
m_textInput.setString("localhost:4242");
m_textInput.setCharacterLimit(15 + 1 + 6);
m_textInput.setBackgroundSize(150, 20);
m_textInput.setBackgroundOutline(1, gk::Color::White);
@ -44,14 +44,14 @@ ServerConnectState::ServerConnectState(gk::ApplicationState *parent) : Interface
m_connectButton.setPosition(Config::screenWidth / 2.0f - m_connectButton.getGlobalBounds().sizeX * Config::guiScale / 2.0f, Config::screenHeight - 340);
m_connectButton.setScale(Config::guiScale, Config::guiScale);
m_connectButton.setCallback([this](TextButton &) {
size_t sep = m_textInput.text().find_first_of(':');
std::string host = m_textInput.text().substr(0, sep);
size_t sep = m_textInput.string().find_first_of(':');
std::string host = m_textInput.string().substr(0, sep);
bool isPortInvalid = false;
int port = 0;
if (sep != std::string::npos) {
try {
port = std::stoi(m_textInput.text().substr(sep + 1));
port = std::stoi(m_textInput.string().substr(sep + 1));
}
catch (const std::invalid_argument &e) {
isPortInvalid = true;
@ -59,7 +59,7 @@ ServerConnectState::ServerConnectState(gk::ApplicationState *parent) : Interface
}
if (port == 0 || isPortInvalid) {
m_errorText.setText("Error: Invalid server address");
m_errorText.setString("Error: Invalid server address");
m_errorText.updateVertexBuffer();
m_errorText.setPosition(
Config::screenWidth / 2.0f - m_errorText.getSize().x * Config::guiScale / 2.0f,
@ -123,7 +123,7 @@ void ServerConnectState::draw(gk::RenderTarget &target, gk::RenderStates states)
target.draw(m_connectButton, states);
target.draw(m_cancelButton, states);
if (!m_errorText.text().empty())
if (!m_errorText.string().empty())
target.draw(m_errorText, states);
}
}

View File

@ -41,7 +41,7 @@
ServerLoadingState::ServerLoadingState(GameState &game, bool showLoadingState, const std::string &host, u16 port, gk::ApplicationState *parent)
: InterfaceState(parent), m_game(game), m_showLoadingState(showLoadingState)
{
m_text.setText("Loading world...");
m_text.setString("Loading world...");
m_text.setColor(gk::Color::White);
m_text.updateVertexBuffer();
m_text.setScale(Config::guiScale * 2, Config::guiScale * 2);