Revert some changes and fix scrolling bug

This commit is contained in:
Syniis 2024-02-22 20:02:13 +01:00
parent debbaea83c
commit 4caebcf4a3
5 changed files with 13 additions and 79 deletions

View File

@ -88,7 +88,6 @@ pub struct Chat<'a> {
history_max: usize, history_max: usize,
chat_size: Vec2<f64>, chat_size: Vec2<f64>,
chat_pos: Vec2<f64>, chat_pos: Vec2<f64>,
unread_tabs: Vec<bool>,
scale: Scale, scale: Scale,
localized_strings: &'a Localization, localized_strings: &'a Localization,
@ -105,7 +104,6 @@ impl<'a> Chat<'a> {
localized_strings: &'a Localization, localized_strings: &'a Localization,
chat_size: Vec2<f64>, chat_size: Vec2<f64>,
chat_pos: Vec2<f64>, chat_pos: Vec2<f64>,
unread_tabs: Vec<bool>,
scale: Scale, scale: Scale,
) -> Self { ) -> Self {
Self { Self {
@ -123,7 +121,6 @@ impl<'a> Chat<'a> {
chat_size, chat_size,
chat_pos, chat_pos,
localized_strings, localized_strings,
unread_tabs,
scale, scale,
} }
} }
@ -201,7 +198,6 @@ pub enum Event {
ShowChatTabSettings(usize), ShowChatTabSettings(usize),
ResizeChat(Vec2<f64>), ResizeChat(Vec2<f64>),
MoveChat(Vec2<f64>), MoveChat(Vec2<f64>),
UpdateUnread(Vec<bool>),
DisableForceChat, DisableForceChat,
} }
@ -245,7 +241,7 @@ impl<'a> Widget for Chat<'a> {
let mut events = Vec::new(); let mut events = Vec::new();
let chat_settings = &self.global_state.settings.chat; let chat_settings = &self.global_state.settings.chat;
let force_chat = !(&self.global_state.settings.interface.toggle_chat);
let chat_tabs = &chat_settings.chat_tabs; let chat_tabs = &chat_settings.chat_tabs;
let current_chat_tab = chat_settings.chat_tab_index.and_then(|i| chat_tabs.get(i)); let current_chat_tab = chat_settings.chat_tab_index.and_then(|i| chat_tabs.get(i));
@ -313,18 +309,6 @@ impl<'a> Widget for Chat<'a> {
}) })
.collect::<HashSet<_>>(); .collect::<HashSet<_>>();
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<bool> = self
.unread_tabs
.iter()
.zip(chat_tabs_with_new_content)
.map(|(a, b)| a | b)
.collect();
// Maintain scrolling // // Maintain scrolling //
if !self.new_messages.is_empty() { if !self.new_messages.is_empty() {
for message in self.new_messages.iter() { for message in self.new_messages.iter() {
@ -342,6 +326,10 @@ impl<'a> Widget for Chat<'a> {
} }
} }
if force_chat {
ui.scroll_widget(state.ids.message_box, [0.0, f64::MAX]);
}
// Trigger scroll event queued from previous frame // Trigger scroll event queued from previous frame
if state.scroll_next { if state.scroll_next {
ui.scroll_widget(state.ids.message_box, [0.0, f64::MAX]); ui.scroll_widget(state.ids.message_box, [0.0, f64::MAX]);
@ -673,15 +661,11 @@ impl<'a> Widget for Chat<'a> {
{ {
state.update(|s| s.tabs_last_hover_pulse = Some(self.pulse)); state.update(|s| s.tabs_last_hover_pulse = Some(self.pulse));
} }
let time_since_hover = if chat_settings.chat_tab_fade { if let Some(time_since_hover) = state
state
.tabs_last_hover_pulse .tabs_last_hover_pulse
.map(|t| self.pulse - t) .map(|t| self.pulse - t)
.filter(|t| t <= &1.5) .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 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); let shading = color::rgba(1.0, 0.82, 0.27, (chat_settings.chat_opacity + 0.1) * alpha);
@ -726,8 +710,7 @@ impl<'a> Widget for Chat<'a> {
}); });
} }
for (i, chat_tab) in chat_tabs.iter().enumerate() { for (i, chat_tab) in chat_tabs.iter().enumerate() {
let is_unread = new_unread[i]; if Button::image(if chat_settings.chat_tab_index == Some(i) {
if Button::image(if chat_settings.chat_tab_index == Some(i) || is_unread {
self.imgs.selection self.imgs.selection
} else { } else {
self.imgs.nothing self.imgs.nothing
@ -748,7 +731,7 @@ impl<'a> Widget for Chat<'a> {
0.0, 0.0,
) )
.and(|r| { .and(|r| {
if is_unread && chat_settings.chat_tab_index != Some(i) { if chat_settings.chat_tab_index != Some(i) {
r.image_color(shading.complement()) r.image_color(shading.complement())
} else { } else {
r.image_color(shading) r.image_color(shading)
@ -757,7 +740,6 @@ impl<'a> Widget for Chat<'a> {
.set(state.ids.chat_tabs[i], ui) .set(state.ids.chat_tabs[i], ui)
.was_clicked() .was_clicked()
{ {
new_unread[i] = false;
events.push(Event::ChangeChatTab(Some(i))); events.push(Event::ChangeChatTab(Some(i)));
} }
@ -867,7 +849,6 @@ impl<'a> Widget for Chat<'a> {
} }
}) })
.set(state.ids.draggable_area, ui); .set(state.ids.draggable_area, ui);
events.push(Event::UpdateUnread(new_unread));
events events
} }
} }

View File

@ -1297,7 +1297,6 @@ pub struct Hud {
map_drag: Vec2<f64>, map_drag: Vec2<f64>,
chat_size: Vec2<f64>, chat_size: Vec2<f64>,
chat_pos: Vec2<f64>, chat_pos: Vec2<f64>,
unread_tabs: Vec<bool>,
force_chat: bool, force_chat: bool,
} }
@ -1437,7 +1436,6 @@ impl Hud {
map_drag: Vec2::zero(), map_drag: Vec2::zero(),
chat_size: Vec2::new(DEFAULT_CHAT_BOX_WIDTH, DEFAULT_CHAT_BOX_HEIGHT), chat_size: Vec2::new(DEFAULT_CHAT_BOX_WIDTH, DEFAULT_CHAT_BOX_HEIGHT),
chat_pos: Vec2::new(10.0, 10.0), chat_pos: Vec2::new(10.0, 10.0),
unread_tabs: vec![false; global_state.settings.chat.chat_tabs.len()],
force_chat: false, force_chat: false,
} }
} }
@ -3512,7 +3510,6 @@ impl Hud {
i18n, i18n,
self.chat_size, self.chat_size,
self.chat_pos, self.chat_pos,
self.unread_tabs.clone(),
scale, scale,
) )
.and_then(self.force_chat_input.take(), |c, input| c.input(input)) .and_then(self.force_chat_input.take(), |c, input| c.input(input))
@ -3549,9 +3546,6 @@ impl Hud {
chat::Event::MoveChat(pos) => { chat::Event::MoveChat(pos) => {
self.chat_pos = pos; self.chat_pos = pos;
}, },
chat::Event::UpdateUnread(unread) => {
self.unread_tabs = unread;
},
chat::Event::DisableForceChat => { chat::Event::DisableForceChat => {
self.force_chat = false; self.force_chat = false;
}, },
@ -3611,16 +3605,6 @@ 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)); events.push(Event::SettingsChange(settings_change));

View File

@ -26,8 +26,6 @@ widget_ids! {
transp_value, transp_value,
char_name_text, char_name_text,
char_name_button, char_name_button,
chat_tab_fade_text,
chat_tab_fade_button,
reset_chat_button, reset_chat_button,
//Tabs //Tabs
@ -215,35 +213,12 @@ 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 // Reset the chat settings to the default settings
if Button::image(self.imgs.button) if Button::image(self.imgs.button)
.w_h(RESET_BUTTONS_WIDTH, RESET_BUTTONS_HEIGHT) .w_h(RESET_BUTTONS_WIDTH, RESET_BUTTONS_HEIGHT)
.hover_image(self.imgs.button_hover) .hover_image(self.imgs.button_hover)
.press_image(self.imgs.button_press) .press_image(self.imgs.button_press)
.down_from(state.ids.chat_tab_fade_text, 20.0) .down_from(state.ids.char_name_text, 20.0)
.label(&self.localized_strings.get_msg("hud-settings-reset_chat")) .label(&self.localized_strings.get_msg("hud-settings-reset_chat"))
.label_font_size(self.fonts.cyri.scale(14)) .label_font_size(self.fonts.cyri.scale(14))
.label_color(TEXT_COLOR) .label_color(TEXT_COLOR)

View File

@ -43,7 +43,6 @@ pub enum Chat {
ChatTabInsert(usize, ChatTab), ChatTabInsert(usize, ChatTab),
ChatTabMove(usize, usize), //(i, j) move item from position i, and insert into position j ChatTabMove(usize, usize), //(i, j) move item from position i, and insert into position j
ChatTabRemove(usize), ChatTabRemove(usize),
ChatTabFade(bool),
ResetChatSettings, ResetChatSettings,
} }
#[derive(Clone)] #[derive(Clone)]
@ -352,9 +351,6 @@ impl SettingsChange {
settings.chat.chat_tabs.remove(i); settings.chat.chat_tabs.remove(i);
} }
}, },
Chat::ChatTabFade(fade) => {
settings.chat.chat_tab_fade = fade;
},
Chat::ResetChatSettings => { Chat::ResetChatSettings => {
settings.chat = ChatSettings::default(); settings.chat = ChatSettings::default();
}, },

View File

@ -73,7 +73,6 @@ pub struct ChatSettings {
pub chat_character_name: bool, pub chat_character_name: bool,
pub chat_tabs: Vec<ChatTab>, pub chat_tabs: Vec<ChatTab>,
pub chat_tab_index: Option<usize>, pub chat_tab_index: Option<usize>,
pub chat_tab_fade: bool,
pub chat_cmd_prefix: char, pub chat_cmd_prefix: char,
} }
@ -84,7 +83,6 @@ impl Default for ChatSettings {
chat_character_name: true, chat_character_name: true,
chat_tabs: vec![ChatTab::default()], chat_tabs: vec![ChatTab::default()],
chat_tab_index: Some(0), chat_tab_index: Some(0),
chat_tab_fade: false,
chat_cmd_prefix: '/', chat_cmd_prefix: '/',
} }
} }