Wetxius

Untitled

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