📄 tooltip.lua
字号:
function showTooltip(currentTooltip, skipEmbedRender) if (self.showIgnore == true) then return end if (EnhancedTooltip.hasEmbed and not skipEmbedRender) then embedRender() self.showIgnore=true; currentTooltip:Show() self.showIgnore=false; end if (not EnhancedTooltip.hasData) then return end local width = EnhancedTooltip.minWidth if (EnhancedTooltip.hasIcon) then width = width + EnhancedTooltipIcon:GetWidth() end local lineCount = EnhancedTooltip.lineCount if (lineCount == 0) then if (not EnhancedTooltip.hasEmbed) then hideTooltip() return end end local height = 0 for currentLine in getglobalIterator("EnhancedTooltipText%d", 1, lineCount) do height = height + currentLine:GetHeight() + 1 end if EnhancedTooltip.hasIcon then height = math.max(height, EnhancedTooltipIcon:GetHeight() - 6) end height = height + 20 local sWidth = GetScreenWidth() local sHeight = GetScreenHeight() local cWidth = currentTooltip:GetWidth() if (cWidth < width) then getglobal(currentTooltip:GetName().."TextLeft1"):SetWidth(width - 20) self.showIgnore=true; currentTooltip:Show() self.showIgnore=false; else width = cWidth end local parentObject = currentTooltip.owner if (parentObject) then local align = currentTooltip.anchor enhTooltipParentRect = getRect(currentTooltip.owner, enhTooltipParentRect) local xAnchor, yAnchor if (enhTooltipParentRect.l - width < sWidth * 0.2) then xAnchor = "RIGHT" elseif (enhTooltipParentRect.r + width > sWidth * 0.8) then xAnchor = "LEFT" elseif (align == "ANCHOR_RIGHT") then xAnchor = "RIGHT" elseif (align == "ANCHOR_LEFT") then xAnchor = "LEFT" else xAnchor = "RIGHT" end if (enhTooltipParentRect.cy < sHeight/2) then yAnchor = "TOP" else yAnchor = "BOTTOM" end -- Handle the situation where there isn't enough room on the choosen side of -- the parent to display the tooltip. In that case we'll just shift tooltip -- enough to the left or right so that it doesn't hang off the screen. local xOffset = 0; if (xAnchor == "RIGHT" and enhTooltipParentRect.r + width > sWidth - 5) then xOffset = -(enhTooltipParentRect.r + width - sWidth + 5); elseif (xAnchor == "LEFT" and enhTooltipParentRect.l - width < 5) then xOffset = -(enhTooltipParentRect.l - width - 5); end -- Handle the situation where there isn't enough room on the top or bottom of -- the parent to display the tooltip. In that case we'll just shift tooltip -- enough up or down so that it doesn't hang off the screen. local yOffset = 0; local totalHeight = height + currentTooltip:GetHeight(); if (yAnchor == "TOP" and enhTooltipParentRect.t + totalHeight > sHeight - 5) then yOffset = -(enhTooltipParentRect.t + totalHeight - sHeight + 5); elseif (yAnchor == "BOTTOM" and enhTooltipParentRect.b - totalHeight < 5) then yOffset = -(enhTooltipParentRect.b - totalHeight - 5); end currentTooltip:ClearAllPoints() EnhancedTooltip:ClearAllPoints() local anchor = yAnchor..xAnchor if (anchor == "TOPLEFT") then EnhancedTooltip:SetPoint("BOTTOMRIGHT", parentObject, "TOPLEFT", -5 + xOffset, 5 + yOffset) currentTooltip:SetPoint("BOTTOMRIGHT", EnhancedTooltip, "TOPRIGHT", 0,0) elseif (anchor == "TOPRIGHT") then EnhancedTooltip:SetPoint("BOTTOMLEFT", parentObject, "TOPRIGHT", 5 + xOffset, 5 + yOffset) currentTooltip:SetPoint("BOTTOMLEFT", EnhancedTooltip, "TOPLEFT", 0,0) elseif (anchor == "BOTTOMLEFT") then currentTooltip:SetPoint("TOPRIGHT", parentObject, "BOTTOMLEFT", -5 + xOffset, -5 + yOffset) EnhancedTooltip:SetPoint("TOPRIGHT", currentTooltip, "BOTTOMRIGHT", 0,0) else -- BOTTOMRIGHT currentTooltip:SetPoint("TOPLEFT", parentObject, "BOTTOMRIGHT", 5 + xOffset, -5 + yOffset) EnhancedTooltip:SetPoint("TOPLEFT", currentTooltip, "BOTTOMLEFT", 0,0) end else -- No parent -- The only option is to tack the object underneath / shuffle it up if there aint enuff room self.showIgnore=true; currentTooltip:Show() self.showIgnore=false; enhTooltipTipRect = getRect(currentTooltip, enhTooltipTipRect) if (enhTooltipTipRect.b - height < 60) then currentTooltip:ClearAllPoints() currentTooltip:SetPoint("BOTTOMLEFT", UIParent, "BOTTOMLEFT", enhTooltipTipRect.l, height+60) end EnhancedTooltip:ClearAllPoints() if (enhTooltipTipRect.cx < 6*sWidth/10) then EnhancedTooltip:SetPoint("TOPLEFT", currentTooltip, "BOTTOMLEFT", 0,0) else EnhancedTooltip:SetPoint("TOPRIGHT", currentTooltip, "BOTTOMRIGHT", 0,0) end end EnhancedTooltip:SetHeight(height) EnhancedTooltip:SetWidth(width) currentTooltip:SetWidth(width) EnhancedTooltip:Show() for ttMoney in getglobalIterator("EnhancedTooltipMoney%d") do if (ttMoney.myLine ~= nil) then local myLine = getglobal(ttMoney.myLine) local ttMoneyWidth = ttMoney:GetWidth() local ttMoneyLineWidth = myLine:GetWidth() ttMoney:ClearAllPoints() if ((ttMoney.myLineNumber < 4) and (EnhancedTooltip.hasIcon)) then ttMoney:SetPoint("LEFT", myLine, "RIGHT", width - ttMoneyLineWidth - ttMoneyWidth - self.moneySpacing*2 - 34, 0) else ttMoney:SetPoint("LEFT", myLine, "RIGHT", width - ttMoneyLineWidth - ttMoneyWidth - self.moneySpacing*2, 0) end end endend-- calculate the gold, silver, and copper values based the amount of copperfunction getGSC(money) if (money == nil) then money = 0 end local g = math.floor(money / 10000) local s = math.floor((money - (g*10000)) / 100) local c = math.ceil(money - (g*10000) - (s*100)) return g,s,cend-- formats money text by color for gold, silver, copperfunction getTextGSC(money, exact, dontUseColorCodes) local TEXT_NONE = "0" local GSC_GOLD="ffd100" local GSC_SILVER="e6e6e6" local GSC_COPPER="c8602c" local GSC_START="|cff%s%d|r" local GSC_PART=".|cff%s%02d|r" local GSC_NONE="|cffa0a0a0"..TEXT_NONE.."|r" if (not exact) and (money >= 10000) then -- Round to nearest silver money = math.floor(money / 100 + 0.5) * 100 end local g, s, c = getGSC(money) local gsc = "" if (not dontUseColorCodes) then local fmt = GSC_START if (g > 0) then gsc = gsc..string.format(fmt, GSC_GOLD, g) fmt = GSC_PART end if (s > 0) or (c > 0) then gsc = gsc..string.format(fmt, GSC_SILVER, s) fmt = GSC_PART end if (c > 0) then gsc = gsc..string.format(fmt, GSC_COPPER, c) end if (gsc == "") then gsc = GSC_NONE end else if (g > 0) then gsc = gsc .. g .. "g "; end; if (s > 0) then gsc = gsc .. s .. "s "; end; if (c > 0) then gsc = gsc .. c .. "c "; end; if (gsc == "") then gsc = TEXT_NONE end end return gscendfunction embedRender() for pos, lData in self.embedLines do self.currentGametip:AddLine(lData.line) if (lData.r) then local lastLine = getglobal(self.currentGametip:GetName().."TextLeft"..self.currentGametip:NumLines()) lastLine:SetTextColor(lData.r,lData.g,lData.b) end endend--[[ @param bExact (boolean) - optional parameter if true, then the copper value of the given moneyAmount will always be printed out if false (default), then the copper value of the given moneyAmount will not be printed out, if the moneyAmount is too high (see getTextGSC for the exact limit) bExact has no meaning, if moneyAmount is nil.]]function addLine(lineText, moneyAmount, embed, bExact) if (embed) and (self.currentGametip) then EnhancedTooltip.hasEmbed = true EnhancedTooltip.curEmbed = true local line = "" if (moneyAmount) then line = lineText .. ": " .. getTextGSC(moneyAmount, bExact) else line = lineText end table.insert(self.embedLines, {line = line}) return end EnhancedTooltip.hasData = true EnhancedTooltip.curEmbed = false local curLine = EnhancedTooltip.lineCount + 1 local line = getglobal("EnhancedTooltipText"..curLine) line:SetText(lineText) line:SetTextColor(1.0, 1.0, 1.0) line:Show() local lineWidth = line:GetWidth() EnhancedTooltip.lineCount = curLine if (moneyAmount ~= nil) and (moneyAmount > 0) then local curMoney = EnhancedTooltip.moneyCount + 1 local money = getglobal("EnhancedTooltipMoney"..curMoney) money:SetPoint("LEFT", line, "RIGHT", self.moneySpacing, 0) TinyMoneyFrame_Update(money:GetName(), math.floor(moneyAmount)) money.myLine = line:GetName() money.myLineNumber = curLine money:Show() local moneyWidth = money:GetWidth() lineWidth = lineWidth + moneyWidth + self.moneySpacing getglobal("EnhancedTooltipMoney"..curMoney.."SilverButtonText"):SetTextColor(1.0,1.0,1.0) getglobal("EnhancedTooltipMoney"..curMoney.."CopperButtonText"):SetTextColor(0.86,0.42,0.19) EnhancedTooltip.moneyCount = curMoney end lineWidth = lineWidth + 20 if (lineWidth > EnhancedTooltip.minWidth) then EnhancedTooltip.minWidth = lineWidth endendfunction addSeparator(embed) if (embed) and (self.currentGametip) then EnhancedTooltip.hasEmbed = true EnhancedTooltip.curEmbed = true table.insert(self.embedLines, {line = " "}) return end EnhancedTooltip.hasData = true EnhancedTooltip.curEmbed = false local curLine = EnhancedTooltip.lineCount +1; local line = getglobal("EnhancedTooltipText"..curLine) line:SetText(" "); line:SetTextColor(1.0, 1.0, 1.0); line:Show(); EnhancedTooltip.lineCount = curLineendfunction lineColor(r, g, b) if (EnhancedTooltip.curEmbed) and (self.currentGametip) then local n = table.getn(self.embedLines) self.embedLines[n].r = r self.embedLines[n].g = g self.embedLines[n].b = b return end local curLine = EnhancedTooltip.lineCount if (curLine == 0) then return end local line = getglobal("EnhancedTooltipText"..curLine) line:SetTextColor(r, g, b)endfunction lineSize_Large() if (EnhancedTooltip.curEmbed) and (self.currentGametip) then return end local curLine = EnhancedTooltip.lineCount if (curLine == 0) then return end local line = getglobal("EnhancedTooltipText"..curLine) line:SetFont(STANDARD_TEXT_FONT, 15)endfunction lineSize_Small() if (EnhancedTooltip.curEmbed) and (self.currentGametip) then return end local curLine = EnhancedTooltip.lineCount if (curLine == 0) then return end local line = getglobal("EnhancedTooltipText"..curLine) line:SetFont(STANDARD_TEXT_FONT, 15)endfunction lineQuality(quality) if ( quality ) then local r, g, b = GetItemQualityColor(quality) lineColor(r, g, b) else lineColor(1.0, 1.0, 1.0) endendfunction setIcon(iconPath) EnhancedTooltipIcon:SetTexture(iconPath) EnhancedTooltipIcon:Show() EnhancedTooltip.hasIcon = trueendfunction gtHookOnHide() local curName = "" local hidingName = this:GetName() if (self.currentGametip) then curName = self.currentGametip:GetName() end if (curName == hidingName) then HideObj = hidingName self.hideTime = self.eventTimer + 0.1 endendfunction doHyperlink(reference, link, button) if (ItemRefTooltip:IsVisible()) then local itemName = ItemRefTooltipTextLeft1:GetText() if (itemName and self.currentItem ~= itemName) then self.currentItem = itemName local testPopup = false if (button == "RightButton") then testPopup = true end local callRes = tooltipCall(ItemRefTooltip, itemName, link, -1, 1, 0, testPopup, reference) if (callRes == true) then self.oldChatItem = {['reference']=reference, ['link']=link, ['button']=button, ['embed']=EnhancedTooltip.hasEmbed} elseif (callRes == false) then return false; end end endendfunction checkHide() if (self.hideTime == 0) then return end if (self.eventTimer >= self.hideTime) then
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -