aux auto bid and price heuristics

this commit does two things
1. it implements auto bid just like auto buy
2. it has some minimum pricing heuristics when posting items. this behavoiur actiaves when the post bid price is set to 0, the buyout price behaves like a minimum
This commit is contained in:
geojak
2022-02-20 23:51:19 +01:00
committed by GitHub
parent 9771521c78
commit 02cfc420dd
42 changed files with 8791 additions and 0 deletions
File diff suppressed because it is too large Load Diff
+569
View File
@@ -0,0 +1,569 @@
module 'aux.gui'
local T = require 'T'
local aux = require 'aux'
M.font = [[Fonts\ARIALN.TTF]]
M.font_size = aux.immutable-{
small = 13,
medium = 15,
large = 18,
}
--function aux.handle.LOAD()
-- do
-- local blizzard_backdrop, aux_background, aux_border
--
-- aux_border = DropDownList1:CreateTexture()
-- aux_border:SetTexture(1, 1, 1, .02)
-- aux_border:SetPoint('TOPLEFT', DropDownList1Backdrop, 'TOPLEFT', -2, 2)
-- aux_border:SetPoint('BOTTOMRIGHT', DropDownList1Backdrop, 'BOTTOMRIGHT', 1.5, -1.5)
-- aux_border:SetBlendMode('ADD')
-- aux_background = DropDownList1:CreateTexture(nil, 'OVERLAY')
-- aux_background:SetTexture(aux.color.content.background())
-- aux_background:SetAllPoints(DropDownList1Backdrop)
-- blizzard_backdrop = DropDownList1Backdrop:GetBackdrop()
-- aux.hook('ToggleDropDownMenu', function(...)
-- T.temp(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 '', '^aux.frame%d+$') then
-- set_aux_dropdown_style(dropdown)
-- else
-- set_blizzard_dropdown_style()
-- end
-- return unpack(ret)
-- end)
--
-- function set_aux_dropdown_style(dropdown)
-- DropDownList1Backdrop:SetBackdrop(T.empty)
-- aux_border:Show()
-- aux_background:Show()
-- DropDownList1:SetWidth(dropdown:GetWidth() * .9)
-- DropDownList1:SetHeight(DropDownList1:GetHeight() - 10)
-- DropDownList1:ClearAllPoints()
-- DropDownList1:SetPoint('TOPLEFT', dropdown, 'BOTTOMLEFT', -2, -2)
-- for i = 1, UIDROPDOWNMENU_MAXBUTTONS do
-- local button = _G['DropDownList1Button' .. i]
-- button:SetPoint('TOPLEFT', 0, -((button:GetID() - 1) * UIDROPDOWNMENU_BUTTON_HEIGHT) - 7)
-- button:SetPoint('TOPRIGHT', 0, -((button:GetID() - 1) * UIDROPDOWNMENU_BUTTON_HEIGHT) - 7)
-- local text = button:GetFontString()
-- text:SetFont(font, 14)
-- text:SetPoint('TOPLEFT', 18, 0)
-- text:SetPoint('BOTTOMRIGHT', -8, 0)
-- local highlight = _G['DropDownList1Button' .. i .. 'Highlight']
-- highlight:ClearAllPoints()
-- highlight:SetDrawLayer('OVERLAY')
-- highlight:SetHeight(14)
-- highlight:SetPoint('LEFT', 5, 0)
-- highlight:SetPoint('RIGHT', -3, 0)
-- local check = _G['DropDownList1Button' .. i .. 'Check']
-- check:SetWidth(16)
-- check:SetHeight(16)
-- check:SetPoint('LEFT', 3, -1)
-- end
-- end
--
-- function set_blizzard_dropdown_style()
-- DropDownList1Backdrop:SetBackdrop(blizzard_backdrop)
-- aux_border:Hide()
-- aux_background:Hide()
-- for i = 1, UIDROPDOWNMENU_MAXBUTTONS do
-- local button = _G['DropDownList1Button' .. i]
-- local text = button:GetFontString()
-- text:SetFont([[Fonts\FRIZQT__.ttf]], 10)
-- text:SetShadowOffset(1, -1)
-- local highlight = _G['DropDownList1Button' .. i .. 'Highlight']
-- highlight:SetAllPoints()
-- highlight:SetDrawLayer('BACKGROUND')
-- local check = _G['DropDownList1Button' .. i .. 'Check']
-- check:SetWidth(24)
-- check:SetHeight(24)
-- check:SetPoint('LEFT', 0, 0)
-- end
-- end
-- end
--end
do
local id = 1
function M.unique_name()
id = id + 1
return 'aux.frame' .. id
end
end
do
local menu = CreateFrame('Frame', unique_name(), UIParent, 'UIDropDownMenuTemplate')
M.menu = T.vararg-function(arg)
HideDropDownMenu(1)
UIDropDownMenu_Initialize(menu, function()
for i = 1, getn(arg), 2 do
UIDropDownMenu_AddButton(T.map('text', arg[i], 'notCheckable', true, 'func', arg[i + 1]))
end
end, 'MENU')
ToggleDropDownMenu(1, nil, menu, 'cursor')
end
end
function M.set_size(frame, width, height)
frame:SetWidth(width)
frame:SetHeight(height or width)
end
function M.set_frame_style(frame, backdrop_color, border_color, left, right, top, bottom)
frame:SetBackdrop{bgFile=[[Interface\Buttons\WHITE8X8]], edgeFile=[[Interface\Buttons\WHITE8X8]], edgeSize=1.5, tile=true, insets={left=left, right=right, top=top, bottom=bottom}}
frame:SetBackdropColor(backdrop_color())
frame:SetBackdropBorderColor(border_color())
end
function M.set_window_style(frame, 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, 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, aux.color.content.background, aux.color.content.border, left, right, top, bottom)
end
function M.panel(parent)
local panel = CreateFrame('Frame', nil, parent)
set_panel_style(panel)
return panel
end
function M.checkbutton(parent, text_height)
local button = button(parent, text_height)
button.state = false
button:SetBackdropColor(aux.color.state.disabled())
function button:SetChecked(state)
if state then
self:SetBackdropColor(aux.color.state.enabled())
self.state = true
else
self:SetBackdropColor(aux.color.state.disabled())
self.state = false
end
end
function button:GetChecked()
return self.state
end
return button
end
function M.button(parent, text_height)
text_height = text_height or font_size.large
local button = CreateFrame('Button', nil, parent)
set_size(button, 80, 24)
set_content_style(button)
local highlight = button:CreateTexture(nil, 'HIGHLIGHT')
highlight:SetAllPoints()
highlight:SetTexture(1, 1, 1, .2)
button.highlight = highlight
do
local label = button:CreateFontString()
label:SetFont(font, text_height)
label:SetAllPoints(button)
label:SetJustifyH('CENTER')
label:SetJustifyV('CENTER')
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(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(aux.color.text.disabled())
return self:default_Disable()
end
return button
end
do
local mt = {__index=T.acquire()}
function mt.__index:create_tab(text)
local id = getn(self._tabs) + 1
local tab = CreateFrame('Button', unique_name(), self._frame)
tab.id = id
tab.group = self
tab:SetHeight(24)
set_panel_style(tab)
local dock = tab:CreateTexture(nil, 'OVERLAY')
dock:SetHeight(3)
if self._orientation == 'UP' then
dock:SetPoint('BOTTOMLEFT', 1, -1)
dock:SetPoint('BOTTOMRIGHT', -1, -1)
elseif self._orientation == 'DOWN' then
dock:SetPoint('TOPLEFT', 1, 1)
dock:SetPoint('TOPRIGHT', -1, 1)
end
dock:SetTexture(aux.color.panel.background())
tab.dock = dock
local highlight = tab:CreateTexture(nil, 'HIGHLIGHT')
highlight:SetAllPoints()
highlight:SetTexture(1, 1, 1, .2)
tab.highlight = highlight
tab.text = tab:CreateFontString()
tab.text:SetAllPoints()
tab.text:SetJustifyH('CENTER')
tab.text:SetJustifyV('CENTER')
tab.text:SetFont(font, font_size.large)
tab:SetFontString(tab.text)
tab:SetText(text)
tab:SetScript('OnClick', function()
if this.id ~= this.group.selected then
PlaySound('igCharacterInfoTab')
this.group:select(this.id)
end
end)
if getn(self._tabs) == 0 then
if self._orientation == 'UP' then
tab:SetPoint('BOTTOMLEFT', self._frame, 'TOPLEFT', 4, -1)
elseif self._orientation == 'DOWN' then
tab:SetPoint('TOPLEFT', self._frame, 'BOTTOMLEFT', 4, 1)
end
else
if self._orientation == 'UP' then
tab:SetPoint('BOTTOMLEFT', self._tabs[getn(self._tabs)], 'BOTTOMRIGHT', 4, 0)
elseif self._orientation == 'DOWN' then
tab:SetPoint('TOPLEFT', self._tabs[getn(self._tabs)], 'TOPRIGHT', 4, 0)
end
end
tab:SetWidth(tab:GetFontString():GetStringWidth() + 14)
tinsert(self._tabs, tab)
end
function mt.__index:select(id)
self._selected = id
self:update()
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(aux.color.label.enabled())
tab:Disable()
tab:SetBackdropColor(aux.color.panel.background())
tab.dock:Show()
tab:SetHeight(29)
else
tab.text:SetTextColor(aux.color.text.enabled())
tab:Enable()
tab:SetBackdropColor(aux.color.content.background())
tab.dock:Hide()
tab:SetHeight(24)
end
end
end
function M.tabs(parent, orientation)
local self = {
_frame = parent,
_orientation = orientation,
_tabs = T.acquire(),
}
return setmetatable(self, mt)
end
end
function M.editbox(parent)
local editbox = CreateFrame('EditBox', nil, parent)
editbox:SetAutoFocus(false)
editbox:SetTextInsets(1.5, 1.5, 3, 3)
editbox:SetMaxLetters(nil)
editbox:SetHeight(24)
editbox:SetTextColor(0, 0, 0, 0)
set_content_style(editbox)
editbox:SetScript('OnEscapePressed', function()
this:ClearFocus()
do (this.escape or pass)() end
end)
editbox:SetScript('OnEnterPressed', function() (this.enter or pass)() end)
editbox:SetScript('OnEditFocusGained', function()
if this.block_focus then
this.block_focus = false
this:ClearFocus()
return
end
this.overlay:Hide()
this:SetTextColor(aux.color.text.enabled())
this.focused = true
this:HighlightText()
do (this.focus_gain or pass)() end
end)
editbox:SetScript('OnEditFocusLost', function()
this.overlay:Show()
this:SetTextColor(0, 0, 0, 0)
this.focused = false
this:HighlightText(0, 0)
this:SetScript('OnUpdate', nil)
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 pass)() end
end)
editbox:SetScript('OnChar', function() (this.char or pass)() end)
do
local last_click = T.map('t', 0)
editbox:SetScript('OnMouseDown', function()
if arg1 == 'RightButton' then
this:SetText('')
this:ClearFocus()
this.block_focus = true
else
local x, y = GetCursorPosition()
-- 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
aux.thread(function() editbox:HighlightText() end)
end
T.wipe(last_click)
last_click.t = GetTime()
last_click.x = x
last_click.y = y
end
end)
end
function editbox:SetAlignment(alignment)
self:SetJustifyH(alignment)
self.overlay:SetJustifyH(alignment)
end
function editbox:SetFontSize(size)
self:SetFont(font, size)
self.overlay:SetFont(font, size)
end
local overlay = label(editbox)
overlay:SetPoint('LEFT', 1.5, 0)
overlay:SetPoint('RIGHT', -1.5, 0)
overlay:SetTextColor(aux.color.text.enabled())
editbox.overlay = overlay
editbox:SetAlignment('LEFT')
editbox:SetFontSize(font_size.medium)
return editbox
end
do
local function update_bar()
if this:GetValue() < 1 then
this:SetAlpha(1 - (sin(GetTime() * 180) + 1) / 4)
else
this:SetAlpha(1)
end
end
function M.status_bar(parent)
local self = CreateFrame('Frame', nil, parent)
local level = parent:GetFrameLevel()
self:SetFrameLevel(level + 1)
do
local status_bar = CreateFrame('StatusBar', nil, self, 'TextStatusBar')
status_bar:SetOrientation('HORIZONTAL')
status_bar:SetMinMaxValues(0, 1)
status_bar:SetAllPoints()
status_bar:SetStatusBarTexture([[Interface\Buttons\WHITE8X8]])
status_bar:SetStatusBarColor(.42, .42, .42, .7)
status_bar:SetFrameLevel(level + 2)
status_bar:SetScript('OnUpdate', update_bar)
self.secondary_status_bar = status_bar
end
do
local status_bar = CreateFrame('StatusBar', nil, self, 'TextStatusBar')
status_bar:SetOrientation('HORIZONTAL')
status_bar:SetMinMaxValues(0, 1)
status_bar:SetAllPoints()
status_bar:SetStatusBarTexture([[Interface\Buttons\WHITE8X8]])
status_bar:SetStatusBarColor(.19, .22, .33, .9)
status_bar:SetFrameLevel(level + 3)
status_bar:SetScript('OnUpdate', update_bar)
self.primary_status_bar = status_bar
end
do
local text_frame = CreateFrame('Frame', nil, self)
text_frame:SetFrameLevel(level + 4)
text_frame:SetAllPoints(self)
local text = label(text_frame, font_size.medium)
text:SetTextColor(aux.color.text.enabled())
text:SetPoint('CENTER', 0, 0)
self.text = text
end
function self:update_status(primary_status, secondary_status)
if primary_status then
self.primary_status_bar:SetValue(primary_status)
end
if secondary_status then
self.secondary_status_bar:SetValue(secondary_status)
end
end
function self:set_text(text)
self.text:SetText(text)
end
return self
end
end
function M.item(parent)
local item = CreateFrame('Frame', nil, parent)
set_size(item, 260, 40)
local btn = CreateFrame('CheckButton', unique_name(), item, 'ActionButtonTemplate')
item.button = btn
btn:SetPoint('LEFT', 2, .5)
btn:SetHighlightTexture(nil)
btn:RegisterForClicks()
item.texture = _G[btn:GetName() .. 'Icon']
item.texture:SetTexCoord(.06, .94, .06, .94)
item.name = label(btn, font_size.medium)
item.name:SetJustifyH('LEFT')
item.name:SetPoint('LEFT', btn, 'RIGHT', 10, 0)
item.name:SetPoint('RIGHT', item, 'RIGHT', -10, .5)
item.count = _G[btn:GetName() .. 'Count']
item.count:SetTextHeight(17)
return item
end
function M.label(parent, size)
local label = parent:CreateFontString()
label:SetFont(font, size or font_size.small)
label:SetTextColor(aux.color.label.enabled())
return label
end
function M.horizontal_line(parent, y_offset, inverted_color)
local texture = parent:CreateTexture()
texture:SetPoint('TOPLEFT', parent, 'TOPLEFT', 2, y_offset)
texture:SetPoint('TOPRIGHT', parent, 'TOPRIGHT', -2, y_offset)
texture:SetHeight(2)
if inverted_color then
texture:SetTexture(aux.color.panel.background())
else
texture:SetTexture(aux.color.content.background())
end
return texture
end
function M.vertical_line(parent, x_offset, top_offset, bottom_offset, inverted_color)
local texture = parent:CreateTexture()
texture:SetPoint('TOPLEFT', parent, 'TOPLEFT', x_offset, top_offset or -2)
texture:SetPoint('BOTTOMLEFT', parent, 'BOTTOMLEFT', x_offset, bottom_offset or 2)
texture:SetWidth(2)
if inverted_color then
texture:SetTexture(aux.color.panel.background())
else
texture:SetTexture(aux.color.content.background())
end
return texture
end
function M.dropdown(parent)
local dropdown = CreateFrame('Frame', unique_name(), parent, 'UIDropDownMenuTemplate')
set_content_style(dropdown, 0, 0, 4, 4)
_G[dropdown:GetName() .. 'Left']:Hide()
_G[dropdown:GetName() .. 'Middle']:Hide()
_G[dropdown:GetName() .. 'Right']:Hide()
local button = _G[dropdown:GetName() .. 'Button']
button:ClearAllPoints()
button:SetScale(.9)
button:SetPoint('RIGHT', dropdown, 0, 0)
dropdown.button = button
local text = _G[dropdown:GetName() .. 'Text']
text:ClearAllPoints()
text:SetPoint('RIGHT', button, 'LEFT', -2, 0)
text:SetPoint('LEFT', 8, 0)
text:SetFont(font, font_size.medium)
text:SetShadowColor(0, 0, 0, 0)
return dropdown
end
function M.slider(parent)
local slider = CreateFrame('Slider', nil, parent)
slider:SetOrientation('HORIZONTAL')
slider:SetHeight(6)
slider:SetHitRectInsets(0, 0, -12, -12)
slider:SetValue(0)
set_panel_style(slider)
local thumb_texture = slider:CreateTexture(nil, 'ARTWORK')
thumb_texture:SetPoint('CENTER', 0, 0)
thumb_texture:SetTexture(aux.color.content.background())
thumb_texture:SetHeight(18)
thumb_texture:SetWidth(8)
set_size(thumb_texture, 8, 18)
slider:SetThumbTexture(thumb_texture)
local label = slider:CreateFontString(nil, 'OVERLAY')
label:SetPoint('BOTTOMLEFT', slider, 'TOPLEFT', -3, 8)
label:SetPoint('BOTTOMRIGHT', slider, 'TOPRIGHT', 6, 8)
label:SetJustifyH('LEFT')
label:SetHeight(13)
label:SetFont(font, font_size.small)
label:SetTextColor(aux.color.label.enabled())
local editbox = editbox(slider)
editbox:SetPoint('LEFT', slider, 'RIGHT', 5, 0)
set_size(editbox, 45, 18)
editbox:SetAlignment('CENTER')
editbox:SetFontSize(17)
slider.label = label
slider.editbox = editbox
return slider
end
function M.checkbox(parent)
local checkbox = CreateFrame('CheckButton', nil, parent, 'UICheckButtonTemplate')
checkbox:SetWidth(16)
checkbox:SetHeight(16)
set_content_style(checkbox)
checkbox:SetNormalTexture(nil)
checkbox:SetPushedTexture(nil)
checkbox:GetHighlightTexture():SetAllPoints()
checkbox:GetHighlightTexture():SetTexture(1, 1, 1, .2)
checkbox:GetCheckedTexture():SetTexCoord(.12, .88, .12, .88)
checkbox:GetHighlightTexture('BLEND')
return checkbox
end
do
local editbox = CreateFrame'EditBox'
editbox:SetAutoFocus(false)
function M.clear_focus()
editbox:SetFocus()
editbox:ClearFocus()
end
end
function M.percentage_historical(pct, bid)
local text = (pct > 10000 and '>10000' or pct) .. '%'
if bid then
return aux.color.gray(text)
elseif pct < 50 then
return aux.color.blue(text)
elseif pct < 80 then
return aux.color.green(text)
elseif pct < 110 then
return aux.color.yellow(text)
elseif pct < 135 then
return aux.color.orange(text)
else
return aux.color.red(text)
end
end
+129
View File
@@ -0,0 +1,129 @@
module 'aux.gui.item_listing'
local T = require 'T'
local aux = require 'aux'
local info = require 'aux.util.info'
local gui = require 'aux.gui'
local ROW_HEIGHT = 39
function M:render()
if getn(self.item_records or T.empty) > getn(self.rows) then
self.content_frame:SetPoint('BOTTOMRIGHT', -15, 0)
else
self.content_frame:SetPoint('BOTTOMRIGHT', 0, 0)
end
FauxScrollFrame_Update(self.scroll_frame, getn(self.item_records), getn(self.rows), ROW_HEIGHT)
local offset = FauxScrollFrame_GetOffset(self.scroll_frame)
local rows = self.rows
for i, row in rows do
local item_record = self.item_records[i + offset]
if item_record then
row.item_record = item_record
if self.selected and self.selected(item_record) or row.mouseover then
row.highlight:Show()
elseif not row.mouse_over then
row.highlight:Hide()
end
row.item.texture:SetTexture(item_record.texture)
row.item.name:SetText('[' .. item_record.name .. ']')
local color = ITEM_QUALITY_COLORS[item_record.quality]
row.item.name:SetTextColor(color.r, color.g, color.b)
if item_record.aux_quantity > 1 then
row.item.count:SetText(item_record.aux_quantity)
else
row.item.count:SetText()
end
row:Show()
else
row:Hide()
end
end
end
function M.new(parent, on_click, selected)
local content_frame = CreateFrame('Frame', nil, parent)
content_frame:SetAllPoints()
local scroll_frame = CreateFrame('ScrollFrame', gui.unique_name(), parent, 'FauxScrollFrameTemplate')
scroll_frame:SetScript('OnVerticalScroll', function()
FauxScrollFrame_OnVerticalScroll(ROW_HEIGHT, function() render(this.item_listing) end)
end)
scroll_frame:SetPoint('TOPLEFT', content_frame, 'TOPLEFT', 0, 29)
scroll_frame:SetPoint('BOTTOMRIGHT', content_frame, 'BOTTOMRIGHT', 0, 0)
local scroll_bar = _G[scroll_frame:GetName() .. 'ScrollBar']
scroll_bar:ClearAllPoints()
scroll_bar:SetPoint('TOPRIGHT', parent, -4, 2)
scroll_bar:SetPoint('BOTTOMRIGHT', parent, -4, 4)
scroll_bar:SetWidth(10)
local thumbTex = scroll_bar:GetThumbTexture()
thumbTex:SetPoint('CENTER', 0, 0)
thumbTex:SetTexture(aux.color.content.background())
thumbTex:SetHeight(150)
thumbTex:SetWidth(scroll_bar:GetWidth())
_G[scroll_bar:GetName() .. 'ScrollUpButton']:Hide()
_G[scroll_bar:GetName() .. 'ScrollDownButton']:Hide()
local rows = T.acquire()
local row_index = 1
local max_height = content_frame:GetHeight()
local total_height = 0
while total_height + ROW_HEIGHT < max_height do
local row = CreateFrame('Frame', nil, content_frame)
row:SetHeight(ROW_HEIGHT)
row:SetPoint('TOPLEFT', content_frame, 0, -((row_index - 1) * ROW_HEIGHT))
row:SetPoint('TOPRIGHT', content_frame, 0, -((row_index - 1) * ROW_HEIGHT))
row:EnableMouse(true)
row:SetScript('OnMouseUp', on_click)
row:SetScript('OnEnter', function()
row.mouseover = true
row.highlight:Show()
end)
row:SetScript('OnLeave', function()
row.mouseover = false
if not selected(row.item_record) then
row.highlight:Hide()
end
end)
row.item = gui.item(row)
row.item:SetScale(.9)
row.item:SetPoint('LEFT', 2.5, 0)
row.item:SetPoint('RIGHT', -2.5, 0)
row.item.button:SetScript('OnEnter', function()
info.set_tooltip(row.item_record.itemstring, this, 'ANCHOR_RIGHT')
end)
row.item.button:SetScript('OnLeave', function() GameTooltip:Hide() end)
local highlight = row:CreateTexture()
highlight:SetAllPoints(row)
highlight:Hide()
highlight:SetTexture(1, .9, 0, .4)
row.highlight = highlight
rows[row_index] = row
row_index = row_index + 1
total_height = total_height + ROW_HEIGHT
end
local item_listing = {
selected = selected,
content_frame = content_frame,
scroll_frame = scroll_frame,
rows = rows,
}
scroll_frame.item_listing = item_listing
return item_listing
end
function M.populate(item_listing, item_records)
item_listing.item_records = item_records
render(item_listing)
end
+300
View File
@@ -0,0 +1,300 @@
module 'aux.gui.listing'
local T = require 'T'
local aux = require 'aux'
local gui = require 'aux.gui'
local ROW_HEIGHT = 15
local ROW_TEXT_SIZE = 14
local HEAD_HEIGHT = 27
local HEAD_SPACE = 2
local DEFAULT_COL_INFO = {{width=1}}
local handlers = {
OnEnter = function()
this.mouseover = true
if not this.data then return end
if not this.st.highlightDisabled then
this.highlight:Show()
end
local handler = this.st.handlers.OnEnter
if handler then
handler(this.st, this.data, this)
end
end,
OnLeave = function()
this.mouseover = false
if not this.data then return end
if not (this.st.selected and this.st.selected(this.data)) then
this.highlight:Hide()
end
local handler = this.st.handlers.OnLeave
if handler then
handler(this.st, this.data, this)
end
end,
OnClick = function()
if not this.data then return end
local handler = this.st.handlers.OnClick
if handler then
handler(this.st, this.data, this, arg1)
end
end,
OnDoubleClick = function()
if not this.data then return end
local handler = this.st.handlers.OnDoubleClick
if handler then
handler(this.st, this.data, this, arg1)
end
end,
}
local methods = {
Update = function(self)
if getn(self.colInfo) > 1 or self.colInfo[1].name then
self.headHeight = HEAD_HEIGHT
else
self.headHeight = 0
end
if getn(self.rowData or T.empty) > self.numRows then
self.contentFrame:SetPoint('BOTTOMRIGHT', -15, 0)
else
self.contentFrame:SetPoint('BOTTOMRIGHT', 0, 0)
end
local width = self.contentFrame:GetRight() - self.contentFrame:GetLeft()
while getn(self.headCols) < getn(self.colInfo) do
self:AddColumn()
end
for i, col in self.headCols do
if self.colInfo[i] then
col:Show()
col:SetWidth(self.colInfo[i].width * width)
col:SetHeight(self.headHeight)
col.text:SetText(self.colInfo[i].name or '')
col.text:SetJustifyH(self.colInfo[i].headAlign or 'CENTER')
else
col:Hide()
end
end
while getn(self.rows) < self.numRows do
self:AddRow()
end
for i, row in self.rows do
if i > self.numRows then
row.data = nil
row:Hide()
else
row:Show()
while getn(row.cols) < getn(self.colInfo) do
self:AddCell(i)
end
for j, col in row.cols do
if self.headCols[j] and self.colInfo[j] then
col:Show()
col:SetWidth(self.colInfo[j].width * width)
col.text:SetJustifyH(self.colInfo[j].align or 'LEFT')
else
col:Hide()
end
end
end
end
if not self.rowData then return end
FauxScrollFrame_Update(self.scrollFrame, getn(self.rowData), self.numRows, ROW_HEIGHT)
local offset = FauxScrollFrame_GetOffset(self.scrollFrame)
self.offset = offset
for i = 1, self.numRows do
local row = self.rows[i]
row.data = nil
if i > getn(self.rowData) then
row:Hide()
else
row:Show()
local data = self.rowData[i + offset]
if not data then break end
row.data = data
if row.mouseover or self.selected and self.selected(data) then
row.highlight:Show()
else
row.highlight:Hide()
end
for j, col in row.cols do
if self.colInfo[j] then
local colData = data.cols[j]
if type(colData.value) == 'function' then
col.text:SetText(colData.value(unpack(colData.args)))
else
col.text:SetText(colData.value)
end
end
end
end
end
end,
SetData = function(self, rowData)
for _, row in self.rowData or T.empty do
for _, col in row.cols do T.release(col) end
T.release(row.cols)
T.release(row)
end
self.rowData = rowData
self.updateSort = true
self:Update()
end,
AddColumn = function(self)
local colNum = getn(self.headCols) + 1
local col = CreateFrame('Frame', nil, self.contentFrame)
if colNum == 1 then
col:SetPoint('TOPLEFT', 0, 0)
else
col:SetPoint('TOPLEFT', self.headCols[colNum - 1], 'TOPRIGHT')
end
col.st = self
col.colNum = colNum
local text = col:CreateFontString()
text:SetAllPoints()
text:SetFont(gui.font, 12)
text:SetTextColor(aux.color.label.enabled())
col.text = text
local tex = col:CreateTexture()
tex:SetAllPoints()
tex:SetTexture([[Interface\AddOns\aux-AddOn\WorldStateFinalScore-Highlight]])
tex:SetTexCoord(.017, 1, .083, .909)
tex:SetAlpha(.5)
tinsert(self.headCols, col)
for i, row in self.rows do
while getn(row.cols) < getn(self.headCols) do
self:AddCell(i)
end
end
end,
AddCell = function(self, rowNum)
local row = self.rows[rowNum]
local colNum = getn(row.cols) + 1
local cell = CreateFrame('Frame', nil, row)
local text = cell:CreateFontString()
cell.text = text
text:SetFont(gui.font, ROW_TEXT_SIZE)
text:SetJustifyV('CENTER')
text:SetPoint('TOPLEFT', 1, -1)
text:SetPoint('BOTTOMRIGHT', -1, 1)
cell:SetHeight(ROW_HEIGHT)
cell.st = self
if colNum == 1 then
cell:SetPoint('TOPLEFT', 0, 0)
else
cell:SetPoint('TOPLEFT', row.cols[colNum - 1], 'TOPRIGHT')
end
tinsert(row.cols, cell)
end,
AddRow = function(self)
local row = CreateFrame('Button', nil, self.contentFrame)
row:SetHeight(ROW_HEIGHT)
row:RegisterForClicks('LeftButtonUp', 'RightButtonUp')
for name, func in handlers do
row:SetScript(name, func)
end
local rowNum = getn(self.rows) + 1
if rowNum == 1 then
row:SetPoint('TOPLEFT', 0, -(self.headHeight + HEAD_SPACE))
row:SetPoint('TOPRIGHT', 0, -(self.headHeight + HEAD_SPACE))
else
row:SetPoint('TOPLEFT', 0, -(self.headHeight + HEAD_SPACE + (rowNum - 1) * ROW_HEIGHT))
row:SetPoint('TOPRIGHT', 0, -(self.headHeight + HEAD_SPACE + (rowNum - 1) * ROW_HEIGHT))
end
local highlight = row:CreateTexture()
highlight:SetAllPoints()
highlight:SetTexture(1, .9, 0, .4)
highlight:Hide()
row.highlight = highlight
row.st = self
row.cols = T.acquire()
self.rows[rowNum] = row
for _ = 1, getn(self.colInfo) do
self:AddCell(rowNum)
end
end,
SetSelection = function(self, f)
self.selected = f
end,
SetHandler = function(self, event, handler)
self.handlers[event] = handler
end,
SetColInfo = function(self, colInfo)
colInfo = colInfo or DEFAULT_COL_INFO
self.colInfo = colInfo
self:Update()
end,
}
function M.new(parent)
local st = CreateFrame('Frame', gui.unique_name(), parent)
st:SetAllPoints()
st.numRows = max(floor((parent:GetHeight() - HEAD_HEIGHT - HEAD_SPACE) / ROW_HEIGHT), 0)
local contentFrame = CreateFrame('Frame', nil, st)
contentFrame:SetPoint('TOPLEFT', 0, 0)
contentFrame:SetPoint('BOTTOMRIGHT', 0, 0)
st.contentFrame = contentFrame
local scrollFrame = CreateFrame('ScrollFrame', st:GetName() .. 'ScrollFrame', st, 'FauxScrollFrameTemplate')
scrollFrame:SetScript('OnVerticalScroll', function()
FauxScrollFrame_OnVerticalScroll(ROW_HEIGHT, function() st:Update() end)
end)
scrollFrame:SetAllPoints(contentFrame)
st.scrollFrame = scrollFrame
local scroll_bar = _G[scrollFrame:GetName() .. 'ScrollBar']
scroll_bar:ClearAllPoints()
scroll_bar:SetPoint('TOPRIGHT', st, -4, -HEAD_HEIGHT)
scroll_bar:SetPoint('BOTTOMRIGHT', st, -4, 4)
scroll_bar:SetWidth(10)
local thumbTex = scroll_bar:GetThumbTexture()
thumbTex:SetPoint('CENTER', 0, 0)
thumbTex:SetTexture(aux.color.content.background())
thumbTex:SetHeight(150)
thumbTex:SetWidth(scroll_bar:GetWidth())
_G[scroll_bar:GetName() .. 'ScrollUpButton']:Hide()
_G[scroll_bar:GetName() .. 'ScrollDownButton']:Hide()
for name, func in methods do
st[name] = func
end
st.headCols = T.acquire()
st.rows = T.acquire()
st.handlers = T.acquire()
st.colInfo = DEFAULT_COL_INFO
return st
end