Advertisement
Guest User

main.lua

a guest
Jan 22nd, 2020
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.45 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 ItemHasCorruption(itemLink)
  124. local result = false
  125. local isCorruptedItem = IsCorruptedItem(itemLink)
  126.  
  127. if isCorruptedItem ~=nil then
  128. result = isCorruptedItem
  129. end
  130.  
  131. return result
  132. end
  133.  
  134. local function Filter(self, event, message, user, ...)
  135. for itemLink in message:gmatch("|%x+|Hitem:.-|h.-|h|r") do
  136. local itemName, _, quality, _, _, itemType, itemSubType, _, itemEquipLoc, _, _, itemClassId, itemSubClassId = GetItemInfo(itemLink)
  137. 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
  138. local itemString = string.match(itemLink, "item[%-?%d:]+")
  139. local _, _, color = string.find(itemLink, "|?c?f?f?(%x*)|?H?([^:]*):?(%d+):?(%d*):?(%d*):?(%d*):?(%d*):?(%d*):?(%-?%d*):?(%-?%d*):?(%d*):?(%d*):?(%-?%d*)|?h?%[?([^%[%]]*)%]?|?h?|?r?")
  140. local iLevel = PLH_GetRealILVL(itemLink)
  141.  
  142. local attrs = {}
  143. if (SavedData.show_subtype and itemSubType ~= nil) then
  144. if (itemClassId == LE_ITEM_CLASS_ARMOR and itemSubClassId == 0) then
  145. -- don't display Miscellaneous for rings, necks and trinkets
  146. elseif (itemClassId == LE_ITEM_CLASS_ARMOR and itemEquipLoc == "INVTYPE_CLOAK") then
  147. -- don't display Cloth for cloaks
  148. else
  149. if (SavedData.subtype_short_format) then
  150. table.insert(attrs, itemSubType:sub(0, 1))
  151. else
  152. table.insert(attrs, itemSubType)
  153. end
  154. end
  155. if (itemClassId == LE_ITEM_CLASS_GEM and itemSubClassId == LE_ITEM_ARMOR_RELIC) then
  156. local relicType = PLH_GetRelicType(itemLink)
  157. table.insert(attrs, relicType)
  158. end
  159. end
  160. if (SavedData.show_equiploc and itemEquipLoc ~= nil and _G[itemEquipLoc] ~= nil) then table.insert(attrs, _G[itemEquipLoc]) end
  161. if (SavedData.show_ilevel and iLevel ~= nil) then
  162. local txt = iLevel
  163. if (ItemHasSockets(itemLink)) then txt = txt .. "+S" end
  164. if (ItemHasCorruption(itemLink)) then txt = txt .. "+C" end
  165. table.insert(attrs, txt)
  166. end
  167.  
  168. local newItemName = itemName.." ("..table.concat(attrs, " ")..")"
  169. local newLink = "|cff"..color.."|H"..itemString.."|h["..newItemName.."]|h|r"
  170.  
  171. message = string.gsub(message, EscapeSearchString(itemLink), newLink)
  172. end
  173. end
  174. return false, message, user, ...
  175. end
  176.  
  177. local function EventHandler(self, event, ...)
  178. if (SavedData == nil) then SavedData = {} end
  179. if (SavedData.trigger_loots == nil) then SavedData.trigger_loots = true end
  180. if (SavedData.trigger_chat == nil) then SavedData.trigger_chat = true end
  181. if (SavedData.trigger_quality == nil) then SavedData.trigger_quality = 3 end
  182. if (SavedData.show_subtype == nil) then SavedData.show_subtype = true end
  183. if (SavedData.subtype_short_format == nil) then SavedData.subtype_short_format = false end
  184. if (SavedData.show_equiploc == nil) then SavedData.show_equiploc = true end
  185. if (SavedData.show_ilevel == nil) then SavedData.show_ilevel = true end
  186.  
  187. if (SavedData.trigger_loots) then
  188. ChatFrame_AddMessageEventFilter("CHAT_MSG_LOOT", Filter);
  189. end
  190.  
  191. if (SavedData.trigger_chat) then
  192. ChatFrame_AddMessageEventFilter("CHAT_MSG_BATTLEGROUND", Filter);
  193. ChatFrame_AddMessageEventFilter("CHAT_MSG_BATTLEGROUND_LEADER", Filter);
  194. ChatFrame_AddMessageEventFilter("CHAT_MSG_CHANNEL", Filter);
  195. ChatFrame_AddMessageEventFilter("CHAT_MSG_EMOTE", Filter);
  196. ChatFrame_AddMessageEventFilter("CHAT_MSG_GUILD", Filter);
  197. ChatFrame_AddMessageEventFilter("CHAT_MSG_INSTANCE_CHAT", Filter);
  198. ChatFrame_AddMessageEventFilter("CHAT_MSG_INSTANCE_CHAT_LEADER", Filter);
  199. ChatFrame_AddMessageEventFilter("CHAT_MSG_OFFICER", Filter);
  200. ChatFrame_AddMessageEventFilter("CHAT_MSG_PARTY", Filter);
  201. ChatFrame_AddMessageEventFilter("CHAT_MSG_PARTY_LEADER", Filter);
  202. ChatFrame_AddMessageEventFilter("CHAT_MSG_RAID", Filter);
  203. ChatFrame_AddMessageEventFilter("CHAT_MSG_RAID_LEADER", Filter);
  204. ChatFrame_AddMessageEventFilter("CHAT_MSG_RAID_WARNING", Filter);
  205. ChatFrame_AddMessageEventFilter("CHAT_MSG_SAY", Filter);
  206. ChatFrame_AddMessageEventFilter("CHAT_MSG_WHISPER", Filter);
  207. ChatFrame_AddMessageEventFilter("CHAT_MSG_WHISPER_INFORM", Filter)
  208. ChatFrame_AddMessageEventFilter("CHAT_MSG_YELL", Filter);
  209. end
  210.  
  211. local panel = CreateFrame("Frame", "OptionsPanel", UIParent)
  212. panel.name = "ItemLinkLevel"
  213.  
  214. local subtypeCheckBox = CreateFrame("CheckButton", "subtypeCheckBox", panel, "UICheckButtonTemplate")
  215. subtypeCheckBox:SetPoint("TOPLEFT",10, -30)
  216. subtypeCheckBox:SetChecked(SavedData.show_subtype)
  217. _G[subtypeCheckBox:GetName().."Text"]:SetText("Display armor/weapon type (Plate, Leather, ...)")
  218. subtypeCheckBox:SetScript("OnClick", function(self) SavedData.show_subtype = self:GetChecked() end)
  219.  
  220. local subtypeShortCheckBox = CreateFrame("CheckButton", "subtypeShortCheckBox", panel, "UICheckButtonTemplate")
  221. subtypeShortCheckBox:SetPoint("TOPLEFT",30, -60)
  222. subtypeShortCheckBox:SetChecked(SavedData.subtype_short_format)
  223. _G[subtypeShortCheckBox:GetName().."Text"]:SetText("Short format (P for plate, L for leather, ...)")
  224. subtypeShortCheckBox:SetScript("OnClick", function(self) SavedData.subtype_short_format = self:GetChecked() end)
  225.  
  226. local equipLocCheckbox = CreateFrame("CheckButton", "equipLocCheckbox", panel, "UICheckButtonTemplate")
  227. equipLocCheckbox:SetPoint("TOPLEFT",10, -90)
  228. equipLocCheckbox:SetChecked(SavedData.show_equiploc)
  229. _G[equipLocCheckbox:GetName().."Text"]:SetText("Display equip location (Head, Trinket, ...)")
  230. equipLocCheckbox:SetScript("OnClick", function(self) SavedData.show_equiploc = self:GetChecked() end)
  231.  
  232. local iLevelCheckbox = CreateFrame("CheckButton", "iLevelCheckbox", panel, "UICheckButtonTemplate")
  233. iLevelCheckbox:SetPoint("TOPLEFT",10, -120)
  234. iLevelCheckbox:SetChecked(SavedData.show_ilevel)
  235. _G[iLevelCheckbox:GetName().."Text"]:SetText("Display item level")
  236. iLevelCheckbox:SetScript("OnClick", function(self) SavedData.show_ilevel = self:GetChecked() end)
  237.  
  238. local triggerLootsCheckbox = CreateFrame("CheckButton", "triggerLootsCheckbox", panel, "UICheckButtonTemplate")
  239. triggerLootsCheckbox:SetPoint("TOPLEFT",10, -180)
  240. triggerLootsCheckbox:SetChecked(SavedData.trigger_loots)
  241. _G[triggerLootsCheckbox:GetName().."Text"]:SetText("Trigger on loots (requires restart)")
  242. triggerLootsCheckbox:SetScript("OnClick", function(self) SavedData.trigger_loots = self:GetChecked() end)
  243.  
  244. local triggerChatCheckbox = CreateFrame("CheckButton", "triggerChatCheckbox", panel, "UICheckButtonTemplate")
  245. triggerChatCheckbox:SetPoint("TOPLEFT",10, -210)
  246. triggerChatCheckbox:SetChecked(SavedData.trigger_chat)
  247. _G[triggerChatCheckbox:GetName().."Text"]:SetText("Trigger on chat messages (requires restart)")
  248. triggerChatCheckbox:SetScript("OnClick", function(self) SavedData.trigger_chat = self:GetChecked() end)
  249.  
  250. local triggerQualityLabel = panel:CreateFontString("triggerQualityLabel", panel, "GameFontNormal")
  251. triggerQualityLabel:SetText("Minimum trigger quality")
  252. triggerQualityLabel:SetPoint("TOPLEFT",10,-260)
  253. local triggerQualityValue = panel:CreateFontString("triggerQualityValue", panel, "GameFontNormal")
  254. local triggerQualitySlider = CreateFrame("Slider", "MySliderGlobalName", panel, "OptionsSliderTemplate")
  255. triggerQualitySlider:SetPoint("LEFT", triggerQualityLabel, "RIGHT", 10, 0)
  256. triggerQualitySlider:SetMinMaxValues(0, 6)
  257. triggerQualitySlider:SetValue(SavedData.trigger_quality)
  258. triggerQualitySlider:SetValueStep(1)
  259. getglobal(triggerQualitySlider:GetName() .. 'Low'):SetText(_G["ITEM_QUALITY0_DESC"])
  260. getglobal(triggerQualitySlider:GetName() .. 'High'):SetText(_G["ITEM_QUALITY6_DESC"])
  261. triggerQualitySlider:SetScript("OnValueChanged", function(self, value)
  262. value = math.floor(value)
  263. SavedData.trigger_quality = value
  264. triggerQualityValue:SetText(_G["ITEM_QUALITY"..value.."_DESC"])
  265. end)
  266.  
  267. triggerQualityValue:SetText(_G["ITEM_QUALITY"..SavedData.trigger_quality.."_DESC"])
  268. triggerQualityValue:SetPoint("LEFT", triggerQualitySlider, "RIGHT", 10, 0)
  269.  
  270. InterfaceOptions_AddCategory(panel)
  271. end
  272. frame:SetScript("OnEvent", EventHandler);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement