Quantcast GUI: treat fragment as overlay and lose focus onClose - ESOUI
Thread Tools Display Modes
03/22/19, 06:55 AM   #1
Supportic
Join Date: Mar 2019
Posts: 24
GUI: treat fragment as overlay and lose focus onClose

Hey I've been following this tutorial https://wiki.esoui.com/SimpleNotebookTutorial/part6 and prepared the following code:

Lua Code:
  1. local UAN = UniqueAddonName
  2. local window = BoxWindow -- name of the XML TopLevelControl element
  3. local SM = SCENE_MANAGER
  4.  
  5. function UAN.ToogleBox()
  6.   -- just toggles the window
  7.   window:SetHidden(not window:IsHidden())
  8.   -- UI work
  9.   local fragment = ZO_SimpleSceneFragment:New(window)
  10.   local scene = ZO_Scene:New(UAN.name, SM)
  11.   scene:AddFragment(fragment)
  12.   SM:Toggle(UAN.name)
  13. end

The ToogleBox() function is bound to a key and can be closed via a $(parent)BtnClose Button inside the box or via a keybind.

Currently when I toggle the box, everything from the UI will hide except my box and my mouse. Pressing
the key or closing the box via the BtnClose button will hide my mouse and get my UI back.

Goal:
Toggle the box so that the box is acting like a overlay to my current base UI. (without a mouse icon)
By enabling the "mouse icon drag mode" (I don't know the name of this mode ) I should be able to close the box via the button or the keybind. After closing it, the mouse should disappear and my base UI should be brought to the top again.

I hope this is kind of understandable.
Thanks in advance.
  Reply With Quote
03/22/19, 12:50 PM   #2
Baertram
 
Baertram's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 2,493
Do NOT put the fragment creation code into your toggle function or you will create a new fragment each time you press the keybind.
Just remove this from the function and put it below local sm = SCENE_MANAGER

local fragment = ZO_SimpleSceneFragment:New(window)
local scene = ZO_Scene:New(UAN.name, SM)
scene:AddFragment(fragment)

This will only create the fragment once.


Not sure why you need to define a new scene on your own.
local scene = ZO_Scene:New(UAN.name, SM)

Isn't it enough to use the existing HUD or HUD_UI scene?
Here is an example for a TOPLEVELCONTROL (your boxwindow control) added to a fragment which automatically hides with the UI (if inventory is shown e.g.) or shows with the UI (if inv., is closed e.g)

https://wiki.esoui.com/Scene_Manager:_On_scene_change

If you want to show the box control or hide it manually without the fragment taking care of it, you need to use SetHidden(true/false) on your toplevelcontrol as the toggle function is called.
But it will also added (in my example above) to the fragment of the hud_Scene and thus be shown/hidden with the HUD_SCENE through the base game.

Last edited by Baertram : 03/22/19 at 12:56 PM.
  Reply With Quote
03/22/19, 03:32 PM   #3
Supportic
Join Date: Mar 2019
Posts: 24
Thank you for your reply.

This is not what I really wanted but I solved it now with the following code:

Lua Code:
  1. local UAN = UniqueAddonName
  2. local SM = SCENE_MANAGER
  3.  
  4. function UAN.ToogleToolbox()
  5.   local window = MyBox
  6.  
  7.   -- toogles the window
  8.   window:SetHidden(not window:IsHidden())
  9.  
  10.   -- hide the scene "hudui" when the BtnClose is pressed in the "hudui" scene
  11.   if window:IsHidden() and SM:GetCurrentScene():GetName() == "hudui" then
  12.     ZO_SceneManager_ToggleHUDUIBinding()
  13.   end
  14. end

My problem was that the scene "hudui" would stay active when I closed the box via a button. When I close the box I expect to go back to the "hud" scene that's why I need to toggle the "hudui" scene to the "hud" scene.

Ingame you can observe the current scene with this command:
Lua Code:
  1. /script d(SCENE_MANAGER:GetCurrentScene():GetName())
  Reply With Quote
03/22/19, 05:05 PM   #4
Baertram
 
Baertram's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 2,493
Oh thanks for ZO_SceneManager_ToggleHUDUIBinding(), did forget about this one
  Reply With Quote
03/23/19, 09:02 AM   #5
Supportic
Join Date: Mar 2019
Posts: 24
There is still one edge case where I want to close my window and another UI from another addon is active at the same time which will just close because of the toggle.

Need to figure out how I can get the number of all active fragments? in a scene and if there are more than two, just close only my own window.

I don't even know what type my GUI is, which is defined in my XML file. It must be a kind of control or fragment.
  Reply With Quote
03/23/19, 05:03 PM   #6
Baertram
 
Baertram's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 2,493
If you know the other addon's name add it to your addon's manifest txt file in the tag ##OptionalDependsOn: OtherAddonFolderName

It will asure that your addon is loaded AFTER the other addon has loaded and that you are able to access the other addons global variables properly. You can also wait for event_player_activated to be fired as it will be the same in the end (all addons have loaded by this time) then (but it fires several times, at each reloadui e.g. and maybe zone changes).

Do you know the other addon? If not you need to find it out by using e.g. /ZGOO mouse in teh chat (uisng the addon ZGOO) on the control you'd like to inspect.
Or just disable the other addons and enable them 1 afer another again.

Or use a tool like Notepadd++ and the "search in files" of the tool to find addons in your AddOns directory which use the keyword scene_manager or fragment or something like the stuff you are searching for.

To get the active fragments check SCENE_MANAGER.currentScene.fragments. It should be a table containing all fragments active at the time you check it.

Last edited by Baertram : 03/23/19 at 05:06 PM.
  Reply With Quote
03/24/19, 04:08 PM   #7
Supportic
Join Date: Mar 2019
Posts: 24
It's not exactly a specific addon or has something to do with overlapping. But imagine you toogle a addon which brings up the hudui mode and the addon's GUI.

Now when I open my addon and toggle it off again the ZO_SceneManager_ToggleHUDUIBinding() will be executed and closes both addons because it toggles the whole hudui.

My current state is that maybe I have to look it up in the global table (_G) and detect other addons. They are basically children controls like my addon but there are over 400 other controls.
  Reply With Quote
03/24/19, 07:13 PM   #8
Baertram
 
Baertram's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 2,493
You maybe shouldn't use the hud toggle function then and only close your addon, or let the user decided with a settings menu (LibAddonMenu) maybe if the whole scene should be closed or only your addon top level control:SetHidden(true).

There is only on and off. If the use decides to close the scene everything is closed which is attached (including all fragments + their contmrols). This is standard and correct.
  Reply With Quote
03/25/19, 09:35 AM   #9
Supportic
Join Date: Mar 2019
Posts: 24
Yeah so after I hit the CloseBtn just the addon closes and the scene hudui will remain.

The idea originally came from AlphaGear where exactly this is possible but I cannot reproduce it.
The command in the addon was "SM:ToggleTopLevel(AG_Panel)" but it did nothing on my side and it wasn't a function written inside the addon so I thought it has to come from the ZOS API. I also have a TopLevelControl over everything just to clarify.
  Reply With Quote
03/25/19, 09:51 AM   #10
Kyoma
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 96
Originally Posted by Supportic View Post
Yeah so after I hit the CloseBtn just the addon closes and the scene hudui will remain.

The idea originally came from AlphaGear where exactly this is possible but I cannot reproduce it.
The command in the addon was "SM:ToggleTopLevel(AG_Panel)" but it did nothing on my side and it wasn't a function written inside the addon so I thought it has to come from the ZOS API. I also have a TopLevelControl over everything just to clarify.
The "SM" was probably just a local variable for SCENE_MANAGER
  Reply With Quote
03/25/19, 12:33 PM   #11
Supportic
Join Date: Mar 2019
Posts: 24
Originally Posted by Kyoma View Post
The "SM" was probably just a local variable for SCENE_MANAGER
I know, I'm talking about the function.

EDIT:
Found out that of course I had to register the window first:
SM:RegisterTopLevel(window,false)

Last edited by Supportic : 03/25/19 at 03:44 PM.
  Reply With Quote

ESOUI » Developer Discussions » General Authoring Discussion » GUI: treat fragment as overlay and lose focus onClose

Thread Tools
Display Modes

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