working on improving the sell tab backend

This commit is contained in:
Manuel Simon Hirsig
2015-10-04 13:43:36 +02:00
parent 89f3a6737f
commit a74e9387a0
3 changed files with 123 additions and 98 deletions
+15 -9
View File
@@ -14,7 +14,8 @@ Aux = {
buy = { buy = {
index = 5 index = 5
} }
} },
last_picked_up = {},
} }
----------------------------------------- -----------------------------------------
@@ -53,6 +54,8 @@ function Aux_OnAddonLoaded()
Aux_SetupHookFunctions() Aux_SetupHookFunctions()
Aux.tabs.sell.hiddenElements = { Aux.tabs.sell.hiddenElements = {
AuctionsCreateAuctionButton,
AuctionsItemButton,
AuctionsTitle, AuctionsTitle,
AuctionsScrollFrame, AuctionsScrollFrame,
AuctionsButton1, AuctionsButton1,
@@ -157,6 +160,9 @@ function Aux_SetupHookFunctions()
BrowseButton8:RegisterForClicks("LeftButtonUp", "RightButtonDown") BrowseButton8:RegisterForClicks("LeftButtonUp", "RightButtonDown")
BrowseButton8:SetScript("OnMouseDown", Aux_BrowseButton_OnMouseDown) BrowseButton8:SetScript("OnMouseDown", Aux_BrowseButton_OnMouseDown)
Aux.orig.PickupContainerItem = PickupContainerItem
PickupContainerItem = Aux.PickupContainerItem
Aux.orig.AuctionSellItemButton_OnEvent = AuctionSellItemButton_OnEvent Aux.orig.AuctionSellItemButton_OnEvent = AuctionSellItemButton_OnEvent
AuctionSellItemButton_OnEvent = Aux.sell.AuctionSellItemButton_OnEvent AuctionSellItemButton_OnEvent = Aux.sell.AuctionSellItemButton_OnEvent
@@ -171,9 +177,6 @@ function Aux_SetupHookFunctions()
Aux.orig.AuctionFrameAuctions_Update = AuctionFrameAuctions_Update Aux.orig.AuctionFrameAuctions_Update = AuctionFrameAuctions_Update
AuctionFrameAuctions_Update = Aux_AuctionFrameAuctions_Update AuctionFrameAuctions_Update = Aux_AuctionFrameAuctions_Update
Aux.orig.AuctionsCreateAuctionButton_OnClick = AuctionsCreateAuctionButton:GetScript('OnClick')
AuctionsCreateAuctionButton:SetScript('OnClick', Aux.sell.AuctionsCreateAuctionButton_OnClick)
end end
----------------------------------------- -----------------------------------------
@@ -242,7 +245,6 @@ function Aux_AuctionFrameTab_OnClick(index)
AuxSellPanel:Show() AuxSellPanel:Show()
AuctionFrame:EnableMouse(false) AuctionFrame:EnableMouse(false)
Aux_OnNewAuctionUpdate()
elseif index == Aux.tabs.buy.index then elseif index == Aux.tabs.buy.index then
AuctionFrameTab_OnClick(2) AuctionFrameTab_OnClick(2)
@@ -421,6 +423,13 @@ end
----------------------------------------- -----------------------------------------
function Aux.PickupContainerItem(bag, item)
Aux.last_picked_up = { bag=bag, slot=item }
return Aux.orig.PickupContainerItem(bag, item)
end
-----------------------------------------
function Aux_ContainerFrameItemButton_OnClick(button) function Aux_ContainerFrameItemButton_OnClick(button)
local bag, slot = this:GetParent():GetID(), this:GetID() local bag, slot = this:GetParent():GetID(), this:GetID()
local container_item = Aux.info.container_item(bag, slot) local container_item = Aux.info.container_item(bag, slot)
@@ -438,10 +447,7 @@ function Aux_ContainerFrameItemButton_OnClick(button)
end end
return return
elseif AUX_SELL_SHORTCUT and IsAltKeyDown()then elseif AUX_SELL_SHORTCUT and IsAltKeyDown()then
ClearCursor() Aux.sell.update_auction(bag, slot)
PickupContainerItem(bag, slot)
ClickAuctionSellItemButton()
ClearCursor()
if PanelTemplates_GetSelectedTab(AuctionFrame) ~= Aux.tabs.sell.index then if PanelTemplates_GetSelectedTab(AuctionFrame) ~= Aux.tabs.sell.index then
AuctionFrameTab_OnClick(Aux.tabs.sell.index) AuctionFrameTab_OnClick(Aux.tabs.sell.index)
end end
+89 -86
View File
@@ -6,11 +6,11 @@ auxSellEntries = {} -- persisted
local bestPriceOurStackSize local bestPriceOurStackSize
local currentAuction local current_auction
----------------------------------------- -----------------------------------------
local record_auction, undercut, item_class_index, item_subclass_index, set_message, report local record_auction, undercut, item_class_index, item_subclass_index, set_message, report, select_entry, update_recommendation, refresh_entries
----------------------------------------- -----------------------------------------
@@ -64,9 +64,9 @@ end
-- that we can note the auction values -- that we can note the auction values
----------------------------------------- -----------------------------------------
function Aux.sell.AuctionsCreateAuctionButton_OnClick() function Aux.sell.post_auctions()
if PanelTemplates_GetSelectedTab(AuctionFrame) == Aux.tabs.sell.index then if PanelTemplates_GetSelectedTab(AuctionFrame) == Aux.tabs.sell.index then
local name, stack_size, buyout_price = currentAuction.name, currentAuction.stackSize, MoneyInputFrame_GetCopper(BuyoutPrice) local name, stack_size, buyout_price = current_auction.name, current_auction.stackSize, MoneyInputFrame_GetCopper(BuyoutPrice)
local duration local duration
if AuctionFrameAuctions.duration == 120 then if AuctionFrameAuctions.duration == 120 then
duration = 2 duration = 2
@@ -82,7 +82,7 @@ function Aux.sell.AuctionsCreateAuctionButton_OnClick()
AuctionFrameAuctions.duration, AuctionFrameAuctions.duration,
MoneyInputFrame_GetCopper(StartPrice), MoneyInputFrame_GetCopper(StartPrice),
buyout_price, buyout_price,
currentAuction.stackCount, current_auction.stackCount,
function(posted) function(posted)
for i = 1, posted do for i = 1, posted do
record_auction(name, stack_size, buyout_price, duration, UnitName("player")) record_auction(name, stack_size, buyout_price, duration, UnitName("player"))
@@ -94,6 +94,7 @@ function Aux.sell.AuctionsCreateAuctionButton_OnClick()
end end
end end
end end
Aux.sell.clear_auction()
report(name, stack_size, buyout_price, posted) report(name, stack_size, buyout_price, posted)
end end
) )
@@ -106,7 +107,6 @@ end
function Aux.sell.AuctionSellItemButton_OnEvent() function Aux.sell.AuctionSellItemButton_OnEvent()
Aux.orig.AuctionSellItemButton_OnEvent() Aux.orig.AuctionSellItemButton_OnEvent()
Aux_OnNewAuctionUpdate()
end end
----------------------------------------- -----------------------------------------
@@ -119,15 +119,15 @@ end
----------------------------------------- -----------------------------------------
function Aux_SelectAuxEntry() function select_entry()
if currentAuction and auxSellEntries[currentAuction.name] and not auxSellEntries[currentAuction.name].selected then if current_auction and auxSellEntries[current_auction.name] and not auxSellEntries[current_auction.name].selected then
local bestPrice = {} -- a table with one entry per stacksize that is the cheapest auction for that particular stacksize local bestPrice = {} -- a table with one entry per stacksize that is the cheapest auction for that particular stacksize
local absoluteBest -- the overall cheapest auction local absoluteBest -- the overall cheapest auction
----- find the best price per stacksize and overall ----- ----- find the best price per stacksize and overall -----
for _,auxEntry in ipairs(auxSellEntries[currentAuction.name]) do for _,auxEntry in ipairs(auxSellEntries[current_auction.name]) do
if not bestPrice[auxEntry.stackSize] or bestPrice[auxEntry.stackSize].itemPrice >= auxEntry.itemPrice then if not bestPrice[auxEntry.stackSize] or bestPrice[auxEntry.stackSize].itemPrice >= auxEntry.itemPrice then
bestPrice[auxEntry.stackSize] = auxEntry bestPrice[auxEntry.stackSize] = auxEntry
end end
@@ -137,21 +137,21 @@ function Aux_SelectAuxEntry()
end end
end end
auxSellEntries[currentAuction.name].selected = absoluteBest auxSellEntries[current_auction.name].selected = absoluteBest
if bestPrice[currentAuction.stackSize] then if bestPrice[current_auction.stackSize] then
auxSellEntries[currentAuction.name].selected = bestPrice[currentAuction.stackSize] auxSellEntries[current_auction.name].selected = bestPrice[current_auction.stackSize]
bestPriceOurStackSize = bestPrice[currentAuction.stackSize] bestPriceOurStackSize = bestPrice[current_auction.stackSize]
end end
end end
end end
----------------------------------------- -----------------------------------------
function Aux_UpdateRecommendation() function update_recommendation()
AuxRecommendStaleText:Hide() AuxRecommendStaleText:Hide()
if not currentAuction then if not current_auction then
AuxSellRefreshButton:Disable() AuxSellRefreshButton:Disable()
Aux_Sell_SetStackSize(0) Aux_Sell_SetStackSize(0)
@@ -160,18 +160,18 @@ function Aux_UpdateRecommendation()
else else
AuxSellRefreshButton:Enable() AuxSellRefreshButton:Enable()
Aux_Sell_SetStackSize(currentAuction.stackSize) Aux_Sell_SetStackSize(current_auction.stackSize)
Aux_Sell_SetStackCount(currentAuction.stackCount) Aux_Sell_SetStackCount(current_auction.stackCount)
if auxSellEntries[currentAuction.name] and auxSellEntries[currentAuction.name].selected then if auxSellEntries[current_auction.name] and auxSellEntries[current_auction.name].selected then
if not auxSellEntries[currentAuction.name].created or GetTime() - auxSellEntries[currentAuction.name].created > 1800 then if not auxSellEntries[current_auction.name].created or GetTime() - auxSellEntries[current_auction.name].created > 1800 then
AuxRecommendStaleText:SetText("STALE DATA") -- data older than half an hour marked as stale AuxRecommendStaleText:SetText("STALE DATA") -- data older than half an hour marked as stale
AuxRecommendStaleText:Show() AuxRecommendStaleText:Show()
end end
local newBuyoutPrice = auxSellEntries[currentAuction.name].selected.itemPrice * currentAuction.stackSize local newBuyoutPrice = auxSellEntries[current_auction.name].selected.itemPrice * current_auction.stackSize
if auxSellEntries[currentAuction.name].selected.numYours == 0 then if auxSellEntries[current_auction.name].selected.numYours == 0 then
newBuyoutPrice = undercut(newBuyoutPrice) newBuyoutPrice = undercut(newBuyoutPrice)
end end
@@ -181,12 +181,12 @@ function Aux_UpdateRecommendation()
Aux_ShowElems(Aux.tabs.sell.recommendationElements) Aux_ShowElems(Aux.tabs.sell.recommendationElements)
AuxRecommendText:SetText("Recommended Buyout Price") AuxRecommendText:SetText("Recommended Buyout Price")
AuxRecommendPerStackText:SetText("for your stack of "..currentAuction.stackSize) AuxRecommendPerStackText:SetText("for your stack of "..current_auction.stackSize)
if currentAuction.texture then if current_auction.texture then
AuxRecommendItemTex:SetNormalTexture(currentAuction.texture) AuxRecommendItemTex:SetNormalTexture(current_auction.texture)
if currentAuction.stackSize > 1 then if current_auction.stackSize > 1 then
AuxRecommendItemTexCount:SetText(currentAuction.stackSize) AuxRecommendItemTexCount:SetText(current_auction.stackSize)
AuxRecommendItemTexCount:Show() AuxRecommendItemTexCount:Show()
else else
AuxRecommendItemTexCount:Hide() AuxRecommendItemTexCount:Hide()
@@ -195,28 +195,28 @@ function Aux_UpdateRecommendation()
AuxRecommendItemTex:Hide() AuxRecommendItemTex:Hide()
end end
MoneyFrame_Update("AuxRecommendPerItemPrice", Aux_Round(newBuyoutPrice / currentAuction.stackSize)) MoneyFrame_Update("AuxRecommendPerItemPrice", Aux_Round(newBuyoutPrice / current_auction.stackSize))
MoneyFrame_Update("AuxRecommendPerStackPrice", Aux_Round(newBuyoutPrice)) MoneyFrame_Update("AuxRecommendPerStackPrice", Aux_Round(newBuyoutPrice))
MoneyInputFrame_SetCopper(BuyoutPrice, Aux_Round(newBuyoutPrice)) MoneyInputFrame_SetCopper(BuyoutPrice, Aux_Round(newBuyoutPrice))
MoneyInputFrame_SetCopper(StartPrice, Aux_Round(newStartPrice)) MoneyInputFrame_SetCopper(StartPrice, Aux_Round(newStartPrice))
if auxSellEntries[currentAuction.name].selected.stackSize == auxSellEntries[currentAuction.name][1].stackSize and auxSellEntries[currentAuction.name].selected.buyoutPrice == auxSellEntries[currentAuction.name][1].buyoutPrice then if auxSellEntries[current_auction.name].selected.stackSize == auxSellEntries[current_auction.name][1].stackSize and auxSellEntries[current_auction.name].selected.buyoutPrice == auxSellEntries[current_auction.name][1].buyoutPrice then
AuxRecommendBasisText:SetText("(based on cheapest)") AuxRecommendBasisText:SetText("(based on cheapest)")
elseif bestPriceOurStackSize and auxSellEntries[currentAuction.name].selected.stackSize == bestPriceOurStackSize.stackSize and auxSellEntries[currentAuction.name].selected.buyoutPrice == bestPriceOurStackSize.buyoutPrice then elseif bestPriceOurStackSize and auxSellEntries[current_auction.name].selected.stackSize == bestPriceOurStackSize.stackSize and auxSellEntries[current_auction.name].selected.buyoutPrice == bestPriceOurStackSize.buyoutPrice then
AuxRecommendBasisText:SetText("(based on cheapest stack of the same size)") AuxRecommendBasisText:SetText("(based on cheapest stack of the same size)")
else else
AuxRecommendBasisText:SetText("(based on auction selected below)") AuxRecommendBasisText:SetText("(based on auction selected below)")
end end
elseif auxSellEntries[currentAuction.name] then elseif auxSellEntries[current_auction.name] then
set_message("No auctions were found for \n\n"..currentAuction.name) set_message("No auctions were found for \n\n"..current_auction.name)
auxSellEntries[currentAuction.name] = nil auxSellEntries[current_auction.name] = nil
else else
Aux_HideElems(Aux.tabs.sell.shownElements) Aux_HideElems(Aux.tabs.sell.shownElements)
end end
end end
Aux_ScrollbarUpdate() Aux.sell.scrollbar_update()
end end
----------------------------------------- -----------------------------------------
@@ -246,49 +246,57 @@ end
----------------------------------------- -----------------------------------------
function Aux_Sell_QuantityUpdate() function Aux_Sell_QuantityUpdate()
if currentAuction then if current_auction then
currentAuction.stackSize = Aux_Sell_GetStackSize() current_auction.stackSize = Aux_Sell_GetStackSize()
currentAuction.stackCount = Aux_Sell_GetStackCount() current_auction.stackCount = Aux_Sell_GetStackCount()
end end
Aux_SelectAuxEntry() select_entry()
Aux_UpdateRecommendation() update_recommendation()
end end
----------------------------------------- -----------------------------------------
function Aux_OnNewAuctionUpdate() function Aux.sell.clear_auction()
current_auction = nil
if PanelTemplates_GetSelectedTab(AuctionFrame) ~= Aux.tabs.sell.index then select_entry()
return update_recommendation()
end
Aux.scan.abort()
local auctionItemName, auctionItemTexture, auctionItemStackSize = GetAuctionSellItemInfo()
local auction_sell_item = Aux.info.auction_sell_item()
currentAuction = auction_sell_item.name and {
name = auction_sell_item.name,
texture = auction_sell_item.texture,
stackSize = auction_sell_item.charges or auction_sell_item.count,
stackCount = 1,
}
if currentAuction and not auxSellEntries[currentAuction.name] then
Aux_RefreshEntries()
end
Aux_SelectAuxEntry()
Aux_UpdateRecommendation()
end end
----------------------------------------- -----------------------------------------
function Aux_RefreshEntries() function Aux.sell.update_auction(bag, slot)
if currentAuction then
local name = currentAuction.name local container_item = Aux.info.container_item(bag, slot)
if container_item then
Aux.scan.abort()
-- local auction_sell_item = Aux.info.auction_sell_item()
current_auction = container_item and {
name = container_item.name,
texture = container_item.texture,
stackSize = container_item.charges or container_item.count,
stackCount = 1,
}
if current_auction and not auxSellEntries[current_auction.name] then
refresh_entries()
end
select_entry()
update_recommendation()
end
end
-----------------------------------------
function refresh_entries()
if current_auction then
local name = current_auction.name
auxSellEntries[name] = nil auxSellEntries[name] = nil
@@ -322,8 +330,8 @@ function Aux_RefreshEntries()
end, end,
on_complete = function() on_complete = function()
auxSellEntries[name] = auxSellEntries[name] or { created = GetTime() } auxSellEntries[name] = auxSellEntries[name] or { created = GetTime() }
Aux_SelectAuxEntry() select_entry()
Aux_UpdateRecommendation() update_recommendation()
end, end,
next_page = function(page, total_pages) next_page = function(page, total_pages)
local last_page = max(total_pages - 1, 0) local last_page = max(total_pages - 1, 0)
@@ -337,13 +345,13 @@ end
----------------------------------------- -----------------------------------------
function Aux_ScrollbarUpdate() function Aux.sell.scrollbar_update()
local numrows local numrows
if not currentAuction or not auxSellEntries[currentAuction.name] then if not current_auction or not auxSellEntries[current_auction.name] then
numrows = 0 numrows = 0
else else
numrows = getn(auxSellEntries[currentAuction.name]) numrows = getn(auxSellEntries[current_auction.name])
end end
FauxScrollFrame_Update(AuxScrollFrame, numrows, 12, 16) FauxScrollFrame_Update(AuxScrollFrame, numrows, 12, 16)
@@ -361,11 +369,11 @@ function Aux_ScrollbarUpdate()
lineEntry:SetID(dataOffset) lineEntry:SetID(dataOffset)
if currentAuction and dataOffset <= numrows and auxSellEntries[currentAuction.name] then if current_auction and dataOffset <= numrows and auxSellEntries[current_auction.name] then
local entry = auxSellEntries[currentAuction.name][dataOffset] local entry = auxSellEntries[current_auction.name][dataOffset]
if auxSellEntries[currentAuction.name].selected and entry.itemPrice == auxSellEntries[currentAuction.name].selected.itemPrice and entry.stackSize == auxSellEntries[currentAuction.name].selected.stackSize then if auxSellEntries[current_auction.name].selected and entry.itemPrice == auxSellEntries[current_auction.name].selected.itemPrice and entry.stackSize == auxSellEntries[current_auction.name].selected.stackSize then
lineEntry:LockHighlight() lineEntry:LockHighlight()
else else
lineEntry:UnlockHighlight() lineEntry:UnlockHighlight()
@@ -384,7 +392,7 @@ function Aux_ScrollbarUpdate()
lineEntry_time:SetText("Very Long") lineEntry_time:SetText("Very Long")
end end
if entry.stackSize == currentAuction.stackSize then if entry.stackSize == current_auction.stackSize then
lineEntry_stacks:SetTextColor(0.2, 0.9, 0.2) lineEntry_stacks:SetTextColor(0.2, 0.9, 0.2)
else else
lineEntry_stacks:SetTextColor(1.0, 1.0, 1.0) lineEntry_stacks:SetTextColor(1.0, 1.0, 1.0)
@@ -418,9 +426,9 @@ end
function AuxSellEntry_OnClick() function AuxSellEntry_OnClick()
local entryIndex = this:GetID() local entryIndex = this:GetID()
auxSellEntries[currentAuction.name].selected = auxSellEntries[currentAuction.name][entryIndex] auxSellEntries[current_auction.name].selected = auxSellEntries[current_auction.name][entryIndex]
Aux_UpdateRecommendation() update_recommendation()
PlaySound("igMainMenuOptionCheckBoxOn") PlaySound("igMainMenuOptionCheckBoxOn")
end end
@@ -429,9 +437,9 @@ end
function AuxSellRefreshButton_OnClick() function AuxSellRefreshButton_OnClick()
Aux.scan.abort() Aux.scan.abort()
Aux_RefreshEntries() refresh_entries()
Aux_SelectAuxEntry() select_entry()
Aux_UpdateRecommendation() update_recommendation()
end end
----------------------------------------- -----------------------------------------
@@ -442,12 +450,7 @@ function AuxMoneyFrame_OnLoad()
MoneyFrame_SetType("AUCTION") MoneyFrame_SetType("AUCTION")
end end
--[[*************************************************************** -----------------------------------------
All function below here are local utility functions.
These should be declared local at the top of this file.
--*****************************************************************]]
function record_auction(name, stack_size, buyout_price, duration, owner) function record_auction(name, stack_size, buyout_price, duration, owner)
if buyout_price > 0 then if buyout_price > 0 then
+23 -7
View File
@@ -153,6 +153,23 @@
</Layers> </Layers>
<Frames> <Frames>
<Button name="AuxSellPostButton" inherits="UIPanelButtonTemplate" text="Post Auctions">
<Size>
<AbsDimension x="191" y="20"/>
</Size>
<Anchors>
<Anchor point="BOTTOMLEFT">
<Offset>
<AbsDimension x="18" y="39"/>
</Offset>
</Anchor>
</Anchors>
<Scripts>
<OnClick>
Aux.sell.post_auctions()
</OnClick>
</Scripts>
</Button>
<Button> <Button>
<Size><AbsDimension x="612" y="118"/></Size> <Size><AbsDimension x="612" y="118"/></Size>
<Anchors> <Anchors>
@@ -172,13 +189,12 @@
end end
</OnEvent> </OnEvent>
<OnClick> <OnClick>
ClickAuctionSellItemButton() Aux.sell.clear_auction()
ClearCursor() -- AuctionsFrameAuctions_ValidateAuction() TODO
AuctionsFrameAuctions_ValidateAuction()
</OnClick> </OnClick>
<OnReceiveDrag> <OnReceiveDrag>
ClickAuctionSellItemButton() Aux.sell.update_auction(Aux.last_picked_up.bag, Aux.last_picked_up.slot)
AuctionsFrameAuctions_ValidateAuction() ClearCursor()
</OnReceiveDrag> </OnReceiveDrag>
<OnEnter> <OnEnter>
Aux_Hilite1:Show() Aux_Hilite1:Show()
@@ -276,10 +292,10 @@
<Scripts> <Scripts>
<OnVerticalScroll> <OnVerticalScroll>
FauxScrollFrame_OnVerticalScroll(16, Aux_ScrollbarUpdate) FauxScrollFrame_OnVerticalScroll(16, Aux.sell.scrollbar_update)
</OnVerticalScroll> </OnVerticalScroll>
<OnShow> <OnShow>
<!--Aux_ScrollbarUpdate();--> <!--Aux.sell.scrollbar_update();-->
</OnShow> </OnShow>
</Scripts> </Scripts>
</ScrollFrame> </ScrollFrame>