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:
local staminaPercent = 0.8
local function OnBlurFragmentStateChange(oldState, newState)
if newState == SCENE_FRAGMENT_SHOWN then
if staminaPercent <= 0.9 then -- at 90% stamina, begin to blur the screen
BlurUI:SetAlpha((1.0 / 0.9) * (0.9 - staminaPercent))
else
BlurUI:SetAlpha(0)
end
elseif newState == SCENE_FRAGMENT_HIDDEN then
BlurUI:SetAlpha(0)
end
end
local blurFragment = ZO_SceneFragment:New("BlurUI") -- or ZO_HUDFadeSceneFragment:New("BlurUI", nil, 0)
HUD_SCENE:AddFragment(blurFragment)
--HUD_UI_SCENE:AddFragment(blurFragment)
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.