working on quantities

This commit is contained in:
Manuel Simon Hirsig
2015-09-20 05:36:20 +02:00
parent 295c0e5585
commit acbd3a5d37
4 changed files with 283 additions and 60 deletions
+1
View File
@@ -9,3 +9,4 @@ sell.xml
buy.xml
options.xml
about.xml
post.lua
+106
View File
@@ -0,0 +1,106 @@
local target_size
local slot
-- iterator for inventory
function inventory()
local inventory = {}
for bag = 0, 4 do
if GetBagName(bag) then
for bagSlot = 1, GetContainerNumSlots(bag) do
tinsert(inventory, { bag = bag, bagSlot = bagSlot })
end
end
end
local i = 0
local n = getn(inventory)
return function()
i = i + 1
if i <= n then
return inventory[i]
end
end
end
function findEmptySlot()
for slot in inventory() do
if not GetContainerItemInfo(slot.bag, slot.bagSlot) then
return slot
end
end
end
function findItem(name)
local slots = {}
for slot in inventory() do
if itemName(slot) == name then
tinsert(slots, slot)
end
end
return slots
end
function sameSlot(slot1, slot2)
return slot1.bag == slot2.bag and slot1.bagSlot == slot2.bagSlot
end
function moveItem(fromSlot, toSlot, amount)
ClearCursor()
SplitContainerItem(fromSlot.bag, fromSlot.bagSlot, amount)
PickupContainerItem(toSlot.bag, toSlot.bagSlot)
ClearCursor()
end
function itemName(slot)
local itemLink = GetContainerItemLink(slot.bag, slot.bagSlot)
if itemLink then
return string.gsub(itemLink, "^.-%[(.*)%].*", "%1")
end
end
function stackSize(slot)
local _, itemCount = GetContainerItemInfo(slot.bag, slot.bagSlot)
return itemCount
end
function postAuction(slot)
ClearCursor()
pickupContainerItem(slot.bag, slot.bagSlot)
ClickAuctionSellItemButton()
ClearCursor()
Aux.orig.AuctionsCreateAuctionButton_OnClick()
-- StartAuction(request.bid, request.buyout, request.duration);
end
function createStack(name, size)
ClearCursor()
ClickAuctionSellItemButton()
ClearCursor()
local slots = findItem(name)
local stackSlot = slots[1]
tremove(slots, 1)
for _, slot in ipairs(slots) do
if stackSize(stackSlot) < size then
moveItem(slot, stackSlot, size - stackSize(stackSlot))
elseif stackSize(stackSlot) > size then
moveItem(stackSlot, slot, stackSize(stackSlot) - size)
else
return stackSlot
end
end
if stackSize(stackSlot) > size then
local emptySlot = findEmptySlot()
Aux_Log(stackSize(stackSlot) .. ' : ' .. emptySlot.bag .. ' ' .. emptySlot.bagSlot)
moveItem(stackSlot, emptySlot, stackSize(stackSlot) - size)
Aux_Log(stackSize(stackSlot) .. ' : ' .. emptySlot.bag .. ' ' .. emptySlot.bagSlot)
if stackSize(stackSlot) == size then
return stackSlot
end
end
end
-- /script createStack('Dried King Bolete', 3)
+78 -59
View File
@@ -4,8 +4,7 @@ auxSellEntries = {} -- persisted
local bestPriceOurStackSize
local currentAuctionItem
local postedItem
local currentAuction
-----------------------------------------
@@ -64,13 +63,10 @@ end
-----------------------------------------
function Aux_AuctionsCreateAuctionButton_OnClick()
if PanelTemplates_GetSelectedTab(AuctionFrame) == Aux.tabs.sell.index and AuctionFrame:IsShown() then
postedItem = {
name = currentAuctionItem.name,
price = MoneyInputFrame_GetCopper(BuyoutPrice),
}
for i=1, currentAuction.stackCount do
local slot = createStack(currentAuction.name, currentAuction.stackCount)
postAuction(slot)
end
Aux.orig.AuctionsCreateAuctionButton_OnClick()
end
-----------------------------------------
@@ -94,13 +90,13 @@ end
function Aux_SelectAuxEntry()
if currentAuctionItem and auxSellEntries[currentAuctionItem.name] and not auxSellEntries[currentAuctionItem.name].selected then
if currentAuction and auxSellEntries[currentAuction.name] and not auxSellEntries[currentAuction.name].selected then
local bestPrice = {} -- a table with one entry per stacksize that is the cheapest auction for that particular stacksize
local absoluteBest -- the overall cheapest auction
----- find the best price per stacksize and overall -----
for _,auxEntry in ipairs(auxSellEntries[currentAuctionItem.name]) do
for _,auxEntry in ipairs(auxSellEntries[currentAuction.name]) do
if not bestPrice[auxEntry.stackSize] or bestPrice[auxEntry.stackSize].itemPrice >= auxEntry.itemPrice then
bestPrice[auxEntry.stackSize] = auxEntry
end
@@ -110,11 +106,11 @@ function Aux_SelectAuxEntry()
end
end
auxSellEntries[currentAuctionItem.name].selected = absoluteBest
auxSellEntries[currentAuction.name].selected = absoluteBest
if bestPrice[currentAuctionItem.stackSize] then
auxSellEntries[currentAuctionItem.name].selected = bestPrice[currentAuctionItem.stackSize]
bestPriceOurStackSize = bestPrice[currentAuctionItem.stackSize]
if bestPrice[currentAuction.stackSize] then
auxSellEntries[currentAuction.name].selected = bestPrice[currentAuction.stackSize]
bestPriceOurStackSize = bestPrice[currentAuction.stackSize]
end
end
end
@@ -124,35 +120,21 @@ end
function Aux_UpdateRecommendation()
AuxRecommendStaleText:Hide()
if not currentAuctionItem then
if not currentAuction then
AuxSellRefreshButton:Disable()
if postedItem then
AuxMessage:Hide()
AuxRecommendText:SetText("Auction Created for "..postedItem.name)
MoneyFrame_Update("AuxRecommendPerStackPrice", postedItem.price)
AuxRecommendPerStackPrice:Show()
AuxRecommendPerItemPrice:Hide()
AuxRecommendPerItemText:Hide()
AuxRecommendBasisText:Hide()
postedItem = nil
else
Aux_SetMessage("Drag an item to the Auction Item area\n\nto see recommended pricing information")
end
Aux_SetMessage("Drag an item to the Auction Item area\n\nto see recommended pricing information")
else
AuxSellRefreshButton:Enable()
if auxSellEntries[currentAuctionItem.name] and auxSellEntries[currentAuctionItem.name].selected then
if not auxSellEntries[currentAuctionItem.name].created or GetTime() - auxSellEntries[currentAuctionItem.name].created > 1800 then
if auxSellEntries[currentAuction.name] and auxSellEntries[currentAuction.name].selected then
if not auxSellEntries[currentAuction.name].created or GetTime() - auxSellEntries[currentAuction.name].created > 1800 then
AuxRecommendStaleText:SetText("STALE DATA") -- data older than half an hour marked as stale
AuxRecommendStaleText:Show()
end
local newBuyoutPrice = auxSellEntries[currentAuctionItem.name].selected.itemPrice * currentAuctionItem.stackSize
local newBuyoutPrice = auxSellEntries[currentAuction.name].selected.itemPrice * currentAuction.stackSize
if auxSellEntries[currentAuctionItem.name].selected.numYours < auxSellEntries[currentAuctionItem.name].selected.count then
if auxSellEntries[currentAuction.name].selected.numYours < auxSellEntries[currentAuction.name].selected.count then
newBuyoutPrice = undercut(newBuyoutPrice)
end
@@ -162,12 +144,12 @@ function Aux_UpdateRecommendation()
Aux_ShowElems(Aux.tabs.sell.recommendationElements)
AuxRecommendText:SetText("Recommended Buyout Price")
AuxRecommendPerStackText:SetText("for your stack of "..currentAuctionItem.stackSize)
AuxRecommendPerStackText:SetText("for your stack of "..currentAuction.stackSize)
if currentAuctionItem.texture then
AuxRecommendItemTex:SetNormalTexture(currentAuctionItem.texture)
if currentAuctionItem.stackSize > 1 then
AuxRecommendItemTexCount:SetText(currentAuctionItem.stackSize)
if currentAuction.texture then
AuxRecommendItemTex:SetNormalTexture(currentAuction.texture)
if currentAuction.stackSize > 1 then
AuxRecommendItemTexCount:SetText(currentAuction.stackSize)
AuxRecommendItemTexCount:Show()
else
AuxRecommendItemTexCount:Hide()
@@ -176,22 +158,22 @@ function Aux_UpdateRecommendation()
AuxRecommendItemTex:Hide()
end
MoneyFrame_Update("AuxRecommendPerItemPrice", Aux_Round(newBuyoutPrice / currentAuctionItem.stackSize))
MoneyFrame_Update("AuxRecommendPerItemPrice", Aux_Round(newBuyoutPrice / currentAuction.stackSize))
MoneyFrame_Update("AuxRecommendPerStackPrice", Aux_Round(newBuyoutPrice))
MoneyInputFrame_SetCopper(BuyoutPrice, newBuyoutPrice)
MoneyInputFrame_SetCopper(StartPrice, newStartPrice)
if auxSellEntries[currentAuctionItem.name].selected.stackSize == auxSellEntries[currentAuctionItem.name][1].stackSize and auxSellEntries[currentAuctionItem.name].selected.buyoutPrice == auxSellEntries[currentAuctionItem.name][1].buyoutPrice then
if auxSellEntries[currentAuction.name].selected.stackSize == auxSellEntries[currentAuction.name][1].stackSize and auxSellEntries[currentAuction.name].selected.buyoutPrice == auxSellEntries[currentAuction.name][1].buyoutPrice then
AuxRecommendBasisText:SetText("(based on cheapest)")
elseif bestPriceOurStackSize and auxSellEntries[currentAuctionItem.name].selected.stackSize == bestPriceOurStackSize.stackSize and auxSellEntries[currentAuctionItem.name].selected.buyoutPrice == bestPriceOurStackSize.buyoutPrice then
elseif bestPriceOurStackSize and auxSellEntries[currentAuction.name].selected.stackSize == bestPriceOurStackSize.stackSize and auxSellEntries[currentAuction.name].selected.buyoutPrice == bestPriceOurStackSize.buyoutPrice then
AuxRecommendBasisText:SetText("(based on cheapest stack of the same size)")
else
AuxRecommendBasisText:SetText("(based on auction selected below)")
end
elseif auxSellEntries[currentAuctionItem.name] then
Aux_SetMessage("No auctions were found for \n\n"..currentAuctionItem.name)
auxSellEntries[currentAuctionItem.name] = nil
elseif auxSellEntries[currentAuction.name] then
Aux_SetMessage("No auctions were found for \n\n"..currentAuction.name)
auxSellEntries[currentAuction.name] = nil
else
Aux_HideElems(Aux.tabs.sell.shownElements)
end
@@ -202,6 +184,42 @@ end
-----------------------------------------
function Aux_Sell_GetStackSize()
return AuxSellStackSize:GetNumber()
end
-----------------------------------------
function Aux_Sell_SetStackSize(stackSize)
return AuxSellStackSize:SetNumber(stackSize)
end
-----------------------------------------
function Aux_Sell_GetStackCount()
return AuxSellStackCount:GetNumber()
end
-----------------------------------------
function Aux_Sell_SetStackCount(stackCount)
return AuxSellStackCount:SetNumber(stackCount)
end
-----------------------------------------
function Aux_Sell_QuantityUpdate()
if currentAuction then
currentAuction.stackSize = Aux_Sell_GetStackSize()
currentAuction.stackCount = Aux_Sell_GetStackCount()
end
Aux_SelectAuxEntry()
Aux_UpdateRecommendation()
end
-----------------------------------------
function Aux_OnNewAuctionUpdate()
if PanelTemplates_GetSelectedTab(AuctionFrame) ~= Aux.tabs.sell.index then
@@ -220,13 +238,14 @@ function Aux_OnNewAuctionUpdate()
AuxScanTooltip:Show()
local tooltip = Aux_Scan_ExtractTooltip()
currentAuctionItem = auctionItemName and {
currentAuction = auctionItemName and {
name = auctionItemName,
texture = auctionItemTexture,
stackSize = Aux_Scan_ItemCharges(tooltip) or auctionItemStackSize,
stackCount = 1,
}
if currentAuctionItem and not auxSellEntries[currentAuctionItem.name] then
if currentAuction and not auxSellEntries[currentAuction.name] then
Aux_RefreshEntries()
end
@@ -237,22 +256,22 @@ end
-----------------------------------------
function Aux_RefreshEntries()
if currentAuctionItem then
auxSellEntries[currentAuctionItem.name] = nil
if currentAuction then
auxSellEntries[currentAuction.name] = nil
local _, _, _, _, _, sType, sSubType, _ = GetItemInfo(currentAuctionItem.name)
local _, _, _, _, _, sType, sSubType, _ = GetItemInfo(currentAuction.name)
local currentAuctionClass = ItemType2AuctionClass(sType)
local currentAuctionSubclass = nil -- SubType2AuctionSubclass(currentAuctionClass, sSubType)
Aux_Scan_Start{
query = Aux_Scan_CreateQuery{
name = currentAuctionItem.name,
name = currentAuction.name,
classIndex = currentAuctionClass,
subclassIndex = currentAuctionSubclass
},
onComplete = function(data)
processScanResults(data, currentAuctionItem.name)
processScanResults(data, currentAuction.name)
Aux_SelectAuxEntry()
Aux_UpdateRecommendation()
end
@@ -265,10 +284,10 @@ end
function Aux_ScrollbarUpdate()
local numrows
if not currentAuctionItem or not auxSellEntries[currentAuctionItem.name] then
if not currentAuction or not auxSellEntries[currentAuction.name] then
numrows = 0
else
numrows = getn(auxSellEntries[currentAuctionItem.name])
numrows = getn(auxSellEntries[currentAuction.name])
end
FauxScrollFrame_Update(AuxScrollFrame, numrows, 12, 16);
@@ -286,11 +305,11 @@ function Aux_ScrollbarUpdate()
lineEntry:SetID(dataOffset)
if currentAuctionItem and dataOffset <= numrows and auxSellEntries[currentAuctionItem.name] then
if currentAuction and dataOffset <= numrows and auxSellEntries[currentAuction.name] then
local entry = auxSellEntries[currentAuctionItem.name][dataOffset]
local entry = auxSellEntries[currentAuction.name][dataOffset]
if auxSellEntries[currentAuctionItem.name].selected and entry.itemPrice == auxSellEntries[currentAuctionItem.name].selected.itemPrice and entry.stackSize == auxSellEntries[currentAuctionItem.name].selected.stackSize then
if auxSellEntries[currentAuction.name].selected and entry.itemPrice == auxSellEntries[currentAuction.name].selected.itemPrice and entry.stackSize == auxSellEntries[currentAuction.name].selected.stackSize then
lineEntry:LockHighlight()
else
lineEntry:UnlockHighlight()
@@ -309,7 +328,7 @@ function Aux_ScrollbarUpdate()
lineEntry_time:SetText("Very Long")
end
if entry.stackSize == currentAuctionItem.stackSize then
if entry.stackSize == currentAuction.stackSize then
lineEntry_stacks:SetTextColor(0.2, 0.9, 0.2)
else
lineEntry_stacks:SetTextColor(1.0, 1.0, 1.0)
@@ -343,7 +362,7 @@ end
function AuxSellEntry_OnClick()
local entryIndex = this:GetID()
auxSellEntries[currentAuctionItem.name].selected = auxSellEntries[currentAuctionItem.name][entryIndex]
auxSellEntries[currentAuction.name].selected = auxSellEntries[currentAuction.name][entryIndex]
Aux_UpdateRecommendation()
+98 -1
View File
@@ -297,7 +297,104 @@
<Button name="AuxSellEntry9" inherits="AuxSellEntryTemplate"><Anchors><Anchor point="TOPLEFT" relativeTo="AuxSellEntry8" relativePoint="BOTTOMLEFT"/></Anchors></Button>
<Button name="AuxSellEntry10" inherits="AuxSellEntryTemplate"><Anchors><Anchor point="TOPLEFT" relativeTo="AuxSellEntry9" relativePoint="BOTTOMLEFT"/></Anchors></Button>
<Button name="AuxSellEntry11" inherits="AuxSellEntryTemplate"><Anchors><Anchor point="TOPLEFT" relativeTo="AuxSellEntry10" relativePoint="BOTTOMLEFT"/></Anchors></Button>
<Button name="AuxSellEntry12" inherits="AuxSellEntryTemplate"><Anchors><Anchor point="TOPLEFT" relativeTo="AuxSellEntry11" relativePoint="BOTTOMLEFT"/></Anchors></Button>
<Button name="AuxSellEntry12" inherits="AuxSellEntryTemplate"><Anchors><Anchor point="TOPLEFT" relativeTo="AuxSellEntry11" relativePoint="BOTTOMLEFT"/></Anchors></Button>
<frame name="AuxSellQuantity">
<Size>
<AbsDimension x="1" y="1"/>
</Size>
<Anchors>
<Anchor point="TOPLEFT">
<Offset>
<AbsDimension x="150" y="-202"/>
</Offset>
</Anchor>
</Anchors>
<layers>
<layer level="BACKGROUND">
<FontString name="AuxSellStackSizeText" inherits="GameFontHighlightSmall" text="Stack Size">
<Anchors>
<Anchor point="TOP" relativePoint="BOTTOM">
<Offset>
<AbsDimension x="0" y="0"/>
</Offset>
</Anchor>
</Anchors>
</FontString>
<FontString name="AuxSellStackCountText" inherits="GameFontHighlightSmall" text="Stacks">
<Anchors>
<Anchor point="TOP" relativePoint="BOTTOM">
<Offset>
<AbsDimension x="0" y="-33"/>
</Offset>
</Anchor>
</Anchors>
</FontString>
</layer>
</layers>
<frames>
<EditBox name="AuxSellStackSize" letters="3" numeric="true" autoFocus="false" inherits="InputBoxTemplate">
<Size>
<AbsDimension x="30" y="16"/>
</Size>
<Anchors>
<Anchor point="TOP" relativePoint="BOTTOM" relativeTo="AuxSellStackSizeText">
<Offset>
<AbsDimension x="0" y="-3"/>
</Offset>
</Anchor>
</Anchors>
<Scripts>
<OnTextChanged>
Aux_Sell_QuantityUpdate()
</OnTextChanged>
<OnTabPressed>
<!-- if (IsShiftKeyDown()) then
getglobal(this:GetParent():GetName().."BuyoutPriceCopper"):SetFocus();
else
getglobal(this:GetParent():GetName().."StackCount"):SetFocus();
end -->
</OnTabPressed>
<OnEditFocusLost>
this:HighlightText(0, 0)
</OnEditFocusLost>
<OnEditFocusGained>
this:HighlightText()
</OnEditFocusGained>
</Scripts>
</EditBox>
<EditBox name="AuxSellStackCount" letters="2" numeric="true" autoFocus="false" inherits="InputBoxTemplate">
<Size>
<AbsDimension x="22" y="16"/>
</Size>
<Anchors>
<Anchor point="TOP" relativePoint="BOTTOM" relativeTo="AuxSellStackCountText">
<Offset>
<AbsDimension x="0" y="-3"/>
</Offset>
</Anchor>
</Anchors>
<Scripts>
<OnTextChanged>
Aux_Sell_QuantityUpdate()
</OnTextChanged>
<OnTabPressed>
<!-- if (IsShiftKeyDown()) then
getglobal(this:GetParent():GetName().."StackSize"):SetFocus();
else
getglobal(this:GetParent():GetName().."StartPriceGold"):SetFocus();
end -->
</OnTabPressed>
<OnEditFocusLost>
this:HighlightText(0, 0)
</OnEditFocusLost>
<OnEditFocusGained>
this:HighlightText()
</OnEditFocusGained>
</Scripts>
</EditBox>
</frames>
</frame>
</Frames>
</Frame>
</Ui>