View Single Post
03-22-13, 10:44 AM   #46
fRodzet
A Flamescale Wyrmkin
Join Date: Mar 2013
Posts: 114
Allright, so i tried to get this straight - by adding comments to my code. Note that my english is not that good:

Lua Code:
  1. -- Create a table which holds the element types you want your tooltip to show
  2. local pinnedElements = {
  3.     item = true,
  4.     achievement = true,
  5.     spell = true,
  6.     quest = true,
  7.     talent = true,
  8.     unit = true,
  9.     glyph = true,
  10.     enchant = true,
  11.     }
  12. -- Create a function which will contain the above elements and tooltip them when it is called
  13. local function MouseHoverToolTip_Show(self, elementData)    --> creates the function and adds two arguments to it, one named self and one named elementData. This will make the call of the MouseHoverToolTip_Show easier, instead of typing it each time - we can call the functions using self and elementData
  14.     local elementType = strmatch(elementData, "(.-):")      --> elementType will now remove the complete elementData and add only the type from our pinnedElements using "(.-):"
  15.     if pinnedElements[elementType] then                     --> if our pinnedElements table matches one argument in our elementType then
  16.         GameTooltip:SetOwner(self, "ANCHOR_CURSOR")         --> This will tell the owner of this specific tooltip which is self(MouseHoverToolTip) and make a position, in this case - where the mouse points
  17.         GameTooltip:SetHyperlink(elementData)               --> This is the hyperlink we would like to display, we call the elementData and not elementType because if our elementType is called it will not meet the requirements in our strmatch function
  18.         GameTooltip:Show()                                  --> This will show the tooltip if the requirements is met, which it is
  19.     end                                                     --> ends the if statement
  20. end                                                         --> ends our MouseHoverToolTip_Show function
  21.  
  22. -- Create a function which will be hidden, when none of the index from our pinnedElements is met
  23. local function MouseHoverToolTip_Hide()                     --> creates the function that is required to hide the tooltip when we want to
  24.         GameTooltip:Hide()                                  --> hides the tooltip
  25. end                                                         --> ends our MouseHoverToolTip_Hide function
  26.  
  27. -- Create a function which will hook the script when it is called
  28. local function HookHandler(self, event, func)               --> creates the function and gives it 3 arguments which must be met to work
  29.         self:HookScript(event, func)                        --> this hooks the given script when it is called, note that we use self:HookScript(event, func) so our first stated argument requirement is met here.
  30. end                                                         --> ends our HookHandler function
  31.  
  32. -- Create a loop that continously will loop trough our functions and do one of the above functions dependent on the event we call
  33. for i = 1, NUM_CHAT_WINDOWS do                              --> NUM_CHAT_WINDOWS is the default API for any chat frame, if 1 of the above statements is met, the loop stops and shows the outcome
  34.     local chatframe = _G["ChatFrame" .. i]                  --> We create a local name for the loop and makes it equal to _G["ChatFrame" .. i] which means that only if the global chat window is a ChatFrame e.g.(trade, local, global, etc) and not a CombatFrame(the combat log)
  35.     HookHandler(chatframe, "OnHyperLinkEnter", MouseHoverToolTip_Show) --> We now call the HookHandler function above and tells it that if its chatframe(_G["ChatFrame" .. i]) and we entered a HyperLink from our table "OnHyperLinkEnter" we should call the function MouseHoverToolTip_Show
  36.     HookHandler(chatframe, "OnHyperLinkLeave", MouseHoverToolTip_Hide) --> This is equal to the above, but this is when our mouse leaves a hyperlink, the MouseHoverToolTip_Hide function is called
  37. end                                                         --> ends the loop

There is alot reading and it might seem abit messy, but if you read it - tell me what is correct and what might be wrong.. I know that i might have mixed some words like arguments and variables - not 100% sure what is what yet :P

EDIT: Ooh yeah and BTW, ty very much for all the help ive had trough this topic.. This site rocks ^^

Last edited by fRodzet : 03-22-13 at 10:59 AM.
  Reply With Quote