refactoring and some work on the buy tab backend

This commit is contained in:
Manuel Simon Hirsig
2015-09-08 22:11:48 +02:00
parent 21ab9ac4a7
commit 0217ac7088
9 changed files with 189 additions and 79 deletions
+15 -37
View File
@@ -1,5 +1,3 @@
local AuctionatorLoaded = false
local recommendationElements = {}
local defaultAuctionTabElements = {}
local defaultBrowseTabElements = {}
@@ -42,14 +40,13 @@ local lastItemPosted = nil
-----------------------------------------
local processScanResults, relevel, log, pluralizeIf, round, undercut, roundPriceDown
local processScanResults, relevel, Auctionator_Log, pluralizeIf, round, undercut, roundPriceDown
local val2gsc, priceToString, ItemType2AuctionClass, SubType2AuctionSubclass
-----------------------------------------
function Auctionator_EventHandler()
if event == "VARIABLES_LOADED" then Auctionator_OnLoad() end
if event == "ADDON_LOADED" then Auctionator_OnAddonLoaded() end
if event == "AUCTION_OWNED_LIST_UPDATE" then Auctionator_OnAuctionOwnedUpdate() end
if event == "AUCTION_HOUSE_SHOW" then Auctionator_OnAuctionHouseShow() end
@@ -59,16 +56,6 @@ end
-----------------------------------------
function Auctionator_OnLoad()
log("Auctionator Loaded")
AuctionatorLoaded = true
end
-----------------------------------------
function Auctionator_AddPanels()
local sellFrame = CreateFrame("Frame", "Auctionator_Sell_Panel", AuctionFrame, "Auctionator_Sell_Template")
@@ -88,7 +75,6 @@ function Auctionator_AddPanels()
optionsFrame:SetPoint("TOPLEFT", "AuctionFrame", "TOPLEFT", 210, 0)
relevel(optionsFrame)
optionsFrame:Hide()
end
-----------------------------------------
@@ -323,22 +309,22 @@ function Auctionator_AddTabs()
Auctionator.tabs.sell.index = AuctionFrame.numTabs + 1
Auctionator.tabs.buy.index = AuctionFrame.numTabs + 2
local sellFrameName = "AuctionFrameTab"..Auctionator.tabs.sell.index
local buyFrameName = "AuctionFrameTab"..Auctionator.tabs.buy.index
local sellTabName = "AuctionFrameTab"..Auctionator.tabs.sell.index
local buyTabName = "AuctionFrameTab"..Auctionator.tabs.buy.index
local sellFrame = CreateFrame("Button", sellFrameName, AuctionFrame, "AuctionTabTemplate")
local buyFrame = CreateFrame("Button", buyFrameName, AuctionFrame, "AuctionTabTemplate")
local sellTab = CreateFrame("Button", sellTabName, AuctionFrame, "AuctionTabTemplate")
local buyTab = CreateFrame("Button", buyTabName, AuctionFrame, "AuctionTabTemplate")
setglobal(sellFrameName, sellFrame)
setglobal(buyFrameName, buyFrame)
setglobal(sellTabName, sellTab)
setglobal(buyTabName, buyTab)
sellFrame:SetID(Auctionator.tabs.sell.index)
sellFrame:SetText("Auctionator")
sellFrame:SetPoint("LEFT", getglobal("AuctionFrameTab"..AuctionFrame.numTabs), "RIGHT", -8, 0)
sellTab:SetID(Auctionator.tabs.sell.index)
sellTab:SetText("Auctionator")
sellTab:SetPoint("LEFT", getglobal("AuctionFrameTab"..AuctionFrame.numTabs), "RIGHT", -8, 0)
buyFrame:SetID(Auctionator.tabs.buy.index)
buyFrame:SetText("Buy")
-- buyFrame:SetPoint("LEFT", getglobal("AuctionFrameTab"..Auctionator.tabs.sell.index), "RIGHT", -8, 0)
buyTab:SetID(Auctionator.tabs.buy.index)
buyTab:SetText("Buy")
-- buyTab:SetPoint("LEFT", getglobal("AuctionFrameTab"..Auctionator.tabs.sell.index), "RIGHT", -8, 0)
PanelTemplates_SetNumTabs(AuctionFrame, Auctionator.tabs.buy.index)
PanelTemplates_EnableTab(AuctionFrame, Auctionator.tabs.sell.index)
@@ -568,7 +554,7 @@ function Auctionator_ScrollbarUpdate()
lineEntry:SetID(dataOffset)
if currentAuctionItemName and dataOffset <= numrows and auctionatorEntries[currentAuctionItemName][dataOffset] then
if currentAuctionItemName and dataOffset <= numrows and auctionatorEntries[currentAuctionItemName] then
local auctionatorEntry = auctionatorEntries[currentAuctionItemName][dataOffset]
@@ -711,14 +697,6 @@ end
-----------------------------------------
function log(msg)
if DEFAULT_CHAT_FRAME then
DEFAULT_CHAT_FRAME:AddMessage(msg)
end
end
-----------------------------------------
function undercut(price)
return math.max(0, price - 1)
end
@@ -781,7 +759,7 @@ function ItemType2AuctionClass(itemType)
end
end
end
else log("Can't GetAuctionItemClasses") end
else Auctionator_Log("Can't GetAuctionItemClasses") end
end
-----------------------------------------
+2 -1
View File
@@ -3,7 +3,8 @@
## Notes: A lightweight addon designed to help manage auctions
## SavedVariablesPerCharacter: AUCTIONATOR_ENABLE_ALT, AUCTIONATOR_OPEN_FIRST, AUCTIONATOR_INSTANT_BUYOUT
## SavedVariables: auctionatorEntries
Scan.lua
Core.xml
Scan.xml
Auctionator.xml
Buy.xml
Options.xml
+1 -1
View File
@@ -3,7 +3,7 @@
<Script file="Auctionator.lua"/>
<!-- Frame to handle all core events -->
<Frame name="Auctionator_Core">
<Frame>
<Scripts>
<OnLoad>
this:RegisterEvent("VARIABLES_LOADED")
+76 -4
View File
@@ -1,4 +1,4 @@
local processScanResults
local processScanResults, scrollbarUpdate
local processedData;
function AuctionatorBuySearchButton_OnClick()
@@ -7,14 +7,15 @@ function AuctionatorBuySearchButton_OnClick()
name = AuctionatorBuySearchBox:GetText(),
exactMatch = true,
onComplete = function(data)
table.sort(data, function(a,b) return a.buyoutPrice < b.buyoutPrice end)
scanData = data
processScanResults(data)
scrollbarUpdate()
Auctionator_Log("done"..getn(data))
end
})
end
function processScanResults(rawData, auctionItemName)
function processScanResults(rawData)
processedData = {}
@@ -50,6 +51,77 @@ function processScanResults(rawData, auctionItemName)
table.sort(processedData, function(a,b) return a.itemPrice < b.itemPrice end)
end
function scrollbarUpdate()
local line -- 1 through 15 of our window to scroll
local dataOffset -- an index into our data calculated from the scroll offset
local numrows
if not currentAuctionItemName or not auctionatorEntries[currentAuctionItemName] then
numrows = 0
else
numrows = getn(auctionatorEntries[currentAuctionItemName])
end
FauxScrollFrame_Update(AuctionatorScrollFrame, numrows, 12, 16);
for line = 1,15 do
dataOffset = line + FauxScrollFrame_GetOffset(AuctionatorScrollFrame)
log(line)
local lineEntry = getglobal("AuctionatorBuyEntry"..line)
if numrows <= 15 then
lineEntry:SetWidth(603)
else
lineEntry:SetWidth(585)
end
lineEntry:SetID(dataOffset)
if currentAuctionItemName and dataOffset <= numrows and auctionatorEntries[currentAuctionItemName][dataOffset] then
local auctionatorEntry = auctionatorEntries[currentAuctionItemName][dataOffset]
local lineEntry_avail = getglobal("AuctionatorBuyEntry"..line.."_Availability")
local lineEntry_comm = getglobal("AuctionatorBuyEntry"..line.."_Comment")
local lineEntry_stack = getglobal("AuctionatorBuyEntry"..line.."_StackPrice")
if selectedAuctionatorEntry and auctionatorEntry.itemPrice == selectedAuctionatorEntry.itemPrice and auctionatorEntry.stackSize == selectedAuctionatorEntry.stackSize then
lineEntry:LockHighlight()
else
lineEntry:UnlockHighlight()
end
if auctionatorEntry.stackSize == currentAuctionItemStackSize then
lineEntry_avail:SetTextColor(0.2, 0.9, 0.2)
else
lineEntry_avail:SetTextColor(1.0, 1.0, 1.0)
end
if auctionatorEntry.numYours == 0 then
lineEntry_comm:SetText("")
elseif
auctionatorEntry.numYours == auctionatorEntry.count then
lineEntry_comm:SetText("yours")
else
lineEntry_comm:SetText("yours: "..auctionatorEntry.numYours)
end
local tx = string.format("%i %s of %i", auctionatorEntry.count, pluralizeIf("stack", auctionatorEntry.count), auctionatorEntry.stackSize)
MoneyFrame_Update("AuctionatorBuyEntry"..line.."_PerItem_Price", round(auctionatorEntry.buyoutPrice/auctionatorEntry.stackSize))
lineEntry_avail:SetText(tx)
lineEntry_stack:SetText(priceToString(auctionatorEntry.buyoutPrice))
lineEntry:Show()
else
lineEntry:Hide()
end
end
end
-----------------------------------------
-- These functions were meant to be used for a search sorted by buyout price but that actually seems impossible to implement nicely with the vanilla interface
+22 -25
View File
@@ -21,34 +21,31 @@
<Anchors><Anchor point="TOP"><Offset><AbsDimension x="-100" y="-18"/></Offset></Anchor></Anchors>
</FontString>
<FontString name="Auctionator_Buy_SearchBox_Label" inherits="GameFontNormalSmall" text="Search For">
<FontString name="AuctionatorBuySearchBoxLabel" inherits="GameFontNormalSmall" text="Search For">
<Anchors><Anchor point="TOPLEFT"><Offset><AbsDimension x="40" y="-50"/></Offset></Anchor></Anchors>
</FontString>
</Layer>
</Layers>
<Frames>
<EditBox name="AuctionatorBuySearchBox" autoFocus="false" inherits="InputBoxTemplate">
<Size><AbsDimension x="240" y="20"/></Size>
<Anchors><Anchor point="TOPLEFT" relativeTo="Auctionator_Buy_SearchBox_Label" relativePoint="BOTTOMLEFT"><Offset><AbsDimension x="2" y="-4"/></Offset></Anchor></Anchors>
<Anchors><Anchor point="TOPLEFT" relativeTo="AuctionatorBuySearchBoxLabel" relativePoint="BOTTOMLEFT"><Offset><AbsDimension x="2" y="-4"/></Offset></Anchor></Anchors>
</EditBox>
<Button name="AuctionatorBuySearchButton" inherits="UIPanelButtonTemplate" text="Search">
<Size><AbsDimension x="80" y="22"/></Size>
<Anchors><Anchor point="RIGHT" relativeTo="Auctionator_Buy_SearchBox" relativePoint="RIGHT"><Offset><AbsDimension x="90" y="3" /></Offset></Anchor></Anchors>
<Anchors><Anchor point="RIGHT" relativeTo="AuctionatorBuySearchBox" relativePoint="RIGHT"><Offset><AbsDimension x="90" y="3" /></Offset></Anchor></Anchors>
<Scripts>
<OnClick>
AuctionatorBuySearchButton_Onclick()
AuctionatorBuySearchButton_OnClick()
</OnClick>
</Scripts>
</Button>
<Button name="Auctionator_Buy_RefreshButton" inherits="UIPanelButtonTemplate" text="Refresh">
<Button name="AuctionatorBuyRefreshButton" inherits="UIPanelButtonTemplate" text="Refresh">
<Size><AbsDimension x="126" y="22"/> </Size>
<Anchors><Anchor point="RIGHT"><Offset><AbsDimension x="-14" y="-199"/></Offset></Anchor></Anchors>
<Scripts>
@@ -58,7 +55,7 @@
</Scripts>
</Button>
<ScrollFrame name="Auctionator_Buy_ScrollFrame" inherits="FauxScrollFrameTemplate">
<ScrollFrame name="AuctionatorBuyScrollFrame" inherits="FauxScrollFrameTemplate">
<Size><AbsDimension x="588" y="194"/></Size>
<Anchors><Anchor point="TOPLEFT"><Offset><AbsDimension x="0" y="-213"/></Offset></Anchor></Anchors>
@@ -72,23 +69,23 @@
</Scripts>
</ScrollFrame>
<Button name="Auctionator_Buy_Entry1" inherits="AuctionatorEntryTemplate">
<Anchors><Anchor point="TOPLEFT" relativeTo="Auctionator_Buy_ScrollFrame" relativePoint="TOPLEFT"><Offset><AbsDimension x="8" y="0"/></Offset></Anchor></Anchors>
<Button name="AuctionatorBuyEntry1" inherits="AuctionatorEntryTemplate">
<Anchors><Anchor point="TOPLEFT" relativeTo="AuctionatorBuyScrollFrame" relativePoint="TOPLEFT"><Offset><AbsDimension x="8" y="0"/></Offset></Anchor></Anchors>
</Button>
<Button name="Auctionator_Buy_Entry2" inherits="AuctionatorEntryTemplate"><Anchors><Anchor point="TOPLEFT" relativeTo="Auctionator_Buy_Entry1" relativePoint="BOTTOMLEFT"/></Anchors></Button>
<Button name="Auctionator_Buy_Entry3" inherits="AuctionatorEntryTemplate"><Anchors><Anchor point="TOPLEFT" relativeTo="Auctionator_Buy_Entry2" relativePoint="BOTTOMLEFT"/></Anchors></Button>
<Button name="Auctionator_Buy_Entry4" inherits="AuctionatorEntryTemplate"><Anchors><Anchor point="TOPLEFT" relativeTo="Auctionator_Buy_Entry3" relativePoint="BOTTOMLEFT"/></Anchors></Button>
<Button name="Auctionator_Buy_Entry5" inherits="AuctionatorEntryTemplate"><Anchors><Anchor point="TOPLEFT" relativeTo="Auctionator_Buy_Entry4" relativePoint="BOTTOMLEFT"/></Anchors></Button>
<Button name="Auctionator_Buy_Entry6" inherits="AuctionatorEntryTemplate"><Anchors><Anchor point="TOPLEFT" relativeTo="Auctionator_Buy_Entry5" relativePoint="BOTTOMLEFT"/></Anchors></Button>
<Button name="Auctionator_Buy_Entry7" inherits="AuctionatorEntryTemplate"><Anchors><Anchor point="TOPLEFT" relativeTo="Auctionator_Buy_Entry6" relativePoint="BOTTOMLEFT"/></Anchors></Button>
<Button name="Auctionator_Buy_Entry8" inherits="AuctionatorEntryTemplate"><Anchors><Anchor point="TOPLEFT" relativeTo="Auctionator_Buy_Entry7" relativePoint="BOTTOMLEFT"/></Anchors></Button>
<Button name="Auctionator_Buy_Entry9" inherits="AuctionatorEntryTemplate"><Anchors><Anchor point="TOPLEFT" relativeTo="Auctionator_Buy_Entry8" relativePoint="BOTTOMLEFT"/></Anchors></Button>
<Button name="Auctionator_Buy_Entry10" inherits="AuctionatorEntryTemplate"><Anchors><Anchor point="TOPLEFT" relativeTo="Auctionator_Buy_Entry9" relativePoint="BOTTOMLEFT"/></Anchors></Button>
<Button name="Auctionator_Buy_Entry11" inherits="AuctionatorEntryTemplate"><Anchors><Anchor point="TOPLEFT" relativeTo="Auctionator_Buy_Entry10" relativePoint="BOTTOMLEFT"/></Anchors></Button>
<Button name="Auctionator_Buy_Entry12" inherits="AuctionatorEntryTemplate"><Anchors><Anchor point="TOPLEFT" relativeTo="Auctionator_Buy_Entry11" relativePoint="BOTTOMLEFT"/></Anchors></Button>
<Button name="Auctionator_Buy_Entry13" inherits="AuctionatorEntryTemplate"><Anchors><Anchor point="TOPLEFT" relativeTo="Auctionator_Buy_Entry12" relativePoint="BOTTOMLEFT"/></Anchors></Button>
<Button name="Auctionator_Buy_Entry14" inherits="AuctionatorEntryTemplate"><Anchors><Anchor point="TOPLEFT" relativeTo="Auctionator_Buy_Entry13" relativePoint="BOTTOMLEFT"/></Anchors></Button>
<Button name="Auctionator_Buy_Entry15" inherits="AuctionatorEntryTemplate"><Anchors><Anchor point="TOPLEFT" relativeTo="Auctionator_Buy_Entry14" relativePoint="BOTTOMLEFT"/></Anchors></Button>
<Button name="AuctionatorBuyEntry2" inherits="AuctionatorEntryTemplate"><Anchors><Anchor point="TOPLEFT" relativeTo="Auctionator_Buy_Entry1" relativePoint="BOTTOMLEFT"/></Anchors></Button>
<Button name="AuctionatorBuyEntry3" inherits="AuctionatorEntryTemplate"><Anchors><Anchor point="TOPLEFT" relativeTo="Auctionator_Buy_Entry2" relativePoint="BOTTOMLEFT"/></Anchors></Button>
<Button name="AuctionatorBuyEntry4" inherits="AuctionatorEntryTemplate"><Anchors><Anchor point="TOPLEFT" relativeTo="Auctionator_Buy_Entry3" relativePoint="BOTTOMLEFT"/></Anchors></Button>
<Button name="AuctionatorBuyEntry5" inherits="AuctionatorEntryTemplate"><Anchors><Anchor point="TOPLEFT" relativeTo="Auctionator_Buy_Entry4" relativePoint="BOTTOMLEFT"/></Anchors></Button>
<Button name="AuctionatorBuyEntry6" inherits="AuctionatorEntryTemplate"><Anchors><Anchor point="TOPLEFT" relativeTo="Auctionator_Buy_Entry5" relativePoint="BOTTOMLEFT"/></Anchors></Button>
<Button name="AuctionatorBuyEntry7" inherits="AuctionatorEntryTemplate"><Anchors><Anchor point="TOPLEFT" relativeTo="Auctionator_Buy_Entry6" relativePoint="BOTTOMLEFT"/></Anchors></Button>
<Button name="AuctionatorBuyEntry8" inherits="AuctionatorEntryTemplate"><Anchors><Anchor point="TOPLEFT" relativeTo="Auctionator_Buy_Entry7" relativePoint="BOTTOMLEFT"/></Anchors></Button>
<Button name="AuctionatorBuyEntry9" inherits="AuctionatorEntryTemplate"><Anchors><Anchor point="TOPLEFT" relativeTo="Auctionator_Buy_Entry8" relativePoint="BOTTOMLEFT"/></Anchors></Button>
<Button name="AuctionatorBuyEntry10" inherits="AuctionatorEntryTemplate"><Anchors><Anchor point="TOPLEFT" relativeTo="Auctionator_Buy_Entry9" relativePoint="BOTTOMLEFT"/></Anchors></Button>
<Button name="AuctionatorBuyEntry11" inherits="AuctionatorEntryTemplate"><Anchors><Anchor point="TOPLEFT" relativeTo="Auctionator_Buy_Entry10" relativePoint="BOTTOMLEFT"/></Anchors></Button>
<Button name="AuctionatorBuyEntry12" inherits="AuctionatorEntryTemplate"><Anchors><Anchor point="TOPLEFT" relativeTo="Auctionator_Buy_Entry11" relativePoint="BOTTOMLEFT"/></Anchors></Button>
<Button name="AuctionatorBuyEntry13" inherits="AuctionatorEntryTemplate"><Anchors><Anchor point="TOPLEFT" relativeTo="Auctionator_Buy_Entry12" relativePoint="BOTTOMLEFT"/></Anchors></Button>
<Button name="AuctionatorBuyEntry14" inherits="AuctionatorEntryTemplate"><Anchors><Anchor point="TOPLEFT" relativeTo="Auctionator_Buy_Entry13" relativePoint="BOTTOMLEFT"/></Anchors></Button>
<Button name="AuctionatorBuyEntry15" inherits="AuctionatorEntryTemplate"><Anchors><Anchor point="TOPLEFT" relativeTo="Auctionator_Buy_Entry14" relativePoint="BOTTOMLEFT"/></Anchors></Button>
</Frames>
</Frame>
</Ui>
+24
View File
@@ -0,0 +1,24 @@
AuctionatorLoaded = false
-----------------------------------------
function Auctionator_Log(msg)
if DEFAULT_CHAT_FRAME then
DEFAULT_CHAT_FRAME:AddMessage(msg)
end
end
-----------------------------------------
function Auctionator_OnLoad()
Auctionator_Log("Auctionator Loaded")
AuctionatorLoaded = true
end
-----------------------------------------
function Auctionator_Core_OnEvent()
if event == "VARIABLES_LOADED" then
Auctionator_OnLoad()
end
end
+16
View File
@@ -0,0 +1,16 @@
<Ui xsi:schemaLocation="http://www.blizzard.com/wow/ui/">
<Script file="Core.lua"/>
<!-- Frame to handle all core events -->
<Frame>
<Scripts>
<OnLoad>
this:RegisterEvent("VARIABLES_LOADED")
</OnLoad>
<OnEvent>
Auctionator_Core_OnEvent()
</OnEvent>
</Scripts>
</Frame>
</Ui>
+14 -11
View File
@@ -26,7 +26,7 @@ end
function Auctionator_Scan_Complete()
if currentQuery.onComplete then
currentQuery.onComplete(scanData);
currentQuery.onComplete(scanData)
end
currentQuery = nil
@@ -40,7 +40,7 @@ end
function Auctionator_Scan_Abort()
if currentQuery and currentQuery.onAbort then
currentQuery.onAbort();
currentQuery.onAbort()
end
currentQuery = nil
@@ -158,8 +158,17 @@ end
-----------------------------------------
local eventFrame = CreateFrame("Frame")
eventFrame:SetScript("OnUpdate", function()
function Auctionator_Scan_OnEvent()
if event == "AUCTION_ITEM_LIST_UPDATE" then
if state == STATE_POSTQUERY then
processQueryResults()
end
end
end
-----------------------------------------
function Auctionator_Scan_OnUpdate()
if state == STATE_PREQUERY and GetTime() - timeOfLastUpdate > 0.5 then
timeOfLastUpdate = GetTime()
@@ -168,10 +177,4 @@ eventFrame:SetScript("OnUpdate", function()
submitQuery()
end
end
end)
eventFrame:RegisterEvent("AUCTION_ITEM_LIST_UPDATE")
eventFrame:SetScript("OnEvent", function(event)
if state == STATE_POSTQUERY then
processQueryResults()
end
end)
end
+19
View File
@@ -0,0 +1,19 @@
<Ui xsi:schemaLocation="http://www.blizzard.com/wow/ui/">
<Script file="Scan.lua"/>
<!-- Frame to handle all core events -->
<Frame>
<Scripts>
<OnLoad>
this:RegisterEvent("AUCTION_ITEM_LIST_UPDATE")
</OnLoad>
<OnEvent>
Auctionator_Scan_OnEvent()
</OnEvent>
<OnUpdate>
Auctionator_Scan_OnUpdate()
</OnUpdate>
</Scripts>
</Frame>
</Ui>