View Single Post
06/21/17, 11:34 AM   #2
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,578
In most cases you shouldn't actually add elements in response to an event, but instead create a scenefragment and assign it to a scene.
For example the guild home menu is a scene. The buttons on top (home, roster, history, etc) are one fragment which is added to the guild home scene.
A fragment is basically just a wrapper around a control and can be added to any number of scenes. When a scene shows up, it will automatically make all its fragments visible.

The scene you are looking for is called GUILD_HOME_SCENE. For most cases you can just create a ZO_SimpleSceneFragment.

Lua Code:
  1. local fragment = ZO_SimpleSceneFragment:New(myControl)
  2. GUILD_HOME_SCENE:AddFragment(myControl)

Of course you need to set your anchors as required. If you reuse a fragment on different scenes and want to position it relative to different elements, you can listen to a scene's "StateChange" callback:

Lua Code:
  1. GUILD_HOME_SCENE:RegisterCallback("StateChange", function(oldState, newState)
  2.     myControl:ClearAnchors()
  3.     if(GUILD_HOME_SCENE:IsShowing()) then
  4.         myControl:SetAnchor(...) -- configuration a
  5.     else
  6.         myControl:SetAnchor(...) -- configuration b
  7.     end
  8. end)

Otherwise you could just set them once when you first create the fragment.
  Reply With Quote