feat(chat): implement client-server chat messaging

Add protobuf definition for ChatMsg, new packet ID CHAT_MSG (4001), and
handle sending/receiving chat messages on both client and server side.
Wire up UI components (ChatBox, TextField) to allow message input and
display, including a message queue in ClientWorld for thread-safe
processing. Also add default initialization for ChatMessage::time.
This commit is contained in:
2026-07-18 20:29:14 +08:00
parent f4103e254e
commit 75f71a537f
19 changed files with 126 additions and 17 deletions

View File

@@ -79,18 +79,15 @@ void TextField::on_update(float dt) {
}
void TextField::update_show_text() {
if (m_input_text.empty()) {
if (!m_typing) {
m_foreground->set_text(m_show_text);
m_foreground->set_color(Color::GRAY);
} else {
m_foreground->set_text(" ");
}
if (!m_typing) {
m_foreground->set_text(m_show_text);
m_foreground->set_color(Color::GRAY);
} else {
m_foreground->set_text(m_input_text);
m_foreground->set_color(Color::WHITE);
}
update_text_scale();
update_input_area();
m_cursor->set_offset({13.0f + m_foreground->width(), 0.0f});
@@ -162,6 +159,12 @@ TextField& TextField::set_typing(bool typing) {
return *this;
}
TextField& TextField::clear_input() {
m_input_text.clear();
update_show_text();
return *this;
}
void TextField::start_typing() {
if (m_app) {
m_app->start_text_input();
@@ -178,7 +181,7 @@ void TextField::stop_typing() {
}
const std::string& TextField::input_text() const { return m_input_text; }
std::string& TextField::input_text() { return m_input_text; }
bool TextField::handle_mouse_move_event(const MouseMoveEvent& e) {
auto p = pos();
if (e.xpos >= p.x && e.xpos <= p.x + width() && e.ypos >= p.y &&