Thread Tools Display Modes
Prev Previous Post   Next Post Next
04/03/23, 10:03 AM   #1
Kismalyn
Join Date: Mar 2023
Posts: 4
conditoinally show a scene fragment

hi hive-dev-mind.

I have an addon that I need to show, via an on/off toggle conditionally. I can't get the fragment to stay hidden, after first enabling it, and then disabling it.

I saw this post and tried the following:

Code:
        fragment:SetConditional(function() 
		return settings.activeWindow
	end)
but it doesn't work, I still get the fragment showing even with the activeWindow var is false.

Ive also tried conditional code in a conventional callback, like this:

Code:
function Ui:ShowHideTLC(makeVis)
	local sceneHUD = SCENE_MANAGER:GetScene("hud")
	local sceneUI = SCENE_MANAGER:GetScene("hudui")
	local TLC = AddOnWindow
	local tlcFragment = ZO_SimpleSceneFragment:New(TLC)
	
        TLC:SetHidden(not makeVis)

	if (makeVis == true and settings.activeWindow == true) then
		sceneHUD:AddFragment(tlcFragment)
		sceneUI:AddFragment(tlcFragment)
	else
		sceneHUD:RemoveFragment(tlcFragment)
		sceneUI:RemoveFragment(tlcFragment)
	end
end

local function tlcFragmentChange(oldState, newState)
	if (newState == SCENE_FRAGMENT_SHOWN) then
		self:ShowHideTLC(true)
	elseif (newState == SCENE_FRAGMENT_HIDDEN) then
		self:ShowHideTLC(false)
	end
end

-- this is bound to a key
function Ui:ToggleShow()
	settings.activeWindow = not settings.activeWindow
	self:ShowHideTLC(settings.activeWindow)
end

-- this is in the init function
local tlcFragment = ZO_SimpleSceneFragment:New(AddOnWindow)
tlcFragment:RegisterCallback("StateChange", tlcFragmentChange)
I almost get the behaviour I want with this, except that once Ive toggled the addon visible, it will always appear on the HUD, even if I retoggle it off again (if that makes sense)

I have a feeling Im overcomplicating it, as I tend to do, but I cant figure it out. I'm new to Lua, let alone ESOUI.

Thanks!

Last edited by Kismalyn : 04/03/23 at 10:09 AM.
  Reply With Quote
 

ESOUI » Developer Discussions » General Authoring Discussion » conditoinally show a scene fragment


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