From 0004b1c785e18c24a1bf0bd90f1160a6479a686c Mon Sep 17 00:00:00 2001 From: atomaka Date: Mon, 19 Sep 2011 05:53:40 -0400 Subject: [PATCH 1/7] Meaningless commit to test new branch. --- ChoreTracker.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ChoreTracker.lua b/ChoreTracker.lua index f1148ae..b5a50f0 100644 --- a/ChoreTracker.lua +++ b/ChoreTracker.lua @@ -266,7 +266,9 @@ function core:GetNextVPReset() end function core:DrawTooltip() - --create the tooltip header + -- Instead of drawing the tooltip directly from data, we will populate a table, + -- sort the table, and then use the table to draw the tooltip + tooltip:AddHeader('') local valorPointColumn = tooltip:AddColumn('LEFT') tooltip:SetCell(1, 1, '') From 2106926a1e0f753d5fba9128e02c5d5627e9548d Mon Sep 17 00:00:00 2001 From: atomaka Date: Mon, 19 Sep 2011 07:42:17 -0400 Subject: [PATCH 2/7] Create table of information needed in tooltip. --- ChoreTracker.lua | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/ChoreTracker.lua b/ChoreTracker.lua index b5a50f0..072e2b0 100644 --- a/ChoreTracker.lua +++ b/ChoreTracker.lua @@ -268,7 +268,40 @@ end function core:DrawTooltip() -- Instead of drawing the tooltip directly from data, we will populate a table, -- sort the table, and then use the table to draw the tooltip - + local tooltipTable = {} + for realm in pairs(db.global) do + for name in pairs(db.global[realm]) do + local valorPoints = db.global[realm][name].valorPoints.points + if valorPoints == nil then + valorPoints = 0 + end + tooltipTable[name] = { name = name, valorPoints = valorPoints } + + for instance in pairs(trackedInstances) do + local defeatedBosses + if db.global[realm][name].lockouts[instance] ~= nil then + defeatedBosses = db.global[realm][name].lockouts[instance].defeatedBosses + else + defeatedBosses = 0 + end + tooltipTable[name][instance] = defeatedBosses + end + end + end + + + -- Sort by name for now + table.sort(tooltipTable, function(a, b) return a.name < b.name end ) + + for name,info in pairs(tooltipTable) do + local printString = name + + for header,value in pairs(info) do + printString = printString .. ' ' .. value + end + print(printString) + end + tooltip:AddHeader('') local valorPointColumn = tooltip:AddColumn('LEFT') tooltip:SetCell(1, 1, '') From 934b03bed90f85a323e1dda749efcb17a63134d6 Mon Sep 17 00:00:00 2001 From: atomaka Date: Mon, 19 Sep 2011 08:48:54 -0400 Subject: [PATCH 3/7] Use infomration table to create the tooltip. --- ChoreTracker.lua | 59 +++++++++++++++++++----------------------------- 1 file changed, 23 insertions(+), 36 deletions(-) diff --git a/ChoreTracker.lua b/ChoreTracker.lua index 072e2b0..6a07fe4 100644 --- a/ChoreTracker.lua +++ b/ChoreTracker.lua @@ -272,10 +272,11 @@ function core:DrawTooltip() for realm in pairs(db.global) do for name in pairs(db.global[realm]) do local valorPoints = db.global[realm][name].valorPoints.points + local class = db.global[realm][name].class if valorPoints == nil then valorPoints = 0 end - tooltipTable[name] = { name = name, valorPoints = valorPoints } + tooltipTable[name] = { name = name, realm = realm, class = class, valorPoints = valorPoints } for instance in pairs(trackedInstances) do local defeatedBosses @@ -291,16 +292,7 @@ function core:DrawTooltip() -- Sort by name for now - table.sort(tooltipTable, function(a, b) return a.name < b.name end ) - - for name,info in pairs(tooltipTable) do - local printString = name - - for header,value in pairs(info) do - printString = printString .. ' ' .. value - end - print(printString) - end + table.sort(tooltipTable, function(a, b) return a.name:lower() < b.name:lower() end ) tooltip:AddHeader('') local valorPointColumn = tooltip:AddColumn('LEFT') @@ -312,34 +304,29 @@ function core:DrawTooltip() nextColumn = nextColumn + 1 end - for realm in pairs(db.global) do - for name in pairs(db.global[realm]) do - local characterLine = tooltip:AddLine('') - local class = db.global[realm][name].class - tooltip:SetCell(characterLine, 1, name, classColors[class], 'LEFT') - - local valorPoints, valorPointColor - valorPoints = db.global[realm][name].valorPoints.points - if valorPoints == nil then - valorPoints = 0 - end - if valorPoints == 980 then - valorPointColor = flagColors['red'] + for name,information in pairs(tooltipTable) do + local characterLine = tooltip:AddLine('') + tooltip:SetCell(characterLine, 1, information.name, classColors[information.class], 'LEFT') + + local valorPointColor + if information.valorPoints == 980 then + valorPointColor = flagColors['red'] + else + valorPointColor = flagColors['green'] + end + tooltip:SetCell(characterLine, 2, information.valorPoints, valorPointColor, 'RIGHT') + + local nextColumn = 3 + for instance, abbreviation in pairs(trackedInstances) do + local instanceColor + if information[instance] == 0 then + instanceColor = flagColors['green'] else - valorPointColor = flagColors['green'] + instanceColor = flagColors['red'] end - tooltip:SetCell(characterLine, 2, valorPoints, valorPointColor, 'RIGHT') + tooltip:SetCell(characterLine, nextColumn, information[instance], instanceColor, 'RIGHT') - local nextColumn = 3 - for instance,abbreviation in pairs(trackedInstances) do - if db.global[realm][name].lockouts[instance] ~= nil then - local defeatedBosses = db.global[realm][name].lockouts[instance].defeatedBosses - tooltip:SetCell(characterLine, nextColumn, defeatedBosses, flagColors['red'], 'RIGHT') - else - tooltip:SetCell(characterLine, nextColumn, '0', flagColors['green'], 'RIGHT') - end - nextColumn = nextColumn + 1 - end + nextColumn = nextColumn + 1 end end end \ No newline at end of file From 4d11c25c2c3ca583e7d8dca6b0ded89439e70d71 Mon Sep 17 00:00:00 2001 From: atomaka Date: Mon, 19 Sep 2011 09:11:10 -0400 Subject: [PATCH 4/7] Store with name and realm in table to prevent duplicate name issues. --- ChoreTracker.lua | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/ChoreTracker.lua b/ChoreTracker.lua index 6a07fe4..faabd2a 100644 --- a/ChoreTracker.lua +++ b/ChoreTracker.lua @@ -110,13 +110,7 @@ function core:OnEnable() LibStub('AceConfigDialog-3.0'):Open('ChoreTracker') end end, - OnEnter = function(self) - local columnCount = 2 - for instance,abbreviation in pairs(trackedInstances) do - columnCount = columnCount + 1 - end - tooltip = LQT:Acquire('ChoreTrackerTooltip', columnCount, 'LEFT', 'CENTER', 'RIGHT') - + OnEnter = function(self) core:DrawTooltip() tooltip:SmartAnchorTo(self) @@ -266,8 +260,13 @@ function core:GetNextVPReset() end function core:DrawTooltip() - -- Instead of drawing the tooltip directly from data, we will populate a table, - -- sort the table, and then use the table to draw the tooltip + local columnCount = 2 + for instance,abbreviation in pairs(trackedInstances) do + columnCount = columnCount + 1 + end + tooltip = LQT:Acquire('ChoreTrackerTooltip', columnCount, 'LEFT', 'CENTER', 'RIGHT') + + -- Populate a table with the information we want for our tooltip local tooltipTable = {} for realm in pairs(db.global) do for name in pairs(db.global[realm]) do @@ -276,7 +275,7 @@ function core:DrawTooltip() if valorPoints == nil then valorPoints = 0 end - tooltipTable[name] = { name = name, realm = realm, class = class, valorPoints = valorPoints } + tooltipTable[name .. '-' .. realm] = { name = name, realm = realm, class = class, valorPoints = valorPoints } for instance in pairs(trackedInstances) do local defeatedBosses @@ -285,15 +284,18 @@ function core:DrawTooltip() else defeatedBosses = 0 end - tooltipTable[name][instance] = defeatedBosses + tooltipTable[name .. '-' .. realm][instance] = defeatedBosses end end end -- Sort by name for now - table.sort(tooltipTable, function(a, b) return a.name:lower() < b.name:lower() end ) + table.sort(tooltipTable, function(a, b) return a.name < b.name end ) + + -- Draw the tooltip + tooltip:SetScale(1) tooltip:AddHeader('') local valorPointColumn = tooltip:AddColumn('LEFT') tooltip:SetCell(1, 1, '') From 070a1641ef346334754aec53fe64306744aa1f60 Mon Sep 17 00:00:00 2001 From: atomaka Date: Tue, 20 Sep 2011 01:12:22 -0400 Subject: [PATCH 5/7] Apparently, this is not PHP and you cannot sort lists. --- ChoreTracker.lua | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/ChoreTracker.lua b/ChoreTracker.lua index faabd2a..65254db 100644 --- a/ChoreTracker.lua +++ b/ChoreTracker.lua @@ -268,10 +268,13 @@ function core:DrawTooltip() -- Populate a table with the information we want for our tooltip local tooltipTable = {} + local characters = {} for realm in pairs(db.global) do for name in pairs(db.global[realm]) do + table.insert(characters,name .. '-' .. realm) local valorPoints = db.global[realm][name].valorPoints.points local class = db.global[realm][name].class + if valorPoints == nil then valorPoints = 0 end @@ -291,7 +294,7 @@ function core:DrawTooltip() -- Sort by name for now - table.sort(tooltipTable, function(a, b) return a.name < b.name end ) + table.sort(characters, function(a, b) return tooltipTable[a].name:lower() < tooltipTable[b].name:lower() end ) -- Draw the tooltip @@ -306,27 +309,27 @@ function core:DrawTooltip() nextColumn = nextColumn + 1 end - for name,information in pairs(tooltipTable) do + for _,name in pairs(characters) do local characterLine = tooltip:AddLine('') - tooltip:SetCell(characterLine, 1, information.name, classColors[information.class], 'LEFT') + tooltip:SetCell(characterLine, 1, tooltipTable[name].name, classColors[tooltipTable[name].class], 'LEFT') local valorPointColor - if information.valorPoints == 980 then + if tooltipTable[name].valorPoints == 980 then valorPointColor = flagColors['red'] else valorPointColor = flagColors['green'] end - tooltip:SetCell(characterLine, 2, information.valorPoints, valorPointColor, 'RIGHT') + tooltip:SetCell(characterLine, 2, tooltipTable[name].valorPoints, valorPointColor, 'RIGHT') local nextColumn = 3 for instance, abbreviation in pairs(trackedInstances) do local instanceColor - if information[instance] == 0 then + if tooltipTable[name][instance] == 0 then instanceColor = flagColors['green'] else instanceColor = flagColors['red'] end - tooltip:SetCell(characterLine, nextColumn, information[instance], instanceColor, 'RIGHT') + tooltip:SetCell(characterLine, nextColumn, tooltipTable[name][instance], instanceColor, 'RIGHT') nextColumn = nextColumn + 1 end From 6cd2ee2e21d3329b05e27a0e288b5e6673a7f3f4 Mon Sep 17 00:00:00 2001 From: atomaka Date: Tue, 20 Sep 2011 04:12:08 -0400 Subject: [PATCH 6/7] Added options to select sort field and direction. --- ChoreTracker.lua | 59 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 46 insertions(+), 13 deletions(-) diff --git a/ChoreTracker.lua b/ChoreTracker.lua index 65254db..2642476 100644 --- a/ChoreTracker.lua +++ b/ChoreTracker.lua @@ -9,6 +9,8 @@ local defaults = { minimap = { hide = false, }, + sortType = 1, + sortDirection = 1, instances = {}, }, } @@ -23,7 +25,23 @@ local options = { type = 'toggle', 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, - } + }, + 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 local tooltipTable = {} - local characters = {} for realm in pairs(db.global) do for name in pairs(db.global[realm]) do - table.insert(characters,name .. '-' .. realm) local valorPoints = db.global[realm][name].valorPoints.points local class = db.global[realm][name].class if valorPoints == nil then valorPoints = 0 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 local defeatedBosses @@ -287,19 +303,36 @@ function core:DrawTooltip() else defeatedBosses = 0 end - tooltipTable[name .. '-' .. realm][instance] = defeatedBosses + characterTable[instance] = defeatedBosses end + + table.insert(tooltipTable,characterTable) 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 - table.sort(characters, function(a, b) return tooltipTable[a].name:lower() < tooltipTable[b].name:lower() end ) + table.sort(tooltipTable, sortTooltip ) -- Draw the tooltip - tooltip:SetScale(1) tooltip:AddHeader('') + tooltip:SetScale(1) local valorPointColumn = tooltip:AddColumn('LEFT') tooltip:SetCell(1, 1, '') tooltip:SetCell(1, 2, 'VP') @@ -309,27 +342,27 @@ function core:DrawTooltip() nextColumn = nextColumn + 1 end - for _,name in pairs(characters) do + for _,information in pairs(tooltipTable) do 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 - if tooltipTable[name].valorPoints == 980 then + if information.valorPoints == 980 then valorPointColor = flagColors['red'] else valorPointColor = flagColors['green'] end - tooltip:SetCell(characterLine, 2, tooltipTable[name].valorPoints, valorPointColor, 'RIGHT') + tooltip:SetCell(characterLine, 2, information.valorPoints, valorPointColor, 'RIGHT') local nextColumn = 3 for instance, abbreviation in pairs(trackedInstances) do local instanceColor - if tooltipTable[name][instance] == 0 then + if information[instance] == 0 then instanceColor = flagColors['green'] else instanceColor = flagColors['red'] end - tooltip:SetCell(characterLine, nextColumn, tooltipTable[name][instance], instanceColor, 'RIGHT') + tooltip:SetCell(characterLine, nextColumn, information[instance], instanceColor, 'RIGHT') nextColumn = nextColumn + 1 end From 24682f9b5f94492ebe27857094b349e977a22ae3 Mon Sep 17 00:00:00 2001 From: atomaka Date: Tue, 20 Sep 2011 12:52:40 -0400 Subject: [PATCH 7/7] Minor reordering. --- ChoreTracker.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ChoreTracker.lua b/ChoreTracker.lua index 2642476..df0e1fa 100644 --- a/ChoreTracker.lua +++ b/ChoreTracker.lua @@ -310,6 +310,7 @@ function core:DrawTooltip() end end + -- Sort table according to options. local sortTooltip = function(a, b) if db.profile.sortType == 1 then if db.profile.sortDirection == 1 then @@ -325,8 +326,6 @@ function core:DrawTooltip() end end end - - -- Sort by name for now table.sort(tooltipTable, sortTooltip )