Thread Tools Display Modes
10/19/15, 12:41 AM   #1
manavortex
 
manavortex's Avatar
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 138
LAM: for-loop for setting controls / icon picker?

Hello lovely people,

I'm currently toying with the add-on SwitchBar. It's supposed to display a customisable icon for each skill bar. I have an array with some icon textures.

Now I run into a problem. I can't get the icon picker to work, so what I'm currently doing is that I manually set up a texture preview for the single icons.
So - does anyone have an idea how I a) get the icon picker to work or b) add controls to the menu in a loop?
  Reply With Quote
10/19/15, 02:24 AM   #2
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,578
The icon picker expects a numerically indexed array of texture paths.
You would then supply that to the icon picker and in the setFunc you do a reverse lookup for the icon index.

I see that you use strings as array indices for your texture array, which makes things a bit inconvenient.
You will need to generate the list of icons from that, or just change it to numeric indices.
From that array you then want to make a reverse lookup table:
Lua Code:
  1. local icons = { "path/to/icon1.dds", "path/to/icon2.dds" }
  2. local indexByIconPath = {}
  3. for i=1, #icons do
  4.   indexByIconPath[icons[i]] = i
  5. end

The iconpicker configuration would then look something like this:
Lua Code:
  1. { -- Icon for Bar 1
  2.     type = "iconpicker",
  3.     name = "Icon for Bar 1",
  4.     tooltip = "",
  5.     choices = icons,
  6.     getFunc = function() return icons[SwitchBar.SavedVars.icons["1"]] end, -- indices are now saved as numbers instead of strings
  7.     setFunc = function(value)
  8.         SwitchBar.SavedVars.icons["1"] = indexByIconPath[value]
  9.         SwitchBar.SetIcon("1", tostring(value))
  10.     end
  11. },

You can also set the color picker up to update the icon picker's colors whenever you select a different one.
First define a global handle in the iconpicker configuration:
Lua Code:
  1. reference = "SwitchBarIconPicker1"
Then update the setFunc of your color picker:
Lua Code:
  1. { -- icon 1 colorpicker
  2.     type = "colorpicker",
  3.     name = "Icon 1 colour",
  4.     getFunc = function() SwitchBar.GetBgColor("1") end,
  5.     setFunc = function(r,g,b,a)
  6.         SwitchBar.SetBgColor(r,g,b,a, "1")
  7.         SwitchBarIconPicker1:SetColor(ZO_ColorDef:New(r,g,b,a))
  8.     end,
  9. },

You can see a working example of a combination of icon and color picker in FCOItemSaver.


The answer to your second question is quite easy. You can add any number of widget configurations to the optionsData array in any way you want before you call RegisterOptionControls.
Lua Code:
  1. local optionsData = {
  2.     {
  3.         type = "header",
  4.         name = "SwitchBar",
  5.     },
  6.     { -- Move around?
  7.         type = "checkbox",
  8.         name = "Move around?",
  9. ...
  10. }
  11. for i=1, 16 do
  12. optionsData[#optionsData + 1] = {  -- icon preview texture
  13.     type = "texture",
  14.     image = SwitchBar.iconTextures[tostring(i)],
  15.     imageWidth = 100,
  16.     imageHeight = 100,
  17.     tooltip = tostring(i),
  18.     width = "half" ,
  19. }
  20. end
  21. LAM:RegisterOptionControls("SwitchBar_Settings", optionsData)
But I can't recommend this way of showing preview textures in your settings menu, because it will take a lot of space.
You could create a custom widget instead which shows them all side by side in whatever way you want.
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » LAM: for-loop for setting controls / icon picker?


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