/Tukui/modules/loot/lootframe.lua

http://github.com/Asphyxia/Tukui · Lua · 332 lines · 285 code · 43 blank · 4 comment · 22 complexity · c1633193cfc8b9b5dcf51742cabdcb1e MD5 · raw file

  1. local T, C, L = unpack(select(2, ...)) -- Import: T - functions, constants, variables; C - config; L - locales
  2. -- credits : Haste
  3. if not C["loot"].lootframe == true then return end
  4. local L = {
  5. fish = "Fishy loot",
  6. empty = "Empty slot",
  7. }
  8. local addon = CreateFrame("Button", "Butsu")
  9. local title = addon:CreateFontString(nil, "OVERLAY")
  10. local iconSize = 30
  11. local frameScale = 1
  12. local sq, ss, sn
  13. local OnEnter = function(self)
  14. local slot = self:GetID()
  15. if(LootSlotIsItem(slot)) then
  16. GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
  17. GameTooltip:SetLootItem(slot)
  18. CursorUpdate(self)
  19. end
  20. LootFrame.selectedSlot = self:GetID()
  21. self.drop:Show()
  22. self.drop:SetVertexColor(1, 1, 0)
  23. end
  24. local OnLeave = function(self)
  25. if(self.quality > 1) then
  26. local color = ITEM_QUALITY_COLORS[self.quality]
  27. self.drop:SetVertexColor(color.r, color.g, color.b)
  28. else
  29. self.drop:Hide()
  30. end
  31. GameTooltip:Hide()
  32. ResetCursor()
  33. end
  34. local OnClick = function(self)
  35. if(IsModifiedClick()) then
  36. HandleModifiedItemClick(GetLootSlotLink(self:GetID()))
  37. else
  38. StaticPopup_Hide"CONFIRM_LOOT_DISTRIBUTION"
  39. ss = self:GetID()
  40. sq = self.quality
  41. sn = self.name:GetText()
  42. LootSlot(ss)
  43. end
  44. end
  45. local OnUpdate = function(self)
  46. if(GameTooltip:IsOwned(self)) then
  47. GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
  48. GameTooltip:SetLootItem(self:GetID())
  49. CursorOnUpdate(self)
  50. end
  51. end
  52. local createSlot = function(id)
  53. local iconsize = iconSize-2
  54. local frame = CreateFrame("Button", 'ButsuSlot'..id, addon)
  55. frame:Point("LEFT", 8, 0)
  56. frame:Point("RIGHT", -8, 0)
  57. frame:Height(iconsize)
  58. frame:SetID(id)
  59. frame:RegisterForClicks("LeftButtonUp", "RightButtonUp")
  60. frame:SetScript("OnEnter", OnEnter)
  61. frame:SetScript("OnLeave", OnLeave)
  62. frame:SetScript("OnClick", OnClick)
  63. frame:SetScript("OnUpdate", OnUpdate)
  64. local iconFrame = CreateFrame("Frame", nil, frame)
  65. iconFrame:Height(iconsize)
  66. iconFrame:Width(iconsize)
  67. iconFrame:ClearAllPoints()
  68. iconFrame:SetPoint("RIGHT", frame)
  69. iconFrame:SetTemplate("Default")
  70. local icon = iconFrame:CreateTexture(nil, "ARTWORK")
  71. icon:SetAlpha(.8)
  72. icon:SetTexCoord(.07, .93, .07, .93)
  73. icon:Point("TOPLEFT", 2, -2)
  74. icon:Point("BOTTOMRIGHT", -2, 2)
  75. frame.icon = icon
  76. local count = iconFrame:CreateFontString(nil, "OVERLAY")
  77. count:ClearAllPoints()
  78. count:SetJustifyH"RIGHT"
  79. count:Point("BOTTOMRIGHT", iconFrame, -1, 2)
  80. count:SetFont(C["media"].font, 12, "OUTLINE")
  81. count:SetShadowOffset(.8, -.8)
  82. count:SetShadowColor(0, 0, 0, 1)
  83. count:SetText(1)
  84. frame.count = count
  85. local name = frame:CreateFontString(nil, "OVERLAY")
  86. name:SetJustifyH"LEFT"
  87. name:ClearAllPoints()
  88. name:SetPoint("LEFT", frame)
  89. name:SetPoint("RIGHT", icon, "LEFT")
  90. name:SetNonSpaceWrap(true)
  91. name:SetFont(C["media"].font, 13, "OUTLINE")
  92. name:SetShadowOffset(.8, -.8)
  93. name:SetShadowColor(0, 0, 0, 1)
  94. frame.name = name
  95. local drop = frame:CreateTexture(nil, "ARTWORK")
  96. drop:SetTexture"Interface\\QuestFrame\\UI-QuestLogTitleHighlight"
  97. drop:SetPoint("LEFT", icon, "RIGHT", 0, 0)
  98. drop:SetPoint("RIGHT", frame)
  99. drop:SetAllPoints(frame)
  100. drop:SetAlpha(.3)
  101. frame.drop = drop
  102. addon.slots[id] = frame
  103. return frame
  104. end
  105. local anchorSlots = function(self)
  106. local iconsize = iconSize
  107. local shownSlots = 0
  108. for i=1, #self.slots do
  109. local frame = self.slots[i]
  110. if(frame:IsShown()) then
  111. shownSlots = shownSlots + 1
  112. -- We don't have to worry about the previous slots as they're already hidden.
  113. frame:Point("TOP", addon, 4, (-8 + iconsize) - (shownSlots * iconsize))
  114. end
  115. end
  116. self:Height(math.max(shownSlots * iconsize + 16, 20))
  117. end
  118. title:SetFont(C["media"].font, 13, "OUTLINE")
  119. title:Point("BOTTOMLEFT", addon, "TOPLEFT", 4, 4)
  120. addon:SetScript("OnMouseDown", function(self) if(IsAltKeyDown()) then self:StartMoving() end end)
  121. addon:SetScript("OnMouseUp", function(self) self:StopMovingOrSizing() end)
  122. addon:SetScript("OnHide", function(self)
  123. StaticPopup_Hide"CONFIRM_LOOT_DISTRIBUTION"
  124. CloseLoot()
  125. end)
  126. addon:SetMovable(true)
  127. addon:RegisterForClicks"anyup"
  128. addon:SetParent(UIParent)
  129. --addon:SetUserPlaced(true)
  130. addon:Point("TOPLEFT", 0, -104)
  131. addon:SetTemplate("Default")
  132. addon:Width(256)
  133. addon:Height(64)
  134. addon:SetBackdropColor(0.1, 0.1, 0.1, 1)
  135. addon:SetClampedToScreen(true)
  136. addon:SetClampRectInsets(0, 0, T.Scale(14), 0)
  137. addon:SetHitRectInsets(0, 0, T.Scale(-14), 0)
  138. addon:SetFrameStrata"HIGH"
  139. addon:SetToplevel(true)
  140. addon.slots = {}
  141. addon.LOOT_OPENED = function(self, event, autoloot)
  142. self:Show()
  143. if(not self:IsShown()) then
  144. CloseLoot(not autoLoot)
  145. end
  146. local items = GetNumLootItems()
  147. if(IsFishingLoot()) then
  148. title:SetText(L.fish)
  149. elseif(not UnitIsFriend("player", "target") and UnitIsDead"target") then
  150. title:SetText(UnitName"target")
  151. else
  152. title:SetText(LOOT)
  153. end
  154. -- Blizzard uses strings here
  155. if(GetCVar("lootUnderMouse") == "1") then
  156. local x, y = GetCursorPosition()
  157. x = x / self:GetEffectiveScale()
  158. y = y / self:GetEffectiveScale()
  159. self:ClearAllPoints()
  160. self:Point("TOPLEFT", nil, "BOTTOMLEFT", x - 40, y + 20)
  161. self:GetCenter()
  162. self:Raise()
  163. else
  164. self:ClearAllPoints()
  165. self:SetUserPlaced(false)
  166. self:Point("TOPLEFT", 0, -104)
  167. end
  168. local m, w, t = 0, 0, title:GetStringWidth()
  169. if(items > 0) then
  170. for i=1, items do
  171. local slot = addon.slots[i] or createSlot(i)
  172. local texture, item, quantity, quality, locked = GetLootSlotInfo(i)
  173. local color = ITEM_QUALITY_COLORS[quality]
  174. if(LootSlotIsCoin(i)) then
  175. item = item:gsub("\n", ", ")
  176. end
  177. if(quantity > 1) then
  178. slot.count:SetText(quantity)
  179. slot.count:Show()
  180. else
  181. slot.count:Hide()
  182. end
  183. if(quality > 1) then
  184. slot.drop:SetVertexColor(color.r, color.g, color.b)
  185. slot.drop:Show()
  186. else
  187. slot.drop:Hide()
  188. end
  189. slot.quality = quality
  190. slot.name:SetText(item)
  191. slot.name:SetTextColor(color.r, color.g, color.b)
  192. slot.icon:SetTexture(texture)
  193. m = math.max(m, quality)
  194. w = math.max(w, slot.name:GetStringWidth())
  195. slot:Enable()
  196. slot:Show()
  197. end
  198. else
  199. local slot = addon.slots[1] or createSlot(1)
  200. local color = ITEM_QUALITY_COLORS[0]
  201. slot.name:SetText(L.empty)
  202. slot.name:SetTextColor(color.r, color.g, color.b)
  203. slot.icon:SetTexture[[Interface\Icons\INV_Misc_Herb_AncientLichen]]
  204. items = 1
  205. w = math.max(w, slot.name:GetStringWidth())
  206. slot.count:Hide()
  207. slot.drop:Hide()
  208. slot:Disable()
  209. slot:Show()
  210. end
  211. anchorSlots(self)
  212. w = w + 60
  213. t = t + 5
  214. local color = ITEM_QUALITY_COLORS[m]
  215. self:SetBackdropBorderColor(color.r, color.g, color.b, .8)
  216. self:Width(math.max(w, t))
  217. end
  218. addon.LOOT_SLOT_CLEARED = function(self, event, slot)
  219. if(not self:IsShown()) then return end
  220. addon.slots[slot]:Hide()
  221. anchorSlots(self)
  222. end
  223. addon.LOOT_CLOSED = function(self)
  224. StaticPopup_Hide"LOOT_BIND"
  225. self:Hide()
  226. for _, v in pairs(self.slots) do
  227. v:Hide()
  228. end
  229. end
  230. addon.OPEN_MASTER_LOOT_LIST = function(self)
  231. ToggleDropDownMenu(1, nil, GroupLootDropDown, addon.slots[ss], 0, 0)
  232. end
  233. addon.UPDATE_MASTER_LOOT_LIST = function(self)
  234. UIDropDownMenu_Refresh(GroupLootDropDown)
  235. end
  236. addon.ADDON_LOADED = function(self, event, addon)
  237. if(addon == "Butsu") then
  238. db = setmetatable({}, {__index = defaults})
  239. self:SetScale(frameScale)
  240. -- clean up.
  241. self[event] = nil
  242. self:UnregisterEvent(event)
  243. end
  244. end
  245. addon:SetScript("OnEvent", function(self, event, ...)
  246. self[event](self, event, ...)
  247. end)
  248. addon:RegisterEvent"LOOT_OPENED"
  249. addon:RegisterEvent"LOOT_SLOT_CLEARED"
  250. addon:RegisterEvent"LOOT_CLOSED"
  251. addon:RegisterEvent"OPEN_MASTER_LOOT_LIST"
  252. addon:RegisterEvent"UPDATE_MASTER_LOOT_LIST"
  253. addon:RegisterEvent"ADDON_LOADED"
  254. addon:Hide()
  255. -- Fuzz
  256. LootFrame:UnregisterAllEvents()
  257. table.insert(UISpecialFrames, "Butsu")
  258. function _G.GroupLootDropDown_GiveLoot(self)
  259. if ( sq >= MASTER_LOOT_THREHOLD ) then
  260. local dialog = StaticPopup_Show("CONFIRM_LOOT_DISTRIBUTION", ITEM_QUALITY_COLORS[sq].hex..sn..FONT_COLOR_CODE_CLOSE, self:GetText())
  261. if (dialog) then
  262. dialog.data = self.value
  263. end
  264. else
  265. GiveMasterLoot(ss, self.value)
  266. end
  267. CloseDropDownMenus()
  268. end
  269. StaticPopupDialogs["CONFIRM_LOOT_DISTRIBUTION"].OnAccept = function(self, data)
  270. GiveMasterLoot(ss, data)
  271. end