This commit is contained in:
Manuel Simon Hirsig
2015-10-16 19:24:45 +02:00
5 changed files with 122 additions and 102 deletions
+5 -8
View File
@@ -78,18 +78,16 @@ function Aux.buy.SearchButton_onclick()
on_page_loaded = function(page)
current_page = page
end,
on_start_page = function(ok, page, total_pages)
on_start_page = function(page, total_pages)
set_message('Scanning auctions: page ' .. page + 1 .. (total_pages and ' out of ' .. total_pages or '') .. ' ...')
return ok()
end,
on_read_auction = function(ok, i)
on_read_auction = function(i)
local auction_item = Aux.info.auction_item(i)
if auction_item then
if (auction_item.name == search_query.name or search_query.name == '' or not AuxBuyExactCheckButton:GetChecked()) and tooltip_match(tooltip_patterns, auction_item.tooltip) then
process_auction(auction_item, current_page)
end
end
return ok()
end,
on_complete = function()
entries = entries or {}
@@ -203,11 +201,11 @@ function find_auction(entry, buyout_mode, express_mode)
on_page_loaded = function(page)
current_page = page
end,
on_read_auction = function(ok, i)
on_read_auction = function(i, ctrl)
local auction_item = Aux.info.auction_item(i)
if not auction_item then
return ok()
return
end
local stack_size = auction_item.charges or auction_item.count
@@ -223,6 +221,7 @@ function find_auction(entry, buyout_mode, express_mode)
local key = Aux.auction_key(auction_item.tooltip, stack_size, auction_amount)
if key == order_key then
ctrl.suspend()
found = true
if express_mode then
@@ -250,8 +249,6 @@ function find_auction(entry, buyout_mode, express_mode)
end
AuxBuyConfirmationActionButton:Enable()
end
else
return ok()
end
end,
on_complete = function()
+88 -82
View File
@@ -2,7 +2,7 @@ Aux.completion = {}
local NUM_MATCHES = 5
local fuzzy, populate_dropdown, toggle_dropdown, suggestions, update_highlighting
local fuzzy, make_suggestions
local item_names = {}
@@ -33,18 +33,7 @@ function fuzzy(input)
end
end
function update_highlighting()
for i=1,32 do
local highlight = getglobal('DropDownList1Button' .. i .. 'Highlight')
if i == selected_index then
highlight:Show()
else
highlight:Hide()
end
end
end
function suggestions(input)
function generate_suggestions(input)
local matcher = fuzzy(input)
function fuzzy_sort(array)
sort(array, function(a, b) return strlen(a.name) < strlen(b.name) end)
@@ -70,93 +59,110 @@ function suggestions(input)
return Aux.util.map(best, function(match) return match.name end)
end
function populate_dropdown(input_box, suggestions)
for _, suggestion in ipairs(suggestions) do
UIDropDownMenu_AddButton{
text = suggestion,
value = suggestion,
notCheckable = true,
func = function()
Aux.completion.set_quietly(input_box, this.value)
end,
}
end
end
function toggle_dropdown(input_box)
ToggleDropDownMenu(1, nil, AuxCompletionDropDown, input_box, -12, 4)
end
function Aux.completion.completor()
function Aux.completion.completor(edit_box)
local self = {}
local current_suggestions = {}
local selected_index = 0
local current_input
local programmatically_set_input
local suggestions = {}
local index = 0
local input
local quietly_set_text
function self.close()
CloseDropDownMenus(1)
local fill_dropdown, update_dropdown, update_highlighting
function fill_dropdown()
for _, suggestion in ipairs(suggestions) do
UIDropDownMenu_AddButton{
text = suggestion,
value = suggestion,
notCheckable = true,
func = function()
self:set_quietly(edit_box, this.value)
end,
}
end
end
function self.set_quietly(edit_box, text)
programmatically_set_input = text
edit_box:SetText(text)
end
function self.highlighted()
return selected_index ~= 0
end
function self.suggest(input_box)
local input = input_box:GetText()
if programmatically_set_input == input then
programmatically_set_input = nil
return
end
programmatically_set_input = nil
current_input = input
selected_index = 0
update_highlighting()
if current_input == '' then
current_suggestions = {}
else
current_suggestions = suggestions(current_input)
UIDropDownMenu_Initialize(AuxCompletionDropDown, function() populate_dropdown(input_box, current_suggestions) end)
function update_dropdown()
function toggle()
ToggleDropDownMenu(1, nil, AuxCompletionDropDown, edit_box, -12, 4)
end
if DropDownList1:IsVisible() then
toggle_dropdown(input_box)
toggle()
end
toggle_dropdown(input_box)
toggle()
end
function self.next(input_box)
if getn(current_suggestions) > 0 then
selected_index = selected_index > 0 and math.mod(selected_index + 1, getn(current_suggestions) + 1) or 1
update_highlighting()
if selected_index == 0 then
Aux.completion.set_quietly(input_box, current_input)
else
Aux.completion.set_quietly(input_box, current_suggestions[selected_index])
function update_highlighting()
for i=1,32 do
local highlight = getglobal('DropDownList1Button' .. i .. 'Highlight')
if i == index then
highlight:Show()
else
highlight:Hide()
end
end
end
function self.previous(input_box)
if getn(current_suggestions) > 0 then
selected_index = selected_index > 0 and math.mod(selected_index + 1, getn(current_suggestions) + 1) or 1
update_highlighting()
if selected_index == 0 then
Aux.completion.set_quietly(input_box, current_input)
function self:close()
CloseDropDownMenus(1)
end
function self:set_quietly(text)
quietly_set_text = text
edit_box:SetText(text)
end
function self:completed()
return index ~= 0
end
function self:suggest()
local new_input = edit_box:GetText()
if new_input == quietly_set_text then
quietly_set_text = nil
return
end
quietly_set_text = nil
input = new_input
index = 0
update_highlighting()
if input == '' then
suggestions = {}
else
suggestions = generate_suggestions(input)
UIDropDownMenu_Initialize(AuxCompletionDropDown, function() fill_dropdown() end)
end
update_dropdown()
end
function self:next()
if getn(suggestions) > 0 then
index = index > 0 and math.mod(index + 1, getn(suggestions) + 1) or 1
self:update_highlighting()
if index == 0 then
self:set_quietly(input)
else
Aux.completion.set_quietly(input_box, current_suggestions[selected_index])
self:set_quietly(suggestions[index])
end
end
end
function self.previous()
if getn(suggestions) > 0 then
index = index > 0 and index - 1 or getn(suggestions)
update_highlighting()
if index == 0 then
self:set_quietly(input)
else
self:set_quietly(suggestions[index])
end
end
end
return self
end
end
+12 -7
View File
@@ -66,16 +66,21 @@ function wait_for_complete_results(k)
end
function wait_for_callback(f, args, k)
local ok
local ok = true
if not f then
ok = true
else
tinsert(args, 1, function() ok = true end)
if f then
tinsert(args, {
suspend = function() ok = false end,
resume = function() ok = true end,
})
f(unpack(args))
end
return controller().wait(function() return ok end, k)
if ok then
return k()
else
return controller().wait(function() return ok end, k)
end
end
function scan()
@@ -147,4 +152,4 @@ function submit_query(k)
else
return k()
end
end
end
+2 -4
View File
@@ -341,17 +341,15 @@ function refresh_entries()
subclass = subclass_index,
},
page = 0,
on_start_page = function(k, page, total_pages)
on_start_page = function(page, total_pages)
set_message('Scanning auctions: page ' .. page + 1 .. (total_pages and ' out of ' .. total_pages or '') .. ' ...')
return k()
end,
on_read_auction = function(k, i)
on_read_auction = function(i)
local auction_item = Aux.info.auction_item(i)
if auction_item and auction_item.name == name then
local stack_size = auction_item.charges or auction_item.count
record_auction(auction_item.name, stack_size, auction_item.buyout_price, auction_item.duration, auction_item.owner)
end
return k()
end,
on_abort = function()
auxSellEntries[name] = nil
+15 -1
View File
@@ -234,4 +234,18 @@ function Aux.util.money_string(money)
return format(GSC_1, c)
end
end
end
end
function Aux.util.group_by(tables, keys)
local groups = {}
Aux.util.map(tables, function(table)
for _, group in ipairs(groups) do
if Aux.util.all(keys, function(key) table[key] == group[1][key] end) then
tinsert(group, table)
return
end
end
tinsert(groups, { table })
end)
return groups
end