module refactoring

This commit is contained in:
Manuel Simon Hirsig
2017-11-25 17:53:39 +01:00
parent 6f71167e48
commit ab94acc2be
38 changed files with 402 additions and 453 deletions
+34 -36
View File
@@ -1,9 +1,7 @@
module 'aux.gui.auction_listing'
include 'aux'
local T = require 'T'
local aux = require 'aux'
local info = require 'aux.util.info'
local sort_util = require 'aux.util.sort'
local money = require 'aux.util.money'
@@ -17,10 +15,10 @@ local HEAD_HEIGHT = 27
local HEAD_SPACE = 2
local TIME_LEFT_STRINGS = {
color.red'30m', -- Short
color.orange'2h', -- Medium
color.yellow'8h', -- Long
color.blue'24h', -- Very Long
aux.color.red'30m', -- Short
aux.color.orange'2h', -- Medium
aux.color.yellow'8h', -- Long
aux.color.blue'24h', -- Very Long
}
function item_column_init(rt, cell)
@@ -81,7 +79,7 @@ M.search_columns = {
align = 'CENTER',
fill = function(cell, record)
local display_level = max(record.level, 1)
display_level = UnitLevel'player' < record.level and color.red(display_level) or display_level
display_level = UnitLevel'player' < record.level and aux.color.red(display_level) or display_level
cell.text:SetText(display_level)
end,
cmp = function(record_a, record_b, desc)
@@ -93,9 +91,9 @@ M.search_columns = {
width = .06,
align = 'CENTER',
fill = function(cell, record, count, own, expandable)
local numAuctionsText = expandable and color.link(count) or count
local numAuctionsText = expandable and aux.color.link(count) or count
if own > 0 then
numAuctionsText = numAuctionsText .. (' ' .. color.yellow('(' .. own .. ')'))
numAuctionsText = numAuctionsText .. (' ' .. aux.color.yellow('(' .. own .. ')'))
end
cell.text:SetText(numAuctionsText)
end,
@@ -139,7 +137,7 @@ M.search_columns = {
width = .13,
align = 'CENTER',
fill = function(cell, record)
cell.text:SetText(info.is_player(record.owner) and (color.yellow(record.owner)) or (record.owner or '?'))
cell.text:SetText(info.is_player(record.owner) and (aux.color.yellow(record.owner)) or (record.owner or '?'))
end,
cmp = function(record_a, record_b, desc)
if not record_a.owner and not record_b.owner then
@@ -161,9 +159,9 @@ M.search_columns = {
fill = function(cell, record)
local price_color
if record.high_bidder then
price_color = color.green
price_color = aux.color.green
elseif record.high_bid ~= 0 then
price_color = color.orange
price_color = aux.color.orange
end
local price
if record.high_bidder then
@@ -213,8 +211,8 @@ M.search_columns = {
cmp = function(record_a, record_b, desc)
local price_a = price_per_unit and record_a.unit_buyout_price or record_a.buyout_price
local price_b = price_per_unit and record_b.unit_buyout_price or record_b.buyout_price
price_a = price_a > 0 and price_a or (desc and -huge or huge)
price_b = price_b > 0 and price_b or (desc and -huge or huge)
price_a = price_a > 0 and price_a or (desc and -aux.huge or aux.huge)
price_b = price_b > 0 and price_b or (desc and -aux.huge or aux.huge)
return sort_util.compare(price_a, price_b, desc)
end,
@@ -228,8 +226,8 @@ M.search_columns = {
cell.text:SetText((pct or bidPct) and gui.percentage_historical(pct or bidPct, not pct) or '?')
end,
cmp = function(record_a, record_b, desc)
local pct_a = record_percentage(record_a) or (desc and -huge or huge)
local pct_b = record_percentage(record_b) or (desc and -huge or huge)
local pct_a = record_percentage(record_a) or (desc and -aux.huge or aux.huge)
local pct_b = record_percentage(record_b) or (desc and -aux.huge or aux.huge)
return sort_util.compare(pct_a, pct_b, desc)
end,
},
@@ -251,7 +249,7 @@ M.auctions_columns = {
align = 'CENTER',
fill = function(cell, record)
local display_level = max(record.level, 1)
display_level = UnitLevel('player') < record.level and color.red(display_level) or display_level
display_level = UnitLevel('player') < record.level and aux.color.red(display_level) or display_level
cell.text:SetText(display_level)
end,
cmp = function(record_a, record_b, desc)
@@ -263,7 +261,7 @@ M.auctions_columns = {
width = .06,
align = 'CENTER',
fill = function(cell, record, count, own, expandable)
local numAuctionsText = expandable and color.link(count) or count
local numAuctionsText = expandable and aux.color.link(count) or count
cell.text:SetText(numAuctionsText)
end,
cmp = function(record_a, record_b, desc)
@@ -343,8 +341,8 @@ M.auctions_columns = {
cmp = function(record_a, record_b, desc)
local price_a = price_per_unit and record_a.unit_buyout_price or record_a.buyout_price
local price_b = price_per_unit and record_b.unit_buyout_price or record_b.buyout_price
price_a = price_a > 0 and price_a or (desc and -huge or huge)
price_b = price_b > 0 and price_b or (desc and -huge or huge)
price_a = price_a > 0 and price_a or (desc and -aux.huge or aux.huge)
price_b = price_b > 0 and price_b or (desc and -aux.huge or aux.huge)
return sort_util.compare(price_a, price_b, desc)
end,
@@ -354,7 +352,7 @@ M.auctions_columns = {
width = .21,
align = 'CENTER',
fill = function(cell, record)
cell.text:SetText(record.high_bidder or color.red 'No Bids')
cell.text:SetText(record.high_bidder or aux.color.red 'No Bids')
end,
cmp = function(record_a, record_b, desc)
if not record_a.high_bidder and not record_b.high_bidder then
@@ -385,7 +383,7 @@ M.bids_columns = {
width = .06,
align = 'CENTER',
fill = function(cell, record, count, own, expandable)
local numAuctionsText = expandable and color.link(count) or count
local numAuctionsText = expandable and aux.color.link(count) or count
cell.text:SetText(numAuctionsText)
end,
cmp = function(record_a, record_b, desc)
@@ -428,7 +426,7 @@ M.bids_columns = {
width = .13,
align = 'CENTER',
fill = function(cell, record)
cell.text:SetText(info.is_player(record.owner) and (color.yellow(record.owner)) or (record.owner or '?'))
cell.text:SetText(info.is_player(record.owner) and (aux.color.yellow(record.owner)) or (record.owner or '?'))
end,
cmp = function(record_a, record_b, desc)
if not record_a.owner and not record_b.owner then
@@ -484,8 +482,8 @@ M.bids_columns = {
cmp = function(record_a, record_b, desc)
local price_a = price_per_unit and record_a.unit_buyout_price or record_a.buyout_price
local price_b = price_per_unit and record_b.unit_buyout_price or record_b.buyout_price
price_a = price_a > 0 and price_a or (desc and -huge or huge)
price_b = price_b > 0 and price_b or (desc and -huge or huge)
price_a = price_a > 0 and price_a or (desc and -aux.huge or aux.huge)
price_b = price_b > 0 and price_b or (desc and -aux.huge or aux.huge)
return sort_util.compare(price_a, price_b, desc)
end,
@@ -497,9 +495,9 @@ M.bids_columns = {
fill = function(cell, record)
local status
if record.high_bidder then
status = color.yellow'High Bidder'
status = aux.color.yellow'High Bidder'
else
status = color.red'Outbid'
status = aux.color.red'Outbid'
end
cell.text:SetText(status)
end,
@@ -515,9 +513,9 @@ function record_percentage(record)
local historical_value = history.value(record.item_key) or 0
if historical_value > 0 then
if record.unit_buyout_price > 0 then
return round(100 * record.unit_buyout_price / historical_value)
return aux.round(100 * record.unit_buyout_price / historical_value)
end
return nil, round(100 * record.unit_bid_price / historical_value)
return nil, aux.round(100 * record.unit_bid_price / historical_value)
end
end
@@ -612,7 +610,7 @@ local methods = {
if not selection or selection.record ~= this.record then
this.rt:SetSelectedRecord(this.record)
end
do (this.rt.handlers.OnClick or nop)(this, button) end
do (this.rt.handlers.OnClick or pass)(this, button) end
end
end,
@@ -645,7 +643,7 @@ local methods = {
local records = self.records
local single_item = all(records, function(record) return record.item_key == records[1].item_key end)
local single_item = aux.all(records, function(record) return record.item_key == records[1].item_key end)
sort(records, function(a, b) return a.search_signature < b.search_signature or a.search_signature == b.search_signature and tostring(a) < tostring(b) end)
@@ -840,7 +838,7 @@ local methods = {
end,
RemoveAuctionRecord = function(self, record)
local index = key(self.records, record)
local index = aux.key(self.records, record)
if index then
tremove(self.records, index)
end
@@ -848,7 +846,7 @@ local methods = {
end,
ContainsRecord = function(self, record)
if key(self.records, record) then
if aux.key(self.records, record) then
return true
end
end,
@@ -930,7 +928,7 @@ function M.new(parent, rows, columns)
scrollBar:SetWidth(10)
local thumbTex = scrollBar:GetThumbTexture()
thumbTex:SetPoint('CENTER', 0, 0)
thumbTex:SetTexture(color.content.background())
thumbTex:SetTexture(aux.color.content.background())
thumbTex:SetHeight(150)
thumbTex:SetWidth(scrollBar:GetWidth())
_G[scrollBar:GetName() .. 'ScrollUpButton']:Hide()
@@ -955,7 +953,7 @@ function M.new(parent, rows, columns)
local text = cell:CreateFontString()
text:SetJustifyH('CENTER')
text:SetFont(gui.font, 12)
text:SetTextColor(color.label.enabled())
text:SetTextColor(aux.color.label.enabled())
cell:SetFontString(text)
if not column.isPrice then cell:SetText(column.title or '') end -- TODO
text:SetAllPoints()
+46 -47
View File
@@ -1,18 +1,17 @@
module 'aux.gui'
include 'aux'
local T = require 'T'
local aux = require 'aux'
M.font = [[Fonts\ARIALN.TTF]]
M.font_size = immutable-{
M.font_size = aux.immutable-{
small = 13,
medium = 15,
large = 18,
}
--function handle.LOAD()
--function aux.handle.LOAD()
-- do
-- local blizzard_backdrop, aux_background, aux_border
--
@@ -22,14 +21,14 @@ M.font_size = immutable-{
-- aux_border:SetPoint('BOTTOMRIGHT', DropDownList1Backdrop, 'BOTTOMRIGHT', 1.5, -1.5)
-- aux_border:SetBlendMode('ADD')
-- aux_background = DropDownList1:CreateTexture(nil, 'OVERLAY')
-- aux_background:SetTexture(color.content.background())
-- aux_background:SetTexture(aux.color.content.background())
-- aux_background:SetAllPoints(DropDownList1Backdrop)
-- blizzard_backdrop = DropDownList1Backdrop:GetBackdrop()
-- hook('ToggleDropDownMenu', function(...)
-- aux.hook('ToggleDropDownMenu', function(...)
-- T.temp(arg)
-- local ret = T.temp-T.list(orig.ToggleDropDownMenu(unpack(arg)))
-- local ret = T.temp-T.list(aux.orig.ToggleDropDownMenu(unpack(arg)))
-- local dropdown = _G[arg[4] or ''] or this:GetParent()
-- if strfind(dropdown:GetName() or '', '^AuxFrame%d+$') then
-- if strfind(dropdown:GetName() or '', '^aux.frame%d+$') then
-- set_aux_dropdown_style(dropdown)
-- else
-- set_blizzard_dropdown_style()
@@ -91,7 +90,7 @@ do
local id = 1
function M.unique_name()
id = id + 1
return 'AuxFrame' .. id
return 'aux.frame' .. id
end
end
@@ -120,15 +119,15 @@ function M.set_frame_style(frame, backdrop_color, border_color, left, right, top
end
function M.set_window_style(frame, left, right, top, bottom)
set_frame_style(frame, color.window.background, color.window.border, left, right, top, bottom)
set_frame_style(frame, aux.color.window.background, aux.color.window.border, left, right, top, bottom)
end
function M.set_panel_style(frame, left, right, top, bottom)
set_frame_style(frame, color.panel.background, color.panel.border, left, right, top, bottom)
set_frame_style(frame, aux.color.panel.background, aux.color.panel.border, left, right, top, bottom)
end
function M.set_content_style(frame, left, right, top, bottom)
set_frame_style(frame, color.content.background, color.content.border, left, right, top, bottom)
set_frame_style(frame, aux.color.content.background, aux.color.content.border, left, right, top, bottom)
end
function M.panel(parent)
@@ -140,13 +139,13 @@ end
function M.checkbutton(parent, text_height)
local button = button(parent, text_height)
button.state = false
button:SetBackdropColor(color.state.disabled())
button:SetBackdropColor(aux.color.state.disabled())
function button:SetChecked(state)
if state then
self:SetBackdropColor(color.state.enabled())
self:SetBackdropColor(aux.color.state.enabled())
self.state = true
else
self:SetBackdropColor(color.state.disabled())
self:SetBackdropColor(aux.color.state.disabled())
self.state = false
end
end
@@ -171,19 +170,19 @@ function M.button(parent, text_height)
label:SetAllPoints(button)
label:SetJustifyH('CENTER')
label:SetJustifyV('CENTER')
label:SetTextColor(color.text.enabled())
label:SetTextColor(aux.color.text.enabled())
button:SetFontString(label)
end
button.default_Enable = button.Enable
function button:Enable()
if self:IsEnabled() == 1 then return end
self:GetFontString():SetTextColor(color.text.enabled())
self:GetFontString():SetTextColor(aux.color.text.enabled())
return self:default_Enable()
end
button.default_Disable = button.Disable
function button:Disable()
if self:IsEnabled() == 0 then return end
self:GetFontString():SetTextColor(color.text.disabled())
self:GetFontString():SetTextColor(aux.color.text.disabled())
return self:default_Disable()
end
@@ -209,7 +208,7 @@ do
dock:SetPoint('TOPLEFT', 1, 1)
dock:SetPoint('TOPRIGHT', -1, 1)
end
dock:SetTexture(color.panel.background())
dock:SetTexture(aux.color.panel.background())
tab.dock = dock
local highlight = tab:CreateTexture(nil, 'HIGHLIGHT')
highlight:SetAllPoints()
@@ -253,20 +252,20 @@ do
function mt.__index:select(id)
self._selected = id
self:update()
do (self._on_select or nop)(id) end
do (self._on_select or pass)(id) end
end
function mt.__index:update()
for _, tab in self._tabs do
if tab.group._selected == tab.id then
tab.text:SetTextColor(color.label.enabled())
tab.text:SetTextColor(aux.color.label.enabled())
tab:Disable()
tab:SetBackdropColor(color.panel.background())
tab:SetBackdropColor(aux.color.panel.background())
tab.dock:Show()
tab:SetHeight(29)
else
tab.text:SetTextColor(color.text.enabled())
tab.text:SetTextColor(aux.color.text.enabled())
tab:Enable()
tab:SetBackdropColor(color.content.background())
tab:SetBackdropColor(aux.color.content.background())
tab.dock:Hide()
tab:SetHeight(24)
end
@@ -292,9 +291,9 @@ function M.editbox(parent)
set_content_style(editbox)
editbox:SetScript('OnEscapePressed', function()
this:ClearFocus()
do (this.escape or nop)() end
do (this.escape or pass)() end
end)
editbox:SetScript('OnEnterPressed', function() (this.enter or nop)() end)
editbox:SetScript('OnEnterPressed', function() (this.enter or pass)() end)
editbox:SetScript('OnEditFocusGained', function()
if this.block_focus then
this.block_focus = false
@@ -302,10 +301,10 @@ function M.editbox(parent)
return
end
this.overlay:Hide()
this:SetTextColor(color.text.enabled())
this:SetTextColor(aux.color.text.enabled())
this.focused = true
this:HighlightText()
do (this.focus_gain or nop)() end
do (this.focus_gain or pass)() end
end)
editbox:SetScript('OnEditFocusLost', function()
this.overlay:Show()
@@ -313,13 +312,13 @@ function M.editbox(parent)
this.focused = false
this:HighlightText(0, 0)
this:SetScript('OnUpdate', nil)
do (this.focus_loss or nop)() end
do (this.focus_loss or pass)() end
end)
editbox:SetScript('OnTextChanged', function()
this.overlay:SetText(this.formatter and this.formatter(this:GetText()) or this:GetText())
do (this.change or nop)() end
do (this.change or pass)() end
end)
editbox:SetScript('OnChar', function() (this.char or nop)() end)
editbox:SetScript('OnChar', function() (this.char or pass)() end)
do
local last_click = T.map('t', 0)
editbox:SetScript('OnMouseDown', function()
@@ -332,7 +331,7 @@ function M.editbox(parent)
-- local offset = x - editbox:GetLeft()*editbox:GetEffectiveScale() TODO use a fontstring to measure getstringwidth for structural highlighting
-- or use an overlay with itemlinks
if GetTime() - last_click.t < .5 and x == last_click.x and y == last_click.y then
thread(function() editbox:HighlightText() end)
aux.thread(function() editbox:HighlightText() end)
end
T.wipe(last_click)
last_click.t = GetTime()
@@ -352,7 +351,7 @@ function M.editbox(parent)
local overlay = label(editbox)
overlay:SetPoint('LEFT', 1.5, 0)
overlay:SetPoint('RIGHT', -1.5, 0)
overlay:SetTextColor(color.text.enabled())
overlay:SetTextColor(aux.color.text.enabled())
editbox.overlay = overlay
editbox:SetAlignment('LEFT')
editbox:SetFontSize(font_size.medium)
@@ -398,7 +397,7 @@ do
text_frame:SetFrameLevel(level + 4)
text_frame:SetAllPoints(self)
local text = label(text_frame, font_size.medium)
text:SetTextColor(color.text.enabled())
text:SetTextColor(aux.color.text.enabled())
text:SetPoint('CENTER', 0, 0)
self.text = text
end
@@ -439,7 +438,7 @@ end
function M.label(parent, size)
local label = parent:CreateFontString()
label:SetFont(font, size or font_size.small)
label:SetTextColor(color.label.enabled())
label:SetTextColor(aux.color.label.enabled())
return label
end
@@ -449,9 +448,9 @@ function M.horizontal_line(parent, y_offset, inverted_color)
texture:SetPoint('TOPRIGHT', parent, 'TOPRIGHT', -2, y_offset)
texture:SetHeight(2)
if inverted_color then
texture:SetTexture(color.panel.background())
texture:SetTexture(aux.color.panel.background())
else
texture:SetTexture(color.content.background())
texture:SetTexture(aux.color.content.background())
end
return texture
end
@@ -462,9 +461,9 @@ function M.vertical_line(parent, x_offset, top_offset, bottom_offset, inverted_c
texture:SetPoint('BOTTOMLEFT', parent, 'BOTTOMLEFT', x_offset, bottom_offset or 2)
texture:SetWidth(2)
if inverted_color then
texture:SetTexture(color.panel.background())
texture:SetTexture(aux.color.panel.background())
else
texture:SetTexture(color.content.background())
texture:SetTexture(aux.color.content.background())
end
return texture
end
@@ -504,7 +503,7 @@ function M.slider(parent)
set_panel_style(slider)
local thumb_texture = slider:CreateTexture(nil, 'ARTWORK')
thumb_texture:SetPoint('CENTER', 0, 0)
thumb_texture:SetTexture(color.content.background())
thumb_texture:SetTexture(aux.color.content.background())
thumb_texture:SetHeight(18)
thumb_texture:SetWidth(8)
set_size(thumb_texture, 8, 18)
@@ -516,7 +515,7 @@ function M.slider(parent)
label:SetJustifyH('LEFT')
label:SetHeight(13)
label:SetFont(font, font_size.small)
label:SetTextColor(color.label.enabled())
label:SetTextColor(aux.color.label.enabled())
local editbox = editbox(slider)
editbox:SetPoint('LEFT', slider, 'RIGHT', 5, 0)
@@ -555,16 +554,16 @@ end
function M.percentage_historical(pct, bid)
local text = (pct > 10000 and '>10000' or pct) .. '%'
if bid then
return color.gray(text)
return aux.color.gray(text)
elseif pct < 50 then
return color.blue(text)
return aux.color.blue(text)
elseif pct < 80 then
return color.green(text)
return aux.color.green(text)
elseif pct < 110 then
return color.yellow(text)
return aux.color.yellow(text)
elseif pct < 135 then
return color.orange(text)
return aux.color.orange(text)
else
return color.red(text)
return aux.color.red(text)
end
end
+2 -4
View File
@@ -1,9 +1,7 @@
module 'aux.gui.item_listing'
include 'aux'
local T = require 'T'
local aux = require 'aux'
local info = require 'aux.util.info'
local gui = require 'aux.gui'
@@ -66,7 +64,7 @@ function M.new(parent, on_click, selected)
scroll_bar:SetWidth(10)
local thumbTex = scroll_bar:GetThumbTexture()
thumbTex:SetPoint('CENTER', 0, 0)
thumbTex:SetTexture(color.content.background())
thumbTex:SetTexture(aux.color.content.background())
thumbTex:SetHeight(150)
thumbTex:SetWidth(scroll_bar:GetWidth())
_G[scroll_bar:GetName() .. 'ScrollUpButton']:Hide()
+3 -5
View File
@@ -1,9 +1,7 @@
module 'aux.gui.listing'
include 'aux'
local T = require 'T'
local aux = require 'aux'
local gui = require 'aux.gui'
local ROW_HEIGHT = 15
@@ -175,7 +173,7 @@ local methods = {
local text = col:CreateFontString()
text:SetAllPoints()
text:SetFont(gui.font, 12)
text:SetTextColor(color.label.enabled())
text:SetTextColor(aux.color.label.enabled())
col.text = text
local tex = col:CreateTexture()
@@ -283,7 +281,7 @@ function M.new(parent)
scroll_bar:SetWidth(10)
local thumbTex = scroll_bar:GetThumbTexture()
thumbTex:SetPoint('CENTER', 0, 0)
thumbTex:SetTexture(color.content.background())
thumbTex:SetTexture(aux.color.content.background())
thumbTex:SetHeight(150)
thumbTex:SetWidth(scroll_bar:GetWidth())
_G[scroll_bar:GetName() .. 'ScrollUpButton']:Hide()