Advertisement
Guest User

main.lua

a guest
Jan 24th, 2020
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.18 KB | None | 0 0
  1. -- constants borrowed from PersonalLootHelper
  2. local PLH_RELIC_TOOLTIP_TYPE_PATTERN = _G.RELIC_TOOLTIP_TYPE:gsub('%%s', '(.+)')
  3. local PLH_ITEM_LEVEL_PATTERN = _G.ITEM_LEVEL:gsub('%%d', '(%%d+)')
  4.  
  5. local frame = CreateFrame("Frame", "ItemLinkLevel");
  6. frame:RegisterEvent("PLAYER_LOGIN");
  7. local tooltip
  8. local socketTooltip
  9.  
  10. -- Inhibit Regular Expression magic characters ^$()%.[]*+-?)
  11. local function EscapeSearchString(str)
  12. return str:gsub("(%W)","%%%1")
  13. end
  14.  
  15. -- function borrowed from PersonalLootHelper
  16. local function CreateEmptyTooltip()
  17. local tip = CreateFrame('GameTooltip')
  18. local leftside = {}
  19. local rightside = {}
  20. local L, R
  21. for i = 1, 6 do
  22. L, R = tip:CreateFontString(), tip:CreateFontString()
  23. L:SetFontObject(GameFontNormal)
  24. R:SetFontObject(GameFontNormal)
  25. tip:AddFontStrings(L, R)
  26. leftside[i] = L
  27. rightside[i] = R
  28. end
  29. tip.leftside = leftside
  30. tip.rightside = rightside
  31. return tip
  32. end
  33.  
  34. -- function borrowed from PersonalLootHelper
  35. local function PLH_GetRelicType(item)
  36. local relicType = nil
  37.  
  38. if item ~= nil then
  39. tooltip = tooltip or CreateEmptyTooltip()
  40. tooltip:SetOwner(UIParent, 'ANCHOR_NONE')
  41. tooltip:ClearLines()
  42. tooltip:SetHyperlink(item)
  43. local t = tooltip.leftside[2]:GetText()
  44.  
  45. local index = 1
  46. local t
  47. while not relicType and tooltip.leftside[index] do
  48. t = tooltip.leftside[index]:GetText()
  49. if t ~= nil then
  50. relicType = t:match(PLH_RELIC_TOOLTIP_TYPE_PATTERN)
  51. end
  52. index = index + 1
  53. end
  54.  
  55. tooltip:Hide()
  56. end
  57.  
  58. return relicType
  59. end
  60.  
  61. -- function borrowed from PersonalLootHelper
  62. local function PLH_GetRealILVL(item)
  63. local realILVL = nil
  64.  
  65. if item ~= nil then
  66. tooltip = tooltip or CreateEmptyTooltip()
  67. tooltip:SetOwner(UIParent, 'ANCHOR_NONE')
  68. tooltip:ClearLines()
  69. tooltip:SetHyperlink(item)
  70. local t = tooltip.leftside[2]:GetText()
  71. if t ~= nil then
  72. -- realILVL = t:match('Item Level (%d+)')
  73. realILVL = t:match(PLH_ITEM_LEVEL_PATTERN)
  74. end
  75. -- ilvl can be in the 2nd or 3rd line dependng on the tooltip; if we didn't find it in 2nd, try 3rd
  76. if realILVL == nil then
  77. t = tooltip.leftside[3]:GetText()
  78. if t ~= nil then
  79. -- realILVL = t:match('Item Level (%d+)')
  80. realILVL = t:match(PLH_ITEM_LEVEL_PATTERN)
  81. end
  82. end
  83. tooltip:Hide()
  84.  
  85. -- if realILVL is still nil, we couldn't find it in the tooltip - try grabbing it from getItemInfo, even though
  86. -- that doesn't return upgrade levels
  87. if realILVL == nil then
  88. _, _, _, realILVL, _, _, _, _, _, _, _ = GetItemInfo(item)
  89. end
  90. end
  91.  
  92. if realILVL == nil then
  93. return 0
  94. else
  95. return tonumber(realILVL)
  96. end
  97. end
  98.  
  99. local function ItemHasSockets(itemLink)
  100. local result = false
  101. socketTooltip = socketTooltip or CreateFrame("GameTooltip", "ItemLinkLevelSocketTooltip", nil, "GameTooltipTemplate")
  102. socketTooltip:SetOwner(UIParent, 'ANCHOR_NONE')
  103. socketTooltip:ClearLines()
  104. for i = 1, 30 do
  105. local texture = _G[socketTooltip:GetName().."Texture"..i]
  106. if texture then
  107. texture:SetTexture(nil)
  108. end
  109. end
  110. socketTooltip:SetHyperlink(itemLink)
  111. for i = 1, 30 do
  112. local texture = _G[socketTooltip:GetName().."Texture"..i]
  113. local textureName = texture and texture:GetTexture()
  114.  
  115. if textureName then
  116. local canonicalTextureName = string.gsub(string.upper(textureName), "\\", "/")
  117. result = string.find(canonicalTextureName, EscapeSearchString("ITEMSOCKETINGFRAME/UI-EMPTYSOCKET-")) or string.find(canonicalTextureName, EscapeSearchString("458977"))
  118. end
  119. end
  120. return result
  121. end
  122.  
  123. local function Filter(self, event, message, user, ...)
  124. for itemLink in message:gmatch("|%x+|Hitem:.-|h.-|h|r") do
  125. local itemName, _, quality, _, _, itemType, itemSubType, _, itemEquipLoc, _, _, itemClassId, itemSubClassId = GetItemInfo(itemLink)
  126. if (quality ~= nil and quality >= SavedData.trigger_quality and (itemClassId == LE_ITEM_CLASS_WEAPON or itemClassId == LE_ITEM_CLASS_GEM or itemClassId == LE_ITEM_CLASS_ARMOR)) then
  127. local itemString = string.match(itemLink, "item[%-?%d:]+")
  128. local _, _, color = string.find(itemLink, "|?c?f?f?(%x*)|?H?([^:]*):?(%d+):?(%d*):?(%d*):?(%d*):?(%d*):?(%d*):?(%-?%d*):?(%-?%d*):?(%d*):?(%d*):?(%-?%d*)|?h?%[?([^%[%]]*)%]?|?h?|?r?")
  129. local iLevel = PLH_GetRealILVL(itemLink)
  130.  
  131. local attrs = {}
  132. if (SavedData.show_subtype and itemSubType ~= nil) then
  133. if (itemClassId == LE_ITEM_CLASS_ARMOR and itemSubClassId == 0) then
  134. -- don't display Miscellaneous for rings, necks and trinkets
  135. elseif (itemClassId == LE_ITEM_CLASS_ARMOR and itemEquipLoc == "INVTYPE_CLOAK") then
  136. -- don't display Cloth for cloaks
  137. else
  138. if (SavedData.subtype_short_format) then
  139. table.insert(attrs, itemSubType:sub(0, 1))
  140. else
  141. table.insert(attrs, itemSubType)
  142. end
  143. end
  144. if (itemClassId == LE_ITEM_CLASS_GEM and itemSubClassId == LE_ITEM_ARMOR_RELIC) then
  145. local relicType = PLH_GetRelicType(itemLink)
  146. table.insert(attrs, relicType)
  147. end
  148. end
  149. if (SavedData.show_equiploc and itemEquipLoc ~= nil and _G[itemEquipLoc] ~= nil) then table.insert(attrs, _G[itemEquipLoc]) end
  150. if (SavedData.show_ilevel and iLevel ~= nil) then
  151. local txt = iLevel
  152. if (ItemHasSockets(itemLink)) then txt = txt .. "+S" end
  153. table.insert(attrs, txt)
  154. end
  155.  
  156. local newItemName = itemName.." ("..table.concat(attrs, " ")..")"
  157. local newLink = "|cff"..color.."|H"..itemString.."|h["..newItemName.."]|h|r"
  158.  
  159. message = string.gsub(message, EscapeSearchString(itemLink), newLink)
  160. end
  161. end
  162. return false, message, user, ...
  163. end
  164.  
  165. local function EventHandler(self, event, ...)
  166. if (SavedData == nil) then SavedData = {} end
  167. if (SavedData.trigger_loots == nil) then SavedData.trigger_loots = true end
  168. if (SavedData.trigger_chat == nil) then SavedData.trigger_chat = true end
  169. if (SavedData.trigger_quality == nil) then SavedData.trigger_quality = 3 end
  170. if (SavedData.show_subtype == nil) then SavedData.show_subtype = true end
  171. if (SavedData.subtype_short_format == nil) then SavedData.subtype_short_format = false end
  172. if (SavedData.show_equiploc == nil) then SavedData.show_equiploc = true end
  173. if (SavedData.show_ilevel == nil) then SavedData.show_ilevel = true end
  174.  
  175. if (SavedData.trigger_loots) then
  176. ChatFrame_AddMessageEventFilter("CHAT_MSG_LOOT", Filter);
  177. end
  178.  
  179. if (SavedData.trigger_chat) then
  180. ChatFrame_AddMessageEventFilter("CHAT_MSG_BATTLEGROUND", Filter);
  181. ChatFrame_AddMessageEventFilter("CHAT_MSG_BATTLEGROUND_LEADER", Filter);
  182. ChatFrame_AddMessageEventFilter("CHAT_MSG_CHANNEL", Filter);
  183. ChatFrame_AddMessageEventFilter("CHAT_MSG_EMOTE", Filter);
  184. ChatFrame_AddMessageEventFilter("CHAT_MSG_GUILD", Filter);
  185. ChatFrame_AddMessageEventFilter("CHAT_MSG_INSTANCE_CHAT", Filter);
  186. ChatFrame_AddMessageEventFilter("CHAT_MSG_INSTANCE_CHAT_LEADER", Filter);
  187. ChatFrame_AddMessageEventFilter("CHAT_MSG_OFFICER", Filter);
  188. ChatFrame_AddMessageEventFilter("CHAT_MSG_PARTY", Filter);
  189. ChatFrame_AddMessageEventFilter("CHAT_MSG_PARTY_LEADER", Filter);
  190. ChatFrame_AddMessageEventFilter("CHAT_MSG_RAID", Filter);
  191. ChatFrame_AddMessageEventFilter("CHAT_MSG_RAID_LEADER", Filter);
  192. ChatFrame_AddMessageEventFilter("CHAT_MSG_RAID_WARNING", Filter);
  193. ChatFrame_AddMessageEventFilter("CHAT_MSG_SAY", Filter);
  194. ChatFrame_AddMessageEventFilter("CHAT_MSG_WHISPER", Filter);
  195. ChatFrame_AddMessageEventFilter("CHAT_MSG_WHISPER_INFORM", Filter)
  196. ChatFrame_AddMessageEventFilter("CHAT_MSG_YELL", Filter);
  197. end
  198.  
  199. local panel = CreateFrame("Frame", "OptionsPanel", UIParent)
  200. panel.name = "ItemLinkLevel"
  201.  
  202. local subtypeCheckBox = CreateFrame("CheckButton", "subtypeCheckBox", panel, "UICheckButtonTemplate")
  203. subtypeCheckBox:SetPoint("TOPLEFT",10, -30)
  204. subtypeCheckBox:SetChecked(SavedData.show_subtype)
  205. _G[subtypeCheckBox:GetName().."Text"]:SetText("Display armor/weapon type (Plate, Leather, ...)")
  206. subtypeCheckBox:SetScript("OnClick", function(self) SavedData.show_subtype = self:GetChecked() end)
  207.  
  208. local subtypeShortCheckBox = CreateFrame("CheckButton", "subtypeShortCheckBox", panel, "UICheckButtonTemplate")
  209. subtypeShortCheckBox:SetPoint("TOPLEFT",30, -60)
  210. subtypeShortCheckBox:SetChecked(SavedData.subtype_short_format)
  211. _G[subtypeShortCheckBox:GetName().."Text"]:SetText("Short format (P for plate, L for leather, ...)")
  212. subtypeShortCheckBox:SetScript("OnClick", function(self) SavedData.subtype_short_format = self:GetChecked() end)
  213.  
  214. local equipLocCheckbox = CreateFrame("CheckButton", "equipLocCheckbox", panel, "UICheckButtonTemplate")
  215. equipLocCheckbox:SetPoint("TOPLEFT",10, -90)
  216. equipLocCheckbox:SetChecked(SavedData.show_equiploc)
  217. _G[equipLocCheckbox:GetName().."Text"]:SetText("Display equip location (Head, Trinket, ...)")
  218. equipLocCheckbox:SetScript("OnClick", function(self) SavedData.show_equiploc = self:GetChecked() end)
  219.  
  220. local iLevelCheckbox = CreateFrame("CheckButton", "iLevelCheckbox", panel, "UICheckButtonTemplate")
  221. iLevelCheckbox:SetPoint("TOPLEFT",10, -120)
  222. iLevelCheckbox:SetChecked(SavedData.show_ilevel)
  223. _G[iLevelCheckbox:GetName().."Text"]:SetText("Display item level")
  224. iLevelCheckbox:SetScript("OnClick", function(self) SavedData.show_ilevel = self:GetChecked() end)
  225.  
  226. local triggerLootsCheckbox = CreateFrame("CheckButton", "triggerLootsCheckbox", panel, "UICheckButtonTemplate")
  227. triggerLootsCheckbox:SetPoint("TOPLEFT",10, -180)
  228. triggerLootsCheckbox:SetChecked(SavedData.trigger_loots)
  229. _G[triggerLootsCheckbox:GetName().."Text"]:SetText("Trigger on loots (requires restart)")
  230. triggerLootsCheckbox:SetScript("OnClick", function(self) SavedData.trigger_loots = self:GetChecked() end)
  231.  
  232. local triggerChatCheckbox = CreateFrame("CheckButton", "triggerChatCheckbox", panel, "UICheckButtonTemplate")
  233. triggerChatCheckbox:SetPoint("TOPLEFT",10, -210)
  234. triggerChatCheckbox:SetChecked(SavedData.trigger_chat)
  235. _G[triggerChatCheckbox:GetName().."Text"]:SetText("Trigger on chat messages (requires restart)")
  236. triggerChatCheckbox:SetScript("OnClick", function(self) SavedData.trigger_chat = self:GetChecked() end)
  237.  
  238. local triggerQualityLabel = panel:CreateFontString("triggerQualityLabel", panel, "GameFontNormal")
  239. triggerQualityLabel:SetText("Minimum trigger quality")
  240. triggerQualityLabel:SetPoint("TOPLEFT",10,-260)
  241. local triggerQualityValue = panel:CreateFontString("triggerQualityValue", panel, "GameFontNormal")
  242. local triggerQualitySlider = CreateFrame("Slider", "MySliderGlobalName", panel, "OptionsSliderTemplate")
  243. triggerQualitySlider:SetPoint("LEFT", triggerQualityLabel, "RIGHT", 10, 0)
  244. triggerQualitySlider:SetMinMaxValues(0, 6)
  245. triggerQualitySlider:SetValue(SavedData.trigger_quality)
  246. triggerQualitySlider:SetValueStep(1)
  247. getglobal(triggerQualitySlider:GetName() .. 'Low'):SetText(_G["ITEM_QUALITY0_DESC"])
  248. getglobal(triggerQualitySlider:GetName() .. 'High'):SetText(_G["ITEM_QUALITY6_DESC"])
  249. triggerQualitySlider:SetScript("OnValueChanged", function(self, value)
  250. value = math.floor(value)
  251. SavedData.trigger_quality = value
  252. triggerQualityValue:SetText(_G["ITEM_QUALITY"..value.."_DESC"])
  253. end)
  254.  
  255. triggerQualityValue:SetText(_G["ITEM_QUALITY"..SavedData.trigger_quality.."_DESC"])
  256. triggerQualityValue:SetPoint("LEFT", triggerQualitySlider, "RIGHT", 10, 0)
  257.  
  258. InterfaceOptions_AddCategory(panel)
  259. end
  260. frame:SetScript("OnEvent", EventHandler);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement