From f3cd6b1345bf368ab54e0386d3b1d76c6aa1f145 Mon Sep 17 00:00:00 2001
From: Manuel Simon Hirsig
' + for _=1,getn(stack) do + str = str..aux.gui.inline_color.content.backdrop..'----'..FONT_COLOR_CODE_CLOSE + end + end + no_line_break = component[1] == 'operator' and component[2] == 'not' + + local OPERATOR_COLOR, FILTER_COLOR, PARAMETER_COLOR + if m.filter_builder_state.selected == i then + OPERATOR_COLOR, FILTER_COLOR, PARAMETER_COLOR = aux.auction_listing.colors.GREEN, aux.auction_listing.colors.GREEN, aux.auction_listing.colors.ORANGE + else + OPERATOR_COLOR, FILTER_COLOR, PARAMETER_COLOR = aux.auction_listing.colors.YELLOW, aux.auction_listing.colors.YELLOW, aux.auction_listing.colors.ORANGE + end + local component_text + if component[1] == 'operator' then + component_text = OPERATOR_COLOR..component[2]..(component[2] ~= 'not' and tonumber(component[3]) or '')..FONT_COLOR_CODE_CLOSE + tinsert(stack, component[3]) + elseif component[1] == 'filter' then + component_text = FILTER_COLOR..component[2]..FONT_COLOR_CODE_CLOSE + if component[3] then + component_text = component_text..': '..PARAMETER_COLOR..component[3]..FONT_COLOR_CODE_CLOSE + end + while getn(stack) > 0 and stack[getn(stack)] do + local top = tremove(stack) + if tonumber(top) and top > 1 then + tinsert(stack, top - 1) + break + end + end + end + str = str..m.data_link(i, component_text) + end + + return '
'..str..'
' +end + +function private.data_link(id, str) + return '|H'..id..'|h'..str..'|h' +end + +private.post_filter = {} +private.filter_builder_state = {selected = 0} + +function private.data_link_click() + local button = arg3 + local index = tonumber(arg1) + if button == 'LeftButton' then + m.filter_builder_state.selected = index + elseif button == 'RightButton' then + m.remove_component(index) + end + m.update_filter_display() +end + +function private.remove_component(index) + if m.filter_builder_state.selected == index then + m.filter_builder_state.selected = max(index - 1, min(1, getn(m.post_filter))) + end + m.filter_builder_state[m.post_filter[index]] = nil + tremove(m.post_filter, index) +end + +function private.add_component(component) + m.filter_builder_state.selected = m.filter_builder_state.selected + 1 + tinsert(m.post_filter, m.filter_builder_state.selected, component) +end + +function private.add_dropdown_component() + for _, str in {UIDropDownMenu_GetSelectedValue(m.filter_dropdown)} do + if not aux.filter.filters[str] and str == 'and' or str == 'or' then local arity = m.filter_input:GetText() arity = tonumber(arity) and aux.util.round(tonumber(arity)) if arity and arity < 2 then aux.log('Invalid operator suffix') return end - filter = filter..(arity or '') + str = str..(arity or '') end - if aux.filter.filters[name] and aux.filter.filters[name].input_type ~= '' then - filter = filter..'/'..m.filter_input:GetText() + if aux.index(aux.filter.filters[str], 'input_type') ~= '' then + str = str..'/'..m.filter_input:GetText() end - local components, error, suggestions = aux.filter.parse_query_string(filter) + local components, error, suggestions = aux.filter.parse_query_string(str) if components then - tinsert(m.post_components, components.post[1]) + m.add_component(components.post[1]) m.update_filter_display() m.filter_input:SetText('') m.filter_input:ClearFocus() @@ -159,16 +234,11 @@ function private.add_post_component() end end -function private.remove_post_filter() - tremove(m.post_components) - m.update_filter_display() -end - do local text function private.update_filter_display() - text = aux.filter.indented_post_query_string(m.post_components) + text = m.formatted_post_filter(m.post_filter) m.filter_display:SetWidth(m.filter_display_size()) m.set_filter_display_offset() m.filter_display:SetText(text) diff --git a/tabs/search/frames.lua b/tabs/search/frames.lua index 60d39e5..c7b0be6 100644 --- a/tabs/search/frames.lua +++ b/tabs/search/frames.lua @@ -225,7 +225,7 @@ function private.create_frames() btn:SetPoint('RIGHT', m.start_button, 'LEFT', -4, 0) btn:SetWidth(70) btn:SetHeight(25) - btn:SetText(aux.auction_listing.COLORS.GREEN..'Resume'..FONT_COLOR_CODE_CLOSE) + btn:SetText(aux.auction_listing.colors.GREEN..'Resume'..FONT_COLOR_CODE_CLOSE) btn:SetScript('OnClick', function() m.execute(true) end) @@ -508,9 +508,9 @@ function private.create_frames() btn:RegisterForClicks('LeftButtonUp', 'RightButtonUp') btn:SetScript('OnClick', function() if arg1 == 'LeftButton' then - m.add_post_component() + m.add_dropdown_component() elseif arg1 == 'RightButton' then - m.remove_post_filter() + m.remove_post_component() end end) private.filter_button = btn @@ -522,7 +522,7 @@ function private.create_frames() input:SetScript('OnChar', function() this:complete() end) - input:SetScript('OnEnterPressed', m.add_post_component) + input:SetScript('OnEnterPressed', m.add_dropdown_component) input:Hide() private.filter_input = input end @@ -563,9 +563,7 @@ function private.create_frames() scroll_child:SetFont('p', [[Fonts\ARIALN.TTF]], 26) scroll_child:SetWidth(1) scroll_child:SetHeight(1) - scroll_child:SetScript('OnHyperlinkClick', function() - aux.log(arg1, arg2, arg3) - end) + scroll_child:SetScript('OnHyperlinkClick', m.data_link_click) -- scroll_child:SetHyperlinkFormat("format") scroll_child.measure = scroll_child:CreateFontString() private.filter_display = scroll_child diff --git a/util/core.lua b/util/core.lua index f146ebd..5410758 100644 --- a/util/core.lua +++ b/util/core.lua @@ -1,9 +1,10 @@ local m, public, private = aux.module'util' -function public.pack(table, ...) - local array = {} - for i=1,arg.n do - tinsert(array, table[arg[i]]) +function public.either(p, a, b) + if p then + return a + else + return b end end @@ -115,6 +116,14 @@ function public.all(xs, p) return holds end +function public.replicate(count, value) + local array = {} + for i=1,count do + tinsert(array, value) + end + return unpack(array) +end + function public.filter(xs, p) local ys = {} for k, x in xs do @@ -166,7 +175,6 @@ function public.split(str, separator) local parts = {} while true do local start_index, _ = strfind(str, separator, 1, true) - if start_index then local part = strsub(str, 1, start_index - 1) tinsert(parts, part) @@ -218,8 +226,8 @@ function public.bag_type(bag) if bag == 0 then return 1 end - if GetInventoryItemLink('player', ContainerIDToInventoryID(bag)) then - local item_id = aux.info.parse_hyperlink(GetInventoryItemLink('player', ContainerIDToInventoryID(bag))) + for _, link in {GetInventoryItemLink('player', ContainerIDToInventoryID(bag))} do + local item_id = aux.info.parse_hyperlink(link) local item_info = aux.info.item(item_id) return aux.info.item_subclass_index(3, item_info.subclass) end diff --git a/util/filter.lua b/util/filter.lua index 17a5ccb..25d160e 100644 --- a/util/filter.lua +++ b/util/filter.lua @@ -531,48 +531,6 @@ function public.query_string(components) return prettified.get() end -function private.data_link(id, str) - return '|H'..id..'|h'..str..'|h' -end - -function public.indented_post_query_string(components) - local no_line_break - local stack = {} - local str = '' - - for i, component in components do - if no_line_break then - str = str..' ' - elseif i > 1 then - str = str..'' - for _=1,getn(stack) do - str = str..aux.gui.inline_color.content.backdrop..'----'..FONT_COLOR_CODE_CLOSE - end - end - no_line_break = component[1] == 'operator' and component[2] == 'not' - local component_text - if component[1] == 'operator' then - component_text = aux.auction_listing.COLORS.YELLOW..component[2]..(component[2] ~= 'not' and tonumber(component[3]) or '')..FONT_COLOR_CODE_CLOSE - tinsert(stack, component[3]) - elseif component[1] == 'filter' then - component_text = aux.auction_listing.COLORS.YELLOW..component[2]..FONT_COLOR_CODE_CLOSE - if component[3] then - str = str..': '..aux.auction_listing.COLORS.ORANGE..component[3]..FONT_COLOR_CODE_CLOSE - end - while getn(stack) > 0 and stack[getn(stack)] do - local top = tremove(stack) - if tonumber(top) and top > 1 then - tinsert(stack, top - 1) - break - end - end - end - str = str..m.data_link(i, component_text) - end - - return '
'..str..'
' -end - function private.prettified_query_string(components) local prettified = m.query_builder() @@ -588,7 +546,7 @@ function private.prettified_query_string(components) if blizzard_filters.name and not blizzard_filters.exact then if m.unquote(blizzard_filters.name) == '' then - prettified.prepend(aux.auction_listing.COLORS.RED..'No Filter'..FONT_COLOR_CODE_CLOSE) + prettified.prepend(aux.auction_listing.colors.RED..'No Filter'..FONT_COLOR_CODE_CLOSE) else prettified.prepend(aux.gui.inline_color.label.enabled..m.unquote(blizzard_filters.name)..FONT_COLOR_CODE_CLOSE) end @@ -596,13 +554,13 @@ function private.prettified_query_string(components) for _, component in components.post do if component[1] == 'operator' then - prettified.append(aux.auction_listing.COLORS.YELLOW..component[2]..(component[2] ~= 'not' and tonumber(component[3]) or '')..FONT_COLOR_CODE_CLOSE) + prettified.append(aux.auction_listing.colors.YELLOW..component[2]..(component[2] ~= 'not' and tonumber(component[3]) or '')..FONT_COLOR_CODE_CLOSE) elseif component[1] == 'filter' then if component[2] ~= 'tooltip' then - prettified.append(aux.auction_listing.COLORS.YELLOW..component[2]..FONT_COLOR_CODE_CLOSE) + prettified.append(aux.auction_listing.colors.YELLOW..component[2]..FONT_COLOR_CODE_CLOSE) end if component[3] then - prettified.append(aux.auction_listing.COLORS.ORANGE..component[3]..FONT_COLOR_CODE_CLOSE) + prettified.append(aux.auction_listing.colors.ORANGE..component[3]..FONT_COLOR_CODE_CLOSE) end end end