From b910c1dd9c981e92377bf972c9aec730506e091b Mon Sep 17 00:00:00 2001 From: Bafon Date: Wed, 15 Sep 2021 12:04:44 +0000 Subject: [PATCH] Add setting to always show energy bars --- CHANGELOG.md | 2 ++ assets/voxygen/i18n/en/hud/settings.ron | 1 + voxygen/src/hud/buffs.rs | 7 +++--- voxygen/src/hud/settings_window/interface.rs | 26 ++++++++++++++++++++ voxygen/src/hud/skillbar.rs | 7 +++--- voxygen/src/session/settings_change.rs | 4 +++ voxygen/src/settings/interface.rs | 2 ++ 7 files changed, 43 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a0209e1bb2..6427b3b411 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +- Added a setting to always show health and energy bars + ### Changed - Made dungeon tiers 3, 4, and 5 more common diff --git a/assets/voxygen/i18n/en/hud/settings.ron b/assets/voxygen/i18n/en/hud/settings.ron index fe1a6f241d..b66d9d7ff8 100644 --- a/assets/voxygen/i18n/en/hud/settings.ron +++ b/assets/voxygen/i18n/en/hud/settings.ron @@ -32,6 +32,7 @@ "hud.settings.speech_bubble_dark_mode": "Speech Bubble Dark Mode", "hud.settings.speech_bubble_icon": "Speech Bubble Icon", "hud.settings.energybar_numbers": "Energybar Numbers", + "hud.settings.always_show_bars": "Always show Energybars", "hud.settings.values": "Values", "hud.settings.percentages": "Percentages", "hud.settings.chat": "Chat", diff --git a/voxygen/src/hud/buffs.rs b/voxygen/src/hud/buffs.rs index 0356f13d52..b8b9bece57 100644 --- a/voxygen/src/hud/buffs.rs +++ b/voxygen/src/hud/buffs.rs @@ -127,10 +127,11 @@ impl<'a> Widget for BuffsBar<'a> { .desc_text_color(TEXT_COLOR); if let BuffPosition::Bar = buff_position { let decayed_health = 1.0 - self.health.maximum() / self.health.base_max(); - let show_health = (self.health.current() - self.health.maximum()).abs() - > Health::HEALTH_EPSILON + let show_health = self.global_state.settings.interface.always_show_bars + || (self.health.current() - self.health.maximum()).abs() > Health::HEALTH_EPSILON || decayed_health > 0.0; - let show_energy = self.energy.current() != self.energy.maximum(); + let show_energy = self.global_state.settings.interface.always_show_bars + || self.energy.current() != self.energy.maximum(); let offset = if show_energy && show_health { 140.0 } else if show_health || show_energy { diff --git a/voxygen/src/hud/settings_window/interface.rs b/voxygen/src/hud/settings_window/interface.rs index 8ccc2c8d34..1fc12eb74b 100644 --- a/voxygen/src/hud/settings_window/interface.rs +++ b/voxygen/src/hud/settings_window/interface.rs @@ -62,6 +62,8 @@ widget_ids! { show_bar_numbers_values_text, show_bar_numbers_percentage_button, show_bar_numbers_percentage_text, + always_show_bars_button, + always_show_bars_label, // show_shortcuts_button, show_shortcuts_text, @@ -981,6 +983,30 @@ impl<'a> Widget for Interface<'a> { .color(TEXT_COLOR) .set(state.ids.show_bar_numbers_percentage_text, ui); + // Always show energy bars + let always_show_bars = ToggleButton::new( + self.global_state.settings.interface.always_show_bars, + self.imgs.checkbox, + self.imgs.checkbox_checked, + ) + .w_h(18.0, 18.0) + .down_from(state.ids.show_bar_numbers_percentage_button, 20.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.always_show_bars_button, ui); + + if always_show_bars != self.global_state.settings.interface.always_show_bars { + events.push(ToggleAlwaysShowBars(always_show_bars)); + } + + Text::new(self.localized_strings.get("hud.settings.always_show_bars")) + .right_from(state.ids.always_show_bars_button, 10.0) + .font_size(self.fonts.cyri.scale(14)) + .font_id(self.fonts.cyri.conrod_id) + .graphics_for(state.ids.always_show_bars_button) + .color(TEXT_COLOR) + .set(state.ids.always_show_bars_label, ui); + // Reset the interface settings to the default settings if Button::image(self.imgs.button) .w_h(RESET_BUTTONS_WIDTH, RESET_BUTTONS_HEIGHT) diff --git a/voxygen/src/hud/skillbar.rs b/voxygen/src/hud/skillbar.rs index 379ae733ed..d9e763eee9 100644 --- a/voxygen/src/hud/skillbar.rs +++ b/voxygen/src/hud/skillbar.rs @@ -377,9 +377,10 @@ impl<'a> Skillbar<'a> { let hp_ani = (self.pulse * 4.0/* speed factor */).cos() * 0.5 + 0.8; let crit_hp_color: Color = Color::Rgba(0.79, 0.19, 0.17, hp_ani); let bar_values = self.global_state.settings.interface.bar_numbers; - let show_health = - (self.health.current() - self.health.maximum()).abs() > Health::HEALTH_EPSILON; - let show_energy = self.energy.current() != self.energy.maximum(); + let show_health = self.global_state.settings.interface.always_show_bars + || (self.health.current() - self.health.maximum()).abs() > Health::HEALTH_EPSILON; + let show_energy = self.global_state.settings.interface.always_show_bars + || self.energy.current() != self.energy.maximum(); let decayed_health = 1.0 - self.health.maximum() as f64 / self.health.base_max() as f64; if show_health && !self.health.is_dead || decayed_health > 0.0 { diff --git a/voxygen/src/session/settings_change.rs b/voxygen/src/session/settings_change.rs index 7d4b63b11e..f3ca3b85a7 100644 --- a/voxygen/src/session/settings_change.rs +++ b/voxygen/src/session/settings_change.rs @@ -106,6 +106,7 @@ pub enum Interface { Intro(Intro), ToggleXpBar(XpBar), ToggleBarNumbers(BarNumbers), + ToggleAlwaysShowBars(bool), ToggleShortcutNumbers(ShortcutNumbers), BuffPosition(BuffPosition), @@ -468,6 +469,9 @@ impl SettingsChange { Interface::ToggleBarNumbers(bar_numbers) => { settings.interface.bar_numbers = bar_numbers; }, + Interface::ToggleAlwaysShowBars(always_show_bars) => { + settings.interface.always_show_bars = always_show_bars; + }, Interface::ToggleShortcutNumbers(shortcut_numbers) => { settings.interface.shortcut_numbers = shortcut_numbers; }, diff --git a/voxygen/src/settings/interface.rs b/voxygen/src/settings/interface.rs index 4f37880dda..ccb1a312dd 100644 --- a/voxygen/src/settings/interface.rs +++ b/voxygen/src/settings/interface.rs @@ -25,6 +25,7 @@ pub struct InterfaceSettings { pub shortcut_numbers: ShortcutNumbers, pub buff_position: BuffPosition, pub bar_numbers: BarNumbers, + pub always_show_bars: bool, pub ui_scale: ScaleMode, pub map_zoom: f64, pub map_drag: Vec2, @@ -62,6 +63,7 @@ impl Default for InterfaceSettings { shortcut_numbers: ShortcutNumbers::On, buff_position: BuffPosition::Bar, bar_numbers: BarNumbers::Values, + always_show_bars: false, ui_scale: ScaleMode::RelativeToWindow([1920.0, 1080.0].into()), map_zoom: 10.0, map_drag: Vec2 { x: 0.0, y: 0.0 },