fix text sizing, and add custom hotkey support

This commit is contained in:
Evan Carroll 2026-01-16 13:58:19 -06:00
parent 09590edd95
commit ee425e224e
10 changed files with 1096 additions and 280 deletions

View file

@ -12,14 +12,15 @@ use leptos_router::hooks::use_params_map;
use uuid::Uuid;
use crate::components::{
ActiveBubble, Card, ChatInput, ChatMessage, InventoryPopup, MessageLog, RealmHeader,
RealmSceneViewer, SettingsPopup, ViewerSettings, DEFAULT_BUBBLE_TIMEOUT_MS,
ActiveBubble, Card, ChatInput, ChatMessage, EmotionKeybindings, InventoryPopup,
KeybindingsPopup, MessageLog, RealmHeader, RealmSceneViewer, SettingsPopup, ViewerSettings,
DEFAULT_BUBBLE_TIMEOUT_MS,
};
#[cfg(feature = "hydrate")]
use crate::components::use_channel_websocket;
use chattyness_db::models::{
AvatarWithPaths, ChannelMemberWithAvatar, EmotionAvailability, EmotionState, LooseProp,
RealmRole, RealmWithUserRole, Scene,
AvatarWithPaths, ChannelMemberWithAvatar, EmotionAvailability, LooseProp, RealmRole,
RealmWithUserRole, Scene,
};
#[cfg(feature = "hydrate")]
use chattyness_db::ws_messages::ClientMessage;
@ -100,6 +101,10 @@ pub fn RealmPage() -> impl IntoView {
let (settings_open, set_settings_open) = signal(false);
let viewer_settings = RwSignal::new(ViewerSettings::load());
// Keybindings popup state
let keybindings = RwSignal::new(EmotionKeybindings::load());
let (keybindings_open, set_keybindings_open) = signal(false);
// Scene dimensions (extracted from bounds_wkt when scene loads)
let (scene_dimensions, set_scene_dimensions) = signal((800.0_f64, 600.0_f64));
@ -450,31 +455,35 @@ pub fn RealmPage() -> impl IntoView {
return;
}
// Handle 'k' to toggle keybindings
if key == "k" || key == "K" {
set_keybindings_open.update(|v| *v = !*v);
ev.prevent_default();
return;
}
// Check if 'e' key was pressed
if key == "e" || key == "E" {
*e_pressed_clone.borrow_mut() = true;
return;
}
// Check for 0-9 after 'e' was pressed
// Check for 0-9, q, w after 'e' was pressed (emotion keybindings)
if *e_pressed_clone.borrow() {
*e_pressed_clone.borrow_mut() = false; // Reset regardless of outcome
if key.len() == 1 {
if let Ok(digit) = key.parse::<u8>() {
// Convert digit to emotion name using EmotionState
if let Some(emotion_state) = EmotionState::from_index(digit) {
let emotion = emotion_state.to_string();
#[cfg(debug_assertions)]
web_sys::console::log_1(
&format!("[Emotion] Sending emotion {}", emotion).into(),
);
ws_sender.with_value(|sender| {
if let Some(send_fn) = sender {
send_fn(ClientMessage::UpdateEmotion { emotion });
}
});
let bindings = keybindings.get_untracked();
if let Some(emotion_state) = bindings.get_emotion_for_key(&key) {
let emotion = emotion_state.to_string();
#[cfg(debug_assertions)]
web_sys::console::log_1(
&format!("[Emotion] Sending emotion {}", emotion).into(),
);
ws_sender.with_value(|sender| {
if let Some(send_fn) = sender {
send_fn(ClientMessage::UpdateEmotion { emotion });
}
}
});
ev.prevent_default();
}
} else {
// Any other key resets the 'e' state
@ -713,6 +722,15 @@ pub fn RealmPage() -> impl IntoView {
})
scene_dimensions=scene_dimensions.get()
/>
// Keybindings popup
<KeybindingsPopup
open=Signal::derive(move || keybindings_open.get())
keybindings=keybindings
emotion_availability=Signal::derive(move || emotion_availability.get())
skin_preview_path=Signal::derive(move || skin_preview_path.get())
on_close=Callback::new(move |_: ()| set_keybindings_open.set(false))
/>
}
.into_any()
}