extended shift-click name copy for the buy tab, generally implemented the buy tab functionality. It's working in principle! but still needs a lot of polish. Also did some refactoring

This commit is contained in:
Manuel Simon Hirsig
2015-09-09 02:17:52 +02:00
parent bbc7e8c260
commit 41e0eefe47
5 changed files with 161 additions and 101 deletions
+36 -26
View File
@@ -165,10 +165,18 @@ end
function Auctionator_ContainerFrameItemButton_OnClick(button)
if AuctionFrameBrowse:IsVisible() and IsShiftKeyDown() and not ChatFrameEditBox:IsVisible() and button == "LeftButton" then
if button == "LeftButton"
and IsShiftKeyDown()
and not ChatFrameEditBox:IsVisible()
and (PanelTemplates_GetSelectedTab(AuctionFrame) == 1 or PanelTemplates_GetSelectedTab(AuctionFrame) == Auctionator.tabs.buy.index)
then
local itemLink = GetContainerItemLink(this:GetParent():GetID(), this:GetID())
local itemName = string.gsub(itemLink, "^.-%[(.*)%].*", "%1")
BrowseName:SetText(itemName)
if PanelTemplates_GetSelectedTab(AuctionFrame) == 1 then
BrowseName:SetText(itemName)
elseif PanelTemplates_GetSelectedTab(AuctionFrame) == Auctionator.tabs.buy.index then
AuctionatorBuySearchBox:SetText(itemName)
end
else
Auctionator_Orig_ContainerFrameItemButton_OnClick(button)
@@ -513,17 +521,18 @@ function Auctionator_RefreshEntries()
local currentAuctionClass = ItemType2AuctionClass(sType)
local currentAuctionSubclass = nil -- SubType2AuctionSubclass(currentAuctionClass, sSubType)
Auctionator_Scan_Start(Auctionator_Scan_CreateQuery{
name = currentAuctionItemName,
exactMatch = true,
classIndex = currentAuctionClass,
subclassIndex = currentAuctionSubclass,
onComplete = function(data)
processScanResults(data, currentAuctionItemName)
Auctionator_SelectAuctionatorEntry()
Auctionator_UpdateRecommendation()
end
})
Auctionator_Scan_Start{
query = Auctionator_Scan_CreateQuery{
name = currentAuctionItemName,
classIndex = currentAuctionClass,
subclassIndex = currentAuctionSubclass
},
onComplete = function(data)
processScanResults(data, currentAuctionItemName)
Auctionator_SelectAuctionatorEntry()
Auctionator_UpdateRecommendation()
end
}
end
-----------------------------------------
@@ -642,19 +651,20 @@ function processScanResults(rawData, auctionItemName)
local condData = {}
for _,rawDatum in ipairs(rawData) do
local key = "_"..rawDatum.stackSize.."_"..rawDatum.buyoutPrice
if condData[key] then
condData[key].count = condData[key].count + 1
else
condData[key] = {
stackSize = rawDatum.stackSize,
buyoutPrice = rawDatum.buyoutPrice,
itemPrice = rawDatum.buyoutPrice / rawDatum.stackSize,
count = 1,
numYours = rawDatum.owner == UnitName("player") and 1 or 0
}
if auctionItemName == rawDatum.name and rawDatum.buyoutPrice > 0 then
local key = "_"..rawDatum.stackSize.."_"..rawDatum.buyoutPrice
if condData[key] then
condData[key].count = condData[key].count + 1
else
condData[key] = {
stackSize = rawDatum.stackSize,
buyoutPrice = rawDatum.buyoutPrice,
itemPrice = rawDatum.buyoutPrice / rawDatum.stackSize,
count = 1,
numYours = rawDatum.owner == UnitName("player") and 1 or 0
}
end
end
end
+78 -42
View File
@@ -1,61 +1,97 @@
local processScanResults
local processedData
local entries
local selectedEntries = {}
local searchQuery
function AuctionatorBuySearchButton_OnClick()
Auctionator_Scan_Start(Auctionator_Scan_CreateQuery{
searchQuery = Auctionator_Scan_CreateQuery{
name = AuctionatorBuySearchBox:GetText(),
exactMatch = true,
onComplete = function(data)
processScanResults(data)
Auctionator_Buy_ScrollbarUpdate()
exactMatch = true
}
Auctionator_Scan_Start{
query = searchQuery,
onComplete = function(data)
processScanResults(data)
Auctionator_Buy_ScrollbarUpdate()
end
}
end
-----------------------------------------
function condensedSelection()
local selection = {}
for entry,_ in pairs(selectedEntries) do
local key = "_"..entry.stackSize.."_"..entry.buyoutPrice
if selection[key] then
selection[key] = selection[key] + 1
else
selection[key] = 1
end
})
end
return selection;
end
-----------------------------------------
function AuctionatorBuyBuySelectedButton_OnClick()
local selection = condensedSelection(selectedEntries)
Auctionator_Scan_Start{
query = searchQuery,
onReadDatum = function(datum)
local key = "_"..datum.stackSize.."_"..datum.buyoutPrice
if selection[key] then
-- Auctionator_Log("match: "..key)
PlaceAuctionBid("list", datum.pageIndex, datum.buyoutPrice)
if selection[key] > 1 then
selection[key] = selection[key] - 1
else
selection[key] = nil
end
end
end
}
end
-----------------------------------------
function AuctionatorBuyEntry_OnClick()
local entryIndex = this:GetID()
local entry = entries[entryIndex]
if Auctionator_SetContains(selectedEntries, entry) then
Auctionator_RemoveFromSet(selectedEntries, entry)
else
Auctionator_AddToSet(selectedEntries, entry)
end
Auctionator_Buy_ScrollbarUpdate()
PlaySound("igMainMenuOptionCheckBoxOn")
end
-----------------------------------------
function processScanResults(rawData)
processedData = {}
----- Condense the scan rawData into a table that has only a single entry per stacksize/price combo
local condData = {}
entries = {}
for _,rawDatum in ipairs(rawData) do
local key = "_"..rawDatum.stackSize.."_"..rawDatum.buyoutPrice
if condData[key] then
condData[key].count = condData[key].count + 1
else
condData[key] = {
if rawDatum.buyoutPrice > 0 then
tinsert(entries, {
stackSize = rawDatum.stackSize,
buyoutPrice = rawDatum.buyoutPrice,
itemPrice = rawDatum.buyoutPrice / rawDatum.stackSize,
count = 1,
numYours = rawDatum.owner == UnitName("player") and 1 or 0
}
})
end
end
----- create a table of these entries sorted by itemPrice
local n = 1
for _,condDatum in pairs(condData) do
processedData[n] = condDatum
n = n + 1
end
table.sort(processedData, function(a,b) return a.itemPrice < b.itemPrice end)
table.sort(entries, function(a,b) return a.itemPrice < b.itemPrice end)
end
-----------------------------------------
@@ -66,10 +102,10 @@ function Auctionator_Buy_ScrollbarUpdate()
local dataOffset -- an index into our data calculated from the scroll offset
local numrows
if not processedData then
if not entries then
numrows = 0
else
numrows = getn(processedData)
numrows = getn(entries)
end
FauxScrollFrame_Update(AuctionatorBuyScrollFrame, numrows, 12, 16);
@@ -87,35 +123,35 @@ function Auctionator_Buy_ScrollbarUpdate()
lineEntry:SetID(dataOffset)
if dataOffset <= numrows and processedData[dataOffset] then
if dataOffset <= numrows and entries[dataOffset] then
local auctionatorEntry = processedData[dataOffset]
local entry = entries[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
if Auctionator_SetContains(selectedEntries, entry) then
lineEntry:LockHighlight()
else
lineEntry:UnlockHighlight()
end
if auctionatorEntry.numYours == 0 then
if entry.numYours == 0 then
lineEntry_comm:SetText("")
elseif
auctionatorEntry.numYours == auctionatorEntry.count then
entry.numYours == entry.count then
lineEntry_comm:SetText("yours")
else
lineEntry_comm:SetText("yours: "..auctionatorEntry.numYours)
lineEntry_comm:SetText("yours: "..entry.numYours)
end
local tx = string.format("%i %s of %i", auctionatorEntry.count, Auctionator_PluralizeIf("stack", auctionatorEntry.count), auctionatorEntry.stackSize)
local tx = string.format("%i %s of %i", entry.count, Auctionator_PluralizeIf("stack", entry.count), entry.stackSize)
MoneyFrame_Update("AuctionatorBuyEntry"..line.."_PerItem_Price", Auctionator_Round(auctionatorEntry.buyoutPrice/auctionatorEntry.stackSize))
MoneyFrame_Update("AuctionatorBuyEntry"..line.."_PerItem_Price", Auctionator_Round(entry.buyoutPrice/entry.stackSize))
lineEntry_avail:SetText(tx)
lineEntry_stack:SetText(Auctionator_PriceToString(auctionatorEntry.buyoutPrice))
lineEntry_stack:SetText(Auctionator_PriceToString(entry.buyoutPrice))
lineEntry:Show()
else
+3 -3
View File
@@ -110,15 +110,15 @@
</Scripts>
</Button>
<!-- <Button name="AuctionatorBuyRefreshButton" inherits="UIPanelButtonTemplate" text="Refresh">
<Button name="AuctionatorBuyBuySelectedButton" inherits="UIPanelButtonTemplate" text="Buy Selected">
<Size><AbsDimension x="126" y="22"/> </Size>
<Anchors><Anchor point="RIGHT"><Offset><AbsDimension x="-14" y="-199"/></Offset></Anchor></Anchors>
<Scripts>
<OnClick>
AuctionatorBuyRefreshButton_OnClick()
AuctionatorBuyBuySelectedButton_OnClick()
</OnClick>
</Scripts>
</Button> -->
</Button>
<ScrollFrame name="AuctionatorBuyScrollFrame" inherits="FauxScrollFrameTemplate">
<Size><AbsDimension x="588" y="194"/></Size>
+14
View File
@@ -74,6 +74,20 @@ end
-----------------------------------------
function Auctionator_AddToSet(set, key)
set[key] = true
end
function Auctionator_RemoveFromSet(set, key)
set[key] = nil
end
function Auctionator_SetContains(set, key)
return set[key] ~= nil
end
-----------------------------------------
function Auctionator_OnLoad()
Auctionator_Log("Auctionator Loaded")
AuctionatorLoaded = true
+30 -30
View File
@@ -4,7 +4,7 @@ local STATE_POSTQUERY = 2
local NUM_AUCTION_ITEMS_PER_PAGE = 50
local currentQuery
local currentJob
local currentPage
local state = STATE_IDLE
@@ -23,27 +23,28 @@ end
-----------------------------------------
function Auctionator_Scan_Complete()
if currentQuery.onComplete then
currentQuery.onComplete(scanData)
function Auctionator_Scan_Complete()
if state ~= STATE_IDLE then
if currentJob.onComplete then
currentJob.onComplete(scanData)
end
currentJob = nil
currentPage = nil
scanData = nil
state = STATE_IDLE
end
currentQuery = nil
currentPage = nil
scanData = nil
state = STATE_IDLE
end
-----------------------------------------
function Auctionator_Scan_Abort()
if currentQuery and currentQuery.onAbort then
currentQuery.onAbort()
if currentJob and currentJob.onAbort then
currentJob.onAbort()
end
currentQuery = nil
currentJob = nil
currentPage = nil
scanData = nil
state = STATE_IDLE
@@ -51,7 +52,7 @@ end
-----------------------------------------
function Auctionator_Scan_Start(query)
function Auctionator_Scan_Start(job)
Auctionator_SetMessage("Scanning auctions ...")
@@ -59,7 +60,7 @@ function Auctionator_Scan_Start(query)
Auctionator_Scan_Abort()
end
currentQuery = query
currentJob = job
currentPage = 0
scanData = {}
state = STATE_PREQUERY
@@ -70,7 +71,6 @@ end
function Auctionator_Scan_CreateQuery(parameterMap)
local query = {
name = nil,
exactMatch = false,
minLevel = "",
maxLevel = "",
invTypeIndex = nil,
@@ -91,15 +91,15 @@ end
function submitQuery()
QueryAuctionItems(
currentQuery.name,
currentQuery.minLevel,
currentQuery.maxLevel,
currentQuery.invTypeIndex,
currentQuery.classIndex,
currentQuery.subclassIndex,
currentJob.query.name,
currentJob.query.minLevel,
currentJob.query.maxLevel,
currentJob.query.invTypeIndex,
currentJob.query.classIndex,
currentJob.query.subclassIndex,
currentPage,
currentQuery.isUsable,
currentQuery.qualityIndex
currentJob.query.isUsable,
currentJob.query.qualityIndex
)
state = STATE_POSTQUERY
currentPage = currentPage + 1
@@ -138,14 +138,14 @@ function processQueryResults()
bidAmount = bidAmount,
highBidder = highBidder,
owner = owner,
duration = duration
duration = duration,
page = currentPage,
pageIndex = i
}
if not currentQuery.exactMatch or (currentQuery.name == scanDatum.name and scanDatum.buyoutPrice > 0) then -- TODO separate option for buyout price
tinsert(scanData, scanDatum)
if currentQuery.onReadDatum then
currentQuery.onReadDatum(scanDatum)
end
tinsert(scanData, scanDatum)
if currentJob.onReadDatum then
currentJob.onReadDatum(scanDatum)
end
end