big refactoring

This commit is contained in:
Manuel Simon Hirsig
2016-08-19 11:57:12 +02:00
parent 667990f7d8
commit 7740ba2f7a
28 changed files with 271 additions and 266 deletions
+28 -28
View File
@@ -4,11 +4,11 @@ aux.tab(2, 'Post')
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'}}
private.existing_auctions = {}
private.inventory_records = nil
private.scan_id = 0
private.selected_item = nil
private.refresh = nil
existing_auctions = {}
inventory_records = nil
scan_id = 0
selected_item = nil
refresh = nil
function m.LOAD()
m.create_frames()
@@ -36,7 +36,7 @@ function m.USE_ITEM(item_info)
m.select_item(item_info.item_key)
end
function private.default_settings()
function default_settings()
return {
duration = DURATION_8,
stack_size = 1,
@@ -46,7 +46,7 @@ function private.default_settings()
}
end
function private.read_settings(item_key)
function read_settings(item_key)
item_key = item_key or m.selected_item.key
local dataset = aux.persistence.load_dataset()
dataset.post = dataset.post or {}
@@ -60,7 +60,7 @@ function private.read_settings(item_key)
return settings
end
function private.write_settings(settings, item_key)
function write_settings(settings, item_key)
item_key = item_key or m.selected_item.key
local dataset = aux.persistence.load_dataset()
@@ -69,25 +69,25 @@ function private.write_settings(settings, item_key)
dataset.post[item_key] = aux.persistence.write(settings_schema, settings)
end
function private.get_unit_start_price()
function get_unit_start_price()
local money_text = m.unit_start_price:GetText()
return aux.money.from_string(money_text) or 0
end
function private.set_unit_start_price(amount)
function set_unit_start_price(amount)
m.unit_start_price:SetText(aux.money.to_string(amount, true, nil, 3))
end
function private.get_unit_buyout_price()
function get_unit_buyout_price()
local money_text = m.unit_buyout_price:GetText()
return aux.money.from_string(money_text) or 0
end
function private.set_unit_buyout_price(amount)
function set_unit_buyout_price(amount)
m.unit_buyout_price:SetText(aux.money.to_string(amount, true, nil, 3))
end
function private.update_inventory_listing()
function update_inventory_listing()
if not m.ACTIVE() then
return
end
@@ -98,7 +98,7 @@ function private.update_inventory_listing()
end)))
end
function private.update_auction_listing()
function update_auction_listing()
if not m.ACTIVE() then
return
end
@@ -183,7 +183,7 @@ function public.select_item(item_key)
end
end
function private.price_update()
function price_update()
if m.selected_item then
local settings = m.read_settings()
@@ -201,7 +201,7 @@ function private.price_update()
end
end
function private.post_auctions()
function post_auctions()
if m.selected_item then
local unit_start_price = m.get_unit_start_price()
local unit_buyout_price = m.get_unit_buyout_price()
@@ -247,7 +247,7 @@ function private.post_auctions()
end
end
function private.validate_parameters()
function validate_parameters()
if not m.selected_item then
m.post_button:Disable()
@@ -272,7 +272,7 @@ function private.validate_parameters()
m.post_button:Enable()
end
function private.update_item_configuration()
function update_item_configuration()
if not m.selected_item then
m.refresh_button:Disable()
@@ -327,7 +327,7 @@ function private.update_item_configuration()
end
end
function private.undercut(record, stack_size, stack)
function undercut(record, stack_size, stack)
local start_price = aux.util.round(record.unit_blizzard_bid * (stack and record.stack_size or stack_size))
local buyout_price = aux.util.round(record.unit_buyout_price * (stack and record.stack_size or stack_size))
@@ -339,7 +339,7 @@ function private.undercut(record, stack_size, stack)
return start_price / stack_size, buyout_price / stack_size
end
function private.quantity_update(max_count)
function quantity_update(max_count)
if m.selected_item then
local max_stack_count = m.selected_item.max_charges and m.selected_item.availability[m.stack_size_slider:GetValue()] or floor(m.selected_item.availability[0] / m.stack_size_slider:GetValue())
m.stack_count_slider:SetMinMaxValues(1, max_stack_count)
@@ -350,7 +350,7 @@ function private.quantity_update(max_count)
m.refresh = true
end
function private.unit_vendor_price(item_key)
function unit_vendor_price(item_key)
for slot in aux.util.inventory() do
@@ -374,7 +374,7 @@ function private.unit_vendor_price(item_key)
end
end
function private.update_historical_value_button()
function update_historical_value_button()
if m.selected_item then
local historical_value = aux.history.value(m.selected_item.key)
m.historical_value_button.amount = historical_value
@@ -382,7 +382,7 @@ function private.update_historical_value_button()
end
end
function private.set_item(item)
function set_item(item)
local settings = m.read_settings(item.key)
item.unit_vendor_price = m.unit_vendor_price(item.key)
@@ -417,7 +417,7 @@ function private.set_item(item)
m.refresh = true
end
function private.update_inventory_records()
function update_inventory_records()
m.inventory_records = {}
m.refresh = true
@@ -470,7 +470,7 @@ function private.update_inventory_records()
m.refresh = true
end
function private.refresh_entries()
function refresh_entries()
if m.selected_item then
local item_id, suffix_id = m.selected_item.item_id, m.selected_item.suffix_id
local item_key = item_id..':'..suffix_id
@@ -518,7 +518,7 @@ function private.refresh_entries()
end
end
function private.record_auction(key, aux_quantity, unit_blizzard_bid, unit_buyout_price, duration, owner)
function record_auction(key, aux_quantity, unit_blizzard_bid, unit_buyout_price, duration, owner)
m.existing_auctions[key] = m.existing_auctions[key] or {}
local entry
for _, existing_entry in m.existing_auctions[key] do
@@ -544,7 +544,7 @@ function private.record_auction(key, aux_quantity, unit_blizzard_bid, unit_buyou
return entry
end
function private.on_update()
function on_update()
if m.refresh then
m.refresh = false
m.price_update()
@@ -557,7 +557,7 @@ function private.on_update()
m.validate_parameters()
end
function private.initialize_duration_dropdown()
function initialize_duration_dropdown()
local function on_click()
UIDropDownMenu_SetSelectedValue(m.duration_dropdown, this.value)
+21 -21
View File
@@ -1,7 +1,7 @@
aux.module 'post_tab'
function private.create_frames()
private.frame = CreateFrame('Frame', nil, aux.frame)
function create_frames()
frame = CreateFrame('Frame', nil, aux.frame)
m.frame:SetAllPoints()
m.frame:SetScript('OnUpdate', m.on_update)
m.frame:Hide()
@@ -35,12 +35,12 @@ function private.create_frames()
local label = aux.gui.label(checkbox, aux.gui.config.small_font_size)
label:SetPoint('LEFT', checkbox, 'RIGHT', 4, 1)
label:SetText('Show hidden items')
private.show_hidden_checkbox = checkbox
show_hidden_checkbox = checkbox
end
aux.gui.horizontal_line(m.frame.inventory, -48)
private.item_listing = aux.item_listing.create(
item_listing = aux.item_listing.create(
m.frame.inventory,
function()
if arg1 == 'LeftButton' then
@@ -56,7 +56,7 @@ function private.create_frames()
end
)
private.auction_listing = aux.listing.CreateScrollingTable(m.frame.auctions)
auction_listing = aux.listing.CreateScrollingTable(m.frame.auctions)
m.auction_listing:SetColInfo({
{ name='Auctions', width=.12, align='CENTER' },
{ name='Left', width=.1, align='CENTER' },
@@ -87,7 +87,7 @@ function private.create_frames()
status_bar:SetPoint('TOPLEFT', aux.frame.content, 'BOTTOMLEFT', 0, -6)
status_bar:update_status(100, 100)
status_bar:set_text('')
private.status_bar = status_bar
status_bar = status_bar
end
do
local btn = aux.gui.button(m.frame.parameters, 16)
@@ -96,7 +96,7 @@ function private.create_frames()
btn:SetHeight(24)
btn:SetText('Post')
btn:SetScript('OnClick', m.post_auctions)
private.post_button = btn
post_button = btn
end
do
local btn = aux.gui.button(m.frame.parameters, 16)
@@ -109,7 +109,7 @@ function private.create_frames()
m.refresh_entries()
m.refresh = true
end)
private.refresh_button = btn
refresh_button = btn
end
do
local item = aux.gui.item(m.frame.parameters)
@@ -122,7 +122,7 @@ function private.create_frames()
item.button:SetScript('OnLeave', function()
GameTooltip:Hide()
end)
private.item = item
item = item
end
do
local slider = aux.gui.slider(m.frame.parameters)
@@ -153,7 +153,7 @@ function private.create_frames()
slider.editbox:SetNumeric(true)
slider.editbox:SetMaxLetters(3)
slider.label:SetText('Stack Size')
private.stack_size_slider = slider
stack_size_slider = slider
end
do
local slider = aux.gui.slider(m.frame.parameters)
@@ -176,7 +176,7 @@ function private.create_frames()
end)
slider.editbox:SetNumeric(true)
slider.label:SetText('Stack Count')
private.stack_count_slider = slider
stack_count_slider = slider
end
do
local dropdown = aux.gui.dropdown(m.frame.parameters)
@@ -189,12 +189,12 @@ function private.create_frames()
dropdown:SetScript('OnShow', function()
UIDropDownMenu_Initialize(this, m.initialize_duration_dropdown)
end)
private.duration_dropdown = dropdown
duration_dropdown = dropdown
end
do
local label = aux.gui.label(m.frame.parameters, aux.gui.config.medium_font_size)
label:SetPoint('LEFT', m.duration_dropdown, 'RIGHT', 25, 0)
private.deposit = label
deposit = label
end
do
local checkbox = aux.gui.checkbox(m.frame.parameters)
@@ -208,11 +208,11 @@ function private.create_frames()
local label = aux.gui.label(checkbox, aux.gui.config.small_font_size)
label:SetPoint('LEFT', checkbox, 'RIGHT', 4, 1)
label:SetText('Hide this item')
private.hide_checkbox = checkbox
hide_checkbox = checkbox
end
do
local frame = CreateFrame('Frame', nil, m.frame.parameters)
private.start_price_frame = frame
start_price_frame = frame
aux.gui.set_content_style(frame)
frame:SetPoint('TOPRIGHT', m.frame.parameters, 'TOPRIGHT', -71, -60)
frame:SetWidth(180)
@@ -260,13 +260,13 @@ function private.create_frames()
label:SetPoint('LEFT', frame, 'RIGHT', 8, 0)
label:SetWidth(50)
label:SetJustifyH('CENTER')
private.start_price_percentage = label
start_price_percentage = label
end
private.unit_start_price = editbox
unit_start_price = editbox
end
do
local frame = CreateFrame('Frame', nil, m.frame.parameters)
private.buyout_price_frame = frame
buyout_price_frame = frame
aux.gui.set_content_style(frame)
frame:SetPoint('TOPRIGHT', m.unit_start_price, 'BOTTOMRIGHT', 0, -19)
frame:SetWidth(180)
@@ -315,9 +315,9 @@ function private.create_frames()
label:SetPoint('LEFT', frame, 'RIGHT', 8, 0)
label:SetWidth(50)
label:SetJustifyH('CENTER')
private.buyout_price_percentage = label
buyout_price_percentage = label
end
private.unit_buyout_price = editbox
unit_buyout_price = editbox
end
do
local btn = aux.gui.button(m.frame.parameters, 14)
@@ -335,6 +335,6 @@ function private.create_frames()
local label = aux.gui.label(btn, aux.gui.config.small_font_size)
label:SetPoint('BOTTOMLEFT', btn, 'TOPLEFT', -2, 1)
label:SetText('Historical Value')
private.historical_value_button = btn
historical_value_button = btn
end
end