diff --git a/Definitions.lua b/Definitions.lua index 186c41d0..7f154563 100644 --- a/Definitions.lua +++ b/Definitions.lua @@ -413,6 +413,8 @@ ---@class breakdownspellscrollframe : frame ---@field Header frame + + ---@class breakdownspellbar : button ---@field index number ---@field rank number @@ -479,6 +481,10 @@ ---@field texture texture ---@field bIsMainLine boolean +---@class breakdownspelldatalist : breakdownspelldata[] +---@field totalValue number +---@field combatTime number + ---@class tabframe : frame this is the tab frame object for the breakdown window ---@class breakdownspellblockcontainer : frame container for the spellblocks in the breakdown window diff --git a/Libs/DF/panel.lua b/Libs/DF/panel.lua index f447601a..46e02659 100644 --- a/Libs/DF/panel.lua +++ b/Libs/DF/panel.lua @@ -5108,6 +5108,8 @@ end ---@field bIsRezising boolean ---@field bInUse boolean ---@field columnData table +---@field order string +---@field key string used to sort the values --mixed functions detailsFramework.HeaderFunctions = { @@ -5254,8 +5256,14 @@ detailsFramework.HeaderCoreFunctions = { --return which header is current selected and the the order ASC DESC ---@param self headerframe + ---@return number, string GetSelectedColumn = function(self) - return self.columnSelected, self.columnHeadersCreated[self.columnSelected or 1].order + ---@type number + local columnSelected = self.columnSelected + ---@type headercolumnframe + local columnHeader = self.columnHeadersCreated[columnSelected or 1] + + return columnSelected, columnHeader.order, columnHeader.key end, --clean up and rebuild the header following the header options @@ -5277,8 +5285,10 @@ detailsFramework.HeaderCoreFunctions = { local previousColumnHeader local growDirection = string.lower(self.options.grow_direction) - --update header frames + --amount of headers to be updated local headerSize = #self.HeaderTable + + --update header frames for i = 1, headerSize do --get the header button, a new one is created if it doesn't exists yet local columnHeader = self:GetNextHeader() @@ -5381,6 +5391,8 @@ detailsFramework.HeaderCoreFunctions = { --this is the data to update the columnHeader local columnData = self.HeaderTable[headerIndex] + columnHeader.key = columnData.key or "total" + if (columnData.icon) then columnHeader.Icon:SetTexture(columnData.icon) diff --git a/classes/class_damage.lua b/classes/class_damage.lua index 9e8b045b..f99b78eb 100644 --- a/classes/class_damage.lua +++ b/classes/class_damage.lua @@ -4517,12 +4517,13 @@ function atributo_damage:MontaInfoDamageDone() --I guess this fills the list of end end + ---@type breakdownspelldatalist + local breakdownSpellDataList = {} + ---@type number local totalDamageWithoutPet = actorObject.total_without_pet ---@type number local actorTotal = actorObject.total - ---@type table - local actorSpellsSorted = {} ---@type table local actorSpells = actorObject:GetSpellList() @@ -4539,10 +4540,9 @@ function atributo_damage:MontaInfoDamageDone() --I guess this fills the list of --actor spells ---@type table local alreadyAdded = {} - for spellId, spellTable in pairs(actorSpells) do - ---@cast spellId number - ---@cast spellTable spelltable + ---@type number, spelltable + for spellId, spellTable in pairs(actorSpells) do spellTable.ChartData = nil ---@type string @@ -4552,7 +4552,7 @@ function atributo_damage:MontaInfoDamageDone() --I guess this fills the list of local index = alreadyAdded[spellName] if (index) then ---@type breakdownspelldata - local bkSpellData = actorSpellsSorted[index] + local bkSpellData = breakdownSpellDataList[index] bkSpellData.spellIds[#bkSpellData.spellIds+1] = spellId bkSpellData.spellTables[#bkSpellData.spellTables+1] = spellTable bkSpellData.petNames[#bkSpellData.petNames+1] = "" @@ -4570,8 +4570,8 @@ function atributo_damage:MontaInfoDamageDone() --I guess this fills the list of petNames = {""}, } - actorSpellsSorted[#actorSpellsSorted+1] = bkSpellData - alreadyAdded[spellName] = #actorSpellsSorted + breakdownSpellDataList[#breakdownSpellDataList+1] = bkSpellData + alreadyAdded[spellName] = #breakdownSpellDataList end end end @@ -4596,7 +4596,7 @@ function atributo_damage:MontaInfoDamageDone() --I guess this fills the list of local index = alreadyAdded[spellName] if (index) then --PET ---@type breakdownspelldata - local bkSpellData = actorSpellsSorted[index] + local bkSpellData = breakdownSpellDataList[index] bkSpellData.spellIds[#bkSpellData.spellIds+1] = spellId bkSpellData.spellTables[#bkSpellData.spellTables+1] = spellTable bkSpellData.petNames[#bkSpellData.petNames+1] = petName @@ -4613,41 +4613,38 @@ function atributo_damage:MontaInfoDamageDone() --I guess this fills the list of spellTables = {spellTable}, petNames = {petName}, } - actorSpellsSorted[#actorSpellsSorted+1] = bkSpellData - alreadyAdded[spellName] = #actorSpellsSorted + breakdownSpellDataList[#breakdownSpellDataList+1] = bkSpellData + alreadyAdded[spellName] = #breakdownSpellDataList end end end end end - for i = 1, #actorSpellsSorted do + --copy the keys from the spelltable and add them to the breakdownspelldata + --repeated spells will be summed + for i = 1, #breakdownSpellDataList do ---@type breakdownspelldata - local bkSpellData = actorSpellsSorted[i] + local bkSpellData = breakdownSpellDataList[i] Details:SumSpellTables(bkSpellData.spellTables, bkSpellData) end - --table.sort(actorSpellsSorted, Details.Sort2) - table.sort(actorSpellsSorted, function(t1, t2) - return t1.total > t2.total - end) - - actorSpellsSorted.totalValue = actorTotal - actorSpellsSorted.combatTime = actorCombatTime - - --actorSpellsSorted has the spell infomation, need to pass to the summary tab + breakdownSpellDataList.totalValue = actorTotal + breakdownSpellDataList.combatTime = actorCombatTime --cleanup table.wipe(alreadyAdded) --send to the breakdown window - Details222.BreakdownWindow.SendSpellData(actorSpellsSorted, actorObject, combatObject, instance) + Details222.BreakdownWindow.SendSpellData(breakdownSpellDataList, actorObject, combatObject, instance) if 1 then return end + --to be deprecated and removed: + --gump:JI_AtualizaContainerBarras (#actorSpellsSorted + 1) - local max_ = actorSpellsSorted[1] and actorSpellsSorted[1][2] or 0 --dano que a primeiro magia vez + local max_ = breakdownSpellDataList[1] and breakdownSpellDataList[1][2] or 0 --dano que a primeiro magia vez local barra --aura bar @@ -4661,7 +4658,7 @@ function atributo_damage:MontaInfoDamageDone() --I guess this fills the list of end --spell bars - for index, tabela in ipairs(actorSpellsSorted) do + for index, tabela in ipairs(breakdownSpellDataList) do --index = index + 1 --with the aura bar index = index diff --git a/frames/window_playerbreakdown.lua b/frames/window_playerbreakdown.lua index ca603d49..2d8b5a3e 100644 --- a/frames/window_playerbreakdown.lua +++ b/frames/window_playerbreakdown.lua @@ -406,9 +406,8 @@ function Details222.BreakdownWindow.IsSpellExpanded(spellID) return Details222.BreakdownWindow.ExpandedSpells[spellID] end - ---receives spell data to show in the summary tab ----@param data table +---@param data breakdownspelldatalist ---@param actorObject actor ---@param combatObject combat ---@param instance instance diff --git a/frames/window_playerbreakdown_spells.lua b/frames/window_playerbreakdown_spells.lua index c806cf1b..1b13ba5d 100644 --- a/frames/window_playerbreakdown_spells.lua +++ b/frames/window_playerbreakdown_spells.lua @@ -87,16 +87,16 @@ local spellContainerColumnInfo = { {name = "rank", label = "#", width = 16, align = "center", enabled = true, offset = columnOffset, dataType = "number"}, {name = "expand", label = "^", width = 16, align = "center", enabled = true, offset = columnOffset}, {name = "name", label = "spell name", width = 246, align = "left", enabled = true, offset = columnOffset}, - {name = "amount", label = "total", selected = true, width = 50, align = "left", enabled = true, canSort = true, dataType = "number", order = "DESC", offset = columnOffset}, - {name = "persecond", label = "ps", width = 50, align = "left", enabled = true, canSort = true, offset = columnOffset, order = "DESC", dataType = "number"}, - {name = "percent", label = "%", width = 50, align = "left", enabled = true, canSort = true, offset = columnOffset, order = "DESC", dataType = "number"}, - {name = "casts", label = "casts", width = 40, align = "left", enabled = false, canSort = true, offset = columnOffset, order = "DESC", dataType = "number"}, - {name = "critpercent", label = "crit %", width = 40, align = "left", enabled = false, canSort = true, offset = columnOffset, order = "DESC", dataType = "number"}, - {name = "hits", label = "hits", width = 40, align = "left", enabled = false, canSort = true, offset = columnOffset, order = "DESC", dataType = "number"}, - {name = "castavg", label = "cast avg", width = 50, align = "left", enabled = false, canSort = true, offset = columnOffset, order = "DESC", dataType = "number"}, - {name = "uptime", label = "uptime", width = 45, align = "left", enabled = false, canSort = true, offset = columnOffset, order = "DESC", dataType = "number"}, - {name = "overheal", label = "overheal", width = 45, align = "left", enabled = false, canSort = true, order = "DESC", dataType = "number", attribute = DETAILS_ATTRIBUTE_HEAL, offset = columnOffset}, - {name = "absorbed", label = "absorbed", width = 45, align = "left", enabled = false, canSort = true, order = "DESC", dataType = "number", attribute = DETAILS_ATTRIBUTE_HEAL, offset = columnOffset}, + {name = "amount", label = "total", key = "total", selected = true, width = 50, align = "left", enabled = true, canSort = true, sortKey = "total", dataType = "number", order = "DESC", offset = columnOffset}, + {name = "persecond", label = "ps", key = "total", width = 50, align = "left", enabled = true, canSort = true, sortKey = "ps", offset = columnOffset, order = "DESC", dataType = "number"}, + {name = "percent", label = "%", key = "total", width = 50, align = "left", enabled = true, canSort = true, offset = columnOffset, order = "DESC", dataType = "number"}, + {name = "casts", label = "casts", key = "total", width = 40, align = "left", enabled = false, canSort = true, offset = columnOffset, order = "DESC", dataType = "number"}, + {name = "critpercent", label = "crit %", key = "total", width = 40, align = "left", enabled = false, canSort = true, offset = columnOffset, order = "DESC", dataType = "number"}, + {name = "hits", label = "hits", key = "counter", width = 40, align = "left", enabled = false, canSort = true, offset = columnOffset, order = "DESC", dataType = "number"}, + {name = "castavg", label = "cast avg", key = "total", width = 50, align = "left", enabled = false, canSort = true, offset = columnOffset, order = "DESC", dataType = "number"}, + {name = "uptime", label = "uptime", key = "total", width = 45, align = "left", enabled = false, canSort = true, offset = columnOffset, order = "DESC", dataType = "number"}, + {name = "overheal", label = "overheal", key = "total", width = 45, align = "left", enabled = false, canSort = true, order = "DESC", dataType = "number", attribute = DETAILS_ATTRIBUTE_HEAL, offset = columnOffset}, + {name = "absorbed", label = "absorbed", key = "total", width = 45, align = "left", enabled = false, canSort = true, order = "DESC", dataType = "number", attribute = DETAILS_ATTRIBUTE_HEAL, offset = columnOffset}, } ---callback for when the user resizes a column on the header @@ -1320,7 +1320,7 @@ end ---refresh the data shown in the spells scroll box ---@param scrollFrame table ----@param scrollData breakdownscrolldata +---@param scrollData breakdownspelldatalist ---@param offset number ---@param totalLines number local refreshFunc = function(scrollFrame, scrollData, offset, totalLines) --~refreshspells ~refresh @@ -1328,7 +1328,6 @@ local refreshFunc = function(scrollFrame, scrollData, offset, totalLines) --~ref local maxValue = scrollData[1] and scrollData[1].total ---@type number local totalValue = scrollData.totalValue - ---@type actor local actorObject = spellsTab.GetActor() ---@type string @@ -1341,16 +1340,7 @@ local refreshFunc = function(scrollFrame, scrollData, offset, totalLines) --~ref local headerTable = spellsTab.spellsHeaderData - --get which column is currently selected and the sort order - local columnIndex, order = scrollFrame.Header:GetSelectedColumn() - - --[=[ - if (order == "DESC") then - table.sort(allSpells, function (t1, t2) return t1[4] > t2[4] end) - else - table.sort(allSpells, function (t1, t2) return t1[4] < t2[4] end) - end - --]=] + --todo: when swapping sort orders, close allexpanded spells local lineIndex = 1 for i = 1, totalLines do @@ -1428,11 +1418,6 @@ function spellsTab.CreateSpellScrollContainer(tabFrame) tabFrame.SpellScrollFrame = scrollFrame spellsTab.SpellScrollFrame = scrollFrame - function scrollFrame:RefreshMe(data) - self:SetData(data) - self:Refresh() - end - --~header local headerOptions = { padding = 2, @@ -1448,7 +1433,9 @@ function spellsTab.CreateSpellScrollContainer(tabFrame) local headerTable = {} - scrollFrame.Header = DetailsFramework:CreateHeader(tabFrame, headerTable, headerOptions) + ---@type headerframe + local header = DetailsFramework:CreateHeader(tabFrame, headerTable, headerOptions) + scrollFrame.Header = header scrollFrame.Header:SetPoint("topleft", scrollFrame, "topleft", 0, 1) scrollFrame.Header:SetColumnSettingChangedCallback(onHeaderColumnOptionChanged) @@ -1460,6 +1447,44 @@ function spellsTab.CreateSpellScrollContainer(tabFrame) scrollFrame:CreateLine(spellsTab.CreateSpellBar) end + ---set the data and refresh the scrollframe + ---@param self any + ---@param data breakdownspelldatalist + function scrollFrame:RefreshMe(data) + --get which column is currently selected and the sort order + local columnIndex, order, key = scrollFrame.Header:GetSelectedColumn() + + --here need an api from the header frame to get the key to sort + print("key:", key) + + --pre process the data which may be used into the scroll + + ---@type string + local keyToSort = "total" + if (columnIndex == 1) then + keyToSort = "total" + end + + if (order == "DESC") then + table.sort(data, + ---@param t1 breakdownspelldata + ---@param t2 breakdownspelldata + function(t1, t2) + return t1[keyToSort] > t2[keyToSort] + end) + else + table.sort(data, + ---@param t1 breakdownspelldata + ---@param t2 breakdownspelldata + function(t1, t2) + return t1[keyToSort] < t2[keyToSort] + end) + end + + self:SetData(data) + self:Refresh() + end + return scrollFrame end @@ -2034,7 +2059,7 @@ function Details.InitializeSpellBreakdownTab() spellsTab.TabFrame = tabFrame ---on receive data from a class - ---@param data table + ---@param data breakdownspelldatalist ---@param actorObject actor ---@param combatObject combat ---@param instance instance diff --git a/functions/mixin.lua b/functions/mixin.lua index 5234e09e..f31f1d65 100644 --- a/functions/mixin.lua +++ b/functions/mixin.lua @@ -154,7 +154,7 @@ local spellTable_FieldsToSum = { ---get the array of spelltables and sum each spellTable with the first spellTable found or on targetTable ---only sum the keys found in the spellTable_FieldsToSum table ----@param spellTables table[] +---@param spellTables spelltable[] ---@param targetTable table function Details:SumSpellTables(spellTables, targetTable) local amtSpellTables = #spellTables @@ -166,10 +166,11 @@ function Details:SumSpellTables(spellTables, targetTable) targetTable = targetTable or spellTables[1] for i = 1, amtSpellTables do - ---@type spelltable local spellTable = spellTables[i] if (spellTable) then for key, value in pairs(spellTable) do + ---@cast key string + ---@cast value number if (spellTable_FieldsToSum[key]) then targetTable[key] = (targetTable[key] or 0) + value end