Allright, so i tried to get this straight - by adding comments to my code. Note that my english is not that good:
Lua Code:
-- Create a table which holds the element types you want your tooltip to show
local pinnedElements = {
item = true,
achievement = true,
spell = true,
quest = true,
talent = true,
unit = true,
glyph = true,
enchant = true,
}
-- Create a function which will contain the above elements and tooltip them when it is called
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
local elementType = strmatch(elementData, "(.-):") --> elementType will now remove the complete elementData and add only the type from our pinnedElements using "(.-):"
if pinnedElements[elementType] then --> if our pinnedElements table matches one argument in our elementType then
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
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
GameTooltip:Show() --> This will show the tooltip if the requirements is met, which it is
end --> ends the if statement
end --> ends our MouseHoverToolTip_Show function
-- Create a function which will be hidden, when none of the index from our pinnedElements is met
local function MouseHoverToolTip_Hide() --> creates the function that is required to hide the tooltip when we want to
GameTooltip:Hide() --> hides the tooltip
end --> ends our MouseHoverToolTip_Hide function
-- Create a function which will hook the script when it is called
local function HookHandler(self, event, func) --> creates the function and gives it 3 arguments which must be met to work
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.
end --> ends our HookHandler function
-- Create a loop that continously will loop trough our functions and do one of the above functions dependent on the event we call
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
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)
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
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
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 ^^