refactoring

This commit is contained in:
Manuel Simon Hirsig
2016-08-29 13:44:18 +02:00
parent 4b8b0cd9d0
commit 2ea9a9d665
11 changed files with 126 additions and 122 deletions
+25 -25
View File
@@ -5,7 +5,7 @@ local DURATION_4, DURATION_8, DURATION_24 = 120, 480, 1440
local settings_schema = {'record', '#', {stack_size='number'}, {duration='number'}, {start_price='number'}, {buyout_price='number'}, {hidden='boolean'}}
function private.default_settings.get()
return -object('duration', DURATION_8 , 'stack_size', 1, 'start_price', 0, 'buyout_price', 0, 'hidden', false)
return T('duration', DURATION_8 , 'stack_size', 1, 'start_price', 0, 'buyout_price', 0, 'hidden', false)
end
do
@@ -70,20 +70,20 @@ end
function get_unit_start_price()
local money_text = unit_start_price:GetText()
return money.from_string(money_text) or 0
return aux.money.from_string(money_text) or 0
end
function set_unit_start_price(amount)
unit_start_price:SetText(money.to_string(amount, true, nil, 3))
unit_start_price:SetText(aux.money.to_string(amount, true, nil, 3))
end
function get_unit_buyout_price()
local money_text = unit_buyout_price:GetText()
return money.from_string(money_text) or 0
return aux.money.from_string(money_text) or 0
end
function set_unit_buyout_price(amount)
unit_buyout_price:SetText(money.to_string(amount, true, nil, 3))
unit_buyout_price:SetText(aux.money.to_string(amount, true, nil, 3))
end
function update_inventory_listing()
@@ -104,32 +104,32 @@ function update_auction_listing()
for i, auction_record in existing_auctions[selected_item.key] or tt do
local blizzard_bid_undercut, buyout_price_undercut = undercut(auction_record, stack_size_slider:GetValue())
blizzard_bid_undercut = money.from_string(money.to_string(blizzard_bid_undercut, true, nil, 3))
buyout_price_undercut = money.from_string(money.to_string(buyout_price_undercut, true, nil, 3))
blizzard_bid_undercut = aux.money.from_string(aux.money.to_string(blizzard_bid_undercut, true, nil, 3))
buyout_price_undercut = aux.money.from_string(aux.money.to_string(buyout_price_undercut, true, nil, 3))
local stack_blizzard_bid_undercut, stack_buyout_price_undercut = undercut(auction_record, stack_size_slider:GetValue(), true)
stack_blizzard_bid_undercut = money.from_string(money.to_string(stack_blizzard_bid_undercut, true, nil, 3))
stack_buyout_price_undercut = money.from_string(money.to_string(stack_buyout_price_undercut, true, nil, 3))
stack_blizzard_bid_undercut = aux.money.from_string(aux.money.to_string(stack_blizzard_bid_undercut, true, nil, 3))
stack_buyout_price_undercut = aux.money.from_string(aux.money.to_string(stack_buyout_price_undercut, true, nil, 3))
local stack_size = stack_size_slider:GetValue()
local historical_value = history.value(selected_item.key)
local bid_color
if blizzard_bid_undercut < unit_start_price and stack_blizzard_bid_undercut < unit_start_price then
bid_color = gui.inline_color.red
bid_color = inline_color.red
elseif blizzard_bid_undercut < unit_start_price then
bid_color = gui.inline_color.orange
bid_color = inline_color.orange
elseif stack_blizzard_bid_undercut < unit_start_price then
bid_color = gui.inline_color.yellow
bid_color = inline_color.yellow
end
local buyout_color
if buyout_price_undercut < unit_buyout_price and stack_buyout_price_undercut < unit_buyout_price then
buyout_color = gui.inline_color.red
buyout_color = inline_color.red
elseif buyout_price_undercut < unit_buyout_price then
buyout_color = gui.inline_color.orange
buyout_color = inline_color.orange
elseif stack_buyout_price_undercut < unit_buyout_price then
buyout_color = gui.inline_color.yellow
buyout_color = inline_color.yellow
end
tinsert(auction_rows, {
@@ -137,9 +137,9 @@ function update_auction_listing()
{value=auction_record.own and color.yellow(auction_record.count) or auction_record.count},
{value=al.time_left(auction_record.duration)},
{value=auction_record.stack_size == stack_size and color.yellow(auction_record.stack_size) or auction_record.stack_size},
{value=money.to_string(auction_record.unit_blizzard_bid, true, nil, 3, bid_color) },
{value=aux.money.to_string(auction_record.unit_blizzard_bid, true, nil, 3, bid_color) },
{value=historical_value and al.percentage_historical(round(auction_record.unit_blizzard_bid / historical_value * 100)) or '---'},
{value=auction_record.unit_buyout_price > 0 and money.to_string(auction_record.unit_buyout_price, true, nil, 3, buyout_color) or '---'},
{value=auction_record.unit_buyout_price > 0 and aux.money.to_string(auction_record.unit_buyout_price, true, nil, 3, buyout_color) or '---'},
{value=auction_record.unit_buyout_price > 0 and historical_value and al.percentage_historical(round(auction_record.unit_buyout_price / historical_value * 100)) or '---'},
},
record = auction_record,
@@ -306,7 +306,7 @@ function update_item_configuration()
local deposit_factor = neutral_faction() and 0.25 or 0.05
local stack_size, stack_count = stack_size_slider:GetValue(), stack_count_slider:GetValue()
local amount = floor(selected_item.unit_vendor_price * deposit_factor * (selected_item.max_charges and 1 or stack_size)) * stack_count * UIDropDownMenu_GetSelectedValue(duration_dropdown) / 120
deposit:SetText('Deposit: '..money.to_string(amount, nil, nil, nil, gui.inline_color.text.enabled))
deposit:SetText('Deposit: '..aux.money.to_string(amount, nil, nil, nil, inline_color.text.enabled))
end
refresh_button:Enable()
@@ -358,7 +358,7 @@ function update_historical_value_button()
if selected_item then
local historical_value = history.value(selected_item.key)
historical_value_button.amount = historical_value
historical_value_button:SetText(historical_value and money.to_string(historical_value, true, nil, 3) or '---')
historical_value_button:SetText(historical_value and aux.money.to_string(historical_value, true, nil, 3) or '---')
end
end
@@ -386,8 +386,8 @@ function set_item(item)
stack_size_slider:SetValue(settings.stack_size)
quantity_update(true)
unit_start_price:SetText(money.to_string(settings.start_price, true, nil, 3, nil, true))
unit_buyout_price:SetText(money.to_string(settings.buyout_price, true, nil, 3, nil, true))
unit_start_price:SetText(aux.money.to_string(settings.start_price, true, nil, 3, nil, true))
unit_buyout_price:SetText(aux.money.to_string(settings.buyout_price, true, nil, 3, nil, true))
if not existing_auctions[selected_item.key] then
refresh_entries()
@@ -409,10 +409,10 @@ function update_inventory_records()
availability[i] = 0
end
availability[charge_class] = item_info.count
auctionable_map[item_info.item_key] = -object(
auctionable_map[item_info.item_key] = T(
'item_id', item_info.item_id,
'suffix_id', item_info.suffix_id,
'key', item_info.item_key
'key', item_info.item_key,
'itemstring', item_info.itemstring,
'name', item_info.name,
'texture', item_info.texture,
@@ -451,7 +451,7 @@ function refresh_entries()
scan_id = scan.start{
type = 'list',
ignore_owner = true,
queries = -list(query),
queries = list(query),
on_page_loaded = function(page, total_pages)
status_bar:update_status(100 * (page - 1) / total_pages, 0) -- TODO
status_bar:set_text(format('Scanning Page %d / %d', page, total_pages))
@@ -493,7 +493,7 @@ function record_auction(key, aux_quantity, unit_blizzard_bid, unit_buyout_price,
end
end
if not entry then
entry = -object('stack_size', aux_quantity 'unit_blizzard_bid', unit_blizzard_bid 'unit_buyout_price', unit_buyout_price 'duration', duration 'own', is_player(owner) 'count', 0)
entry = T('stack_size', aux_quantity, 'unit_blizzard_bid', unit_blizzard_bid, 'unit_buyout_price', unit_buyout_price, 'duration', duration, 'own', is_player(owner), 'count', 0)
tinsert(existing_auctions[key], entry)
end
entry.count = entry.count + 1
+15 -15
View File
@@ -72,14 +72,14 @@ function update_form()
end
if blizzard_query.exact then
for key in -temp-set('class', 'subclass', 'slot', 'quality') do
for key in temp-set('class', 'subclass', 'slot', 'quality') do
M[key..'_dropdown'].button:Disable()
end
else
class_dropdown.button:Enable()
quality_dropdown.button:Enable()
end
for key in -temp-set('min_level', 'max_level') do
for key in temp-set('min_level', 'max_level') do
if blizzard_query.exact then
M[key..'_input']:Disable()
else
@@ -134,7 +134,7 @@ function get_filter_builder_query()
add(strlower(_G['ITEM_QUALITY'..quality..'_DESC']))
end
local post_filter_string = filter_util.query_string(-temp-object('blizzard', tt, 'post', post_filter))
local post_filter_string = filter_util.query_string(temp-T('blizzard', tt, 'post', post_filter))
add(post_filter_string ~= '' and post_filter_string)
return query_string or ''
@@ -231,7 +231,7 @@ function data_link(id, str)
end
post_filter = t
filter_builder_state = -object('selected', 0)
filter_builder_state = T('selected', 0)
function data_link_click()
local button = arg3
@@ -313,8 +313,8 @@ function set_filter_display_offset(x_offset, y_offset)
end
function initialize_filter_dropdown()
for filter in -temp-set('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(-object(
for filter in temp-set('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,
'value', filter,
'func', function()
@@ -343,9 +343,9 @@ function initialize_class_dropdown()
update_form()
end
end
UIDropDownMenu_AddButton(-object('text', ALL, 'value', 0, 'func', on_click))
UIDropDownMenu_AddButton(T('text', ALL, 'value', 0, 'func', on_click))
for i, class in temp-{GetAuctionItemClasses()} do
UIDropDownMenu_AddButton(-object('text', class, 'value', i, 'func', on_click))
UIDropDownMenu_AddButton(T('text', class, 'value', i, 'func', on_click))
end
end
@@ -360,9 +360,9 @@ function initialize_subclass_dropdown()
end
local class_index = UIDropDownMenu_GetSelectedValue(class_dropdown)
if class_index and GetAuctionItemSubClasses(class_index) then
UIDropDownMenu_AddButton(-object('text', ALL, 'value', 0, 'func', on_click))
for i, subclass in temp-{GetAuctionItemSubClasses(class_index)} do
UIDropDownMenu_AddButton(-object('text', subclass, 'value', i, 'func', on_click))
UIDropDownMenu_AddButton(T('text', ALL, 'value', 0, 'func', on_click))
for i, subclass in temp-list(GetAuctionItemSubClasses(class_index)) do
UIDropDownMenu_AddButton(T('text', subclass, 'value', i, 'func', on_click))
end
end
end
@@ -375,9 +375,9 @@ function initialize_slot_dropdown()
local class_index = UIDropDownMenu_GetSelectedValue(class_dropdown)
local subclass_index = UIDropDownMenu_GetSelectedValue(subclass_dropdown)
if subclass_index and GetAuctionInvTypes(class_index, subclass_index) then
UIDropDownMenu_AddButton(-object('text', ALL, 'value', '', 'func', on_click))
UIDropDownMenu_AddButton(T('text', ALL, 'value', '', 'func', on_click))
for _, slot in {GetAuctionInvTypes(class_index, subclass_index)} do
UIDropDownMenu_AddButton(-object('text', _G[slot], 'value', slot, 'func', on_click))
UIDropDownMenu_AddButton(T('text', _G[slot], 'value', slot, 'func', on_click))
end
end
end
@@ -387,8 +387,8 @@ function initialize_quality_dropdown()
UIDropDownMenu_SetSelectedValue(quality_dropdown, this.value)
update_form()
end
UIDropDownMenu_AddButton(-object('text', ALL, 'value', -1, 'func', on_click))
UIDropDownMenu_AddButton(T('text', ALL, 'value', -1, 'func', on_click))
for i = 0, 4 do
UIDropDownMenu_AddButton(-object('text', _G['ITEM_QUALITY'..i..'_DESC'], 'value', i, 'func', on_click))
UIDropDownMenu_AddButton(T('text', _G['ITEM_QUALITY'..i..'_DESC'], 'value', i, 'func', on_click))
end
end
+3 -3
View File
@@ -56,7 +56,7 @@ do
while getn(searches) > search_index do
tremove(searches)
end
local search = -object('filter_string', filter_string, 'records', t)
local search = T('filter_string', filter_string, 'records', t)
tinsert(searches, search)
if getn(searches) > 5 then
tremove(searches, 1)
@@ -124,7 +124,7 @@ end
function update_auto_buy_filter()
if _G.aux_auto_buy_filter ~= '' then
local queries = filter_util.queries(_G.aux_auto_buy_filter)
local queries = aux.filter_util.queries(_G.aux_auto_buy_filter)
if queries then
if getn(queries) > 1 then
log 'Error: The automatic buyout filter does not support multi-queries'
@@ -319,7 +319,7 @@ function public.execute(resume, real_time)
end
local filter_string = search_box:GetText()
local queries = filter_util.queries(filter_string)
local queries = aux.filter_util.queries(filter_string)
if not queries then
return
elseif real_time then