big refactoring

This commit is contained in:
Manuel Simon Hirsig
2016-08-19 12:32:44 +02:00
parent 7740ba2f7a
commit b37e91b739
8 changed files with 108 additions and 114 deletions
+1 -1
View File
@@ -44,7 +44,7 @@ end
do
local id = 0
function id()
function m.id()
id = id + 1
return id
end
+2 -4
View File
@@ -60,15 +60,13 @@ function _G.aux_module()
local data, metadata, modifier, env, interface
modifier = setmetatable({}, modifier_mt) env = setmetatable({}, env_mt) interface = setmetatable({}, interface_mt)
local function modifier_accessor(key) _modifier_properties[modifier] = DECLARED+PROPERTY[key] return modifier end
data = {_G=_G, [ACCESSOR_KEY]=modifier_accessor, [MUTABLE_KEY]=modifier_accessor, [PUBLIC_KEY]=modifier_accessor}
metadata = setmetatable({_G=DECLARED, [ACCESSOR_KEY]=ACCESSOR, [MUTABLE_KEY]=ACCESSOR, [PUBLIC_KEY]=ACCESSOR}, metadata_mt)
data = {_G=_G, m=env, [ACCESSOR_KEY]=modifier_accessor, [MUTABLE_KEY]=modifier_accessor, [PUBLIC_KEY]=modifier_accessor}
metadata = setmetatable({_G=DECLARED, m=DECLARED, [ACCESSOR_KEY]=ACCESSOR, [MUTABLE_KEY]=ACCESSOR, [PUBLIC_KEY]=ACCESSOR}, metadata_mt)
_data[modifier], _data[env], _data[interface] = data, data, data
_metadata[modifier], _metadata[env], _metadata[interface] = metadata, metadata, metadata
env.mutable.__ = nil
env.m = env -- TODO for compatibility, remove later
env.private = env -- TODO for compatibility, remove later
setfenv(2, env)
return interface
+17 -18
View File
@@ -2,39 +2,38 @@ aux.module 'auctions_tab'
function create_frames()
frame = CreateFrame('Frame', nil, aux.frame)
m.frame:SetAllPoints()
m.frame:SetScript('OnUpdate', m.on_update)
m.frame:Hide()
frame:SetAllPoints()
frame:SetScript('OnUpdate', on_update)
frame:Hide()
m.frame.listing = aux.gui.panel(m.frame)
m.frame.listing:SetPoint('TOP', aux.frame, 'TOP', 0, -8)
m.frame.listing:SetPoint('BOTTOMLEFT', aux.frame.content, 'BOTTOMLEFT', 0, 0)
m.frame.listing:SetPoint('BOTTOMRIGHT', aux.frame.content, 'BOTTOMRIGHT', 0, 0)
frame.listing = aux.gui.panel(frame)
frame.listing:SetPoint('TOP', aux.frame, 'TOP', 0, -8)
frame.listing:SetPoint('BOTTOMLEFT', aux.frame.content, 'BOTTOMLEFT', 0, 0)
frame.listing:SetPoint('BOTTOMRIGHT', aux.frame.content, 'BOTTOMRIGHT', 0, 0)
listing = aux.auction_listing.CreateAuctionResultsTable(m.frame.listing, aux.auction_listing.auctions_config)
m.listing:SetSort(1,2,3,4,5,6,7,8)
m.listing:Reset()
m.listing:SetHandler('OnCellClick', function(cell, button)
if IsAltKeyDown() and m.listing:GetSelection().record == cell.row.data.record and m.cancel_button:IsEnabled() then
m.cancel_button:Click()
listing = aux.auction_listing.CreateAuctionResultsTable(frame.listing, aux.auction_listing.auctions_config)
listing:SetSort(1,2,3,4,5,6,7,8)
listing:Reset()
listing:SetHandler('OnCellClick', function(cell, button)
if IsAltKeyDown() and listing:GetSelection().record == cell.row.data.record and cancel_button:IsEnabled() then
cancel_button:Click()
end
end)
m.listing:SetHandler('OnSelectionChanged', function(rt, datum)
listing:SetHandler('OnSelectionChanged', function(rt, datum)
if not datum then return end
m.find_auction(datum.record)
find_auction(datum.record)
end)
do
local status_bar = aux.gui.status_bar(m.frame)
status_bar = aux.gui.status_bar(frame)
status_bar:SetWidth(265)
status_bar:SetHeight(25)
status_bar:SetPoint('TOPLEFT', aux.frame.content, 'BOTTOMLEFT', 0, -6)
status_bar:update_status(100, 100)
status_bar:set_text('')
status_bar = status_bar
end
do
local btn = aux.gui.button(m.frame, 16)
local btn = aux.gui.button(frame, 16)
btn:SetPoint('TOPLEFT', m.status_bar, 'TOPRIGHT', 5, 0)
btn:SetWidth(80)
btn:SetHeight(24)
+1 -2
View File
@@ -29,13 +29,12 @@ function create_frames()
end)
do
local status_bar = aux.gui.status_bar(m.frame)
status_bar = aux.gui.status_bar(m.frame)
status_bar:SetWidth(265)
status_bar:SetHeight(25)
status_bar:SetPoint('TOPLEFT', aux.frame.content, 'BOTTOMLEFT', 0, -6)
status_bar:update_status(100, 0)
status_bar:set_text('')
status_bar = status_bar
end
do
local btn = aux.gui.button(m.frame, 16)
+22 -22
View File
@@ -274,31 +274,31 @@ end
function update_item_configuration()
if not m.selected_item then
m.refresh_button:Disable()
if not selected_item then
refresh_button:Disable()
m.item.texture:SetTexture(nil)
m.item.count:SetText()
m.item.name:SetTextColor(unpack(aux.gui.color.label.enabled))
m.item.name:SetText('No item selected')
item.texture:SetTexture(nil)
item.count:SetText()
item.name:SetTextColor(unpack(aux.gui.color.label.enabled))
item.name:SetText('No item selected')
m.start_price_frame:Hide()
m.buyout_price_frame:Hide()
m.stack_size_slider:Hide()
m.stack_count_slider:Hide()
m.deposit:Hide()
m.duration_dropdown:Hide()
m.historical_value_button:Hide()
m.hide_checkbox:Hide()
start_price_frame:Hide()
buyout_price_frame:Hide()
stack_size_slider:Hide()
stack_count_slider:Hide()
deposit:Hide()
duration_dropdown:Hide()
historical_value_button:Hide()
hide_checkbox:Hide()
else
m.start_price_frame:Show()
m.buyout_price_frame:Show()
m.stack_size_slider:Show()
m.stack_count_slider:Show()
m.deposit:Show()
m.duration_dropdown:Show()
m.historical_value_button:Show()
m.hide_checkbox:Show()
start_price_frame:Show()
buyout_price_frame:Show()
stack_size_slider:Show()
stack_count_slider:Show()
deposit:Show()
duration_dropdown:Show()
historical_value_button:Show()
hide_checkbox:Show()
m.item.texture:SetTexture(m.selected_item.texture)
m.item.name:SetText('['..m.selected_item.name..']')
+44 -46
View File
@@ -2,32 +2,32 @@ aux.module 'post_tab'
function create_frames()
frame = CreateFrame('Frame', nil, aux.frame)
m.frame:SetAllPoints()
m.frame:SetScript('OnUpdate', m.on_update)
m.frame:Hide()
frame:SetAllPoints()
frame:SetScript('OnUpdate', on_update)
frame:Hide()
m.frame.content = CreateFrame('Frame', nil, m.frame)
m.frame.content:SetPoint('TOP', aux.frame, 'TOP', 0, -8)
m.frame.content:SetPoint('BOTTOMLEFT', aux.frame.content, 'BOTTOMLEFT', 0, 0)
m.frame.content:SetPoint('BOTTOMRIGHT', aux.frame.content, 'BOTTOMRIGHT', 0, 0)
frame.content = CreateFrame('Frame', nil, frame)
frame.content:SetPoint('TOP', aux.frame, 'TOP', 0, -8)
frame.content:SetPoint('BOTTOMLEFT', aux.frame.content, 'BOTTOMLEFT', 0, 0)
frame.content:SetPoint('BOTTOMRIGHT', aux.frame.content, 'BOTTOMRIGHT', 0, 0)
m.frame.inventory = aux.gui.panel(m.frame.content)
m.frame.inventory:SetWidth(212)
m.frame.inventory:SetPoint('TOPLEFT', 0, 0)
m.frame.inventory:SetPoint('BOTTOMLEFT', 0, 0)
frame.inventory = aux.gui.panel(frame.content)
frame.inventory:SetWidth(212)
frame.inventory:SetPoint('TOPLEFT', 0, 0)
frame.inventory:SetPoint('BOTTOMLEFT', 0, 0)
m.frame.parameters = aux.gui.panel(m.frame.content)
m.frame.parameters:SetHeight(173)
m.frame.parameters:SetPoint('TOPLEFT', m.frame.inventory, 'TOPRIGHT', 2.5, 0)
m.frame.parameters:SetPoint('TOPRIGHT', 0, 0)
frame.parameters = aux.gui.panel(frame.content)
frame.parameters:SetHeight(173)
frame.parameters:SetPoint('TOPLEFT', frame.inventory, 'TOPRIGHT', 2.5, 0)
frame.parameters:SetPoint('TOPRIGHT', 0, 0)
m.frame.auctions = aux.gui.panel(m.frame.content)
m.frame.auctions:SetHeight(228)
m.frame.auctions:SetPoint('BOTTOMLEFT', m.frame.inventory, 'BOTTOMRIGHT', 2.5, 0)
m.frame.auctions:SetPoint('BOTTOMRIGHT', 0, 0)
frame.auctions = aux.gui.panel(frame.content)
frame.auctions:SetHeight(228)
frame.auctions:SetPoint('BOTTOMLEFT', frame.inventory, 'BOTTOMRIGHT', 2.5, 0)
frame.auctions:SetPoint('BOTTOMRIGHT', 0, 0)
do
local checkbox = aux.gui.checkbox(m.frame.inventory)
local checkbox = aux.gui.checkbox(frame.inventory)
checkbox:SetPoint('TOPLEFT', 49, -16)
checkbox:SetScript('OnClick', function()
m.refresh = true
@@ -38,13 +38,13 @@ function create_frames()
show_hidden_checkbox = checkbox
end
aux.gui.horizontal_line(m.frame.inventory, -48)
aux.gui.horizontal_line(frame.inventory, -48)
item_listing = aux.item_listing.create(
m.frame.inventory,
frame.inventory,
function()
if arg1 == 'LeftButton' then
m.set_item(this.item_record)
set_item(this.item_record)
elseif arg1 == 'RightButton' then
aux.set_tab(1)
aux.search_tab.set_filter(strlower(aux.info.item(this.item_record.item_id).name)..'/exact')
@@ -52,12 +52,12 @@ function create_frames()
end
end,
function(item_record)
return item_record == m.selected_item
return item_record == selected_item
end
)
auction_listing = aux.listing.CreateScrollingTable(m.frame.auctions)
m.auction_listing:SetColInfo({
auction_listing = aux.listing.CreateScrollingTable(frame.auctions)
auction_listing:SetColInfo({
{ name='Auctions', width=.12, align='CENTER' },
{ name='Left', width=.1, align='CENTER' },
{ name='Qty', width=.08, align='CENTER' },
@@ -66,53 +66,52 @@ function create_frames()
{ name='Buy/ea', width=.22, align='RIGHT' },
{ name='Buy Pct', width=.13, align='CENTER' }
})
m.auction_listing:EnableSorting(false)
m.auction_listing:DisableSelection(true)
m.auction_listing:SetHandler('OnClick', function(table, row_data, column, button)
auction_listing:EnableSorting(false)
auction_listing:DisableSelection(true)
auction_listing:SetHandler('OnClick', function(table, row_data, column, button)
local column_index = aux.util.key(column, column.row.cols)
local unit_start_price, unit_buyout_price = m.undercut(row_data.record, m.stack_size_slider:GetValue(), button == 'RightButton')
local unit_start_price, unit_buyout_price = undercut(row_data.record, stack_size_slider:GetValue(), button == 'RightButton')
if column_index == 3 then
m.stack_size_slider:SetValue(row_data.record.stack_size)
stack_size_slider:SetValue(row_data.record.stack_size)
elseif column_index == 4 then
m.set_unit_start_price(unit_start_price)
set_unit_start_price(unit_start_price)
elseif column_index == 6 then
m.set_unit_buyout_price(unit_buyout_price)
set_unit_buyout_price(unit_buyout_price)
end
end)
do
local status_bar = aux.gui.status_bar(m.frame)
status_bar = aux.gui.status_bar(frame)
status_bar:SetWidth(265)
status_bar:SetHeight(25)
status_bar:SetPoint('TOPLEFT', aux.frame.content, 'BOTTOMLEFT', 0, -6)
status_bar:update_status(100, 100)
status_bar:set_text('')
status_bar = status_bar
end
do
local btn = aux.gui.button(m.frame.parameters, 16)
btn:SetPoint('TOPLEFT', m.status_bar, 'TOPRIGHT', 5, 0)
local btn = aux.gui.button(frame.parameters, 16)
btn:SetPoint('TOPLEFT', status_bar, 'TOPRIGHT', 5, 0)
btn:SetWidth(80)
btn:SetHeight(24)
btn:SetText('Post')
btn:SetScript('OnClick', m.post_auctions)
btn:SetScript('OnClick', post_auctions)
post_button = btn
end
do
local btn = aux.gui.button(m.frame.parameters, 16)
btn:SetPoint('TOPLEFT', m.post_button, 'TOPRIGHT', 5, 0)
local btn = aux.gui.button(frame.parameters, 16)
btn:SetPoint('TOPLEFT', post_button, 'TOPRIGHT', 5, 0)
btn:SetWidth(80)
btn:SetHeight(24)
btn:SetText('Refresh')
btn:SetScript('OnClick', function()
aux.scan.abort(m.scan_id)
aux.scan.abort(scan_id)
m.refresh_entries()
m.refresh = true
end)
refresh_button = btn
end
do
local item = aux.gui.item(m.frame.parameters)
item = aux.gui.item(m.frame.parameters)
item:SetPoint('TOPLEFT', 10, -6)
item.button:SetScript('OnEnter', function()
if m.selected_item then
@@ -122,7 +121,6 @@ function create_frames()
item.button:SetScript('OnLeave', function()
GameTooltip:Hide()
end)
item = item
end
do
local slider = aux.gui.slider(m.frame.parameters)
@@ -130,12 +128,12 @@ function create_frames()
slider:SetPoint('TOPLEFT', 13, -74)
slider:SetWidth(190)
slider:SetScript('OnValueChanged', function()
m.quantity_update(true)
quantity_update(true)
end)
slider.editbox:SetScript('OnTextChanged', function()
slider:SetValue(this:GetNumber())
m.quantity_update(true)
if m.selected_item then
quantity_update(true)
if selected_item then
local settings = m.read_settings()
settings.stack_size = this:GetNumber()
m.write_settings(settings)
+1 -1
View File
@@ -103,7 +103,7 @@ function discard_continuation()
m.update_continuation()
end
function private:update_start_stop()
function update_start_stop()
if m.current_search().active then
m.stop_button:Show()
m.start_button:Hide()
+20 -20
View File
@@ -7,15 +7,15 @@ COPPER_TEXT = '|cffeda55fc|r'
COPPER_PER_SILVER = 100
COPPER_PER_GOLD = 10000
function public.gsc(money)
local gold = floor(money / m.COPPER_PER_GOLD)
local silver = floor(mod(money, m.COPPER_PER_GOLD) / m.COPPER_PER_SILVER)
local copper = mod(money, m.COPPER_PER_SILVER)
function public.to_gsc(money)
local gold = floor(money / COPPER_PER_GOLD)
local silver = floor(mod(money, COPPER_PER_GOLD) / COPPER_PER_SILVER)
local copper = mod(money, COPPER_PER_SILVER)
return gold, silver, copper
end
function public.copper(gold, silver, copper)
return gold * m.COPPER_PER_GOLD + silver * m.COPPER_PER_SILVER + copper
function public.from_gsc(gold, silver, copper)
return gold * COPPER_PER_GOLD + silver * COPPER_PER_SILVER + copper
end
function public.to_string2(money, exact, color)
@@ -34,7 +34,7 @@ function public.to_string2(money, exact, color)
-- Round to nearest silver
money = floor(money / 100 + 0.5) * 100
end
local g, s, c = m.gsc(money)
local g, s, c = to_gsc(money)
local str = ''
@@ -56,15 +56,15 @@ function public.to_string2(money, exact, color)
return str
end
--function public.to_string(params) -- TODOSS
-- local gold, silver, copper = m.gsc(params.copper or 0 + )
--function public.to_string(params) -- TODO
-- local gold, silver, copper = to_gsc(params.copper or 0 + )
-- local settings = aux.util.set(unpack(arg))
--end
function public.to_string(money, pad, trim, decimal_points, color, no_color)
local is_negative = money < 0
money = abs(money)
local gold, silver, copper = m.gsc(money)
local gold, silver, copper = to_gsc(money)
-- rounding
if decimal_points then
@@ -75,29 +75,29 @@ function public.to_string(money, pad, trim, decimal_points, color, no_color)
if no_color then
gold_text, silver_text, copper_text = 'g', 's', 'c'
else
gold_text, silver_text, copper_text = m.GOLD_TEXT, m.SILVER_TEXT, m.COPPER_TEXT
gold_text, silver_text, copper_text = GOLD_TEXT, SILVER_TEXT, COPPER_TEXT
end
local text
if trim then
local parts = {}
if gold > 0 then
tinsert(parts, m.format_number(gold, false, nil, color)..gold_text)
tinsert(parts, format_number(gold, false, nil, color)..gold_text)
end
if silver > 0 then
tinsert(parts, m.format_number(silver, pad, nil, color)..silver_text)
tinsert(parts, format_number(silver, pad, nil, color)..silver_text)
end
if copper > 0 or gold == 0 and silver == 0 then
tinsert(parts, m.format_number(copper, pad, decimal_points, color)..copper_text)
tinsert(parts, format_number(copper, pad, decimal_points, color)..copper_text)
end
text = table.concat(parts, ' ')
else
if gold > 0 then
text = m.format_number(gold, false, nil, color)..gold_text..' '..m.format_number(silver, pad, nil, color)..silver_text..' '..m.format_number(copper, pad, decimal_points, color)..copper_text
text = format_number(gold, false, nil, color)..gold_text..' '..format_number(silver, pad, nil, color)..silver_text..' '..format_number(copper, pad, decimal_points, color)..copper_text
elseif silver > 0 then
text = m.format_number(silver, false, nil, color)..silver_text..' '..m.format_number(copper, pad, decimal_points, color)..copper_text
text = format_number(silver, false, nil, color)..silver_text..' '..format_number(copper, pad, decimal_points, color)..copper_text
else
text = m.format_number(copper, false, decimal_points, color)..copper_text
text = format_number(copper, false, decimal_points, color)..copper_text
end
end
@@ -114,7 +114,7 @@ end
function public.from_string(value)
if aux.temp(tonumber(value)) and __ >= 0 then
return __ * m.COPPER_PER_GOLD
return __ * COPPER_PER_GOLD
end
-- remove any colors
@@ -131,8 +131,8 @@ function public.from_string(value)
value = gsub(value, '%d*%.?%d+s', '', 1)
value = gsub(value, '%d*%.?%d+c', '', 1)
if strfind(value, '%S') then return end
return m.copper(gold or 0, silver or 0, copper or 0)
return from_gsc(gold or 0, silver or 0, copper or 0)
end
function public.format_number(num, pad, decimal_padding, color)