From b84708ca7561b9ec7ebccc3815b023c334d5cb1a Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Mon, 21 Jun 2021 20:16:03 +0100 Subject: [PATCH] Added chat toggle --- CHANGELOG.md | 1 + assets/voxygen/i18n/en/hud/hud_settings.ron | 1 + voxygen/src/hud/mod.rs | 76 ++++++++++---------- voxygen/src/hud/settings_window/interface.rs | 28 +++++++- voxygen/src/session/settings_change.rs | 4 ++ voxygen/src/settings/interface.rs | 2 + 6 files changed, 74 insertions(+), 38 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ee737abab2..b0874a123a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added debug line info to release builds, enhancing the usefulness of panic backtraces - NPCs and animals can now make sounds in response to certain events - Players can press H to greet others +- Ability to toggle chat visibility ### Changed - Entity-entity pushback is no longer applied in forced movement states like rolling and leaping. diff --git a/assets/voxygen/i18n/en/hud/hud_settings.ron b/assets/voxygen/i18n/en/hud/hud_settings.ron index 24023e2ba3..1292fb06c7 100644 --- a/assets/voxygen/i18n/en/hud/hud_settings.ron +++ b/assets/voxygen/i18n/en/hud/hud_settings.ron @@ -11,6 +11,7 @@ "hud.settings.help_window": "Help Window", "hud.settings.debug_info": "Debug Info", "hud.settings.show_hitboxes": "Show hitboxes", + "hud.settings.show_chat": "Show chat", "hud.settings.tips_on_startup": "Tips-On-Startup", "hud.settings.ui_scale": "UI-Scale", "hud.settings.relative_scaling": "Relative Scaling", diff --git a/voxygen/src/hud/mod.rs b/voxygen/src/hud/mod.rs index d409045156..fa478cb929 100644 --- a/voxygen/src/hud/mod.rs +++ b/voxygen/src/hud/mod.rs @@ -2706,43 +2706,45 @@ impl Hud { .retain(|m| !matches!(m.chat_type, comp::ChatType::Npc(_, _))); // Chat box - for event in Chat::new( - &mut self.new_messages, - &client, - global_state, - self.pulse, - &self.imgs, - &self.fonts, - i18n, - ) - .and_then(self.force_chat_input.take(), |c, input| c.input(input)) - .and_then(self.tab_complete.take(), |c, input| { - c.prepare_tab_completion(input) - }) - .and_then(self.force_chat_cursor.take(), |c, pos| c.cursor_pos(pos)) - .set(self.ids.chat, ui_widgets) - { - match event { - chat::Event::TabCompletionStart(input) => { - self.tab_complete = Some(input); - }, - chat::Event::SendMessage(message) => { - events.push(Event::SendMessage(message)); - }, - chat::Event::SendCommand(name, args) => { - events.push(Event::SendCommand(name, args)); - }, - chat::Event::Focus(focus_id) => { - self.to_focus = Some(Some(focus_id)); - }, - chat::Event::ChangeChatTab(tab) => { - events.push(Event::SettingsChange(ChatChange::ChangeChatTab(tab).into())); - }, - chat::Event::ShowChatTabSettings(tab) => { - self.show.chat_tab_settings_index = Some(tab); - self.show.settings_tab = SettingsTab::Chat; - self.show.settings(true); - }, + if global_state.settings.interface.toggle_chat { + for event in Chat::new( + &mut self.new_messages, + &client, + global_state, + self.pulse, + &self.imgs, + &self.fonts, + i18n, + ) + .and_then(self.force_chat_input.take(), |c, input| c.input(input)) + .and_then(self.tab_complete.take(), |c, input| { + c.prepare_tab_completion(input) + }) + .and_then(self.force_chat_cursor.take(), |c, pos| c.cursor_pos(pos)) + .set(self.ids.chat, ui_widgets) + { + match event { + chat::Event::TabCompletionStart(input) => { + self.tab_complete = Some(input); + }, + chat::Event::SendMessage(message) => { + events.push(Event::SendMessage(message)); + }, + chat::Event::SendCommand(name, args) => { + events.push(Event::SendCommand(name, args)); + }, + chat::Event::Focus(focus_id) => { + self.to_focus = Some(Some(focus_id)); + }, + chat::Event::ChangeChatTab(tab) => { + events.push(Event::SettingsChange(ChatChange::ChangeChatTab(tab).into())); + }, + chat::Event::ShowChatTabSettings(tab) => { + self.show.chat_tab_settings_index = Some(tab); + self.show.settings_tab = SettingsTab::Chat; + self.show.settings(true); + }, + } } } diff --git a/voxygen/src/hud/settings_window/interface.rs b/voxygen/src/hud/settings_window/interface.rs index 30478a2e20..11dd1ff536 100644 --- a/voxygen/src/hud/settings_window/interface.rs +++ b/voxygen/src/hud/settings_window/interface.rs @@ -38,6 +38,8 @@ widget_ids! { debug_button_label, hitboxes_button, hitboxes_button_label, + chat_button, + chat_button_label, ch_title, ch_transp_slider, ch_transp_value, @@ -266,9 +268,33 @@ impl<'a> Widget for Interface<'a> { .color(TEXT_COLOR) .set(state.ids.hitboxes_button_label, ui); + // Chat + let show_chat = ToggleButton::new( + self.global_state.settings.interface.toggle_chat, + self.imgs.checkbox, + self.imgs.checkbox_checked, + ) + .w_h(18.0, 18.0) + .down_from(state.ids.hitboxes_button, 8.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_button, ui); + + if self.global_state.settings.interface.toggle_chat != show_chat { + events.push(ToggleChat(show_chat)); + } + + Text::new(&self.localized_strings.get("hud.settings.show_chat")) + .right_from(state.ids.chat_button, 10.0) + .font_size(self.fonts.cyri.scale(14)) + .font_id(self.fonts.cyri.conrod_id) + .graphics_for(state.ids.chat_button) + .color(TEXT_COLOR) + .set(state.ids.chat_button_label, ui); + // Ui Scale Text::new(&self.localized_strings.get("hud.settings.ui_scale")) - .down_from(state.ids.hitboxes_button, 20.0) + .down_from(state.ids.chat_button, 20.0) .font_size(self.fonts.cyri.scale(18)) .font_id(self.fonts.cyri.conrod_id) .color(TEXT_COLOR) diff --git a/voxygen/src/session/settings_change.rs b/voxygen/src/session/settings_change.rs index cbb4fdaa64..0b62766580 100644 --- a/voxygen/src/session/settings_change.rs +++ b/voxygen/src/session/settings_change.rs @@ -97,6 +97,7 @@ pub enum Interface { ToggleHelp(bool), ToggleDebug(bool), ToggleHitboxes(bool), + ToggleChat(bool), ToggleTips(bool), CrosshairTransp(f32), @@ -450,6 +451,9 @@ impl SettingsChange { Interface::ToggleHitboxes(toggle_hitboxes) => { settings.interface.toggle_hitboxes = toggle_hitboxes; }, + Interface::ToggleChat(toggle_chat) => { + settings.interface.toggle_chat = toggle_chat; + }, Interface::ToggleTips(loading_tips) => { settings.interface.loading_tips = loading_tips; }, diff --git a/voxygen/src/settings/interface.rs b/voxygen/src/settings/interface.rs index 0e632d4765..b85caac831 100644 --- a/voxygen/src/settings/interface.rs +++ b/voxygen/src/settings/interface.rs @@ -11,6 +11,7 @@ use vek::*; pub struct InterfaceSettings { pub toggle_debug: bool, pub toggle_hitboxes: bool, + pub toggle_chat: bool, pub sct: bool, pub sct_player_batch: bool, pub sct_damage_batch: bool, @@ -46,6 +47,7 @@ impl Default for InterfaceSettings { Self { toggle_debug: false, toggle_hitboxes: false, + toggle_chat: true, sct: true, sct_player_batch: false, sct_damage_batch: false,