Added report to breakdown window

This commit is contained in:
Tercio Jose
2024-02-26 13:53:27 -03:00
parent 937e167327
commit c4040ac4de
4 changed files with 205 additions and 53 deletions
@@ -12,6 +12,7 @@ local _GetSpellInfo = Details.GetSpellInfo
local GameTooltip = GameTooltip
local IsShiftKeyDown = IsShiftKeyDown
local DF = DetailsFramework
local detailsFramework = DetailsFramework
local tinsert = table.insert
local spellsTab = DetailsSpellBreakdownTab
@@ -246,6 +247,34 @@ function spellsTab.CreatePhasesContainer(tabFrame) --~phase ~createphasecontaine
local phaseScrollFrame = DF:CreateScrollBox(container, "$parentPhaseScroll", refreshPhaseFunc, {}, width, height, defaultAmountOfLines, CONST_SPELLSCROLL_LINEHEIGHT)
DF:ReskinSlider(phaseScrollFrame)
---@param self breakdownphasescrollframe
---@return breakdownreporttable
function phaseScrollFrame:GetReportData()
local instance = spellsTab.GetInstance()
local data = phaseScrollFrame:GetData()
local formatFunc = Details:GetCurrentToKFunction()
local actorObject = spellsTab.GetActor()
local displayId, subDisplayId = instance:GetDisplay()
local subDisplayName = Details:GetSubAttributeName(displayId, subDisplayId)
local combatName = instance:GetCombat():GetCombatName()
---@type breakdownreporttable
local reportData = {
title = "Phases for " .. detailsFramework:RemoveRealmName(actorObject:Name()) .. " | " .. subDisplayName .. " | " .. combatName
}
for i = 1, #data do
local dataTable = data[i]
reportData[#reportData+1] = {
name = "Phase:" .. dataTable.phaseName,
amount = formatFunc(nil, dataTable.amountDone),
percent = string.format("%.1f", dataTable.percentDone) .. "%",
}
end
return reportData
end
phaseScrollFrame:SetBackdrop({})
phaseScrollFrame:SetAllPoints()
@@ -15,6 +15,8 @@ local tinsert = table.insert
---@type detailsframework
local DF = DetailsFramework
---@type detailsframework
local detailsFramework = DetailsFramework
local spellsTab = DetailsSpellBreakdownTab
@@ -191,7 +193,7 @@ local onEnterSpellBar = function(spellBar, motion) --parei aqui: precisa por nom
local elapsedTime = spellBar.combatTime --this should be actorObject:Tempo()
---@type string
local actorName = spellsTab.GetActor():Name() --attempt to index a nil value
local actorName = spellsTab.GetActor():Name() --attempt to index a nil value x2
---@type spelltable
local spellTable = spellBar.spellTable
@@ -511,7 +513,7 @@ local spellBlockMixin = {
function spellsTab.CreateSpellBlock(spellBlockContainer, index) --~breakdownspellblock ~create ~spellblocks
---@type breakdownspellblock
local spellBlock = CreateFrame("statusbar", "$parentBlock" .. index, spellBlockContainer, "BackdropTemplate")
DetailsFramework:Mixin(spellBlock, spellBlockMixin)
detailsFramework:Mixin(spellBlock, spellBlockMixin)
local statusBarTexture = spellBlock:CreateTexture("$parentTexture", "artwork")
statusBarTexture:SetColorTexture(unpack(CONST_SPELLBLOCK_DEFAULT_COLOR))
@@ -570,7 +572,7 @@ function spellsTab.CreateSpellBlock(spellBlockContainer, index) --~breakdownspel
spellBlock.sparkTexture:SetTexture("Interface\\AddOns\\Details\\images\\bar_detalhes2_end")
spellBlock.sparkTexture:SetBlendMode("ADD")
local gradientDown = DetailsFramework:CreateTexture(spellBlock, {gradient = "vertical", fromColor = {0, 0, 0, 0.1}, toColor = "transparent"}, 1, spellBlock:GetHeight(), "background", {0, 1, 0, 1})
local gradientDown = detailsFramework:CreateTexture(spellBlock, {gradient = "vertical", fromColor = {0, 0, 0, 0.1}, toColor = "transparent"}, 1, spellBlock:GetHeight(), "background", {0, 1, 0, 1})
gradientDown:SetPoint("bottoms")
spellBlock.gradientTexture = gradientDown
spellBlock.gradientTexture:Hide()
@@ -776,7 +778,7 @@ function spellsTab.CreateSpellBlockContainer(tabFrame) --~create ~createblock ~s
spellBlockFrame:SetResizable(false)
spellBlockFrame:SetMovable(false)
spellBlockFrame:SetAllPoints()
DetailsFramework:Mixin(spellBlockFrame, spellBlockContainerMixin)
detailsFramework:Mixin(spellBlockFrame, spellBlockContainerMixin)
tabFrame.SpellBlockFrame = spellBlockFrame
spellsTab.SpellBlockFrame = spellBlockFrame
@@ -1313,6 +1315,52 @@ function spellsTab.CreateSpellScrollContainer(tabFrame) --~scroll ~create ~spell
spellsTab.ApplyStandardBackdrop(container, scrollFrame)
---@param self breakdownphasescrollframe
---@return breakdownreporttable
function scrollFrame:GetReportData()
local instance = spellsTab.GetInstance()
---@type breakdownspelldatalist
local data = self:GetData()
local formatFunc = Details:GetCurrentToKFunction()
local actorObject = spellsTab.GetActor()
local displayId, subDisplayId = instance:GetDisplay()
local subDisplayName = Details:GetSubAttributeName(displayId, subDisplayId)
local combatName = instance:GetCombat():GetCombatName()
---@type breakdownreporttable
local reportData = {
title = subDisplayName .. " for " .. detailsFramework:RemoveRealmName(actorObject:Name()) .. " | " .. combatName
}
local topValue = data[1] and data[1].total or 0
for i = 1, #data do
---@type spelltableadv
local bkSpellData = data[i]
local spellId = bkSpellData.id
local spellName = Details.GetSpellInfo(spellId)
if (not spellName) then
--dumpt(bkSpellData)
if (bkSpellData.npcId) then
spellName = detailsFramework:CleanUpName(bkSpellData.actorName)
end
else
spellName = detailsFramework:CleanUpName(spellName)
end
reportData[#reportData+1] = {
name = spellName,
amount = formatFunc(nil, bkSpellData.total),
percent = string.format("%.1f", bkSpellData.total/topValue*100) .. "%",
}
end
return reportData
end
--~header
local headerOptions = {
padding = 2,
@@ -11,9 +11,13 @@ local GetSpellInfo = GetSpellInfo
local _GetSpellInfo = Details.GetSpellInfo
local GameTooltip = GameTooltip
local IsShiftKeyDown = IsShiftKeyDown
local DF = DetailsFramework
local tinsert = table.insert
---@type detailsframework
local DF = DetailsFramework
---@type detailsframework
local detailsFramework = DetailsFramework
local spellsTab = DetailsSpellBreakdownTab
local headerContainerType = spellsTab.headerContainerType
@@ -280,6 +284,38 @@ function spellsTab.CreateTargetContainer(tabFrame) --~create ~target ~createtarg
targetScrollFrame:SetBackdrop({})
targetScrollFrame:SetAllPoints()
---@param self breakdownphasescrollframe
---@return breakdownreporttable
function targetScrollFrame:GetReportData()
local instance = spellsTab.GetInstance()
local data = targetScrollFrame:GetData()
local formatFunc = Details:GetCurrentToKFunction()
local actorObject = spellsTab.GetActor()
local displayId, subDisplayId = instance:GetDisplay()
local subDisplayName = Details:GetSubAttributeName(displayId, subDisplayId)
local combatName = instance:GetCombat():GetCombatName()
---@type breakdownreporttable
local reportData = {
title = "Target of " .. detailsFramework:RemoveRealmName(actorObject:Name()) .. " | " .. subDisplayName .. " | " .. combatName
}
local topValue = data[1] and data[1].total or 0
for i = 1, #data do
---@type breakdowntargettable
local dataTable = data[i]
reportData[#reportData+1] = {
name = dataTable.name,
amount = formatFunc(nil, dataTable.total),
percent = string.format("%.1f", dataTable.total / topValue * 100) .. "%",
}
end
return reportData
end
container:RegisterChildForDrag(targetScrollFrame)
targetScrollFrame.DontHideChildrenOnPreRefresh = false
@@ -13,11 +13,22 @@ local GetSpellInfo = GetSpellInfo
local _GetSpellInfo = Details.GetSpellInfo
local GameTooltip = GameTooltip
local IsShiftKeyDown = IsShiftKeyDown
local DF = DetailsFramework
local tinsert = table.insert
---@type detailsframework
local DF = DetailsFramework
---@type detailsframework
local detailsFramework = DetailsFramework
---@type breakdownspelltab
local spellsTab = {}
spellsTab.ReportOverlays = {}
function spellsTab.SetShownReportOverlay(bIsShown)
for robIndex, ROB in ipairs(spellsTab.ReportOverlays) do
ROB:SetShown(bIsShown)
end
end
--expose the object to the global namespace
DetailsSpellBreakdownTab = spellsTab
@@ -521,6 +532,8 @@ function spellsTab.OnShownTab()
spellsTab.UpdateHeadersSettings("phases")
spellsTab.UpdateHeadersSettings("generic_left")
spellsTab.UpdateHeadersSettings("generic_right")
spellsTab.SetShownReportOverlay(false)
end
---called when the tab is getting created, run only once
@@ -550,63 +563,89 @@ function spellsTab.OnCreateTabCallback(tabButton, tabFrame) --~init
local optionsButton = DF:CreateButton(tabFrame, Details.OpenSpellBreakdownOptions, 130, 18, Loc["STRING_OPTIONS_PLUGINS_OPTIONS"], 14)
--optionsButton:SetTemplate(DF:GetTemplate("button", "OPTIONS_BUTTON_TEMPLATE"))
optionsButton:SetPoint("bottomright", tabFrame, "bottomright", -10, -19)
optionsButton:SetTemplate("OPTIONS_BUTTON_TEMPLATE")
optionsButton:SetIcon(Details:GetTextureAtlas("breakdown-icon-optionsbutton"))
optionsButton.textsize = 12
optionsButton.textcolor = "orange"
---@type df_roundedpanel_preset
local preset = {
roundness = 5,
color = {.2, .2, .2, 0.98},
border_color = {.1, .1, .1, 0.834},
}
DF:AddRoundedCornersToFrame(optionsButton, preset)
optionsButton.textcolor = "DETAILS_STATISTICS_ICON"
optionsButton:SetAlpha(0.834)
--create a report button
local onClickReportButton = function(blizButton, buttonType, param1, param2)
--get what is shown in the breakdown window
local instance = spellsTab.GetInstance()
local actor = spellsTab.GetActor()
local combat = spellsTab.GetCombat()
local displayId, subDisplayId = instance:GetDisplay()
local spellScroll = spellsTab.GetSpellScrollFrame()
local getNumLines = spellScroll:GetNumFramesShown()
local dataToReport = {}
for i = 1, getNumLines do
---@type breakdownspellbar
local thisLine = spellScroll:GetLine(i)
--get the spell id
local spellId = thisLine.spellId
local spellName = GetSpellInfo(spellId)
--get the amount
local bkSpellData = thisLine.bkSpellData
if (bkSpellData) then
--dumpt(bkSpellData)
if (displayId == DETAILS_ATTRIBUTE_DAMAGE) then
if (subDisplayId == DETAILS_ATTRIBUTE_DAMAGE) then
dataToReport[#dataToReport+1] = spellName .. " .. " .. bkSpellData.total --, {bkSpellData.total, spellName, spellId}
end
end
end
if (spellsTab.ReportOverlays[1]:IsShown()) then
spellsTab.SetShownReportOverlay(false)
else
spellsTab.SetShownReportOverlay(true)
end
if (#dataToReport > 0) then
instance:Reportar(dataToReport, {}, nil, nil)
end
end
---~report
local reportScrollContents = function(self, buttonPressed)
local scrollFrame = self.scrollFrame
---@type breakdownreporttable
local reportData = scrollFrame:GetReportData()
local reportDataBuilt = {reportData.title}
for i = 1, #reportData do
local data = reportData[i]
local str = data.name .. " ...... " .. data.amount .. " (" .. data.percent .. ")"
reportDataBuilt[#reportDataBuilt+1] = str
end
spellsTab.SetShownReportOverlay(false)
Details:Reportar(reportDataBuilt, {_no_current = true, _no_inverse = true, _custom = true})
end
--create a report overlay for each of the containers
local createReportOverlay = function(scrollFrame)
local reportOverlayButton = CreateFrame("button", "DetailsSpellScrollSelectionButton", scrollFrame, "BackdropTemplate")
local ROB = reportOverlayButton
spellsTab.ReportOverlays[#spellsTab.ReportOverlays+1] = ROB
--backdrop
ROB:SetBackdrop({
edgeFile = [[Interface\AddOns\Details\images\border_2]],
edgeSize = 16,
})
ROB:SetFrameLevel(scrollFrame:GetFrameLevel()+5)
ROB:SetAllPoints()
ROB:EnableMouse(true)
local backgroundTexture = ROB:CreateTexture("DetailsSpellScrollSelectionButtonTexture", "overlay")
--instead of all point, do topleft and bottomright
backgroundTexture:SetPoint("topleft", ROB, "topleft", 0, 0)
backgroundTexture:SetPoint("bottomright", ROB, "bottomright", 0, 0)
ROB.backgroundTexture = backgroundTexture
backgroundTexture:SetColorTexture(.1, .1, .1, 0.834)
local text = ROB:CreateFontString(nil, "overlay", "GameFontNormal")
text:SetText("REPORT")
text:SetTextColor(1, 1, 1, 1)
text:SetPoint("center", ROB, "center", 0, 0)
ROB.reportText = text
ROB.scrollFrame = scrollFrame
ROB:SetScript("OnClick", reportScrollContents)
ROB:Hide()
end
createReportOverlay(spellsTab.GetSpellScrollFrame())
createReportOverlay(spellsTab.GetTargetScrollFrame())
createReportOverlay(spellsTab.GetPhaseScrollFrame())
createReportOverlay(spellsTab.GetGenericScrollFrame())
local reportButton = DF:CreateButton(tabFrame, onClickReportButton, 130, 18, Loc["STRING_REPORT_TEXT"], 1, 2) --will have a text?
reportButton:SetPoint("right", optionsButton, "left", -5, 0)
reportButton.textsize = 12
reportButton.textcolor = "orange"
DF:AddRoundedCornersToFrame(reportButton, preset)
reportButton.textcolor = "DETAILS_STATISTICS_ICON"
reportButton:SetTemplate("OPTIONS_BUTTON_TEMPLATE")
reportButton:SetIcon(Details:GetTextureAtlas("breakdown-icon-reportbutton"))
reportButton:SetAlpha(0.834)
--open the breakdown window at startup for testing
--[=[ debug