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

@@ -98,7 +98,12 @@ bool WorldScene::handle_event(const Event& e) {
}
return false;
},
[](const TextInputEvent&) { return false; },
[this](const TextInputEvent& e) {
if (handle_text_input_event(e)) {
return true;
}
return false;
},
[this](const WindowResizeEvent& e) {
handle_window_resize_event(e);
return false;
@@ -257,6 +262,17 @@ bool WorldScene::handle_key_event(const KeyEvent& e) {
m_show_dev_pannel = !m_show_dev_pannel;
return true;
}
if (e.key == Key::T && e.action == KeyAction::PRESS) {
if (m_chatting) {
set_chatting(false);
} else {
set_chatting(true);
}
return true;
}
if (m_paused) {
if (m_pasue_menu.handle_event(e)) {
return true;
@@ -265,6 +281,9 @@ bool WorldScene::handle_key_event(const KeyEvent& e) {
if (m_hud_ui.handle_event(e)) {
return true;
}
if (m_chatting) {
return true;
}
if (m_camera.handle_event(e)) {
return true;
}
@@ -276,6 +295,14 @@ bool WorldScene::handle_key_event(const KeyEvent& e) {
return false;
}
bool WorldScene::handle_text_input_event(const TextInputEvent& e) {
if (m_paused) {
return m_pasue_menu.handle_text_input_event(e);
}
Logger::info("Hud ui handle text input");
return m_hud_ui.handle_text_input_event(e);
}
Camera& WorldScene::camera() { return m_camera; }
SceneManager& WorldScene::scene_manager() { return m_scene_manager; }
ClientWorld& WorldScene::client_world() { return m_client_world; }
@@ -286,13 +313,27 @@ void WorldScene::set_pause(bool pause) {
return;
}
m_paused = pause;
set_mouse(pause);
}
void WorldScene::set_mouse(bool enable) {
auto& window = m_scene_manager.app().window();
window.set_game_running(!m_paused);
if (m_paused) {
window.set_game_running(!enable);
if (enable) {
m_client_world.reset_key_status();
}
}
void WorldScene::set_chatting(bool chatting) {
if (m_paused) {
return;
}
m_chatting = chatting;
set_mouse(chatting);
m_hud_ui.set_chatting(chatting);
Logger::info("World Scene Chatting {}", chatting);
}
void WorldScene::set_error(std::string_view error) {
Logger::error("WorldScene Error Set {}", error);
m_error_ui.set_error(error);