You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
359 lines
10 KiB
359 lines
10 KiB
-- ------------------------------------------------------------------------------ -- |
|
-- TradeSkillMaster_AuctionDB -- |
|
-- http://www.curse.com/addons/wow/tradeskillmaster_auctiondb -- |
|
-- -- |
|
-- 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 GUI = TSM:NewModule("GUI") |
|
local L = LibStub("AceLocale-3.0"):GetLocale("TradeSkillMaster_AuctionDB") -- loads the localization table |
|
|
|
local private = {} |
|
|
|
function GUI:Show(frame) |
|
private.statusBar = private.statusBar or private:CreateStatusBar(frame.content) |
|
private.statusBar:Show() |
|
GUI:UpdateStatus("", 0, 0) |
|
|
|
private.startScanContent = private.startScanContent or private:CreateStartScanContent(frame) |
|
private.startScanContent:Show() |
|
if TSM.Scan.isScanning and not TSMAPI.AuctionScan:IsScanning() then |
|
TSM.Scan:DoneScanning() |
|
end |
|
if TSM.Scan.isScanning then |
|
GUI:SetPauseEnabled(true) |
|
GUI:SetPaused(TSMAPI.AuctionScan:IsPaused()) |
|
else |
|
GUI:SetPauseEnabled(false) |
|
GUI:SetPaused(false) |
|
end |
|
end |
|
|
|
function GUI:Hide() |
|
private.statusBar:Hide() |
|
private.startScanContent:Hide() |
|
|
|
if TSM.Scan.isScanning and not TSMAPI.AuctionScan:IsScanning() then |
|
TSM.Scan:DoneScanning() |
|
end |
|
if TSM.Scan.isScanning then |
|
TSM.Scan:PauseScan() |
|
else |
|
TSM.Scan:DoneScanning() |
|
TSMAPI.AuctionScan:StopScan() |
|
GUI:SetPauseEnabled(false) |
|
GUI:SetPaused(false) |
|
end |
|
end |
|
|
|
function GUI:UpdateStatus(text, major, minor) |
|
if text then |
|
private.statusBar:SetStatusText(text) |
|
end |
|
if major or minor then |
|
private.statusBar:UpdateStatus(major, minor) |
|
end |
|
end |
|
|
|
function GUI:SetPauseEnabled(enabled) |
|
if not private.startScanContent or not private.startScanContent.pauseFullScanButton then return end |
|
if enabled then |
|
private.startScanContent.pauseFullScanButton:Enable() |
|
else |
|
private.startScanContent.pauseFullScanButton:Disable() |
|
end |
|
end |
|
|
|
function GUI:SetPaused(isPaused) |
|
if not private.startScanContent or not private.startScanContent.pauseFullScanButton then return end |
|
private.startScanContent.pauseFullScanButton:SetText(isPaused and L["Resume"] or L["Pause"]) |
|
end |
|
|
|
function private:CreateStatusBar(parent) |
|
local frame = TSMAPI.GUI:CreateStatusBar(parent, "TSMAuctionDBStatusBar") |
|
TSMAPI.GUI:CreateHorizontalLine(frame, -30, parent) |
|
|
|
return frame |
|
end |
|
|
|
function private:CreateStartScanContent(parent) |
|
local frame = CreateFrame("Frame", nil, parent) |
|
frame:SetAllPoints(parent) |
|
frame:Hide() |
|
|
|
frame.Enable = function(self) |
|
self.startFullScanButton:Enable() |
|
self.pauseFullScanButton:Disable() |
|
self.cancelScanButton:Disable() |
|
self.startGroupScanButton:Enable() |
|
self.startInventoryScanButton:Enable() |
|
self.startBagScanButton:Enable() |
|
self.startBankScanButton:Enable() |
|
end |
|
|
|
frame.Disable = function(self) |
|
self.startFullScanButton:Disable() |
|
if TSM.Scan.isScanning then |
|
self.pauseFullScanButton:Enable() |
|
self.cancelScanButton:Enable() |
|
else |
|
self.pauseFullScanButton:Disable() |
|
self.cancelScanButton:Disable() |
|
end |
|
self.startGroupScanButton:Disable() |
|
self.startInventoryScanButton:Disable() |
|
self.startBagScanButton:Disable() |
|
self.startBankScanButton:Disable() |
|
end |
|
|
|
-- Top row: Auto updater. |
|
local text = TSMAPI.GUI:CreateLabel(frame) |
|
text:SetFont(TSMAPI.Design:GetContentFont(), 24) |
|
text:SetPoint("TOP", 0, -24) |
|
text:SetHeight(24) |
|
text:SetJustifyH("CENTER") |
|
text:SetJustifyV("CENTER") |
|
text:SetText(TSMAPI.Design:GetInlineColor("link").."TSM_AuctionDB") |
|
local ag = text:CreateAnimationGroup() |
|
local a1 = ag:CreateAnimation("Alpha") |
|
a1:SetChange(-.5) |
|
a1:SetDuration(.5) |
|
ag:SetLooping("BOUNCE") |
|
ag:Play() |
|
|
|
local content = CreateFrame("Frame", nil, frame) |
|
content:SetAllPoints(parent.content) |
|
TSMAPI.Design:SetFrameBackdropColor(content) |
|
|
|
-- Group tree. |
|
local container = CreateFrame("Frame", nil, content) |
|
container:SetPoint("TOPLEFT", 5, -35) |
|
container:SetPoint("BOTTOMRIGHT", -205, 5) |
|
TSMAPI.Design:SetFrameColor(container) |
|
frame.groupTree = TSMAPI:CreateGroupTree(container, nil, "AuctionDB") |
|
|
|
local bar = TSMAPI.GUI:CreateVerticalLine(content, 0) |
|
bar:ClearAllPoints() |
|
bar:SetPoint("TOPRIGHT", -200, -30) |
|
bar:SetPoint("BOTTOMRIGHT", -200, 0) |
|
|
|
local buttonFrame = CreateFrame("Frame", nil, content) |
|
buttonFrame:SetPoint("TOPLEFT", content, "TOPRIGHT", -200, 0) |
|
buttonFrame:SetPoint("BOTTOMRIGHT") |
|
|
|
-- Row: Full Scan. |
|
local yOffset = -50 |
|
|
|
-- Row: Full Scan. |
|
local btn = TSMAPI.GUI:CreateButton(buttonFrame, 18) |
|
btn:SetPoint("TOPLEFT", 6, yOffset) |
|
btn:SetPoint("TOPRIGHT", -6, yOffset) |
|
btn:SetHeight(22) |
|
btn:SetScript("OnClick", TSM.Scan.StartFullScan) |
|
btn:SetText(L["Run Full Scan"]) |
|
btn.tooltip = L["A full auction house scan will scan every item on the auction house. Expect this scan to take several minutes or longer."] |
|
frame.startFullScanButton = btn |
|
|
|
yOffset = yOffset - 40 |
|
|
|
TSMAPI.GUI:CreateHorizontalLine(buttonFrame, yOffset) |
|
|
|
yOffset = yOffset - 20 |
|
|
|
-- Row: Group Scan. |
|
local btn = TSMAPI.GUI:CreateButton(buttonFrame, 18) |
|
btn:SetPoint("TOPLEFT", 6, yOffset) |
|
btn:SetPoint("TOPRIGHT", -6, yOffset) |
|
btn:SetHeight(22) |
|
btn:SetScript("OnClick", GUI.StartGroupScan) |
|
btn:SetText(L["Scan Selected Groups"]) |
|
btn.tooltip = L["This will do a slow auction house scan of every item in the selected groups and update their AuctionDB prices. This may take several minutes."] |
|
frame.startGroupScanButton = btn |
|
|
|
yOffset = yOffset - 40 |
|
|
|
TSMAPI.GUI:CreateHorizontalLine(buttonFrame, yOffset) |
|
|
|
yOffset = yOffset - 20 |
|
|
|
-- Row: Inventory Scan. |
|
local btn = TSMAPI.GUI:CreateButton(buttonFrame, 18) |
|
btn:SetPoint("TOPLEFT", 6, yOffset) |
|
btn:SetPoint("TOPRIGHT", -6, yOffset) |
|
btn:SetHeight(22) |
|
btn:SetScript("OnClick", GUI.StartInventoryScan) |
|
btn:SetText(L["Scan Inventory"]) |
|
btn.tooltip = L["Scans bags and bank for all characters."] |
|
frame.startInventoryScanButton = btn |
|
|
|
yOffset = yOffset - 30 |
|
|
|
-- Row: Bag Scan. |
|
local btn = TSMAPI.GUI:CreateButton(buttonFrame, 18) |
|
btn:SetPoint("TOPLEFT", 6, yOffset) |
|
btn:SetPoint("TOPRIGHT", -6, yOffset) |
|
btn:SetHeight(22) |
|
btn:SetScript("OnClick", GUI.StartBagScan) |
|
btn:SetText(L["Scan Bags"]) |
|
btn.tooltip = L["Scan bag items."] |
|
frame.startBagScanButton = btn |
|
|
|
yOffset = yOffset - 30 |
|
|
|
-- Row: Bank Scan. |
|
local btn = TSMAPI.GUI:CreateButton(buttonFrame, 18) |
|
btn:SetPoint("TOPLEFT", 6, yOffset) |
|
btn:SetPoint("TOPRIGHT", -6, yOffset) |
|
btn:SetHeight(22) |
|
btn:SetScript("OnClick", GUI.StartBankScan) |
|
btn:SetText(L["Scan Bank"]) |
|
btn.tooltip = L["Scan bank items."] |
|
frame.startBankScanButton = btn |
|
|
|
yOffset = yOffset - 40 |
|
|
|
TSMAPI.GUI:CreateHorizontalLine(buttonFrame, yOffset) |
|
|
|
yOffset = yOffset - 20 |
|
|
|
local pauseBtn = TSMAPI.GUI:CreateButton(buttonFrame, 16) |
|
pauseBtn:SetPoint("TOPLEFT", 6, yOffset) |
|
pauseBtn:SetPoint("TOPRIGHT", -6, yOffset) |
|
pauseBtn:SetHeight(18) |
|
pauseBtn:SetScript("OnClick", TSM.Scan.TogglePause) |
|
pauseBtn:SetText(L["Pause"]) |
|
pauseBtn:Disable() |
|
frame.pauseFullScanButton = pauseBtn |
|
|
|
yOffset = yOffset - 24 |
|
|
|
local cancelBtn = TSMAPI.GUI:CreateButton(buttonFrame, 16) |
|
cancelBtn:SetPoint("TOPLEFT", 6, yOffset) |
|
cancelBtn:SetPoint("TOPRIGHT", -6, yOffset) |
|
cancelBtn:SetHeight(18) |
|
cancelBtn:SetScript("OnClick", GUI.CancelScan) |
|
cancelBtn:SetText(L["Cancel Scan"]) |
|
cancelBtn:Disable() |
|
frame.cancelScanButton = cancelBtn |
|
|
|
return frame |
|
end |
|
|
|
function GUI:StartGroupScan() |
|
local items = {} |
|
for groupName, data in pairs(private.startScanContent.groupTree:GetSelectedGroupInfo()) do |
|
groupName = TSMAPI:FormatGroupPath(groupName, true) |
|
for itemString in pairs(data.items) do |
|
tinsert(items, itemString) |
|
end |
|
end |
|
TSM.Scan:StartGroupScan(items) |
|
end |
|
|
|
function GUI:StartInventoryScan() |
|
local players = TSMAPI:ModuleAPI("ItemTracker", "playerlist") |
|
if not players then |
|
TSM:Print(L["ItemTracker data unavailable."]) |
|
return |
|
end |
|
|
|
local specificItems, baseCandidates, hasSpecific = {}, {}, {} |
|
for _, player in ipairs(players) do |
|
local bags = TSMAPI:ModuleAPI("ItemTracker", "playerbags", player) |
|
local bank = TSMAPI:ModuleAPI("ItemTracker", "playerbank", player) |
|
if bags then |
|
private:CollectItemStrings(bags, specificItems, baseCandidates, hasSpecific) |
|
end |
|
if bank then |
|
private:CollectItemStrings(bank, specificItems, baseCandidates, hasSpecific) |
|
end |
|
end |
|
|
|
for baseItemString in pairs(baseCandidates) do |
|
if not hasSpecific[baseItemString] then |
|
specificItems[baseItemString] = true |
|
end |
|
end |
|
|
|
local items = {} |
|
for itemString in pairs(specificItems) do |
|
tinsert(items, itemString) |
|
end |
|
if #items == 0 then |
|
TSM:Print(L["No inventory items found."]) |
|
return |
|
end |
|
|
|
TSM.Scan:StartGroupScan(items) |
|
end |
|
|
|
function private:CollectItemStrings(data, specificItems, baseCandidates, hasSpecific) |
|
for itemString in pairs(data) do |
|
if type(itemString) == "string" then |
|
local baseItemString = TSMAPI:GetBaseItemString(itemString) or itemString |
|
if itemString ~= baseItemString then |
|
specificItems[itemString] = true |
|
hasSpecific[baseItemString] = true |
|
else |
|
baseCandidates[baseItemString] = true |
|
end |
|
end |
|
end |
|
end |
|
|
|
function private:GetItemTrackerItems(key) |
|
local data = TSMAPI:ModuleAPI("ItemTracker", key) |
|
if not data then |
|
TSM:Print(L["ItemTracker data unavailable."]) |
|
return |
|
end |
|
|
|
local specificItems, baseCandidates, hasSpecific = {}, {}, {} |
|
private:CollectItemStrings(data, specificItems, baseCandidates, hasSpecific) |
|
|
|
for baseItemString in pairs(baseCandidates) do |
|
if not hasSpecific[baseItemString] then |
|
specificItems[baseItemString] = true |
|
end |
|
end |
|
|
|
local items = {} |
|
for itemString in pairs(specificItems) do |
|
tinsert(items, itemString) |
|
end |
|
return items |
|
end |
|
|
|
function GUI:StartBagScan() |
|
local items = private:GetItemTrackerItems("playerbags") |
|
if not items then |
|
return |
|
end |
|
if #items == 0 then |
|
TSM:Print(L["No bag items found."]) |
|
return |
|
end |
|
|
|
TSM.Scan:StartGroupScan(items) |
|
end |
|
|
|
function GUI:StartBankScan() |
|
local items = private:GetItemTrackerItems("playerbank") |
|
if not items then |
|
return |
|
end |
|
if #items == 0 then |
|
TSM:Print(L["No bank items found."]) |
|
return |
|
end |
|
|
|
TSM.Scan:StartGroupScan(items) |
|
end |
|
|
|
function GUI:CancelScan() |
|
TSMAPI.AuctionScan:StopScan(true) |
|
TSM.Scan:DoneScanning() |
|
end
|
|
|