module refactoring

This commit is contained in:
Manuel Simon Hirsig
2016-10-14 01:55:38 +02:00
parent 2660b44861
commit cc7139c0e2
30 changed files with 326 additions and 343 deletions
+6 -16
View File
@@ -12,20 +12,10 @@ StaticPopupDialogs.AUX_SEARCH_TABLE_FULL = {
timeout = 0,
hideOnEscape = 1,
}
--StaticPopupDialogs.AUX_SEARCH_AUTO_BUY = {
-- text = 'Are you sure you want to activate automatic buyout?',
-- button1 = 'Yes',
-- button2 = 'No',
-- OnAccept = function()
-- auto_buy_button:SetChecked(true)
-- end,
-- timeout = 0,
-- hideOnEscape = 1,
--}
private.RESULTS = 1
private.SAVED = 2
private.FILTER = 3
RESULTS = 1
SAVED = 2
FILTER = 3
function LOAD()
-- aux_search_tab_frame.create()
@@ -52,7 +42,7 @@ function USE_ITEM(item_info)
execute(nil, false)
end
function private.subtab.set(tab)
function set_subtab(tab)
search_results_button:UnlockHighlight()
saved_searches_button:UnlockHighlight()
new_filter_button:UnlockHighlight()
@@ -76,7 +66,7 @@ function public.set_filter(filter_string)
search_box:SetText(filter_string)
end
function private.add_filter(filter_string)
function add_filter(filter_string)
local old_filter_string = search_box:GetText()
old_filter_string = trim(old_filter_string)
@@ -87,7 +77,7 @@ function private.add_filter(filter_string)
search_box:SetText(old_filter_string .. filter_string)
end
function private.blizzard_page_index(str)
function blizzard_page_index(str)
if tonumber(str) then
return max(0, tonumber(str) - 1)
end
+24 -24
View File
@@ -5,12 +5,12 @@ local money = require 'aux.util.money'
local cache = require 'aux.core.cache'
local filter_util = require 'aux.util.filter'
function private.valid_level(str)
function valid_level(str)
local level = tonumber(str)
return level and bounded(1, 60, level)
end
private.blizzard_query = setmetatable(t, {
blizzard_query = setmetatable(t, {
__index = function(_, key)
if key == 'name' then
return name_input:GetText()
@@ -63,7 +63,7 @@ private.blizzard_query = setmetatable(t, {
end,
})
function private.update_form()
function update_form()
if blizzard_query.class and GetAuctionItemSubClasses(blizzard_query.class) then
subclass_dropdown.button:Enable()
else
@@ -105,7 +105,7 @@ function private.update_form()
end
end
function private.get_filter_builder_query()
function get_filter_builder_query()
local filter_string
local function add(part)
@@ -149,7 +149,7 @@ function private.get_filter_builder_query()
return filter_string or ''
end
function private.set_form(filter)
function set_form(filter)
clear_form()
for _, component in filter.components do
if component[1] == 'blizzard' then
@@ -161,7 +161,7 @@ function private.set_form(filter)
update_filter_display()
end
function private.clear_form()
function clear_form()
blizzard_query.name = ''
name_input:ClearFocus()
blizzard_query.exact = false
@@ -180,19 +180,19 @@ function private.clear_form()
update_filter_display()
end
function private.import_filter_string()
function import_filter_string()
local filter, error = filter_util.parse_filter_string(select(3, strfind(search_box:GetText(), '^([^;]*)')))
if filter or print(error) then
set_form(filter)
end
end
function private.export_filter_string()
function export_filter_string()
search_box:SetText(get_filter_builder_query())
filter_parameter_input:ClearFocus()
end
function private.formatted_post_filter(components)
function formatted_post_filter(components)
local no_line_break
local stack = tt
local str = ''
@@ -236,14 +236,14 @@ function private.formatted_post_filter(components)
return '<html><body><p>' .. str .. '</p></body></html>'
end
function private.data_link(id, str)
function data_link(id, str)
return '|H' .. id .. '|h' .. str .. '|h'
end
private.post_filter = t
private.filter_builder_state = T('selected', 0)
post_filter = t
filter_builder_state = T('selected', 0)
function private.data_link_click()
function data_link_click()
local button = arg3
local index = tonumber(arg1)
if button == 'LeftButton' then
@@ -254,7 +254,7 @@ function private.data_link_click()
update_filter_display()
end
function private.remove_component(index)
function remove_component(index)
index = index or filter_builder_state.selected
if filter_builder_state.selected >= index then
filter_builder_state.selected = max(filter_builder_state.selected - 1, min(1, getn(post_filter)))
@@ -263,12 +263,12 @@ function private.remove_component(index)
tremove(post_filter, index)
end
function private.add_component(component)
function add_component(component)
filter_builder_state.selected = filter_builder_state.selected + 1
tinsert(post_filter, filter_builder_state.selected, component)
end
function private.add_post_filter()
function add_post_filter()
for str in present(filter_input:GetText()) do
for filter in present(filter_util.filters[str]) do
if filter.input_type ~= '' then
@@ -290,13 +290,13 @@ end
do
local text = ''
function private.update_filter_display()
function update_filter_display()
text = formatted_post_filter(post_filter)
filter_display:SetWidth(filter_display_size())
set_filter_display_offset()
filter_display:SetText(text)
end
function private.filter_display_size()
function filter_display_size()
local font, font_size = filter_display:GetFont()
filter_display.measure:SetFont(font, font_size)
local lines = 0
@@ -310,7 +310,7 @@ do
end
end
function private.set_filter_display_offset(x_offset, y_offset)
function set_filter_display_offset(x_offset, y_offset)
local scroll_frame = filter_display:GetParent()
x_offset, y_offset = x_offset or scroll_frame:GetHorizontalScroll(), y_offset or scroll_frame:GetVerticalScroll()
local width, height = filter_display_size()
@@ -322,7 +322,7 @@ function private.set_filter_display_offset(x_offset, y_offset)
scroll_frame:SetVerticalScroll(bounded(y_lower_bound, y_upper_bound, y_offset))
end
function private.initialize_filter_dropdown()
function initialize_filter_dropdown()
for filter in temp-S('and', 'or', 'not', 'min-unit-bid', 'min-unit-buy', 'max-unit-bid', 'max-unit-buy', 'bid-profit', 'buy-profit', 'bid-vend-profit', 'buy-vend-profit', 'bid-dis-profit', 'buy-dis-profit', 'bid-pct', 'buy-pct', 'item', 'tooltip', 'min-lvl', 'max-lvl', 'rarity', 'left', 'utilizable', 'discard') do
UIDropDownMenu_AddButton(T(
'text', filter,
@@ -342,7 +342,7 @@ function private.initialize_filter_dropdown()
end
end
function private.initialize_class_dropdown()
function initialize_class_dropdown()
local function on_click()
if this.value ~= blizzard_query.class then
UIDropDownMenu_SetSelectedValue(class_dropdown, this.value)
@@ -359,7 +359,7 @@ function private.initialize_class_dropdown()
end
end
function private.initialize_subclass_dropdown()
function initialize_subclass_dropdown()
local function on_click()
if this.value ~= blizzard_query.subclass then
UIDropDownMenu_SetSelectedValue(subclass_dropdown, this.value)
@@ -377,7 +377,7 @@ function private.initialize_subclass_dropdown()
end
end
function private.initialize_slot_dropdown()
function initialize_slot_dropdown()
local function on_click()
UIDropDownMenu_SetSelectedValue(slot_dropdown, this.value)
update_form()
@@ -392,7 +392,7 @@ function private.initialize_slot_dropdown()
end
end
function private.initialize_quality_dropdown()
function initialize_quality_dropdown()
local function on_click()
UIDropDownMenu_SetSelectedValue(quality_dropdown, this.value)
update_form()
+35 -35
View File
@@ -9,7 +9,7 @@ local auction_listing = require 'aux.gui.auction_listing'
local FILTER_SPACING = 28.5
private.frame = CreateFrame('Frame', nil, AuxFrame)
frame = CreateFrame('Frame', nil, AuxFrame)
frame:SetAllPoints()
frame:SetScript('OnUpdate', on_update)
frame:Hide()
@@ -42,7 +42,7 @@ do
btn:SetHeight(25)
btn:SetText'<'
btn:SetScript('OnClick', previous_search)
private.previous_button = btn
previous_button = btn
end
do
local btn = gui.button(frame, 25)
@@ -51,7 +51,7 @@ do
btn:SetHeight(25)
btn:SetText'>'
btn:SetScript('OnClick', next_search)
private.next_button = btn
next_button = btn
end
do
local btn = gui.button(frame, gui.font_size.small)
@@ -61,7 +61,7 @@ do
btn:SetScript('OnClick', function()
update_real_time(true)
end)
private.range_button = btn
range_button = btn
end
do
local btn = gui.button(frame, gui.font_size.small)
@@ -72,7 +72,7 @@ do
btn:SetScript('OnClick', function()
update_real_time(false)
end)
private.real_time_button = btn
real_time_button = btn
end
do
local function change()
@@ -96,7 +96,7 @@ do
label:SetPoint('LEFT', editbox, 'RIGHT', 0, 0)
label:SetTextColor(color.label.enabled())
label:SetText'-'
private.first_page_input = editbox
first_page_input = editbox
end
do
local editbox = gui.editbox(range_button)
@@ -108,7 +108,7 @@ do
editbox:SetScript('OnTabPressed', function() first_page_input:SetFocus() end)
editbox.enter = execute
editbox.change = change
private.last_page_input = editbox
last_page_input = editbox
end
end
do
@@ -122,7 +122,7 @@ do
end
execute()
end)
private.start_button = btn
start_button = btn
end
do
local btn = gui.button(frame)
@@ -131,7 +131,7 @@ do
btn:SetScript('OnClick', function()
scan.abort(search_scan_id)
end)
private.stop_button = btn
stop_button = btn
end
do
local btn = gui.button(frame)
@@ -141,7 +141,7 @@ do
btn:SetScript('OnClick', function()
execute(true)
end)
private.resume_button = btn
resume_button = btn
end
do
local editbox = gui.editbox(frame)
@@ -159,7 +159,7 @@ do
this:HighlightText(0, 0)
end)
editbox.enter = execute
private.search_box = editbox
search_box = editbox
end
do
gui.horizontal_line(frame, -40)
@@ -171,7 +171,7 @@ do
btn:SetHeight(22)
btn:SetText'Search Results'
btn:SetScript('OnClick', function() subtab = RESULTS end)
private.search_results_button = btn
search_results_button = btn
end
do
local btn = gui.button(frame, gui.font_size.large)
@@ -180,7 +180,7 @@ do
btn:SetHeight(22)
btn:SetText'Saved Searches'
btn:SetScript('OnClick', function() subtab = SAVED end)
private.saved_searches_button = btn
saved_searches_button = btn
end
do
local btn = gui.button(frame, gui.font_size.large)
@@ -189,28 +189,28 @@ do
btn:SetHeight(22)
btn:SetText'Filter Builder'
btn:SetScript('OnClick', function() subtab = FILTER end)
private.new_filter_button = btn
new_filter_button = btn
end
do
local frame = CreateFrame('Frame', nil, frame)
frame:SetWidth(265)
frame:SetHeight(25)
frame:SetPoint('TOPLEFT', AuxFrame.content, 'BOTTOMLEFT', 0, -6)
private.status_bar_frame = frame
status_bar_frame = frame
end
do
local btn = gui.button(frame.results)
btn:SetPoint('TOPLEFT', status_bar_frame, 'TOPRIGHT', 5, 0)
btn:SetText'Bid'
btn:Disable()
private.bid_button = btn
bid_button = btn
end
do
local btn = gui.button(frame.results)
btn:SetPoint('TOPLEFT', bid_button, 'TOPRIGHT', 5, 0)
btn:SetText'Buyout'
btn:Disable()
private.buyout_button = btn
buyout_button = btn
end
do
local btn = gui.button(frame.results)
@@ -281,7 +281,7 @@ do
local label = gui.label(editbox, gui.font_size.small)
label:SetPoint('BOTTOMLEFT', editbox, 'TOPLEFT', -2, 1)
label:SetText'Name'
private.name_input = editbox
name_input = editbox
end
do
local checkbox = gui.checkbox(frame.filter)
@@ -290,7 +290,7 @@ do
local label = gui.label(checkbox, gui.font_size.small)
label:SetPoint('BOTTOMLEFT', checkbox, 'TOPLEFT', -2, 1)
label:SetText'Exact'
private.exact_checkbox = checkbox
exact_checkbox = checkbox
end
do
local editbox = gui.editbox(frame.filter)
@@ -316,7 +316,7 @@ do
local label = gui.label(editbox, gui.font_size.small)
label:SetPoint('BOTTOMLEFT', editbox, 'TOPLEFT', -2, 1)
label:SetText'Level Range'
private.min_level_input = editbox
min_level_input = editbox
end
do
local editbox = gui.editbox(frame.filter)
@@ -342,7 +342,7 @@ do
local label = gui.label(editbox, gui.font_size.medium)
label:SetPoint('RIGHT', editbox, 'LEFT', -3, 0)
label:SetText'-'
private.max_level_input = editbox
max_level_input = editbox
end
do
local checkbox = gui.checkbox(frame.filter)
@@ -351,11 +351,11 @@ do
local label = gui.label(checkbox, gui.font_size.small)
label:SetPoint('BOTTOMLEFT', checkbox, 'TOPLEFT', -2, 1)
label:SetText'Usable'
private.usable_checkbox = checkbox
usable_checkbox = checkbox
end
do
local dropdown = gui.dropdown(frame.filter)
private.class_dropdown = dropdown
class_dropdown = dropdown
dropdown:SetPoint('TOPLEFT', min_level_input, 'BOTTOMLEFT', 0, 5 - FILTER_SPACING)
dropdown:SetWidth(300)
local label = gui.label(dropdown, gui.font_size.small)
@@ -368,7 +368,7 @@ do
end
do
local dropdown = gui.dropdown(frame.filter)
private.subclass_dropdown = dropdown
subclass_dropdown = dropdown
dropdown:SetPoint('TOPLEFT', class_dropdown, 'BOTTOMLEFT', 0, 10 - FILTER_SPACING)
dropdown:SetWidth(300)
local label = gui.label(dropdown, gui.font_size.small)
@@ -381,7 +381,7 @@ do
end
do
local dropdown = gui.dropdown(frame.filter)
private.slot_dropdown = dropdown
slot_dropdown = dropdown
dropdown:SetPoint('TOPLEFT', subclass_dropdown, 'BOTTOMLEFT', 0, 10 - FILTER_SPACING)
dropdown:SetWidth(300)
local label = gui.label(dropdown, gui.font_size.small)
@@ -394,7 +394,7 @@ do
end
do
local dropdown = gui.dropdown(frame.filter)
private.quality_dropdown = dropdown
quality_dropdown = dropdown
dropdown:SetPoint('TOPLEFT', slot_dropdown, 'BOTTOMLEFT', 0, 10 - FILTER_SPACING)
dropdown:SetWidth(300)
local label = gui.label(dropdown, gui.font_size.small)
@@ -418,7 +418,7 @@ do
local label = gui.label(dropdown, gui.font_size.medium)
label:SetPoint('RIGHT', dropdown, 'LEFT', -15, 0)
label:SetText'Post Filter'
private.filter_dropdown = dropdown
filter_dropdown = dropdown
end
do
local input = gui.editbox(frame.filter)
@@ -445,7 +445,7 @@ do
add_post_filter()
end
end
private.filter_input = input
filter_input = input
end
do
local input = gui.editbox(frame.filter)
@@ -457,7 +457,7 @@ do
input.char = function() this:complete() end
input.enter = add_post_filter
input:Hide()
private.filter_parameter_input = input
filter_parameter_input = input
end
do
local scroll_frame = CreateFrame('ScrollFrame', nil, frame.filter)
@@ -500,11 +500,11 @@ do
scroll_child:SetScript('OnHyperlinkClick', data_link_click)
-- scroll_child:SetHyperlinkFormat("format") TODO
scroll_child.measure = scroll_child:CreateFontString()
private.filter_display = scroll_child
filter_display = scroll_child
end
private.status_bars = t
private.tables = t
status_bars = t
tables = t
for _ = 1, 5 do
local status_bar = gui.status_bar(frame)
status_bar:SetAllPoints(status_bar_frame)
@@ -529,7 +529,7 @@ for _ = 1, 5 do
tinsert(tables, table)
end
private.auto_buy_listing = listing.CreateScrollingTable(frame.saved.autobuy)
auto_buy_listing = listing.CreateScrollingTable(frame.saved.autobuy)
auto_buy_listing:SetColInfo{{name='Auto Buy Filters', width=1}}
auto_buy_listing:EnableSorting(false)
auto_buy_listing:DisableSelection(true)
@@ -537,7 +537,7 @@ auto_buy_listing:SetHandler('OnClick', handlers.OnClick)
auto_buy_listing:SetHandler('OnEnter', handlers.OnEnter)
auto_buy_listing:SetHandler('OnLeave', handlers.OnLeave)
private.recent_searches_listing = listing.CreateScrollingTable(frame.saved.recent)
recent_searches_listing = listing.CreateScrollingTable(frame.saved.recent)
recent_searches_listing:SetColInfo{{name='Recent Searches', width=1}}
recent_searches_listing:EnableSorting(false)
recent_searches_listing:DisableSelection(true)
@@ -545,7 +545,7 @@ recent_searches_listing:SetHandler('OnClick', handlers.OnClick)
recent_searches_listing:SetHandler('OnEnter', handlers.OnEnter)
recent_searches_listing:SetHandler('OnLeave', handlers.OnLeave)
private.favorite_searches_listing = listing.CreateScrollingTable(frame.saved.favorite)
favorite_searches_listing = listing.CreateScrollingTable(frame.saved.favorite)
favorite_searches_listing:SetColInfo{{name='Favorite Searches', width=1}}
favorite_searches_listing:EnableSorting(false)
favorite_searches_listing:DisableSelection(true)
+25 -15
View File
@@ -9,7 +9,17 @@ function LOAD()
new_search()
end
function private.update_real_time(enable)
do
local id = 0
function get_search_scan_id()
return id
end
function set_search_scan_id(v)
id = v
end
end
function update_real_time(enable)
if enable then
range_button:Hide()
real_time_button:Show()
@@ -25,11 +35,11 @@ do
local searches = t
local search_index = 1
function private.current_search.get()
function get_current_search()
return searches[search_index]
end
function private.update_search(index)
function update_search(index)
searches[search_index].status_bar:Hide()
searches[search_index].table:Hide()
searches[search_index].table:SetSelectedRecord()
@@ -61,7 +71,7 @@ do
update_continuation()
end
function private.new_search(filter_string, first_page, last_page, real_time)
function new_search(filter_string, first_page, last_page, real_time)
while getn(searches) > search_index do
tremove(searches)
end
@@ -86,26 +96,26 @@ do
update_search(getn(searches))
end
function private.clear_control_focus()
function clear_control_focus()
search_box:ClearFocus()
first_page_input:ClearFocus()
last_page_input:ClearFocus()
end
function private.previous_search()
function previous_search()
clear_control_focus()
update_search(search_index - 1)
subtab = RESULTS
end
function private.next_search()
function next_search()
clear_control_focus()
update_search(search_index + 1)
subtab = RESULTS
end
end
function private.update_continuation()
function update_continuation()
if current_search.continuation then
resume_button:Show()
search_box:SetPoint('RIGHT', resume_button, 'LEFT', -4, 0)
@@ -115,13 +125,13 @@ function private.update_continuation()
end
end
function private.discard_continuation()
function discard_continuation()
scan.abort(search_scan_id)
current_search.continuation = nil
update_continuation()
end
function private.update_start_stop()
function update_start_stop()
if current_search.active then
stop_button:Show()
start_button:Hide()
@@ -131,7 +141,7 @@ function private.update_start_stop()
end
end
function private.start_real_time_scan(query, search, continuation)
function start_real_time_scan(query, search, continuation)
local ignore_page
if not search then
@@ -199,7 +209,7 @@ function private.start_real_time_scan(query, search, continuation)
}
end
function private.start_search(queries, continuation)
function start_search(queries, continuation)
local current_query, current_page, total_queries, start_query, start_page
local search = current_search
@@ -349,7 +359,7 @@ function public.execute(resume, real_time)
end
end
function private.test(record)
function test(record)
return function(index)
local auction_info = info.auction(index)
return auction_info and auction_info.search_signature == record.search_signature
@@ -362,7 +372,7 @@ do
local state = IDLE
local found_index
function private.find_auction(record)
function find_auction(record)
local search = current_search
if not search.table:ContainsRecord(record) or is_player(record.owner) then
@@ -413,7 +423,7 @@ do
)
end
function private.on_update()
function on_update()
if state == IDLE or state == SEARCHING then
buyout_button:Disable()
bid_button:Disable()
+11 -11
View File
@@ -2,11 +2,11 @@ module 'aux.tabs.search'
local filter_util = require 'aux.util.filter'
aux_auto_buy_filters = t
aux_favorite_searches = t
aux_recent_searches = t
_G.aux_auto_buy_filters = t
_G.aux_favorite_searches = t
_G.aux_recent_searches = t
function private.update_search_listings()
function update_search_listings()
local autobuy_filter_rows = t
for i, autobuy_filter in aux_auto_buy_filters do
local name = strsub(autobuy_filter.prettified, 1, 250)
@@ -41,7 +41,7 @@ function private.update_search_listings()
recent_searches_listing:SetData(recent_search_rows)
end
function private.new_recent_search(filter_string, prettified)
function new_recent_search(filter_string, prettified)
tinsert(aux_recent_searches, 1, {
filter_string = filter_string,
prettified = prettified,
@@ -52,7 +52,7 @@ function private.new_recent_search(filter_string, prettified)
update_search_listings()
end
private.handlers = {
handlers = {
OnClick = function(st, data, _, button)
if not data then return end
if button == 'LeftButton' and IsShiftKeyDown() then
@@ -104,7 +104,7 @@ private.handlers = {
end
}
function private.auto_buy_validator.get()
function get_auto_buy_validator()
local validators = t
for _, filter in aux_auto_buy_filters do
local queries, error = filter_util.queries(filter.filter_string)
@@ -119,7 +119,7 @@ function private.auto_buy_validator.get()
end
end
function private.add_favorite(filter_string)
function add_favorite(filter_string)
local queries, error = filter_util.queries(filter_string)
if queries then
tinsert(aux_favorite_searches, 1, T(
@@ -132,7 +132,7 @@ function private.add_favorite(filter_string)
end
end
function private.add_auto_buy(filter_string)
function add_auto_buy(filter_string)
local queries, error = filter_util.queries(filter_string)
if queries then
if getn(queries) > 1 then
@@ -150,13 +150,13 @@ function private.add_auto_buy(filter_string)
end
end
function private.move_up(list, index)
function move_up(list, index)
if list[index - 1] then
list[index], list[index - 1] = list[index - 1], list[index]
end
end
function private.move_down(list, index)
function move_down(list, index)
if list[index + 1] then
list[index], list[index + 1] = list[index + 1], list[index]
end