Thread Tools Display Modes
05/15/23, 10:34 AM   #1
sinnereso
AddOn Author - Click to view addons
Join Date: Oct 2022
Posts: 244
Question libaddonmenu dropdown listbox default display

Hey guys im looking for a way to get a dropdown listbox using libaddonmenu to display a saved variable on it when it is NOT dropped down but otherwise NOT have that variable as a choice.

The reason is I'm trying to avoid the "double listing" that happens when the saved variable happens to be one of the choices. If i remove it as a choice the dropdown is blank other than the choices.

Any suggestions? heres what im messing with right now:

Code:
{
	type = "dropdown",
	name = "name",
	tooltip = "tooltip",
	choices = {
		tostring("DISABLED"),
		tostring(MyAddon.savedVariables.noDeposit),
		tostring(GetUnitName("player")),
		},
	getFunc = function() return tostring(MyAddon.savedVariables.noDeposit) end,
	setFunc = function(var) MyAddon.savedVariables.noDeposit = (var) end,
	disabled = function() return not MyAddon.savedVariables.goldDeposit end,
	--width = "half",
},

Last edited by sinnereso : 05/15/23 at 10:52 AM.
  Reply With Quote
05/15/23, 10:53 AM   #2
ExoY
 
ExoY's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2020
Posts: 87
create your choices with a predefined table, regardless of what your save variable is and you shoudnt have the problem you are talking about
  Reply With Quote
05/15/23, 10:58 AM   #3
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,912
Your choices will be build once as the dropdown is created, as the menus opens.
If you want to update that later one, after changing the dropdown's selected entry, you need to update that table and re-assign it via dropdown:UpdateChoices(choices, choicesValues, choicesTooltips) function.

Provide a reference to your LAM dropdwn so you can access it after it was created, e.g.in your data table of that dropdown add
reference = "MyAddon_LAM_Dropdown1",

Then crete a small fucntion e.g.
Code:
local function updateMyChoices()
  if MyAddon_LAM_Dropdown1 == nil then return end
  local myChoices = {
    [1]=var1,
    [2]=var2,
    [3]=var3,
 }
 local myChoicesValues = {
    [1]=value1,
    [3]=value2,
    [2]=value3,
 }
 MyAddon_LAM_Dropdown1:UpdateChoices(myChoices, myChoicesValues )
end
At your setFunc of the dropdown change the value in the SV and after that call the func updateMyChoices() then.
Something like that.


This is only needed if your dropdown choices should cange based on the SV you change via that dropdown, so take care what you reference! e.g. do not reference the SAME SV variable in teh choices directly which you change via the same dropdown!

Last edited by Baertram : 05/15/23 at 11:00 AM.
  Reply With Quote
05/15/23, 03:28 PM   #4
sinnereso
AddOn Author - Click to view addons
Join Date: Oct 2022
Posts: 244
Another option I could work with might be to retrieve a list of all characters on the account and list them there but I'm not yet certain its possible.. Still digging.
  Reply With Quote
05/15/23, 06:30 PM   #5
Sharlikran
 
Sharlikran's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 626
IF you retrieve a list of characters from a saved variables file then you have the list.

CharacterA
CharacterB
CharacterC

then you register the LAM options. Once you do that the table is set, the choices are set, and LAM knows how to populate the dropdown. You are trying to dynamically change the choices after registering the LAM menu.
  Reply With Quote
05/16/23, 01:25 AM   #6
sinnereso
AddOn Author - Click to view addons
Join Date: Oct 2022
Posts: 244
I like the idea of making a list in saved variables. Is it possible to create a table of character names manually in my accountwide variables?

something like:

MyAddon.savedVariables.charNames = GetUnitName("player")

but add to a table instead of just replacing the value? Ive never created a table this way and cant seem to wrap my head around how to do it.
  Reply With Quote
05/16/23, 06:41 AM   #7
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,912
Lua Code:
  1. --Get the currently logged in account's characters as table, with the name as key and the characterId as value,
  2. --or the characterId as key and the character name as key (depending in boolean parameter keyIsCharName)
  3. --Function to get all characters of the account, ID and name.
  4. --Returns a table with 2 possible variants, either the character ID is key and the name is the value,
  5. --or vice versa.
  6. --Parameter boolean, keyIsCharName:
  7. -->True: the key of the returned table is the character name
  8. -->False: the key of the returned table is the unique character ID (standard)
  9. local function GetCharactersOfAccount(keyIsCharName)
  10.     keyIsCharName = keyIsCharName or false
  11.     local charactersOfAccount
  12.     --Check all the characters of the account
  13.     for i = 1, GetNumCharacters() do
  14.         local name, _, _, _, _, _, characterId = GetCharacterInfo(i)
  15.         local charName = zo_strf(SI_UNIT_NAME, name)
  16.         if characterId ~= nil and charName ~= "" then
  17.             if charactersOfAccount == nil then charactersOfAccount = {} end
  18.             if keyIsCharName then
  19.                 charactersOfAccount[charName]   = characterId
  20.             else
  21.                 charactersOfAccount[characterId]= charName
  22.             end
  23.         end
  24.     end
  25.     return charactersOfAccount
  26. end


Use table with the charname as choices (shows the names of the char as dropdown entries in the LAM dropdown)
AND IMPORTANT: build your choicesValues table which uses the internal characterId then as key, and not the name as the name can be changed but characterId is unique (stays the same after rename) per server.

So basically call the above function once with false -> returned table will be tab[characterId] = charName
Then loop over tab with
local choices = {}
local choicesValues = {}
local count = 0
for charId, charName in pairs(tab) do
count = count + 1
choices[count] = charName
choicesValues[count] = charId
end

Else you will get into trouble like always when you depend on translatable or changeable strings!

Last edited by Baertram : 05/16/23 at 06:45 AM.
  Reply With Quote
05/16/23, 09:17 AM   #8
sinnereso
AddOn Author - Click to view addons
Join Date: Oct 2022
Posts: 244
TY. That looks like its to retrieve the charName from the saved variables? How do I save them there though? Or is that always done automatically already when they log in with account wide variables? I only ever made 1 toon so I never noticed this.

Last edited by sinnereso : 05/16/23 at 09:21 AM.
  Reply With Quote
05/16/23, 09:56 AM   #9
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,912
It does not read anything from savedvariables, it's reading it via API functions from your account. No SV needed for that.

What do you want to save in the SV? All the characternames and ids? Not needed as they do not change and the function can determine them on the fly quickly.
Just call that ONCE at start of your addon and keep them local in your addon data, not in the sv.

e.g. MyAddon.characterData = GetCharactersOfAccount(false)
If you need the characterId or name then just access your MyAddon.characterData table.
Or build yourself a lookup tbale like described above with the choices and choicesValues example for the LAM dropdown!

Example for LAM dropdown "Choose a character":
Follow my example how to build the choices and choicesValues above, last post!

And then use the characterId returned by choicesValues, via the LAM dropdown -> selected entry will use the choicesValues characterId and pass it to the setFunc of your dropdown -> save the selected characterId to the SV that way via the setFunc as normal LAM settings work.


General character dependent SavedVariables (if your addon should save per char and not per account):
If you want to save data BELOW your characterId in the SavedVariables you need to use another ZO_SavedVars: wrapper like NewCharacterIdSettings instead of New or NewAccountWide, but this will save your total SavedVars character dependent and not account dependent then.

The WIKI explains more, search there please.


If this all does not help please explain what exactly you want to achieve here, and if you use a LAM dropdown and what it should show as entries, and what should happen then if you change that dropdown entries etc.
Make a simple example and describe in simple steps, and then we will find a simple way (or not ;-) ).

Last edited by Baertram : 05/16/23 at 10:03 AM.
  Reply With Quote
05/16/23, 01:16 PM   #10
sinnereso
AddOn Author - Click to view addons
Join Date: Oct 2022
Posts: 244
I appreciate all the help.

Im looking to build a list of all character names on account ONLY for one LAM dropdown panel, otherwise am perfectly happy with a NewAccountWide settings in my variables. The purpose is to be able to select ONE of them in the list to NOT auto deposit. Like a main character sort of thing. The rest of my LAM dropdown works perfectly I just need to get a list of names into it for the "CHOICES".

**EDIT
I realize ID's are the preferred method due to them being compatible with name changes etc but NAMES is fine for my needs. Its not a critical feature and it can be changed/updated from any character if a name change does happen.

That function looks pretty clear but how do I get that data into the LAM control HERE:
Code:
{
	type = "dropdown",
	name = "Disable Gold Deposit",
	tooltip = "One character that does not auto deposit per account",
	choices = {
               "DISABLED",
               function() return MyAddon.GetCharacterNamesOnAccount(false) end,--<< HERE
               },
	getFunc = function() return tostring(MyAddon.savedVariables.noDeposit) end,
	setFunc = function(var) MyAddon.savedVariables.noDeposit = (var) end,
	disabled = function() return not MyAddon.savedVariables.goldDeposit end,
},

Last edited by sinnereso : 05/16/23 at 02:14 PM.
  Reply With Quote
05/16/23, 03:03 PM   #11
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,912
I showed you how to do that already in my 2nd last post where I showed you the fucntion to get the character names AND I also showed you how to build the choices (names to show in dropdown) AND choicesValues (characterIds to se in savedvariables) there?

So basically call the above function once with false -> returned table will be tab[characterId] = charName

local tab = GetCharactersOfAccount(false)
--Then loop over tab with
local choices = {}
local choicesValues = {}
local count = 0
for charId, charName in pairs(tab) do
count = count + 1
choices[count] = charName
choicesValues[count] = charId
end
Call that once before the LAM settings are created to create choices and choicesValues.
Then just pass in that choices and choicesValues table to the LAM dropdown, at the very same parameter names of the dropdown's data table.
If choicesValues is defined your setFunc will save those values (the characterId) to your SV then, instead of the names of choices. If choicesValues is nil it will just use the chocies entries (string characterName).

If you need a disabled entry just use table.insert(choices, 1, "Disabled") and table.insert(choicesValues, 1, -1) after choices and choicesValues have been fileld from tab (after the for...do ... end loop)
-1 is the disabled value then to save in the SVs.

I dunno how to describe that better without writing you the whole addon code, so this is up to you now

btw:
Disabled is a string that the game already translates so you can use the GetString(SI_*) function to get it localized already.
Check the localized strings here for the correct SI_* constant and search for "Disabled": and you'll find SI_CHECK_BUTTON_DISABLED
So use GetString(SI_CHECK_BUTTON_DISABLED) instead of a fixes string "Disabled" and you will have all supported languages based on the actual client language. As your choicesValues always returns -1 you just need to check for -1 instead of "Disabled" (which shouldn't be done at all, string comparison, if there is a way to use a dedicated number e.g.. Same like characterNames vs characerIds!)

Last edited by Baertram : 05/16/23 at 03:12 PM.
  Reply With Quote
05/16/23, 03:55 PM   #12
sinnereso
AddOn Author - Click to view addons
Join Date: Oct 2022
Posts: 244
tables kill me everytime. I cant seem to vizualize the flow with these things.
  Reply With Quote
05/16/23, 04:31 PM   #13
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,912
Not sure what exactly you mean?

tables are quite easy.
They are defined via = {}
and in there is a key = value, pair.
key can be string like "hello" or a number like [1] or even a control or another table or some pointer to another variable,
and value can be about the same
-> That's the only challenging part here that a table could contain other tables.

tables with non-gap numbers like
[1] = "a",
[2] = "b",
[3] = "c",
can be iterated via ipairs function (in defined order 1 to n (here 3)).

And tables with a gap number, or a non-number key like
[1] = "a",
[3] = "c",
or
["a"] = "a",
["b"] = "b",
["c"] = "c",
can be iterated via the pairs function (attention: Will iterate keys in random order! each time)

in lua about everything uses tables so you should get comfortable with these ;-)
https://wiki.esoui.com/LUA_Tables
  Reply With Quote
05/16/23, 04:34 PM   #14
sinnereso
AddOn Author - Click to view addons
Join Date: Oct 2022
Posts: 244
yeh ive been over that 1000 times.. guess i need another 1000 =p

**EDIT
I got it working finally! Thank you all for the help

Last edited by sinnereso : 05/16/23 at 08:49 PM.
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » libaddonmenu dropdown listbox default display

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