From 91b1eebefcd76a1aab4ad698adc7a9d2d19b815f Mon Sep 17 00:00:00 2001 From: Manuel Simon Hirsig Date: Mon, 25 Jul 2016 23:36:05 +0200 Subject: [PATCH] search config design improvements --- core.lua | 4 +- core.xml | 2 +- gui.lua | 42 +++++++++++---- tables/auction_listing.lua | 2 +- tabs/post/frames.lua | 2 +- tabs/search/core.lua | 94 ++++++++++++++++++-------------- tabs/search/frames.lua | 108 +++++++++++++++++++------------------ 7 files changed, 145 insertions(+), 109 deletions(-) diff --git a/core.lua b/core.lua index 6e58cd5..73d7cb7 100644 --- a/core.lua +++ b/core.lua @@ -359,7 +359,7 @@ function private.SetItemRef(...) local item_info = m.info.item(tonumber(({strfind(itemstring, '^item:(%d+)')})[3])) if item_info then m.search_tab.set_filter(strlower(item_info.name)..'/exact') - if m.real_time_button.on then + if m.real_time_button:GetChecked() then m.real_time_button:Click() end m.search_tab.execute() @@ -380,7 +380,7 @@ function private.UseContainerItem(...) item_info = item_info and m.info.item(item_info.item_id) if item_info then m.search_tab.set_filter(strlower(item_info.name)..'/exact') - if m.real_time_button.on then + if m.real_time_button:GetChecked() then m.real_time_button:Click() end m.search_tab.execute() diff --git a/core.xml b/core.xml index 6db9622..2f68645 100644 --- a/core.xml +++ b/core.xml @@ -80,7 +80,7 @@ - + diff --git a/gui.lua b/gui.lua index 6425c35..e93c909 100644 --- a/gui.lua +++ b/gui.lua @@ -46,7 +46,8 @@ public.config = { normal_button_font_size = 16, -- 15 not working for some clients text_color = { enabled = { 255/255, 254/255, 250/255, 1 }, disabled = { 147/255, 151/255, 139/255, 1 } }, label_color = { enabled = { 216/255, 225/255, 211/255, 1 }, disabled = { 150/255, 148/255, 140/255, 1 } }, - + on_color = {0.3, 0.7, 0.3}, + off_color = {0.7, 0.3, 0.3 }, } function public.inline_color(color) @@ -56,14 +57,33 @@ end function public.panel(parent) local panel = CreateFrame('Frame', nil, parent) - panel:SetBackdrop{bgFile='Interface\\Buttons\\WHITE8X8'} + panel:SetBackdrop{bgFile=[[Interface\Buttons\WHITE8X8]]} panel:SetBackdropColor(unpack(m.config.content_color)) return panel end -function public.button(parent, text_height, name) - local button = CreateFrame('Button', name, parent) - button:SetBackdrop{bgFile='Interface\\Buttons\\WHITE8X8', edgeFile='Interface\\Buttons\\WHITE8X8', edgeSize=m.config.edge_size} +function public.checkbutton(parent, text_height) + local button = m.button(parent, text_height) + button.state = false + button:SetBackdropColor(unpack(m.config.off_color)) + function button:SetChecked(state) + if state then + self:SetBackdropColor(unpack(m.config.on_color)) + self.state = true + else + self:SetBackdropColor(unpack(m.config.off_color)) + self.state = false + end + end + function button:GetChecked() + return self.state + end + return button +end + +function public.button(parent, text_height) + local button = CreateFrame('Button', nil, parent) + button:SetBackdrop{bgFile=[[Interface\Buttons\WHITE8X8]], edgeFile=[[Interface\Buttons\WHITE8X8]], edgeSize=m.config.edge_size} button:SetBackdropColor(unpack(m.config.content_color)) button:SetBackdropBorderColor(unpack(m.config.content_border_color)) local highlight = button:CreateTexture(nil, 'HIGHLIGHT') @@ -127,7 +147,7 @@ do tab.id = id tab.group = self tab:SetHeight(24) - tab:SetBackdrop{bgFile='Interface\\Buttons\\WHITE8X8', edgeFile='Interface\\Buttons\\WHITE8X8', edgeSize=m.config.edge_size} + tab:SetBackdrop{bgFile=[[Interface\Buttons\WHITE8X8]], edgeFile=[[Interface\Buttons\WHITE8X8]], edgeSize=m.config.edge_size} tab:SetBackdropColor(0, 0, 0, 0) tab:SetBackdropBorderColor(unpack(m.config.frame_border_color)) local image = tab:CreateTexture(nil, 'BACKGROUND') @@ -230,7 +250,7 @@ function public.editbox(parent, name) editbox:SetHeight(19) editbox:SetFont(m.config.content_font, m.config.normal_font_size) editbox:SetShadowColor(0, 0, 0, 0) - editbox:SetBackdrop{bgFile='Interface\\Buttons\\WHITE8X8', edgeFile='Interface\\Buttons\\WHITE8X8', edgeSize=m.config.edge_size} + editbox:SetBackdrop{bgFile=[[Interface\Buttons\WHITE8X8]], edgeFile=[[Interface\Buttons\WHITE8X8]], edgeSize=m.config.edge_size} editbox:SetBackdropColor(unpack(m.config.content_color)) editbox:SetBackdropBorderColor(unpack(m.config.content_border_color)) @@ -384,7 +404,7 @@ do local dropdown = CreateFrame('Frame', 'aux_dropdown'..id, parent, 'UIDropDownMenuTemplate') - dropdown:SetBackdrop{bgFile='Interface\\Buttons\\WHITE8X8', edgeFile='Interface\\Buttons\\WHITE8X8', edgeSize=m.config.edge_size, insets={top=5,bottom=5}} + dropdown:SetBackdrop{bgFile=[[Interface\Buttons\WHITE8X8]], edgeFile=[[Interface\Buttons\WHITE8X8]], edgeSize=m.config.edge_size, insets={top=5,bottom=5}} dropdown:SetBackdropColor(unpack(m.config.content_color)) dropdown:SetBackdropBorderColor(unpack(m.config.content_border_color)) local left = getglobal(dropdown:GetName()..'Left'):Hide() @@ -479,7 +499,7 @@ function public.slider(frame, name) slider:SetHeight(6) slider:SetHitRectInsets(0, 0, -8, -8) slider:SetValue(0) - slider:SetBackdrop{ bgFile='Interface\\Buttons\\WHITE8X8', edgeFile='Interface\\Buttons\\WHITE8X8', edgeSize=m.config.edge_size } + slider:SetBackdrop{ bgFile=[[Interface\Buttons\WHITE8X8]], edgeFile=[[Interface\Buttons\WHITE8X8]], edgeSize=m.config.edge_size } slider:SetBackdropColor(unpack(m.config.frame_color)) slider:SetBackdropBorderColor(unpack(m.config.frame_border_color)) local thumb_texture = slider:CreateTexture(nil, 'ARTWORK') @@ -504,7 +524,7 @@ function public.slider(frame, name) editbox:SetWidth(70) editbox:SetJustifyH('CENTER') editbox:EnableMouse(true) - editbox:SetBackdrop{ bgFile='Interface\\Buttons\\WHITE8X8', edgeFile='Interface\\Buttons\\WHITE8X8', edgeSize=m.config.edge_size } + editbox:SetBackdrop{ bgFile=[[Interface\Buttons\WHITE8X8]], edgeFile=[[Interface\Buttons\WHITE8X8]], edgeSize=m.config.edge_size } editbox:SetBackdropColor(unpack(m.config.content_color)) editbox:SetBackdropBorderColor(unpack(m.config.content_border_color)) -- editbox:SetFont(m.config.content_font, m.config.normal_font_size) @@ -538,7 +558,7 @@ end -- checkbox:SetWidth(16) -- checkbox:SetHeight(16) -- checkbox:SetPoint('TOPLEFT', 4, -4) --- checkbox:SetBackdrop({ bgFile='Interface\\Buttons\\WHITE8X8', edgeFile='Interface\\Buttons\\WHITE8X8', edgeSize=m.config.edge_size }) +-- checkbox:SetBackdrop({ bgFile=[[Interface\Buttons\WHITE8X8]], edgeFile=[[Interface\Buttons\WHITE8X8]], edgeSize=m.config.edge_size }) -- checkbox:SetBackdropColor(unpack(m.config.content_color)) -- checkbox:SetBackdropBorderColor(unpack(m.config.content_border_color)) -- local highlight = checkbox:CreateTexture(nil, 'HIGHLIGHT') diff --git a/tables/auction_listing.lua b/tables/auction_listing.lua index 10ce800..23084e6 100644 --- a/tables/auction_listing.lua +++ b/tables/auction_listing.lua @@ -655,7 +655,7 @@ local methods = { elseif Aux.unmodified() and button == 'RightButton' then -- TODO not when alt (how?) Aux.tab_group:set_tab(1) Aux.search_tab.set_filter(strlower(Aux.info.item(this.row.data.record.item_id).name)..'/exact') - if m.real_time_button.on then + if m.real_time_button:GetChecked() then m.real_time_button:Click() end Aux.search_tab.execute() diff --git a/tabs/post/frames.lua b/tabs/post/frames.lua index 41d3b6d..cb2f4aa 100644 --- a/tabs/post/frames.lua +++ b/tabs/post/frames.lua @@ -82,7 +82,7 @@ Aux.post_tab.FRAMES(function(m, public, private) elseif arg1 == 'RightButton' then Aux.tab_group:set_tab(1) Aux.search_tab.set_filter(strlower(Aux.info.item(this.item_record.item_id).name)..'/exact') - if m.real_time_button.on then + if m.real_time_button:GetChecked() then m.real_time_button:Click() end Aux.search_tab.execute() diff --git a/tabs/search/core.lua b/tabs/search/core.lua index a8eafc8..a89a3c7 100644 --- a/tabs/search/core.lua +++ b/tabs/search/core.lua @@ -19,33 +19,15 @@ StaticPopupDialogs['AUX_SEARCH_AUTO_BUY'] = { button1 = 'Yes', button2 = 'No', OnAccept = function() - m.auto_buy_button.on = true - m.auto_buy_button:SetBackdropColor(0.3, 0.7, 0.3) + m.auto_buy_button:SetChecked(true) end, timeout = 0, hideOnEscape = 1, } do local function action() - local queries = Aux.scan_util.parse_filter_string(getglobal(this:GetParent():GetName()..'EditBox'):GetText()) - if queries then - - if getn(queries) > 1 then - Aux.log('Error: The automatic buyout filter may contain only one query') - return - end - - if Aux.util.size(queries[1].blizzard_query) > 0 then - Aux.log('Error: The automatic buyout filter does not support Blizzard filters') - return - end - - aux_auto_buy_filter = m.auto_buy_filter_editbox:GetText() - m.auto_buy_validator = queries[1].validator - m.auto_buy_filter_button.on = true - m.auto_buy_button:SetBackdropColor(0.3, 0.7, 0.3) - m.auto_buy_filter_editbox:ClearFocus() - end + aux_auto_buy_filter = getglobal(this:GetParent():GetName()..'EditBox'):GetText() + m.update_auto_buy_filter() end StaticPopupDialogs['AUX_SEARCH_AUTO_BUY_FILTER'] = { @@ -88,6 +70,7 @@ function public.LOAD() m.create_frames(m, public, private) m.update_search() m.update_tab(m.SAVED) + m.update_auto_buy_filter() end function public.OPEN() @@ -167,6 +150,25 @@ function private.add_filter(filter_string, replace) m.search_box:SetText((old_filter_string or '')..filter_string) end +function private.update_auto_buy_filter() + if aux_auto_buy_filter then + local queries = Aux.scan_util.parse_filter_string(aux_auto_buy_filter) + if queries then + if getn(queries) > 1 then + Aux.log('Error: The automatic buyout filter may contain only one query') + elseif Aux.util.size(queries[1].blizzard_query) > 0 then + Aux.log('Error: The automatic buyout filter does not support Blizzard filters') + else + m.auto_buy_validator = queries[1].validator + m.auto_buy_filter_button.prettified = queries[1].prettified + m.auto_buy_filter_button:SetChecked(true) + return + end + end + end + aux_auto_buy_filter = nil +end + function private.close_settings() if m.settings_button.open then m.settings_button:Click() @@ -198,12 +200,14 @@ function private.get_form_filter() add('exact') end - if tonumber(m.min_level_input:GetText()) then - add(max(1, min(60, tonumber(m.min_level_input:GetText())))) + local min_level = m.blizzard_level(m.min_level_input:GetText()) + if min_level then + add(min_level) end - if tonumber(m.max_level_input:GetText()) then - add(max(1, min(60, tonumber(m.max_level_input:GetText())))) + local max_level = m.blizzard_level(m.min_level_input:GetText()) + if max_level then + add(max_level) end if m.usable_checkbox:GetChecked() then @@ -265,7 +269,7 @@ function private.start_real_time_scan(query, search, continuation) m.search_scan_id = Aux.scan.start{ type = 'list', queries = {query}, - auto_buy_validator = m.auto_buy_validator, + auto_buy_validator = m.auto_buy_filter_button:GetChecked() and aux_auto_buy_filter and m.auto_buy_validator, -- some redundancy but why not to be save on_scan_start = function() m.status_bar:update_status(99.99, 99.99) m.status_bar:set_text('Scanning last page ...') @@ -278,7 +282,7 @@ function private.start_real_time_scan(query, search, continuation) end, on_auction = function(auction_record, ctrl) if not ignore_page then - if m.auto_buy_button.on then + if m.auto_buy_button:GetChecked() then ctrl.suspend() Aux.place_bid('list', auction_record.index, auction_record.buyout_price, function() ctrl.resume(true) end) else @@ -370,7 +374,7 @@ function private.start_search(queries, continuation) current_page = current_page and 0 or start_page - 1 end, on_auction = function(auction_record, ctrl) - if m.auto_buy_button.on then + if m.auto_buy_button:GetChecked() then ctrl.suspend() Aux.place_bid('list', auction_record.index, auction_record.buyout_price, function() ctrl.resume(true) end) elseif getn(search.records) < 1000 then @@ -417,12 +421,12 @@ function public.execute(resume) local queries = Aux.scan_util.parse_filter_string(filter_string) if not queries then return - elseif m.real_time_button.on then + elseif m.real_time_button:GetChecked() then if getn(queries) > 1 then - Aux.log('Invalid filter: The sniping mode does not support multiple queries') + Aux.log('Invalid filter: The real time mode does not support multiple queries') return elseif queries[1].blizzard_query.first_page or queries[1].blizzard_query.last_page then - Aux.log('Invalid filter: The sniping mode does not support page range filters') + Aux.log('Invalid filter: The real time mode does not support page range filters') return end end @@ -434,7 +438,7 @@ function public.execute(resume) if resume then m.results_listing:SetSelectedRecord() else - if m.current_search().real_time ~= m.real_time_button.on then + if m.current_search().real_time ~= m.real_time_button:GetChecked() then m.results_listing:Reset() end m.current_search().records = {} @@ -448,22 +452,30 @@ function public.execute(resume) m.close_settings() m.update_tab(m.RESULTS) - m.current_search().real_time = m.real_time_button.on - if m.real_time_button.on then + m.current_search().real_time = m.real_time_button:GetChecked() + if m.real_time_button:GetChecked() then m.start_real_time_scan(queries[1], nil, continuation) else for _, query in queries do - if tonumber(m.first_page_input:GetText()) then - query.blizzard_query.first_page = Aux.round(max(0, m.first_page_input:GetNumber() - 1)) - end - if tonumber(m.last_page_input:GetText()) then - query.blizzard_query.last_page = Aux.round(max(0, m.last_page_input:GetNumber() - 1)) - end + query.blizzard_query.first_page = m.blizzard_page_index(m.first_page_input:GetText()) + query.blizzard_query.last_page = m.blizzard_page_index(m.last_page_input:GetText()) end m.start_search(queries, continuation) end end +function private.blizzard_page_index(str) + if tonumber(str) then + return Aux.round(max(0, tonumber(str) - 1)) + end +end + +function private.blizzard_level(str) + if tonumber(str) then + return Aux.round(max(1, min(60, tonumber(str)))) + end +end + function private.test(record) return function(index) local auction_info = Aux.info.auction(index) @@ -558,7 +570,7 @@ do end function private.update_continuation() - if m.current_search().continuation and m.current_search().real_time == m.real_time_button.on then + if m.current_search().continuation and m.current_search().real_time == m.real_time_button:GetChecked() then m.resume_button:Show() m.search_box:SetPoint('RIGHT', m.resume_button, 'LEFT', -4, 0) else diff --git a/tabs/search/frames.lua b/tabs/search/frames.lua index 8408407..7c419b5 100644 --- a/tabs/search/frames.lua +++ b/tabs/search/frames.lua @@ -27,21 +27,6 @@ Aux.search_tab.FRAMES(function(m, public, private) btn:SetPoint('TOPLEFT', 0, 0) btn:SetWidth(42) btn:SetHeight(42) - local t1 = btn:CreateTexture() - t1:SetTexture(unpack(Aux.gui.config.text_color.enabled)) - t1:SetWidth(20) - t1:SetHeight(2.5) - t1:SetPoint('CENTER', 0, 6.7) - local t2 = btn:CreateTexture() - t2:SetTexture(unpack(Aux.gui.config.text_color.enabled)) - t2:SetWidth(20) - t2:SetHeight(2.5) - t2:SetPoint('CENTER', 0, 0) - local t3 = btn:CreateTexture() - t3:SetTexture(unpack(Aux.gui.config.text_color.enabled)) - t3:SetWidth(20) - t3:SetHeight(2.5) - t3:SetPoint('CENTER', 0, -6.7) btn:SetScript('OnClick', function() if this.open then m.settings:Hide() @@ -53,6 +38,15 @@ Aux.search_tab.FRAMES(function(m, public, private) end this.open = not this.open end) + + for _, offset in {15, 10, 5} do + local fake_icon_part = btn:CreateFontString() + fake_icon_part:SetFont([[Fonts\FRIZQT__.TTF]], 23) + fake_icon_part:SetPoint('CENTER', 0, offset) + fake_icon_part:SetText('_') +-- fake_icon:SetTextHeight(28) + end + private.settings_button = btn end do @@ -72,9 +66,8 @@ Aux.search_tab.FRAMES(function(m, public, private) end do local editbox = Aux.gui.editbox(m.settings) - editbox:SetBackdropColor(unpack(Aux.gui.config.frame_color)) - editbox:SetPoint('LEFT', 80, 0) - editbox:SetWidth(30) + editbox:SetPoint('LEFT', 70, 0) + editbox:SetWidth(50) editbox:SetNumeric(true) editbox:SetMaxLetters(nil) editbox:SetScript('OnTabPressed', function() @@ -84,16 +77,23 @@ Aux.search_tab.FRAMES(function(m, public, private) this:ClearFocus() m.execute() end) + editbox:SetScript('OnTextChanged', function() + if m.blizzard_page_index(this:GetText()) and not m.real_time_button:GetChecked() then + this:SetBackdropColor(unpack(Aux.gui.config.on_color)) + else + this:SetBackdropColor(unpack(Aux.gui.config.off_color)) + end + end) local label = Aux.gui.label(editbox, 15) label:SetPoint('RIGHT', editbox, 'LEFT', -5, 0) label:SetText('Pages') + label:SetTextColor(unpack(Aux.gui.config.text_color.enabled)) private.first_page_input = editbox end do local editbox = Aux.gui.editbox(m.settings) - editbox:SetBackdropColor(unpack(Aux.gui.config.frame_color)) editbox:SetPoint('LEFT', m.first_page_input, 'RIGHT', 10, 0) - editbox:SetWidth(30) + editbox:SetWidth(50) editbox:SetNumeric(true) editbox:SetMaxLetters(nil) editbox:SetScript('OnTabPressed', function() @@ -103,48 +103,44 @@ Aux.search_tab.FRAMES(function(m, public, private) this:ClearFocus() m.execute() end) + editbox:SetScript('OnTextChanged', function() + if m.blizzard_page_index(this:GetText()) and not m.real_time_button:GetChecked() then + this:SetBackdropColor(unpack(Aux.gui.config.on_color)) + else + this:SetBackdropColor(unpack(Aux.gui.config.off_color)) + end + end) local label = Aux.gui.label(editbox, 16) label:SetPoint('RIGHT', editbox, 'LEFT', -3, 0) label:SetText('-') + label:SetTextColor(unpack(Aux.gui.config.text_color.enabled)) private.last_page_input = editbox end do - local btn = Aux.gui.button(m.settings, 16) - btn:SetBackdropColor(unpack(Aux.gui.config.frame_color)) - btn:SetPoint('LEFT', 240, 0) + local btn = Aux.gui.checkbutton(m.settings, 16) + btn:SetPoint('LEFT', 230, 0) btn:SetWidth(140) btn:SetHeight(25) btn:SetText('Real Time Mode') - btn:SetBackdropColor(0.7, 0.3, 0.3) btn:SetScript('OnClick', function() - this.on = not this.on - if this.on then - this:SetBackdropColor(0.3, 0.7, 0.3) - m.first_page_input:EnableMouse(nil) - m.last_page_input:EnableMouse(nil) - m.first_page_input:ClearFocus() - m.last_page_input:ClearFocus() - else - this:SetBackdropColor(0.7, 0.3, 0.3) - m.first_page_input:EnableMouse(true) - m.last_page_input:EnableMouse(true) - end + this:SetChecked(not this:GetChecked()) + this = m.first_page_input + m.first_page_input:GetScript('OnTextChanged')() + this = m.last_page_input + m.last_page_input:GetScript('OnTextChanged')() m.update_continuation() end) public.real_time_button = btn end do - local btn = Aux.gui.button(m.settings, 16) - btn:SetBackdropColor(unpack(Aux.gui.config.frame_color)) - btn:SetPoint('LEFT', m.real_time_button, 'RIGHT', 30, 0) + local btn = Aux.gui.checkbutton(m.settings, 16) + btn:SetPoint('LEFT', m.real_time_button, 'RIGHT', 15, 0) btn:SetWidth(140) btn:SetHeight(25) btn:SetText('Auto Buyout Mode') - btn:SetBackdropColor(0.7, 0.3, 0.3) btn:SetScript('OnClick', function() - if this.on then - this.on = false - this:SetBackdropColor(0.7, 0.3, 0.3) + if this:GetChecked() then + this:SetChecked(false) else StaticPopup_Show('AUX_SEARCH_AUTO_BUY') end @@ -152,22 +148,31 @@ Aux.search_tab.FRAMES(function(m, public, private) private.auto_buy_button = btn end do - local btn = Aux.gui.button(m.settings, 16) - btn:SetBackdropColor(unpack(Aux.gui.config.frame_color)) - btn:SetPoint('LEFT', m.auto_buy_button, 'RIGHT', 30, 0) + local btn = Aux.gui.checkbutton(m.settings, 16) + btn:SetPoint('LEFT', m.auto_buy_button, 'RIGHT', 15, 0) btn:SetWidth(140) btn:SetHeight(25) btn:SetText('Auto Buyout Filter') - btn:SetBackdropColor(0.7, 0.3, 0.3) btn:SetScript('OnClick', function() - if this.on then - this.on = false + if this:GetChecked() then + this:SetChecked(false) + aux_auto_buy_filter = nil + this.prettified = nil m.auto_buy_validator = nil - this:SetBackdropColor(0.7, 0.3, 0.3) else StaticPopup_Show('AUX_SEARCH_AUTO_BUY_FILTER') end end) + btn:SetScript('OnEnter', function() + if this.prettified then + GameTooltip_SetDefaultAnchor(GameTooltip, UIParent) + GameTooltip:AddLine(gsub(this.prettified, ';', '\n\n'), 255/255, 254/255, 250/255, true) + GameTooltip:Show() + end + end) + btn:SetScript('OnLeave', function() + GameTooltip:Hide() + end) private.auto_buy_filter_button = btn end do @@ -248,7 +253,7 @@ Aux.search_tab.FRAMES(function(m, public, private) local item_info = Aux.cursor_item() and Aux.info.item(Aux.cursor_item().item_id) if item_info then m.set_filter(strlower(item_info.name)..'/exact') - if m.real_time_button.on then + if m.real_time_button:GetChecked() then m.real_time_button:Click() end m.execute() @@ -759,7 +764,6 @@ Aux.search_tab.FRAMES(function(m, public, private) GameTooltip_SetDefaultAnchor(GameTooltip, UIParent) GameTooltip:AddLine(gsub(data.search.prettified, ';', '\n\n'), 255/255, 254/255, 250/255, true) GameTooltip:Show() - GameTooltip:Show() end, OnLeave = function() GameTooltip:ClearLines()