12.07.2015 Views

Wiley-World.of.Warcraft.Programming.A.Guide.and.Reference.for.Creating.WoW.Addons

Wiley-World.of.Warcraft.Programming.A.Guide.and.Reference.for.Creating.WoW.Addons

Wiley-World.of.Warcraft.Programming.A.Guide.and.Reference.for.Creating.WoW.Addons

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

440 Part III ■ Advanced Addon TechniquesFunction Menu ItemsAny menu item can be set to call a function when it is clicked by using thefollowing set <strong>of</strong> attributes:func—The function to be called when the button is clicked.arg1—An argument to be passed to the function when it is called.arg2—Another argument to be passed to the function when it is called.keepShownOnClick—A boolean flag indicating whether or not the dropdownmenu should remain showing instead <strong>of</strong> disappearing when thebutton is clicked.Although the attributes are called arg1 <strong>and</strong> arg2, they are actually thesecond <strong>and</strong> third arguments that are passed to the function. The first argumentis the button itself (which contains all <strong>of</strong> the valid attributes in the originalinfo table).Add a function-enabled button to your dropdown using the following code:info = UIDropDownMenu_CreateInfo()info.text = “Function Button“function info.func(button, arg1, arg2)print(“CALL: Arg1: “ .. tostring(arg1) .. “ Arg2: “ .. tostring(arg2))endinfo.arg1 = “Foo“info.arg2 = “Bar“UIDropDownMenu_AddButton(info)CheckButton Menu ItemsMany dropdown menus are used <strong>for</strong> configuration, such as the ‘‘Player vs.Player’’ setting that can be accessed by right-clicking the player frame. Thesetoggleable items make use <strong>of</strong> the checkbox included in each dropdown entry,<strong>and</strong> the checked attribute to signify that the item is checked.info = UIDropDownMenu_CreateInfo()info.text = “Toggleable setting“info.checked = SOME_SETTINGfunction info.func(button, arg1, arg2)SOME_SETTING = not SOME_SETTINGprint(“SOME_SETTING is “ .. tostring(SOME_SETTING)endUIDropDownMenu_AddButton(info)This code defines a new button that can be clicked to change the value <strong>of</strong>the global variable SOME_SETTING. Because it starts <strong>of</strong>f with a value <strong>of</strong> nil, the

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!