initial commit
This commit is contained in:
44
Core/Service/TaskList/Tasks/AltTask.lua
Normal file
44
Core/Service/TaskList/Tasks/AltTask.lua
Normal file
@@ -0,0 +1,44 @@
|
||||
-- ------------------------------------------------------------------------------ --
|
||||
-- TradeSkillMaster --
|
||||
-- https://tradeskillmaster.com --
|
||||
-- All Rights Reserved - Detailed license information included with addon. --
|
||||
-- ------------------------------------------------------------------------------ --
|
||||
|
||||
local _, TSM = ...
|
||||
local AltTask = TSM.Include("LibTSMClass").DefineClass("AltTask", TSM.TaskList.Task)
|
||||
local L = TSM.Include("Locale").GetTable()
|
||||
TSM.TaskList.AltTask = AltTask
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- Class Meta Methods
|
||||
-- ============================================================================
|
||||
|
||||
function AltTask.Acquire(self, doneHandler, category, character)
|
||||
self.__super:Acquire(doneHandler, category, format(L["Switch to %s"], character))
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- Public Class Methods
|
||||
-- ============================================================================
|
||||
|
||||
function AltTask.IsSecureMacro(self)
|
||||
return true
|
||||
end
|
||||
|
||||
function AltTask.GetSecureMacroText(self)
|
||||
return "/logout"
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- Private Class Methods
|
||||
-- ============================================================================
|
||||
|
||||
function AltTask._UpdateState(self)
|
||||
return self:_SetButtonState(true, strupper(LOGOUT))
|
||||
end
|
||||
132
Core/Service/TaskList/Tasks/BankingTask.lua
Normal file
132
Core/Service/TaskList/Tasks/BankingTask.lua
Normal file
@@ -0,0 +1,132 @@
|
||||
-- ------------------------------------------------------------------------------ --
|
||||
-- TradeSkillMaster --
|
||||
-- https://tradeskillmaster.com --
|
||||
-- All Rights Reserved - Detailed license information included with addon. --
|
||||
-- ------------------------------------------------------------------------------ --
|
||||
|
||||
local _, TSM = ...
|
||||
local BankingTask = TSM.Include("LibTSMClass").DefineClass("BankingTask", TSM.TaskList.ItemTask)
|
||||
local L = TSM.Include("Locale").GetTable()
|
||||
local Inventory = TSM.Include("Service.Inventory")
|
||||
TSM.TaskList.BankingTask = BankingTask
|
||||
local private = {
|
||||
registeredCallbacks = false,
|
||||
currentlyMoving = nil,
|
||||
activeTasks = {},
|
||||
}
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- Class Meta Methods
|
||||
-- ============================================================================
|
||||
|
||||
function BankingTask.__init(self, isGuildBank)
|
||||
self.__super:__init()
|
||||
self._isMoving = false
|
||||
self._isGuildBank = isGuildBank
|
||||
|
||||
if not private.registeredCallbacks then
|
||||
TSM.Banking.RegisterFrameCallback(private.FrameCallback)
|
||||
private.registeredCallbacks = true
|
||||
end
|
||||
end
|
||||
|
||||
function BankingTask.Acquire(self, doneHandler, category)
|
||||
self.__super:Acquire(doneHandler, category, self._isGuildBank and L["Get from Guild Bank"] or L["Get from Bank"])
|
||||
private.activeTasks[self] = true
|
||||
end
|
||||
|
||||
function BankingTask.Release(self)
|
||||
self.__super:Release()
|
||||
self._isMoving = false
|
||||
private.activeTasks[self] = nil
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- Public Class Methods
|
||||
-- ============================================================================
|
||||
|
||||
function BankingTask.OnButtonClick(self)
|
||||
private.currentlyMoving = self
|
||||
self._isMoving = true
|
||||
TSM.Banking.MoveToBag(self:GetItems(), private.MoveCallback)
|
||||
self:_UpdateState()
|
||||
TSM.TaskList.OnTaskUpdated()
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- Private Class Methods
|
||||
-- ============================================================================
|
||||
|
||||
function BankingTask._UpdateState(self)
|
||||
local isOpen = nil
|
||||
if self._isGuildBank then
|
||||
isOpen = TSM.Banking.IsGuildBankOpen()
|
||||
else
|
||||
isOpen = TSM.Banking.IsBankOpen()
|
||||
end
|
||||
if not isOpen then
|
||||
return self:_SetButtonState(false, L["NOT OPEN"])
|
||||
end
|
||||
local canMove = false
|
||||
for itemString in pairs(self:GetItems()) do
|
||||
if self._isGuildBank and Inventory.GetGuildQuantity(itemString) > 0 then
|
||||
canMove = true
|
||||
break
|
||||
elseif not self._isGuildBank and Inventory.GetBankQuantity(itemString) + Inventory.GetReagentBankQuantity(itemString) > 0 then
|
||||
canMove = true
|
||||
break
|
||||
end
|
||||
end
|
||||
if self._isMoving then
|
||||
return self:_SetButtonState(false, L["MOVING"])
|
||||
elseif private.currentlyMoving then
|
||||
return self:_SetButtonState(false, L["BUSY"])
|
||||
elseif not canMove then
|
||||
return self:_SetButtonState(false, L["NO ITEMS"])
|
||||
else
|
||||
return self:_SetButtonState(true, L["MOVE"])
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- Private Helper Functions
|
||||
-- ============================================================================
|
||||
|
||||
function private.FrameCallback()
|
||||
for task in pairs(private.activeTasks) do
|
||||
task:Update()
|
||||
end
|
||||
end
|
||||
|
||||
function private.MoveCallback(event, ...)
|
||||
local self = private.currentlyMoving
|
||||
if not self then
|
||||
return
|
||||
end
|
||||
assert(self._isMoving)
|
||||
if event == "MOVED" then
|
||||
local itemString, quantity = ...
|
||||
if self:_RemoveItem(itemString, quantity) then
|
||||
TSM.TaskList.OnTaskUpdated()
|
||||
end
|
||||
if not private.activeTasks[self] then
|
||||
-- this task finished
|
||||
private.currentlyMoving = nil
|
||||
end
|
||||
elseif event == "DONE" then
|
||||
self._isMoving = false
|
||||
private.currentlyMoving = nil
|
||||
elseif event == "PROGRESS" then
|
||||
-- pass
|
||||
else
|
||||
error("Unexpected event: "..tostring(event))
|
||||
end
|
||||
end
|
||||
94
Core/Service/TaskList/Tasks/CooldownCraftingTask.lua
Normal file
94
Core/Service/TaskList/Tasks/CooldownCraftingTask.lua
Normal file
@@ -0,0 +1,94 @@
|
||||
-- ------------------------------------------------------------------------------ --
|
||||
-- TradeSkillMaster --
|
||||
-- https://tradeskillmaster.com --
|
||||
-- All Rights Reserved - Detailed license information included with addon. --
|
||||
-- ------------------------------------------------------------------------------ --
|
||||
|
||||
local _, TSM = ...
|
||||
local CooldownCraftingTask = TSM.Include("LibTSMClass").DefineClass("CooldownCraftingTask", TSM.TaskList.CraftingTask)
|
||||
local Math = TSM.Include("Util.Math")
|
||||
TSM.TaskList.CooldownCraftingTask = CooldownCraftingTask
|
||||
local private = {
|
||||
registeredCallbacks = false,
|
||||
activeTasks = {},
|
||||
}
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- Class Meta Methods
|
||||
-- ============================================================================
|
||||
|
||||
function CooldownCraftingTask.__init(self)
|
||||
self.__super:__init()
|
||||
if not private.registeredCallbacks then
|
||||
TSM.Crafting.CreateIgnoredCooldownQuery()
|
||||
:SetUpdateCallback(private.UpdateTasks)
|
||||
private.registeredCallbacks = true
|
||||
end
|
||||
end
|
||||
|
||||
function CooldownCraftingTask.Acquire(self, ...)
|
||||
self.__super:Acquire(...)
|
||||
private.activeTasks[self] = true
|
||||
end
|
||||
|
||||
function CooldownCraftingTask.Release(self)
|
||||
self.__super:Release()
|
||||
private.activeTasks[self] = nil
|
||||
end
|
||||
|
||||
function CooldownCraftingTask.CanHideSubTasks(self)
|
||||
return true
|
||||
end
|
||||
|
||||
function CooldownCraftingTask.HideSubTask(self, index)
|
||||
TSM.Crafting.IgnoreCooldown(self._spellIds[index])
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- Private Class Methods
|
||||
-- ============================================================================
|
||||
|
||||
function CooldownCraftingTask._UpdateState(self)
|
||||
local result = self.__super:_UpdateState()
|
||||
if not self:HasSpellIds() then
|
||||
return result
|
||||
end
|
||||
for i = #self._spellIds, 1, -1 do
|
||||
if self:_IsOnCooldown(self._spellIds[i]) or TSM.Crafting.IsCooldownIgnored(self._spellIds[i]) then
|
||||
self:_RemoveSpellId(self._spellIds[i])
|
||||
end
|
||||
end
|
||||
if not self:HasSpellIds() then
|
||||
self:_doneHandler()
|
||||
return true
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
function CooldownCraftingTask._IsOnCooldown(self, spellId)
|
||||
assert(not TSM.db.char.internalData.craftingCooldowns[spellId])
|
||||
local remainingCooldown = TSM.Crafting.ProfessionUtil.GetRemainingCooldown(spellId)
|
||||
if remainingCooldown then
|
||||
TSM.db.char.internalData.craftingCooldowns[spellId] = time() + Math.Round(remainingCooldown)
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- Private Helper Functions
|
||||
-- ============================================================================
|
||||
|
||||
function private.UpdateTasks()
|
||||
for task in pairs(private.activeTasks) do
|
||||
if task:HasSpellIds() then
|
||||
task:Update()
|
||||
end
|
||||
end
|
||||
end
|
||||
212
Core/Service/TaskList/Tasks/CraftingTask.lua
Normal file
212
Core/Service/TaskList/Tasks/CraftingTask.lua
Normal file
@@ -0,0 +1,212 @@
|
||||
-- ------------------------------------------------------------------------------ --
|
||||
-- TradeSkillMaster --
|
||||
-- https://tradeskillmaster.com --
|
||||
-- All Rights Reserved - Detailed license information included with addon. --
|
||||
-- ------------------------------------------------------------------------------ --
|
||||
|
||||
local _, TSM = ...
|
||||
local CraftingTask = TSM.Include("LibTSMClass").DefineClass("CraftingTask", TSM.TaskList.Task)
|
||||
local L = TSM.Include("Locale").GetTable()
|
||||
local Table = TSM.Include("Util.Table")
|
||||
local Log = TSM.Include("Util.Log")
|
||||
local BagTracking = TSM.Include("Service.BagTracking")
|
||||
TSM.TaskList.CraftingTask = CraftingTask
|
||||
local private = {
|
||||
currentlyCrafting = nil,
|
||||
registeredCallbacks = false,
|
||||
activeTasks = {},
|
||||
}
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- Class Meta Methods
|
||||
-- ============================================================================
|
||||
|
||||
function CraftingTask.__init(self)
|
||||
self.__super:__init()
|
||||
self._profession = nil
|
||||
self._skillId = nil
|
||||
self._spellIds = {}
|
||||
self._spellQuantity = {}
|
||||
|
||||
if not private.registeredCallbacks then
|
||||
TSM.Crafting.ProfessionState.RegisterUpdateCallback(private.UpdateTasks)
|
||||
TSM.Crafting.ProfessionScanner.RegisterHasScannedCallback(private.UpdateTasks)
|
||||
BagTracking.RegisterCallback(private.UpdateTasks)
|
||||
private.registeredCallbacks = true
|
||||
end
|
||||
end
|
||||
|
||||
function CraftingTask.Acquire(self, doneHandler, category, profession)
|
||||
self.__super:Acquire(doneHandler, category, format(L["%s Crafts"], profession))
|
||||
self._profession = profession
|
||||
for _, _, prof, skillId in TSM.Crafting.PlayerProfessions.Iterator() do
|
||||
if prof == profession and (not self._skillId or (self._skillId == -1 and skillId ~= -1)) then
|
||||
self._skillId = skillId
|
||||
end
|
||||
end
|
||||
private.activeTasks[self] = true
|
||||
end
|
||||
|
||||
function CraftingTask.Release(self)
|
||||
self.__super:Release()
|
||||
self._profession = nil
|
||||
self._skillId = nil
|
||||
wipe(self._spellIds)
|
||||
wipe(self._spellQuantity)
|
||||
private.activeTasks[self] = nil
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- Public Class Methods
|
||||
-- ============================================================================
|
||||
|
||||
function CraftingTask.WipeSpellIds(self)
|
||||
wipe(self._spellIds)
|
||||
wipe(self._spellQuantity)
|
||||
end
|
||||
|
||||
function CraftingTask.HasSpellIds(self)
|
||||
return #self._spellIds > 0
|
||||
end
|
||||
|
||||
function CraftingTask.GetProfession(self)
|
||||
return self._profession
|
||||
end
|
||||
|
||||
function CraftingTask.HasSpellId(self, spellId)
|
||||
return self._spellQuantity[spellId] and true or false
|
||||
end
|
||||
|
||||
function CraftingTask.AddSpellId(self, spellId, quantity)
|
||||
tinsert(self._spellIds, spellId)
|
||||
self._spellQuantity[spellId] = quantity
|
||||
end
|
||||
|
||||
function CraftingTask.OnMouseDown(self)
|
||||
if self._buttonText == L["CRAFT"] then
|
||||
local spellId = self._spellIds[1]
|
||||
local quantity = self._spellQuantity[spellId]
|
||||
Log.Info("Preparing %d (%d)", spellId, quantity)
|
||||
TSM.Crafting.ProfessionUtil.PrepareToCraft(spellId, quantity)
|
||||
end
|
||||
end
|
||||
|
||||
function CraftingTask.OnButtonClick(self)
|
||||
if self._buttonText == L["CRAFT"] then
|
||||
local spellId = self._spellIds[1]
|
||||
local quantity = self._spellQuantity[spellId]
|
||||
Log.Info("Crafting %d (%d)", spellId, quantity)
|
||||
private.currentlyCrafting = self
|
||||
local numCrafted = TSM.Crafting.ProfessionUtil.Craft(spellId, quantity, true, private.CraftCompleteCallback)
|
||||
if numCrafted == 0 then
|
||||
-- we're probably crafting something else already - so just bail
|
||||
Log.Err("Failed to craft")
|
||||
private.currentlyCrafting = nil
|
||||
end
|
||||
elseif self._buttonText == L["OPEN"] then
|
||||
TSM.Crafting.ProfessionUtil.OpenProfession(self._profession, self._skillId)
|
||||
else
|
||||
error("Invalid state: "..tostring(self._buttonText))
|
||||
end
|
||||
self:Update()
|
||||
end
|
||||
|
||||
function CraftingTask.HasSubTasks(self)
|
||||
assert(self:HasSpellIds())
|
||||
return true
|
||||
end
|
||||
|
||||
function CraftingTask.SubTaskIterator(self)
|
||||
assert(self:HasSpellIds())
|
||||
sort(self._spellIds, private.SpellIdSort)
|
||||
return private.SubTaskIterator, self, 0
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- Private Class Methods
|
||||
-- ============================================================================
|
||||
|
||||
function CraftingTask._UpdateState(self)
|
||||
sort(self._spellIds, private.SpellIdSort)
|
||||
if TSM.Crafting.ProfessionUtil.GetNumCraftableFromDB(self._spellIds[1]) == 0 then
|
||||
-- don't have the mats to craft this
|
||||
return self:_SetButtonState(false, L["NEED MATS"])
|
||||
elseif self._profession ~= TSM.Crafting.ProfessionState.GetCurrentProfession() then
|
||||
-- the profession isn't opened
|
||||
return self:_SetButtonState(true, L["OPEN"])
|
||||
elseif not TSM.Crafting.ProfessionScanner.HasScanned() then
|
||||
-- the profession is opened, but we haven't yet fully scanned it
|
||||
return self:_SetButtonState(false, strupper(OPENING))
|
||||
elseif private.currentlyCrafting == self then
|
||||
return self:_SetButtonState(false, L["CRAFTING"])
|
||||
elseif private.currentlyCrafting then
|
||||
return self:_SetButtonState(false, L["BUSY"])
|
||||
else
|
||||
-- ready to craft
|
||||
return self:_SetButtonState(true, L["CRAFT"])
|
||||
end
|
||||
end
|
||||
|
||||
function CraftingTask._RemoveSpellId(self, spellId)
|
||||
assert(Table.RemoveByValue(self._spellIds, spellId) == 1)
|
||||
self._spellQuantity[spellId] = nil
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- Private Helper Functions
|
||||
-- ============================================================================
|
||||
|
||||
function private.SubTaskIterator(self, index)
|
||||
index = index + 1
|
||||
local spellId = self._spellIds[index]
|
||||
if not spellId then
|
||||
return
|
||||
end
|
||||
return index, TSM.Crafting.GetName(spellId).." ("..self._spellQuantity[spellId]..")"
|
||||
end
|
||||
|
||||
function private.CraftCompleteCallback(success, isDone)
|
||||
local self = private.currentlyCrafting
|
||||
assert(self)
|
||||
local spellId = self._spellIds[1]
|
||||
if isDone then
|
||||
private.currentlyCrafting = nil
|
||||
if success then
|
||||
self:_RemoveSpellId(spellId)
|
||||
if not self:HasSpellIds() then
|
||||
self:_doneHandler()
|
||||
end
|
||||
end
|
||||
elseif success then
|
||||
self._spellQuantity[spellId] = self._spellQuantity[spellId] - 1
|
||||
assert(self._spellQuantity[spellId] > 0)
|
||||
end
|
||||
if self:HasSpellIds() then
|
||||
self:Update()
|
||||
end
|
||||
end
|
||||
|
||||
function private.UpdateTasks()
|
||||
for task in pairs(private.activeTasks) do
|
||||
if task:HasSpellIds() then
|
||||
task:Update()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function private.SpellIdSort(a, b)
|
||||
local aNumCraftable = TSM.Crafting.ProfessionUtil.GetNumCraftableFromDB(a)
|
||||
local bNumCraftable = TSM.Crafting.ProfessionUtil.GetNumCraftableFromDB(b)
|
||||
if aNumCraftable == bNumCraftable then
|
||||
return a < b
|
||||
end
|
||||
return aNumCraftable > bNumCraftable
|
||||
end
|
||||
124
Core/Service/TaskList/Tasks/ExpiredAuctionTask.lua
Normal file
124
Core/Service/TaskList/Tasks/ExpiredAuctionTask.lua
Normal file
@@ -0,0 +1,124 @@
|
||||
-- ------------------------------------------------------------------------------ --
|
||||
-- TradeSkillMaster --
|
||||
-- https://tradeskillmaster.com --
|
||||
-- All Rights Reserved - Detailed license information included with addon. --
|
||||
-- ------------------------------------------------------------------------------ --
|
||||
|
||||
local _, TSM = ...
|
||||
local ExpiredAuctionTask = TSM.Include("LibTSMClass").DefineClass("ExpiredAuctionTask", TSM.TaskList.Task)
|
||||
local L = TSM.Include("Locale").GetTable()
|
||||
TSM.TaskList.ExpiredAuctionTask = ExpiredAuctionTask
|
||||
local private = {}
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- Class Meta Methods
|
||||
-- ============================================================================
|
||||
|
||||
function ExpiredAuctionTask.__init(self)
|
||||
self.__super:__init()
|
||||
self._characters = {}
|
||||
self._daysLeft = {}
|
||||
end
|
||||
|
||||
function ExpiredAuctionTask.Acquire(self, doneHandler, category)
|
||||
self.__super:Acquire(doneHandler, category, L["Expired Auctions"])
|
||||
end
|
||||
|
||||
function ExpiredAuctionTask.Release(self)
|
||||
self.__super:Release()
|
||||
wipe(self._characters)
|
||||
wipe(self._daysLeft)
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- Public Class Methods
|
||||
-- ============================================================================
|
||||
|
||||
function ExpiredAuctionTask.IsSecureMacro(self)
|
||||
return true
|
||||
end
|
||||
|
||||
function ExpiredAuctionTask.GetSecureMacroText(self)
|
||||
return "/logout"
|
||||
end
|
||||
|
||||
function ExpiredAuctionTask.GetDaysLeft(self, character)
|
||||
return self._daysLeft[character] or false
|
||||
end
|
||||
|
||||
function ExpiredAuctionTask.WipeCharacters(self)
|
||||
wipe(self._characters)
|
||||
wipe(self._daysLeft)
|
||||
end
|
||||
|
||||
function ExpiredAuctionTask.HasCharacters(self)
|
||||
return #self._characters > 0
|
||||
end
|
||||
|
||||
function ExpiredAuctionTask.HasCharacter(self, character)
|
||||
return self._daysLeft[character] and true or false
|
||||
end
|
||||
|
||||
function ExpiredAuctionTask.AddCharacter(self, character, days)
|
||||
tinsert(self._characters, character)
|
||||
self._daysLeft[character] = days
|
||||
end
|
||||
|
||||
function ExpiredAuctionTask.CanHideSubTasks(self)
|
||||
return true
|
||||
end
|
||||
|
||||
function ExpiredAuctionTask.HideSubTask(self, index)
|
||||
local character = self._characters[index]
|
||||
if not character then
|
||||
return
|
||||
end
|
||||
TSM.db.factionrealm.internalData.expiringAuction[character] = nil
|
||||
|
||||
TSM.TaskList.Expirations.Update()
|
||||
end
|
||||
|
||||
function ExpiredAuctionTask.HasSubTasks(self)
|
||||
assert(self:HasCharacters())
|
||||
return true
|
||||
end
|
||||
|
||||
function ExpiredAuctionTask.SubTaskIterator(self)
|
||||
assert(self:HasCharacters())
|
||||
sort(self._characters)
|
||||
return private.SubTaskIterator, self, 0
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- Private Class Methods
|
||||
-- ============================================================================
|
||||
|
||||
function ExpiredAuctionTask._UpdateState(self)
|
||||
return self:_SetButtonState(true, strupper(LOGOUT))
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- Private Helper Functions
|
||||
-- ============================================================================
|
||||
|
||||
function private.SubTaskIterator(self, index)
|
||||
index = index + 1
|
||||
local character = self._characters[index]
|
||||
if not character then
|
||||
return
|
||||
end
|
||||
local charColored = character
|
||||
local classColor = RAID_CLASS_COLORS[TSM.db:Get("sync", TSM.db:GetSyncScopeKeyByCharacter(character), "internalData", "classKey")]
|
||||
if classColor then
|
||||
charColored = "|c"..classColor.colorStr..charColored.."|r"
|
||||
end
|
||||
return index, charColored
|
||||
end
|
||||
140
Core/Service/TaskList/Tasks/ExpiringMailTask.lua
Normal file
140
Core/Service/TaskList/Tasks/ExpiringMailTask.lua
Normal file
@@ -0,0 +1,140 @@
|
||||
-- ------------------------------------------------------------------------------ --
|
||||
-- TradeSkillMaster --
|
||||
-- https://tradeskillmaster.com --
|
||||
-- All Rights Reserved - Detailed license information included with addon. --
|
||||
-- ------------------------------------------------------------------------------ --
|
||||
|
||||
local _, TSM = ...
|
||||
local ExpiringMailTask = TSM.Include("LibTSMClass").DefineClass("ExpiringMailTask", TSM.TaskList.Task)
|
||||
local L = TSM.Include("Locale").GetTable()
|
||||
TSM.TaskList.ExpiringMailTask = ExpiringMailTask
|
||||
local private = {}
|
||||
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- Class Meta Methods
|
||||
-- ============================================================================
|
||||
|
||||
function ExpiringMailTask.__init(self)
|
||||
self.__super:__init()
|
||||
self._characters = {}
|
||||
self._daysLeft = {}
|
||||
end
|
||||
|
||||
function ExpiringMailTask.Acquire(self, doneHandler, category)
|
||||
self.__super:Acquire(doneHandler, category, L["Expiring Mails"])
|
||||
end
|
||||
|
||||
function ExpiringMailTask.Release(self)
|
||||
self.__super:Release()
|
||||
wipe(self._characters)
|
||||
wipe(self._daysLeft)
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- Public Class Methods
|
||||
-- ============================================================================
|
||||
|
||||
function ExpiringMailTask.IsSecureMacro(self)
|
||||
return true
|
||||
end
|
||||
|
||||
function ExpiringMailTask.GetSecureMacroText(self)
|
||||
return "/logout"
|
||||
end
|
||||
|
||||
function ExpiringMailTask.GetDaysLeft(self, character)
|
||||
return self._daysLeft[character] or false
|
||||
end
|
||||
|
||||
function ExpiringMailTask.WipeCharacters(self)
|
||||
wipe(self._characters)
|
||||
wipe(self._daysLeft)
|
||||
end
|
||||
|
||||
function ExpiringMailTask.HasCharacters(self)
|
||||
return #self._characters > 0
|
||||
end
|
||||
|
||||
function ExpiringMailTask.HasCharacter(self, character)
|
||||
return self._daysLeft[character] and true or false
|
||||
end
|
||||
|
||||
function ExpiringMailTask.AddCharacter(self, character, days)
|
||||
tinsert(self._characters, character)
|
||||
self._daysLeft[character] = days
|
||||
end
|
||||
|
||||
function ExpiringMailTask.CanHideSubTasks(self)
|
||||
return true
|
||||
end
|
||||
|
||||
function ExpiringMailTask.HideSubTask(self, index)
|
||||
local character = self._characters[index]
|
||||
if not character then
|
||||
return
|
||||
end
|
||||
TSM.db.factionrealm.internalData.expiringMail[character] = nil
|
||||
|
||||
TSM.TaskList.Expirations.Update()
|
||||
end
|
||||
|
||||
function ExpiringMailTask.HasSubTasks(self)
|
||||
assert(self:HasCharacters())
|
||||
return true
|
||||
end
|
||||
|
||||
function ExpiringMailTask.SubTaskIterator(self)
|
||||
assert(self:HasCharacters())
|
||||
sort(self._characters)
|
||||
return private.SubTaskIterator, self, 0
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- Private Class Methods
|
||||
-- ============================================================================
|
||||
|
||||
function ExpiringMailTask._UpdateState(self)
|
||||
return self:_SetButtonState(true, strupper(LOGOUT))
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- Private Helper Functions
|
||||
-- ============================================================================
|
||||
|
||||
function private.SubTaskIterator(self, index)
|
||||
index = index + 1
|
||||
local character = self._characters[index]
|
||||
if not character then
|
||||
return
|
||||
end
|
||||
local timeLeft = self._daysLeft[character]
|
||||
if timeLeft < 0 then
|
||||
timeLeft = L["Expired"]
|
||||
elseif timeLeft >= 1 then
|
||||
timeLeft = floor(timeLeft).." "..DAYS
|
||||
else
|
||||
local hoursLeft = floor(timeLeft * 24)
|
||||
if hoursLeft > 1 then
|
||||
timeLeft = hoursLeft.." "..L["Hrs"]
|
||||
elseif hoursLeft == 1 then
|
||||
timeLeft = hoursLeft.." "..L["Hr"]
|
||||
else
|
||||
timeLeft = floor(hoursLeft / 60).." "..L["Min"]
|
||||
end
|
||||
end
|
||||
local charColored = character
|
||||
local classColor = RAID_CLASS_COLORS[TSM.db:Get("sync", TSM.db:GetSyncScopeKeyByCharacter(character), "internalData", "classKey")]
|
||||
if classColor then
|
||||
charColored = "|c"..classColor.colorStr..charColored.."|r"
|
||||
end
|
||||
return index, charColored.." ("..timeLeft..")"
|
||||
end
|
||||
118
Core/Service/TaskList/Tasks/ItemTask.lua
Normal file
118
Core/Service/TaskList/Tasks/ItemTask.lua
Normal file
@@ -0,0 +1,118 @@
|
||||
-- ------------------------------------------------------------------------------ --
|
||||
-- TradeSkillMaster --
|
||||
-- https://tradeskillmaster.com --
|
||||
-- All Rights Reserved - Detailed license information included with addon. --
|
||||
-- ------------------------------------------------------------------------------ --
|
||||
|
||||
local _, TSM = ...
|
||||
local ItemTask = TSM.Include("LibTSMClass").DefineClass("ItemTask", TSM.TaskList.Task, "ABSTRACT")
|
||||
local Table = TSM.Include("Util.Table")
|
||||
local Math = TSM.Include("Util.Math")
|
||||
local ItemInfo = TSM.Include("Service.ItemInfo")
|
||||
TSM.TaskList.ItemTask = ItemTask
|
||||
local private = {}
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- Class Meta Methods
|
||||
-- ============================================================================
|
||||
|
||||
function ItemTask.__init(self)
|
||||
self.__super:__init()
|
||||
self._itemList = {}
|
||||
self._itemNum = {}
|
||||
end
|
||||
|
||||
function ItemTask.Release(self)
|
||||
self.__super:Release()
|
||||
self:WipeItems()
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- Public Class Methods
|
||||
-- ============================================================================
|
||||
|
||||
function ItemTask.WipeItems(self)
|
||||
wipe(self._itemList)
|
||||
wipe(self._itemNum)
|
||||
end
|
||||
|
||||
function ItemTask.AddItem(self, itemString, quantity)
|
||||
if not self._itemNum[itemString] then
|
||||
tinsert(self._itemList, itemString)
|
||||
self._itemNum[itemString] = 0
|
||||
end
|
||||
self._itemNum[itemString] = self._itemNum[itemString] + quantity
|
||||
end
|
||||
|
||||
function ItemTask.GetItems(self)
|
||||
return self._itemNum
|
||||
end
|
||||
|
||||
function ItemTask.HasItems(self)
|
||||
return next(self._itemNum) and true or false
|
||||
end
|
||||
|
||||
function ItemTask.HasSubTasks(self)
|
||||
assert(#self._itemList > 0)
|
||||
return true
|
||||
end
|
||||
|
||||
function ItemTask.SubTaskIterator(self)
|
||||
assert(#self._itemList > 0)
|
||||
Table.Sort(self._itemList, private.ItemSortHelper)
|
||||
return private.SubTaskIterator, self, 0
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- Private Class Methods
|
||||
-- ============================================================================
|
||||
|
||||
function ItemTask._RemoveItem(self, itemString, quantity)
|
||||
if not self._itemNum[itemString] then
|
||||
return false
|
||||
end
|
||||
self._itemNum[itemString] = Math.Round(self._itemNum[itemString] - quantity, 0.01)
|
||||
if self._itemNum[itemString] <= 0.01 then
|
||||
self._itemNum[itemString] = nil
|
||||
assert(Table.RemoveByValue(self._itemList, itemString) == 1)
|
||||
end
|
||||
if #self._itemList == 0 then
|
||||
self:_doneHandler()
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- Private Helper Functions
|
||||
-- ============================================================================
|
||||
|
||||
function private.SubTaskIterator(self, index)
|
||||
index = index + 1
|
||||
local itemString = self._itemList[index]
|
||||
if not itemString then
|
||||
return
|
||||
end
|
||||
return index, format("%s (%d)", ItemInfo.GetLink(itemString), self._itemNum[itemString])
|
||||
end
|
||||
|
||||
function private.ItemSortHelper(a, b)
|
||||
local aName = ItemInfo.GetName(a)
|
||||
local bName = ItemInfo.GetName(b)
|
||||
if aName == bName then
|
||||
return a < b
|
||||
end
|
||||
if not aName then
|
||||
return false
|
||||
elseif not bName then
|
||||
return true
|
||||
end
|
||||
return aName < bName
|
||||
end
|
||||
74
Core/Service/TaskList/Tasks/OpenMailTask.lua
Normal file
74
Core/Service/TaskList/Tasks/OpenMailTask.lua
Normal file
@@ -0,0 +1,74 @@
|
||||
-- ------------------------------------------------------------------------------ --
|
||||
-- TradeSkillMaster --
|
||||
-- https://tradeskillmaster.com --
|
||||
-- All Rights Reserved - Detailed license information included with addon. --
|
||||
-- ------------------------------------------------------------------------------ --
|
||||
|
||||
local _, TSM = ...
|
||||
local OpenMailTask = TSM.Include("LibTSMClass").DefineClass("OpenMailTask", TSM.TaskList.ItemTask)
|
||||
local L = TSM.Include("Locale").GetTable()
|
||||
TSM.TaskList.OpenMailTask = OpenMailTask
|
||||
local private = {
|
||||
activeTasks = {},
|
||||
registeredCallbacks = false,
|
||||
}
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- Class Meta Methods
|
||||
-- ============================================================================
|
||||
|
||||
function OpenMailTask.__init(self)
|
||||
self.__super:__init()
|
||||
if not private.registeredCallbacks then
|
||||
TSM.Mailing.RegisterFrameCallback(private.FrameCallback)
|
||||
private.registeredCallbacks = true
|
||||
end
|
||||
end
|
||||
|
||||
function OpenMailTask.Acquire(self, doneHandler, category)
|
||||
self.__super:Acquire(doneHandler, category, L["Open Mail"])
|
||||
private.activeTasks[self] = true
|
||||
end
|
||||
|
||||
function OpenMailTask.Release(self)
|
||||
self.__super:Release()
|
||||
private.activeTasks[self] = nil
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- Public Class Methods
|
||||
-- ============================================================================
|
||||
|
||||
function OpenMailTask.OnButtonClick(self)
|
||||
-- TODO
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- Private Class Methods
|
||||
-- ============================================================================
|
||||
|
||||
function OpenMailTask._UpdateState(self)
|
||||
if not TSM.Mailing.IsOpen() then
|
||||
return self:_SetButtonState(false, L["NOT OPEN"])
|
||||
else
|
||||
return self:_SetButtonState(false, L["OPEN"])
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- Private Helper Functions
|
||||
-- ============================================================================
|
||||
|
||||
function private.FrameCallback()
|
||||
for task in pairs(private.activeTasks) do
|
||||
task:Update()
|
||||
end
|
||||
end
|
||||
105
Core/Service/TaskList/Tasks/SendMailTask.lua
Normal file
105
Core/Service/TaskList/Tasks/SendMailTask.lua
Normal file
@@ -0,0 +1,105 @@
|
||||
-- ------------------------------------------------------------------------------ --
|
||||
-- TradeSkillMaster --
|
||||
-- https://tradeskillmaster.com --
|
||||
-- All Rights Reserved - Detailed license information included with addon. --
|
||||
-- ------------------------------------------------------------------------------ --
|
||||
|
||||
local _, TSM = ...
|
||||
local SendMailTask = TSM.Include("LibTSMClass").DefineClass("SendMailTask", TSM.TaskList.ItemTask)
|
||||
local L = TSM.Include("Locale").GetTable()
|
||||
TSM.TaskList.SendMailTask = SendMailTask
|
||||
local private = {
|
||||
registeredCallbacks = false,
|
||||
currentlySending = nil,
|
||||
activeTasks = {},
|
||||
}
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- Class Meta Methods
|
||||
-- ============================================================================
|
||||
|
||||
function SendMailTask.__init(self)
|
||||
self.__super:__init()
|
||||
self._target = nil
|
||||
self._isSending = false
|
||||
if not private.registeredCallbacks then
|
||||
TSM.Mailing.RegisterFrameCallback(private.FrameCallback)
|
||||
private.registeredCallbacks = true
|
||||
end
|
||||
end
|
||||
|
||||
function SendMailTask.Acquire(self, doneHandler, category)
|
||||
self.__super:Acquire(doneHandler, category, "")
|
||||
private.activeTasks[self] = true
|
||||
end
|
||||
|
||||
function SendMailTask.Release(self)
|
||||
self.__super:Release()
|
||||
self._target = nil
|
||||
self._isSending = false
|
||||
private.activeTasks[self] = nil
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- Public Class Methods
|
||||
-- ============================================================================
|
||||
|
||||
function SendMailTask.SetTarget(self, target)
|
||||
self._target = target
|
||||
self._desc = format(L["Mail to %s"], target)
|
||||
end
|
||||
|
||||
function SendMailTask.OnButtonClick(self)
|
||||
private.currentlySending = self
|
||||
self._isSending = true
|
||||
TSM.Mailing.Send.StartSending(private.SendCallback, self._target, "", "", 0, self:GetItems())
|
||||
self:_UpdateState()
|
||||
TSM.TaskList.OnTaskUpdated()
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- Private Class Methods
|
||||
-- ============================================================================
|
||||
|
||||
function SendMailTask._UpdateState(self)
|
||||
if not TSM.Mailing.IsOpen() then
|
||||
return self:_SetButtonState(false, L["NOT OPEN"])
|
||||
elseif self._isSending then
|
||||
return self:_SetButtonState(false, L["SENDING"])
|
||||
elseif private.currentlySending then
|
||||
return self:_SetButtonState(false, L["BUSY"])
|
||||
else
|
||||
return self:_SetButtonState(true, strupper(L["Send"]))
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- Private Helper Methods
|
||||
-- ============================================================================
|
||||
|
||||
function private.FrameCallback()
|
||||
for task in pairs(private.activeTasks) do
|
||||
task:Update()
|
||||
end
|
||||
end
|
||||
|
||||
function private.SendCallback()
|
||||
local self = private.currentlySending
|
||||
if not self then
|
||||
return
|
||||
end
|
||||
assert(self._isSending)
|
||||
self._isSending = false
|
||||
private.currentlySending = nil
|
||||
for itemString, quantity in pairs(self:GetItems()) do
|
||||
self:_RemoveItem(itemString, quantity)
|
||||
end
|
||||
end
|
||||
141
Core/Service/TaskList/Tasks/ShoppingTask.lua
Normal file
141
Core/Service/TaskList/Tasks/ShoppingTask.lua
Normal file
@@ -0,0 +1,141 @@
|
||||
-- ------------------------------------------------------------------------------ --
|
||||
-- TradeSkillMaster --
|
||||
-- https://tradeskillmaster.com --
|
||||
-- All Rights Reserved - Detailed license information included with addon. --
|
||||
-- ------------------------------------------------------------------------------ --
|
||||
|
||||
local _, TSM = ...
|
||||
local ShoppingTask = TSM.Include("LibTSMClass").DefineClass("ShoppingTask", TSM.TaskList.ItemTask)
|
||||
local L = TSM.Include("Locale").GetTable()
|
||||
local Delay = TSM.Include("Util.Delay")
|
||||
local Log = TSM.Include("Util.Log")
|
||||
TSM.TaskList.ShoppingTask = ShoppingTask
|
||||
local private = {
|
||||
registeredCallbacks = false,
|
||||
currentlyScanning = nil,
|
||||
activeTasks = {},
|
||||
}
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- Class Meta Methods
|
||||
-- ============================================================================
|
||||
|
||||
function ShoppingTask.__init(self, searchType)
|
||||
self.__super:__init()
|
||||
self._isScanning = false
|
||||
self._isShowingResults = false
|
||||
assert(searchType == "NORMAL" or searchType == "DISENCHANT" or searchType == "CRAFTING")
|
||||
self._searchType = searchType
|
||||
|
||||
if not private.registeredCallbacks then
|
||||
TSM.UI.AuctionUI.RegisterUpdateCallback(private.UIUpdateCallback)
|
||||
TSM.UI.AuctionUI.Shopping.RegisterUpdateCallback(private.UIUpdateCallback)
|
||||
private.registeredCallbacks = true
|
||||
end
|
||||
end
|
||||
|
||||
function ShoppingTask.Acquire(self, doneHandler, category)
|
||||
local name = nil
|
||||
if self._searchType == "NORMAL" then
|
||||
name = L["Buy from AH"]
|
||||
elseif self._searchType == "DISENCHANT" then
|
||||
name = L["Buy from AH (Disenchant)"]
|
||||
elseif self._searchType == "CRAFTING" then
|
||||
name = L["Buy from AH (Crafting)"]
|
||||
else
|
||||
error("Invalid searchType: "..tostring(self._searchType))
|
||||
end
|
||||
self.__super:Acquire(doneHandler, category, name)
|
||||
private.activeTasks[self] = true
|
||||
end
|
||||
|
||||
function ShoppingTask.Release(self)
|
||||
self.__super:Release()
|
||||
self._isScanning = false
|
||||
self._isShowingResults = false
|
||||
private.activeTasks[self] = nil
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- Public Class Methods
|
||||
-- ============================================================================
|
||||
|
||||
function ShoppingTask.OnButtonClick(self)
|
||||
private.currentlyScanning = self
|
||||
TSM.UI.AuctionUI.Shopping.StartGatheringSearch(self:GetItems(), private.StateCallback, private.BuyCallback, self._searchType)
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- Private Class Methods
|
||||
-- ============================================================================
|
||||
|
||||
function ShoppingTask._UpdateState(self)
|
||||
if not TSM.UI.AuctionUI.Shopping.IsVisible() then
|
||||
return self:_SetButtonState(false, L["NOT OPEN"])
|
||||
elseif self._isScanning then
|
||||
return self:_SetButtonState(false, L["SCANNING"])
|
||||
elseif self._isShowingResults then
|
||||
return self:_SetButtonState(false, L["BUY"])
|
||||
elseif TSM.UI.AuctionUI.IsScanning() or private.currentlyScanning then
|
||||
return self:_SetButtonState(false, L["AH BUSY"])
|
||||
else
|
||||
return self:_SetButtonState(true, L["SCAN ALL"])
|
||||
end
|
||||
end
|
||||
|
||||
function ShoppingTask._OnSearchStateChanged(self, state)
|
||||
if state == "SCANNING" then
|
||||
self._isScanning = true
|
||||
self._isShowingResults = false
|
||||
elseif state == "RESULTS" then
|
||||
self._isScanning = false
|
||||
self._isShowingResults = true
|
||||
elseif state == "DONE" then
|
||||
assert(private.currentlyScanning == self)
|
||||
private.currentlyScanning = nil
|
||||
self._isScanning = false
|
||||
self._isShowingResults = false
|
||||
else
|
||||
error("Unexpected state: "..tostring(state))
|
||||
end
|
||||
self:Update()
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- Private Helper Functions
|
||||
-- ============================================================================
|
||||
|
||||
function private.UIUpdateCallback()
|
||||
Delay.AfterFrame("SHOPPING_TASK_UPDATE_CALLBACK", 1, private.UIUpdateCallbackDelayed)
|
||||
end
|
||||
|
||||
function private.UIUpdateCallbackDelayed()
|
||||
for task in pairs(private.activeTasks) do
|
||||
task:Update()
|
||||
end
|
||||
end
|
||||
|
||||
function private.StateCallback(state)
|
||||
Log.Info("State changed (%s)", state)
|
||||
local self = private.currentlyScanning
|
||||
assert(self)
|
||||
self:_OnSearchStateChanged(state)
|
||||
private.UIUpdateCallback()
|
||||
end
|
||||
|
||||
function private.BuyCallback(itemString, quantity)
|
||||
Log.Info("Bought item (%s,%d)", itemString, quantity)
|
||||
local self = private.currentlyScanning
|
||||
assert(self)
|
||||
if self:_RemoveItem(itemString, quantity) then
|
||||
TSM.TaskList.OnTaskUpdated()
|
||||
end
|
||||
end
|
||||
112
Core/Service/TaskList/Tasks/Task.lua
Normal file
112
Core/Service/TaskList/Tasks/Task.lua
Normal file
@@ -0,0 +1,112 @@
|
||||
-- ------------------------------------------------------------------------------ --
|
||||
-- TradeSkillMaster --
|
||||
-- https://tradeskillmaster.com --
|
||||
-- All Rights Reserved - Detailed license information included with addon. --
|
||||
-- ------------------------------------------------------------------------------ --
|
||||
|
||||
local _, TSM = ...
|
||||
local Task = TSM.Include("LibTSMClass").DefineClass("TASK", nil, "ABSTRACT")
|
||||
TSM.TaskList.Task = Task
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- Task - Class Meta Methods
|
||||
-- ============================================================================
|
||||
|
||||
function Task.__init(self)
|
||||
self._category = nil
|
||||
self._desc = nil
|
||||
self._buttonEnabled = nil
|
||||
self._buttonText = nil
|
||||
self._doneHandler = nil
|
||||
end
|
||||
|
||||
function Task.Acquire(self, doneHandler, category, desc)
|
||||
self._doneHandler = doneHandler
|
||||
self._category = category
|
||||
self._desc = desc
|
||||
end
|
||||
|
||||
function Task.Release(self)
|
||||
self._category = nil
|
||||
self._desc = nil
|
||||
self._buttonEnabled = nil
|
||||
self._buttonText = nil
|
||||
self._doneHandler = nil
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- Task - Public Methods
|
||||
-- ============================================================================
|
||||
|
||||
function Task.GetCategory(self)
|
||||
return self._category
|
||||
end
|
||||
|
||||
function Task.GetTaskDesc(self)
|
||||
return self._desc
|
||||
end
|
||||
|
||||
function Task.HasSubTasks(self)
|
||||
return false
|
||||
end
|
||||
|
||||
function Task.SubTaskIterator(self)
|
||||
error("Must be implemented by the subclass")
|
||||
end
|
||||
|
||||
function Task.IsSecureMacro(self)
|
||||
return false
|
||||
end
|
||||
|
||||
function Task.GetSecureMacroText(self)
|
||||
error("Must be implemented by the subclass")
|
||||
end
|
||||
|
||||
function Task.GetButtonState(self)
|
||||
return self._buttonEnabled, self._buttonText
|
||||
end
|
||||
|
||||
function Task.Update(self)
|
||||
if self:_UpdateState() then
|
||||
TSM.TaskList.OnTaskUpdated()
|
||||
end
|
||||
end
|
||||
|
||||
function Task.OnMouseDown(self)
|
||||
end
|
||||
|
||||
function Task.OnButtonClick(self)
|
||||
error("Must be implemented by the subclass")
|
||||
end
|
||||
|
||||
function Task.CanHideSubTasks(self)
|
||||
return false
|
||||
end
|
||||
|
||||
function Task.HideSubTask(self)
|
||||
error("Must be implemented by the subclass")
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- Task - Private Methods
|
||||
-- ============================================================================
|
||||
|
||||
function Task._UpdateState(self)
|
||||
error("Must be implemented by the subclass")
|
||||
end
|
||||
|
||||
function Task._SetButtonState(self, buttonEnabled, buttonText)
|
||||
if buttonEnabled == self._buttonEnabled and buttonText == self._buttonText then
|
||||
-- nothing changed
|
||||
return false
|
||||
end
|
||||
self._buttonEnabled = buttonEnabled
|
||||
self._buttonText = buttonText
|
||||
return true
|
||||
end
|
||||
104
Core/Service/TaskList/Tasks/VendoringTask.lua
Normal file
104
Core/Service/TaskList/Tasks/VendoringTask.lua
Normal file
@@ -0,0 +1,104 @@
|
||||
-- ------------------------------------------------------------------------------ --
|
||||
-- TradeSkillMaster --
|
||||
-- https://tradeskillmaster.com --
|
||||
-- All Rights Reserved - Detailed license information included with addon. --
|
||||
-- ------------------------------------------------------------------------------ --
|
||||
|
||||
local _, TSM = ...
|
||||
local VendoringTask = TSM.Include("LibTSMClass").DefineClass("VendoringTask", TSM.TaskList.ItemTask)
|
||||
local L = TSM.Include("Locale").GetTable()
|
||||
local TempTable = TSM.Include("Util.TempTable")
|
||||
TSM.TaskList.VendoringTask = VendoringTask
|
||||
local private = {
|
||||
query = nil,
|
||||
activeTasks = {},
|
||||
}
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- Class Meta Methods
|
||||
-- ============================================================================
|
||||
|
||||
function VendoringTask.__init(self)
|
||||
self.__super:__init()
|
||||
|
||||
if not private.query then
|
||||
private.query = TSM.Vendoring.Buy.CreateMerchantQuery()
|
||||
:SetUpdateCallback(private.QueryUpdateCallback)
|
||||
end
|
||||
end
|
||||
|
||||
function VendoringTask.Acquire(self, doneHandler, category)
|
||||
self.__super:Acquire(doneHandler, category, L["Buy from Vendor"])
|
||||
private.activeTasks[self] = true
|
||||
end
|
||||
|
||||
function VendoringTask.Release(self)
|
||||
self.__super:Release()
|
||||
private.activeTasks[self] = nil
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- Public Class Methods
|
||||
-- ============================================================================
|
||||
|
||||
function VendoringTask.OnButtonClick(self)
|
||||
local itemsToBuy = TempTable.Acquire()
|
||||
local query = TSM.Vendoring.Buy.CreateMerchantQuery()
|
||||
:Select("itemString")
|
||||
for _, itemString in query:Iterator() do
|
||||
itemsToBuy[itemString] = self:GetItems()[itemString]
|
||||
end
|
||||
query:Release()
|
||||
|
||||
local didBuy = false
|
||||
for itemString, quantity in pairs(itemsToBuy) do
|
||||
TSM.Vendoring.Buy.BuyItem(itemString, quantity)
|
||||
self:_RemoveItem(itemString, quantity)
|
||||
didBuy = true
|
||||
end
|
||||
TempTable.Release(itemsToBuy)
|
||||
|
||||
if didBuy then
|
||||
TSM.TaskList.OnTaskUpdated(self)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- Private Class Methods
|
||||
-- ============================================================================
|
||||
|
||||
function VendoringTask._UpdateState(self)
|
||||
if not TSM.UI.VendoringUI.IsVisible() then
|
||||
return self:_SetButtonState(false, L["NOT OPEN"])
|
||||
end
|
||||
local canBuy = false
|
||||
for itemString in pairs(self:GetItems()) do
|
||||
if TSM.Vendoring.Buy.CanBuyItem(itemString) then
|
||||
canBuy = true
|
||||
break
|
||||
end
|
||||
end
|
||||
if not canBuy then
|
||||
return self:_SetButtonState(false, L["NO ITEMS"])
|
||||
else
|
||||
return self:_SetButtonState(true, L["BUY"])
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- ============================================================================
|
||||
-- Private Helper Functions
|
||||
-- ============================================================================
|
||||
|
||||
function private.QueryUpdateCallback()
|
||||
for task in pairs(private.activeTasks) do
|
||||
task:Update()
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user