Advertisement
Wetxius

Untitled

Oct 17th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.53 KB | None | 0 0
  1. local T, C, L, _ = unpack(select(2, ...))
  2. if C.tooltip.enable ~= true then return end
  3.  
  4. ----------------------------------------------------------------------------------------
  5. -- Based on aTooltip(by ALZA)
  6. ----------------------------------------------------------------------------------------
  7. local StoryTooltip = QuestScrollFrame.StoryTooltip
  8. StoryTooltip:SetFrameLevel(4)
  9.  
  10. local tooltips = {
  11. GameTooltip,
  12. ItemRefTooltip,
  13. ShoppingTooltip1,
  14. ShoppingTooltip2,
  15. WorldMapTooltip.BackdropFrame,
  16. WorldMapCompareTooltip1,
  17. WorldMapCompareTooltip2,
  18. FriendsTooltip,
  19. ItemRefShoppingTooltip1,
  20. ItemRefShoppingTooltip2,
  21. AtlasLootTooltip,
  22. QuestHelperTooltip,
  23. QuestGuru_QuestWatchTooltip,
  24. StoryTooltip
  25. }
  26.  
  27. local backdrop = {
  28. bgFile = C.media.blank, edgeFile = C.media.blank, edgeSize = T.mult,
  29. insets = {left = -T.mult, right = -T.mult, top = -T.mult, bottom = -T.mult}
  30. }
  31.  
  32. for _, tt in pairs(tooltips) do
  33. if not IsAddOnLoaded("Aurora") then
  34. tt:SetBackdrop(nil)
  35. if tt.BackdropFrame then
  36. tt.BackdropFrame:SetBackdrop(nil)
  37. end
  38. local bg = CreateFrame("Frame", nil, tt)
  39. bg:SetPoint("TOPLEFT")
  40. bg:SetPoint("BOTTOMRIGHT")
  41. bg:SetFrameLevel(tt:GetFrameLevel() - 1)
  42. bg:SetTemplate("Transparent")
  43.  
  44. tt.GetBackdrop = function() return backdrop end
  45. tt.GetBackdropColor = function() return unpack(C.media.overlay_color) end
  46. tt.GetBackdropBorderColor = function() return unpack(C.media.border_color) end
  47. end
  48. end
  49.  
  50. local anchor = CreateFrame("Frame", "TooltipAnchor", UIParent)
  51. anchor:SetSize(200, 40)
  52. anchor:SetPoint(unpack(C.position.tooltip))
  53.  
  54. -- Hide PVP text
  55. PVP_ENABLED = ""
  56.  
  57. -- Statusbar
  58. GameTooltipStatusBar:SetStatusBarTexture(C.media.texture)
  59. GameTooltipStatusBar:SetHeight(4)
  60. GameTooltipStatusBar:ClearAllPoints()
  61. GameTooltipStatusBar:SetPoint("TOPLEFT", GameTooltip, "BOTTOMLEFT", 2, 6)
  62. GameTooltipStatusBar:SetPoint("TOPRIGHT", GameTooltip, "BOTTOMRIGHT", -2, 6)
  63.  
  64. -- Raid icon
  65. local ricon = GameTooltip:CreateTexture("GameTooltipRaidIcon", "OVERLAY")
  66. ricon:SetHeight(18)
  67. ricon:SetWidth(18)
  68. ricon:SetPoint("BOTTOM", GameTooltip, "TOP", 0, 5)
  69.  
  70. GameTooltip:HookScript("OnHide", function(self) ricon:SetTexture(nil) end)
  71.  
  72. -- Add "Targeted By" line
  73. local targetedList = {}
  74. local ClassColors = {}
  75. local token
  76. for class, color in next, RAID_CLASS_COLORS do
  77. ClassColors[class] = ("|cff%.2x%.2x%.2x"):format(color.r * 255, color.g * 255, color.b * 255)
  78. end
  79.  
  80. local function AddTargetedBy()
  81. local numParty, numRaid = GetNumSubgroupMembers(), GetNumGroupMembers()
  82. if numParty > 0 or numRaid > 0 then
  83. for i = 1, (numRaid > 0 and numRaid or numParty) do
  84. local unit = (numRaid > 0 and "raid"..i or "party"..i)
  85. if UnitIsUnit(unit.."target", token) and not UnitIsUnit(unit, "player") then
  86. local _, class = UnitClass(unit)
  87. targetedList[#targetedList + 1] = ClassColors[class]
  88. targetedList[#targetedList + 1] = UnitName(unit)
  89. targetedList[#targetedList + 1] = "|r, "
  90. end
  91. end
  92. if #targetedList > 0 then
  93. targetedList[#targetedList] = nil
  94. GameTooltip:AddLine(" ", nil, nil, nil, 1)
  95. local line = _G["GameTooltipTextLeft"..GameTooltip:NumLines()]
  96. if not line then return end
  97. line:SetFormattedText(L_TOOLTIP_WHO_TARGET.." (|cffffffff%d|r): %s", (#targetedList + 1) / 3, table.concat(targetedList))
  98. wipe(targetedList)
  99. end
  100. end
  101. end
  102.  
  103. ----------------------------------------------------------------------------------------
  104. -- Unit tooltip styling
  105. ----------------------------------------------------------------------------------------
  106. function GameTooltip_UnitColor(unit)
  107. if not unit then return end
  108. local r, g, b
  109.  
  110. if UnitIsPlayer(unit) then
  111. local _, class = UnitClass(unit)
  112. local color = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[class]
  113. if color then
  114. r, g, b = color.r, color.g, color.b
  115. else
  116. r, g, b = 1, 1, 1
  117. end
  118. elseif UnitIsTapDenied(unit) or UnitIsDead(unit) then
  119. r, g, b = 0.6, 0.6, 0.6
  120. else
  121. local reaction = T.oUF_colors.reaction[UnitReaction(unit, "player")]
  122. if reaction then
  123. r, g, b = reaction[1], reaction[2], reaction[3]
  124. else
  125. r, g, b = 1, 1, 1
  126. end
  127. end
  128.  
  129. return r, g, b
  130. end
  131.  
  132. local function GameTooltipDefault(tooltip, parent)
  133. if C.tooltip.cursor == true then
  134. tooltip:SetOwner(parent, "ANCHOR_CURSOR_RIGHT", 20, 20)
  135. else
  136. tooltip:SetOwner(parent, "ANCHOR_NONE")
  137. tooltip:ClearAllPoints()
  138. tooltip:SetPoint("BOTTOMRIGHT", TooltipAnchor, "BOTTOMRIGHT", 0, 0)
  139. tooltip.default = 1
  140. end
  141. end
  142. hooksecurefunc("GameTooltip_SetDefaultAnchor", GameTooltipDefault)
  143.  
  144. if C.tooltip.shift_modifer == true then
  145. local ShiftShow = function()
  146. if IsShiftKeyDown() then
  147. GameTooltip:Show()
  148. else
  149. if not HoverBind.enabled then
  150. GameTooltip:Hide()
  151. end
  152. end
  153. end
  154. GameTooltip:SetScript("OnShow", ShiftShow)
  155. local EventShow = function()
  156. if arg1 == "LSHIFT" and arg2 == 1 then
  157. GameTooltip:Show()
  158. elseif arg1 == "LSHIFT" and arg2 == 0 then
  159. GameTooltip:Hide()
  160. end
  161. end
  162. local sh = CreateFrame("Frame")
  163. sh:RegisterEvent("MODIFIER_STATE_CHANGED")
  164. sh:SetScript("OnEvent", EventShow)
  165. else
  166. if C.tooltip.cursor == true then
  167. hooksecurefunc("GameTooltip_SetDefaultAnchor", function(self, parent)
  168. if InCombatLockdown() and C.tooltip.hide_combat and not IsShiftKeyDown() then
  169. self:Hide()
  170. else
  171. self:SetOwner(parent, "ANCHOR_CURSOR_RIGHT", 20, 20)
  172. end
  173. end)
  174. else
  175. hooksecurefunc("GameTooltip_SetDefaultAnchor", function(self)
  176. if InCombatLockdown() and C.tooltip.hide_combat and not IsShiftKeyDown() then
  177. self:Hide()
  178. else
  179. self:SetPoint("BOTTOMRIGHT", TooltipAnchor, "BOTTOMRIGHT", 0, 0)
  180. end
  181. end)
  182. end
  183. end
  184.  
  185. if C.tooltip.health_value == true then
  186. GameTooltipStatusBar:SetScript("OnValueChanged", function(self, value)
  187. if not value then return end
  188. local min, max = self:GetMinMaxValues()
  189. if (value < min) or (value > max) then return end
  190. self:SetStatusBarColor(0, 1, 0)
  191. local _, unit = GameTooltip:GetUnit()
  192. if unit then
  193. min, max = UnitHealth(unit), UnitHealthMax(unit)
  194. if not self.text then
  195. self.text = self:CreateFontString(nil, "OVERLAY", "Tooltip_Med")
  196. self.text:SetPoint("CENTER", GameTooltipStatusBar, 0, 1.5)
  197. end
  198. self.text:Show()
  199. local hp = T.ShortValue(min).." / "..T.ShortValue(max)
  200. self.text:SetText(hp)
  201. end
  202. end)
  203. end
  204.  
  205. local OnTooltipSetUnit = function(self)
  206. local lines = self:NumLines()
  207. local unit = (select(2, self:GetUnit())) or (GetMouseFocus() and GetMouseFocus():GetAttribute("unit")) or (UnitExists("mouseover") and "mouseover") or nil
  208.  
  209. if not unit then return end
  210.  
  211. local name, realm = UnitName(unit)
  212. local race, englishRace = UnitRace(unit)
  213. local level = UnitLevel(unit)
  214. local levelColor = GetQuestDifficultyColor(level)
  215. local classification = UnitClassification(unit)
  216. local creatureType = UnitCreatureType(unit)
  217. local _, faction = UnitFactionGroup(unit)
  218. local _, playerFaction = UnitFactionGroup("player")
  219. local relationship = UnitRealmRelationship(unit)
  220. local UnitPVPName = UnitPVPName
  221.  
  222. if level and level == -1 then
  223. if classification == "worldboss" then
  224. level = "|cffff0000|r"..ENCOUNTER_JOURNAL_ENCOUNTER
  225. else
  226. level = "|cffff0000??|r"
  227. end
  228. end
  229.  
  230. if classification == "rareelite" then classification = " R+"
  231. elseif classification == "rare" then classification = " R"
  232. elseif classification == "elite" then classification = "+"
  233. else classification = "" end
  234.  
  235.  
  236. if UnitPVPName(unit) and C.tooltip.title then
  237. name = UnitPVPName(unit)
  238. end
  239.  
  240. _G["GameTooltipTextLeft1"]:SetText(name)
  241. if realm and realm ~= "" and C.tooltip.realm then
  242. self:AddLine(FRIENDS_LIST_REALM.."|cffffffff"..realm.."|r")
  243. end
  244.  
  245.  
  246. if UnitIsPlayer(unit) then
  247. if UnitIsAFK(unit) then
  248. self:AppendText((" %s"):format("|cffE7E716"..L_CHAT_AFK.."|r"))
  249. elseif UnitIsDND(unit) then
  250. self:AppendText((" %s"):format("|cffFF0000"..L_CHAT_DND.."|r"))
  251. end
  252.  
  253. if UnitIsPlayer(unit) and englishRace == "Pandaren" and faction ~= nil and faction ~= playerFaction then
  254. local hex = "cffff3333"
  255. if faction == "Alliance" then
  256. hex = "cff69ccf0"
  257. end
  258. self:AppendText((" [|%s%s|r]"):format(hex, faction:sub(1, 2)))
  259. end
  260.  
  261. if GetGuildInfo(unit) then
  262. _G["GameTooltipTextLeft2"]:SetFormattedText("%s", GetGuildInfo(unit))
  263. if UnitIsInMyGuild(unit) then
  264. _G["GameTooltipTextLeft2"]:SetTextColor(1, 1, 0)
  265. else
  266. _G["GameTooltipTextLeft2"]:SetTextColor(0, 1, 1)
  267. end
  268. end
  269.  
  270. local n = GetGuildInfo(unit) and 3 or 2
  271. -- thx TipTac for the fix above with color blind enabled
  272. if GetCVar("colorblindMode") == "1" then n = n + 1 end
  273. _G["GameTooltipTextLeft"..n]:SetFormattedText("|cff%02x%02x%02x%s|r %s", levelColor.r * 255, levelColor.g * 255, levelColor.b * 255, level, race or UNKNOWN)
  274.  
  275. for i = 2, lines do
  276. local line = _G["GameTooltipTextLeft"..i]
  277. if not line or not line:GetText() then return end
  278. if line and line:GetText() and (line:GetText() == FACTION_HORDE or line:GetText() == FACTION_ALLIANCE) then
  279. line:SetText()
  280. break
  281. end
  282. end
  283. else
  284. for i = 2, lines do
  285. local line = _G["GameTooltipTextLeft"..i]
  286. if not line or not line:GetText() or UnitIsBattlePetCompanion(unit) then return end
  287. if (level and line:GetText():find("^"..LEVEL)) or (creatureType and line:GetText():find("^"..creatureType)) then
  288. local r, g, b = GameTooltip_UnitColor(unit)
  289. line:SetFormattedText("|cff%02x%02x%02x%s%s|r %s", levelColor.r * 255, levelColor.g * 255, levelColor.b * 255, level, classification, creatureType or "")
  290. break
  291. end
  292. end
  293. end
  294.  
  295. if C.tooltip.target == true and UnitExists(unit.."target") then
  296. local r, g, b = GameTooltip_UnitColor(unit.."target")
  297. local text = ""
  298.  
  299. if UnitIsEnemy("player", unit.."target") then
  300. r, g, b = unpack(T.oUF_colors.reaction[1])
  301. elseif not UnitIsFriend("player", unit.."target") then
  302. r, g, b = unpack(T.oUF_colors.reaction[4])
  303. end
  304.  
  305. if UnitName(unit.."target") == UnitName("player") then
  306. text = "|cfffed100"..STATUS_TEXT_TARGET..":|r ".."|cffff0000> "..UNIT_YOU.." <|r"
  307. else
  308. text = "|cfffed100"..STATUS_TEXT_TARGET..":|r "..UnitName(unit.."target")
  309. end
  310.  
  311. self:AddLine(text, r, g, b)
  312. end
  313.  
  314. if C.tooltip.raid_icon == true then
  315. local raidIndex = GetRaidTargetIndex(unit)
  316. if raidIndex then
  317. ricon:SetTexture("Interface\\TargetingFrame\\UI-RaidTargetingIcon_"..raidIndex)
  318. end
  319. end
  320.  
  321. if C.tooltip.who_targetting == true then
  322. token = unit AddTargetedBy()
  323. end
  324. end
  325.  
  326. GameTooltip:HookScript("OnTooltipSetUnit", OnTooltipSetUnit)
  327.  
  328. ----------------------------------------------------------------------------------------
  329. -- Adds guild rank to tooltips(GuildRank by Meurtcriss)
  330. ----------------------------------------------------------------------------------------
  331. if C.tooltip.rank == true then
  332. GameTooltip:HookScript("OnTooltipSetUnit", function(self, ...)
  333. -- Get the unit
  334. local _, unit = self:GetUnit()
  335. if not unit then
  336. local mFocus = GetMouseFocus()
  337. if mFocus and mFocus.unit then
  338. unit = mFocus.unit
  339. end
  340. end
  341. -- Get and display guild rank
  342. if UnitIsPlayer(unit) then
  343. local guildName, guildRank = GetGuildInfo(unit)
  344. if guildName then
  345. self:AddLine(RANK..": |cffffffff"..guildRank.."|r")
  346. end
  347. end
  348. end)
  349. end
  350.  
  351. ----------------------------------------------------------------------------------------
  352. -- Hide tooltips in combat for action bars, pet bar and stance bar
  353. ----------------------------------------------------------------------------------------
  354. if C.tooltip.hidebuttons == true then
  355. local CombatHideActionButtonsTooltip = function(self)
  356. if not IsShiftKeyDown() then
  357. self:Hide()
  358. end
  359. end
  360.  
  361. hooksecurefunc(GameTooltip, "SetAction", CombatHideActionButtonsTooltip)
  362. hooksecurefunc(GameTooltip, "SetPetAction", CombatHideActionButtonsTooltip)
  363. hooksecurefunc(GameTooltip, "SetShapeshift", CombatHideActionButtonsTooltip)
  364. end
  365.  
  366. ----------------------------------------------------------------------------------------
  367. -- Fix compare tooltips(by Blizzard)(../FrameXML/GameTooltip.lua)
  368. ----------------------------------------------------------------------------------------
  369. hooksecurefunc("GameTooltip_ShowCompareItem", function(self, anchorFrame)
  370. if ( not self ) then
  371. self = GameTooltip;
  372. end
  373.  
  374. if( not anchorFrame ) then
  375. anchorFrame = self.overrideComparisonAnchorFrame or self;
  376. end
  377.  
  378. if ( self.needsReset ) then
  379. self:ResetSecondaryCompareItem();
  380. GameTooltip_AdvanceSecondaryCompareItem(self);
  381. self.needsReset = false;
  382. end
  383.  
  384. local shoppingTooltip1, shoppingTooltip2 = unpack(self.shoppingTooltips);
  385.  
  386. local primaryItemShown, secondaryItemShown = shoppingTooltip1:SetCompareItem(shoppingTooltip2, self);
  387.  
  388. local leftPos = anchorFrame:GetLeft();
  389. local rightPos = anchorFrame:GetRight();
  390.  
  391. local side;
  392. local anchorType = self:GetAnchorType();
  393. local totalWidth = 0;
  394. if ( primaryItemShown ) then
  395. totalWidth = totalWidth + shoppingTooltip1:GetWidth();
  396. end
  397. if ( secondaryItemShown ) then
  398. totalWidth = totalWidth + shoppingTooltip2:GetWidth();
  399. end
  400. if ( self.overrideComparisonAnchorSide ) then
  401. side = self.overrideComparisonAnchorSide;
  402. else
  403. -- find correct side
  404. local rightDist = 0;
  405. if ( not rightPos ) then
  406. rightPos = 0;
  407. end
  408. if ( not leftPos ) then
  409. leftPos = 0;
  410. end
  411.  
  412. rightDist = GetScreenWidth() - rightPos;
  413.  
  414. if ( anchorType and totalWidth < leftPos and (anchorType == "ANCHOR_LEFT" or anchorType == "ANCHOR_TOPLEFT" or anchorType == "ANCHOR_BOTTOMLEFT") ) then
  415. side = "left";
  416. elseif ( anchorType and totalWidth < rightDist and (anchorType == "ANCHOR_RIGHT" or anchorType == "ANCHOR_TOPRIGHT" or anchorType == "ANCHOR_BOTTOMRIGHT") ) then
  417. side = "right";
  418. elseif ( rightDist < leftPos ) then
  419. side = "left";
  420. else
  421. side = "right";
  422. end
  423. end
  424.  
  425. -- see if we should slide the tooltip
  426. if ( anchorType and anchorType ~= "ANCHOR_PRESERVE" ) then
  427. if ( (side == "left") and (totalWidth > leftPos) ) then
  428. self:SetAnchorType(anchorType, (totalWidth - leftPos), 0);
  429. elseif ( (side == "right") and (rightPos + totalWidth) > GetScreenWidth() ) then
  430. self:SetAnchorType(anchorType, -((rightPos + totalWidth) - GetScreenWidth()), 0);
  431. end
  432. end
  433.  
  434. if ( secondaryItemShown ) then
  435. shoppingTooltip2:SetOwner(self, "ANCHOR_NONE");
  436. shoppingTooltip2:ClearAllPoints();
  437. shoppingTooltip1:SetOwner(self, "ANCHOR_NONE");
  438. shoppingTooltip1:ClearAllPoints();
  439.  
  440. if ( side and side == "left" ) then
  441. shoppingTooltip1:SetPoint("TOPRIGHT", anchorFrame, "TOPLEFT", -3, -10);
  442. else
  443. shoppingTooltip2:SetPoint("TOPLEFT", anchorFrame, "TOPRIGHT", 3, -10);
  444. end
  445.  
  446. if ( side and side == "left" ) then
  447. shoppingTooltip2:SetPoint("TOPRIGHT", shoppingTooltip1, "TOPLEFT", -3, 0);
  448. else
  449. shoppingTooltip1:SetPoint("TOPLEFT", shoppingTooltip2, "TOPRIGHT", 3, 0);
  450. end
  451. else
  452. shoppingTooltip1:SetOwner(self, "ANCHOR_NONE");
  453. shoppingTooltip1:ClearAllPoints();
  454.  
  455. if ( side and side == "left" ) then
  456. shoppingTooltip1:SetPoint("TOPRIGHT", anchorFrame, "TOPLEFT", -3, -10);
  457. else
  458. shoppingTooltip1:SetPoint("TOPLEFT", anchorFrame, "TOPRIGHT", 3, -10);
  459. end
  460.  
  461. shoppingTooltip2:Hide();
  462. end
  463.  
  464. -- We have to call this again because :SetOwner clears the tooltip.
  465. shoppingTooltip1:SetCompareItem(shoppingTooltip2, self);
  466. shoppingTooltip1:Show();
  467. end)
  468.  
  469. ----------------------------------------------------------------------------------------
  470. -- Fix GameTooltipMoneyFrame font size
  471. ----------------------------------------------------------------------------------------
  472. local function FixFont(self)
  473. for i = 1, 2 do
  474. if _G["GameTooltipMoneyFrame"..i] then
  475. _G["GameTooltipMoneyFrame"..i.."PrefixText"]:SetFontObject("GameTooltipText")
  476. _G["GameTooltipMoneyFrame"..i.."SuffixText"]:SetFontObject("GameTooltipText")
  477. _G["GameTooltipMoneyFrame"..i.."GoldButton"]:SetNormalFontObject("GameTooltipText")
  478. _G["GameTooltipMoneyFrame"..i.."SilverButton"]:SetNormalFontObject("GameTooltipText")
  479. _G["GameTooltipMoneyFrame"..i.."CopperButton"]:SetNormalFontObject("GameTooltipText")
  480. end
  481. end
  482. for i = 1, 2 do
  483. if _G["ItemRefTooltipMoneyFrame"..i] then
  484. _G["ItemRefTooltipMoneyFrame"..i.."PrefixText"]:SetFontObject("GameTooltipText")
  485. _G["ItemRefTooltipMoneyFrame"..i.."SuffixText"]:SetFontObject("GameTooltipText")
  486. _G["ItemRefTooltipMoneyFrame"..i.."GoldButton"]:SetNormalFontObject("GameTooltipText")
  487. _G["ItemRefTooltipMoneyFrame"..i.."SilverButton"]:SetNormalFontObject("GameTooltipText")
  488. _G["ItemRefTooltipMoneyFrame"..i.."CopperButton"]:SetNormalFontObject("GameTooltipText")
  489. end
  490. end
  491. end
  492.  
  493. GameTooltip:HookScript("OnTooltipSetItem", FixFont)
  494. ItemRefTooltip:HookScript("OnTooltipSetItem", FixFont)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement