/Tukui/modules/loot/rollframe.lua

http://github.com/Asphyxia/Tukui · Lua · 342 lines · 283 code · 55 blank · 4 comment · 51 complexity · 8770b018c667d4256885dbddedb31c61 MD5 · raw file

  1. local T, C, L = unpack(select(2, ...)) -- Import: T - functions, constants, variables; C - config; L - locales
  2. --[[
  3. this is an edited version of teksloot
  4. all credits of this mod goes to tekhub
  5. --]]
  6. if C["loot"].rolllootframe ~= true then return end
  7. local backdrop = {
  8. bgFile = C["media"].blank, tile = true, tileSize = 0,
  9. edgeFile = C["media"].blank, edgeSize = T.mult,
  10. insets = {left = -T.mult, right = -T.mult, top = -T.mult, bottom = -T.mult},
  11. }
  12. local function ClickRoll(frame)
  13. RollOnLoot(frame.parent.rollid, frame.rolltype)
  14. end
  15. local function HideTip() GameTooltip:Hide() end
  16. local function HideTip2() GameTooltip:Hide(); ResetCursor() end
  17. local rolltypes = {"need", "greed", "disenchant", [0] = "pass"}
  18. local function SetTip(frame)
  19. GameTooltip:SetOwner(frame, "ANCHOR_RIGHT")
  20. GameTooltip:SetText(frame.tiptext)
  21. if frame:IsEnabled() == 0 then GameTooltip:AddLine("|cffff3333Cannot roll") end
  22. for name,roll in pairs(frame.parent.rolls) do if roll == rolltypes[frame.rolltype] then GameTooltip:AddLine(name, 1, 1, 1) end end
  23. GameTooltip:Show()
  24. end
  25. local function SetItemTip(frame)
  26. if not frame.link then return end
  27. GameTooltip:SetOwner(frame, "ANCHOR_TOPLEFT")
  28. GameTooltip:SetHyperlink(frame.link)
  29. if IsShiftKeyDown() then GameTooltip_ShowCompareItem() end
  30. if IsModifiedClick("DRESSUP") then ShowInspectCursor() else ResetCursor() end
  31. end
  32. local function ItemOnUpdate(self)
  33. if IsShiftKeyDown() then GameTooltip_ShowCompareItem() end
  34. CursorOnUpdate(self)
  35. end
  36. local function LootClick(frame)
  37. if IsControlKeyDown() then DressUpItemLink(frame.link)
  38. elseif IsShiftKeyDown() then ChatEdit_InsertLink(frame.link) end
  39. end
  40. local cancelled_rolls = {}
  41. local function OnEvent(frame, event, rollid)
  42. cancelled_rolls[rollid] = true
  43. if frame.rollid ~= rollid then return end
  44. frame.rollid = nil
  45. frame.time = nil
  46. frame:Hide()
  47. end
  48. local function StatusUpdate(frame)
  49. local t = GetLootRollTimeLeft(frame.parent.rollid)
  50. local perc = t / frame.parent.time
  51. frame.spark:Point("CENTER", frame, "LEFT", perc * frame:GetWidth(), 0)
  52. frame:SetValue(t)
  53. end
  54. local function CreateRollButton(parent, ntex, ptex, htex, rolltype, tiptext, ...)
  55. local f = CreateFrame("Button", nil, parent)
  56. f:SetPoint(...)
  57. f:Width(28)
  58. f:Height(28)
  59. f:SetNormalTexture(ntex)
  60. if ptex then f:SetPushedTexture(ptex) end
  61. f:SetHighlightTexture(htex)
  62. f.rolltype = rolltype
  63. f.parent = parent
  64. f.tiptext = tiptext
  65. f:SetScript("OnEnter", SetTip)
  66. f:SetScript("OnLeave", HideTip)
  67. f:SetScript("OnClick", ClickRoll)
  68. f:SetMotionScriptsWhileDisabled(true)
  69. local txt = f:CreateFontString(nil, nil)
  70. txt:SetFont(C.media.pixelfont, C["datatext"].fontsize, "MONOCHROMEOUTLINE")
  71. txt:SetPoint("CENTER", 0, rolltype == 2 and 1 or rolltype == 0 and -1.2 or 0)
  72. return f, txt
  73. end
  74. local function CreateRollFrame()
  75. local frame = CreateFrame("Frame", nil, UIParent)
  76. frame:Width(328)
  77. frame:Height(22)
  78. frame:SetBackdrop(backdrop)
  79. frame:SetBackdropColor(0.1, 0.1, 0.1, 1)
  80. frame:SetScript("OnEvent", OnEvent)
  81. frame:RegisterEvent("CANCEL_LOOT_ROLL")
  82. frame:Hide()
  83. local button = CreateFrame("Button", nil, frame)
  84. button:SetPoint("LEFT", -24, 0)
  85. button:Width(22)
  86. button:Height(22)
  87. button:SetScript("OnEnter", SetItemTip)
  88. button:SetScript("OnLeave", HideTip2)
  89. button:SetScript("OnUpdate", ItemOnUpdate)
  90. button:SetScript("OnClick", LootClick)
  91. frame.button = button
  92. local buttonborder = CreateFrame("Frame", nil, button)
  93. buttonborder:Width(22)
  94. buttonborder:Height(22)
  95. buttonborder:SetPoint("CENTER", button, "CENTER")
  96. buttonborder:SetBackdrop(backdrop)
  97. buttonborder:SetBackdropColor(1, 1, 1, 0)
  98. local buttonborder2 = CreateFrame("Frame", nil, button)
  99. buttonborder2:Width(24)
  100. buttonborder2:Height(24)
  101. buttonborder2:SetFrameLevel(buttonborder:GetFrameLevel()+1)
  102. buttonborder2:SetPoint("CENTER", button, "CENTER")
  103. buttonborder2:SetBackdrop(backdrop)
  104. buttonborder2:SetBackdropColor(0, 0, 0, 0)
  105. buttonborder2:SetBackdropBorderColor(0,0,0,1)
  106. frame.buttonborder = buttonborder
  107. local tfade = frame:CreateTexture(nil, "BORDER")
  108. tfade:Point("TOPLEFT", frame, "TOPLEFT", 4, 0)
  109. tfade:Point("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -4, 0)
  110. tfade:SetTexture("Interface\\ChatFrame\\ChatFrameBackground")
  111. tfade:SetBlendMode("ADD")
  112. tfade:SetGradientAlpha("VERTICAL", .1, .1, .1, 0, .1, .1, .1, 0)
  113. local status = CreateFrame("StatusBar", nil, frame)
  114. status:Width(326)
  115. status:Height(20)
  116. status:SetPoint("CENTER", frame, "CENTER", 0, 0)
  117. status:SetScript("OnUpdate", StatusUpdate)
  118. status:SetFrameLevel(status:GetFrameLevel()-1)
  119. status:SetStatusBarTexture(C["media"].normTex)
  120. status:SetStatusBarColor(.8, .8, .8, .9)
  121. status.parent = frame
  122. frame.status = status
  123. local spark = frame:CreateTexture(nil, "OVERLAY")
  124. spark:Width(14)
  125. spark:Height(25)
  126. spark:SetTexture("Interface\\CastingBar\\UI-CastingBar-Spark")
  127. spark:SetBlendMode("ADD")
  128. status.spark = spark
  129. local need, needtext = CreateRollButton(frame, "Interface\\Buttons\\UI-GroupLoot-Dice-Up", "Interface\\Buttons\\UI-GroupLoot-Dice-Highlight", "Interface\\Buttons\\UI-GroupLoot-Dice-Down", 1, NEED, "LEFT", frame.button, "RIGHT", T.Scale(5), T.Scale(-1))
  130. local greed, greedtext = CreateRollButton(frame, "Interface\\Buttons\\UI-GroupLoot-Coin-Up", "Interface\\Buttons\\UI-GroupLoot-Coin-Highlight", "Interface\\Buttons\\UI-GroupLoot-Coin-Down", 2, GREED, "LEFT", need, "RIGHT", 0, T.Scale(-1))
  131. local de, detext
  132. de, detext = CreateRollButton(frame, "Interface\\Buttons\\UI-GroupLoot-DE-Up", "Interface\\Buttons\\UI-GroupLoot-DE-Highlight", "Interface\\Buttons\\UI-GroupLoot-DE-Down", 3, ROLL_DISENCHANT, "LEFT", greed, "RIGHT", 0, T.Scale(-1))
  133. local pass, passtext = CreateRollButton(frame, "Interface\\Buttons\\UI-GroupLoot-Pass-Up", nil, "Interface\\Buttons\\UI-GroupLoot-Pass-Down", 0, PASS, "LEFT", de or greed, "RIGHT", 0, T.Scale(2.2))
  134. frame.needbutt, frame.greedbutt, frame.disenchantbutt = need, greed, de
  135. frame.need, frame.greed, frame.pass, frame.disenchant = needtext, greedtext, passtext, detext
  136. local bind = frame:CreateFontString()
  137. bind:Point("LEFT", pass, "RIGHT", 3, 1)
  138. bind:SetFont(C.media.pixelfont, C["datatext"].fontsize, "MONOCHROMEOUTLINE")
  139. frame.fsbind = bind
  140. local loot = frame:CreateFontString(nil, "ARTWORK")
  141. loot:SetFont(C.media.pixelfont, C["datatext"].fontsize, "MONOCHROMEOUTLINE")
  142. loot:Point("LEFT", bind, "RIGHT", 0, 0)
  143. loot:Point("RIGHT", frame, "RIGHT", -5, 0)
  144. loot:Height(10)
  145. loot:Width(200)
  146. loot:SetJustifyH("LEFT")
  147. frame.fsloot = loot
  148. frame.rolls = {}
  149. return frame
  150. end
  151. local anchor = CreateFrame("Button", "TukuiRollAnchor", UIParent)
  152. anchor:Width(300)
  153. anchor:Height(22)
  154. anchor:SetBackdrop(backdrop)
  155. anchor:SetBackdropColor(0.25, 0.25, 0.25, 1)
  156. local label = anchor:CreateFontString(nil, "ARTWORK")
  157. label:SetFont(C.media.pixelfont, C["datatext"].fontsize, "MONOCHROMEOUTLINE")
  158. label:SetAllPoints(anchor)
  159. label:SetText(L.move_roll)
  160. anchor:SetMovable(true)
  161. anchor:EnableMouse(false)
  162. anchor:SetTemplate("Default")
  163. anchor:SetAlpha(0)
  164. anchor:SetBackdropBorderColor(1, 0, 0, 1)
  165. local frames = {}
  166. local f = CreateRollFrame() -- Create one for good measure
  167. f:Point("BOTTOMLEFT", next(frames) and frames[#frames] or anchor, "TOPLEFT", 0, 4)
  168. table.insert(frames, f)
  169. local function GetFrame()
  170. for i,f in ipairs(frames) do
  171. if not f.rollid then return f end
  172. end
  173. local f = CreateRollFrame()
  174. f:Point("BOTTOMLEFT", next(frames) and frames[#frames] or anchor, "TOPLEFT", 0, 4)
  175. table.insert(frames, f)
  176. return f
  177. end
  178. local function START_LOOT_ROLL(rollid, time)
  179. if cancelled_rolls[rollid] then return end
  180. local f = GetFrame()
  181. f.rollid = rollid
  182. f.time = time
  183. for i in pairs(f.rolls) do f.rolls[i] = nil end
  184. f.need:SetText(0)
  185. f.greed:SetText(0)
  186. f.pass:SetText(0)
  187. f.disenchant:SetText(0)
  188. local texture, name, count, quality, bop, canNeed, canGreed, canDisenchant = GetLootRollItemInfo(rollid)
  189. f.button:SetNormalTexture(texture)
  190. f.button.link = GetLootRollItemLink(rollid)
  191. if canNeed then f.needbutt:Enable() else f.needbutt:Disable() end
  192. if canGreed then f.greedbutt:Enable() else f.greedbutt:Disable() end
  193. if canDisenchant then f.disenchantbutt:Enable() else f.disenchantbutt:Disable() end
  194. SetDesaturation(f.needbutt:GetNormalTexture(), not canNeed)
  195. SetDesaturation(f.greedbutt:GetNormalTexture(), not canGreed)
  196. SetDesaturation(f.disenchantbutt:GetNormalTexture(), not canDisenchant)
  197. f.fsbind:SetText(bop and "BoP" or "BoE")
  198. f.fsbind:SetVertexColor(bop and 1 or .3, bop and .3 or 1, bop and .1 or .3)
  199. local color = ITEM_QUALITY_COLORS[quality]
  200. f.fsloot:SetVertexColor(color.r, color.g, color.b)
  201. f.fsloot:SetText(name)
  202. f:SetBackdropBorderColor(color.r, color.g, color.b, 1)
  203. f.buttonborder:SetBackdropBorderColor(color.r, color.g, color.b, 1)
  204. f.status:SetStatusBarColor(color.r, color.g, color.b, .7)
  205. f.status:SetMinMaxValues(0, time)
  206. f.status:SetValue(time)
  207. f:SetPoint("CENTER", WorldFrame, "CENTER")
  208. f:Show()
  209. end
  210. local locale = GetLocale()
  211. local rollpairs = locale == "deDE" and {
  212. ["(.*) passt automatisch bei (.+), weil [ersi]+ den Gegenstand nicht benutzen kann.$"] = "pass",
  213. ["(.*) würfelt nicht für: (.+|r)$"] = "pass",
  214. ["(.*) hat für (.+) 'Gier' ausgewählt"] = "greed",
  215. ["(.*) hat für (.+) 'Bedarf' ausgewählt"] = "need",
  216. ["(.*) hat für '(.+)' Entzauberung gewählt."] = "disenchant",
  217. } or locale == "frFR" and {
  218. ["(.*) a passé pour : (.+) parce qu'((il)|(elle)) ne peut pas ramasser cette objet.$"] = "pass",
  219. ["(.*) a passé pour : (.+)"] = "pass",
  220. ["(.*) a choisi Cupidité pour : (.+)"] = "greed",
  221. ["(.*) a choisi Besoin pour : (.+)"] = "need",
  222. ["(.*) a choisi Désenchantement pour : (.+)"] = "disenchant",
  223. } or locale == "zhTW" and {
  224. ["(.*)自動放棄:(.+),因為"] = "pass",
  225. ["(.*)放棄了:(.+)"] = "pass",
  226. ["(.*)選擇了貪婪優先:(.+)"] = "greed",
  227. ["(.*)選擇了需求優先:(.+)"] = "need",
  228. ["(.*)選擇分解:(.+)"] = "disenchant",
  229. } or locale == "ruRU" and {
  230. ["(.*) автоматически передает предмет (.+), поскольку не может его забрать"] = "pass",
  231. ["(.*) пропускает розыгрыш предмета \"(.+)\", поскольку не может его забрать"] = "pass",
  232. ["(.*) отказывается от предмета (.+)%."] = "pass",
  233. ["Разыгрывается: (.+)%. (.*): \"Не откажусь\""] = "greed",
  234. ["Разыгрывается: (.+)%. (.*): \"Мне это нужно\""] = "need",
  235. ["Разыгрывается: (.+)%. (.*): \"Распылить\""] = "disenchant",
  236. } or locale == "koKR" and {
  237. ["(.+)님이 획득할 수 없는 아이템이어서 자동으로 주사위 굴리기를 포기했습니다: (.+)"] = "pass",
  238. ["(.+)님이 주사위 굴리기를 포기했습니다: (.+)"] = "pass",
  239. ["(.+)님이 차비를 선택했습니다: (.+)"] = "greed",
  240. ["(.+)님이 입찰을 선택했습니다: (.+)"] = "need",
  241. ["(.+)님이 마력 추출을 선택했습니다: (.+)"] = "disenchant",
  242. } or {
  243. ["^(.*) automatically passed on: (.+) because s?he cannot loot that item.$"] = "pass",
  244. ["^(.*) passed on: (.+|r)$"] = "pass",
  245. ["(.*) has selected Greed for: (.+)"] = "greed",
  246. ["(.*) has selected Need for: (.+)"] = "need",
  247. ["(.*) has selected Disenchant for: (.+)"] = "disenchant",
  248. }
  249. local function ParseRollChoice(msg)
  250. for i,v in pairs(rollpairs) do
  251. local _, _, playername, itemname = string.find(msg, i)
  252. if locale == "ruRU" and (v == "greed" or v == "need" or v == "disenchant") then
  253. local temp = playername
  254. playername = itemname
  255. itemname = temp
  256. end
  257. if playername and itemname and playername ~= "Everyone" then return playername, itemname, v end
  258. end
  259. end
  260. local function CHAT_MSG_LOOT(msg)
  261. local playername, itemname, rolltype = ParseRollChoice(msg)
  262. if playername and itemname and rolltype then
  263. for _,f in ipairs(frames) do
  264. if f.rollid and f.button.link == itemname and not f.rolls[playername] then
  265. f.rolls[playername] = rolltype
  266. f[rolltype]:SetText(tonumber(f[rolltype]:GetText()) + 1)
  267. return
  268. end
  269. end
  270. end
  271. end
  272. anchor:RegisterEvent("ADDON_LOADED")
  273. anchor:SetScript("OnEvent", function(frame, event, addon)
  274. if addon ~= "Tukui" then return end
  275. anchor:UnregisterEvent("ADDON_LOADED")
  276. anchor:RegisterEvent("START_LOOT_ROLL")
  277. anchor:RegisterEvent("CHAT_MSG_LOOT")
  278. UIParent:UnregisterEvent("START_LOOT_ROLL")
  279. UIParent:UnregisterEvent("CANCEL_LOOT_ROLL")
  280. anchor:SetScript("OnEvent", function(frame, event, ...) if event == "CHAT_MSG_LOOT" then return CHAT_MSG_LOOT(...) else return START_LOOT_ROLL(...) end end)
  281. anchor:Point("CENTER", UIParent, "CENTER", 0, -100)
  282. end)