Thread Tools Display Modes
01/15/15, 02:02 PM   #1
EmberQuill
 
EmberQuill's Avatar
Join Date: Jan 2015
Posts: 4
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.
  Reply With Quote
01/15/15, 02:47 PM   #2
ZOS_ChipHilseberg
ZOS Staff!
Premium Member
Yes this person is from ZeniMax!
Join Date: Oct 2014
Posts: 551
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).
  Reply With Quote
01/15/15, 03:17 PM   #3
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 832
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. --
  Reply With Quote
01/15/15, 03:59 PM   #4
EmberQuill
 
EmberQuill's Avatar
Join Date: Jan 2015
Posts: 4
Since I'm just using a ZO_SimpleSceneFragment, I'll go with the SetConditional method. Thanks for the quick answers!
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » Scene Manager and the Hidden Attribute


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off