massive buy upgrade, sorting and bidding

This commit is contained in:
Manuel Simon Hirsig
2015-10-03 20:22:30 +02:00
parent 951498377c
commit d5e5449a01
7 changed files with 536 additions and 647 deletions
+225 -187
View File
@@ -2,68 +2,137 @@ Aux.list = {}
local MAX_COLUMNS = 6
local order = {
BUYOUT = "Buyout price",
BID = "Bid price",
BUYOUT_UNIT = "Unit buyout price",
BID_UNIT = "Unit bid price",
local NAME, OWNER, BID, BID_UNIT, BUYOUT, BUYOUT_UNIT, QUANTITY = 1, 2, 3, 4, 5, 6, 7, 8
MoneyTypeInfo["AUX_LIST"] = {
UpdateFunc = function()
return this.staticMoney
end,
collapse = 1,
fixedWidth = 1,
showSmallerCoins = 1,
}
local logical_columns = {
{
type = 'STRING',
title = 'Name',
comparator = function(row1, row2) return Aux.util.compare(row1.name, row2.name, Aux.util.GT) end,
getter = function(row) return row.name end,
color = function(row) return ITEM_QUALITY_COLORS[row.quality] end,
},
{
type = 'STRING',
title = 'Owner',
comparator = function(row1, row2) return Aux.util.compare(row1.owner, row2.owner, Aux.util.GT) end,
getter = function(row) return row.owner end,
},
{
type = 'MONEY',
title = 'Bid',
comparator = function(row1, row2) return Aux.util.compare(row1.bid, row2.bid, Aux.util.GT) end,
getter = function(row) return row.bid end,
},
{
type = 'MONEY',
title = 'Bid (Unit)',
comparator = function(row1, row2) return Aux.util.compare(row1.bid_per_unit, row2.bid_per_unit, Aux.util.GT) end,
getter = function(row) return row.bid_per_unit end,
},
{
type = 'MONEY',
title = 'Buyout',
comparator = function(row1, row2) return Aux.util.compare(row1.buyout_price, row2.buyout_price, Aux.util.GT) end,
getter = function(row) return row.buyout_price end,
},
{
type = 'MONEY',
title = 'Buyout (Unit)',
comparator = function(row1, row2) return Aux.util.compare(row1.buyout_price_per_unit, row2.buyout_price_per_unit, Aux.util.GT) end,
getter = function(row) return row.buyout_price_per_unit end,
},
{
type = 'NUMBER',
title = 'Quantity',
comparator = function(row1, row2) return Aux.util.compare(row1.stack_size, row2.stack_size, Aux.util.LT) end,
getter = function(row) return row.stack_size end,
},
{
type = 'STRING',
title = 'Time Left',
comparator = function(row1, row2) return Aux.util.invert_order(Aux.util.compare(row1.duration, row2.duration, Aux.util.GT)) end,
getter = function(row)
if row.duration == 1 then
return 'Short'
elseif row.duration == 2 then
return 'Medium'
elseif row.duration == 3 then
return 'Long'
elseif row.duration == 4 then
return 'Very Long'
end
end,
},
}
local physical_columns = {
{ logical_column = logical_columns[NAME], width = 156 },
{ logical_column = logical_columns[OWNER], width = 156 },
{ logical_column = logical_columns[BUYOUT_UNIT], width = 156 },
{ logical_column = logical_columns[QUANTITY], width = 156 },
{ logical_column = logical_columns[BUYOUT], width = 156 },
}
function Aux.list.on_load()
Aux.list.initialize(this, physical_columns, logical_columns)
end
-------------------------------------------------------------------------------
-- Compare two rows
-- Aux.util.compare two rows
-------------------------------------------------------------------------------
local CurrentListFrame = nil;
function ListTemplate_CompareRows(row1, row2)
frame = CurrentListFrame;
for index, value in ipairs(frame.sortOrder) do
local column = value;
local physicalColumn = frame.physicalColumns[column.columnIndex];
local logicalColumn = physicalColumn.logicalColumn;
if (logicalColumn.compareAscendingFunc and logicalColumn.compareDescendingFunc) then
local ascending = logicalColumn.compareAscendingFunc(row1, row2);
local descending = logicalColumn.compareDescendingFunc(row1, row2);
if (ascending or descending) then
if (column.sortAscending) then
return ascending;
else
return descending;
function Aux.list.row_comparator(list_frame)
return function(row1, row2)
for index, sort_info in ipairs(list_frame.sort_order) do
local physical_column = list_frame.physical_columns[sort_info.column_index]
local logical_column = physical_column.logical_column
if logical_column.comparator then
local ordering = logical_column.comparator(row1, row2)
if ordering ~= Aux.util.EQ then
return sort_info.sort_ascending and ordering or Aux.util.invert_order(ordering)
end
end
end
return Aux.util.EQ
end
return false;
end
-------------------------------------------------------------------------------
-- Initialize the list with the column information
-------------------------------------------------------------------------------
function Aux.list.initialize(frame, physicalColumns, logicalColumns)
function Aux.list.initialize(frame, physical_columns, logical_columns)
frame.lines = 19
frame.lineHeight = 16
frame.content = {}
frame.physicalColumns = physicalColumns
frame.logicalColumns = logicalColumns
frame.physical_columns = physical_columns
frame.logical_columns = logical_columns
frame.sortOrder = {}
for physicalColumnIndex = 1, MAX_COLUMNS do
local button = getglobal(frame:GetName().."Column"..physicalColumnIndex.."Sort")
local dropdown = getglobal(frame:GetName().."Column"..physicalColumnIndex.."DropDown")
if (physicalColumnIndex <= table.getn(physicalColumns)) then
local physicalColumn = physicalColumns[physicalColumnIndex]
local logicalColumn = {title='kek'} -- physicalColumn.logicalColumn
local column = {}
column.columnIndex = physicalColumnIndex
column.sortAscending = true
table.insert(frame.sortOrder, column)
frame.sort_order = {}
for i = 1, MAX_COLUMNS do
local button = getglobal(frame:GetName().."Column"..i.."Sort")
local dropdown = getglobal(frame:GetName().."Column"..i.."DropDown")
if (i <= table.getn(physical_columns)) then
local physical_column = physical_columns[i]
local logical_column = physical_column.logical_column
table.insert(frame.sort_order, { column_index = i, sort_ascending = true})
getglobal(button:GetName().."Arrow"):Hide()
getglobal(button:GetName().."Text"):SetText(logicalColumn.title)
getglobal(button:GetName().."Text"):SetText(logical_column.title)
button:Show()
if (table.getn(physicalColumn.logicalColumns) > 1) then
dropdown:Show()
else
dropdown:Hide()
end
Aux.list.set_column_width(frame, physicalColumnIndex, physicalColumn.width);
dropdown:Show()
Aux.list.set_column_width(frame, i, physical_column.width);
else
button:Hide()
dropdown:Hide()
@@ -76,19 +145,18 @@ end
-------------------------------------------------------------------------------
-- Initialize the list with the column information
-------------------------------------------------------------------------------
function Aux.list.set_column_width(frame, column, width)
function Aux.list.set_column_width(frame, column_index, width)
-- Resize the header
frame.physicalColumns[column].width = width
local button = getglobal(frame:GetName().."Column"..column.."Sort")
local button = getglobal(frame:GetName().."Column"..column_index.."Sort")
button:SetWidth(width + 2)
local dropdown = getglobal(frame:GetName().."Column"..column.."DropDown")
local dropdown = getglobal(frame:GetName().."Column"..column_index.."DropDown")
UIDropDownMenu_SetWidth(width - 18, dropdown)
-- Resize each cell in the columns
for line = 1, frame.lines do
local textControl = getglobal(frame:GetName().."Item"..line.."Column"..column)
if textControl then
textControl:SetWidth(width - 20)
local text = getglobal(frame:GetName().."Item"..line.."Column"..column_index)
if text then
text:SetWidth(width - 20)
end
end
end
@@ -96,194 +164,168 @@ end
-------------------------------------------------------------------------------
-- Set the item to display.
-------------------------------------------------------------------------------
function ListTemplate_SetContent(frame, content)
function Aux.list.populate(frame, content)
frame.content = content
-- Perform the sort.
CurrentListFrame = frame
table.sort(frame.content, ListTemplate_CompareRows)
CurrentListFrame = nil
Aux.util.merge_sort(frame.content, Aux.list.row_comparator(frame))
-- Update the scroll pane.
ListTemplateScrollFrame_Update(getglobal(frame:GetName().."ScrollFrame"))
Aux.list.scroll_frame_update(getglobal(frame:GetName().."ScrollFrame"))
end
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
function ListTemplate_SelectRow(frame, row)
if (frame.selectedRow ~= row) then
local scrollFrame = getglobal(frame:GetName().."ScrollFrame");
local firstVisibleRow = FauxScrollFrame_GetOffset(scrollFrame) + 1;
local lastVisibleRow = firstVisibleRow + frame.lines - 1;
if frame.selectedRow ~= row then
local scrollFrame = getglobal(frame:GetName().."ScrollFrame")
local firstVisibleRow = FauxScrollFrame_GetOffset(scrollFrame) + 1
local lastVisibleRow = firstVisibleRow + frame.lines - 1
-- Deselect the previous row
if (frame.selectedRow and firstVisibleRow <= frame.selectedRow and frame.selectedRow <= lastVisibleRow) then
local line = frame.selectedRow - firstVisibleRow + 1;
local item = getglobal(frame:GetName().."Item"..line);
item:UnlockHighlight();
if frame.selectedRow and firstVisibleRow <= frame.selectedRow and frame.selectedRow <= lastVisibleRow then
local line = frame.selectedRow - firstVisibleRow + 1
local item = getglobal(frame:GetName().."Item"..line)
item:UnlockHighlight()
end
-- Update the selected item
frame.selectedRow = row;
frame.selectedRow = row
-- Select the new row
if (frame.selectedRow and firstVisibleRow <= frame.selectedRow and frame.selectedRow <= lastVisibleRow) then
local line = frame.selectedRow - firstVisibleRow + 1;
local item = getglobal(frame:GetName().."Item"..line);
item:LockHighlight();
if frame.selectedRow and firstVisibleRow <= frame.selectedRow and frame.selectedRow <= lastVisibleRow then
local line = frame.selectedRow - firstVisibleRow + 1
local item = getglobal(frame:GetName().."Item"..line)
item:LockHighlight()
end
end
end
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
function Aux.list.sort(frame, columnIndex)
-- -- Update the SortColumn order
-- if (frame.sortOrder[1].columnIndex == columnIndex) then
-- frame.sortOrder[1].sortAscending = not frame.sortOrder[1].sortAscending;
-- else
-- getglobal(frame:GetName().."Column"..frame.sortOrder[1].columnIndex.."SortArrow"):Hide();
-- for index, value in ipairs(frame.sortOrder) do
-- if (value.columnIndex == columnIndex) then
-- local temp = value;
-- table.remove(frame.sortOrder, index);
-- table.insert(frame.sortOrder, 1, temp);
-- break;
-- end
-- end
-- frame.sortOrder[1].sortAscending = true;
-- getglobal(frame:GetName().."Column"..frame.sortOrder[1].columnIndex.."SortArrow"):Show();
-- end
function Aux.list.sort(frame, i)
-- -- Perform the sort.
-- CurrentListFrame = frame;
-- table.sort(frame.content, ListTemplate_CompareRows);
-- CurrentListFrame = nil;
if frame.sort_order[1].column_index == i then
frame.sort_order[1].sort_ascending = not frame.sort_order[1].sort_ascending
else
getglobal(frame:GetName().."Column"..frame.sort_order[1].column_index.."SortArrow"):Hide()
for index, value in ipairs(frame.sort_order) do
if value.column_index == i then
local temp = value
table.remove(frame.sort_order, index)
table.insert(frame.sort_order, 1, temp)
break
end
end
frame.sort_order[1].sort_ascending = true
getglobal(frame:GetName().."Column"..frame.sort_order[1].column_index.."SortArrow"):Show()
end
Aux.util.merge_sort(frame.content, Aux.list.row_comparator(frame))
-- -- Update the sort arrow.
-- if (frame.sortOrder[1].sortAscending) then
-- getglobal(frame:GetName().."Column"..frame.sortOrder[1].columnIndex.."SortArrow"):SetTexCoord(0, 0.5625, 0, 1.0);
-- else
-- getglobal(frame:GetName().."Column"..frame.sortOrder[1].columnIndex.."SortArrow"):SetTexCoord(0, 0.5625, 1.0, 0);
-- end
if frame.sort_order[1].sort_ascending then
getglobal(frame:GetName().."Column"..frame.sort_order[1].column_index.."SortArrow"):SetTexCoord(0, 0.5625, 0, 1.0)
else
getglobal(frame:GetName().."Column"..frame.sort_order[1].column_index.."SortArrow"):SetTexCoord(0, 0.5625, 1.0, 0)
end
-- -- Update the scroll pane.
-- ListTemplateScrollFrame_Update(getglobal(frame:GetName().."ScrollFrame"));
Aux.list.scroll_frame_update(getglobal(frame:GetName().."ScrollFrame"))
end
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
function ListTemplateScrollFrame_Update(frame)
if (not frame) then frame = this end;
local parent = frame:GetParent();
local content = parent.content;
FauxScrollFrame_Update(frame, table.getn(content), parent.lines, parent.lineHeight);
function Aux.list.scroll_frame_update(frame)
if not frame then frame = this end
local parent = frame:GetParent()
local content = parent.content
FauxScrollFrame_Update(frame, table.getn(content), parent.lines, parent.lineHeight)
for line = 1, parent.lines do
local item = getglobal(parent:GetName().."Item"..line);
local contentIndex = line + FauxScrollFrame_GetOffset(frame);
if contentIndex <= table.getn(content) then
for columnIndex = 1, MAX_COLUMNS do
-- Get the text control (if any)
local text = getglobal(parent:GetName().."Item"..line.."Column"..columnIndex);
if (text) then
text:Hide();
end
local item = getglobal(parent:GetName().."Item"..line)
local row_index = line + FauxScrollFrame_GetOffset(frame)
if row_index <= table.getn(content) then
for column_index = 1, MAX_COLUMNS do
-- Get the money frame (if any)
local moneyFrame = getglobal(parent:GetName().."Item"..line.."Column"..columnIndex.."MoneyFrame");
if (moneyFrame) then
moneyFrame:Hide();
end
local text = getglobal(parent:GetName().."Item"..line.."Column"..column_index)
-- text:Hide() TODO
text:SetText()
-- If the column exists, update it
if (columnIndex <= table.getn(parent.physicalColumns)) then
local physicalColumn = parent.physicalColumns[columnIndex];
local logicalColumn = physicalColumn.logicalColumn;
local value = logicalColumn.valueFunc(content[contentIndex]);
local moneyFrame = getglobal(parent:GetName().."Item"..line.."Column"..column_index.."MoneyFrame")
moneyFrame:Hide()
-- Setup the control based on the datatype
if (value) then
if (text and (logicalColumn.dataType == "Date" or logicalColumn.dataType == "Number" or logicalColumn.dataType == "String")) then
text:SetText(value);
if (logicalColumn.colorFunc) then
local color = logicalColumn.colorFunc(content[contentIndex]);
text:SetTextColor(color.r, color.g, color.b);
if column_index <= table.getn(parent.physical_columns) then
local physical_column = parent.physical_columns[column_index]
local logical_column = physical_column.logical_column
local value = logical_column.getter(content[row_index])
if value then
if text and (logical_column.type == "DATE" or logical_column.type == "NUMBER" or logical_column.type == "STRING") then
text:SetText(value)
if logical_column.color then
local color = logical_column.color(content[row_index])
text:SetTextColor(color.r, color.g, color.b)
else
text:SetTextColor(255, 255, 255);
text:SetTextColor(255, 255, 255)
end
if (logicalColumn.alphaFunc) then
text:SetAlpha(logicalColumn.alphaFunc(content[contentIndex]));
if logical_column.alphaFunc then
text:SetAlpha(logical_column.alphaFunc(content[row_index]))
else
text:SetAlpha(1.0);
text:SetAlpha(1.0)
end
if (logicalColumn.dataType == "Number") then
text:SetJustifyH("RIGHT");
if (logical_column.type == "NUMBER") then
text:SetJustifyH("RIGHT")
else
text:SetJustifyH("LEFT");
text:SetJustifyH("LEFT")
end
text:Show();
elseif (moneyFrame and logicalColumn.dataType == "Money") then
if (value >= 0) then
MoneyFrame_Update(moneyFrame:GetName(), value);
SetMoneyFrameColor(moneyFrame:GetName(), 255, 255, 255);
text:Show()
elseif moneyFrame and logical_column.type == "MONEY" then
if value >= 0 then
MoneyFrame_Update(moneyFrame:GetName(), value)
SetMoneyFrameColor(moneyFrame:GetName(), 255, 255, 255)
else
MoneyFrame_Update(moneyFrame:GetName(), -value);
SetMoneyFrameColor(moneyFrame:GetName(), 255, 0, 0);
MoneyFrame_Update(moneyFrame:GetName(), -value)
SetMoneyFrameColor(moneyFrame:GetName(), 255, 0, 0)
end
if (logicalColumn.alphaFunc) then
moneyFrame:SetAlpha(logicalColumn.alphaFunc(content[contentIndex]));
if logical_column.alphaFunc then
moneyFrame:SetAlpha(logical_column.alphaFunc(content[row_index]))
else
moneyFrame:SetAlpha(1.0);
moneyFrame:SetAlpha(1.0)
end
moneyFrame:Show();
moneyFrame:Show()
end
end
end
end
-- Update the row highlight
if (parent.selectedRow and parent.selectedRow == contentIndex) then
item:LockHighlight();
if parent.selectedRow and parent.selectedRow == row_index then
item:LockHighlight()
else
item:UnlockHighlight();
item:UnlockHighlight()
end
item:Show();
item:Show()
else
item:Hide();
item:Hide()
end
end
end
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
function Aux.list.dropdown_onload()
function Aux.list.dropdown_on_load()
getglobal(this:GetName().."Text"):Hide()
this.initialize = ListTemplate_DropDown_Initialize
UIDropDownMenu_SetSelectedID(this, 1)
this.initialize = Aux.list.dropdown_initialize
-- UIDropDownMenu_SetSelectedID(this, 1) TODO
end
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
function ListTemplate_DropDown_Initialize()
function Aux.list.dropdown_initialize()
local dropdown = this:GetParent()
local frame = dropdown:GetParent()
-- if (frame.physicalColumns) then
-- local physicalColumnIndex = dropdown:GetID();
-- local physicalColumn = frame.physicalColumns[physicalColumnIndex];
-- for index, value in pairs(physicalColumn.logicalColumns) do
-- local logicalColumn = value;
-- local info = {};
-- info.text = logicalColumn.title;
-- info.func = ListTemplate_DropDownItem_OnClick;
-- info.owner = dropdown;
-- UIDropDownMenu_AddButton(info);
-- end
-- end
for _, name in pairs(order) do
for _, logical_column in pairs(frame.logical_columns) do
UIDropDownMenu_AddButton({
text = name,
text = logical_column.title,
owner = dropdown,
func = Aux.list.dropdown_item_onclick
})
@@ -292,25 +334,21 @@ end
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
function Aux.list.dropdown_item_onclick()
-- local logicalColumnIndex = this:GetID()
-- local physicalColumnIndex = this.owner:GetID()
-- local dropdown = this.owner
-- local frame = dropdown:GetParent()
-- if (frame.physicalColumns[physicalColumnIndex].logicalColumn ~= frame.physicalColumns[physicalColumnIndex].logicalColumns[logicalColumnIndex]) then
-- -- Change the physical column's logical column
-- frame.physicalColumns[physicalColumnIndex].logicalColumn = frame.physicalColumns[physicalColumnIndex].logicalColumns[logicalColumnIndex]
-- getglobal(frame:GetName().."Column"..physicalColumnIndex.."SortText"):SetText(frame.physicalColumns[physicalColumnIndex].logicalColumn.title)
function Aux.list.dropdown_item_onclick()
local logical_column_index = this:GetID()
local physical_column_index = this.owner:GetID()
local dropdown = this.owner
local frame = dropdown:GetParent()
if (frame.physical_columns[physical_column_index].logical_column ~= frame.logical_columns[logical_column_index]) then
-- -- Sort the content based on the new logical column
-- CurrentListFrame = frame;
-- table.sort(frame.content, ListTemplate_CompareRows)
-- CurrentListFrame = nil
frame.physical_columns[physical_column_index].logical_column = frame.logical_columns[logical_column_index]
getglobal(frame:GetName().."Column"..physical_column_index.."SortText"):SetText(frame.physical_columns[physical_column_index].logical_column.title)
-- -- Update the combo and scroll pane.
-- UIDropDownMenu_SetSelectedID(dropdown, logicalColumnIndex)
-- ListTemplateScrollFrame_Update(getglobal(frame:GetName().."ScrollFrame"))
-- end
Aux.util.merge_sort(frame.content, Aux.list.row_comparator(frame))
UIDropDownMenu_SetSelectedID(dropdown, logical_column_index)
Aux.list.scroll_frame_update(getglobal(frame:GetName().."ScrollFrame"))
end
end