Added an option to nest pet spells within a bar showing the pet name

This commit is contained in:
Tercio Jose
2023-05-14 16:30:09 -03:00
parent 907d88fad5
commit 7fb0ae469c
8 changed files with 152 additions and 68 deletions
+6 -2
View File
@@ -358,10 +358,11 @@
---@field ListActors fun(container: actorcontainer) usage: for index, actorObject in container:ListActors() do
---@class spellcontainer : table
---@field _ActorTable table store [spellId] = spelltable
---@field GetSpell fun(container: spellcontainer, spellId: number) get a spell by its id
---@field ListActors fun(container: spellcontainer) : any, any usage: for spellId, spelltable in container:ListActors() do
---@field ListSpells fun(container: spellcontainer) : any, any usage: for spellId, spelltable in container:ListActors() do
---@field _ActorTable table
---@field HasTwoOrMoreSpells fun(container: spellcontainer) : boolean return true if the container has two or more spells
---@class friendlyfiretable : table
---@field total number total amount of friendly fire caused by the actor
@@ -593,8 +594,11 @@
---@field expandedIndex number
---@field bIsExpanded boolean
---@field statusBarValue number
---@field actorName string --when showing an actor header, this is the actor name
---@field bIsActorHeader boolean is this is true, the spellbar is an actor header, which is a bar with the actor name with the actor spells nested
---@field actorIcon texture
---@class bknesteddata : {spellId: number, spellTable: spelltable, petName: string, value: number}
---@class bknesteddata : {spellId: number, spellTable: spelltable, actorName: string, value: number, bIsActorHeader: boolean} fills .nestedData table in spelltableadv, used to store the nested spells data, 'value' is set when the breakdown sort the values by the selected header
---@class breakdowntargetframe : frame
---@field spellId number
+41 -28
View File
@@ -4446,7 +4446,7 @@ end
end
--lock into a line after clicking on it
--[[exported]] function Details:FocusLock(row, spellId)
--[[exported]] function Details:FocusLock(row, spellId) --will be deprecated
if (not info.mostrando_mouse_over) then
if (spellId == self.detalhes) then --tabela [1] = spellid = spellid que esta na caixa da direita
if (not row.on_focus) then --se a barra no tiver no foco
@@ -4466,11 +4466,11 @@ end
end
end
local wipeSpellCache = function()
local wipeSpellCache = function() --deprecated
table.wipe(Details222.PlayerBreakdown.DamageSpellsCache)
end
local addToSpellCache = function(unitGUID, spellName, spellTable)
local addToSpellCache = function(unitGUID, spellName, spellTable) --deprecated
local unitSpellCache = Details222.PlayerBreakdown.DamageSpellsCache[unitGUID]
if (not unitSpellCache) then
unitSpellCache = {}
@@ -4486,7 +4486,7 @@ local addToSpellCache = function(unitGUID, spellName, spellTable)
table.insert(spellCache, spellTable)
end
local getSpellDetails = function(unitGUID, spellName)
local getSpellDetails = function(unitGUID, spellName) --deprecated
local unitCachedSpells = Details222.PlayerBreakdown.DamageSpellsCache[unitGUID]
local spellsTableForSpellName = unitCachedSpells and unitCachedSpells[spellName]
@@ -4605,7 +4605,7 @@ function damageClass:MontaInfoDamageDone() --I guess this fills the list of spel
---@type table<string, number>
local alreadyAdded = {}
local bShouldMergePlayerSpells = Details.breakdown_spell_tab.merge_players_spells_with_same_name
local bShouldMergePlayerSpells = Details.breakdown_spell_tab.nest_players_spells_with_same_name
---@type number, spelltable
for spellId, spellTable in pairs(actorSpells) do
@@ -4623,7 +4623,7 @@ function damageClass:MontaInfoDamageDone() --I guess this fills the list of spel
bkSpellData.spellTables[#bkSpellData.spellTables+1] = spellTable
---@type bknesteddata
local nestedData = {spellId = spellId, spellTable = spellTable, petName = "", value = 0}
local nestedData = {spellId = spellId, spellTable = spellTable, actorName = "", value = 0}
bkSpellData.nestedData[#bkSpellData.nestedData+1] = nestedData
bkSpellData.bCanExpand = true
else
@@ -4635,7 +4635,7 @@ function damageClass:MontaInfoDamageDone() --I guess this fills the list of spel
bCanExpand = false,
spellTables = {spellTable},
nestedData = {{spellId = spellId, spellTable = spellTable, petName = "", value = 0}},
nestedData = {{spellId = spellId, spellTable = spellTable, actorName = "", value = 0}},
}
detailsFramework:Mixin(bkSpellData, Details.SpellTableMixin)
@@ -4646,33 +4646,46 @@ function damageClass:MontaInfoDamageDone() --I guess this fills the list of spel
end
--pets spells
local bShouldMergeSpellsWithThePet = false
local bShouldMergePetSpells = Details.breakdown_spell_tab.merge_pet_spells_with_same_name
local bShouldMergeSpellsWithThePet = Details.breakdown_spell_tab.nest_pet_spells_by_caster
local bShouldMergePetSpells = Details.breakdown_spell_tab.nest_pet_spells_by_name
local actorPets = actorObject:GetPets()
for _, petName in ipairs(actorPets) do
---@type actor
local petActor = combatObject(DETAILS_ATTRIBUTE_DAMAGE, petName)
if (petActor) then --PET
if (bShouldMergeSpellsWithThePet) then
--so, this is the bar with the pet name, it'll have a sum of all pet damage and other stuff to show in a bar
--get the amount of spells the pet used, if the pet used only one there`s no reason to nest one spell with the pet
local petSpellContainer = petActor:GetSpellContainer("spell")
if (bShouldMergeSpellsWithThePet and petSpellContainer:HasTwoOrMoreSpells()) then
---@type spelltableadv
local bkSpellData = {
bIsActorHeader = true, --tag this spelltable as an actor header, when the actor is the header it will nest the spells use by this actor
actorName = petName,
id = 0,
spellschool = spellTable.spellschool,
bIsExpanded = Details222.BreakdownWindow.IsSpellExpanded(spellId),
bCanExpand = false,
spellTables = {spellTable},
nestedData = {{spellId = spellId, spellTable = spellTable, petName = petName, value = 0}},
spellschool = 0,
bIsExpanded = Details222.BreakdownWindow.IsSpellExpanded(petName),
spellTables = {}, --populated below with the spells the pet used
nestedData = {}, --there's none data here in the main bar as the first bar is the pet name
bCanExpand = true,
actorIcon = [[Interface\AddOns\Details\images\pets\pet_icon_1]],
}
detailsFramework:Mixin(bkSpellData, Details.SpellTableMixin)
--output
breakdownSpellDataList[#breakdownSpellDataList+1] = bkSpellData
alreadyAdded[spellName] = #breakdownSpellDataList
--fill here the spellTables using the actor abilities
--all these spells belong to the current actor in the loop
for spellId, spellTable in petSpellContainer:ListSpells() do
local spellName, _, spellIcon = GetSpellInfo(spellId)
if (spellName) then
bkSpellData.spellTables[#bkSpellData.spellTables+1] = spellTable
---@type bknesteddata
local nestedData = {spellId = spellId, spellTable = spellTable, actorName = petName, value = 0, bIsActorHeader = true} --value to be defined
bkSpellData.nestedData[#bkSpellData.nestedData+1] = nestedData
end
end
else
local spells = petActor:GetSpellList()
--all these spells belong to the current pet in the loop
@@ -4694,7 +4707,7 @@ function damageClass:MontaInfoDamageDone() --I guess this fills the list of spel
bkSpellData.spellTables[#bkSpellData.spellTables+1] = spellTable
---@type bknesteddata
local nestedData = {spellId = spellId, spellTable = spellTable, petName = petName, value = 0}
local nestedData = {spellId = spellId, spellTable = spellTable, actorName = petName, value = 0}
bkSpellData.nestedData[#bkSpellData.nestedData+1] = nestedData
bkSpellData.bCanExpand = true
else --PET
@@ -4706,7 +4719,7 @@ function damageClass:MontaInfoDamageDone() --I guess this fills the list of spel
bCanExpand = false,
spellTables = {spellTable},
nestedData = {{spellId = spellId, spellTable = spellTable, petName = petName, value = 0}},
nestedData = {{spellId = spellId, spellTable = spellTable, actorName = petName, value = 0}},
}
detailsFramework:Mixin(bkSpellData, Details.SpellTableMixin)
@@ -5368,23 +5381,23 @@ function damageClass:BuildSpellDetails(spellBar, spellBlockContainer, blockIndex
blockLine1.leftText:SetText("Spell Empower Average Level: " .. string.format("%.2f", empowerLevelSum / empowerAmount))
if (level1AverageDamage ~= "0") then
blockLine2.leftText:SetText("Level 1 Avg: " .. level1AverageDamage .. " (" .. (empowerAmountPerLevel[1] or 0) .. ")")
blockLine2.leftText:SetText("#1 Avg: " .. level1AverageDamage .. " (" .. (empowerAmountPerLevel[1] or 0) .. ")")
end
if (level2AverageDamage ~= "0") then
blockLine2.centerText:SetText("Level 2 Avg: " .. level2AverageDamage .. " (" .. (empowerAmountPerLevel[2] or 0) .. ")")
blockLine2.centerText:SetText("#2 Avg: " .. level2AverageDamage .. " (" .. (empowerAmountPerLevel[2] or 0) .. ")")
end
if (level3AverageDamage ~= "0") then
blockLine2.rightText:SetText("Level 3 Avg: " .. level3AverageDamage .. " (" .. (empowerAmountPerLevel[3] or 0) .. ")")
blockLine2.rightText:SetText("#3 Avg: " .. level3AverageDamage .. " (" .. (empowerAmountPerLevel[3] or 0) .. ")")
end
if (level4AverageDamage ~= "0") then
blockLine3.leftText:SetText("Level 4 Avg: " .. level4AverageDamage .. " (" .. (empowerAmountPerLevel[4] or 0) .. ")")
blockLine3.leftText:SetText("#4 Avg: " .. level4AverageDamage .. " (" .. (empowerAmountPerLevel[4] or 0) .. ")")
end
if (level5AverageDamage ~= "0") then
blockLine3.rightText:SetText("Level 5 Avg: " .. level5AverageDamage .. " (" .. (empowerAmountPerLevel[5] or 0) .. ")")
blockLine3.rightText:SetText("#5 Avg: " .. level5AverageDamage .. " (" .. (empowerAmountPerLevel[5] or 0) .. ")")
end
end
+14
View File
@@ -71,6 +71,20 @@ local addonName, Details222 = ...
return self:PegaHabilidade (id, shouldCreate, token)
end
---return (boolean) if the container two or more spells within
---@return boolean
function container_habilidades:HasTwoOrMoreSpells()
local count = 0
for _ in pairs(self._ActorTable) do
count = count + 1
if (count >= 2) then
return true
end
end
return false
end
function container_habilidades:PegaHabilidade (id, criar, token)
local esta_habilidade = self._ActorTable [id]
+6 -6
View File
@@ -418,17 +418,17 @@ end
Details222.BreakdownWindow.ExpandedSpells = {}
---set a spell as expanded or not in the breakdown window
---@param spellID number
---@param key any
---@param bIsExpanded boolean
function Details222.BreakdownWindow.SetSpellAsExpanded(spellID, bIsExpanded)
Details222.BreakdownWindow.ExpandedSpells[spellID] = bIsExpanded
function Details222.BreakdownWindow.SetSpellAsExpanded(key, bIsExpanded)
Details222.BreakdownWindow.ExpandedSpells[key] = bIsExpanded
end
---get the state of the expanded for a spell
---@param spellID number
---@param key any
---@return boolean
function Details222.BreakdownWindow.IsSpellExpanded(spellID)
return Details222.BreakdownWindow.ExpandedSpells[spellID]
function Details222.BreakdownWindow.IsSpellExpanded(key)
return Details222.BreakdownWindow.ExpandedSpells[key]
end
---receives spell data to show in the summary tab
+44 -21
View File
@@ -2238,7 +2238,7 @@ local onClickExpandButton = function(expandButton, button)
--todo: check is any other bar has expanded state true, and close the expand (or not)
--toggle this spell expand mode
Details222.BreakdownWindow.SetSpellAsExpanded(expandButton.spellId, not bIsSpellExpaded)
Details222.BreakdownWindow.SetSpellAsExpanded(expandButton.petName or expandButton.spellId, not bIsSpellExpaded)
--call the refresh function of the window
---@type instance
@@ -2291,20 +2291,34 @@ local updateSpellBar = function(spellBar, index, actorName, combatObject, scroll
---@type spelltable
local spellTable
local petName = ""
spellBar.bkSpellData = bkSpellData
if (bIsMainLine) then
local petName = ""
---@type boolean @if true, this is the main line of an actor which has its spells nested in the bkSpellData.nestedData
local bIsActorHeader = bkSpellData.bIsActorHeader
if (bIsMainLine and bIsActorHeader) then
spellTable = bkSpellData
value = bkSpellData.total
spellId = 0
petName = actorName
elseif (bIsMainLine) then
spellTable = bkSpellData
value = bkSpellData.total
spellId = bkSpellData.id
petName = bkSpellData.nestedData[spellTableIndex].petName
petName = bkSpellData.nestedData[spellTableIndex].actorName
else
spellTable = bkSpellData.nestedData[spellTableIndex].spellTable
value = spellTable.total
spellId = spellTable.id
petName = bkSpellData.nestedData[spellTableIndex].petName
--if isn't a spell from a nested actor, then it can use the pet name in the spell name
if (not bkSpellData.nestedData[spellTableIndex].bIsActorHeader) then
petName = bkSpellData.nestedData[spellTableIndex].actorName
end
spellBar.bIsExpandedSpell = true
end
@@ -2315,6 +2329,10 @@ local updateSpellBar = function(spellBar, index, actorName, combatObject, scroll
---@type string, number, string
local spellName, _, spellIcon = Details.GetSpellInfo(spellId)
if (not spellName) then
spellName = actorName
spellIcon = bkSpellData.actorIcon or ""
end
---@type number
local amtCasts = combatObject:GetSpellCastAmount(actorName, spellName)
@@ -2335,9 +2353,9 @@ local updateSpellBar = function(spellBar, index, actorName, combatObject, scroll
end
if (petName ~= "") then
--if is a pet spell and has more pets nested
--if is a pet spell and has more pets nested || nop, now is a pet with its spells nested
if (spellTablesAmount > 1 and bIsMainLine) then
spellName = formatPetName("", spellName, "")
spellName = formatPetName("", spellName, "") --causing error as spellName is nil
elseif (bIsMainLine) then
spellName = formatPetName(petName, spellName, actorName)
else
@@ -2361,7 +2379,7 @@ local updateSpellBar = function(spellBar, index, actorName, combatObject, scroll
local text = spellBar.InLineTexts[textIndex]
local header = headerTable[headerIndex]
if (header.name == "icon") then --ok
if (header.name == "icon") then
spellBar.spellIcon:Show()
spellBar.spellIcon:SetTexture(spellIcon)
spellBar.spellIcon:SetAlpha(0.92)
@@ -2377,7 +2395,7 @@ local updateSpellBar = function(spellBar, index, actorName, combatObject, scroll
targetsSquareFrame.bIsMainLine = bIsMainLine
spellBar:AddFrameToHeaderAlignment(targetsSquareFrame)
elseif (header.name == "rank") then --ok
elseif (header.name == "rank") then
text:SetText(index)
spellBar:AddFrameToHeaderAlignment(text)
spellBar.rank = index
@@ -2390,9 +2408,8 @@ local updateSpellBar = function(spellBar, index, actorName, combatObject, scroll
if (bkSpellData.bCanExpand and bIsMainLine) then
spellBar.expandButton:Show()
local bIsSpellExpaded = Details222.BreakdownWindow.IsSpellExpanded(spellId)
spellBar.expandButton.spellId = spellId
local bIsSpellExpaded = Details222.BreakdownWindow.IsSpellExpanded(bIsActorHeader and actorName or spellId)
spellBar.expandButton.spellId = bIsActorHeader and actorName or spellId
spellBar.expandButton.bIsSpellExpaded = bIsSpellExpaded
spellBar.expandButton:SetScript("OnClick", onClickExpandButton)
@@ -2409,18 +2426,18 @@ local updateSpellBar = function(spellBar, index, actorName, combatObject, scroll
spellBar.expandButton.texture:SetSize(16, 16)
end
elseif (header.name == "name") then --ok
text:SetText(spellName)
elseif (header.name == "name") then
text:SetText(Details:RemoveOwnerName(spellName))
spellBar.name = spellName
spellBar:AddFrameToHeaderAlignment(text)
textIndex = textIndex + 1
elseif (header.name == "amount") then --ok
elseif (header.name == "amount") then
text:SetText(Details:Format(value))
spellBar:AddFrameToHeaderAlignment(text)
textIndex = textIndex + 1
elseif (header.name == "persecond") then --ok
elseif (header.name == "persecond") then
spellBar.perSecond = value / combatTime
---@type string
@@ -2430,7 +2447,7 @@ local updateSpellBar = function(spellBar, index, actorName, combatObject, scroll
spellBar:AddFrameToHeaderAlignment(text)
textIndex = textIndex + 1
elseif (header.name == "percent") then --ok
elseif (header.name == "percent") then
spellBar.percent = value / totalValue * 100
---@type string
local percentFormatted = string.format("%.1f", spellBar.percent) .. "%"
@@ -2562,12 +2579,18 @@ local refreshSpellsFunc = function(scrollFrame, scrollData, offset, totalLines)
if (mainSpellBar) then
lineIndex = lineIndex + 1
local bIsMainLine = true
updateSpellBar(mainSpellBar, index, actorName, combatObject, scrollFrame, headerTable, bkSpellData, 1, totalValue, topValue, bIsMainLine, keyToSort, spellTablesAmount)
if (bkSpellData.bIsActorHeader) then
updateSpellBar(mainSpellBar, index, bkSpellData.actorName, combatObject, scrollFrame, headerTable, bkSpellData, 1, totalValue, topValue, bIsMainLine, keyToSort, spellTablesAmount)
else
updateSpellBar(mainSpellBar, index, actorName, combatObject, scrollFrame, headerTable, bkSpellData, 1, totalValue, topValue, bIsMainLine, keyToSort, spellTablesAmount)
end
end
end
--if the spell is expanded
--then it adds the lines for each spell merged, but it cannot use the bkSpellData, it needs the spellTable, it's kinda using bkSpellData, need to debug
if (bkSpellData.bIsExpanded and spellTablesAmount > 1) then
if (bkSpellData.bIsExpanded and (spellTablesAmount > 1)) then
--filling necessary information to sort the data by the selected header column
for spellTableIndex = 1, spellTablesAmount do
---@type bknesteddata
@@ -2599,7 +2622,7 @@ local refreshSpellsFunc = function(scrollFrame, scrollData, offset, totalLines)
lineIndex = lineIndex + 1
---@type string
local petName = nestedBkSpellData.petName
local petName = nestedBkSpellData.actorName
---@type string
local nameToUse = petName ~= "" and petName or actorName
local bIsMainLine = false
@@ -201,25 +201,51 @@ local createOptionsPanel = function()
},
{type = "blank"},
{type = "label", get = function() return "Merge Options" end, text_template = subSectionTitleTextTemplate},
{ --merge player spells
{type = "label", get = function() return "Group Player Spells:" end, text_template = subSectionTitleTextTemplate},
{ --nest player spells | merge player spells
type = "toggle",
get = function() return Details.breakdown_spell_tab.merge_players_spells_with_same_name end,
get = function() return Details.breakdown_spell_tab.nest_players_spells_with_same_name end,
set = function(self, fixedparam, value)
Details.breakdown_spell_tab.merge_players_spells_with_same_name = value
Details.breakdown_spell_tab.nest_players_spells_with_same_name = value
end,
name = "Group Player Spells With Same Name",
desc = "Group Player Spells With Same Name",
desc = "Group spells casted by players which has the same name",
},
{ --merge pet spells with the same name
{type = "blank"},
{type = "label", get = function() return "Group Pet Spells:" end, text_template = subSectionTitleTextTemplate},
{ --nest pet spells with the same name
type = "toggle",
get = function() return Details.breakdown_spell_tab.merge_pet_spells_with_same_name end,
get = function() return Details.breakdown_spell_tab.nest_pet_spells_by_name end,
set = function(self, fixedparam, value)
Details.breakdown_spell_tab.merge_pet_spells_with_same_name = value
Details.breakdown_spell_tab.nest_pet_spells_by_name = value
end,
name = "Group Pets By Spell",
name = "Group Pet Names Under a Pet Spell Bar",
desc = "Group Pets By Name",
hooks = {["OnSwitch"] = function()
if (Details.breakdown_spell_tab.nest_pet_spells_by_name) then
Details.breakdown_spell_tab.nest_pet_spells_by_caster = false
DetailsSpellBreakdownOptionsPanel:RefreshOptions()
end
end}
},
{ --nest pet spells with the same name
type = "toggle",
get = function() return Details.breakdown_spell_tab.nest_pet_spells_by_caster end,
set = function(self, fixedparam, value)
Details.breakdown_spell_tab.nest_pet_spells_by_caster = value
end,
name = "Group Pet Spells Under a Pet Name Bar",
desc = "Group Pets By Spell",
hooks = {["OnSwitch"] = function()
if (Details.breakdown_spell_tab.nest_pet_spells_by_caster) then
Details.breakdown_spell_tab.nest_pet_spells_by_name = false
DetailsSpellBreakdownOptionsPanel:RefreshOptions()
end
end}
},
}
+6 -2
View File
@@ -1411,8 +1411,12 @@ local default_global_data = {
--/run Details.breakdown_spell_tab.statusbar_alpha = 0.823
--breakdown spell tab
breakdown_spell_tab = {
merge_players_spells_with_same_name = true,
merge_pet_spells_with_same_name = true,
--player spells
nest_players_spells_with_same_name = true,
--pet spells
nest_pet_spells_by_name = false,
nest_pet_spells_by_caster = true,
blockcontainer_width = 430,
blockcontainer_height = 270,
blockcontainer_islocked = true,
Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB