From dffc91045eeecd4891d8ed6aa0cd186d843728db Mon Sep 17 00:00:00 2001 From: "Dr. Dystopia" Date: Sun, 1 Aug 2021 21:59:09 +0200 Subject: [PATCH 1/3] Move variables closer to usage in 'buttons' file --- voxygen/src/hud/buttons.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/voxygen/src/hud/buttons.rs b/voxygen/src/hud/buttons.rs index d046c8a783..21a8b3f943 100644 --- a/voxygen/src/hud/buttons.rs +++ b/voxygen/src/hud/buttons.rs @@ -126,13 +126,7 @@ impl<'a> Widget for Buttons<'a> { fn update(self, args: widget::UpdateArgs) -> Self::Event { common_base::prof_span!("Buttons::update"); let widget::UpdateArgs { state, ui, .. } = args; - let invs = self.client.inventories(); - let inventory = match invs.get(self.client.entity()) { - Some(inv) => inv, - None => return None, - }; let localized_strings = self.localized_strings; - let arrow_ani = (self.pulse * 4.0/* speed factor */).cos() * 0.5 + 0.8; //Animation timer let button_tooltip = Tooltip::new({ // Edge images [t, b, r, l] @@ -197,6 +191,11 @@ impl<'a> Widget for Buttons<'a> { state.ids.bag_text, ); } + let invs = self.client.inventories(); + let inventory = match invs.get(self.client.entity()) { + Some(inv) => inv, + None => return None, + }; if !self.show_bag { let space_used = inventory.populated_slots(); let space_max = inventory.slots().count(); @@ -357,6 +356,7 @@ impl<'a> Widget for Buttons<'a> { } // Unspent SP indicator if unspent_sp { + let arrow_ani = (self.pulse * 4.0/* speed factor */).cos() * 0.5 + 0.8; //Animation timer Image::new(self.imgs.sp_indicator_arrow) .w_h(20.0, 11.0) .graphics_for(state.ids.spellbook_button) From 323e3166f5d279085c2d300f937cba64e920bde4 Mon Sep 17 00:00:00 2001 From: "Dr. Dystopia" Date: Sun, 1 Aug 2021 22:43:41 +0200 Subject: [PATCH 2/3] Create 'animation' file --- voxygen/src/hud/animation.rs | 3 +++ voxygen/src/hud/buffs.rs | 4 ++-- voxygen/src/hud/buttons.rs | 3 ++- voxygen/src/hud/mod.rs | 1 + 4 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 voxygen/src/hud/animation.rs diff --git a/voxygen/src/hud/animation.rs b/voxygen/src/hud/animation.rs new file mode 100644 index 0000000000..ec6a141f3e --- /dev/null +++ b/voxygen/src/hud/animation.rs @@ -0,0 +1,3 @@ +pub fn animation_timer(pulse: f32) -> f32 { + (pulse * 4.0/* speed factor */).cos() * 0.5 + 0.8 //y=0.5cos(4x)+0.8 +} diff --git a/voxygen/src/hud/buffs.rs b/voxygen/src/hud/buffs.rs index da63a601c3..2c3ca35b06 100644 --- a/voxygen/src/hud/buffs.rs +++ b/voxygen/src/hud/buffs.rs @@ -3,7 +3,7 @@ use super::{ BUFF_COLOR, DEBUFF_COLOR, TEXT_COLOR, }; use crate::{ - hud::{self, BuffPosition}, + hud::{self, animation::animation_timer, BuffPosition}, ui::{fonts::Fonts, ImageFrame, Tooltip, TooltipManager, Tooltipable}, GlobalState, }; @@ -104,7 +104,7 @@ impl<'a> Widget for BuffsBar<'a> { let mut event = Vec::new(); let localized_strings = self.localized_strings; let buffs = self.buffs; - let buff_ani = ((self.pulse * 4.0/* speed factor */).cos() * 0.5 + 0.8) + 0.5; //Animation timer + let buff_ani = animation_timer(self.pulse) + 0.5; //Animation timer let pulsating_col = Color::Rgba(1.0, 1.0, 1.0, buff_ani); let norm_col = Color::Rgba(1.0, 1.0, 1.0, 1.0); let buff_position = self.global_state.settings.interface.buff_position; diff --git a/voxygen/src/hud/buttons.rs b/voxygen/src/hud/buttons.rs index 21a8b3f943..e6d2418276 100644 --- a/voxygen/src/hud/buttons.rs +++ b/voxygen/src/hud/buttons.rs @@ -4,6 +4,7 @@ use super::{ }; use crate::{ game_input::GameInput, + hud::animation::animation_timer, ui::{fonts::Fonts, ImageFrame, Tooltip, TooltipManager, Tooltipable}, window::KeyMouse, GlobalState, @@ -356,7 +357,7 @@ impl<'a> Widget for Buttons<'a> { } // Unspent SP indicator if unspent_sp { - let arrow_ani = (self.pulse * 4.0/* speed factor */).cos() * 0.5 + 0.8; //Animation timer + let arrow_ani = animation_timer(self.pulse); //Animation timer Image::new(self.imgs.sp_indicator_arrow) .w_h(20.0, 11.0) .graphics_for(state.ids.spellbook_button) diff --git a/voxygen/src/hud/mod.rs b/voxygen/src/hud/mod.rs index 5250e94d69..ff863b4018 100644 --- a/voxygen/src/hud/mod.rs +++ b/voxygen/src/hud/mod.rs @@ -1,3 +1,4 @@ +mod animation; mod bag; mod buffs; mod buttons; From e62d903041f192a2dd3afcce660d764547f0793f Mon Sep 17 00:00:00 2001 From: "Dr. Dystopia" Date: Mon, 2 Aug 2021 13:33:52 +0200 Subject: [PATCH 3/3] Add 'UpdateArgs import to 'buttons' file --- voxygen/src/hud/buttons.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/voxygen/src/hud/buttons.rs b/voxygen/src/hud/buttons.rs index e6d2418276..d91df8188c 100644 --- a/voxygen/src/hud/buttons.rs +++ b/voxygen/src/hud/buttons.rs @@ -12,7 +12,7 @@ use crate::{ use client::Client; use common::comp::{SkillSet, Stats}; use conrod_core::{ - widget::{self, Button, Image, Text}, + widget::{self, Button, Image, Text, UpdateArgs}, widget_ids, Color, Colorable, Positionable, Sizeable, UiCell, Widget, WidgetCommon, }; use i18n::Localization; @@ -124,9 +124,9 @@ impl<'a> Widget for Buttons<'a> { fn style(&self) -> Self::Style {} - fn update(self, args: widget::UpdateArgs) -> Self::Event { + fn update(self, args: UpdateArgs) -> Self::Event { common_base::prof_span!("Buttons::update"); - let widget::UpdateArgs { state, ui, .. } = args; + let UpdateArgs { state, ui, .. } = args; let localized_strings = self.localized_strings; let button_tooltip = Tooltip::new({