ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   Lua/XML Help (https://www.esoui.com/forums/forumdisplay.php?f=175)
-   -   Need help with simple function, it wont work. (https://www.esoui.com/forums/showthread.php?t=1478)

deathangel1479 05/12/14 10:56 AM

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

Roupine 05/12/14 11:06 AM

Have you tried:
Code:

if not WINDOW_MANAGER:GetControlByName("RMM_MAPS_"..iX..iY) then

deathangel1479 05/12/14 11:18 AM

Quote:

Originally Posted by Roupine (Post 7572)
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

Harven 05/12/14 11:36 AM

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>


deathangel1479 05/12/14 12:06 PM

Quote:

Originally Posted by Harven (Post 7575)
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... :confused: 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.

Roupine 05/12/14 12:08 PM

Quote:

Originally Posted by deathangel1479 (Post 7573)
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

deathangel1479 05/12/14 12:31 PM

Quote:

Originally Posted by Roupine (Post 7583)
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?


All times are GMT -6. The time now is 09:32 AM.

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