Advertisement
Wetxius

Untitled

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