Thread Tools Display Modes
08/18/14, 01:28 AM   #1
Dero
 
Dero's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2014
Posts: 14
SCENE_MANAGER problems

Hi guys, ive got some Problems with the SCENE_MANAGER.
Im adding Stuff to the SCENE_MANAGER like this:

Code:
tlw = WINDOW_MANAGER:CreateTopLevelWindow("tlw")

zo_callLater(function() addon.AddUiFragment(tlw) end,4000)

function addon.AddUiFragment(Newfragment)
	local HideFragment = Newfragment:IsHidden()
	local Hud = SCENE_MANAGER:GetScene("hud")
	local HudUI = SCENE_MANAGER:GetScene("hudui")
	local fragment = ZO_SimpleSceneFragment:New(Newfragment)
	Hud:AddFragment(fragment)
	HudUI:AddFragment(fragment)
	Newfragment:SetHidden(HideFragment)
end
The Problem is, that when i open for example the MAP, and then go back to the MainUI the TopLevelWindow i added to the SCENE_MANAGER loses its visible status and is always visible (also if it was hidden before opening the map). Since the SCENE_MANAGER has almost no documentation i hope that someone of you guys already worked a little bit with it and can help with this issue.
  Reply With Quote
08/18/14, 04:15 AM   #2
merlight
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 671
Another edit: I got it wrong

Untested, not sure it does what you want:
Lua Code:
  1. local g_tlwHiddenInMainUI = true
  2.  
  3. -- then in your fragment construction:
  4.  
  5. fragment:RegisterCallback("StateChange", function(oldState, newState)
  6.   if newState == SCENE_FRAGMENT_SHOWING then
  7.     tlw:SetHidden(g_tlwHiddenInMainUI)
  8.   elseif newState == SCENE_FRAGMENT_HIDDEN then
  9.     g_tlwHiddenInMainUI = tlw:IsHidden()
  10.     tlw:SetHidden(true)
  11.   end
  12. end)

Last edited by merlight : 08/18/14 at 04:20 AM. Reason: fixed typos
  Reply With Quote
08/18/14, 04:21 AM   #3
merlight
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 671
Sorry for making a million edits, I got it completely reversed in my head. Hope it helps a bit.
  Reply With Quote
08/18/14, 06:10 AM   #4
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 832
If you add scene fragment to the scene, it means that fragment should be visible when scene is shown. So, I'd say it's working as intended.

But I think you want to set conditional to your fragment:
Lua Code:
  1. local tlw = WINDOW_MANAGER:CreateTopLevelWindow("tlw")
  2. local hidden = true
  3.  
  4. zo_callLater(function() addon.AddUiFragment(tlw) end,4000)
  5.  
  6. function addon.AddUiFragment(control)
  7.     local fragment = ZO_SimpleSceneFragment:New(tlw)
  8.     fragment:SetConditional(function() return hidden end)
  9.     HUD_SCENE:AddFragment(fragment)
  10.     HUD_UI_SCENE:AddFragment(fragment)
  11. end

Another method would be adding or removing scene fragment.
  Reply With Quote
08/18/14, 06:28 AM   #5
circonian
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 613
Originally Posted by Dero View Post
The Problem is, that when i open for example the MAP, and then go back to the MainUI the TopLevelWindow i added to the SCENE_MANAGER loses its visible status and is always visible (also if it was hidden before opening the map). Since the SCENE_MANAGER has almost no documentation i hope that someone of you guys already worked a little bit with it and can help with this issue.

The code looks fine & works fine for me. I don't understand though you said:
"It loses its visibility status" AND "Is always visible" (did you just mean the visibility changes & is always visible on the main UI)?

Either way it is supposed to always be visible when your on the mainUI thats the scene you added your tlc to.
If you were trying to do the opposite (make it only visible with the map) that is the worldMap scene and you only want to add it to this one:
Lua Code:
  1. local sceneWorldMap = SCENE_MANAGER:GetScene("worldMap")
  Reply With Quote
08/18/14, 10:20 AM   #6
Dero
 
Dero's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2014
Posts: 14
What i wanted to do is Adding something to the HUD_SCENE and HUD_UI_SCENE.
But within this i wanted the option to set it Hidden, when the user decides to hide it.
this works at the first Moment with a simple control:SetHidden(true) but then after opening a map or another SCENE, the window will pop up if i go back to the HUD_SCENE or HUD_UI_SCENE no matter if it was hidden before or not. (that was ment with losing visible status)
i think i misunderstood the way the SCENE_MANAGER works.

Originally Posted by Garkin
If you add scene fragment to the scene, it means that fragment should be visible when scene is shown.
Thats the point. I thought you just attach them to the scene and can handle them like you want. But this only works within this "SCENE-Session".
I think ill use the way to attach them when they should be visible and remove them when they should be hidden.

Edit:
Okay, i did it now that way and i works really well
Lua Code:
  1. --function to show / hide tlw
  2. function AddOn.ShowHide()
  3.     if(tlw:IsHidden() == true)then
  4.         AddedFrag = AddOn.AddUiFragment(tlw)
  5.     else
  6.         AddOn.RemUiFragment(AddedFrag)
  7.     end
  8. end
  9.  
  10. --function to Add Toplevelwindows to HUD Scene to Hide if another SCENE opens
  11. function AddOn.AddUiFragment(NewFragment)
  12.     local Hud = SCENE_MANAGER:GetScene("hud")
  13.     local HudUI = SCENE_MANAGER:GetScene("hudui")
  14.     local fragment = ZO_SimpleSceneFragment:New(NewFragment)
  15.     Hud:AddFragment(fragment)
  16.     HudUI:AddFragment(fragment)
  17.     return fragment
  18. end
  19.  
  20. --function to Remove Toplevelwindows from HUD Scene
  21. function AddOn.RemUiFragment(OldFragment)
  22.     local Hud = SCENE_MANAGER:GetScene("hud")
  23.     local HudUI = SCENE_MANAGER:GetScene("hudui")
  24.     Hud:RemoveFragment(OldFragment)
  25.     HudUI:RemoveFragment(OldFragment)
  26. end

Last edited by Dero : 08/18/14 at 11:17 AM.
  Reply With Quote
08/18/14, 11:13 AM   #7
merlight
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 671
I think I get it now. The fragment shows the top-level control when it's shown, regardless of its visibility when the fragment was previously hidden. So I think you basically have two options:
1) RegisterCallback("StateChange", ... like I posted earlier, and show/hide the control based on an outer variable that will remember whether it should be visible in main scene.
2) Make the control you want to hide a child of the top-level control. The fragment only shows the top-level control. If you have other controls in it, they retain whatever value you gave their SetHidden.
  Reply With Quote
08/18/14, 04:24 PM   #8
circonian
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 613
Originally Posted by Dero View Post
What i wanted to do is Adding something to the HUD_SCENE and HUD_UI_SCENE.
But within this i wanted the option to set it Hidden, when the user decides to hide it.
this works at the first Moment with a simple control:SetHidden(true) but then after opening a map or another SCENE, the window will pop up if i go back to the HUD_SCENE or HUD_UI_SCENE no matter if it was hidden before or not. (that was ment with losing visible status)
i think i misunderstood the way the SCENE_MANAGER works.
I get it now. You want it to only be visible in that scene but still have the option to force it to stay hidden...or not.
You can set conditions to whether or not the fragment gets shown with a scene. You have to keep track of the state you want it to be in. You can just store it in a variable (as true or false) whenever the user pushes your show/hide button. Lets say the variable that holds that information is this:
Lua Code:
  1. myAddon.ShowWindow = false

Then add this line to your code:
Lua Code:
  1. tlw = WINDOW_MANAGER:CreateTopLevelWindow("tlw")
  2.  
  3. zo_callLater(function() addon.AddUiFragment(tlw) end,4000)
  4.  
  5. function addon.AddUiFragment(Newfragment)
  6.     local HideFragment = Newfragment:IsHidden()
  7.     local Hud = SCENE_MANAGER:GetScene("hud")
  8.     local HudUI = SCENE_MANAGER:GetScene("hudui")
  9.     local fragment = ZO_SimpleSceneFragment:New(Newfragment)
  10.     Hud:AddFragment(fragment)
  11.     HudUI:AddFragment(fragment)
  12.     Newfragment:SetHidden(HideFragment)
  13.  
  14. ------------  Add this  -----------------------------
  15.     Newfragment:SetConditional(function()
  16.         return myAddon.ShowWindow
  17.     end)
  18. -----------------------------------------------------
  19. end

Last edited by circonian : 08/18/14 at 04:29 PM.
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » SCENE_MANAGER problems


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