Wetxius

Untitled

Jan 4th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 42.51 KB | None | 0 0
  1. local T, C, L, _ = unpack(select(2, ...))
  2. if C.bag.enable ~= true then return end
  3.  
  4. ----------------------------------------------------------------------------------------
  5. -- Based on Stuffing(by Hungtar, editor Tukz)
  6. ----------------------------------------------------------------------------------------
  7. local BAGS_BACKPACK = {0, 1, 2, 3, 4}
  8. local BAGS_BANK = {-1, 5, 6, 7, 8, 9, 10, 11}
  9. local ST_NORMAL = 1
  10. local ST_FISHBAG = 2
  11. local ST_SPECIAL = 3
  12. local bag_bars = 0
  13. local unusable
  14.  
  15. if T.class == "DEATHKNIGHT" then
  16. unusable = {{LE_ITEM_WEAPON_BOWS, LE_ITEM_WEAPON_GUNS, LE_ITEM_WEAPON_WARGLAIVE, LE_ITEM_WEAPON_STAFF, LE_ITEM_WEAPON_UNARMED, LE_ITEM_WEAPON_DAGGER, LE_ITEM_WEAPON_THROWN, LE_ITEM_WEAPON_CROSSBOW, LE_ITEM_WEAPON_WAND}, {LE_ITEM_ARMOR_SHIELD}} -- weapons, armor, dual wield
  17. elseif T.class == "DEMONHUNTER" then
  18. unusable = {{LE_ITEM_WEAPON_AXE2H, LE_ITEM_WEAPON_BOWS, LE_ITEM_WEAPON_GUNS, LE_ITEM_WEAPON_MACE2H, LE_ITEM_WEAPON_POLEARM, LE_ITEM_WEAPON_SWORD2H, LE_ITEM_WEAPON_STAFF, LE_ITEM_WEAPON_THROWN, LE_ITEM_WEAPON_CROSSBOW, LE_ITEM_WEAPON_WAND}, {LE_ITEM_ARMOR_MAIL, LE_ITEM_ARMOR_PLATE, LE_ITEM_ARMOR_SHIELD}}
  19. elseif T.class == "DRUID" then
  20. unusable = {{LE_ITEM_WEAPON_AXE1H, LE_ITEM_WEAPON_AXE2H, LE_ITEM_WEAPON_BOWS, LE_ITEM_WEAPON_GUNS, LE_ITEM_WEAPON_SWORD1H, LE_ITEM_WEAPON_SWORD2H, LE_ITEM_WEAPON_WARGLAIVE, LE_ITEM_WEAPON_THROWN, LE_ITEM_WEAPON_CROSSBOW, LE_ITEM_WEAPON_WAND}, {LE_ITEM_ARMOR_MAIL, LE_ITEM_ARMOR_PLATE, LE_ITEM_ARMOR_SHIELD}, true}
  21. elseif T.class == "HUNTER" then
  22. unusable = {{LE_ITEM_WEAPON_MACE1H, LE_ITEM_WEAPON_MACE2H, LE_ITEM_WEAPON_WARGLAIVE, LE_ITEM_WEAPON_THROWN, LE_ITEM_WEAPON_WAND}, {LE_ITEM_ARMOR_PLATE, LE_ITEM_ARMOR_SHIELD}}
  23. elseif T.class == "MAGE" then
  24. unusable = {{LE_ITEM_WEAPON_AXE1H, LE_ITEM_WEAPON_AXE2H, LE_ITEM_WEAPON_BOWS, LE_ITEM_WEAPON_GUNS, LE_ITEM_WEAPON_MACE1H, LE_ITEM_WEAPON_MACE2H, LE_ITEM_WEAPON_POLEARM, LE_ITEM_WEAPON_SWORD2H, LE_ITEM_WEAPON_WARGLAIVE, LE_ITEM_WEAPON_UNARMED, LE_ITEM_WEAPON_THROWN, LE_ITEM_WEAPON_CROSSBOW}, {LE_ITEM_ARMOR_LEATHER, LE_ITEM_ARMOR_MAIL, LE_ITEM_ARMOR_PLATE, LE_ITEM_ARMOR_SHIELD,}, true}
  25. elseif T.class == "MONK" then
  26. unusable = {{LE_ITEM_WEAPON_AXE2H, LE_ITEM_WEAPON_BOWS, LE_ITEM_WEAPON_GUNS, LE_ITEM_WEAPON_MACE2H, LE_ITEM_WEAPON_SWORD2H, LE_ITEM_WEAPON_WARGLAIVE, LE_ITEM_WEAPON_DAGGER, LE_ITEM_WEAPON_THROWN, LE_ITEM_WEAPON_CROSSBOW, LE_ITEM_WEAPON_WAND}, {LE_ITEM_ARMOR_MAIL, LE_ITEM_ARMOR_PLATE, LE_ITEM_ARMOR_SHIELD}}
  27. elseif T.class == "PALADIN" then
  28. unusable = {{LE_ITEM_WEAPON_BOWS, LE_ITEM_WEAPON_GUNS, LE_ITEM_WEAPON_WARGLAIVE, LE_ITEM_WEAPON_STAFF, LE_ITEM_WEAPON_UNARMED, LE_ITEM_WEAPON_DAGGER, LE_ITEM_WEAPON_THROWN, LE_ITEM_WEAPON_CROSSBOW, LE_ITEM_WEAPON_WAND}, {}, true}
  29. elseif T.class == "PRIEST" then
  30. unusable = {{LE_ITEM_WEAPON_AXE1H, LE_ITEM_WEAPON_AXE2H, LE_ITEM_WEAPON_BOWS, LE_ITEM_WEAPON_GUNS, LE_ITEM_WEAPON_MACE2H, LE_ITEM_WEAPON_POLEARM, LE_ITEM_WEAPON_SWORD1H, LE_ITEM_WEAPON_SWORD2H, LE_ITEM_WEAPON_WARGLAIVE, LE_ITEM_WEAPON_UNARMED, LE_ITEM_WEAPON_THROWN, LE_ITEM_WEAPON_CROSSBOW}, {LE_ITEM_ARMOR_LEATHER, LE_ITEM_ARMOR_MAIL, LE_ITEM_ARMOR_PLATE, LE_ITEM_ARMOR_SHIELD}, true}
  31. elseif T.class == "ROGUE" then
  32. unusable = {{LE_ITEM_WEAPON_AXE2H, LE_ITEM_WEAPON_MACE2H, LE_ITEM_WEAPON_POLEARM, LE_ITEM_WEAPON_SWORD2H, LE_ITEM_WEAPON_WARGLAIVE, LE_ITEM_WEAPON_STAFF, LE_ITEM_WEAPON_WAND}, {LE_ITEM_ARMOR_MAIL, LE_ITEM_ARMOR_PLATE, LE_ITEM_ARMOR_SHIELD}}
  33. elseif T.class == "SHAMAN" then
  34. unusable = {{LE_ITEM_WEAPON_BOWS, LE_ITEM_WEAPON_GUNS, LE_ITEM_WEAPON_POLEARM, LE_ITEM_WEAPON_SWORD1H, LE_ITEM_WEAPON_SWORD2H, LE_ITEM_WEAPON_WARGLAIVE, LE_ITEM_WEAPON_THROWN, LE_ITEM_WEAPON_CROSSBOW, LE_ITEM_WEAPON_WAND}, {LE_ITEM_ARMOR_PLATEM}}
  35. elseif T.class == "WARLOCK" then
  36. unusable = {{LE_ITEM_WEAPON_AXE1H, LE_ITEM_WEAPON_AXE2H, LE_ITEM_WEAPON_BOWS, LE_ITEM_WEAPON_GUNS, LE_ITEM_WEAPON_MACE1H, LE_ITEM_WEAPON_MACE2H, LE_ITEM_WEAPON_POLEARM, LE_ITEM_WEAPON_SWORD2H, LE_ITEM_WEAPON_WARGLAIVE, LE_ITEM_WEAPON_UNARMED, LE_ITEM_WEAPON_THROWN, LE_ITEM_WEAPON_CROSSBOW}, {LE_ITEM_ARMOR_LEATHER, LE_ITEM_ARMOR_MAIL, LE_ITEM_ARMOR_PLATE, LE_ITEM_ARMOR_SHIELD}, true}
  37. elseif T.class == "WARRIOR" then
  38. unusable = {{LE_ITEM_WEAPON_WARGLAIVE, LE_ITEM_WEAPON_WAND}, {}}
  39. else
  40. unusable = {{}, {}}
  41. end
  42.  
  43. local subs = {}
  44. for k = 0, 20 do
  45. subs[k + 1] = GetItemSubClassInfo(LE_ITEM_CLASS_WEAPON, k)
  46. end
  47.  
  48. for i, subclass in ipairs(unusable[1]) do
  49. unusable[subs[subclass+1]] = true
  50. end
  51.  
  52. subs = {}
  53. for k = 0, 11 do
  54. subs[k + 1] = GetItemSubClassInfo(LE_ITEM_CLASS_ARMOR, k)
  55. end
  56.  
  57. for i, subclass in ipairs(unusable[2]) do
  58. unusable[subs[subclass + 1]] = true
  59. end
  60.  
  61.  
  62. local function IsClassUnusable(subclass, slot)
  63. if subclass then
  64. return slot ~= "" and unusable[subclass] or slot == "INVTYPE_WEAPONOFFHAND" and unusable[3]
  65. end
  66. end
  67.  
  68. local function IsItemUnusable(...)
  69. if ... then
  70. local subclass, _, slot = select(7, GetItemInfo(...))
  71. return IsClassUnusable(subclass, slot)
  72. end
  73. end
  74.  
  75. Stuffing = CreateFrame("Frame", nil, UIParent)
  76. Stuffing:RegisterEvent("ADDON_LOADED")
  77. Stuffing:RegisterEvent("PLAYER_ENTERING_WORLD")
  78. Stuffing:SetScript("OnEvent", function(this, event, ...)
  79. if IsAddOnLoaded("AdiBags") or IsAddOnLoaded("ArkInventory") or IsAddOnLoaded("cargBags_Nivaya") or IsAddOnLoaded("cargBags") or IsAddOnLoaded("Bagnon") or IsAddOnLoaded("Combuctor") or IsAddOnLoaded("TBag") or IsAddOnLoaded("BaudBag") then return end
  80. Stuffing[event](this, ...)
  81. end)
  82.  
  83. -- Drop down menu stuff from Postal
  84. local Stuffing_DDMenu = CreateFrame("Frame", "StuffingDropDownMenu")
  85. Stuffing_DDMenu.displayMode = "MENU"
  86. Stuffing_DDMenu.info = {}
  87. Stuffing_DDMenu.HideMenu = function()
  88. if UIDROPDOWNMENU_OPEN_MENU == Stuffing_DDMenu then
  89. CloseDropDownMenus()
  90. end
  91. end
  92.  
  93. local function Stuffing_OnShow()
  94. Stuffing:PLAYERBANKSLOTS_CHANGED(29)
  95.  
  96. for i = 0, #BAGS_BACKPACK - 1 do
  97. Stuffing:BAG_UPDATE(i)
  98. end
  99.  
  100. Stuffing:Layout()
  101. Stuffing:SearchReset()
  102. PlaySound("igBackPackOpen")
  103. collectgarbage("collect")
  104. end
  105.  
  106. local function StuffingBank_OnHide()
  107. CloseBankFrame()
  108. if Stuffing.frame:IsShown() then
  109. Stuffing.frame:Hide()
  110. end
  111. PlaySound("igBackPackClose")
  112. end
  113.  
  114. local function Stuffing_OnHide()
  115. if Stuffing.bankFrame and Stuffing.bankFrame:IsShown() then
  116. Stuffing.bankFrame:Hide()
  117. end
  118. PlaySound("igBackPackClose")
  119. end
  120.  
  121. local function Stuffing_Open()
  122. if not Stuffing.frame:IsShown() then
  123. Stuffing.frame:Show()
  124. end
  125. end
  126.  
  127. local function Stuffing_Close()
  128. Stuffing.frame:Hide()
  129. end
  130.  
  131. local function Stuffing_Toggle()
  132. if Stuffing.frame:IsShown() then
  133. Stuffing.frame:Hide()
  134. else
  135. Stuffing.frame:Show()
  136. end
  137. end
  138.  
  139. -- Bag slot stuff
  140. local trashButton = {}
  141. local trashBag = {}
  142.  
  143. local ItemDB = {}
  144.  
  145. -- Tooltip and scanning by Phanx @ http://www.wowinterface.com/forums/showthread.php?p=271406
  146. local S_ITEM_LEVEL = "^" .. gsub(ITEM_LEVEL, "%%d", "(%%d+)")
  147.  
  148. local scantip = CreateFrame("GameTooltip", "iLvlScanningTooltip", nil, "GameTooltipTemplate")
  149. scantip:SetOwner(UIParent, "ANCHOR_NONE")
  150.  
  151. local function _getRealItemLevel(link)
  152. if ItemDB[link] then return ItemDB[link] end
  153.  
  154. local realItemLevel
  155. scantip:SetHyperlink(link)
  156.  
  157. for i = 2, scantip:NumLines() do -- Line 1 is always the name so you can skip it.
  158. local text = _G["iLvlScanningTooltipTextLeft"..i]:GetText()
  159. if text and text ~= "" then
  160. realItemLevel = realItemLevel or strmatch(text, S_ITEM_LEVEL)
  161.  
  162. if realItemLevel then
  163. ItemDB[link] = tonumber(realItemLevel)
  164. return tonumber(realItemLevel)
  165. end
  166. end
  167. end
  168.  
  169. return realItemLevel
  170. end
  171.  
  172. function Stuffing:SlotUpdate(b)
  173. local texture, count, locked, quality = GetContainerItemInfo(b.bag, b.slot)
  174. local clink = GetContainerItemLink(b.bag, b.slot)
  175. local isQuestItem, questId = GetContainerItemQuestInfo(b.bag, b.slot)
  176.  
  177. -- Set all slot color to default ShestakUI on update
  178. if not b.frame.lock then
  179. b.frame:SetBackdropBorderColor(unpack(C.media.border_color))
  180. end
  181.  
  182. if C.bag.ilvl == true then
  183. b.frame.text:SetText("")
  184. end
  185.  
  186. if b.cooldown and StuffingFrameBags and StuffingFrameBags:IsShown() then
  187. local start, duration, enable = GetContainerItemCooldown(b.bag, b.slot)
  188. CooldownFrame_Set(b.cooldown, start, duration, enable)
  189. end
  190.  
  191. if clink then
  192. b.name, _, _, b.itemlevel, b.level, _, _, _, _, _, _, b.itemClassID, b.itemSubClassID = GetItemInfo(clink)
  193.  
  194. if C.bag.ilvl == true and b.itemlevel and quality > 1 and (b.itemClassID == 2 or b.itemClassID == 4 or (b.itemClassID == 3 and b.itemSubClassID == 11)) then
  195. b.itemlevel = _getRealItemLevel(clink) or b.itemlevel
  196. b.frame.text:SetText(b.itemlevel)
  197. end
  198.  
  199. if (IsItemUnusable(clink) or b.level and b.level > T.level) and not locked then
  200. _G[b.frame:GetName().."IconTexture"]:SetVertexColor(1, 0.1, 0.1)
  201. else
  202. _G[b.frame:GetName().."IconTexture"]:SetVertexColor(1, 1, 1)
  203. end
  204.  
  205. -- Color slot according to item quality
  206. if not b.frame.lock and quality and quality > 1 and not (isQuestItem or questId) then
  207. b.frame:SetBackdropBorderColor(GetItemQualityColor(quality))
  208. elseif isQuestItem or questId then
  209. b.frame:SetBackdropBorderColor(1, 1, 0)
  210. end
  211. else
  212. b.name, b.level = nil, nil
  213. end
  214.  
  215. SetItemButtonTexture(b.frame, texture)
  216. SetItemButtonCount(b.frame, count)
  217. SetItemButtonDesaturated(b.frame, locked)
  218.  
  219. b.frame:Show()
  220. end
  221.  
  222. function Stuffing:BagSlotUpdate(bag)
  223. if not self.buttons then
  224. return
  225. end
  226.  
  227. for _, v in ipairs(self.buttons) do
  228. if v.bag == bag then
  229. self:SlotUpdate(v)
  230. end
  231. end
  232. end
  233.  
  234. function CreateReagentContainer()
  235. ReagentBankFrame:StripTextures()
  236.  
  237. local Reagent = CreateFrame("Frame", "StuffingFrameReagent", UIParent)
  238. local SwitchBankButton = CreateFrame("Button", nil, Reagent)
  239. local NumButtons = ReagentBankFrame.size
  240. local NumRows, LastRowButton, NumButtons, LastButton = 0, ReagentBankFrameItem1, 1, ReagentBankFrameItem1
  241. local Deposit = ReagentBankFrame.DespositButton
  242.  
  243. Reagent:SetWidth(((C.bag.button_size + C.bag.button_space) * C.bag.bank_columns) + 17)
  244. Reagent:SetPoint("TOPLEFT", _G["StuffingFrameBank"], "TOPLEFT", 0, 0)
  245. Reagent:SetTemplate("Transparent")
  246. Reagent:SetFrameStrata(_G["StuffingFrameBank"]:GetFrameStrata())
  247. Reagent:SetFrameLevel(_G["StuffingFrameBank"]:GetFrameLevel() + 5)
  248. Reagent:EnableMouse(true)
  249. Reagent:SetMovable(true)
  250. Reagent:SetClampedToScreen(true)
  251. Reagent:SetClampRectInsets(0, 0, 0, -20)
  252. Reagent:SetScript("OnMouseDown", function(self, button)
  253. if IsShiftKeyDown() and button == "LeftButton" then
  254. self:StartMoving()
  255. end
  256. end)
  257. Reagent:SetScript("OnMouseUp", Reagent.StopMovingOrSizing)
  258.  
  259. SwitchBankButton:SetSize(80, 20)
  260. SwitchBankButton:SkinButton()
  261. SwitchBankButton:SetPoint("TOPLEFT", 10, -4)
  262. SwitchBankButton:FontString("text", C.font.bags_font, C.font.bags_font_size, C.font.bags_font_style)
  263. SwitchBankButton.text:SetPoint("CENTER")
  264. SwitchBankButton.text:SetText(BANK)
  265. SwitchBankButton:SetScript("OnClick", function()
  266. Reagent:Hide()
  267. _G["StuffingFrameBank"]:Show()
  268. _G["StuffingFrameBank"]:SetAlpha(1)
  269. BankFrame_ShowPanel(BANK_PANELS[1].name)
  270. PlaySound("igBackPackOpen")
  271. end)
  272.  
  273. Deposit:SetParent(Reagent)
  274. Deposit:ClearAllPoints()
  275. Deposit:SetSize(170, 20)
  276. Deposit:SetPoint("TOPLEFT", SwitchBankButton, "TOPRIGHT", 3, 0)
  277. Deposit:SkinButton()
  278. Deposit:FontString("text", C.font.bags_font, C.font.bags_font_size, C.font.bags_font_style)
  279. Deposit.text:SetShadowOffset(C.font.bags_font_shadow and 1 or 0, C.font.bags_font_shadow and -1 or 0)
  280. Deposit.text:SetTextColor(1, 1, 1)
  281. Deposit.text:SetText(REAGENTBANK_DEPOSIT)
  282. Deposit:SetFontString(Deposit.text)
  283.  
  284. -- Close button
  285. local Close = CreateFrame("Button", "StuffingCloseButtonReagent", Reagent, "UIPanelCloseButton")
  286. T.SkinCloseButton(Close, nil, nil, true)
  287. Close:SetSize(15, 15)
  288. Close:RegisterForClicks("AnyUp")
  289. Close:SetScript("OnClick", function(self, btn)
  290. if btn == "RightButton" then
  291. if Stuffing_DDMenu.initialize ~= Stuffing.Menu then
  292. CloseDropDownMenus()
  293. Stuffing_DDMenu.initialize = Stuffing.Menu
  294. end
  295. ToggleDropDownMenu(nil, nil, Stuffing_DDMenu, self:GetName(), 0, 0)
  296. return
  297. else
  298. StuffingBank_OnHide()
  299. end
  300. end)
  301.  
  302. local tooltip_hide = function()
  303. GameTooltip:Hide()
  304. end
  305.  
  306. local tooltip_show = function(self)
  307. GameTooltip:SetOwner(self, "ANCHOR_LEFT", 19, 7)
  308. GameTooltip:ClearLines()
  309. GameTooltip:SetText(L_BAG_RIGHT_CLICK_CLOSE)
  310. end
  311.  
  312. Close:HookScript("OnEnter", tooltip_show)
  313. Close:HookScript("OnLeave", tooltip_hide)
  314.  
  315. for i = 1, 98 do
  316. local button = _G["ReagentBankFrameItem" .. i]
  317. local icon = _G[button:GetName() .. "IconTexture"]
  318. local count = _G[button:GetName().."Count"]
  319.  
  320. ReagentBankFrame:SetParent(Reagent)
  321. ReagentBankFrame:ClearAllPoints()
  322. ReagentBankFrame:SetAllPoints()
  323.  
  324. button:StyleButton()
  325. button:SetTemplate("Default")
  326. button:SetNormalTexture(nil)
  327. button.IconBorder:SetAlpha(0)
  328.  
  329. button:ClearAllPoints()
  330. button:SetSize(C.bag.button_size, C.bag.button_size)
  331.  
  332. local _, _, _, quality = GetContainerItemInfo(-3, i)
  333. local clink = GetContainerItemLink(-3, i)
  334. if clink then
  335. if quality and quality > 1 then
  336. button:SetBackdropBorderColor(GetItemQualityColor(quality))
  337. end
  338. end
  339.  
  340. if i == 1 then
  341. button:SetPoint("TOPLEFT", Reagent, "TOPLEFT", 10, -27)
  342. LastRowButton = button
  343. LastButton = button
  344. elseif NumButtons == C.bag.bank_columns then
  345. button:SetPoint("TOPRIGHT", LastRowButton, "TOPRIGHT", 0, -(C.bag.button_space + C.bag.button_size))
  346. button:SetPoint("BOTTOMLEFT", LastRowButton, "BOTTOMLEFT", 0, -(C.bag.button_space + C.bag.button_size))
  347. LastRowButton = button
  348. NumRows = NumRows + 1
  349. NumButtons = 1
  350. else
  351. button:SetPoint("TOPRIGHT", LastButton, "TOPRIGHT", (C.bag.button_space + C.bag.button_size), 0)
  352. button:SetPoint("BOTTOMLEFT", LastButton, "BOTTOMLEFT", (C.bag.button_space + C.bag.button_size), 0)
  353. NumButtons = NumButtons + 1
  354. end
  355.  
  356. icon:SetTexCoord(0.1, 0.9, 0.1, 0.9)
  357. icon:SetPoint("TOPLEFT", 2, -2)
  358. icon:SetPoint("BOTTOMRIGHT", -2, 2)
  359.  
  360. count:SetFont(C.font.bags_font, C.font.bags_font_size, C.font.bags_font_style)
  361. count:SetShadowOffset(C.font.bags_font_shadow and 1 or 0, C.font.bags_font_shadow and -1 or 0)
  362. count:SetPoint("BOTTOMRIGHT", 1, 1)
  363.  
  364. LastButton = button
  365. end
  366. Reagent:SetHeight(((C.bag.button_size + C.bag.button_space) * (NumRows + 1) + 40) - C.bag.button_space)
  367.  
  368. MoneyFrame_Update(ReagentBankFrame.UnlockInfo.CostMoneyFrame, GetReagentBankCost())
  369. ReagentBankFrameUnlockInfo:StripTextures()
  370. ReagentBankFrameUnlockInfo:SetAllPoints(Reagent)
  371. ReagentBankFrameUnlockInfo:SetTemplate("Overlay")
  372. ReagentBankFrameUnlockInfo:SetFrameStrata("FULLSCREEN")
  373. ReagentBankFrameUnlockInfoPurchaseButton:SkinButton()
  374. end
  375.  
  376. function Stuffing:BagFrameSlotNew(p, slot)
  377. for _, v in ipairs(self.bagframe_buttons) do
  378. if v.slot == slot then
  379. return v, false
  380. end
  381. end
  382.  
  383. local ret = {}
  384.  
  385. if slot > 3 then
  386. ret.slot = slot
  387. slot = slot - 4
  388. ret.frame = CreateFrame("CheckButton", "StuffingBBag"..slot.."Slot", p, "BankItemButtonBagTemplate")
  389. ret.frame:StripTextures()
  390. ret.frame:SetID(slot)
  391. table.insert(self.bagframe_buttons, ret)
  392.  
  393. BankFrameItemButton_Update(ret.frame)
  394. BankFrameItemButton_UpdateLocked(ret.frame)
  395.  
  396. if not ret.frame.tooltipText then
  397. ret.frame.tooltipText = ""
  398. end
  399. else
  400. ret.frame = CreateFrame("CheckButton", "StuffingFBag"..slot.."Slot", p, "BagSlotButtonTemplate")
  401.  
  402. hooksecurefunc(ret.frame.IconBorder, "SetVertexColor", function(self, r, g, b)
  403. if r ~= 0.65882 and g ~= 0.65882 and b ~= 0.65882 then
  404. self:GetParent():SetBackdropBorderColor(r, g, b)
  405. end
  406. self:SetTexture("")
  407. end)
  408.  
  409. hooksecurefunc(ret.frame.IconBorder, "Hide", function(self)
  410. self:GetParent():SetBackdropBorderColor(unpack(C.media.border_color))
  411. end)
  412.  
  413. ret.slot = slot
  414. table.insert(self.bagframe_buttons, ret)
  415. end
  416.  
  417. ret.frame:SetTemplate("Default")
  418. ret.frame:StyleButton()
  419. ret.frame:SetNormalTexture("")
  420. ret.frame:SetCheckedTexture("")
  421.  
  422. ret.icon = _G[ret.frame:GetName().."IconTexture"]
  423. ret.icon:SetTexCoord(0.1, 0.9, 0.1, 0.9)
  424. ret.icon:SetPoint("TOPLEFT", ret.frame, 2, -2)
  425. ret.icon:SetPoint("BOTTOMRIGHT", ret.frame, -2, 2)
  426.  
  427. return ret
  428. end
  429.  
  430. function Stuffing:SlotNew(bag, slot)
  431. for _, v in ipairs(self.buttons) do
  432. if v.bag == bag and v.slot == slot then
  433. v.lock = false
  434. return v, false
  435. end
  436. end
  437.  
  438. local tpl = "ContainerFrameItemButtonTemplate"
  439.  
  440. if bag == -1 then
  441. tpl = "BankItemButtonGenericTemplate"
  442. end
  443.  
  444. local ret = {}
  445.  
  446. if #trashButton > 0 then
  447. local f = -1
  448. for i, v in ipairs(trashButton) do
  449. local b, s = v:GetName():match("(%d+)_(%d+)")
  450.  
  451. b = tonumber(b)
  452. s = tonumber(s)
  453.  
  454. if b == bag and s == slot then
  455. f = i
  456. break
  457. else
  458. v:Hide()
  459. end
  460. end
  461.  
  462. if f ~= -1 then
  463. ret.frame = trashButton[f]
  464. table.remove(trashButton, f)
  465. ret.frame:Show()
  466. end
  467. end
  468.  
  469. if not ret.frame then
  470. ret.frame = CreateFrame("Button", "StuffingBag"..bag.."_"..slot, self.bags[bag], tpl)
  471. ret.frame:StyleButton()
  472. ret.frame:SetTemplate("Default")
  473. ret.frame:SetNormalTexture(nil)
  474.  
  475. ret.icon = _G[ret.frame:GetName().."IconTexture"]
  476. ret.icon:SetTexCoord(0.1, 0.9, 0.1, 0.9)
  477. ret.icon:SetPoint("TOPLEFT", ret.frame, 2, -2)
  478. ret.icon:SetPoint("BOTTOMRIGHT", ret.frame, -2, 2)
  479.  
  480. ret.count = _G[ret.frame:GetName().."Count"]
  481. ret.count:SetFont(C.font.bags_font, C.font.bags_font_size, C.font.bags_font_style)
  482. ret.count:SetShadowOffset(C.font.bags_font_shadow and 1 or 0, C.font.bags_font_shadow and -1 or 0)
  483. ret.count:SetPoint("BOTTOMRIGHT", 1, 1)
  484.  
  485. if C.bag.ilvl == true then
  486. ret.frame:FontString("text", C.font.bags_font, C.font.bags_font_size, C.font.bags_font_style)
  487. ret.frame.text:SetPoint("TOPLEFT", 1, -1)
  488. ret.frame.text:SetTextColor(1, 1, 0)
  489. end
  490.  
  491. local Battlepay = _G[ret.frame:GetName()].BattlepayItemTexture
  492. if Battlepay then
  493. Battlepay:SetAlpha(0)
  494. end
  495. end
  496.  
  497. ret.bag = bag
  498. ret.slot = slot
  499. ret.frame:SetID(slot)
  500.  
  501. ret.cooldown = _G[ret.frame:GetName().."Cooldown"]
  502. ret.cooldown:Show()
  503.  
  504. self:SlotUpdate(ret)
  505.  
  506. return ret, true
  507. end
  508.  
  509. -- From OneBag
  510. local BAGTYPE_PROFESSION = 0x0008 + 0x0010 + 0x0020 + 0x0040 + 0x0080 + 0x0200 + 0x0400 + 0x10000
  511. local BAGTYPE_FISHING = 32768
  512.  
  513. function Stuffing:BagType(bag)
  514. local bagType = select(2, GetContainerNumFreeSlots(bag))
  515.  
  516. if bagType and bit.band(bagType, BAGTYPE_FISHING) > 0 then
  517. return ST_FISHBAG
  518. elseif bagType and bit.band(bagType, BAGTYPE_PROFESSION) > 0 then
  519. return ST_SPECIAL
  520. end
  521.  
  522. return ST_NORMAL
  523. end
  524.  
  525. function Stuffing:BagNew(bag, f)
  526. for i, v in pairs(self.bags) do
  527. if v:GetID() == bag then
  528. v.bagType = self:BagType(bag)
  529. return v
  530. end
  531. end
  532.  
  533. local ret
  534.  
  535. if #trashBag > 0 then
  536. local f = -1
  537. for i, v in pairs(trashBag) do
  538. if v:GetID() == bag then
  539. f = i
  540. break
  541. end
  542. end
  543.  
  544. if f ~= -1 then
  545. ret = trashBag[f]
  546. table.remove(trashBag, f)
  547. ret:Show()
  548. ret.bagType = self:BagType(bag)
  549. return ret
  550. end
  551. end
  552.  
  553. ret = CreateFrame("Frame", "StuffingBag"..bag, f)
  554. ret.bagType = self:BagType(bag)
  555.  
  556. ret:SetID(bag)
  557. return ret
  558. end
  559.  
  560. function Stuffing:SearchUpdate(str)
  561. str = string.lower(str)
  562.  
  563. for _, b in ipairs(self.buttons) do
  564. if b.frame and not b.name then
  565. b.frame:SetAlpha(0.2)
  566. end
  567. if b.name then
  568. local _, setName = GetContainerItemEquipmentSetInfo(b.bag, b.slot)
  569. setName = setName or ""
  570. local ilink = GetContainerItemLink(b.bag, b.slot)
  571. local class, subclass, _, equipSlot = select(6, GetItemInfo(ilink))
  572. local minLevel = select(5, GetItemInfo(ilink))
  573. equipSlot = _G[equipSlot] or ""
  574. if not string.find(string.lower(b.name), str) and not string.find(string.lower(setName), str) and not string.find(string.lower(class), str) and not string.find(string.lower(subclass), str) and not string.find(string.lower(equipSlot), str) then
  575. if IsItemUnusable(b.name) or minLevel > T.level then
  576. _G[b.frame:GetName().."IconTexture"]:SetVertexColor(0.5, 0.5, 0.5)
  577. end
  578. SetItemButtonDesaturated(b.frame, true)
  579. b.frame:SetAlpha(0.2)
  580. else
  581. if IsItemUnusable(b.name) or minLevel > T.level then
  582. _G[b.frame:GetName().."IconTexture"]:SetVertexColor(1, 0.1, 0.1)
  583. end
  584. SetItemButtonDesaturated(b.frame, false)
  585. b.frame:SetAlpha(1)
  586. end
  587. end
  588. end
  589. end
  590.  
  591. function Stuffing:SearchReset()
  592. for _, b in ipairs(self.buttons) do
  593. if IsItemUnusable(b.name) or (b.level and b.level > T.level) then
  594. _G[b.frame:GetName().."IconTexture"]:SetVertexColor(1, 0.1, 0.1)
  595. end
  596. b.frame:SetAlpha(1)
  597. SetItemButtonDesaturated(b.frame, false)
  598. end
  599. end
  600.  
  601. local function DragFunction(self, mode)
  602. for index = 1, select("#", self:GetChildren()) do
  603. local frame = select(index, self:GetChildren())
  604. if frame:GetName() and frame:GetName():match("StuffingBag") then
  605. if mode then
  606. frame:Hide()
  607. else
  608. frame:Show()
  609. end
  610. end
  611. end
  612. end
  613.  
  614. function Stuffing:CreateBagFrame(w)
  615. local n = "StuffingFrame"..w
  616. local f = CreateFrame("Frame", n, UIParent)
  617. f:EnableMouse(true)
  618. f:SetMovable(true)
  619. f:SetFrameStrata("MEDIUM")
  620. f:SetFrameLevel(5)
  621. f:RegisterForDrag("LeftButton")
  622. f:SetScript("OnDragStart", function(self)
  623. if IsShiftKeyDown() then
  624. self:StartMoving()
  625. DragFunction(self, true)
  626. end
  627. end)
  628. f:SetScript("OnDragStop", function(self)
  629. self:StopMovingOrSizing()
  630. DragFunction(self, false)
  631. end)
  632.  
  633. if w == "Bank" then
  634. f:SetPoint(unpack(C.position.bank))
  635. else
  636. f:SetPoint(unpack(C.position.bag))
  637. end
  638.  
  639. if w == "Bank" then
  640. -- Reagent button
  641. f.b_reagent = CreateFrame("Button", "StuffingReagentButton"..w, f)
  642. f.b_reagent:SetSize(105, 20)
  643. f.b_reagent:SetPoint("TOPLEFT", 10, -4)
  644. f.b_reagent:RegisterForClicks("AnyUp")
  645. f.b_reagent:SkinButton()
  646. f.b_reagent:SetScript("OnClick", function()
  647. BankFrame_ShowPanel(BANK_PANELS[2].name)
  648. PlaySound("igBackPackOpen")
  649. if not ReagentBankFrame.isMade then
  650. CreateReagentContainer()
  651. ReagentBankFrame.isMade = true
  652. else
  653. _G["StuffingFrameReagent"]:Show()
  654. end
  655. _G["StuffingFrameBank"]:SetAlpha(0)
  656. end)
  657. f.b_reagent:FontString("text", C.font.bags_font, C.font.bags_font_size, C.font.bags_font_style)
  658. f.b_reagent.text:SetPoint("CENTER")
  659. f.b_reagent.text:SetText(REAGENT_BANK)
  660. f.b_reagent:SetFontString(f.b_reagent.text)
  661.  
  662. -- Buy button
  663. f.b_purchase = CreateFrame("Button", "StuffingPurchaseButton"..w, f)
  664. f.b_purchase:SetSize(80, 20)
  665. f.b_purchase:SetPoint("TOPLEFT", f.b_reagent, "TOPRIGHT", 3, 0)
  666. f.b_purchase:RegisterForClicks("AnyUp")
  667. f.b_purchase:SkinButton()
  668. f.b_purchase:SetScript("OnClick", function(self) StaticPopup_Show("CONFIRM_BUY_BANK_SLOT") end)
  669. f.b_purchase:FontString("text", C.font.bags_font, C.font.bags_font_size, C.font.bags_font_style)
  670. f.b_purchase.text:SetPoint("CENTER")
  671. f.b_purchase.text:SetText(BANKSLOTPURCHASE)
  672. f.b_purchase:SetFontString(f.b_purchase.text)
  673. local _, full = GetNumBankSlots()
  674. if full then
  675. f.b_purchase:Hide()
  676. else
  677. f.b_purchase:Show()
  678. end
  679. end
  680.  
  681. -- Close button
  682. f.b_close = CreateFrame("Button", "StuffingCloseButton"..w, f, "UIPanelCloseButton")
  683. T.SkinCloseButton(f.b_close, nil, nil, true)
  684. f.b_close:SetSize(15, 15)
  685. f.b_close:RegisterForClicks("AnyUp")
  686. f.b_close:SetScript("OnClick", function(self, btn)
  687. if btn == "RightButton" then
  688. if Stuffing_DDMenu.initialize ~= Stuffing.Menu then
  689. CloseDropDownMenus()
  690. Stuffing_DDMenu.initialize = Stuffing.Menu
  691. end
  692. ToggleDropDownMenu(nil, nil, Stuffing_DDMenu, self:GetName(), 0, 0)
  693. return
  694. end
  695. self:GetParent():Hide()
  696. end)
  697.  
  698. local tooltip_hide = function()
  699. GameTooltip:Hide()
  700. end
  701.  
  702. local tooltip_show = function(self)
  703. GameTooltip:SetOwner(self, "ANCHOR_LEFT", 19, 7)
  704. GameTooltip:ClearLines()
  705. GameTooltip:SetText(L_BAG_RIGHT_CLICK_CLOSE)
  706. end
  707.  
  708. f.b_close:HookScript("OnEnter", tooltip_show)
  709. f.b_close:HookScript("OnLeave", tooltip_hide)
  710.  
  711. -- Create the bags frame
  712. local fb = CreateFrame("Frame", n.."BagsFrame", f)
  713. fb:SetPoint("BOTTOMLEFT", f, "TOPLEFT", 0, 3)
  714. fb:SetFrameStrata("MEDIUM")
  715. f.bags_frame = fb
  716.  
  717. return f
  718. end
  719.  
  720. function Stuffing:InitBank()
  721. if self.bankFrame then
  722. return
  723. end
  724.  
  725. local f = self:CreateBagFrame("Bank")
  726. f:SetScript("OnHide", StuffingBank_OnHide)
  727. self.bankFrame = f
  728. end
  729.  
  730. function Stuffing:InitBags()
  731. if self.frame then return end
  732.  
  733. self.buttons = {}
  734. self.bags = {}
  735. self.bagframe_buttons = {}
  736.  
  737. local f = self:CreateBagFrame("Bags")
  738. f:SetScript("OnShow", Stuffing_OnShow)
  739. f:SetScript("OnHide", Stuffing_OnHide)
  740.  
  741. -- Search editbox (tekKonfigAboutPanel.lua)
  742. local editbox = CreateFrame("EditBox", nil, f)
  743. editbox:Hide()
  744. editbox:SetAutoFocus(true)
  745. editbox:SetHeight(32)
  746. editbox:CreateBackdrop("Default")
  747. editbox.backdrop:SetPoint("TOPLEFT", -2, 1)
  748. editbox.backdrop:SetPoint("BOTTOMRIGHT", 2, -1)
  749.  
  750. local resetAndClear = function(self)
  751. self:GetParent().detail:Show()
  752. self:ClearFocus()
  753. Stuffing:SearchReset()
  754. end
  755.  
  756. local updateSearch = function(self, t)
  757. if t == true then
  758. Stuffing:SearchUpdate(self:GetText())
  759. end
  760. end
  761.  
  762. editbox:SetScript("OnEscapePressed", resetAndClear)
  763. editbox:SetScript("OnEnterPressed", resetAndClear)
  764. editbox:SetScript("OnEditFocusLost", editbox.Hide)
  765. editbox:SetScript("OnEditFocusGained", editbox.HighlightText)
  766. editbox:SetScript("OnTextChanged", updateSearch)
  767. editbox:SetText(SEARCH)
  768.  
  769. local detail = f:CreateFontString(nil, "ARTWORK", "GameFontHighlightLarge")
  770. detail:SetPoint("TOPLEFT", f, 11, -10)
  771. detail:SetPoint("RIGHT", f, -140, -10)
  772. detail:SetHeight(13)
  773. detail:SetShadowColor(0, 0, 0, 0)
  774. detail:SetJustifyH("LEFT")
  775. detail:SetText("|cff9999ff"..SEARCH.."|r")
  776. editbox:SetAllPoints(detail)
  777.  
  778. local button = CreateFrame("Button", nil, f)
  779. button:EnableMouse(true)
  780. button:RegisterForClicks("LeftButtonUp", "RightButtonUp")
  781. button:SetAllPoints(detail)
  782. button:SetScript("OnClick", function(self, btn)
  783. if btn == "RightButton" then
  784. self:GetParent().detail:Hide()
  785. self:GetParent().editbox:Show()
  786. self:GetParent().editbox:HighlightText()
  787. else
  788. if self:GetParent().editbox:IsShown() then
  789. self:GetParent().editbox:Hide()
  790. self:GetParent().editbox:ClearFocus()
  791. self:GetParent().detail:Show()
  792. Stuffing:SearchReset()
  793. end
  794. end
  795. end)
  796.  
  797. local tooltip_hide = function()
  798. GameTooltip:Hide()
  799. end
  800.  
  801. local tooltip_show = function(self)
  802. GameTooltip:SetOwner(self, "ANCHOR_TOPLEFT", -12, 11)
  803. GameTooltip:ClearLines()
  804. GameTooltip:SetText(L_BAG_RIGHT_CLICK_SEARCH)
  805. end
  806.  
  807. button:SetScript("OnEnter", tooltip_show)
  808. button:SetScript("OnLeave", tooltip_hide)
  809.  
  810. f.editbox = editbox
  811. f.detail = detail
  812. f.button = button
  813. self.frame = f
  814. f:Hide()
  815. end
  816.  
  817. function Stuffing:Layout(isBank)
  818. local slots = 0
  819. local rows = 0
  820. local off = 20
  821. local cols, f, bs
  822.  
  823. if isBank then
  824. bs = BAGS_BANK
  825. cols = C.bag.bank_columns
  826. f = self.bankFrame
  827. f:SetAlpha(1)
  828. else
  829. bs = BAGS_BACKPACK
  830. cols = C.bag.bag_columns
  831. f = self.frame
  832.  
  833. f.editbox:SetFont(C.media.normal_font, C.font.bags_font_size + 3)
  834. f.detail:SetFont(C.font.bags_font, C.font.bags_font_size, C.font.bags_font_style)
  835. f.detail:SetShadowOffset(C.font.bags_font_shadow and 1 or 0, C.font.bags_font_shadow and -1 or 0)
  836.  
  837. f.detail:ClearAllPoints()
  838. f.detail:SetPoint("TOPLEFT", f, 12, -8)
  839. f.detail:SetPoint("RIGHT", f, -140, 0)
  840. end
  841.  
  842. f:SetClampedToScreen(1)
  843. f:SetTemplate("Transparent")
  844.  
  845. -- Bag frame stuff
  846. local fb = f.bags_frame
  847. if bag_bars == 1 then
  848. fb:SetClampedToScreen(1)
  849. fb:SetTemplate("Transparent")
  850.  
  851. local bsize = C.bag.button_size
  852.  
  853. local w = 2 * 10
  854. w = w + ((#bs - 1) * bsize)
  855. w = w + ((#bs - 2) * 4)
  856.  
  857. fb:SetHeight(2 * 10 + bsize)
  858. fb:SetWidth(w)
  859. fb:Show()
  860. else
  861. fb:Hide()
  862. end
  863.  
  864. local idx = 0
  865. for _, v in ipairs(bs) do
  866. if (not isBank and v <= 3 ) or (isBank and v ~= -1) then
  867. local bsize = C.bag.button_size
  868. local b = self:BagFrameSlotNew(fb, v)
  869. local xoff = 10
  870.  
  871. xoff = xoff + (idx * bsize)
  872. xoff = xoff + (idx * 4)
  873.  
  874. b.frame:ClearAllPoints()
  875. b.frame:SetPoint("LEFT", fb, "LEFT", xoff, 0)
  876. b.frame:SetSize(bsize, bsize)
  877.  
  878. local btns = self.buttons
  879. b.frame:HookScript("OnEnter", function(self)
  880. local bag
  881. if isBank then bag = v else bag = v + 1 end
  882.  
  883. for ind, val in ipairs(btns) do
  884. if val.bag == bag then
  885. val.frame:SetAlpha(1)
  886. else
  887. val.frame:SetAlpha(0.2)
  888. end
  889. end
  890. end)
  891.  
  892. b.frame:HookScript("OnLeave", function(self)
  893. for _, btn in ipairs(btns) do
  894. btn.frame:SetAlpha(1)
  895. end
  896. end)
  897.  
  898. b.frame:SetScript("OnClick", nil)
  899.  
  900. idx = idx + 1
  901. end
  902. end
  903.  
  904. for _, i in ipairs(bs) do
  905. local x = GetContainerNumSlots(i)
  906. if x > 0 then
  907. if not self.bags[i] then
  908. self.bags[i] = self:BagNew(i, f)
  909. end
  910.  
  911. slots = slots + GetContainerNumSlots(i)
  912. end
  913. end
  914.  
  915. rows = floor(slots / cols)
  916. if (slots % cols) ~= 0 then
  917. rows = rows + 1
  918. end
  919.  
  920. f:SetWidth(cols * C.bag.button_size + (cols - 1) * C.bag.button_space + 10 * 2)
  921. f:SetHeight(rows * C.bag.button_size + (rows - 1) * C.bag.button_space + off + 10 * 2)
  922.  
  923. local idx = 0
  924. for _, i in ipairs(bs) do
  925. local bag_cnt = GetContainerNumSlots(i)
  926. local specialType = select(2, GetContainerNumFreeSlots(i))
  927. if bag_cnt > 0 then
  928. self.bags[i] = self:BagNew(i, f)
  929. local bagType = self.bags[i].bagType
  930.  
  931. self.bags[i]:Show()
  932. for j = 1, bag_cnt do
  933. local b, isnew = self:SlotNew(i, j)
  934. local xoff
  935. local yoff
  936. local x = (idx % cols)
  937. local y = floor(idx / cols)
  938.  
  939. if isnew then
  940. table.insert(self.buttons, idx + 1, b)
  941. end
  942.  
  943. xoff = 10 + (x * C.bag.button_size) + (x * C.bag.button_space)
  944. yoff = off + 10 + (y * C.bag.button_size) + ((y - 1) * C.bag.button_space)
  945. yoff = yoff * -1
  946.  
  947. b.frame:ClearAllPoints()
  948. b.frame:SetPoint("TOPLEFT", f, "TOPLEFT", xoff, yoff)
  949. b.frame:SetSize(C.bag.button_size, C.bag.button_size)
  950. b.frame.lock = false
  951. b.frame:SetAlpha(1)
  952.  
  953. if bagType == ST_FISHBAG then
  954. b.frame:SetBackdropBorderColor(1, 0, 0) -- Tackle
  955. b.frame.lock = true
  956. elseif bagType == ST_SPECIAL then
  957. if specialType == 0x0008 then -- Leatherworking
  958. b.frame:SetBackdropBorderColor(0.8, 0.7, 0.3)
  959. elseif specialType == 0x0010 then -- Inscription
  960. b.frame:SetBackdropBorderColor(0.3, 0.3, 0.8)
  961. elseif specialType == 0x0020 then -- Herbs
  962. b.frame:SetBackdropBorderColor(0.3, 0.7, 0.3)
  963. elseif specialType == 0x0040 then -- Enchanting
  964. b.frame:SetBackdropBorderColor(0.6, 0, 0.6)
  965. elseif specialType == 0x0080 then -- Engineering
  966. b.frame:SetBackdropBorderColor(0.9, 0.4, 0.1)
  967. elseif specialType == 0x0200 then -- Gems
  968. b.frame:SetBackdropBorderColor(0, 0.7, 0.8)
  969. elseif specialType == 0x0400 then -- Mining
  970. b.frame:SetBackdropBorderColor(0.4, 0.3, 0.1)
  971. elseif specialType == 0x10000 then -- Cooking
  972. b.frame:SetBackdropBorderColor(0.9, 0, 0.1)
  973. end
  974. b.frame.lock = true
  975. end
  976.  
  977. idx = idx + 1
  978. end
  979. end
  980. end
  981. end
  982.  
  983. function Stuffing:SetBagsForSorting(c)
  984. Stuffing_Open()
  985.  
  986. self.sortBags = {}
  987.  
  988. local cmd = ((c == nil or c == "") and {"d"} or {strsplit("/", c)})
  989.  
  990. for _, s in ipairs(cmd) do
  991. if s == "c" then
  992. self.sortBags = {}
  993. elseif s == "d" then
  994. if not self.bankFrame or not self.bankFrame:IsShown() then
  995. for _, i in ipairs(BAGS_BACKPACK) do
  996. if self.bags[i] and self.bags[i].bagType == ST_NORMAL then
  997. table.insert(self.sortBags, i)
  998. end
  999. end
  1000. elseif not _G["StuffingFrameReagent"] or not _G["StuffingFrameReagent"]:IsShown() then
  1001. for _, i in ipairs(BAGS_BANK) do
  1002. if self.bags[i] and self.bags[i].bagType == ST_NORMAL then
  1003. table.insert(self.sortBags, i)
  1004. end
  1005. end
  1006. end
  1007. elseif s == "p" then
  1008. if not self.bankFrame or not self.bankFrame:IsShown() then
  1009. for _, i in ipairs(BAGS_BACKPACK) do
  1010. if self.bags[i] and self.bags[i].bagType == ST_SPECIAL then
  1011. table.insert(self.sortBags, i)
  1012. end
  1013. end
  1014. else
  1015. for _, i in ipairs(BAGS_BANK) do
  1016. if self.bags[i] and self.bags[i].bagType == ST_SPECIAL then
  1017. table.insert(self.sortBags, i)
  1018. end
  1019. end
  1020. end
  1021. else
  1022. table.insert(self.sortBags, tonumber(s))
  1023. end
  1024. end
  1025. end
  1026.  
  1027. function Stuffing:ADDON_LOADED(addon)
  1028. if addon ~= "ShestakUI" then return nil end
  1029.  
  1030. self:RegisterEvent("BAG_UPDATE")
  1031. self:RegisterEvent("ITEM_LOCK_CHANGED")
  1032. self:RegisterEvent("BANKFRAME_OPENED")
  1033. self:RegisterEvent("BANKFRAME_CLOSED")
  1034. self:RegisterEvent("GUILDBANKFRAME_OPENED")
  1035. self:RegisterEvent("GUILDBANKFRAME_CLOSED")
  1036. self:RegisterEvent("PLAYERBANKSLOTS_CHANGED")
  1037. self:RegisterEvent("PLAYERBANKBAGSLOTS_CHANGED")
  1038. self:RegisterEvent("PLAYERREAGENTBANKSLOTS_CHANGED")
  1039. self:RegisterEvent("BAG_CLOSED")
  1040. self:RegisterEvent("BAG_UPDATE_COOLDOWN")
  1041. --self:RegisterEvent("REAGENTBANK_UPDATE")
  1042.  
  1043. self:InitBags()
  1044.  
  1045. tinsert(UISpecialFrames, "StuffingFrameBags")
  1046. tinsert(UISpecialFrames, "StuffingFrameReagent")
  1047.  
  1048. ToggleBackpack = Stuffing_Toggle
  1049. ToggleBag = Stuffing_Toggle
  1050. ToggleAllBags = Stuffing_Toggle
  1051. OpenAllBags = Stuffing_Open
  1052. OpenBackpack = Stuffing_Open
  1053. CloseAllBags = Stuffing_Close
  1054. CloseBackpack = Stuffing_Close
  1055.  
  1056. --BankFrame:UnregisterAllEvents()
  1057. BankFrame:SetScale(0.00001)
  1058. BankFrame:SetAlpha(0)
  1059. BankFrame:SetPoint("TOPLEFT")
  1060. end
  1061.  
  1062. function Stuffing:PLAYER_ENTERING_WORLD()
  1063. Stuffing:UnregisterEvent("PLAYER_ENTERING_WORLD")
  1064. ToggleBackpack()
  1065. ToggleBackpack()
  1066. end
  1067.  
  1068. function Stuffing:PLAYERBANKSLOTS_CHANGED(id)
  1069. if id > 28 then
  1070. for _, v in ipairs(self.bagframe_buttons) do
  1071. if v.frame and v.frame.GetInventorySlot then
  1072.  
  1073. BankFrameItemButton_Update(v.frame)
  1074. BankFrameItemButton_UpdateLocked(v.frame)
  1075.  
  1076. if not v.frame.tooltipText then
  1077. v.frame.tooltipText = ""
  1078. end
  1079. end
  1080. end
  1081. end
  1082.  
  1083. if self.bankFrame and self.bankFrame:IsShown() then
  1084. self:BagSlotUpdate(-1)
  1085. end
  1086. end
  1087.  
  1088. function Stuffing:PLAYERREAGENTBANKSLOTS_CHANGED()
  1089. for i = 1, 98 do
  1090. local button = _G["ReagentBankFrameItem" .. i]
  1091. if not button then return end
  1092. local _, _, _, quality = GetContainerItemInfo(-3, i)
  1093. local clink = GetContainerItemLink(-3, i)
  1094. button:SetBackdropBorderColor(unpack(C.media.border_color))
  1095.  
  1096. if clink then
  1097. if quality and quality > 1 then
  1098. button:SetBackdropBorderColor(GetItemQualityColor(quality))
  1099. end
  1100. end
  1101. end
  1102. end
  1103.  
  1104. function Stuffing:BAG_UPDATE(id)
  1105. self:BagSlotUpdate(id)
  1106. end
  1107.  
  1108. function Stuffing:ITEM_LOCK_CHANGED(bag, slot)
  1109. if slot == nil then return end
  1110. for _, v in ipairs(self.buttons) do
  1111. if v.bag == bag and v.slot == slot then
  1112. self:SlotUpdate(v)
  1113. break
  1114. end
  1115. end
  1116. end
  1117.  
  1118. function Stuffing:BANKFRAME_OPENED()
  1119. if not self.bankFrame then
  1120. self:InitBank()
  1121. end
  1122.  
  1123. self:Layout(true)
  1124. for _, x in ipairs(BAGS_BANK) do
  1125. self:BagSlotUpdate(x)
  1126. end
  1127.  
  1128. self.bankFrame:Show()
  1129. Stuffing_Open()
  1130. end
  1131.  
  1132. function Stuffing:BANKFRAME_CLOSED()
  1133. if StuffingFrameReagent then
  1134. StuffingFrameReagent:Hide()
  1135. end
  1136. if self.bankFrame then
  1137. self.bankFrame:Hide()
  1138. end
  1139. end
  1140.  
  1141. function Stuffing:GUILDBANKFRAME_OPENED()
  1142. Stuffing_Open()
  1143. end
  1144.  
  1145. function Stuffing:GUILDBANKFRAME_CLOSED()
  1146. Stuffing_Close()
  1147. end
  1148.  
  1149. function Stuffing:BAG_CLOSED(id)
  1150. local b = self.bags[id]
  1151. if b then
  1152. table.remove(self.bags, id)
  1153. b:Hide()
  1154. table.insert(trashBag, #trashBag + 1, b)
  1155. end
  1156.  
  1157. while true do
  1158. local changed = false
  1159.  
  1160. for i, v in ipairs(self.buttons) do
  1161. if v.bag == id then
  1162. v.frame:Hide()
  1163. v.frame.lock = false
  1164.  
  1165. table.insert(trashButton, #trashButton + 1, v.frame)
  1166. table.remove(self.buttons, i)
  1167.  
  1168. v = nil
  1169. changed = true
  1170. end
  1171. end
  1172.  
  1173. if not changed then
  1174. break
  1175. end
  1176. end
  1177. end
  1178.  
  1179. function Stuffing:BAG_UPDATE_COOLDOWN()
  1180. for i, v in pairs(self.buttons) do
  1181. self:SlotUpdate(v)
  1182. end
  1183. end
  1184.  
  1185. local function InBags(x)
  1186. if not Stuffing.bags[x] then
  1187. return false
  1188. end
  1189.  
  1190. for _, v in ipairs(Stuffing.sortBags) do
  1191. if x == v then
  1192. return true
  1193. end
  1194. end
  1195. return false
  1196. end
  1197.  
  1198. local BS_bagGroups
  1199. local BS_itemSwapGrid
  1200.  
  1201. local function BS_clearData()
  1202. BS_itemSwapGrid = {}
  1203. BS_bagGroups = {}
  1204. end
  1205.  
  1206. function Stuffing:SortOnUpdate(elapsed)
  1207. self.elapsed = (self.elapsed or 0) + elapsed
  1208.  
  1209. if self.elapsed < 0.05 then
  1210. return
  1211. end
  1212.  
  1213. self.elapsed = 0
  1214.  
  1215. local changed = false
  1216. local blocked = false
  1217.  
  1218. for bagIndex in pairs(BS_itemSwapGrid) do
  1219. for slotIndex in pairs(BS_itemSwapGrid[bagIndex]) do
  1220. local destinationBag = BS_itemSwapGrid[bagIndex][slotIndex].destinationBag
  1221. local destinationSlot = BS_itemSwapGrid[bagIndex][slotIndex].destinationSlot
  1222.  
  1223. local _, _, locked1 = GetContainerItemInfo(bagIndex, slotIndex)
  1224. local _, _, locked2 = GetContainerItemInfo(destinationBag, destinationSlot)
  1225.  
  1226. if locked1 or locked2 then
  1227. blocked = true
  1228. elseif bagIndex ~= destinationBag or slotIndex ~= destinationSlot then
  1229. PickupContainerItem(bagIndex, slotIndex)
  1230. PickupContainerItem(destinationBag, destinationSlot)
  1231.  
  1232. local tempItem = BS_itemSwapGrid[destinationBag][destinationSlot]
  1233. BS_itemSwapGrid[destinationBag][destinationSlot] = BS_itemSwapGrid[bagIndex][slotIndex]
  1234. BS_itemSwapGrid[bagIndex][slotIndex] = tempItem
  1235.  
  1236. changed = true
  1237. return
  1238. end
  1239. end
  1240. end
  1241.  
  1242. if not changed and not blocked then
  1243. self:SetScript("OnUpdate", nil)
  1244. BS_clearData()
  1245. end
  1246. end
  1247.  
  1248. function Stuffing:SortBags()
  1249. BS_clearData()
  1250.  
  1251. local bagList
  1252. if _G["StuffingFrameReagent"] and _G["StuffingFrameReagent"]:IsShown() then
  1253. bagList = {-3}
  1254. elseif Stuffing.bankFrame and Stuffing.bankFrame:IsShown() then
  1255. bagList = {11, 10, 9, 8, 7, 6, 5, -1}
  1256. else
  1257. bagList = {4, 3, 2, 1, 0}
  1258. end
  1259.  
  1260. for _, slotNum in pairs(bagList) do
  1261. if GetContainerNumSlots(slotNum) > 0 then
  1262. BS_itemSwapGrid[slotNum] = {}
  1263. local family = select(2, GetContainerNumFreeSlots(slotNum))
  1264. if family then
  1265. if family == 0 then family = "Default" end
  1266. if not BS_bagGroups[family] then
  1267. BS_bagGroups[family] = {}
  1268. BS_bagGroups[family].bagSlotNumbers = {}
  1269. end
  1270. table.insert(BS_bagGroups[family].bagSlotNumbers, slotNum)
  1271. end
  1272. end
  1273. end
  1274.  
  1275. for _, group in pairs(BS_bagGroups) do
  1276. group.itemList = {}
  1277. for _, bagSlot in pairs(group.bagSlotNumbers) do
  1278. for itemSlot = 1, GetContainerNumSlots(bagSlot) do
  1279.  
  1280. local itemLink = GetContainerItemLink(bagSlot, itemSlot)
  1281. if itemLink ~= nil then
  1282.  
  1283. local newItem = {}
  1284.  
  1285. local n, _, q, iL, rL, c1, c2, _, Sl = GetItemInfo(itemLink)
  1286. -- Hearthstone
  1287. if n == GetItemInfo(6948) or n == GetItemInfo(110560) then
  1288. q = 9
  1289. end
  1290. -- Fix for battle pets
  1291. if not n then
  1292. n = itemLink
  1293. q = select(4, GetContainerItemInfo(bagSlot, itemSlot))
  1294. iL = 1
  1295. rL = 1
  1296. c1 = "Pet"
  1297. c2 = "Pet"
  1298. Sl = ""
  1299. end
  1300.  
  1301. newItem.sort = q..c1..c2..rL..n..iL..Sl
  1302.  
  1303. tinsert(group.itemList, newItem)
  1304.  
  1305. BS_itemSwapGrid[bagSlot][itemSlot] = newItem
  1306. newItem.startBag = bagSlot
  1307. newItem.startSlot = itemSlot
  1308. end
  1309. end
  1310. end
  1311.  
  1312. table.sort(group.itemList, function(a, b)
  1313. return a.sort > b.sort
  1314. end)
  1315.  
  1316. for index, item in pairs(group.itemList) do
  1317. local gridSlot = index
  1318. for _, bagSlotNumber in pairs(group.bagSlotNumbers) do
  1319. if gridSlot <= GetContainerNumSlots(bagSlotNumber) then
  1320. BS_itemSwapGrid[item.startBag][item.startSlot].destinationBag = bagSlotNumber
  1321. BS_itemSwapGrid[item.startBag][item.startSlot].destinationSlot = GetContainerNumSlots(bagSlotNumber) - gridSlot + 1
  1322. break
  1323. else
  1324. gridSlot = gridSlot - GetContainerNumSlots(bagSlotNumber)
  1325. end
  1326. end
  1327. end
  1328. end
  1329.  
  1330. self:SetScript("OnUpdate", Stuffing.SortOnUpdate)
  1331. end
  1332.  
  1333. function Stuffing:RestackOnUpdate(e)
  1334. if not self.elapsed then
  1335. self.elapsed = 0
  1336. end
  1337.  
  1338. self.elapsed = self.elapsed + e
  1339.  
  1340. if self.elapsed < 0.1 then return end
  1341.  
  1342. self.elapsed = 0
  1343. self:Restack()
  1344. end
  1345.  
  1346. function Stuffing:Restack()
  1347. local st = {}
  1348.  
  1349. Stuffing_Open()
  1350.  
  1351. for i, v in pairs(self.buttons) do
  1352. if InBags(v.bag) then
  1353. local _, cnt, _, _, _, _, clink = GetContainerItemInfo(v.bag, v.slot)
  1354. if clink then
  1355. local n, _, _, _, _, _, _, s = GetItemInfo(clink)
  1356.  
  1357. if n and cnt ~= s then
  1358. if not st[n] then
  1359. st[n] = {{item = v, size = cnt, max = s}}
  1360. else
  1361. table.insert(st[n], {item = v, size = cnt, max = s})
  1362. end
  1363. end
  1364. end
  1365. end
  1366. end
  1367.  
  1368. local did_restack = false
  1369.  
  1370. for i, v in pairs(st) do
  1371. if #v > 1 then
  1372. for j = 2, #v, 2 do
  1373. local a, b = v[j - 1], v[j]
  1374. local _, _, l1 = GetContainerItemInfo(a.item.bag, a.item.slot)
  1375. local _, _, l2 = GetContainerItemInfo(b.item.bag, b.item.slot)
  1376.  
  1377. if l1 or l2 then
  1378. did_restack = true
  1379. else
  1380. PickupContainerItem(a.item.bag, a.item.slot)
  1381. PickupContainerItem(b.item.bag, b.item.slot)
  1382. did_restack = true
  1383. end
  1384. end
  1385. end
  1386. end
  1387.  
  1388. if did_restack then
  1389. self:SetScript("OnUpdate", Stuffing.RestackOnUpdate)
  1390. else
  1391. self:SetScript("OnUpdate", nil)
  1392. end
  1393. end
  1394.  
  1395. function Stuffing:PLAYERBANKBAGSLOTS_CHANGED()
  1396. if not StuffingPurchaseButtonBank then return end
  1397. local _, full = GetNumBankSlots()
  1398. if full then
  1399. StuffingPurchaseButtonBank:Hide()
  1400. else
  1401. StuffingPurchaseButtonBank:Show()
  1402. end
  1403. end
  1404.  
  1405. function Stuffing.Menu(self, level)
  1406. if not level then return end
  1407.  
  1408. local info = self.info
  1409.  
  1410. wipe(info)
  1411.  
  1412. if level ~= 1 then return end
  1413.  
  1414. wipe(info)
  1415. info.text = BAG_FILTER_CLEANUP.." Blizzard"
  1416. info.notCheckable = 1
  1417. info.func = function()
  1418. if _G["StuffingFrameReagent"] and _G["StuffingFrameReagent"]:IsShown() then
  1419. SortReagentBankBags()
  1420. elseif Stuffing.bankFrame and Stuffing.bankFrame:IsShown() then
  1421. SortBankBags()
  1422. else
  1423. SortBags()
  1424. end
  1425. end
  1426. UIDropDownMenu_AddButton(info, level)
  1427.  
  1428. wipe(info)
  1429. info.text = BAG_FILTER_CLEANUP
  1430. info.notCheckable = 1
  1431. info.func = function()
  1432. if InCombatLockdown() then
  1433. print("|cffffff00"..ERR_NOT_IN_COMBAT.."|r") return
  1434. end
  1435. Stuffing:SortBags()
  1436. end
  1437. UIDropDownMenu_AddButton(info, level)
  1438.  
  1439. wipe(info)
  1440. info.text = L_BAG_STACK_MENU
  1441. info.notCheckable = 1
  1442. info.func = function()
  1443. if InCombatLockdown() then
  1444. print("|cffffff00"..ERR_NOT_IN_COMBAT.."|r") return
  1445. end
  1446. Stuffing:SetBagsForSorting("d")
  1447. Stuffing:Restack()
  1448. end
  1449. UIDropDownMenu_AddButton(info, level)
  1450.  
  1451. wipe(info)
  1452. info.text = L_BAG_SHOW_BAGS
  1453. info.checked = function()
  1454. return bag_bars == 1
  1455. end
  1456.  
  1457. info.func = function()
  1458. if bag_bars == 1 then
  1459. bag_bars = 0
  1460. else
  1461. bag_bars = 1
  1462. end
  1463. Stuffing:Layout()
  1464. if Stuffing.bankFrame and Stuffing.bankFrame:IsShown() then
  1465. Stuffing:Layout(true)
  1466. end
  1467. end
  1468. UIDropDownMenu_AddButton(info, level)
  1469.  
  1470. wipe(info)
  1471. info.disabled = nil
  1472. info.notCheckable = 1
  1473. info.text = CLOSE
  1474. info.func = self.HideMenu
  1475. info.tooltipTitle = CLOSE
  1476. UIDropDownMenu_AddButton(info, level)
  1477. end
  1478.  
  1479. -- Kill Blizzard functions
  1480. LootWonAlertFrame_OnClick = T.dummy
  1481. LootUpgradeFrame_OnClick = T.dummy
  1482. StorePurchaseAlertFrame_OnClick = T.dummy
Add Comment
Please, Sign In to add comment