diff --git a/tables/auction_listing.lua b/tables/auction_listing.lua index ec2388d..a361ddf 100644 --- a/tables/auction_listing.lua +++ b/tables/auction_listing.lua @@ -4,7 +4,7 @@ local RT_COUNT = 1 local HEAD_HEIGHT = 27 local HEAD_SPACE = 2 -public.COLORS = { +public.colors = { BLUE = '|cff2992ff', GREEN = '|cff16ff16', YELLOW = '|cffffff00', @@ -14,17 +14,17 @@ public.COLORS = { } local AUCTION_PCT_COLORS = { - {color=m.COLORS.BLUE, value=50}, - {color=m.COLORS.GREEN, value=80}, - {color=m.COLORS.YELLOW, value=110}, - {color=m.COLORS.ORANGE, value=135}, - {color=m.COLORS.RED, value=aux.huge}, + {color=m.colors.BLUE, value=50}, + {color=m.colors.GREEN, value=80}, + {color=m.colors.YELLOW, value=110}, + {color=m.colors.ORANGE, value=135}, + {color=m.colors.RED, value=aux.huge}, } local TIME_LEFT_STRINGS = { - m.COLORS.RED..'30m'..FONT_COLOR_CODE_CLOSE, -- Short - m.COLORS.ORANGE..'2h'..FONT_COLOR_CODE_CLOSE, -- Medium - m.COLORS.YELLOW..'8h'..FONT_COLOR_CODE_CLOSE, -- Long - m.COLORS.BLUE..'24h'..FONT_COLOR_CODE_CLOSE, -- Very Long + m.colors.RED..'30m'..FONT_COLOR_CODE_CLOSE, -- Short + m.colors.ORANGE..'2h'..FONT_COLOR_CODE_CLOSE, -- Medium + m.colors.YELLOW..'8h'..FONT_COLOR_CODE_CLOSE, -- Long + m.colors.BLUE..'24h'..FONT_COLOR_CODE_CLOSE, -- Very Long } function private.item_column_init(rt, cell) @@ -84,7 +84,7 @@ public.search_config = { align = 'CENTER', set = function(cell, record) local display_level = max(record.level, 1) - display_level = UnitLevel('player') < record.level and m.COLORS.RED..display_level..FONT_COLOR_CODE_CLOSE or display_level + display_level = UnitLevel('player') < record.level and m.colors.RED..display_level..FONT_COLOR_CODE_CLOSE or display_level cell:SetText(display_level) end, cmp = function(record_a, record_b, desc) @@ -98,7 +98,7 @@ public.search_config = { set = function(cell, record, count, own, expandable) local numAuctionsText = expandable and aux.gui.inline_color.link..count..FONT_COLOR_CODE_CLOSE or count if own > 0 then - numAuctionsText = numAuctionsText..(' '..m.COLORS.YELLOW..'('..own..')'..FONT_COLOR_CODE_CLOSE) + numAuctionsText = numAuctionsText..(' '..m.colors.YELLOW..'('..own..')'..FONT_COLOR_CODE_CLOSE) end cell:SetText(numAuctionsText) end, @@ -142,7 +142,7 @@ public.search_config = { width = 0.13, align = 'CENTER', set = function(cell, record) - cell:SetText(aux.is_player(record.owner) and (m.COLORS.YELLOW..record.owner..FONT_COLOR_CODE_CLOSE) or (record.owner or '---')) + cell:SetText(aux.is_player(record.owner) and (m.colors.YELLOW..record.owner..FONT_COLOR_CODE_CLOSE) or (record.owner or '---')) end, cmp = function(record_a, record_b, desc) if not record_a.owner and not record_b.owner then @@ -254,7 +254,7 @@ public.auctions_config = { align = 'CENTER', set = function(cell, record) local display_level = max(record.level, 1) - display_level = UnitLevel('player') < record.level and m.COLORS.RED..display_level..FONT_COLOR_CODE_CLOSE or display_level + display_level = UnitLevel('player') < record.level and m.colors.RED..display_level..FONT_COLOR_CODE_CLOSE or display_level cell:SetText(display_level) end, cmp = function(record_a, record_b, desc) @@ -357,7 +357,7 @@ public.auctions_config = { width = 0.21, align = 'CENTER', set = function(cell, record) - cell:SetText(record.high_bidder or m.COLORS.RED..'No Bids'..FONT_COLOR_CODE_CLOSE) + cell:SetText(record.high_bidder or m.colors.RED..'No Bids'..FONT_COLOR_CODE_CLOSE) end, cmp = function(record_a, record_b, desc) if not record_a.high_bidder and not record_b.high_bidder then @@ -443,7 +443,7 @@ public.bids_config = { width = 0.13, align = 'CENTER', set = function(cell, record) - cell:SetText(aux.is_player(record.owner) and (m.COLORS.YELLOW..record.owner..FONT_COLOR_CODE_CLOSE) or (record.owner or '---')) + cell:SetText(aux.is_player(record.owner) and (m.colors.YELLOW..record.owner..FONT_COLOR_CODE_CLOSE) or (record.owner or '---')) end, cmp = function(record_a, record_b, desc) if not record_a.owner and not record_b.owner then @@ -512,9 +512,9 @@ public.bids_config = { set = function(cell, record) local status if record.high_bidder then - status = m.COLORS.YELLOW..'High Bidder'..FONT_COLOR_CODE_CLOSE + status = m.colors.YELLOW..'High Bidder'..FONT_COLOR_CODE_CLOSE else - status = m.COLORS.RED..'Outbid'..FONT_COLOR_CODE_CLOSE + status = m.colors.RED..'Outbid'..FONT_COLOR_CODE_CLOSE end cell:SetText(status) end, @@ -548,7 +548,7 @@ function public.percentage_historical(pct, bid) if pct > 10000 then pct = '>10000' end - return (bid and m.COLORS.GRAY or m.percentage_color(pct))..pct..'%'..FONT_COLOR_CODE_CLOSE + return (bid and m.colors.GRAY or m.percentage_color(pct))..pct..'%'..FONT_COLOR_CODE_CLOSE end function public.time_left(code) diff --git a/tabs/post/core.lua b/tabs/post/core.lua index 5d941f8..70bf5eb 100644 --- a/tabs/post/core.lua +++ b/tabs/post/core.lua @@ -122,27 +122,27 @@ function private.update_auction_listing() local bid_color if blizzard_bid_undercut < unit_start_price and stack_blizzard_bid_undercut < unit_start_price then - bid_color = aux.auction_listing.COLORS.RED + bid_color = aux.auction_listing.colors.RED elseif blizzard_bid_undercut < unit_start_price then - bid_color = aux.auction_listing.COLORS.ORANGE + bid_color = aux.auction_listing.colors.ORANGE elseif stack_blizzard_bid_undercut < unit_start_price then - bid_color = aux.auction_listing.COLORS.YELLOW + bid_color = aux.auction_listing.colors.YELLOW end local buyout_color if buyout_price_undercut < unit_buyout_price and stack_buyout_price_undercut < unit_buyout_price then - buyout_color = aux.auction_listing.COLORS.RED + buyout_color = aux.auction_listing.colors.RED elseif buyout_price_undercut < unit_buyout_price then - buyout_color = aux.auction_listing.COLORS.ORANGE + buyout_color = aux.auction_listing.colors.ORANGE elseif stack_buyout_price_undercut < unit_buyout_price then - buyout_color = aux.auction_listing.COLORS.YELLOW + buyout_color = aux.auction_listing.colors.YELLOW end tinsert(auction_rows, { cols = { - { value=auction_record.own and aux.auction_listing.COLORS.GREEN..auction_record.count..FONT_COLOR_CODE_CLOSE or auction_record.count }, + { value=auction_record.own and aux.auction_listing.colors.GREEN..auction_record.count..FONT_COLOR_CODE_CLOSE or auction_record.count }, { value=aux.auction_listing.time_left(auction_record.duration) }, - { value=auction_record.stack_size == stack_size and aux.auction_listing.COLORS.GREEN..auction_record.stack_size..FONT_COLOR_CODE_CLOSE or auction_record.stack_size }, + { value=auction_record.stack_size == stack_size and aux.auction_listing.colors.GREEN..auction_record.stack_size..FONT_COLOR_CODE_CLOSE or auction_record.stack_size }, { value=aux.money.to_string(auction_record.unit_blizzard_bid, true, nil, 3, bid_color) }, { value=historical_value and aux.auction_listing.percentage_historical(aux.util.round(auction_record.unit_blizzard_bid / historical_value * 100)) or '---' }, { value=auction_record.unit_buyout_price > 0 and aux.money.to_string(auction_record.unit_buyout_price, true, nil, 3, buyout_color) or '---' }, diff --git a/tabs/search/filter.lua b/tabs/search/filter.lua index dde42fd..31b0fcb 100644 --- a/tabs/search/filter.lua +++ b/tabs/search/filter.lua @@ -85,7 +85,9 @@ function private.set_form(components) end end - m.post_components = components.post + for _, component in components.post do + m.add_component(component) + end m.update_filter_display() end @@ -103,7 +105,8 @@ function private.clear_form() UIDropDownMenu_ClearAll(m.slot_dropdown) UIDropDownMenu_ClearAll(m.quality_dropdown) m.filter_input:ClearFocus() - m.post_components = {} + m.post_filter = {} + m.filter_builder_state = {selected=0} m.update_filter_display() end @@ -119,7 +122,7 @@ end function private.export_query_string() local components, error = aux.filter.parse_query_string(m.get_form()) if components then - m.search_box:SetText(aux.filter.query_string({blizzard=components.blizzard, post=m.post_components})) + m.search_box:SetText(aux.filter.query_string({blizzard=components.blizzard, post=m.post_filter})) m.filter_input:ClearFocus() m.update_filter_display() else @@ -127,29 +130,101 @@ function private.export_query_string() end end -private.post_components = {} +function public.formatted_post_filter(components) + local no_line_break + local stack = {} + local str = '' -function private.add_post_component() - local name = UIDropDownMenu_GetSelectedValue(m.filter_dropdown) - if name then - local filter = name - if not aux.filter.filters[name] and filter == 'and' or filter == 'or' then + 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 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