feat(chat): implement in-game chat box with UTF-8 support

- Add ChatMessage struct and ChatBox widget for displaying and sending messages
- Introduce split_utf8() in text_tools for splitting UTF-8 strings by character count
- Add TimeTools utility (get_time_ticks) for message timestamps
- Update TextField with start_typing/stop_typing methods and set_typing()
- Integrate text input handling in WorldScene and WorldUIManager for chat
- Add utf8cpp library for robust UTF-8 validation and processing
- Add ChatBox rendering and input logic (src/ui/chat_box.cpp)
- Register ChatBox source in CMakeLists.txt
- Fix Renderer::render_lable to skip rendering if VAO is null
- Update credits to include utf8cpp library
This commit is contained in:
2026-07-18 17:34:38 +08:00
parent 41c145ab30
commit 7f2597ebe0
24 changed files with 1952 additions and 27 deletions

View File

@@ -149,6 +149,34 @@ TextField& TextField::set_app(App* app) {
m_app = app;
return *this;
}
TextField& TextField::set_typing(bool typing) {
Logger::info("Typing {}", typing);
m_typing = typing;
if (m_typing) {
start_typing();
} else {
stop_typing();
}
return *this;
}
void TextField::start_typing() {
if (m_app) {
m_app->start_text_input();
}
update_show_text();
}
void TextField::stop_typing() {
if (m_app) {
m_app->stop_text_input();
}
if (m_on_finished) {
m_on_finished();
}
}
const std::string& TextField::input_text() const { return m_input_text; }
bool TextField::handle_mouse_move_event(const MouseMoveEvent& e) {
@@ -166,20 +194,12 @@ bool TextField::handle_mouse_button_event(const MouseButtonEvent& e) {
if (e.key == MouseKey::LEFT_BUTTON && e.action == KeyAction::PRESS) {
if (m_inside) {
m_typing = true;
if (m_app) {
m_app->start_text_input();
}
update_show_text();
start_typing();
return false;
} else {
if (m_typing) {
m_typing = false;
if (m_app) {
m_app->stop_text_input();
}
if (m_on_finished) {
m_on_finished();
}
stop_typing();
return false;
}
@@ -188,6 +208,7 @@ bool TextField::handle_mouse_button_event(const MouseButtonEvent& e) {
return false;
}
bool TextField::handle_text_input_event(const TextInputEvent& e) {
Logger::info("Recive Text Input Event");
if (m_typing) {
m_input_text.append(e.text);
update_show_text();