Advertisement
Wetxius

Untitled

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