ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   Lua/XML Help (https://www.esoui.com/forums/forumdisplay.php?f=175)
-   -   Scene Manager and the Hidden Attribute (https://www.esoui.com/forums/showthread.php?t=4207)

EmberQuill 01/15/15 02:02 PM

Scene Manager and the Hidden Attribute
 
So I understand (more or less) how the Scene Manager works. I know how to get it to show and hide a control based on what scene is open. The thing is, I want a control's visibility to also depend on whether the player is in a guild.

I know how to handle the conditional stuff and detecting when a player joins or leaves a guild; I'm just wondering how I would go about keeping the control hidden. As far as I can tell, there are three possibilities:
  1. SetHidden(true)
  2. Remove the fragment from all of its scenes
  3. Both?
I'd like to know which one has priority: SetHidden or the scene manager. If I manually hide it, will the Scene Manager make it visible again if I switch scenes? If I remove it from all of its scenes, will it be shown or hidden by default?

AFAIK using both would work, but I was wondering if a simpler solution would be enough.

ZOS_ChipHilseberg 01/15/15 02:47 PM

Scene fragments have a method called SetConditional which lets you add a callback that is evaluated whenever the fragment is refreshed. If the callback returns false the fragment is hidden. If it returns true whether it's shown is based on if it's part of a scene that is showing. So you could write a function that returns if the player is in a guild and pass that to SetConditional on the fragment. Then you just call Refresh on the fragment whenever it would change (when the player joins or leaves a guild).

Garkin 01/15/15 03:17 PM

I really like ZO_HUDFadeSceneFragment's hidden reasons (ZO_HiddenReasons).

Lua Code:
  1. local ADDON_NAME = "someUniquieName"
  2.  
  3. local function OnLoaded(evt, name)
  4.     if name:find("^ZO_") then return end
  5.     EVENT_MANAGER:UnregisterForEvent(ADDON_NAME, evt)
  6.  
  7.     local tlw, texture, fragment
  8.     tlw = WINDOW_MANAGER:CreateTopLevelWindow()
  9.     tlw:SetDimensions(128,128)
  10.     tlw:SetAnchor(CENTER, GuiRoot, CENTER, 0, 0)
  11.     tlw:SetHidden(true)
  12.     texture = WINDOW_MANAGER:CreateControl(nil, tlw, CT_TEXTURE)
  13.     texture:SetTexture("esoui/art/icons/poi/poi_groupboss_complete.dds")
  14.     texture:SetAnchorFill(tlw)
  15.  
  16.     fragment = ZO_HUDFadeSceneFragment:New(tlw)
  17.  
  18.     HUD_SCENE:AddFragment(fragment)
  19.     HUD_UI_SCENE:AddFragment(fragment)
  20.  
  21.     --this part does all the work
  22.     local function UpdateHidden()
  23.         fragment:SetHiddenForReason("notInGuild", GetNumGuilds() == 0)
  24.     end
  25.  
  26.     tlw:RegisterForEvent(EVENT_GUILD_SELF_JOINED_GUILD, UpdateHidden)
  27.     tlw:RegisterForEvent(EVENT_GUILD_SELF_LEFT_GUILD, UpdateHidden)
  28. end
  29.  
  30. EVENT_MANAGER:RegisterForEvent(ADDON_NAME, EVENT_ADDON_LOADED, OnLoaded)

But this method has just ZO_HUDFadeSceneFragment, if you use any other scene fragment, you should use SetConditional as ZOS_ChipHilseberg said:

Lua Code:
  1. --the same code as above
  2.     fragment:SetConditional(function() return GetNumGuilds() > 0 end)
  3.  
  4.     tlw:RegisterForEvent(EVENT_GUILD_SELF_JOINED_GUILD, function() fragment:Refresh() end)
  5.     tlw:RegisterForEvent(EVENT_GUILD_SELF_LEFT_GUILD, function() fragment:Refresh() end)
  6. --

EmberQuill 01/15/15 03:59 PM

Since I'm just using a ZO_SimpleSceneFragment, I'll go with the SetConditional method. Thanks for the quick answers!


All times are GMT -6. The time now is 08:20 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI