init
This commit is contained in:
@@ -0,0 +1,127 @@
|
||||
-- ------------------------------------------------------------------------------ --
|
||||
-- TradeSkillMaster_Warehousing --
|
||||
-- http://www.curse.com/addons/wow/tradeskillmaster_warehousing --
|
||||
-- --
|
||||
-- A TradeSkillMaster Addon (http://tradeskillmaster.com) --
|
||||
-- All Rights Reserved* - Detailed license information included with addon. --
|
||||
-- ------------------------------------------------------------------------------ --
|
||||
|
||||
-- loads the localization table --
|
||||
local L = LibStub("AceLocale-3.0"):GetLocale("TradeSkillMaster_Warehousing")
|
||||
|
||||
-- load the parent file (TSM) into a local variable and register this file as a module
|
||||
local TSM = select(2, ...)
|
||||
local bankui = TSM:NewModule("bankui", "AceEvent-3.0")
|
||||
local AceGUI = LibStub("AceGUI-3.0") -- load the AceGUI librarie
|
||||
|
||||
local currentBank = nil
|
||||
local bFrame = nil
|
||||
local buttonFrame = nil
|
||||
local groupTree = nil
|
||||
|
||||
function bankui:OnEnable()
|
||||
|
||||
bankui:RegisterEvent("GUILDBANKFRAME_OPENED", function(event)
|
||||
currentBank = "guildbank"
|
||||
end)
|
||||
|
||||
bankui:RegisterEvent("BANKFRAME_OPENED", function(event)
|
||||
currentBank = "bank"
|
||||
end)
|
||||
|
||||
bankui:RegisterEvent("GUILDBANKFRAME_CLOSED", function(event, addon)
|
||||
currentBank = nil
|
||||
end)
|
||||
|
||||
bankui:RegisterEvent("BANKFRAME_CLOSED", function(event)
|
||||
currentBank = nil
|
||||
end)
|
||||
end
|
||||
|
||||
local function createButton(text, parent, func)
|
||||
local btn = TSMAPI.GUI:CreateButton(bFrame, 15, "Button")
|
||||
btn:SetText(text)
|
||||
btn:SetHeight(17)
|
||||
btn:SetWidth(230)
|
||||
return btn
|
||||
end
|
||||
|
||||
function bankui:createTab(parent)
|
||||
|
||||
bFrame = CreateFrame("Frame", nil, parent)
|
||||
--TSMAPI.Design:SetFrameColor(bFrame)
|
||||
bFrame:Hide()
|
||||
|
||||
--size--
|
||||
bFrame:SetAllPoints()
|
||||
|
||||
--GroupTree--
|
||||
local tFrame = CreateFrame("Frame", nil, bFrame)
|
||||
tFrame:SetPoint("TOPLEFT", 0, -5)
|
||||
tFrame:SetPoint("TOPRIGHT", 0, -5)
|
||||
tFrame:SetPoint("BOTTOMLEFT", 0, 120)
|
||||
tFrame:SetPoint("BOTTOMRIGHT", 0, 120)
|
||||
|
||||
groupTree = TSMAPI:CreateGroupTree(tFrame, "Warehousing", "Warehousing_Bank")
|
||||
groupTree:SetPoint("TOPLEFT", 5, -5)
|
||||
groupTree:SetPoint("BOTTOMRIGHT", -5, 5)
|
||||
|
||||
--Buttons--
|
||||
buttonFrame = CreateFrame("Frame", nil, bFrame)
|
||||
buttonFrame:SetPoint("TOPLEFT", 0, -330)
|
||||
buttonFrame:SetPoint("TOPRIGHT", 0, -330)
|
||||
buttonFrame:SetPoint("BOTTOMLEFT")
|
||||
buttonFrame:SetPoint("BOTTOMRIGHT")
|
||||
|
||||
buttonFrame.btnToBags = createButton(L["Move Group To Bags"], buttonFrame, nil)
|
||||
buttonFrame.btnToBags:SetPoint("BOTTOM", buttonFrame, "BOTTOM", 0, 75)
|
||||
|
||||
buttonFrame.btnToBank = createButton(L["Move Group To Bank"], buttonFrame, nil)
|
||||
buttonFrame.btnToBank:SetPoint("BOTTOM", buttonFrame, "BOTTOM", 0, 95)
|
||||
|
||||
buttonFrame.btnRestock = createButton(L["Restock Bags"], buttonFrame, nil)
|
||||
buttonFrame.btnRestock:SetPoint("BOTTOM", buttonFrame, "BOTTOM", 0, 45)
|
||||
|
||||
buttonFrame.btnEmpty = createButton(L["Empty Bags"], buttonFrame, nil)
|
||||
buttonFrame.btnEmpty:SetPoint("BOTTOM", buttonFrame, "BOTTOM", 0, 25)
|
||||
|
||||
buttonFrame.btnRestore = createButton(L["Restore Bags"], buttonFrame, nil)
|
||||
buttonFrame.btnRestore:SetPoint("BOTTOM", buttonFrame, "BOTTOM", 0, 5)
|
||||
|
||||
bankui:updateButtons()
|
||||
|
||||
return bFrame
|
||||
end
|
||||
|
||||
function bankui:updateButtons()
|
||||
------------------
|
||||
-- Move to Bank --
|
||||
------------------
|
||||
buttonFrame.btnToBank:SetScript("OnClick", function(self)
|
||||
TSM.move:groupTree(groupTree:GetSelectedGroupInfo(), "bags")
|
||||
end)
|
||||
|
||||
-------------------------
|
||||
-- Empty / Restore Bags--
|
||||
-------------------------
|
||||
buttonFrame.btnEmpty:SetScript("OnClick", function(self) TSM.move:EmptyRestore(currentBank) end)
|
||||
|
||||
buttonFrame.btnRestore:SetScript("OnClick", function(self)
|
||||
TSM.move:EmptyRestore(currentBank, true)
|
||||
end)
|
||||
|
||||
-------------------
|
||||
-- Move to Bags --
|
||||
-------------------
|
||||
buttonFrame.btnToBags:SetScript("OnClick", function(self)
|
||||
TSM.move:groupTree(groupTree:GetSelectedGroupInfo(), currentBank)
|
||||
end)
|
||||
|
||||
-------------------
|
||||
-- Restock --
|
||||
-------------------
|
||||
buttonFrame.btnRestock:SetScript("OnClick", function(self)
|
||||
TSM.move:restockGroup(groupTree:GetSelectedGroupInfo())
|
||||
end)
|
||||
|
||||
end
|
||||
@@ -0,0 +1,235 @@
|
||||
-- ------------------------------------------------------------------------------ --
|
||||
-- TradeSkillMaster_Warehousing --
|
||||
-- http://www.curse.com/addons/wow/tradeskillmaster_warehousing --
|
||||
-- --
|
||||
-- A TradeSkillMaster Addon (http://tradeskillmaster.com) --
|
||||
-- All Rights Reserved* - Detailed license information included with addon. --
|
||||
-- ------------------------------------------------------------------------------ --
|
||||
|
||||
-- loads the localization table --
|
||||
local L = LibStub("AceLocale-3.0"):GetLocale("TradeSkillMaster_Warehousing")
|
||||
|
||||
-- load the parent file (TSM) into a local variable and register this file as a module
|
||||
local TSM = select(2, ...)
|
||||
local data = TSM:NewModule("data", "AceEvent-3.0")
|
||||
local AceGUI = LibStub("AceGUI-3.0") -- load the AceGUI librarie
|
||||
|
||||
----------------------------------
|
||||
-- Generates the Bagstate table --
|
||||
----------------------------------
|
||||
function data:getEmptyRestoreGroup(container, isGuildBank)
|
||||
TSM.util:setSrcBagFunctions("bags")
|
||||
local tmp = {}
|
||||
local grp = {}
|
||||
local restore = {}
|
||||
|
||||
for i, bagid in ipairs(container) do
|
||||
for slotid = 1, TSM.util.getContainerNumSlotsSrc(bagid) do
|
||||
local id, quan = TSM.util.getContainerItemIDSrc(bagid, slotid)
|
||||
if id then
|
||||
if not isGuildBank or not TSMAPI:IsSoulbound(bagid, slotid) then
|
||||
if not tmp[id] then tmp[id] = 0 end
|
||||
tmp[id] = tmp[id] + quan
|
||||
end --end if
|
||||
end --end if id
|
||||
end --end for slots
|
||||
end --end for bags
|
||||
|
||||
for i, q in pairs(tmp) do
|
||||
grp[i] = q * -1 -- convert to negative number for TSMAPI:MoveItems
|
||||
restore[i] = q -- for the restore bagstate
|
||||
end
|
||||
TSM.db.factionrealm.BagState = restore
|
||||
return grp
|
||||
end
|
||||
|
||||
function data:unIndexMoveGroupTree(grpInfo, src)
|
||||
local newgrp = {}
|
||||
local totalItems = data:getTotalItems(src)
|
||||
for groupName, info in pairs(grpInfo) do
|
||||
groupName = TSMAPI:FormatGroupPath(groupName, true)
|
||||
for _, opName in ipairs(info.operations) do
|
||||
TSMAPI:UpdateOperation("Warehousing", opName)
|
||||
local opSettings = TSM.operations[opName]
|
||||
if not opSettings then
|
||||
-- operation doesn't exist anymore in Crafting
|
||||
TSM:Printf(L["'%s' has a Warehousing operation of '%s' which no longer exists."], groupName, opName)
|
||||
else
|
||||
-- it's a valid operation
|
||||
for itemString in pairs(info.items) do
|
||||
itemString = TSMAPI:GetItemString(itemString)
|
||||
local totalq = 0
|
||||
if totalItems then
|
||||
totalq = totalItems[itemString] or 0
|
||||
end
|
||||
|
||||
if src == "bags" then -- if moving from bags to bank/gbank
|
||||
if opSettings.moveQtyEnabled and opSettings.keepBagQtyEnabled then -- move specified quantity but keep x in bags
|
||||
local q = (totalq - opSettings.keepBagQuantity)
|
||||
if q > 0 then
|
||||
--newgrp[itemString] = min(tonumber(q), tonumber(opSettings.moveQuantity))
|
||||
newgrp[itemString] = max(tonumber(q * -1), tonumber(opSettings.moveQuantity * -1))
|
||||
end
|
||||
elseif opSettings.moveQtyEnabled then -- move specified quantity
|
||||
newgrp[itemString] = tonumber(opSettings.moveQuantity * -1)
|
||||
elseif opSettings.keepBagQtyEnabled then -- move all but keep x in bags
|
||||
local q = totalq - opSettings.keepBagQuantity
|
||||
if q > 0 then
|
||||
newgrp[itemString] = tonumber(q * -1)
|
||||
end
|
||||
else -- move everything
|
||||
if totalq > 0 then
|
||||
newgrp[itemString] = tonumber(totalq * -1)
|
||||
end
|
||||
end
|
||||
else -- move from bank/gbank to bags
|
||||
local stacksize = 1
|
||||
if opSettings.stackSizeEnabled and opSettings.stackSize then -- only move in multiples of the stack size set
|
||||
stacksize = opSettings.stackSize
|
||||
end
|
||||
if opSettings.moveQtyEnabled and opSettings.keepBankQtyEnabled then -- move specified quantity but keep x in bank
|
||||
local q = (totalq - opSettings.keepBankQuantity)
|
||||
if q > 0 then
|
||||
newgrp[itemString] = floor(min(tonumber(q), tonumber(opSettings.moveQuantity)) / tonumber(stacksize)) * tonumber(stacksize)
|
||||
end
|
||||
elseif opSettings.moveQtyEnabled then -- move specified quantity
|
||||
newgrp[itemString] = floor(tonumber(opSettings.moveQuantity) / tonumber(stacksize)) * tonumber(stacksize)
|
||||
elseif opSettings.keepBankQtyEnabled then -- move all but keep x in bank
|
||||
local q = totalq - opSettings.keepBankQuantity
|
||||
if q > 0 then
|
||||
newgrp[itemString] = floor(tonumber(q) / tonumber(stacksize)) * tonumber(stacksize)
|
||||
end
|
||||
else -- move everything
|
||||
if totalq > 0 then
|
||||
newgrp[itemString] = floor(tonumber(totalq) / tonumber(stacksize)) * tonumber(stacksize)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return newgrp
|
||||
end
|
||||
|
||||
function data:unIndexRestockGroupTree(grpInfo)
|
||||
local newgrp = {}
|
||||
local totalItems = data:getTotalItems("bags")
|
||||
for groupName, info in pairs(grpInfo) do
|
||||
groupName = TSMAPI:FormatGroupPath(groupName, true)
|
||||
for _, opName in ipairs(info.operations) do
|
||||
TSMAPI:UpdateOperation("Warehousing", opName)
|
||||
local opSettings = TSM.operations[opName]
|
||||
if not opSettings then
|
||||
-- operation doesn't exist anymore in Crafting
|
||||
TSM:Printf(L["'%s' has a Warehousing operation of '%s' which no longer exists."], groupName, opName)
|
||||
else
|
||||
-- it's a valid operation
|
||||
for itemString in pairs(info.items) do
|
||||
local totalq = 0
|
||||
if totalItems then
|
||||
totalq = totalItems[itemString] or 0
|
||||
end
|
||||
if opSettings.restockQtyEnabled then -- work out qty to add or remove from bags
|
||||
local q = opSettings.restockQuantity - totalq
|
||||
if q ~= 0 then
|
||||
newgrp[itemString] = tonumber(q)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return newgrp
|
||||
end
|
||||
|
||||
function data:unIndexItem(searchString, src, quantity)
|
||||
local newgrp = {}
|
||||
local totalItems = data:getTotalItems(src) -- table of itemstrings and total qty in source
|
||||
|
||||
if totalItems then
|
||||
local matchedString = TSMAPI:GetBaseItemString(TSMAPI:GetItemString(searchString))
|
||||
if matchedString then
|
||||
for itemString, totalQty in pairs(totalItems) do
|
||||
if TSMAPI:GetBaseItemString(itemString) == matchedString then
|
||||
if quantity then
|
||||
if src == "bags" then
|
||||
newgrp[itemString] = tonumber(quantity * -1)
|
||||
else
|
||||
newgrp[itemString] = tonumber(quantity)
|
||||
end
|
||||
else
|
||||
if src == "bags" then
|
||||
newgrp[itemString] = tonumber(totalQty * -1)
|
||||
else
|
||||
newgrp[itemString] = tonumber(totalQty)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
for itemString, totalQty in pairs(totalItems) do
|
||||
local name = strlower(TSMAPI:GetSafeItemInfo(itemString))
|
||||
if strfind(name, strlower(searchString)) then
|
||||
if quantity then
|
||||
if src == "bags" then
|
||||
newgrp[itemString] = tonumber(quantity * -1)
|
||||
else
|
||||
newgrp[itemString] = tonumber(quantity)
|
||||
end
|
||||
else
|
||||
if src == "bags" then
|
||||
newgrp[itemString] = tonumber(totalQty * -1)
|
||||
else
|
||||
newgrp[itemString] = tonumber(totalQty)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return newgrp
|
||||
end
|
||||
|
||||
function data:getTotalItems(src)
|
||||
local results = {}
|
||||
if src == "bank" then
|
||||
local function ScanBankBag(bag)
|
||||
for slot = 1, GetContainerNumSlots(bag) do
|
||||
local itemString = TSMAPI:GetBaseItemString(GetContainerItemLink(bag, slot), true)
|
||||
if itemString then
|
||||
local quantity = select(2, GetContainerItemInfo(bag, slot))
|
||||
if not results[itemString] then results[itemString] = 0 end
|
||||
results[itemString] = results[itemString] + quantity
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
for bag = NUM_BAG_SLOTS + 1, NUM_BAG_SLOTS + NUM_BANKBAGSLOTS do
|
||||
ScanBankBag(bag)
|
||||
end
|
||||
ScanBankBag(-1)
|
||||
|
||||
return results
|
||||
elseif src == "guildbank" then
|
||||
for bag = 1, GetNumGuildBankTabs() do
|
||||
for slot = 1, MAX_GUILDBANK_SLOTS_PER_TAB or 98 do
|
||||
local link = GetGuildBankItemLink(bag, slot)
|
||||
local itemString = TSMAPI:GetBaseItemString(link, true)
|
||||
if itemString then
|
||||
local quantity = select(2, GetGuildBankItemInfo(bag, slot))
|
||||
if not results[itemString] then results[itemString] = 0 end
|
||||
results[itemString] = results[itemString] + quantity
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return results
|
||||
elseif src == "bags" then
|
||||
for _, _, itemString, quantity in TSMAPI:GetBagIterator(true) do
|
||||
results[itemString] = (results[itemString] or 0) + quantity
|
||||
end
|
||||
|
||||
return results
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,160 @@
|
||||
-- ------------------------------------------------------------------------------ --
|
||||
-- TradeSkillMaster_Warehousing --
|
||||
-- http://www.curse.com/addons/wow/tradeskillmaster_warehousing --
|
||||
-- --
|
||||
-- A TradeSkillMaster Addon (http://tradeskillmaster.com) --
|
||||
-- All Rights Reserved* - Detailed license information included with addon. --
|
||||
-- ------------------------------------------------------------------------------ --
|
||||
|
||||
-- loads the localization table --
|
||||
local L = LibStub("AceLocale-3.0"):GetLocale("TradeSkillMaster_Warehousing")
|
||||
|
||||
-- load the parent file (TSM) into a local variable and register this file as a module
|
||||
local TSM = select(2, ...)
|
||||
local move = TSM:NewModule("move", "AceEvent-3.0")
|
||||
local AceGUI = LibStub("AceGUI-3.0") -- load the AceGUI libraries
|
||||
|
||||
function move:restockGroup(grpInfo)
|
||||
local restockItems, next = TSM.data:unIndexRestockGroupTree(grpInfo), next
|
||||
if next(restockItems) == nil then
|
||||
TSM:Print(L["Nothing to Restock"])
|
||||
else
|
||||
TSM:Print(L["Restocking"])
|
||||
TSMAPI:MoveItems(restockItems, TSM.PrintMsg)
|
||||
end
|
||||
end
|
||||
|
||||
function move:groupTree(grpInfo, src)
|
||||
local moveItems, next = TSM.data:unIndexMoveGroupTree(grpInfo, src), next
|
||||
if next(moveItems) == nil then
|
||||
TSM:Print(L["Nothing to Move"])
|
||||
else
|
||||
TSM:Print(L["Preparing to Move"])
|
||||
TSMAPI:MoveItems(moveItems, TSM.PrintMsg)
|
||||
end
|
||||
end
|
||||
|
||||
function move:EmptyRestore(dest, restore)
|
||||
local moveItems
|
||||
local next = next
|
||||
local isGuildBank = false
|
||||
|
||||
if dest == "guildbank" then
|
||||
isGuildBank = true
|
||||
else
|
||||
isGuildBank = false
|
||||
end
|
||||
|
||||
if restore then
|
||||
moveItems = TSM.db.factionrealm.BagState
|
||||
else
|
||||
local srcTable = move:getContainerTable("bags")
|
||||
moveItems = TSM.data:getEmptyRestoreGroup(srcTable, isGuildBank)
|
||||
end
|
||||
|
||||
if next(moveItems) == nil then
|
||||
TSM:Print(L["Nothing to Move"])
|
||||
else
|
||||
TSM:Print(L["Preparing to Move"])
|
||||
TSMAPI:MoveItems(moveItems, TSM.PrintMsg, true)
|
||||
if restore then
|
||||
TSM.db.factionrealm.BagState = {}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function move:manualMove(searchString, src, quantity)
|
||||
local moveItems = TSM.data:unIndexItem(searchString, src, quantity)
|
||||
local next = next
|
||||
if next(moveItems) == nil then
|
||||
TSM:Print(L["Nothing to Move"])
|
||||
else
|
||||
TSM:Print(L["Preparing to Move"])
|
||||
TSMAPI:MoveItems(moveItems, TSM.PrintMsg)
|
||||
end
|
||||
end
|
||||
|
||||
function move:getContainerTable(cnt)
|
||||
local t = {}
|
||||
|
||||
if cnt == "bank" then
|
||||
local numSlots, _ = GetNumBankSlots()
|
||||
|
||||
for i = 1, numSlots + 1 do
|
||||
if i == 1 then
|
||||
t[i] = -1
|
||||
else
|
||||
t[i] = i + 3
|
||||
end
|
||||
end
|
||||
|
||||
return t
|
||||
|
||||
elseif cnt == "guildbank" then
|
||||
for i = 1, GetNumGuildBankTabs() do
|
||||
local canView, canDeposit, stacksPerDay = GetGuildBankTabInfo(i);
|
||||
if canView and canDeposit and stacksPerDay then
|
||||
t[i] = i
|
||||
end
|
||||
end
|
||||
|
||||
return t
|
||||
elseif cnt == "bags" then
|
||||
for i = 1, NUM_BAG_SLOTS + 1 do t[i] = i - 1
|
||||
end
|
||||
|
||||
return t
|
||||
end
|
||||
end
|
||||
|
||||
function move:areBanksVisible()
|
||||
if BagnonFrameguildbank and BagnonFrameguildbank:IsVisible() then
|
||||
return true
|
||||
elseif BagnonFramebank and BagnonFramebank:IsVisible() then
|
||||
return true
|
||||
elseif GuildBankFrame and GuildBankFrame:IsVisible() then
|
||||
return true
|
||||
elseif BankFrame and BankFrame:IsVisible() then
|
||||
return true
|
||||
elseif (ARKINV_Frame4 and ARKINV_Frame4:IsVisible()) or (ARKINV_Frame3 and ARKINV_Frame3:IsVisible()) then
|
||||
return true
|
||||
elseif (BagginsBag8 and BagginsBag8:IsVisible()) or (BagginsBag9 and BagginsBag9:IsVisible()) or (BagginsBag10 and BagginsBag10:IsVisible()) or (BagginsBag11 and BagginsBag11:IsVisible()) or (BagginsBag12 and BagginsBag12:IsVisible()) then
|
||||
return true
|
||||
elseif (CombuctorFrame2 and CombuctorFrame2:IsVisible()) then
|
||||
return true
|
||||
elseif (BaudBagContainer2_1 and BaudBagContainer2_1:IsVisible()) then
|
||||
return true
|
||||
elseif (AdiBagsContainer2 and AdiBagsContainer2:IsVisible()) then
|
||||
return true
|
||||
elseif (OneBankFrame and OneBankFrame:IsVisible()) then
|
||||
return true
|
||||
elseif (EngBank_frame and EngBank_frame:IsVisible()) then
|
||||
return true
|
||||
elseif (TBnkFrame and TBnkFrame:IsVisible()) then
|
||||
return true
|
||||
elseif (famBankFrame and famBankFrame:IsVisible()) then
|
||||
return true
|
||||
elseif (LUIBank and LUIBank:IsVisible()) then
|
||||
return true
|
||||
elseif (ElvUI_BankContainerFrame and ElvUI_BankContainerFrame:IsVisible()) then
|
||||
return true
|
||||
elseif (TukuiBank and TukuiBank:IsShown()) then
|
||||
return true
|
||||
elseif (AdiBagsContainer1 and AdiBagsContainer1.isBank and AdiBagsContainer1:IsVisible()) or (AdiBagsContainer2 and AdiBagsContainer2.isBank and AdiBagsContainer2:IsVisible()) then
|
||||
return true
|
||||
elseif BagsFrameBank and BagsFrameBank:IsVisible() then
|
||||
return true
|
||||
elseif AspUIBank and AspUIBank:IsVisible() then
|
||||
return true
|
||||
elseif NivayacBniv_Bank and NivayacBniv_Bank:IsVisible() then
|
||||
return true
|
||||
elseif DufUIBank and DufUIBank:IsVisble() then
|
||||
return true
|
||||
end
|
||||
TSM:Print(L["Canceled"])
|
||||
return nil
|
||||
end
|
||||
|
||||
function TSM.PrintMsg(message)
|
||||
TSM:Print(message)
|
||||
end
|
||||
@@ -0,0 +1,432 @@
|
||||
-- ------------------------------------------------------------------------------ --
|
||||
-- TradeSkillMaster_Warehousing --
|
||||
-- http://www.curse.com/addons/wow/tradeskillmaster_warehousing --
|
||||
-- --
|
||||
-- A TradeSkillMaster Addon (http://tradeskillmaster.com) --
|
||||
-- All Rights Reserved* - Detailed license information included with addon. --
|
||||
-- ------------------------------------------------------------------------------ --
|
||||
|
||||
-- load the parent file (TSM) into a local variable and register this file as a module
|
||||
local TSM = select(2, ...)
|
||||
local Options = TSM:NewModule("Options", "AceEvent-3.0", "AceHook-3.0")
|
||||
local AceGUI = LibStub("AceGUI-3.0") -- load the AceGUI libraries
|
||||
|
||||
local L = LibStub("AceLocale-3.0"):GetLocale("TradeSkillMaster_Warehousing") -- loads the localization table
|
||||
|
||||
local function getHelpString1()
|
||||
return
|
||||
L["Warehousing will try to get the right number of items, if there are not enough in the bank to fill out the order, it will grab all that there is."]
|
||||
end
|
||||
|
||||
local function getHelpString2()
|
||||
return
|
||||
L["1) Select Operations on the left menu and type a name in the textbox labeled \"Operation Name\", hit okay"] .. "\n" ..
|
||||
L["2) You can delete an operation by selecting the operation and then under Operation Management click the button labelled \"Delete Operation\". "]
|
||||
end
|
||||
|
||||
local function getHelpString3()
|
||||
return
|
||||
L["Simply hit empty bags, warehousing will remember what you had so that when you hit restore, it will grab all those items again. If you hit empty bags while your bags are empty it will overwrite the previous bag state, so you will not be able to use restore."]
|
||||
end
|
||||
|
||||
local function getHelpString4()
|
||||
return
|
||||
L["1) Open up a bank (either the gbank or personal bank)"] .. "\n" ..
|
||||
L["2) You should see a window on your right with a list of groups"] .. "\n" ..
|
||||
format(L["3) Select one or more groups and hit either %s or %s"], "\"" .. L["Move Group To Bank"] .. "\"", "\"" .. L["Move Group To Bags"] .. "\"")
|
||||
end
|
||||
|
||||
local function getHelpString5()
|
||||
return
|
||||
L["You can use the following slash commands to get items from or put items into your bank or guildbank."] .. "\n" ..
|
||||
L["/tsm get/put X Y - X can be either an itemID, ItemLink (shift-click item) or partial text. Y is optionally the quantity you want to move."] .. "\n\n" ..
|
||||
L["Example 1: /tsm get glyph 20 - get up to 20 of each item in your bank/guildbank where the name contains" .. "\"" .. "glyph" .. "\"" .. " and place them in your bags."] .. "\n\n" ..
|
||||
L["Example 2: /tsm put 74249 - get all of item 74249 (Spirit Dust) from your bags and put them in your bank/guildbank"]
|
||||
end
|
||||
|
||||
local function getHelpString6()
|
||||
return
|
||||
L["You can toggle the Bank UI by typing the command "] .. "/tsm bankui "
|
||||
end
|
||||
|
||||
local function CreateOperation(name)
|
||||
TSM.operations[name] = CopyTable(TSM.operationDefaults)
|
||||
end
|
||||
|
||||
local function DeleteOperation(name)
|
||||
TSM.operations[name] = nil
|
||||
end
|
||||
|
||||
function Options:Load(parent, operation, group)
|
||||
Options.treeGroup = AceGUI:Create("TSMTreeGroup")
|
||||
Options.treeGroup:SetLayout("Fill")
|
||||
Options.treeGroup:SetCallback("OnGroupSelected", function(...) Options:SelectTree(...) end)
|
||||
Options.treeGroup:SetStatusTable(TSM.db.global.optionsTreeStatus)
|
||||
parent:AddChild(Options.treeGroup)
|
||||
|
||||
Options:UpdateTree()
|
||||
if operation then
|
||||
if operation == "" then
|
||||
Options.currentGroup = group
|
||||
Options.treeGroup:SelectByPath(2)
|
||||
Options.currentGroup = nil
|
||||
else
|
||||
Options.treeGroup:SelectByPath(2, operation)
|
||||
end
|
||||
else
|
||||
Options.treeGroup:SelectByPath(1)
|
||||
end
|
||||
end
|
||||
|
||||
function Options:UpdateTree()
|
||||
local operationTreeChildren = {}
|
||||
|
||||
for name in pairs(TSM.operations) do
|
||||
tinsert(operationTreeChildren, { value = name, text = name })
|
||||
end
|
||||
|
||||
sort(operationTreeChildren, function(a, b) return a.value < b.value end)
|
||||
|
||||
Options.treeGroup:SetTree({ { value = 1, text = L["Help"] }, { value = 2, text = L["Operations"], children = operationTreeChildren } })
|
||||
end
|
||||
|
||||
function Options:SelectTree(treeGroup, _, selection)
|
||||
treeGroup:ReleaseChildren()
|
||||
|
||||
local major, minor = ("\001"):split(selection)
|
||||
major = tonumber(major)
|
||||
if major == 1 then
|
||||
Options:DrawHelp(treeGroup)
|
||||
elseif minor then
|
||||
Options:DrawOperationSettings(treeGroup, minor)
|
||||
else
|
||||
Options:DrawNewOperation(treeGroup)
|
||||
end
|
||||
end
|
||||
|
||||
function Options:DrawHelp(container)
|
||||
local page = {
|
||||
{
|
||||
type = "ScrollFrame",
|
||||
layout = "List",
|
||||
children = {
|
||||
{
|
||||
type = "InlineGroup",
|
||||
layout = "flow",
|
||||
title = "TSM_Warehousing",
|
||||
children = {
|
||||
{
|
||||
type = "Label",
|
||||
text = getHelpString1(),
|
||||
relativeWidth = 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
type = "Spacer",
|
||||
},
|
||||
{
|
||||
type = "InlineGroup",
|
||||
layout = "flow",
|
||||
title = L["To create a Warehousing Operation"],
|
||||
children = {
|
||||
{
|
||||
type = "Label",
|
||||
text = getHelpString2(),
|
||||
relativeWidth = 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
type = "Spacer",
|
||||
},
|
||||
{
|
||||
type = "InlineGroup",
|
||||
layout = "flow",
|
||||
title = L["Empty Bags/Restore Bags"],
|
||||
children = {
|
||||
{
|
||||
type = "Label",
|
||||
text = getHelpString3(),
|
||||
relativeWidth = 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
type = "Spacer",
|
||||
},
|
||||
{
|
||||
type = "InlineGroup",
|
||||
layout = "flow",
|
||||
title = L["To move a Group"],
|
||||
children = {
|
||||
{
|
||||
type = "Label",
|
||||
text = getHelpString4(),
|
||||
relativeWidth = 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
type = "Spacer",
|
||||
},
|
||||
{
|
||||
type = "InlineGroup",
|
||||
layout = "flow",
|
||||
title = L["Slash Commands"],
|
||||
children = {
|
||||
{
|
||||
type = "Label",
|
||||
text = getHelpString5(),
|
||||
relativeWidth = 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
type = "InlineGroup",
|
||||
layout = "flow",
|
||||
title = L["Bank UI"],
|
||||
children = {
|
||||
{
|
||||
type = "Label",
|
||||
text = getHelpString6(),
|
||||
relativeWidth = 1,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
TSMAPI:BuildPage(container, page)
|
||||
end
|
||||
|
||||
function Options:DrawNewOperation(container)
|
||||
local currentGroup = Options.currentGroup
|
||||
local page = {
|
||||
{
|
||||
-- scroll frame to contain everything
|
||||
type = "ScrollFrame",
|
||||
layout = "List",
|
||||
children = {
|
||||
{
|
||||
type = "InlineGroup",
|
||||
layout = "flow",
|
||||
title = L["New Operation"],
|
||||
children = {
|
||||
{
|
||||
type = "Label",
|
||||
text = L["Warehousing operations contain settings for moving the items in a group. Type the name of the new operation into the box below and hit 'enter' to create a new Warehousing operation."],
|
||||
relativeWidth = 1,
|
||||
},
|
||||
{
|
||||
type = "EditBox",
|
||||
label = L["Operation Name"],
|
||||
relativeWidth = 0.8,
|
||||
callback = function(self, _, name)
|
||||
name = (name or ""):trim()
|
||||
if name == "" then return end
|
||||
if TSM.operations[name] then
|
||||
self:SetText("")
|
||||
return TSM:Printf(L["Error creating operation. Operation with name '%s' already exists."], name)
|
||||
end
|
||||
CreateOperation(name)
|
||||
Options:UpdateTree()
|
||||
Options.treeGroup:SelectByPath(2, name)
|
||||
TSMAPI:NewOperationCallback("Warehousing", currentGroup, name)
|
||||
end,
|
||||
tooltip = L["Give the new operation a name. A descriptive name will help you find this operation later."],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
TSMAPI:BuildPage(container, page)
|
||||
end
|
||||
|
||||
function Options:DrawOperationSettings(container, operationName)
|
||||
local tg = AceGUI:Create("TSMTabGroup")
|
||||
tg:SetLayout("Fill")
|
||||
tg:SetFullHeight(true)
|
||||
tg:SetFullWidth(true)
|
||||
tg:SetTabs({{value=1, text=L["General"]}, {value=2, text=L["Relationships"]}, {value=3, text=L["Management"]}})
|
||||
tg:SetCallback("OnGroupSelected", function(self,_,value)
|
||||
tg:ReleaseChildren()
|
||||
TSMAPI:UpdateOperation("Warehousing", operationName)
|
||||
if value == 1 then
|
||||
Options:DrawOperationGeneral(self, operationName)
|
||||
elseif value == 2 then
|
||||
Options:DrawOperationRelationships(self, operationName)
|
||||
elseif value == 3 then
|
||||
TSMAPI:DrawOperationManagement(TSM, self, operationName)
|
||||
end
|
||||
end)
|
||||
container:AddChild(tg)
|
||||
tg:SelectTab(1)
|
||||
end
|
||||
|
||||
function Options:DrawOperationGeneral(container, operationName)
|
||||
local operationSettings = TSM.operations[operationName]
|
||||
|
||||
local page = {
|
||||
{
|
||||
-- scroll frame to contain everything
|
||||
type = "ScrollFrame",
|
||||
layout = "List",
|
||||
children = {
|
||||
{
|
||||
type = "InlineGroup",
|
||||
layout = "flow",
|
||||
title = L["Move Quantity Settings"],
|
||||
children = {
|
||||
{
|
||||
type = "CheckBox",
|
||||
label = L["Set Move Quantity"],
|
||||
relativeWidth = 0.35,
|
||||
settingInfo = {operationSettings, "moveQtyEnabled"},
|
||||
callback = function() container:ReloadTab() end,
|
||||
tooltip = L["Enable this to set the quantity to move, if disabled Warehousing will move all of the item"],
|
||||
},
|
||||
{
|
||||
-- slider to set the move quantity
|
||||
type = "Slider",
|
||||
settingInfo = {operationSettings, "moveQuantity"},
|
||||
label = L["Move Quantity"],
|
||||
disabled = not operationSettings.moveQtyEnabled,
|
||||
isPercent = false,
|
||||
min = 1,
|
||||
max = 5000,
|
||||
step = 1,
|
||||
relativeWidth = 0.65,
|
||||
tooltip = L["Warehousing will move this number of each item"],
|
||||
},
|
||||
{
|
||||
type = "Spacer",
|
||||
},
|
||||
{
|
||||
type = "CheckBox",
|
||||
label = L["Set Stack Size for bags"],
|
||||
relativeWidth = 0.35,
|
||||
settingInfo = {operationSettings, "stackSizeEnabled"},
|
||||
callback = function() container:ReloadTab() end,
|
||||
tooltip = L["Enable this to set the stack size multiple to be moved"],
|
||||
},
|
||||
{
|
||||
-- slider to set the move quantity
|
||||
type = "Slider",
|
||||
settingInfo = {operationSettings, "stackSize"},
|
||||
label = L["Stack Size Multiple"],
|
||||
disabled = not operationSettings.stackSizeEnabled,
|
||||
isPercent = false,
|
||||
min = 1,
|
||||
max = 200,
|
||||
step = 1,
|
||||
relativeWidth = 0.65,
|
||||
tooltip = L["Warehousing will only move items in multiples of the stack size set when moving to your bags, this is useful for milling/prospecting etc to ensure you don't move items you can't process"],
|
||||
},
|
||||
{
|
||||
type = "Spacer",
|
||||
},
|
||||
{
|
||||
type = "CheckBox",
|
||||
settingInfo = {operationSettings, "keepBagQtyEnabled"},
|
||||
label = L["Set Keep in Bags Quantity"],
|
||||
relativeWidth = 0.35,
|
||||
callback = function() container:ReloadTab() end,
|
||||
tooltip = L["Enable this to set the quantity to keep back in your bags"],
|
||||
},
|
||||
{
|
||||
-- slider to set the keep bags qty
|
||||
type = "Slider",
|
||||
settingInfo = {operationSettings, "keepBagQuantity"},
|
||||
label = L["Keep in Bags Quantity"],
|
||||
disabled = not operationSettings.keepBagQtyEnabled,
|
||||
isPercent = false,
|
||||
min = 1,
|
||||
max = 5000,
|
||||
step = 1,
|
||||
relativeWidth = 0.65,
|
||||
tooltip = L["Warehousing will ensure this number remain in your bags when moving items to the bank / guildbank."],
|
||||
},
|
||||
{
|
||||
type = "Spacer",
|
||||
},
|
||||
{
|
||||
type = "CheckBox",
|
||||
settingInfo = {operationSettings, "keepBankQtyEnabled"},
|
||||
label = L["Set Keep in Bank Quantity"],
|
||||
relativeWidth = 0.35,
|
||||
callback = function() container:ReloadTab() end,
|
||||
tooltip = L["Enable this to set the quantity to keep back in your bank / guildbank"],
|
||||
},
|
||||
{
|
||||
-- slider to set the keep bank qty
|
||||
type = "Slider",
|
||||
settingInfo = {operationSettings, "keepBankQuantity"},
|
||||
label = L["Keep in Bank/GuildBank Quantity"],
|
||||
disabled = not operationSettings.keepBankQtyEnabled,
|
||||
isPercent = false,
|
||||
min = 1,
|
||||
max = 5000,
|
||||
step = 1,
|
||||
relativeWidth = 0.65,
|
||||
tooltip = L["Warehousing will ensure this number remain in your bank / guildbank when moving items to your bags."],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
type = "Spacer",
|
||||
},
|
||||
{
|
||||
type = "InlineGroup",
|
||||
layout = "flow",
|
||||
title = L["Restock Settings"],
|
||||
children = {
|
||||
{
|
||||
type = "CheckBox",
|
||||
settingInfo = {operationSettings, "restockQtyEnabled"},
|
||||
label = L["Enable Restock"],
|
||||
relativeWidth = 0.25,
|
||||
callback = function() container:ReloadTab() end,
|
||||
tooltip = L["Enable this to set the restock quantity"],
|
||||
},
|
||||
{
|
||||
-- slider to set the move quantity
|
||||
type = "Slider",
|
||||
settingInfo = {operationSettings, "restockQuantity"},
|
||||
label = L["Restock Quantity"],
|
||||
disabled = not operationSettings.restockQtyEnabled,
|
||||
isPercent = false,
|
||||
min = 1,
|
||||
max = 5000,
|
||||
step = 1,
|
||||
relativeWidth = 0.75,
|
||||
tooltip = L["Warehousing will restock your bags up to this number of items"],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
TSMAPI:BuildPage(container, page)
|
||||
end
|
||||
|
||||
function Options:DrawOperationRelationships(container, operationName)
|
||||
local settingInfo = {
|
||||
{
|
||||
label = L["Move Quantity Settings"],
|
||||
{key="moveQtyEnabled", label=L["Set Move Quantity"]},
|
||||
{key="moveQuantity", label=L["Move Quantity"]},
|
||||
{key="keepBagQtyEnabled", label=L["Set Keep in Bags Quantity"]},
|
||||
{key="keepBagQuantity", label=L["Keep in Bags Quantity"]},
|
||||
{key="keepBankQtyEnabled", label=L["Set Keep in Bank Quantity"]},
|
||||
{key="keepBankQuantity", label=L["Keep in Bank/GuildBank Quantity"]},
|
||||
},
|
||||
{
|
||||
label = L["Restock Settings"],
|
||||
{key="restockQtyEnabled", label=L["Enable Restock"]},
|
||||
{key="restockQuantity", label=L["Restock Quantity"]},
|
||||
},
|
||||
}
|
||||
TSMAPI:ShowOperationRelationshipTab(TSM, container, TSM.operations[operationName], settingInfo)
|
||||
end
|
||||
@@ -0,0 +1,125 @@
|
||||
-- ------------------------------------------------------------------------------ --
|
||||
-- TradeSkillMaster_Warehousing --
|
||||
-- http://www.curse.com/addons/wow/tradeskillmaster_warehousing --
|
||||
-- --
|
||||
-- A TradeSkillMaster Addon (http://tradeskillmaster.com) --
|
||||
-- All Rights Reserved* - Detailed license information included with addon. --
|
||||
-- ------------------------------------------------------------------------------ --
|
||||
|
||||
-- loads the localization table --
|
||||
local L = LibStub("AceLocale-3.0"):GetLocale("TradeSkillMaster_Warehousing")
|
||||
|
||||
-- load the parent file (TSM) into a local variable and register this file as a module
|
||||
local TSM = select(2, ...)
|
||||
local util = TSM:NewModule("util", "AceEvent-3.0")
|
||||
local AceGUI = LibStub("AceGUI-3.0") -- load the AceGUI libraries
|
||||
|
||||
-- this is a set of wrapper functions so that I can switch
|
||||
-- between guildbank and bank function easily
|
||||
|
||||
|
||||
util.pickupContainerItemSrc = nil
|
||||
util.getContainerItemIDSrc = nil
|
||||
util.getContainerNumSlotsSrc = nil
|
||||
util.getContainerItemLinkSrc = nil
|
||||
util.getContainerNumFreeSlotsSrc = nil
|
||||
util.splitContainerItemSrc = nil
|
||||
|
||||
util.pickupContainerItemDest = nil
|
||||
util.getContainerItemIDDest = nil
|
||||
util.getContainerNumSlotsDest = nil
|
||||
util.getContainerItemLinkDest = nil
|
||||
util.getContainerNumFreeSlotsDest = nil
|
||||
|
||||
util.getItemString = nil
|
||||
util.autoStoreItem = nil
|
||||
|
||||
|
||||
function util:setSrcBagFunctions(bagType)
|
||||
if bagType == "guildbank" then
|
||||
util.autoStoreItem = function(bag, slot) AutoStoreGuildBankItem(bag, slot) end
|
||||
util.splitContainerItemSrc = function(bag, slot, need) SplitGuildBankItem(bag, slot, need); end
|
||||
util.pickupContainerItemSrc = function(bag, slot) PickupGuildBankItem(bag, slot) end
|
||||
util.getContainerNumSlotsSrc = function(bag) return MAX_GUILDBANK_SLOTS_PER_TAB or 98 end
|
||||
util.getContainerItemLinkSrc = function(bag, slot) return GetGuildBankItemLink(bag, slot) end
|
||||
util.getContainerNumFreeSlotsSrc = function(bag) return MAX_GUILDBANK_SLOTS_PER_TAB or 98 end --need to change this eventually
|
||||
util.getContainerItemIDSrc = function(bag, slot)
|
||||
local tmpLink = GetGuildBankItemLink(bag, slot)
|
||||
local quantity = select(2, GetGuildBankItemInfo(bag, slot))
|
||||
if tmpLink then
|
||||
return TSMAPI:GetItemString(tmpLink), quantity
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
elseif bagType == "mail" then
|
||||
util.autoStoreItem = function(bag, slot) TakeInboxItem(bag, slot) end
|
||||
util.splitContainerItemSrc = function(bag, slot, need) TakeInboxItem(bag, slot) end
|
||||
util.pickupContainerItemSrc = function(bag, slot) return end
|
||||
util.getContainerItemIDSrc = function(bag, slot)
|
||||
local quantity = select(3, GetInboxItem(bag, slot))
|
||||
local tmpLink = GetInboxItemLink(bag, slot)
|
||||
return TSMAPI:GetItemString(tmpLink), quantity
|
||||
end
|
||||
util.getContainerNumSlotsSrc = function(bag) return 16 end
|
||||
util.getContainerItemLinkSrc = function(bag, slot) return GetInboxItemLink(bag, slot) end
|
||||
util.getContainerNumFreeSlotsSrc = function(bag) return 16 end
|
||||
else
|
||||
util.autoStoreItem = function(bag, slot) UseContainerItem(bag, slot) end
|
||||
util.splitContainerItemSrc = function(bag, slot, need) SplitContainerItem(bag, slot, need) end
|
||||
util.pickupContainerItemSrc = function(bag, slot) PickupContainerItem(bag, slot) end
|
||||
util.getContainerItemIDSrc = function(bag, slot)
|
||||
local tmpLink = GetContainerItemLink(bag, slot)
|
||||
local quantity = select(2, GetContainerItemInfo(bag, slot))
|
||||
return TSMAPI:GetItemString(tmpLink), quantity
|
||||
end
|
||||
util.getContainerNumSlotsSrc = function(bag) return GetContainerNumSlots(bag) end
|
||||
util.getContainerItemLinkSrc = function(bag, slot) return GetContainerItemLink(bag, slot) end
|
||||
util.getContainerNumFreeSlotsSrc = function(bag) return GetContainerNumFreeSlots(bag) end
|
||||
end
|
||||
end
|
||||
|
||||
function util:setDestBagFunctions(bagType)
|
||||
if bagType == "guildbank" then
|
||||
util.pickupContainerItemDest = function(bag, slot) PickupGuildBankItem(bag, slot) end
|
||||
util.getContainerNumSlotsDest = function(bag) return 98 end
|
||||
util.getContainerNumFreeSlotsDest = function(bag) return 98 end --need to change this eventually
|
||||
util.getContainerItemLinkDest = function(bag, slot) return GetGuildBankItemLink(bag, slot) end
|
||||
util.getContainerItemIDDest = function(bag, slot)
|
||||
local tmpLink = GetGuildBankItemLink(bag, slot)
|
||||
local quantity = select(2, GetGuildBankItemInfo(bag, slot))
|
||||
if tmpLink then
|
||||
return TSMAPI:GetItemString(tmpLink), quantity
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
else
|
||||
util.pickupContainerItemDest = function(bag, slot) PickupContainerItem(bag, slot) end
|
||||
util.getContainerItemIDDest = function(bag, slot)
|
||||
local tmpLink = GetContainerItemLink(bag, slot)
|
||||
local quantity = select(2, GetContainerItemInfo(bag, slot))
|
||||
return TSMAPI:GetItemString(tmpLink), quantity
|
||||
end
|
||||
util.getContainerNumSlotsDest = function(bag) return GetContainerNumSlots(bag) end
|
||||
util.getContainerItemLinkDest = function(bag, slot) return GetContainerItemLink(bag, slot) end
|
||||
util.getContainerNumFreeSlotsDest = function(bag) return GetContainerNumFreeSlots(bag) end
|
||||
end
|
||||
end
|
||||
|
||||
--
|
||||
--This will find a special bag for your special item
|
||||
--
|
||||
function util:canGoInBag(item, destTable)
|
||||
local itemFamily = GetItemFamily(item)
|
||||
local default
|
||||
for bag, _ in pairs(destTable) do
|
||||
local bagFamily = GetItemFamily(GetBagName(bag)) or 0
|
||||
if itemFamily and bagFamily and bagFamily > 0 and bit.band(itemFamily, bagFamily) > 0 then
|
||||
return bag
|
||||
elseif bagFamily == 0 then
|
||||
default = bag
|
||||
end
|
||||
end
|
||||
return default
|
||||
end
|
||||
Reference in New Issue
Block a user