Go Back   WowAce Forums > Tips, FAQs, and Guides

Reply
 
Thread Tools
Old 10-07-2009   #21
OrionShock
Legendary Member
 
OrionShock's Avatar
 
Join Date: May 2006
Location: Arizona
Posts: 3,379
Default Re: Guide: Using UIDropDownMenu in your addon

Torhal, while those perticular scripts may only be used for highlights and beggener tooltips, those perticualr frames are created by blizzard and are secure. Setting a insecure script, IMO, shouse be avoided. A secure hook might be better.
__________________
Author of GuildCraft, SickOfClickingDailies, and CursorCooldown

"I was there in the beginning... and things were very different back then" --An Echo from a time before.
OrionShock is offline   Reply With Quote
Old 10-07-2009   #22
Torhal
Moderator
 
Torhal's Avatar
 
Join Date: Feb 2008
Posts: 1,431
Send a message via ICQ to Torhal
Default Re: Guide: Using UIDropDownMenu in your addon

You can't un-hook secure hooks, which is why it was done that way. If this becomes an issue, I have a way of handling it so that it no longer is.

I'll just have to finish getting Revelation working without Dewdrop, and see if I have issues with taint or blocked actions from CastSpellByName() and such.
__________________
Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Author of Revelation, Volumizer, and many other AddOns.
Torhal is offline   Reply With Quote
Old 10-09-2009   #23
Xinhuan
Asian Sheep Lover
 
Xinhuan's Avatar
 
Join Date: Aug 2007
Location: Singapore
Posts: 3,420
Default Re: Guide: Using UIDropDownMenu in your addon

Hi Torhal, your method is too complicated. There is a much simpler method to display tooltips regardless of whether the Beginner Tooltips option is turned on or off.

Here's how.

Step 1: Securehook the function GameTooltip_AddNewbieTip(frame, normalText, r, g, b, newbieText, noNormalText)

PHP Code:
    -- Hook the tooltips on UIDropDownMenu
    hooksecurefunc
("GameTooltip_AddNewbieTip", function(framenormalTextrgbnewbieTextnoNormalText)
        if 
normalText == "WoWEquipShowTooltip" then
            GameTooltip_SetDefaultAnchor
(GameTooltipframe)
            if 
newbieText 0 then
                GameTooltip
:SetHyperlink("item:"..newbieText)
            elseif 
newbieText 0 then
                GameTooltip
:SetHyperlink("enchant:"..-newbieText)
            
end
            GameTooltip
:AddLine(" ")
            
GameTooltip:AddLine(L["|cffeda55fCtrl-Click|r to add to/remove from Favorites"], 010)
            
GameTooltip:AddLine(L["|cffeda55fShift-Click|r to link to chat"], 010)
            
GameTooltip:Show()
        
end
    end

In the above code, what we have done is check if normalText == "WoWEquipShowTooltip". If it is true, I look at the data contained in the newbieText variable and in my case, I chose to make GameTooltip display an itemlink if it is a positive number, and an enchant link if it is a negative number. I added some extra tooltip text after that about Ctrl/Shift clicks.

If you looked in WoWEquip's code, you'll see that the menuitems in question has .keepShownOnClick = true, and the menu is only forcefully closed on a normal click, and kept open on a Shift or Ctrl-click which does different things.

The beauty of this hook is that it really is just about 5 lines of code without all the extra if-then-else logic for checking if the number I passed in is positive or negative. In the simplest use-case, you can just have

PHP Code:
    -- Hook the tooltips on UIDropDownMenu
    hooksecurefunc
("GameTooltip_AddNewbieTip", function(framenormalTextrgbnewbieTextnoNormalText)
        if 
normalText == "WoWEquipShowTooltip" then
            GameTooltip_SetDefaultAnchor
(GameTooltipframe)
            
GameTooltip:Clear()
            
GameTooltip:AddLine(myTooltipTitles[newbieText], 010)
            
GameTooltip:AddLine(myTooltipTexts[newbieText], 010)
            
GameTooltip:Show()
        
end
    end

where newbieText is just a pointer to the data you wish to display in your tooltips.

Now compare my simple 5 line function hook which is safe, compared to your 60 line behemoth mess of hooks which may or may not have unknown tainting side-effects, you'll probably want to rewrite all of your code.



Step 2: In your info[] table when passing to UIDropDownMenu_AddButton(), simply include info.tooltipTitle and info.tooltipText. For example:

PHP Code:
            info.func self.UncheckHack
            info
.text v.t
            info
.value v
            info
.icon GetItemIcon(v[2])
            
info.tooltipTitle "WoWEquipShowTooltip"
            
info.tooltipText v[2]
            
UIDropDownMenu_AddButton(infolevel
info.tooltipTitle and info.tooltipText are passed into GameTooltip_AddNewbieTip() as normalText and newbieText so you only need to match the tooltipTitle to your addon (if more than one addon is using this technique), and use newbieText as pointer to the data you wish to display to in the tooltip.

GameTooltip_AddNewbieTip() is called whenever your mouse enters a UIDropDownMenuButton, regardless of whether newbie tooltips are on or off. Because our securehooked function runs after Blizzard's one, it overwrites the GameTooltip that Blizzard created with normalText and newbieText in it.
__________________
Author/Maintainer of Postal, Omen3, GemHelper, BankItems, WoWEquip, GatherMate, Routes, HandyNotes and some others.

Last edited by Xinhuan; 10-09-2009 at 10:08 AM.
Xinhuan is offline   Reply With Quote
Old 10-09-2009   #24
Torhal
Moderator
 
Torhal's Avatar
 
Join Date: Feb 2008
Posts: 1,431
Send a message via ICQ to Torhal
Default Re: Guide: Using UIDropDownMenu in your addon

Much, much simpler. I'll adjust accordingly.
__________________
Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Author of Revelation, Volumizer, and many other AddOns.
Torhal is offline   Reply With Quote
Old 6 Days Ago   #25
Requital
Member
 
Join Date: Mar 2008
Posts: 12
Default Re: Guide: Using UIDropDownMenu in your addon

I'm not really sure if this is the right place to post this but this guide while teaching me some I'm still lost as to what is happening in this addon.

I took over a bag addon because it was dying out and it was the bag addon I have used since Vanilla and I couldn't continue without it. So I started cleaning it up to be more up to date code wise. The problem I'm coming up with is the Submenus 2 and 3 from the context menu.

When you control right click I get my context menu and it works perfect. When you mouse over the arrow to open the sub menu it shows up as it should. When you move the mouse across the category and into the next sub menu the menu vanishes. It's very buggy if you move the mouse really fast or back and forth sometimes you can get the 2nd and 3rd sub menus to stay visible but in most cases they just vanish and you can't just have to keep moving the mouse back over the arrow to bring then back.

I have read through this tutorial 100% and I can't find anything that would cause this or allow it. So if anyone can point me into a direction as to what I can look for I would really appreciate it. I'm pretty new to coding I dabble in it so I don't know all of it but I am learning more about it.

I can post parts of the code if there is something that would be helpful to determine it.
Requital is offline   Reply With Quote
Old 6 Days Ago   #26
Xinhuan
Asian Sheep Lover
 
Xinhuan's Avatar
 
Join Date: Aug 2007
Location: Singapore
Posts: 3,420
Default Re: Guide: Using UIDropDownMenu in your addon

Hi Requital, read the reply I have posted in your other thread on this issue.
(And use that thread.)
__________________
Author/Maintainer of Postal, Omen3, GemHelper, BankItems, WoWEquip, GatherMate, Routes, HandyNotes and some others.
Xinhuan is offline   Reply With Quote
Old 6 Days Ago   #27
Requital
Member
 
Join Date: Mar 2008
Posts: 12
Default Re: Guide: Using UIDropDownMenu in your addon

Man you are everywhere, I guess I kinda forgot the sites were linked these days but will do thank you again.
Requital is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT. The time now is 08:58 AM.