ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   General Authoring Discussion (https://www.esoui.com/forums/forumdisplay.php?f=174)
-   -   GUI: treat fragment as overlay and lose focus onClose (https://www.esoui.com/forums/showthread.php?t=8423)

Supportic 03/22/19 06:55 AM

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 :D) 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. :D
Thanks in advance. :)

Baertram 03/22/19 12:50 PM

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.

Supportic 03/22/19 03:32 PM

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())

Baertram 03/22/19 05:05 PM

Oh thanks for ZO_SceneManager_ToggleHUDUIBinding(), did forget about this one :)

Supportic 03/23/19 09:02 AM

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. :confused:

Baertram 03/23/19 05:03 PM

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.

Supportic 03/24/19 04:08 PM

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. :mad:

Baertram 03/24/19 07:13 PM

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.

Supportic 03/25/19 09:35 AM

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.

Kyoma 03/25/19 09:51 AM

Quote:

Originally Posted by Supportic (Post 37563)
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

Supportic 03/25/19 12:33 PM

Quote:

Originally Posted by Kyoma (Post 37564)
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)


All times are GMT -6. The time now is 03:22 AM.

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