VernonKun

StaminaUIFix

Jan 17th, 2021 (edited)
752
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local mod_name = "StaminaUIFix"
  2.  
  3. -- Probably this isn't the cause of the bug, but OCD happens
  4. Mods.hook.set(mod_name, "FatigueUI.shield_state", function(func, self, shield_number, living_shields)
  5.     local leftover = living_shields - shield_number
  6.  
  7.     if leftover >= 0 then
  8.         return "state_1"        -- full shield
  9. --edit--vv
  10.     -- elseif leftover == -0.5 then
  11.     elseif leftover >= -0.5 then
  12.         return "state_2"        -- half shield
  13.     else
  14.         return "state_3"        -- no shield
  15.     end
  16. end)
  17.  
  18. Mods.hook.set(mod_name, "FatigueUI.update_shields", function(func, self, status_extension, dt)
  19.     local current_fatigue = self.current_fatigue
  20.     local fatigue_points, max_fatigue_points = status_extension:current_fatigue_points()
  21.  
  22.     if max_fatigue_points ~= self.max_fatigue_points then
  23.         self:setup_hud(status_extension)
  24.     end
  25.  
  26.     if fatigue_points == current_fatigue then
  27.         return
  28.     end
  29.  
  30.     local living_shields = max_fatigue_points * 0.5 - fatigue_points * 0.5
  31.     local active_shields = self.active_shields
  32.     local shields = self.shields
  33.  
  34.     for i = 1, active_shields, 1 do
  35.         local shield = shields[i]
  36.         local style = shield.style
  37.         local current_state = shield.state
  38.         local new_state = self:shield_state(i, living_shields)
  39. --edit--
  40.         -- if current_state ~= new_state then
  41.             -- local state_animations = style.state_animations[current_state]
  42.  
  43.             -- if state_animations and state_animations[new_state] then
  44.                 -- local animation_data = state_animations[new_state]
  45.  
  46.                 -- UIWidget.animate(shield, UIAnimation.init(UIAnimation.picture_sequence, shield.content, "texture_id", animation_data.pictures, animation_data.time))
  47.             -- else
  48.                 -- shield.content.texture_id = style.state_textures[new_state]
  49.             -- end
  50.         -- end
  51.         local state_animations = style.state_animations[current_state]
  52.  
  53.         if state_animations and state_animations[new_state] then
  54.             local animation_data = state_animations[new_state]
  55.            
  56.             -- Below is basically what UIWidget.animate does
  57.             shield.break_animation = UIAnimation.init(UIAnimation.picture_sequence, shield.content, "texture_id", animation_data.pictures, animation_data.time)
  58.             shield.animations[shield.break_animation] = true
  59.            
  60.             -- EchoConsole(shield.break_animation)
  61.         else
  62.             if new_state ~= "state_3" and shield.animations[shield.break_animation] then
  63.                 -- EchoConsole(shield.break_animation)
  64.                
  65.                 shield.animations[shield.break_animation] = nil
  66.             end
  67.            
  68.             shield.content.texture_id = style.state_textures[new_state]
  69.         end
  70. --edit--
  71.         shield.state = new_state
  72.     end
  73.  
  74.     self.current_fatigue = fatigue_points
  75. end)
  76.  
RAW Paste Data