WoWInterface SVN BuyDropper

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /trunk
    from Rev 4 to Rev 5
    Reverse comparison

Rev 4 → Rev 5

BuyDropper/BuyDropper.xml
411,7 → 411,7
<Scripts>
<OnClick>
PlaySound("gsTitleOptionExit")
this:GetParent():Hide()
self:GetParent():Hide()
</OnClick>
</Scripts>
</Button>
424,10 → 424,10
BuyDropper:OptionsShow()
</OnShow>
<OnDragStart>
this:StartMoving()
self:StartMoving()
</OnDragStart>
<OnDragStop>
this:StopMovingOrSizing()
self:StopMovingOrSizing()
</OnDragStop>
</Scripts>
</Frame>
BuyDropper/BuyDropper.lua
8,97 → 8,97
BuyDropper = AceLibrary("AceAddon-2.0"):new("AceEvent-2.0", "AceHook-2.1", "AceConsole-2.0", "AceDB-2.0")
 
function BuyDropper:OnInitialize()
self:InitDB() -- Set up saved variables
self:InitConsole() -- Create slash commands
self:InitPopup() -- Create amount entry popup dialog
self:InitLabels() -- Create tracking labels in merchant window
self:InitDB() -- Set up saved variables
self:InitConsole() -- Create slash commands
self:InitPopup() -- Create amount entry popup dialog
self:InitLabels() -- Create tracking labels in merchant window
self:InitPurchaseQueue()-- Initialization for the purchase queue
self:UpdateDropper() -- Position the Merchant Dropper based on saved preferences
self:UpdateDropper() -- Position the Merchant Dropper based on saved preferences
end
 
 
 
 
function BuyDropper:InitDB()
self:RegisterDB("BuyDropperDB")
 
self:RegisterDefaults("char", {
profile = "char"
})
 
self:RegisterDefaults("profile", {
list = {},
vendor = {
enabled = true,
confirm = true,
self:RegisterDB("BuyDropperDB")
 
self:RegisterDefaults("char", {
profile = "char"
})
 
self:RegisterDefaults("profile", {
list = {},
vendor = {
enabled = true,
confirm = true,
budget = 0.50,
fallthrough = false
},
bank = true,
overstock = false,
dropper = {
enabled = true,
position = DROPPER_MAX_X,
label = true
},
})
},
bank = true,
overstock = false,
dropper = {
enabled = true,
position = DROPPER_MAX_X,
label = true
},
})
 
self:SetProfile(self.db.char.profile)
self:SetProfile(self.db.char.profile)
end
 
 
 
 
function BuyDropper:InitPopup()
StaticPopupDialogs["BUYDROPPER_ASK_AMOUNT"] = {
text = "Please enter the amount of this item would you like to keep in stock:",
button1 = ACCEPT,
button2 = CANCEL,
hasEditBox = 1,
maxLetters = 5,
timeout = 0,
OnAccept = function()
self:AcceptAmount(this:GetParent().data, tonumber(getglobal(this:GetParent():GetName().."EditBox"):GetText()))
end,
OnCancel = function()
end,
OnShow = function()
local name = this:GetName()
getglobal(name.."EditBox"):SetText("")
getglobal(name.."Button1"):Disable()
getglobal(name.."EditBox"):SetFocus()
end,
OnHide = function()
getglobal(this.data:GetName().."IconTexture"):SetTexture(nil)
this.data.link = nil
end,
EditBoxOnTextChanged = function()
local name = this:GetParent():GetName()
local button = getglobal(name.."Button1")
if tonumber(getglobal(name.."EditBox"):GetText()) then
button:Enable()
else
button:Disable()
end
end,
EditBoxOnEnterPressed = function()
if getglobal(this:GetParent():GetName().."Button1"):IsEnabled() then
self:AcceptAmount(this:GetParent().data, tonumber(getglobal(this:GetParent():GetName().."EditBox"):GetText()))
end
this:GetParent():Hide()
end,
}
StaticPopupDialogs["BUYDROPPER_ASK_AMOUNT"] = {
text = "Please enter the amount of this item would you like to keep in stock:",
button1 = ACCEPT,
button2 = CANCEL,
hasEditBox = 1,
maxLetters = 5,
timeout = 0,
OnAccept = function()
self:AcceptAmount(this:GetParent().data, tonumber(getglobal(this:GetParent():GetName().."EditBox"):GetText()))
end,
OnCancel = function()
end,
OnShow = function()
local name = this:GetName()
getglobal(name.."EditBox"):SetText("")
getglobal(name.."Button1"):Disable()
getglobal(name.."EditBox"):SetFocus()
end,
OnHide = function()
getglobal(this.data:GetName().."IconTexture"):SetTexture(nil)
this.data.link = nil
end,
EditBoxOnTextChanged = function()
local name = this:GetParent():GetName()
local button = getglobal(name.."Button1")
if tonumber(getglobal(name.."EditBox"):GetText()) then
button:Enable()
else
button:Disable()
end
end,
EditBoxOnEnterPressed = function()
if getglobal(this:GetParent():GetName().."Button1"):IsEnabled() then
self:AcceptAmount(this:GetParent().data, tonumber(getglobal(this:GetParent():GetName().."EditBox"):GetText()))
end
this:GetParent():Hide()
end,
}
 
StaticPopupDialogs["BUYDROPPER_CONFIRM_PURCHASE"] = {
text = "BuyDropper would like to buy items from this vendor totaling %s. Proceed?",
button1 = YES,
button2 = NO,
OnAccept = function()
StaticPopupDialogs["BUYDROPPER_CONFIRM_PURCHASE"] = {
text = "BuyDropper would like to buy items from this vendor totaling %s. Proceed?",
button1 = YES,
button2 = NO,
OnAccept = function()
self:ReleasePurchaseQueue()
end,
timeout = 0,
hideOnEscape = true,
}
timeout = 0,
hideOnEscape = true,
}
 
StaticPopupDialogs["BUYDROPPER_CONFIRM_CLEAR"] = {
text = "Are you sure you want to clear your BuyDropper tracking list?",
116,14 → 116,14
 
 
function BuyDropper:InitLabels()
local labels = {}
 
for i=1,10 do
labels[i] = CreateFrame("Button", nil, getglobal("MerchantItem"..i.."ItemButton"), "BuyDropperMerchantTracking")
labels[i]:SetPoint("TOPRIGHT", getglobal("MerchantItem"..i.."ItemButtonCount"), "BOTTOMRIGHT")
 
labels[i].Update = function(this)
local link = GetMerchantItemLink(this:GetParent():GetID())
local labels = {}
 
for i=1,10 do
labels[i] = CreateFrame("Button", nil, getglobal("MerchantItem"..i.."ItemButton"), "BuyDropperMerchantTracking")
labels[i]:SetPoint("TOPRIGHT", getglobal("MerchantItem"..i.."ItemButtonCount"), "BOTTOMRIGHT")
 
labels[i].Update = function(this)
local link = GetMerchantItemLink(this:GetParent():GetID())
local item = link and self:GetLinkItem(link)
if item and self.enabled then
this:SetText(item.amount)
131,35 → 131,35
else
this:Hide()
end
end
end
 
self.merchantLabels = labels
end
end
 
self.merchantLabels = labels
end
 
 
 
 
function BuyDropper:UpdateDropper()
local db = self.db.profile.dropper
local dropper = BuyDropperMerchantDropper
local label = BuyDropperMerchantDropperLabel
 
if db.enabled then
dropper:Show()
dropper:ClearAllPoints()
dropper:SetPoint("TOPLEFT", db.position, -36)
 
label:Anchor(db.position < label:GetWidth() + 70 and "RIGHT" or "LEFT")
 
if db.label then
label:Show()
else
label:Hide()
end
else
dropper:Hide()
end
local db = self.db.profile.dropper
local dropper = BuyDropperMerchantDropper
local label = BuyDropperMerchantDropperLabel
 
if db.enabled then
dropper:Show()
dropper:ClearAllPoints()
dropper:SetPoint("TOPLEFT", db.position, -36)
 
label:Anchor(db.position < label:GetWidth() + 70 and "RIGHT" or "LEFT")
 
if db.label then
label:Show()
else
label:Hide()
end
else
dropper:Hide()
end
end
 
 
185,7 → 185,7
self:ScanMerchant()
end)
self:RegisterEvent("MERCHANT_UPDATE", "ScanMerchant")
self:RegisterEvent("MERCHANT_CLOSED", "Cleanup")
self:RegisterEvent("MERCHANT_CLOSED", "Cleanup")
 
self.list = self.db.profile.list
self.idPriorityCache = {}
260,26 → 260,26
if not link or which ~= "item" then
return
end
 
this.link = link
local texture = select(10, GetItemInfo(link))
getglobal(this:GetName().."IconTexture"):SetTexture(texture)
 
ClearCursor()
 
local dialog = StaticPopup_Show("BUYDROPPER_ASK_AMOUNT")
dialog.data = this
 
this.link = link
local texture = select(10, GetItemInfo(link))
getglobal(this:GetName().."IconTexture"):SetTexture(texture)
 
ClearCursor()
 
local dialog = StaticPopup_Show("BUYDROPPER_ASK_AMOUNT")
dialog.data = this
end
 
 
 
 
function BuyDropper:AcceptAmount(button, amount)
if amount > 0 then
self:AddTrackingItem(button.link, amount)
else
self:RemoveTrackingItem(select(2, self:GetLinkItem(button.link)))
end
if amount > 0 then
self:AddTrackingItem(button.link, amount)
else
self:RemoveTrackingItem(select(2, self:GetLinkItem(button.link)))
end
end
 
 
BuyDropper/BuyDropperConsole.lua
39,7 → 39,7
func = function()
local message = "Currently Tracking:"
if #self.list == 0 then
message = message.."\n Nothing"
message = message.."\n Nothing"
end
for priority, item in ipairs(self.list) do
message = message..format("\n%4d: %s × %s", priority, self:MakeItemLink(item.id), item.amount)
BuyDropper/BuyDropperEngine.lua
272,23 → 272,23
 
 
function BuyDropper:DoPurchase(item, num)
local numLoops, purchAmount, leftover
local numLoops, purchAmount, leftover
local stack = select(8, GetItemInfo(item.id))
if item.preset > 1 then
numLoops = num
purchAmount = 1
leftover = 0
else
numLoops = floor(num/stack)
purchAmount = stack
leftover = num % stack
end
 
for i = 1, numLoops do
BuyMerchantItem(item.index, purchAmount)
end
 
if leftover > 0 then
if item.preset > 1 then
numLoops = num
purchAmount = 1
leftover = 0
else
numLoops = floor(num/stack)
purchAmount = stack
leftover = num % stack
end
 
for i = 1, numLoops do
BuyMerchantItem(item.index, purchAmount)
end
 
if leftover > 0 then
BuyMerchantItem(item.index, leftover)
end
end
BuyDropper/BuyDropperOptions.lua
10,31 → 10,31
BDOPTS_ITEM_HEIGHT = 56
 
local optionsChecks = {
Vendor = { label = "Buy from vendors", parent = "vendor", field = "enabled" },
Confirm = { label = "Confirm purchase", parent = "vendor", field = "confirm" },
Bank = { label = "Withdraw from bank", field = "bank"},
Overstock = { label = "Overstock", field = "overstock", tooltipText = "Buy more than your set amount if the item comes in preset stacks" },
 
Dropper = { label = "Enable Dropper", parent = "dropper", field = "enabled" },
Label = { label = "Show Label", parent = "dropper", field = "label" },
Vendor = { label = "Buy from vendors", parent = "vendor", field = "enabled" },
Confirm = { label = "Confirm purchase", parent = "vendor", field = "confirm" },
Bank = { label = "Withdraw from bank", field = "bank"},
Overstock = { label = "Overstock", field = "overstock", tooltipText = "Buy more than your set amount if the item comes in preset stacks" },
 
Dropper = { label = "Enable Dropper", parent = "dropper", field = "enabled" },
Label = { label = "Show Label", parent = "dropper", field = "label" },
}
 
function BuyDropper:OptionsLoad(this)
this:RegisterForDrag("LeftButton")
this:RegisterForDrag("LeftButton")
 
for which, options in pairs(optionsChecks) do
local button = getglobal("BuyDropper"..which.."Check")
local label = getglobal("BuyDropper"..which.."CheckText")
label:SetText(options.label)
button.tooltipText = options.tooltipText
button.db = { parent = options.parent, field = options.field }
end
 
BuyDropperPositionSliderHigh:SetText "Right"
BuyDropperPositionSliderLow:SetText "Left"
BuyDropperPositionSliderText:SetText "Position"
 
BuyDropperOptionsOperationsDropperLabel:SetText("Add an item")
for which, options in pairs(optionsChecks) do
local button = getglobal("BuyDropper"..which.."Check")
local label = getglobal("BuyDropper"..which.."CheckText")
label:SetText(options.label)
button.tooltipText = options.tooltipText
button.db = { parent = options.parent, field = options.field }
end
 
BuyDropperPositionSliderHigh:SetText "Right"
BuyDropperPositionSliderLow:SetText "Left"
BuyDropperPositionSliderText:SetText "Position"
 
BuyDropperOptionsOperationsDropperLabel:SetText("Add an item")
BuyDropperOptionsOperationsDropperLabel:Anchor("RIGHT")
 
--[[local items = {}
53,24 → 53,24
 
 
function BuyDropper:OptionBoxLoad(this, title)
this:SetBackdropBorderColor(0.4, 0.4, 0.4)
this:SetBackdropColor(0.15, 0.15, 0.15)
getglobal(this:GetName().."Title"):SetText(title)
this:SetBackdropBorderColor(0.4, 0.4, 0.4)
this:SetBackdropColor(0.15, 0.15, 0.15)
getglobal(this:GetName().."Title"):SetText(title)
end
 
 
 
 
function BuyDropper:OptionsShow()
PlaySound("igMainMenuOption")
 
local db = self.db.profile
for which, options in pairs(optionsChecks) do
local checked = options.parent and db[options.parent][options.field] or db[options.field]
getglobal("BuyDropper"..which.."Check"):SetChecked(checked)
end
 
self:UpdateEnabled()
PlaySound("igMainMenuOption")
 
local db = self.db.profile
for which, options in pairs(optionsChecks) do
local checked = options.parent and db[options.parent][options.field] or db[options.field]
getglobal("BuyDropper"..which.."Check"):SetChecked(checked)
end
 
self:UpdateEnabled()
self:UpdateTrackingList()
end
 
78,9 → 78,9
 
 
function BuyDropper:SetCheckData(this)
local db, checked = self.db.profile, this:GetChecked()
db = this.db.parent and db[this.db.parent] or db
db[this.db.field] = checked and true or false -- GetChecked returns nil or 1, but nils aren't saved
local db, checked = self.db.profile, this:GetChecked()
db = this.db.parent and db[this.db.parent] or db
db[this.db.field] = checked and true or false -- GetChecked returns nil or 1, but nils aren't saved
end
 
 
105,7 → 105,7
OptionsFrame_DisableCheckBox(BuyDropperOverstockCheck)
end
end
 
 
do
checked = profile.dropper.enabled
if checked then
123,10 → 123,10
 
 
function BuyDropper:PositionSliderValueChanged(this)
if self.db then -- ValueChanged can occur before variables are loaded
self.db.profile.dropper.position = this:GetValue()
self:UpdateDropper()
end
if self.db then -- ValueChanged can occur before variables are loaded
self.db.profile.dropper.position = this:GetValue()
self:UpdateDropper()
end
end
 
 
139,15 → 139,15
 
 
function BuyDropper:TrackingItemOnLoad(this)
local button = getglobal(this:GetName().."ItemButton")
 
button:SetScript("OnEnter", function(this)
local button = getglobal(this:GetName().."ItemButton")
 
button:SetScript("OnEnter", function(this)
GameTooltip:SetOwner(this, "ANCHOR_RIGHT")
GameTooltip:SetText("Click to change tracking amount", 1, 1, 1, true)
GameTooltip:Show()
end)
 
button:SetScript("OnLeave", function()
end)
 
button:SetScript("OnLeave", function()
GameTooltip:Hide()
end)
end)
end