Thread Tools Display Modes
09-03-10, 02:23 PM   #1
Cidwel
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Jun 2008
Posts: 23
Question Showing data of an option clicked in a DropDownMenu

Hi!

I'm trying to create a dropdown menu. I've read the Xinhuan post in Ace explaining how to do the work. I've read wowwiki too.

I can create dynamical menus. My code is:
http://pastebin.com/CPY6eZdJ

this creates a dropdown menu that shows the info stored in a battleground strategies database if I'm in battleground. My trouble is when I try to catch the info.value when I click any option in the dropdown menu.

I want to do something like when I click any value, print(info.value) of the clicked menu. So I tried to use some of the built in functions of uiDropDownMenu like UIDropDownMenu_GetSelectedValue(frame) it ever returns nil

I try to get this value by printing the value in the info.func function

info.func = function()
UIDropDownMenu_GetSelectedValue(frame)
end

I tried changing frame with the name reference of the dropdown menu or by typing (self) without any result

I don't know what I'm doing wrong. Is there a way to show the info. data table when I click in some option of my dropdown menu? Thanks!
  Reply With Quote
09-03-10, 04:00 PM   #2
Torhal
A Pyroguard Emberseer
 
Torhal's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 1,196
You can look at how I handled this in Revelation.
__________________
Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Author of NPCScan and many other AddOns.
  Reply With Quote
09-03-10, 05:07 PM   #3
Vrul
A Scalebane Royal Guard
 
Vrul's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 404
The data in info is volatile so you can't really use it as you tried since each new button you need to create will be writing over the previous buttons data. However, most of the fields are copied into the button you are setting up and that button is the first argument passed to the function you supply (info.func).

Your menu doesn't really need a close button since anything you click in the menu will close it anyway, and you can also click the button that opened it to just toggle it closed. Also, there is no real need to keep your own local info table since Blizzard provides the function UIDropDownMenu_CreateInfo for just this purpose.

I would change that linked code to something more along the lines of:
Code:
local Pipican_strategySelectionMenu = CreateFrame("Frame", "Pipican_strategySelectionMenu")
Pipican_strategySelectionMenu.displayMode = "MENU"

local function menuOnClick(self)
	PipicanOptions["commandCenterFrame_" .. GetTechBGNameByLarge(GetRealZoneText()) .. "_spammedStrategy"] = self.value
end

Pipican_strategySelectionMenu.initialize = function(self, level)
	local info = UIDropDownMenu_CreateInfo()

	info.isTitle = true
	info.text = "Select strategy to spam"
	info.notCheckable = true
	UIDropDownMenu_AddButton(info, level)
 
	info.disabled = nil
	info.isTitle = nil
	info.notCheckable = nil
	info.func = menuOnClick

	local techGBName = GetTechBGNameByLarge(GetRealZoneText())
	local dataStrategies, options = Pipican_dataStrategies[techBGName], PipicanOptions["commandCenterFrame_" .. techBGName .. "_spammedStrategy"]
	for i = 1, #dataStrategies do
		info.checked = options == i
		info.text = dataStrategies[i].name
		info.value = i
		UIDropDownMenu_AddButton(info, level)
	end
end
 
Pipican_switchMode_RaidModeButton:SetScript("OnClick", function(self, button, down)
	if button == "RightButton" then
		ToggleDropDownMenu(1, nil, Pipican_strategySelectionMenu, self:GetName(), 0, 0)
	end
end)
Pipican_switchMode_RaidModeButton:RegisterForClicks("RightButtonUp")
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Showing data of an option clicked in a DropDownMenu


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