ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   Lua/XML Help (https://www.esoui.com/forums/forumdisplay.php?f=175)
-   -   LAM Control setup (Iconpicker) (https://www.esoui.com/forums/showthread.php?t=7021)

Letho 05/08/17 12:23 AM

LAM Control setup (Iconpicker)
 
Hey, I ran into an issue that I don't understand. Here is the code:

Code:

        local        iconSelect = LAMCreateControl.iconpicker(parent, {
                type = "iconpicker",
                name = "",
                tooltip = "Select the aura's appearance.",
                choices = icons,
                choicesTooltips = icons,
                --sort = "name-up", --or "name-down", "numeric-up", "numeric-down" (optional) - if not provided, list will not be sorted
                getFunc = function() d(self) end,
                setFunc = AuraMastery.EditAuraIcon,
                maxColumns = 20,
                visibleRows = 10,
                iconSize = 40,
                reference = "AuraMasteryDisplayMenu_IconSelect"
        })
       
        iconSelect:SetWidth(160)
        iconSelect:ClearAnchors()
        iconSelect:SetAnchor(TOPLEFT, parent, TOPLEFT, 0, 4)

ESO shows an error for the first line: function expected instead of nil, but I don't get, why. The Iconpicker works btw. and this error is NOT! detected by zbug, I just ran into it because I accidently deactivated zbug.

And another question concerning LAM's iconpicker: Is there any way to preselect an icon from the list for the button? The path is saved insinde the saved variables.

Cheers,
Letho

rullof 05/08/17 05:52 AM

The error is comming either fron getFunc or setFunc make sure you're calling your function using : and check if EditAuraIcon doesnt have any errors

sirinsidiator 05/08/17 07:28 AM

iconSelect is not a ZOS control. You cannot call SetWidth, ClearAnchors and SetAnchor on it directly. Instead you need to access iconSelect.container.

You can set an initial icon via the "default" property on the data table.

Letho 05/08/17 08:46 AM

Thank you for your answers!

Quote:

Originally Posted by rullof (Post 30861)
The error is comming either fron getFunc or setFunc make sure you're calling your function using : and check if EditAuraIcon doesnt have any errors

It was indeed the GetFunc though I have no idea what actually caused the error, I leave it to be an empty function now. (According to LAM's code the getFunc should return the currently selected icon's texture path, allthough this does not work in my case :/).


Quote:

Originally Posted by sirinsidiator (Post 30863)
iconSelect is not a ZOS control. You cannot call SetWidth, ClearAnchors and SetAnchor on it directly. Instead you need to access iconSelect.container.
You can set an initial icon via the "default" property on the data table.


According to zgoo iconSelect is of type #userData :O
This is the code in LibAddonMenu-2.0.lua where it is created:
Code:

local function CreateBaseControl(parent, controlData, controlName)
    local control = wm:CreateControl(controlName or controlData.reference, parent.scroll or parent, CT_CONTROL)
    control.panel = parent.panel or parent -- if this is in a submenu, panel is the submenu's parent
    control.data = controlData

    control.isHalfWidth = controlData.width == "half"
    local width = 510 -- set default width in case a custom parent object is passed
    if control.panel.GetWidth ~= nil then width = control.panel:GetWidth() - 60 end
    control:SetWidth(width)
    return control
end

So isn't it a ZOS control of type CT_CONTROL?

Additionally:
Code:

iconSelect:SetWidth() --does indeed do nothing
iconSelect.container:SetAnchor() --does not do nothing aswell
iconSelect.SetAnchor(TOPLEFT, parent, TOPLEFT) --is working as intended

Regarding preSelection: I tried using
Code:

iconSelectReference:UpdateValue()
, but it is a local function and only called upon the control's creation. I'm now using

Code:

iconSelectReference.icon:SetTexture(path)
I basically needed the icon to dynamically change to the path returned by a function that is called on clicking another button that selects the aura to be currently edited. This active aura's path is stored in AuraMastery.svars.auraData[activeAura].iconPath.

Baertram 05/08/17 09:42 AM

Simply specifying "self" is not returning the icon.
You need to let it return the SavedVariables data where the selected icon from the iconpicker is stored.

e.g.

function AuraMastery.EditAuraIcon(value)
AuraMastery.svars.auraData[activeAura].iconPath = value
end

getFunc = function() return AuraMastery.svars.auraData[activeAura].iconPath end,
setFunc = function(value) AuraMastery.EditAuraIcon(value) end,

Quote:

basically needed the icon to dynamically change to the path returned by a function that is called on clicking another button that selects the aura to be currently edited. This active aura's path is stored in AuraMastery.svars.auraData[activeAura].iconPath.
default = AuraMastery.svars.DEFAULTS.auraData[activeAura].iconPath

The default values just need to be an array/table with all your possible saved variables as default values, which you use at the SavedVariables creation as the default values/fallback values if the real saved variables are missing (new savedvars version, new addon, settings = nil ...)
Setting the default values at lam controls will let you use the "Set back to defaults" button fo all the LAM controls e.g.

The getfunc will try to read the savedvars and if nothing is found (= nil) it will use the default value.
If the default value is the same that you use for the SavedVars creation the settings probably won't be nil, as they got copied from the defaults. So the getfunc will just automatically use the default variable which is stored in the savedvars now.

Letho 05/08/17 10:51 AM

Quote:

Originally Posted by Baertram (Post 30867)
Simply specifying "self" is not returning the icon.
You need to let it return the SavedVariables data where the selected icon from the iconpicker is stored.

e.g.

function AuraMastery.EditAuraIcon(value)
AuraMastery.svars.auraData[activeAura].iconPath = value
end

It was d(self) and I dont have any idea how it got there^^

Quote:

Originally Posted by Baertram (Post 30867)
getFunc = function() return AuraMastery.svars.auraData[activeAura].iconPath end,
setFunc = function(value) AuraMastery.EditAuraIcon(value) end,


default = AuraMastery.svars.DEFAULTS.auraData[activeAura].iconPath

Tried it that way and it didn't work for me.

Quote:

Originally Posted by Baertram (Post 30867)
The default values just need to be an array/table with all your possible saved variables as default values, which you use at the SavedVariables creation as the default values/fallback values if the real saved variables are missing (new savedvars version, new addon, settings = nil ...)
Setting the default values at lam controls will let you use the "Set back to defaults" button fo all the LAM controls e.g.

The getfunc will try to read the savedvars and if nothing is found (= nil) it will use the default value.
If the default value is the same that you use for the SavedVars creation the settings probably won't be nil, as they got copied from the defaults. So the getfunc will just automatically use the default variable which is stored in the savedvars now.

Well, that's not exactly what I needed. Here is a screenshot that makes it easier understandable:



The controls on the right side of the menu are all precreated and hidden. As soon as the user "selects" an aura from the left menu it's name is saved to the addons "global" table (AuraMastery.activeAura = auraName), the editboxes will be filled with the appropriate text values and all menu controls will be displayed. If controls are not used, they are simply anchored to an invisible pool-control - the "control structure", meaning which control to display on what position is saved into an array containing the appropriate values.

Baertram 05/08/17 02:32 PM

If you save the path of the selected icon, coming from the value parameter of the setFunc of the icon picker, to
AuraMastery.svars.auraData[AuraMastery.activeAura].iconPath

you can use the getfunc to get the icon's path that was saved
return AuraMastery.svars.auraData[AuraMastery.activeAura].iconPath

And the same for the default icon path, if you have a default specified somewhere.


The controls are not inside a LAM panel as it seems (correct?) and thus won't get updated automatically via the getFunc I guess. Maybe you need to set the texture manually to the iconpicker by using the reference of the LAM control and use something like
WINDOW_MANAGER:GetControlByName(reference, "").icon:SetTexture(AuraMastery.svars.auraData[AuraMastery.activeAura].iconPath)

?

Letho 05/08/17 04:16 PM

As I wrote above, that's the way I do it^^


All times are GMT -6. The time now is 10:46 AM.

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