WoW:USERAPI addDropDownMenuButton

From AddOn Studio
Jump to navigation Jump to search
This page documents a <i>user-defined function</i> that you can copy and paste into your addon. Replace PREFIX with your addon or lib prefix to avoid conflicts between different versions of these functions.

User defined functions

This function has been found to be faulty. It taints the pathway of other buttons in all drop downs, whereby the built-in security system prevent some secure functions from running. Do not use this function.

Calls to this function add additional buttons/links to the drop down/ right click popup menus within World of Warcraft.

<PREFIX>_addDropDownMenuButton(uid, dropdown, index, title, usable, onClick[, hint])

Function Parameters[edit]

Arguments[edit]

uid
String - A unique id to identify your custom button.
dropdown
String - The string represending the drop down menu to add this button too.
index
Integer - An integer saying where you would like it placed in the list.
title
String - The text to display on the button.
usable
Function - A function that returns true if the current setup is valid for it to display. (Two parameter: target name, target unit|Returns Boolean)
onClick
Function - A function that is performed when the button is clicked. (Four parameters: the button itself, target name, target unit, target server|No return)

Note:

The parameters target name, target unit and target server for the usable and onClick functions are not garunteed to be filled, and thus may have values of 'nil'.

Additional[edit]

Here is the list of WoW predefined drop downs and their button lists:

Drop downs Buttons
"SELF" "SET_FOCUS", "PVP_FLAG", "LOOT_METHOD", "LOOT_THRESHOLD", "OPT_OUT_LOOT_TITLE", "LOOT_PROMOTE", "DUNGEON_DIFFICULTY", "RESET_INSTANCES", "RAID_TARGET_ICON", "LEAVE", "CANCEL"
"PET" "SET_FOCUS", "PET_PAPERDOLL", "PET_RENAME", "PET_ABANDON", "PET_DISMISS", "CANCEL"
"PARTY" "SET_FOCUS", "MUTE", "UNMUTE", "PARTY_SILENCE", "PARTY_UNSILENCE", "RAID_SILENCE", "RAID_UNSILENCE", "BATTLEGROUND_SILENCE", "BATTLEGROUND_UNSILENCE", "WHISPER", "PROMOTE", "LOOT_PROMOTE", "UNINVITE", "INSPECT", "ACHIEVEMENTS", "TRADE", "FOLLOW", "DUEL", "RAID_TARGET_ICON", "PVP_REPORT_AFK", "RAF_SUMMON", "RAF_GRANT_LEVEL", "CANCEL"
"PLAYER" "SET_FOCUS", "WHISPER", "INSPECT", "INVITE", "ACHIEVEMENTS", "TRADE", "FOLLOW", "DUEL", "RAID_TARGET_ICON", "RAF_SUMMON", "RAF_GRANT_LEVEL", "CANCEL" };
"RAID_PLAYER" "SET_FOCUS", "MUTE", "UNMUTE", "RAID_SILENCE", "RAID_UNSILENCE", "BATTLEGROUND_SILENCE", "BATTLEGROUND_UNSILENCE", "WHISPER", "INSPECT", "ACHIEVEMENTS", "TRADE", "FOLLOW", "DUEL", "RAID_TARGET_ICON", "RAID_LEADER", "RAID_PROMOTE", "RAID_DEMOTE", "LOOT_PROMOTE", "RAID_REMOVE", "PVP_REPORT_AFK", "RAF_SUMMON", "RAF_GRANT_LEVEL", "CANCEL"
"RAID" "SET_FOCUS", "MUTE", "UNMUTE", "RAID_SILENCE", "RAID_UNSILENCE", "BATTLEGROUND_SILENCE", "BATTLEGROUND_UNSILENCE", "RAID_LEADER", "RAID_PROMOTE", "RAID_MAINTANK", "RAID_MAINASSIST", "LOOT_PROMOTE", "RAID_DEMOTE", "RAID_REMOVE", "PVP_REPORT_AFK", "CANCEL"
"FRIEND" "WHISPER", "INVITE", "TARGET", "IGNORE", "REPORT_SPAM", "GUILD_PROMOTE", "GUILD_LEAVE", "PVP_REPORT_AFK", "CANCEL"
"TEAM" "WHISPER", "INVITE", "TARGET", "TEAM_PROMOTE", "TEAM_KICK", "TEAM_LEAVE", "CANCEL"
"RAID_TARGET_ICON" "RAID_TARGET_1", "RAID_TARGET_2", "RAID_TARGET_3", "RAID_TARGET_4", "RAID_TARGET_5", "RAID_TARGET_6", "RAID_TARGET_7", "RAID_TARGET_8", "RAID_TARGET_NONE"
"CHAT_ROSTER" "WHISPER", "TARGET", "MUTE", "UNMUTE", "CHAT_SILENCE", "CHAT_UNSILENCE", "CHAT_PROMOTE", "CHAT_DEMOTE", "CHAT_OWNER", "CANCEL"
"VEHICLE" "SET_FOCUS", "RAID_TARGET_ICON", "VEHICLE_LEAVE", "CANCEL"
"TARGET" "SET_FOCUS", "RAID_TARGET_ICON", "CANCEL"
"ARENAENEMY" "SET_FOCUS", "CANCEL"
"FOCUS" "CLEAR_FOCUS", "LOCK_FOCUS_FRAME", "UNLOCK_FOCUS_FRAME", "RAID_TARGET_ICON", "CANCEL"

Example[edit]

<PREFIX>_addDropDownMenuButton("HELLOW_WORLD","SELF",3,"Hello",function(name,unit) return true; end;,function(self,name,unit,server) <i><PREFIX></i>_printMSG("Hello World!"); end,"Click to greet the world");

Result[edit]

This example will add a new button called "Hello" to the drop down/popup when you right click you icon in the top left. Clicking on it will write "Hello World!" to the default chat frame.

Code[edit]

Note:

This code uses the support function allAreType
function <PREFIX>_addDropDownMenuButton(uid, dropdown, index, title, usable, onClick, hint)
  if(not (<PREFIX>_allAreType('string',uid,dropdown,title) and <PREFIX>_allAreType('function',usable,onClick) and type(index)=="number" and (hint==nil or type(hint)=="string") ) ) then
    return;
  end
  if(not UnitPopupMenus[dropdown]) then
    return;
  end
  tinsert(UnitPopupMenus[dropdown],index,uid);
  if(hint) then
    UnitPopupButtons[uid] = { text = title, dist = 0, tooltip = hint};
  else
    UnitPopupButtons[uid] = { text = title, dist = 0};
  end
  USER_DROPDOWNBUTTONS[uid] = {func = function(self)
      onClick(self,UIDROPDOWNMENU_OPEN_MENU.name,UIDROPDOWNMENU_OPEN_MENU.unit,UIDROPDOWNMENU_OPEN_MENU.server);
    end, enabled = usable};
end

USER_DROPDOWNBUTTONS = {};


local default_UIDropDownMenu_AddButton = UIDropDownMenu_AddButton;
UIDropDownMenu_AddButton = function(info, level)
  if(USER_DROPDOWNBUTTONS[info.value]) then
    local dropdownFrame = getglobal(UIDROPDOWNMENU_INIT_MENU);
    if(not USER_DROPDOWNBUTTONS[info.value].enabled(UIDROPDOWNMENU_OPEN_MENU.name,UIDROPDOWNMENU_OPEN_MENU.unit) ) then
      return
    end
    info.func = USER_DROPDOWNBUTTONS[info.value].func;
  end;
  default_UIDropDownMenu_AddButton(info,level);
end;