Advertisement
Wetxius

Untitled

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