Friday 23 December 2016

WoW - Text Colour Codes


WoW - Add Button to Target Dropdown Menu

I was having a real issue trying to add buttons to the target right click dropdown menu in WoW.

After posting on a few questions on the CurseForge, WoW Interface and WoW UI & Macro forums without much success, I pulled apart the AddFriend addon and created the following chunk.

local function testDropdownMenuButton(self)
if self.value == "GreenButton" then
print("GreenButton clicked")
elseif self.value == "RedButton" then
print("RedButton clicked")
else
print(" WTF how did I fail?")
end
end

hooksecurefunc("UnitPopup_ShowMenu", function()
if (UIDROPDOWNMENU_MENU_LEVEL > 1) then
return
end
local info = UIDropDownMenu_CreateInfo()
info.text = "Dropdown Menu Button"
info.owner = which
info.notCheckable = 1
info.func = testDropdownMenuButton
if UnitName("target")=="Tauren Commoner" or UnitName("target")=="Orgrimmar Brave" then
info.colorCode = "|cff00ff00"
info.value = "GreenButton"
else
info.colorCode = "|cffff0000"
info.value = "RedButton"
end
UIDropDownMenu_AddButton(info)
end)

This is the most economical solution that I could work out, (proper coders could probably reduce the code further but this did work for me).
I also decided to have the button click to run a separate function for the sake of clarity.

I hope that this can provide benefit to other beginners.