1
0
Fork 0

Added options to select sort field and direction.

This commit is contained in:
Andrew Tomaka 2011-09-20 04:12:08 -04:00
parent 070a1641ef
commit 6cd2ee2e21

View file

@ -9,6 +9,8 @@ local defaults = {
minimap = { minimap = {
hide = false, hide = false,
}, },
sortType = 1,
sortDirection = 1,
instances = {}, instances = {},
}, },
} }
@ -23,7 +25,23 @@ local options = {
type = 'toggle', type = 'toggle',
get = function(info) return db.profile.minimap.hide end, get = function(info) return db.profile.minimap.hide end,
set = function(info, value) db.profile.minimap.hide = value LDBIcon[value and 'Hide' or 'Show'](LDBIcon, 'ChoreTracker') end, set = function(info, value) db.profile.minimap.hide = value LDBIcon[value and 'Hide' or 'Show'](LDBIcon, 'ChoreTracker') end,
} },
sortType = {
name = 'Sort Field',
desc = 'Field to sort the tooltip by.',
type = 'select',
values = { 'character', 'vp' },
get = function(info) return db.profile.sortType end,
set = function(info, value) db.profile.sortType = value end,
},
sortingDirection = {
name = 'Sorting Direction',
desc = 'Which direction to sort.',
type = 'select',
values = { 'ascending', 'descending' },
get = function(info) return db.profile.sortDirection end,
set = function(info, value) db.profile.sortDirection = value end,
},
} }
} }
@ -268,17 +286,15 @@ function core:DrawTooltip()
-- Populate a table with the information we want for our tooltip -- Populate a table with the information we want for our tooltip
local tooltipTable = {} local tooltipTable = {}
local characters = {}
for realm in pairs(db.global) do for realm in pairs(db.global) do
for name in pairs(db.global[realm]) do for name in pairs(db.global[realm]) do
table.insert(characters,name .. '-' .. realm)
local valorPoints = db.global[realm][name].valorPoints.points local valorPoints = db.global[realm][name].valorPoints.points
local class = db.global[realm][name].class local class = db.global[realm][name].class
if valorPoints == nil then if valorPoints == nil then
valorPoints = 0 valorPoints = 0
end end
tooltipTable[name .. '-' .. realm] = { name = name, realm = realm, class = class, valorPoints = valorPoints } local characterTable = { name = name, realm = realm, class = class, valorPoints = valorPoints }
for instance in pairs(trackedInstances) do for instance in pairs(trackedInstances) do
local defeatedBosses local defeatedBosses
@ -287,19 +303,36 @@ function core:DrawTooltip()
else else
defeatedBosses = 0 defeatedBosses = 0
end end
tooltipTable[name .. '-' .. realm][instance] = defeatedBosses characterTable[instance] = defeatedBosses
end end
table.insert(tooltipTable,characterTable)
end end
end end
local sortTooltip = function(a, b)
if db.profile.sortType == 1 then
if db.profile.sortDirection == 1 then
return a.name:lower() < b.name:lower()
else
return a.name:lower() > b.name:lower()
end
elseif db.profile.sortType == 2 then
if db.profile.sortDirection == 1 then
return a.valorPoints < b.valorPoints
else
return a.valorPoints > b.valorPoints
end
end
end
-- Sort by name for now -- Sort by name for now
table.sort(characters, function(a, b) return tooltipTable[a].name:lower() < tooltipTable[b].name:lower() end ) table.sort(tooltipTable, sortTooltip )
-- Draw the tooltip -- Draw the tooltip
tooltip:SetScale(1)
tooltip:AddHeader('') tooltip:AddHeader('')
tooltip:SetScale(1)
local valorPointColumn = tooltip:AddColumn('LEFT') local valorPointColumn = tooltip:AddColumn('LEFT')
tooltip:SetCell(1, 1, '') tooltip:SetCell(1, 1, '')
tooltip:SetCell(1, 2, 'VP') tooltip:SetCell(1, 2, 'VP')
@ -309,27 +342,27 @@ function core:DrawTooltip()
nextColumn = nextColumn + 1 nextColumn = nextColumn + 1
end end
for _,name in pairs(characters) do for _,information in pairs(tooltipTable) do
local characterLine = tooltip:AddLine('') local characterLine = tooltip:AddLine('')
tooltip:SetCell(characterLine, 1, tooltipTable[name].name, classColors[tooltipTable[name].class], 'LEFT') tooltip:SetCell(characterLine, 1, information.name, classColors[information.class], 'LEFT')
local valorPointColor local valorPointColor
if tooltipTable[name].valorPoints == 980 then if information.valorPoints == 980 then
valorPointColor = flagColors['red'] valorPointColor = flagColors['red']
else else
valorPointColor = flagColors['green'] valorPointColor = flagColors['green']
end end
tooltip:SetCell(characterLine, 2, tooltipTable[name].valorPoints, valorPointColor, 'RIGHT') tooltip:SetCell(characterLine, 2, information.valorPoints, valorPointColor, 'RIGHT')
local nextColumn = 3 local nextColumn = 3
for instance, abbreviation in pairs(trackedInstances) do for instance, abbreviation in pairs(trackedInstances) do
local instanceColor local instanceColor
if tooltipTable[name][instance] == 0 then if information[instance] == 0 then
instanceColor = flagColors['green'] instanceColor = flagColors['green']
else else
instanceColor = flagColors['red'] instanceColor = flagColors['red']
end end
tooltip:SetCell(characterLine, nextColumn, tooltipTable[name][instance], instanceColor, 'RIGHT') tooltip:SetCell(characterLine, nextColumn, information[instance], instanceColor, 'RIGHT')
nextColumn = nextColumn + 1 nextColumn = nextColumn + 1
end end