From e59a6c76c0096b2e96770b536986452e29a82291 Mon Sep 17 00:00:00 2001 From: Manuel Simon Hirsig Date: Mon, 1 Feb 2016 23:33:34 +0100 Subject: [PATCH] more progress on the search tab --- listing.lua | 2 +- money.lua | 6 +-- scan_util.lua | 20 ++++++++-- search_frame.lua | 100 +++++++++++++++++++++++++++++------------------ test.lua | 21 ++++++++++ 5 files changed, 102 insertions(+), 47 deletions(-) diff --git a/listing.lua b/listing.lua index 25f4a42..2bd9c16 100644 --- a/listing.lua +++ b/listing.lua @@ -391,7 +391,7 @@ local methods = { end, } -function CreateScrollingTable(parent) +function public.CreateScrollingTable(parent) -- create the base frame ST_COUNT = ST_COUNT + 1 local st = CreateFrame('Frame', 'TSMScrollingTable'..ST_COUNT, parent) diff --git a/money.lua b/money.lua index f0987ec..ac2b050 100644 --- a/money.lua +++ b/money.lua @@ -29,13 +29,13 @@ function m.to_string(money, pad, trim, color, no_color) if trim then local parts = {} if gold > 0 then - tinsert(parts, private:format_number(gold, false, color)..gold_text) + tinsert(parts, m.format_number(gold, false, color)..gold_text) end if silver > 0 then - tinsert(parts, private:format_number(silver, pad, color)..silver_text) + tinsert(parts, m.format_number(silver, pad, color)..silver_text) end if copper > 0 then - tinsert(parts, private:format_number(copper, pad, color)..copper_text) + tinsert(parts, m.format_number(copper, pad, color)..copper_text) end text = Aux.util.join(parts, ' ') else diff --git a/scan_util.lua b/scan_util.lua index 77622c6..08a7aa0 100644 --- a/scan_util.lua +++ b/scan_util.lua @@ -177,6 +177,10 @@ function m.filter_to_string(filter) filter_term = filter_term == '' and part or filter_term..'/'..part end + if filter.exact then + add('/exact') + end + if filter.min_level then add(filter.min_level) end @@ -185,6 +189,10 @@ function m.filter_to_string(filter) add(filter.max_level) end + if filter.usable then + add('/usable') + end + if filter.class then local classes = { GetAuctionItemClasses() } add(classes[filter.class]) @@ -201,12 +209,16 @@ function m.filter_to_string(filter) add(getglobal('ITEM_QUALITY'..filter.quality..'_DESC')) end - if filter.usable then - add(filter_term) + if filter.max_price then + add(Aux.money.to_string(filter.max_price, nil, true, nil, true)) end - if filter.exact then - add(filter_term) + if filter.max_percent then + add(filter.max_percent..'%') + end + + if filter.discard then + add('/discard') end return filter_term diff --git a/search_frame.lua b/search_frame.lua index a85073f..9f0f040 100644 --- a/search_frame.lua +++ b/search_frame.lua @@ -20,7 +20,7 @@ StaticPopupDialogs['AUX_SEARCH_SAVED_RENAME'] = { edit_box:HighlightText() edit_box:SetFocus() edit_box:SetScript('OnEscapePressed', function() StaticPopup_Hide('AUX_SEARCH_SAVED_RENAME') end) - edit_box:SetScript('OnEnterPressed', function() this.button1:Click() end) + edit_box:SetScript('OnEnterPressed', function() getglobal(this:GetParent():GetName()..'Button1'):Click() end) end, OnAccept = function() private.popup_info.rename.name = getglobal(this:GetParent():GetName()..'EditBox'):GetText() @@ -101,20 +101,36 @@ function private.add_filter() end function private.clear_filter() - + AuxFilterSearchFrameFilterNameInputBox:SetText('') + AuxFilterSearchFrameFilterExactCheckButton:SetChecked(nil) + AuxFilterSearchFrameFilterMinLevel:SetText('') + AuxFilterSearchFrameFilterMaxLevel:SetText('') + UIDropDownMenu_ClearAll(private.class_dropdown) + UIDropDownMenu_ClearAll(private.subclass_dropdown) + UIDropDownMenu_ClearAll(private.slot_dropdown) + UIDropDownMenu_ClearAll(private.quality_dropdown) + AuxFilterSearchFrameFilterUsableCheckButton:SetChecked(nil) + AuxFilterSearchFrameFilterDiscardCheckButton:SetChecked(nil) + private.max_buyout_price:SetText('') + private.max_percent:SetText('') end function private.get_form_filter() + local exact = AuxFilterSearchFrameFilterExactCheckButton:GetChecked() + local max_price = Aux.money.from_string(private.max_buyout_price:GetText()) return { name = AuxFilterSearchFrameFilterNameInputBox:GetText(), - min_level = tonumber(AuxFilterSearchFrameFilterMinLevel:GetText()), - max_level = tonumber(AuxFilterSearchFrameFilterMaxLevel:GetText()), - class = UIDropDownMenu_GetSelectedValue(private.class_dropdown), - subclass = UIDropDownMenu_GetSelectedValue(private.subclass_dropdown), - slot = UIDropDownMenu_GetSelectedValue(private.slot_dropdown), - quality = UIDropDownMenu_GetSelectedValue(private.quality_dropdown), - usable = AuxFilterSearchFrameFilterUsableCheckButton:GetChecked(), exact = AuxFilterSearchFrameFilterExactCheckButton:GetChecked(), + min_level = not exact and tonumber(AuxFilterSearchFrameFilterMinLevel:GetText()), + max_level = not exact and tonumber(AuxFilterSearchFrameFilterMaxLevel:GetText()), + class = not exact and UIDropDownMenu_GetSelectedValue(private.class_dropdown), + subclass = not exact and UIDropDownMenu_GetSelectedValue(private.subclass_dropdown), + slot = not exact and UIDropDownMenu_GetSelectedValue(private.slot_dropdown), + quality = not exact and UIDropDownMenu_GetSelectedValue(private.quality_dropdown), + usable = not exact and AuxFilterSearchFrameFilterUsableCheckButton:GetChecked(), + discard = AuxFilterSearchFrameFilterDiscardCheckButton:GetChecked(), + max_price = max_price > 0 and max_price, + max_percent = tonumber(private.max_percent:GetText()), } end @@ -215,34 +231,6 @@ function public.on_load() btn:SetScript('OnClick', function() private.update_tab(FILTER) end) private.new_filter_button = btn end - do - local btn1 = Aux.gui.button(AuxFilterSearchFrameFilter, 16) - btn1:SetPoint('TOPLEFT', private.status_bar, 'TOPRIGHT', 5, 0) - btn1:SetWidth(80) - btn1:SetHeight(24) - btn1:SetText('Add Filter') - btn1:SetScript('OnClick', private.add_filter) - - local btn2 = Aux.gui.button(AuxFilterSearchFrameFilter, 16) - btn2:SetPoint('LEFT', btn1, 'RIGHT', 5, 0) - btn2:SetWidth(80) - btn2:SetHeight(24) - btn2:SetText('Search Filter') - btn2:SetScript('OnClick', function() - private.search_box:SetText('') - private.add_filter() - public.start_search() - end) - - local btn3 = Aux.gui.button(AuxFilterSearchFrameFilter, 16) - btn3:SetPoint('LEFT', btn2, 'RIGHT', 5, 0) - btn3:SetWidth(80) - btn3:SetHeight(24) - btn3:SetText('Clear Filter') - btn3:SetScript('OnClick', function() - private.clear_filter() - end) - end do local status_bar = Aux.gui.status_bar(AuxFilterSearchFrame) status_bar:SetWidth(265) @@ -270,10 +258,44 @@ function public.on_load() btn:Disable() private.bid_button = btn end + do + local btn1 = Aux.gui.button(AuxFilterSearchFrameFilter, 16) + btn1:SetPoint('TOPLEFT', private.status_bar, 'TOPRIGHT', 5, 0) + btn1:SetWidth(80) + btn1:SetHeight(24) + btn1:SetText('Search') + btn1:SetScript('OnClick', function() + private.search_box:SetText('') + private.add_filter() + public.start_search() + end) + + local btn2 = Aux.gui.button(AuxFilterSearchFrameFilter, 16) + btn2:SetPoint('LEFT', btn1, 'RIGHT', 5, 0) + btn2:SetWidth(80) + btn2:SetHeight(24) + btn2:SetText('Add') + btn2:SetScript('OnClick', private.add_filter) + + local btn3 = Aux.gui.button(AuxFilterSearchFrameFilter, 16) + btn3:SetPoint('LEFT', btn2, 'RIGHT', 5, 0) + btn3:SetWidth(80) + btn3:SetHeight(24) + btn3:SetText('Clear') + btn3:SetScript('OnClick', function() + private.clear_filter() + end) + end do local editbox = Aux.gui.editbox(AuxFilterSearchFrameFilter, '$parentNameInputBox') + editbox.complete_item = Aux.test.complete_item editbox:SetPoint('TOPLEFT', 14, -20) editbox:SetWidth(300) + editbox:SetScript('OnChar', function() + if AuxFilterSearchFrameFilterExactCheckButton:GetChecked() then + this:complete_item() + end + end) editbox:SetScript('OnTabPressed', function() if IsShiftKeyDown() then getglobal(this:GetParent():GetName()..'TooltipInputBox4'):SetFocus() @@ -664,7 +686,7 @@ end end } - private.recent_searches_listing = CreateScrollingTable(AuxFilterSearchFrameSavedRecent) + private.recent_searches_listing = Aux.listing.CreateScrollingTable(AuxFilterSearchFrameSavedRecent) private.recent_searches_listing:SetColInfo({{name='Recent Searches', width=1}}) private.recent_searches_listing:SetHandler('OnClick', handlers.OnClick) private.recent_searches_listing:SetHandler('OnEnter', handlers.OnEnter) @@ -672,7 +694,7 @@ end Aux.gui.vertical_line(AuxFilterSearchFrameSaved, 379) - private.favorite_searches_listing = CreateScrollingTable(AuxFilterSearchFrameSavedFavorite) + private.favorite_searches_listing = Aux.listing.CreateScrollingTable(AuxFilterSearchFrameSavedFavorite) private.favorite_searches_listing:SetColInfo({{name='Favorite Searches', width=1}}) private.favorite_searches_listing:SetHandler('OnClick', handlers.OnClick) private.favorite_searches_listing:SetHandler('OnEnter', handlers.OnEnter) diff --git a/test.lua b/test.lua index 966740a..d0baad0 100644 --- a/test.lua +++ b/test.lua @@ -109,6 +109,27 @@ function m:complete() end end +function m:complete_item() + + local text = this:GetText() + + local item_names = {} + for key, value in Aux.static.auctionable_items do + if type(key) == 'number' then + tinsert(item_names, value.name) + end + end + sort(item_names) + + for _, item_name in ipairs(item_names) do + if string.sub(strupper(item_name), 1, strlen(text)) == strupper(text) then + this:SetText(item_name) + this:HighlightText(strlen(text), -1) + return + end + end +end + --StaticPopupDialogs["CANCEL_AUCTION"] = { -- text = TEXT(CANCEL_AUCTION_CONFIRMATION), -- button1 = TEXT(ACCEPT),