Thread Tools Display Modes
07-23-13, 05:52 AM   #1
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Multiple selection dropdown

Anyone can provide me a template about this? The problems i run into mostly when you select a value to not to clear the already selected values.
I remember i saw some kinda template on the web back then, but i just can't find it now.
  Reply With Quote
07-23-13, 12:30 PM   #2
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Check here: http://forums.wowace.com/showthread.php?t=15763
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
07-23-13, 01:06 PM   #3
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Originally Posted by Seerah View Post
Coundn't find anything about it. My problem is about the UIDropDownMenu_GetSelected... and UIDropDownMenu_SetSelected..., only supports one checked item. I'm pretty sure there is a trick for it, since i don't want to rebuild the whole dropdown by myself.
  Reply With Quote
07-23-13, 01:09 PM   #4
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
There is a way to do it. The Postal screenshot in that thread has checks next to almost every entry in the dropdown.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
07-23-13, 01:14 PM   #5
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Originally Posted by Seerah View Post
There is a way to do it. The Postal screenshot in that thread has checks next to almost every entry in the dropdown.
I see, but i think Postal using AceGUI, and i already looked up in the Ace code, and got me nowhere.
  Reply With Quote
07-23-13, 01:24 PM   #6
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
What i really want to do is:

Have 1 variable a string like:

Code:
local lolvar = "0"
And a dropdown with lets say 3 buttons: 1, 2, 3.

And i want to change the lolvar's value based on the checked dropdown buttons.

Like if all is checked then the lolvar = "1/2/3".
If none is checked then the lolvar = "0".
If only the 1 and 3 is checked then lolvar = "1/3".

And so on.

The problems is i don't know how to get and set the selected values if multiple checks is also allowed.
  Reply With Quote
07-23-13, 03:00 PM   #7
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Resike View Post
Coundn't find anything about it. My problem is about the UIDropDownMenu_GetSelected... and UIDropDownMenu_SetSelected..., only supports one checked item. I'm pretty sure there is a trick for it, since i don't want to rebuild the whole dropdown by myself.
Postal does not use UIDropDownMenu_GetSelected or UIDropDownMenu_SetSelected, but if you are using those functions in your addon, then you are already "rebuilding the whole dropdown".

Originally Posted by Resike View Post
I see, but i think Postal using AceGUI, and i already looked up in the Ace code, and got me nowhere.
The menu in Postal does not use AceGUI or any other libraries. In fact, the thread Seerah linked is a tutorial written by the author of Postal showing you how to use the UIDropDownMenu system the way Postal does -- without any libraries.

Originally Posted by Resike View Post
Like if all is checked then the lolvar = "1/2/3".
If none is checked then the lolvar = "0".
If only the 1 and 3 is checked then lolvar = "1/3".
You'd need to keep a table containing each menu option and its check state. When the user checks or unchecks one entry, update its value in the table to reflect its new state, and then loop over the table to update your "lolvar" variable.

However, concatenating values into a string seems like a really inefficient way to store multiple values. You should just store them in the table, and use the table values, instead of squishing them into a string.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
07-23-13, 04:22 PM   #8
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Originally Posted by Phanx View Post
Postal does not use UIDropDownMenu_GetSelected or UIDropDownMenu_SetSelected, but if you are using those functions in your addon, then you are already "rebuilding the whole dropdown".



The menu in Postal does not use AceGUI or any other libraries. In fact, the thread Seerah linked is a tutorial written by the author of Postal showing you how to use the UIDropDownMenu system the way Postal does -- without any libraries.



You'd need to keep a table containing each menu option and its check state. When the user checks or unchecks one entry, update its value in the table to reflect its new state, and then loop over the table to update your "lolvar" variable.

However, concatenating values into a string seems like a really inefficient way to store multiple values. You should just store them in the table, and use the table values, instead of squishing them into a string.
So i pretty much need to use the info.checked and write my own iterator functions, thats what i was meant by rebuilding it and wanted to skip.

I would like to work with tables too, but i cant, the lolvar is a savedvar too, and it's size based on the number of the player's avaliable stances.
  Reply With Quote
07-23-13, 11:49 PM   #9
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Resike View Post
I would like to work with tables too, but i cant, the lolvar is a savedvar too, and it's size based on the number of the player's avaliable stances.
You can store a table in a saved variable, and it's a lot faster and cheaper to get the number of values in a table, vs. splitting up a string and counting the parts. Without seeing your code it's impossible to be more specific, but I can't imagine any scenario where constantly concatenating and splitting a string is in any way better than using a table, unless you're displaying the string to the user somewhere, in which case it is still more efficient to keep the actual data in a table, and only convert one way (table data -> string) instead of constantly going back and forth.

Originally Posted by Resike View Post
So i pretty much need to use the info.checked and write my own iterator functions, thats what i was meant by rebuilding it and wanted to skip.
Again, without seeing your actual code, all I can really tell you is that (a) it's possible and (b) it's not very hard. If you want any real help, you're going to have to show your code.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
07-24-13, 12:38 AM   #10
Vlad
A Molten Giant
 
Vlad's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2005
Posts: 793
Could use bit.band for this task, let me explain:

Code:
-- just for convencience
local optMap = {
  [1] = "Option 1",
  [2] = "Option 2",
  [4] = "Option 3",
  [8] = "Option 4",
}

-- the option value
local opt = 0

--[[
Opt starts at 0; when an option is checked/unchecked either
add or remove its value from opt; if you click "Option 3"
so it becomes checked you opt=opt+4 while if you uncheck
it you must opt=opt-4 and so forth.

You can use bit.band(opt, index) to figure out if a certain
bit is on or off, and the best part is that it supports storing
several field values in one integer - no need to create
more variables than you have to!

"bit.band(opt, 1) > 0" is true when "Option 1" is checked
"bit.band(opt, 2) > 0" is true when "Option 2" is checked
"bit.band(opt, 4) > 0" is true when "Option 3" is checked
"bit.band(opt, 8) > 0" is true when "Option 4" is checked
]]

-- print results
for index, name in pairs(optMap) do
  local checked = bit.band(opt, index) > 0
  print(name .. " = " .. (checked and "TRUE" or "FALSE"))
end
__________________
Profile: Curse | Wowhead
  Reply With Quote
07-24-13, 01:45 AM   #11
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Yeah, but I wasn't going to go there, as the OP seems to be learning enough new things at the same time already.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
07-24-13, 01:46 AM   #12
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Originally Posted by Phanx View Post
You can store a table in a saved variable, and it's a lot faster and cheaper to get the number of values in a table, vs. splitting up a string and counting the parts. Without seeing your code it's impossible to be more specific, but I can't imagine any scenario where constantly concatenating and splitting a string is in any way better than using a table, unless you're displaying the string to the user somewhere, in which case it is still more efficient to keep the actual data in a table, and only convert one way (table data -> string) instead of constantly going back and forth.
The var is already used for import export options, and already have an ADDON_MESSAGE communication built around it, and if i create another table in the table i have to rewrite the whole package to support this new table too, and this new type of communication with import export is not gonna work with the older addon versions then.
  Reply With Quote
07-24-13, 01:01 PM   #13
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
You realize that you can have more than one saved variable, right?
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Multiple selection dropdown


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