From 1cb0b6a84ea2c4a148a23fe34ab937ba5697efb7 Mon Sep 17 00:00:00 2001 From: Syniis Date: Tue, 30 Jan 2024 11:56:49 +0100 Subject: [PATCH] Chat tab message notification and disable chat tab fade-out --- voxygen/src/hud/chat.rs | 65 ++++++++++++++++++------- voxygen/src/hud/mod.rs | 16 ++++++ voxygen/src/hud/settings_window/chat.rs | 27 +++++++++- voxygen/src/session/settings_change.rs | 4 ++ voxygen/src/settings/chat.rs | 2 + 5 files changed, 95 insertions(+), 19 deletions(-) diff --git a/voxygen/src/hud/chat.rs b/voxygen/src/hud/chat.rs index 5a30b09a41..17ee07a869 100644 --- a/voxygen/src/hud/chat.rs +++ b/voxygen/src/hud/chat.rs @@ -19,6 +19,7 @@ use conrod_core::{ }; use i18n::Localization; use i18n_helpers::localize_chat_message; +use inline_tweak::tweak; use std::collections::{HashSet, VecDeque}; use vek::Vec2; @@ -83,6 +84,7 @@ pub struct Chat<'a> { history_max: usize, chat_size: Vec2, chat_pos: Vec2, + unread_tabs: Vec, localized_strings: &'a Localization, } @@ -98,6 +100,7 @@ impl<'a> Chat<'a> { localized_strings: &'a Localization, chat_size: Vec2, chat_pos: Vec2, + unread_tabs: Vec, ) -> Self { Self { pulse, @@ -114,6 +117,7 @@ impl<'a> Chat<'a> { chat_size, chat_pos, localized_strings, + unread_tabs, } } @@ -190,6 +194,7 @@ pub enum Event { ShowChatTabSettings(usize), ResizeChat(Vec2), MoveChat(Vec2), + UpdateUnread(Vec), } impl<'a> Widget for Chat<'a> { @@ -286,6 +291,28 @@ impl<'a> Widget for Chat<'a> { handle_chat_mouse_events(state.ids.draggable_area, ui, &mut events); + let group_members = self + .client + .group_members() + .iter() + .filter_map(|(u, r)| match r { + Role::Member => Some(u), + Role::Pet => None, + }) + .collect::>(); + + let chat_tabs_with_new_content = chat_tabs.iter().map(|tab| { + self.new_messages + .iter() + .any(|new_message| tab.filter.satisfies(new_message, &group_members)) + }); + let mut new_unread: Vec = self + .unread_tabs + .iter() + .zip(chat_tabs_with_new_content) + .map(|(a, b)| a | b) + .collect(); + // Maintain scrolling // if !self.new_messages.is_empty() { for message in self.new_messages.iter() { @@ -521,15 +548,6 @@ impl<'a> Widget for Chat<'a> { .resize(s.messages.len(), &mut ui.widget_id_generator()) }); } - let group_members = self - .client - .group_members() - .iter() - .filter_map(|(u, r)| match r { - Role::Member => Some(u), - Role::Pet => None, - }) - .collect::>(); let show_char_name = chat_settings.chat_character_name; let messages = &state .messages @@ -643,12 +661,15 @@ impl<'a> Widget for Chat<'a> { { state.update(|s| s.tabs_last_hover_pulse = Some(self.pulse)); } - - if let Some(time_since_hover) = state - .tabs_last_hover_pulse - .map(|t| self.pulse - t) - .filter(|t| t <= &1.5) - { + let time_since_hover = if chat_settings.chat_tab_fade { + state + .tabs_last_hover_pulse + .map(|t| self.pulse - t) + .filter(|t| t <= &1.5) + } else { + Some(0.0) + }; + if let Some(time_since_hover) = time_since_hover { let alpha = 1.0 - (time_since_hover / 1.5).powi(4); let shading = color::rgba(1.0, 0.82, 0.27, (chat_settings.chat_opacity + 0.1) * alpha); @@ -693,7 +714,8 @@ impl<'a> Widget for Chat<'a> { }); } for (i, chat_tab) in chat_tabs.iter().enumerate() { - if Button::image(if chat_settings.chat_tab_index == Some(i) { + let is_unread = new_unread[i]; + if Button::image(if chat_settings.chat_tab_index == Some(i) || is_unread { self.imgs.selection } else { self.imgs.nothing @@ -701,7 +723,6 @@ impl<'a> Widget for Chat<'a> { .w_h(chat_tab_width, CHAT_TAB_HEIGHT) .hover_image(self.imgs.selection_hover) .press_image(self.imgs.selection_press) - .image_color(shading) .label(chat_tab.label.as_str()) .label_font_size(self.fonts.cyri.scale(14)) .label_font_id(self.fonts.cyri.conrod_id) @@ -714,9 +735,17 @@ impl<'a> Widget for Chat<'a> { }, 0.0, ) + .and(|r| { + if is_unread && chat_settings.chat_tab_index != Some(i) { + r.image_color(shading.complement()) + } else { + r.image_color(shading) + } + }) .set(state.ids.chat_tabs[i], ui) .was_clicked() { + new_unread[i] = false; events.push(Event::ChangeChatTab(Some(i))); } @@ -815,7 +844,7 @@ impl<'a> Widget for Chat<'a> { } }) .set(state.ids.draggable_area, ui); - + events.push(Event::UpdateUnread(new_unread)); events } } diff --git a/voxygen/src/hud/mod.rs b/voxygen/src/hud/mod.rs index ab59ea2784..2b7f6fdb6a 100755 --- a/voxygen/src/hud/mod.rs +++ b/voxygen/src/hud/mod.rs @@ -1296,6 +1296,7 @@ pub struct Hud { map_drag: Vec2, chat_size: Vec2, chat_pos: Vec2, + unread_tabs: Vec, } impl Hud { @@ -1433,6 +1434,7 @@ impl Hud { map_drag: Vec2::zero(), chat_size: Vec2::new(DEFAULT_CHAT_BOX_WIDTH, DEFAULT_CHAT_BOX_HEIGHT), chat_pos: Vec2::new(10.0, 10.0), + unread_tabs: vec![false; global_state.settings.chat.chat_tabs.len()], } } @@ -3502,6 +3504,7 @@ impl Hud { i18n, self.chat_size, self.chat_pos, + self.unread_tabs.clone(), ) .and_then(self.force_chat_input.take(), |c, input| c.input(input)) .and_then(self.tab_complete.take(), |c, input| { @@ -3537,6 +3540,9 @@ impl Hud { chat::Event::MoveChat(pos) => { self.chat_pos = pos; }, + chat::Event::UpdateUnread(unread) => { + self.unread_tabs = unread; + }, } } } @@ -3588,6 +3594,16 @@ impl Hud { }, _ => {}, }, + SettingsChange::Chat(chat_change) => match chat_change { + ChatChange::ChatTabInsert(idx, _) => { + self.unread_tabs.insert(*idx, false) + }, + ChatChange::ChatTabRemove(idx) => { + self.unread_tabs.remove(*idx); + }, + ChatChange::ResetChatSettings => self.unread_tabs.truncate(1), + _ => {}, + }, _ => {}, } events.push(Event::SettingsChange(settings_change)); diff --git a/voxygen/src/hud/settings_window/chat.rs b/voxygen/src/hud/settings_window/chat.rs index d57143d6e9..2c0ce765a9 100644 --- a/voxygen/src/hud/settings_window/chat.rs +++ b/voxygen/src/hud/settings_window/chat.rs @@ -26,6 +26,8 @@ widget_ids! { transp_value, char_name_text, char_name_button, + chat_tab_fade_text, + chat_tab_fade_button, reset_chat_button, //Tabs @@ -213,12 +215,35 @@ impl<'a> Widget for Chat<'a> { ))); } + // "Show character names in chat" toggle button + Text::new("Fade out Chat Tabs") + .down_from(state.ids.char_name_text, 10.0) + .font_size(self.fonts.cyri.scale(14)) + .font_id(self.fonts.cyri.conrod_id) + .color(TEXT_COLOR) + .set(state.ids.chat_tab_fade_text, ui); + + if chat_settings.chat_tab_fade + != ToggleButton::new( + chat_settings.chat_tab_fade, + self.imgs.checkbox, + self.imgs.checkbox_checked, + ) + .w_h(18.0, 18.0) + .right_from(state.ids.chat_tab_fade_text, 10.0) + .hover_images(self.imgs.checkbox_mo, self.imgs.checkbox_checked_mo) + .press_images(self.imgs.checkbox_press, self.imgs.checkbox_checked) + .set(state.ids.chat_tab_fade_button, ui) + { + events.push(Event::ChatChange(ChatTabFade(!chat_settings.chat_tab_fade))); + } + // Reset the chat settings to the default settings if Button::image(self.imgs.button) .w_h(RESET_BUTTONS_WIDTH, RESET_BUTTONS_HEIGHT) .hover_image(self.imgs.button_hover) .press_image(self.imgs.button_press) - .down_from(state.ids.char_name_text, 20.0) + .down_from(state.ids.chat_tab_fade_text, 20.0) .label(&self.localized_strings.get_msg("hud-settings-reset_chat")) .label_font_size(self.fonts.cyri.scale(14)) .label_color(TEXT_COLOR) diff --git a/voxygen/src/session/settings_change.rs b/voxygen/src/session/settings_change.rs index 0e7096230a..b32035698a 100644 --- a/voxygen/src/session/settings_change.rs +++ b/voxygen/src/session/settings_change.rs @@ -43,6 +43,7 @@ pub enum Chat { ChatTabInsert(usize, ChatTab), ChatTabMove(usize, usize), //(i, j) move item from position i, and insert into position j ChatTabRemove(usize), + ChatTabFade(bool), ResetChatSettings, } #[derive(Clone)] @@ -351,6 +352,9 @@ impl SettingsChange { settings.chat.chat_tabs.remove(i); } }, + Chat::ChatTabFade(fade) => { + settings.chat.chat_tab_fade = fade; + }, Chat::ResetChatSettings => { settings.chat = ChatSettings::default(); }, diff --git a/voxygen/src/settings/chat.rs b/voxygen/src/settings/chat.rs index 4b0b29ceac..b8724ded08 100644 --- a/voxygen/src/settings/chat.rs +++ b/voxygen/src/settings/chat.rs @@ -73,6 +73,7 @@ pub struct ChatSettings { pub chat_character_name: bool, pub chat_tabs: Vec, pub chat_tab_index: Option, + pub chat_tab_fade: bool, pub chat_cmd_prefix: char, } @@ -83,6 +84,7 @@ impl Default for ChatSettings { chat_character_name: true, chat_tabs: vec![ChatTab::default()], chat_tab_index: Some(0), + chat_tab_fade: false, chat_cmd_prefix: '/', } }