View Single Post
02/08/23, 10:16 AM   #5
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 5,000
If you use ZO_HUDFadeSceneFragment:New be sure to pass in all 3 paramaters espeically the last one with 0 else there might be errors on the UI because of the "fade" of the fading fragment.
I do not know what exactly was the problem here but I remember it could happen, if the value 0 is missing or does not equal 0.

Or you need to use another scenefragment type instead, like a normal ZO_SceneFragment


Lua Code:
  1. local staminaPercent = 0.8
  2.  
  3. local function OnBlurFragmentStateChange(oldState, newState)
  4.     if newState == SCENE_FRAGMENT_SHOWN then
  5.         if staminaPercent <= 0.9 then -- at 90% stamina, begin to blur the screen
  6.             BlurUI:SetAlpha((1.0 / 0.9) * (0.9 - staminaPercent))
  7.         else
  8.             BlurUI:SetAlpha(0)
  9.         end
  10.     elseif newState == SCENE_FRAGMENT_HIDDEN then
  11.         BlurUI:SetAlpha(0)
  12.     end
  13. end
  14.  
  15. local blurFragment = ZO_SceneFragment:New("BlurUI")  -- or ZO_HUDFadeSceneFragment:New("BlurUI", nil, 0)
  16.  
  17. HUD_SCENE:AddFragment(blurFragment)
  18. --HUD_UI_SCENE:AddFragment(blurFragment)
  19. blurFragment:RegisterCallback("StateChange", OnBlurFragmentStateChange)

HUD_SCENE should be enough btw to show your fragment or do you want to blur the normal inventory if opened (HUD_UI_SCENE) too?

And:
This StateChange only happens if the scene fragment is shown or hidden! So it does not update the BlurUI everytime as your stamina updates! You need to take care of that at the event where the stamina updates could be tracked with (event power update or similar).
The fragment will get to state hidden as you open another scene where the fragment was not added to, that's why only adding it to HUD_SCENE makes sense here, so if HUD_UI_SCENE is shown your not-there-added-fragment will be hidden automatically, making the SCENE_FRAGMENT_HIDDEN trigegr and BlurUI:SetAlpha(0) trigger.

Last edited by Baertram : 02/08/23 at 10:27 AM.
  Reply With Quote