This commit is contained in:
Manuel Simon Hirsig
2016-03-04 21:45:15 +01:00
parent 24159a0255
commit f1ca8ec46c
5 changed files with 173 additions and 168 deletions
+9 -78
View File
@@ -17,91 +17,22 @@ end
function m:complete()
if IsControlKeyDown() then -- TODO problem is ctrl-v, maybe find a better solution
return
return
end
local filter_string = this:GetText()
local completed_filter_string = ({strfind(filter_string, '([^;]*)/[^/;]*$')})[3]
local current_filter = completed_filter_string and Aux.scan_util.filter_from_string(completed_filter_string)
local current_query = current_filter and current_filter.blizzard_query
local _, suggestions = Aux.scan_util.filter_from_string(completed_filter_string or '')
local options = {}
local start_index, _, current_modifier = strfind(filter_string, '([^/;]*)$')
current_modifier = current_modifier or ''
if current_query or not completed_filter_string then
current_query = current_query or {}
if current_query.name
and Aux.static.item_id(strupper(current_query.name))
and not current_query.min_level
and not current_query.max_level
and not current_query.class
and not current_query.subclass
and not current_query.slot
and not current_query.quality
and not current_query.usable
then
tinsert(options, 'exact')
end
tinsert(options, 'and')
tinsert(options, 'or')
tinsert(options, 'not')
tinsert(options, 'tt')
for filter, _ in pairs(Aux.scan_util.filters) do
tinsert(options, strlower(filter))
end
-- classes
if not current_query.class then
for _, class in ipairs({ GetAuctionItemClasses() }) do
tinsert(options, class)
end
end
-- subclasses
if current_query.class and not current_query.subclass then
for _, subclass in ipairs({ GetAuctionItemSubClasses(current_query.class) }) do
tinsert(options, subclass)
end
end
-- slots
if current_query.class and current_query.subclass and not current_query.slot then
for _, invtype in ipairs({ GetAuctionInvTypes(current_query.class, current_query.subclass) }) do
tinsert(options, getglobal(invtype))
end
end
-- usable
if not current_query.usable then
tinsert(options, 'usable')
end
-- rarities
if not current_query.quality then
for i=0,4 do
tinsert(options, getglobal('ITEM_QUALITY'..i..'_DESC'))
end
end
-- item names
if not completed_filter_string then
for _, name in ipairs(m.sorted_item_names()) do
tinsert(options, name..'/exact')
end
end
local start_index, _, current_modifier = strfind(filter_string, '([^/;]*)$')
current_modifier = current_modifier or ''
for _, option in ipairs(options) do
if string.sub(strupper(option), 1, strlen(current_modifier)) == strupper(current_modifier) then
this:SetText(strlower(string.sub(filter_string, 1, start_index - 1)..option))
this:HighlightText(strlen(filter_string), -1)
return
end
for _, suggestion in ipairs(suggestions) do
if string.sub(strupper(suggestion), 1, strlen(current_modifier)) == strupper(current_modifier) then
this:SetText(strlower(string.sub(filter_string, 1, start_index - 1).. suggestion))
this:HighlightText(strlen(filter_string), -1)
return
end
end
end