feat(ui): add microphone icon when recording voice

This commit is contained in:
2026-07-20 18:35:37 +08:00
parent b64d887e78
commit 527178e067
10 changed files with 34 additions and 11 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 137 B

View File

@@ -51,6 +51,7 @@ public:
void receive_voice(std::span<const char> opus, const glm::vec3& pos);
AudioRecording& audio_recording();
const AudioRecording& audio_recording() const;
private:
using FadeMap = std::unordered_map<std::string, AudioFade>;

View File

@@ -100,6 +100,7 @@ public:
int chunk_size() const;
static AABB get_block_aabb(const glm::ivec3& pos);
AudioEngine& get_audio();
const AudioEngine& get_audio() const;
Config& get_config();
WorldScene& world_scene();
void set_direct_exit();

View File

@@ -39,6 +39,8 @@ public:
// Not thread safe
void handle_chat_message(ChatMessage& message);
bool is_recording() const;
private:
SceneManager& m_scene_manager;
DevPanel m_dev_panel;

View File

@@ -1,6 +1,7 @@
#pragma once
#include "Cubed/ui/chat_box.hpp"
#include "Cubed/ui/image.hpp"
#include "Cubed/ui/ui_manager.hpp"
#include "Cubed/ui/widget.hpp"
@@ -18,7 +19,7 @@ public:
void init() override;
void render(Renderer& renderer) override;
void update(float dt) override;
void set_chatting(bool chantting, bool sned);
void add_chat_message(ChatMessage& message);
@@ -26,6 +27,8 @@ public:
private:
bool handle_key_event(const KeyEvent& e) override;
WorldScene& m_scene;
ChatBox* m_chat_box;
ChatBox* m_chat_box = nullptr;
Image* m_mircophone = nullptr;
};
} // namespace Cubed

View File

@@ -302,5 +302,7 @@ void AudioEngine::receive_voice(std::span<const char> opus,
}
AudioRecording& AudioEngine::audio_recording() { return m_recording; }
const AudioRecording& AudioEngine::audio_recording() const {
return m_recording;
}
} // namespace Cubed

View File

@@ -726,6 +726,7 @@ AABB ClientWorld::get_block_aabb(const glm::ivec3& pos) {
}
AudioEngine& ClientWorld::get_audio() { return m_audio; }
const AudioEngine& ClientWorld::get_audio() const { return m_audio; }
Config& ClientWorld::get_config() { return m_config; }
WorldScene& ClientWorld::world_scene() { return m_world_scene; }
void ClientWorld::set_direct_exit() { m_exit_direct = true; }

View File

@@ -773,7 +773,6 @@ void ServerWorld::handle_chat_message(ChatMsg& msg) {
}
void ServerWorld::handle_voice_message(VoiceMsg& msg) {
Logger::info("Get voice Message");
auto pool = m_net_thread_pool.load();
std::string uuid = msg.uuid();
std::string data = msg.opus_data();
@@ -806,7 +805,6 @@ void ServerWorld::handle_voice_message(VoiceMsg& msg) {
for (auto& s : session) {
s->send(make_packet(*msg), 5);
}
Logger::info("Send voice message sum {}", session.size());
});
}

View File

@@ -394,7 +394,9 @@ void WorldScene::set_chatting(bool chatting, bool send) {
void WorldScene::handle_chat_message(ChatMessage& message) {
m_hud_ui.add_chat_message(message);
}
bool WorldScene::is_recording() const {
return m_client_world.get_audio().audio_recording().is_recording();
}
void WorldScene::set_error(std::string_view error) {
Logger::error("WorldScene Error Set {}", error);
m_error_ui.set_error(error);

View File

@@ -20,13 +20,11 @@ void WorldUIManager::init() {
m_root_widget->set_window_size(renderer.window_width(),
renderer.window_height());
auto& texture_manager = m_scene.scene_manager().app().texture_manager();
auto& crosshair = m_root_widget->add_child<Image>();
crosshair.set_image("texture/ui/0.png",
m_scene.scene_manager().app().texture_manager());
crosshair.set_window_size(renderer.window_width(),
renderer.window_height());
crosshair.set_image("texture/ui/0.png", texture_manager);
crosshair.set_anchor(Anchor::CENTER);
crosshair.set_scale(3.0f);
m_widgets.try_emplace("crosshair", &crosshair);
@@ -57,6 +55,12 @@ void WorldUIManager::init() {
m_scene.client_world().send_chat_message(message);
});
m_chat_box = &chat_box;
auto& microphone = m_root_widget->add_child<Image>();
microphone.set_image("texture/ui/microphone.png", texture_manager)
.set_scale(5.0f)
.set_anchor(Anchor::BOTTOM_RIGHT)
.set_visible(false);
m_mircophone = &microphone;
}
void WorldUIManager::render(Renderer& renderer) {
renderer.begin_render_ui();
@@ -68,6 +72,15 @@ void WorldUIManager::render(Renderer& renderer) {
renderer.end_render_ui();
}
void WorldUIManager::update(float dt) {
UIManager::update(dt);
if (m_scene.is_recording()) {
m_mircophone->set_visible(true);
} else {
m_mircophone->set_visible(false);
}
}
void WorldUIManager::set_chatting(bool chantting, bool send) {
m_chat_box->set_typing(chantting, send);