Quantcast
Need help with simple function, it wont work. - ESOUI
Thread Tools Display Modes
05/12/14, 10:56 AM   #1
deathangel1479
 
deathangel1479's Avatar
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 6
Need help with simple function, it wont work.

Because Controls cant removed, i want to reuse them and if need more add them.

This is my function, it dont work, what ever I try.

Code:
function RMM.CreateControl(iY,iX)
	if not RMM.c.map:GetNamedChild("RMM_MAPS_"..iX..iY) then
		RMM.maps[iY][iX] = WINDOW_MANAGER:CreateControl("RMM_MAPS_"..iX..iY, RMM.c.map, CT_TEXTURE)
	end
end
if not RMM.c.map:GetNamedChild("RMM_MAPS_"..iX..iY) <--- everytime true

RMM.c.map is a CT_CONTROLk, wrong type?

I have also tryed:
if not RMM.maps[iY][iX] then <--- everytime false

And a lot other with: ==nil, ~=nil then return ........

Last edited by deathangel1479 : 05/12/14 at 11:46 AM.
  Reply With Quote
05/12/14, 11:06 AM   #2
Roupine
Join Date: May 2014
Posts: 18
Have you tried:
Code:
if not WINDOW_MANAGER:GetControlByName("RMM_MAPS_"..iX..iY) then
  Reply With Quote
05/12/14, 11:18 AM   #3
deathangel1479
 
deathangel1479's Avatar
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 6
Originally Posted by Roupine View Post
Have you tried:
Code:
if not WINDOW_MANAGER:GetControlByName("RMM_MAPS_"..iX..iY) then
I think i have tryed this yesterday without result, but I will try again. Thanks for Reply.

......

if not WINDOW_MANAGER:GetControlByName("RMM_MAPS_"..iX..iY) then <--- function expected instead of nil

Last edited by deathangel1479 : 05/12/14 at 11:30 AM.
  Reply With Quote
05/12/14, 11:36 AM   #4
Harven
 
Harven's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 137
Hey, there is a mechanism for this kind of situations. It's called control pool. You take a control from the pool and when it's no longer needed you just put it back to the pool. Here is an example:

Lua Code:
  1. --first you have to have some parent control
  2. local parentControl = WINDOW_MANAGER:CreateTopLevelWindow("MyParentControl")
  3. --[[
  4. here you create the control pool.
  5. - the first argument is a control template which must be defined in XML file
  6. - the second argument is your parent control
  7. - the third argument is just some name you like
  8. --]]
  9. local myControlPool = ZO_ControlPool:New("MyLabelControlTemplate", parentControl, "SomeName")
  10.  
  11. --then when you want to get a control from the pool you just call:
  12. local myControl, controlKey = myControlPool:AcquireObject()
  13. --controlKey is a key that allows you to put the control back to the pool
  14.  
  15. --you can then do whatever you like with the control, for example attach it to your parent control:
  16. myControl:SetAnchor(CENTER, parentControl, CENTER)
  17.  
  18. --when you no longer need the control, just call"
  19. myControlPool:ReleaseObject(controlKey)
  20. --the control will be hidden automatically, then you can just forget about this control
  21. myControl = nil
  22. controlKey = nil

Here an example XML to define you control template:

Code:
<GuiXml>
	<Controls>
                <!-- It's important to set "virtual" attribute to "true" -->
		<Label name="MyLabelControlTemplate" font="ZoFontGame" virtual="true" />
	</Controls>
</GuiXml>
  Reply With Quote
05/12/14, 12:06 PM   #5
deathangel1479
 
deathangel1479's Avatar
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 6
Originally Posted by Harven View Post
Hey, there is a mechanism for this kind of situations. It's called control pool. You take a control from the pool and when it's no longer needed you just put it back to the pool. Here is an example:

Lua Code:
  1. --first you have to have some parent control
  2. local parentControl = WINDOW_MANAGER:CreateTopLevelWindow("MyParentControl")
  3. --[[
  4. here you create the control pool.
  5. - the first argument is a control template which must be defined in XML file
  6. - the second argument is your parent control
  7. - the third argument is just some name you like
  8. --]]
  9. local myControlPool = ZO_ControlPool:New("MyLabelControlTemplate", parentControl, "SomeName")
  10.  
  11. --then when you want to get a control from the pool you just call:
  12. local myControl, controlKey = myControlPool:AcquireObject()
  13. --controlKey is a key that allows you to put the control back to the pool
  14.  
  15. --you can then do whatever you like with the control, for example attach it to your parent control:
  16. myControl:SetAnchor(CENTER, parentControl, CENTER)
  17.  
  18. --when you no longer need the control, just call"
  19. myControlPool:ReleaseObject(controlKey)
  20. --the control will be hidden automatically, then you can just forget about this control
  21. myControl = nil
  22. controlKey = nil

Here an example XML to define you control template:

Code:
<GuiXml>
	<Controls>
                <!-- It's important to set "virtual" attribute to "true" -->
		<Label name="MyLabelControlTemplate" font="ZoFontGame" virtual="true" />
	</Controls>
</GuiXml>
dont know how i can intigrate this in my code... And I dont use xml...
But thanks, if no one knows how I can check the exist of my texture, I will try.
I think it must be possible, to check whether the texture exist.

Last edited by deathangel1479 : 05/12/14 at 12:10 PM.
  Reply With Quote
05/12/14, 12:08 PM   #6
Roupine
Join Date: May 2014
Posts: 18
Originally Posted by deathangel1479 View Post
I think i have tryed this yesterday without result, but I will try again. Thanks for Reply.

......

if not WINDOW_MANAGER:GetControlByName("RMM_MAPS_"..iX..iY) then <--- function expected instead of nil
Have you redefined WINDOW_MANAGER somewhere? If WINDOW_MANAGER:GetControlByName() doesn't work, neither should WINDOW_MANAGER:CreateControl()

It's weird that this wouldn't work for you-- I use this all the time:
Lua Code:
  1. tlw = WINDOW_MANAGER:GetControlByName("MODUI_TLW")
  2. if(not tlw) then -- GetControlByName() returns nil if Control does not exist
  3.   tlw = WINDOW_MANAGER:CreateControl("MODUI_TLW", GuiRoot, CT_TOPLEVEL)
  4. end
  Reply With Quote
05/12/14, 12:31 PM   #7
deathangel1479
 
deathangel1479's Avatar
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 6
Originally Posted by Roupine View Post
Have you redefined WINDOW_MANAGER somewhere? If WINDOW_MANAGER:GetControlByName() doesn't work, neither should WINDOW_MANAGER:CreateControl()

It's weird that this wouldn't work for you-- I use this all the time:
Lua Code:
  1. tlw = WINDOW_MANAGER:GetControlByName("MODUI_TLW")
  2. if(not tlw) then -- GetControlByName() returns nil if Control does not exist
  3.   tlw = WINDOW_MANAGER:CreateControl("MODUI_TLW", GuiRoot, CT_TOPLEVEL)
  4. end
Dont think so.

Code:
function RMM.CreateUI()

	--main
	RMM.c = WINDOW_MANAGER:CreateTopLevelWindow("RMM_root")
    RMM.c:SetDimensions(256,256)
    RMM.c:SetAnchor(TOPLEFT,GuiRoot,TOPLEFT,100,100)
    RMM.c:SetHidden(false)
    RMM.c:SetMovable(true)
    RMM.c:SetMouseEnabled(true)
    RMM.c:SetClampedToScreen(true)

--overlay
    RMM.c.overlay = WINDOW_MANAGER:CreateControl("RMM_overlay", RMM.c, CT_TEXTURE)
	RMM.c.overlay:SetTexture("RadarMiniMap/textures/rad.dds")
    RMM.c.overlay:SetAnchorFill(RMM.c)	
	RMM.c.overlay:SetDrawLayer(3)
	
	--nord
	RMM.c.nord = WINDOW_MANAGER:CreateControl("RMM_nord", RMM.c, CT_TEXTURE)
	RMM.c.nord:SetTexture("RadarMiniMap/textures/nor.dds")
    RMM.c.nord:SetAnchorFill(RMM.c)	
	RMM.c.nord:SetDrawLayer(4)
	
    --scroll
    RMM.c.sc = WINDOW_MANAGER:CreateControl("RMM_scroll", RMM.c, CT_SCROLL)
    RMM.c.sc:SetAnchorFill(RMM.c)

    --map
	RMM.c.map = WINDOW_MANAGER:CreateControl("RMM_map", RMM.c, CT_CONTROL)
	RMM.c.map:SetAnchor(TOPLEFT, RMM.c, TOPLEFT, 0,0)
	
end
There is a opposit between our code:
Code:
WINDOW_MANAGER:CreateControl("MODUI_TLW", GuiRoot, CT_TOPLEVEL)

WINDOW_MANAGER:CreateTopLevelWindow("RMM_root")
Is that the problem?

Last edited by deathangel1479 : 05/12/14 at 12:39 PM.
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » Need help with simple function, it wont work.

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