You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1121 lines
51 KiB

4 years ago
--todo: need to fix this file after pre-patch
local Details = _G.Details
local DF = _G.DetailsFramework
local Loc = _G.LibStub("AceLocale-3.0"):GetLocale("Details")
local tocName, Details222 = ...
local _
4 years ago
--prefix used on sync statistics
local CONST_GUILD_SYNC = "GS"
5 months ago
local difficultyNames = {
["normal"] = true,
["heroic"] = true,
["mythic"] = true,
["raidfinder"] = true,
}
4 years ago
function Details:InitializeRaidHistoryWindow()
3 years ago
local DetailsRaidHistoryWindow = CreateFrame("frame", "DetailsRaidHistoryWindow", UIParent,"BackdropTemplate")
4 years ago
DetailsRaidHistoryWindow.Frame = DetailsRaidHistoryWindow
DetailsRaidHistoryWindow.__name = Loc ["STRING_STATISTICS"]
DetailsRaidHistoryWindow.real_name = "DETAILS_STATISTICS"
DetailsRaidHistoryWindow.__icon = [[Interface\AddOns\Details\images\icons]]
DetailsRaidHistoryWindow.__iconcoords = {278/512, 314/512, 43/512, 76/512}
DetailsRaidHistoryWindow.__iconcolor = "DETAILS_STATISTICS_ICON"
DetailsPluginContainerWindow.EmbedPlugin (DetailsRaidHistoryWindow, DetailsRaidHistoryWindow, true)
function DetailsRaidHistoryWindow.RefreshWindow()
Details:OpenRaidHistoryWindow()
C_Timer.After(1, function()
Details:OpenRaidHistoryWindow()
end)
end
end
function Details:OpenRaidHistoryWindow(raidName, bossEncounterId, difficultyId, playerRole, guildName, playerBase, playerName, historyType)
5 months ago
if (type(raidName) == "table") then
raidName = nil
end
if (guildName == "LeftButton") then
guildName = nil
end
4 years ago
if (not DetailsRaidHistoryWindow or not DetailsRaidHistoryWindow.Initialized) then
DetailsRaidHistoryWindow.Initialized = true
3 years ago
local statisticsFrame = DetailsRaidHistoryWindow or CreateFrame("frame", "DetailsRaidHistoryWindow", UIParent, "BackdropTemplate")
statisticsFrame:SetPoint("center", UIParent, "center")
statisticsFrame:SetFrameStrata("HIGH")
statisticsFrame:SetToplevel(true)
3 years ago
statisticsFrame:SetMovable(true)
statisticsFrame:SetWidth(850)
statisticsFrame:SetHeight(500)
table.insert(UISpecialFrames, "DetailsRaidHistoryWindow")
4 years ago
function statisticsFrame.OpenDB()
local db = Details222.storage.OpenRaidStorage()
4 years ago
if (not db) then
Details:Msg(Loc ["STRING_GUILDDAMAGERANK_DATABASEERROR"])
return
end
return db
end
local db = statisticsFrame.OpenDB()
4 years ago
if (not db) then
return
end
statisticsFrame.Mode = 2
4 years ago
DF:ApplyStandardBackdrop(statisticsFrame)
--create title bar
local titlebar = DF:CreateTitleBar(statisticsFrame, "Details! " .. Loc ["STRING_STATISTICS"])
titlebar.CloseButton:SetScript("OnClick", function() statisticsFrame:GetParent():Hide() end)
--STRING_GUILDDAMAGERANK_TUTORIAL_DESC
--STRING_OPTIONS_CHART_CLOSE
3 years ago
--background
local background = statisticsFrame:CreateTexture("$parentBackgroundImage", "border")
background:SetAlpha(0.3)
background:SetPoint("topleft", statisticsFrame, "topleft", 6, -65)
background:SetPoint("bottomright", statisticsFrame, "bottomright", -10, 28)
3 years ago
--separate menu and main list
local div = statisticsFrame:CreateTexture(nil, "artwork")
div:SetTexture([[Interface\ACHIEVEMENTFRAME\UI-Achievement-MetalBorder-Left]])
div:SetAlpha(0.1)
div:SetPoint("topleft", statisticsFrame, "topleft", 180, -64)
div:SetHeight(574)
4 years ago
--select history or guild rank
3 years ago
local options_switch_template = DF:GetTemplate("switch", "OPTIONS_CHECKBOX_TEMPLATE")
local options_text_template = DF:GetTemplate("font", "OPTIONS_FONT_TEMPLATE")
local options_button_template = DF:GetTemplate("button", "OPTIONS_BUTTON_TEMPLATE")
4 years ago
local selectKillTimeline = function()
statisticsFrame.GuildRankCheckBox:SetValue(false)
statisticsFrame.HistoryCheckBox:SetValue(true)
statisticsFrame.Mode = 1
statisticsFrame:Refresh()
statisticsFrame.ReportButton:Hide()
4 years ago
end
local selectGuildRank = function()
statisticsFrame.HistoryCheckBox:SetValue(false)
statisticsFrame.GuildRankCheckBox:SetValue(true)
statisticsFrame.select_player:Select(1, true)
statisticsFrame.select_player2:Hide()
statisticsFrame.select_player2_label:Hide()
statisticsFrame.Mode = 2
statisticsFrame:Refresh()
statisticsFrame.ReportButton:Show()
4 years ago
end
--kill timeline
local HistoryCheckBox, HistoryLabel = DF:CreateSwitch(statisticsFrame, selectKillTimeline, false, 18, 18, "", "", "HistoryCheckBox", nil, nil, nil, nil, Loc ["STRING_GUILDDAMAGERANK_SHOWHISTORY"], options_switch_template) --, options_text_template
4 years ago
HistoryLabel:ClearAllPoints()
HistoryCheckBox:ClearAllPoints()
HistoryCheckBox:SetPoint("topleft", statisticsFrame, "topleft", 100, -34)
3 years ago
HistoryLabel:SetPoint("left", HistoryCheckBox, "right", 2, 0)
4 years ago
HistoryCheckBox:SetAsCheckBox()
--guildrank
local GuildRankCheckBox, GuildRankLabel = DF:CreateSwitch(statisticsFrame, selectGuildRank, true, 18, 18, "", "", "GuildRankCheckBox", nil, nil, nil, nil, Loc ["STRING_GUILDDAMAGERANK_SHOWRANK"], options_switch_template) --, options_text_template
4 years ago
GuildRankLabel:ClearAllPoints()
GuildRankCheckBox:ClearAllPoints()
GuildRankCheckBox:SetPoint("topleft", statisticsFrame, "topleft", 240, -34)
3 years ago
GuildRankLabel:SetPoint("left", GuildRankCheckBox, "right", 2, 0)
4 years ago
GuildRankCheckBox:SetAsCheckBox()
3 years ago
--guild sync
local doGuildSync = function()
statisticsFrame.RequestedAmount = 0
statisticsFrame.DownloadedAmount = 0
statisticsFrame.EstimateSize = 0
statisticsFrame.DownloadedSize = 0
statisticsFrame.SyncStartTime = time()
Details222.storage.DBGuildSync()
statisticsFrame.GuildSyncButton:Disable()
if (not statisticsFrame.SyncTexture) then
local workingFrame = CreateFrame("frame", nil, statisticsFrame, "BackdropTemplate")
statisticsFrame.WorkingFrame = workingFrame
workingFrame:SetSize(1, 1)
statisticsFrame.SyncTextureBackground = workingFrame:CreateTexture(nil, "border")
statisticsFrame.SyncTextureBackground:SetPoint("bottomright", statisticsFrame, "bottomright", -5, -1)
statisticsFrame.SyncTextureBackground:SetTexture([[Interface\COMMON\StreamBackground]])
statisticsFrame.SyncTextureBackground:SetSize(32, 32)
statisticsFrame.SyncTextureCircle = workingFrame:CreateTexture(nil, "artwork")
statisticsFrame.SyncTextureCircle:SetPoint("center", statisticsFrame.SyncTextureBackground, "center", 0, 0)
statisticsFrame.SyncTextureCircle:SetTexture([[Interface\COMMON\StreamCircle]])
statisticsFrame.SyncTextureCircle:SetSize(32, 32)
statisticsFrame.SyncTextureGrade = workingFrame:CreateTexture(nil, "overlay")
statisticsFrame.SyncTextureGrade:SetPoint("center", statisticsFrame.SyncTextureBackground, "center", 0, 0)
statisticsFrame.SyncTextureGrade:SetTexture([[Interface\COMMON\StreamFrame]])
statisticsFrame.SyncTextureGrade:SetSize(32, 32)
local animationHub = DF:CreateAnimationHub(workingFrame)
animationHub:SetLooping("Repeat")
statisticsFrame.WorkingAnimation = animationHub
local rotation = DF:CreateAnimation(animationHub, "ROTATION", 1, 3, -360)
rotation:SetTarget(statisticsFrame.SyncTextureCircle)
statisticsFrame.SyncText = workingFrame:CreateFontString(nil, "border", "GameFontNormal")
statisticsFrame.SyncText:SetPoint("right", statisticsFrame.SyncTextureBackground, "left", 0, 0)
statisticsFrame.SyncText:SetText("working")
local endAnimationHub = DF:CreateAnimationHub(workingFrame, nil, function() workingFrame:Hide() end)
DF:CreateAnimation(endAnimationHub, "ALPHA", 1, 0.5, 1, 0)
statisticsFrame.EndAnimationHub = endAnimationHub
end
4 years ago
statisticsFrame.WorkingFrame:Show()
statisticsFrame.WorkingAnimation:Play()
4 years ago
C_Timer.NewTicker(10, function(self)
if (not Details.LastGuildSyncReceived) then
statisticsFrame.GuildSyncButton:Enable()
statisticsFrame.EndAnimationHub:Play()
4 years ago
elseif (Details.LastGuildSyncReceived+10 < GetTime()) then
statisticsFrame.GuildSyncButton:Enable()
statisticsFrame.EndAnimationHub:Play()
self:Cancel()
end
end)
end
4 years ago
local guildSyncButton = DF:CreateButton(statisticsFrame, doGuildSync, 130, 20, Loc ["STRING_GUILDDAMAGERANK_SYNCBUTTONTEXT"], nil, nil, nil, "GuildSyncButton", nil, nil, options_button_template, options_text_template)
guildSyncButton:SetPoint("topright", statisticsFrame, "topright", -20, -34)
guildSyncButton:SetIcon([[Interface\GLUES\CharacterSelect\RestoreButton]], 12, 12, "overlay", {0.2, .8, 0.2, .8}, nil, 4)
4 years ago
3 years ago
--listen to comm events
local eventListener = Details:CreateEventListener()
4 years ago
function eventListener:OnCommReceived(event, length, prefix, playerName, realmName, detailsVersion, guildSyncID, data)
if (prefix == CONST_GUILD_SYNC) then
--print(event, length, prefix, playerName, realmName, detailsVersion, guildSyncID, data)
4 years ago
--received a list of encounter IDs
if (guildSyncID == "L") then
--received one encounter table
elseif (guildSyncID == "A") then
if (not statisticsFrame.RequestedAmount) then
--if the receiving player reloads, f.RequestedAmount is nil
return
4 years ago
end
statisticsFrame.DownloadedAmount = (statisticsFrame.DownloadedAmount or 0) + 1
--size = 1 byte per characters in the string
statisticsFrame.EstimateSize = length * statisticsFrame.RequestedAmount > statisticsFrame.EstimateSize and length * statisticsFrame.RequestedAmount or statisticsFrame.RequestedAmount
statisticsFrame.DownloadedSize = statisticsFrame.DownloadedSize + length
local downloadSpeed = statisticsFrame.DownloadedSize / (time() - statisticsFrame.SyncStartTime)
statisticsFrame.SyncText:SetText("working [downloading " .. statisticsFrame.DownloadedAmount .. "/" .. statisticsFrame.RequestedAmount .. ", " .. format("%.2f", downloadSpeed/1024) .. "Kbps]")
4 years ago
end
end
end
4 years ago
function eventListener:OnCommSent(event, length, prefix, playerName, realmName, detailsVersion, guildSyncID, missingIDs, arg8, arg9)
if (prefix == CONST_GUILD_SYNC) then
--print(event, length, prefix, playerName, realmName, detailsVersion, guildSyncID, missingIDs, arg8, arg9)
4 years ago
--requested a list of encounters
if (guildSyncID == "R") then
--requested to download a selected list of encounter tables
elseif (guildSyncID == "G") then
statisticsFrame.RequestedAmount = statisticsFrame.RequestedAmount + #missingIDs
statisticsFrame.SyncText:SetText("working [downloading " .. statisticsFrame.DownloadedAmount .. "/" .. statisticsFrame.RequestedAmount .. "]")
4 years ago
end
end
end
4 years ago
eventListener:RegisterEvent("COMM_EVENT_RECEIVED", "OnCommReceived")
eventListener:RegisterEvent("COMM_EVENT_SENT", "OnCommSent")
4 years ago
3 years ago
--report results
function statisticsFrame.BuildReport()
if (statisticsFrame.LatestResourceTable) then
local reportFunc = function(IsCurrent, IsReverse, AmtLines)
local bossName = statisticsFrame.select_boss.label:GetText()
local bossDiff = statisticsFrame.select_diff.label:GetText()
local guildName = statisticsFrame.select_guild.label:GetText()
local reportTable = {"Details!: DPS Rank for: " .. (bossDiff or "") .. " " .. (bossName or "--x--x--") .. " <" .. (guildName or "") .. ">"}
local result = {}
for i = 1, AmtLines do
if (statisticsFrame.LatestResourceTable[i]) then
local playerName = statisticsFrame.LatestResourceTable[i][1]
playerName = playerName:gsub("%|c%x%x%x%x%x%x%x%x", "")
playerName = playerName:gsub("%|r", "")
playerName = playerName:gsub(".*%s", "")
table.insert(result, {playerName, statisticsFrame.LatestResourceTable[i][2]})
else
break
4 years ago
end
end
Details:FormatReportLines(reportTable, result)
Details:SendReportLines(reportTable)
4 years ago
end
Details:SendReportWindow(reportFunc, nil, nil, true)
4 years ago
end
end
4 years ago
local reportButton = DF:CreateButton(statisticsFrame, statisticsFrame.BuildReport, 130, 20, Loc ["STRING_OPTIONS_REPORT_ANCHOR"]:gsub(":", ""), nil, nil, nil, "ReportButton", nil, nil, options_button_template, options_text_template)
reportButton:SetPoint("right", guildSyncButton, "left", -2, 0)
reportButton:SetIcon([[Interface\GLUES\CharacterSelect\RestoreButton]], 12, 12, "overlay", {0.2, .8, 0.2, .8}, nil, 4)
4 years ago
--
function statisticsFrame:SetBackgroundImage(encounterId)
local instanceId = Details:GetInstanceIdFromEncounterId(encounterId)
4 years ago
if (instanceId) then
local file, L, R, T, B = Details:GetRaidBackground(instanceId)
3 years ago
--print("file:", file)
4 years ago
--can't get the image, looks to be restricted
--[[
if (file) then
background:SetTexture(file)
background:SetTexCoord(L, R, T, B)
else
background:SetColorTexture(0.2, 0.2, 0.2, 0.8)
end
--]]
background:SetColorTexture(0.2, 0.2, 0.2, 0.8)
end
end
3 years ago
--window script handlers
statisticsFrame:SetScript("OnMouseDown", function(self, button)
if (self.isMoving) then
return
end
if (button == "RightButton") then
self:Hide()
else
self:StartMoving()
self.isMoving = true
end
end)
4 years ago
statisticsFrame:SetScript("OnMouseUp", function(self, button)
if (self.isMoving and button == "LeftButton") then
self:StopMovingOrSizing()
self.isMoving = nil
end
end)
4 years ago
statisticsFrame:SetScript("OnHide", function()
--save latest shown state
statisticsFrame.LatestSelection = statisticsFrame.LatestSelection or {}
statisticsFrame.LatestSelection.Raid = DetailsRaidHistoryWindow.select_raid.value
statisticsFrame.LatestSelection.Boss = DetailsRaidHistoryWindow.select_boss.value
statisticsFrame.LatestSelection.Diff = DetailsRaidHistoryWindow.select_diff.value
statisticsFrame.LatestSelection.Role = DetailsRaidHistoryWindow.select_role.value
statisticsFrame.LatestSelection.Guild = DetailsRaidHistoryWindow.select_guild.value
statisticsFrame.LatestSelection.PlayerBase = DetailsRaidHistoryWindow.select_player.value
statisticsFrame.LatestSelection.PlayerName = DetailsRaidHistoryWindow.select_player2.value
end)
4 years ago
local dropdownWidth = 160
local icon = [[Interface\FriendsFrame\battlenet-status-offline]]
local difficultyList = {}
local raidList = {}
local bossList = {}
local guildList = {}
local sortAlphabetical = function(a,b) return a.value < b.value end
4 years ago
local onSelect = function()
if (statisticsFrame.Refresh) then
statisticsFrame:Refresh()
4 years ago
end
end
3 years ago
--select raid:
local onRaidSelect = function(_, _, raid)
Details.rank_window.last_raid = raid
statisticsFrame:UpdateDropdowns(true)
onSelect()
end
local buildRaidList = function()
return raidList
end
local raidDropdown = DF:CreateDropDown(statisticsFrame, buildRaidList, 1, dropdownWidth, 20, "select_raid")
local raidString = DF:CreateLabel(statisticsFrame, Loc ["STRING_GUILDDAMAGERANK_RAID"] .. ":", _, _, "GameFontNormal", "select_raid_label")
raidDropdown:SetTemplate(DF:GetTemplate("dropdown", "OPTIONS_DROPDOWN_TEMPLATE"))
4 years ago
3 years ago
--select boss:
local onSelectBoss = function(_, _, boss)
onSelect()
end
local buildBossList = function()
return bossList
end
local bossDropdown = DF:CreateDropDown(statisticsFrame, buildBossList, 1, dropdownWidth, 20, "select_boss")
local bossString = DF:CreateLabel(statisticsFrame, Loc ["STRING_GUILDDAMAGERANK_BOSS"] .. ":", _, _, "GameFontNormal", "select_boss_label")
bossDropdown:SetTemplate(DF:GetTemplate("dropdown", "OPTIONS_DROPDOWN_TEMPLATE"))
4 years ago
3 years ago
--select difficulty:
local onDifficultySelect = function(_, _, diff)
Details.rank_window.last_difficulty = diff
onSelect()
end
4 years ago
local buildDifficultyList = function()
return difficultyList
end
local difficultyDropdown = DF:CreateDropDown(statisticsFrame, buildDifficultyList, 1, dropdownWidth, 20, "select_diff")
local difficultyString = DF:CreateLabel(statisticsFrame, Loc ["STRING_GUILDDAMAGERANK_DIFF"] .. ":", _, _, "GameFontNormal", "select_diff_label")
difficultyDropdown:SetTemplate(DF:GetTemplate("dropdown", "OPTIONS_DROPDOWN_TEMPLATE"))
4 years ago
3 years ago
--select role:
local onRoleSelect = function(_, _, role)
onSelect()
end
local buildRoleList = function()
return {
5 months ago
{value = "DAMAGER", label = "Damager", icon = icon, onclick = onRoleSelect},
{value = "HEALER", label = "Healer", icon = icon, onclick = onRoleSelect}
}
end
local role_dropdown = DF:CreateDropDown (statisticsFrame, buildRoleList, 1, dropdownWidth, 20, "select_role")
local role_string = DF:CreateLabel(statisticsFrame, Loc ["STRING_GUILDDAMAGERANK_ROLE"] .. ":", _, _, "GameFontNormal", "select_role_label")
role_dropdown:SetTemplate(DF:GetTemplate("dropdown", "OPTIONS_DROPDOWN_TEMPLATE"))
4 years ago
3 years ago
--select guild:
local onGuildSelect = function(_, _, guild)
onSelect()
end
local buildGuildList = function()
return guildList
end
local guildDropdown = DF:CreateDropDown(statisticsFrame, buildGuildList, 1, dropdownWidth, 20, "select_guild")
local guildString = DF:CreateLabel(statisticsFrame, Loc ["STRING_GUILDDAMAGERANK_GUILD"] .. ":", _, _, "GameFontNormal", "select_guild_label")
guildDropdown:SetTemplate(DF:GetTemplate("dropdown", "OPTIONS_DROPDOWN_TEMPLATE"))
4 years ago
3 years ago
--select playerbase:
local onPlayerSelect = function(_, _, player)
onSelect()
end
local buildPlayerList = function()
return {
{value = 1, label = Loc ["STRING_GUILDDAMAGERANK_PLAYERBASE_RAID"], icon = icon, onclick = onPlayerSelect},
{value = 2, label = Loc ["STRING_GUILDDAMAGERANK_PLAYERBASE_INDIVIDUAL"], icon = icon, onclick = onPlayerSelect},
}
end
local player_dropdown = DF:CreateDropDown(statisticsFrame, buildPlayerList, 1, dropdownWidth, 20, "select_player")
local player_string = DF:CreateLabel(statisticsFrame, Loc ["STRING_GUILDDAMAGERANK_PLAYERBASE"] .. ":", _, _, "GameFontNormal", "select_player_label")
player_dropdown:SetTemplate(DF:GetTemplate("dropdown", "OPTIONS_DROPDOWN_TEMPLATE"))
4 years ago
3 years ago
--select player:
local onPlayer2Select = function(_, _, player)
statisticsFrame.latest_player_selected = player
statisticsFrame:BuildPlayerTable(player)
end
local buildPlayer2List = function()
local encounterTable, guild, role = unpack(statisticsFrame.build_player2_data or {})
local t = {}
local alreadyListed = {}
if (encounterTable) then
for encounterIndex, encounter in ipairs(encounterTable) do
if (encounter.guild == guild) then
local roleTable = encounter [role]
for playerName, _ in pairs(roleTable) do
if (not alreadyListed [playerName]) then
table.insert(t, {value = playerName, label = playerName, icon = icon, onclick = onPlayer2Select})
alreadyListed [playerName] = true
4 years ago
end
end
end
end
end
table.sort(t, sortAlphabetical)
return t
end
local player2Dropdown = DF:CreateDropDown(statisticsFrame, buildPlayer2List, 1, dropdownWidth, 20, "select_player2")
local player2String = DF:CreateLabel(statisticsFrame, Loc ["STRING_GUILDDAMAGERANK_PLAYERBASE_PLAYER"] .. ":", _, _, "GameFontNormal", "select_player2_label")
player2Dropdown:SetTemplate(DF:GetTemplate("dropdown", "OPTIONS_DROPDOWN_TEMPLATE"))
4 years ago
5 months ago
local fillDifficultyDropdown = function(difficulty)
--add the difficult to the dropdown
if (difficulty == "normal") then
local alreadyHave = false
for i, t in ipairs(difficultyList) do
if (t.label == "Normal") then
alreadyHave = true
end
end
if (not alreadyHave) then
table.insert(difficultyList, 1, {value = difficulty, label = "Normal", icon = icon, onclick = onDifficultySelect})
end
elseif (difficulty == "heroic") then
local alreadyHave = false
for i, t in ipairs(difficultyList) do
if (t.label == "Heroic") then
alreadyHave = true
end
end
if (not alreadyHave) then
table.insert(difficultyList, 1, {value = difficulty, label = "Heroic", icon = icon, onclick = onDifficultySelect})
end
elseif (difficulty == "mythic") then
local alreadyHave = false
for i, t in ipairs(difficultyList) do
if (t.label == "Mythic") then
alreadyHave = true
end
end
if (not alreadyHave) then
table.insert(difficultyList, {value = difficulty, label = "Mythic", icon = icon, onclick = onDifficultySelect})
end
end
end
function statisticsFrame:UpdateDropdowns(bDoNotSelectRaid)
local currentGuild = guildDropdown.value
4 years ago
--wipe data
Details:Destroy(difficultyList)
Details:Destroy(bossList)
Details:Destroy(raidList)
Details:Destroy(guildList)
4 years ago
local bossRepeated = {}
local raidRepeated = {}
local guildRepeated = {}
local raidSelected = _G.DetailsRaidHistoryWindow.select_raid:GetValue()
db = statisticsFrame.OpenDB()
4 years ago
if (not db) then
return
end
5 months ago
---@cast db details_storage
4 years ago
local playerGuildName = GetGuildInfo("player")
4 years ago
for difficulty, encounterIdTable in pairs(db) do
5 months ago
---@cast difficulty details_raid_difficulties
if (difficultyNames[difficulty]) then
---@cast encounterIdTable table<encounterid, details_encounterkillinfo[]>
for dungeonEncounterID, encounterKillsTable in pairs(encounterIdTable) do
---@cast encounterKillsTable details_encounterkillinfo[]
if (Details222.EJCache.IsCurrentContent(dungeonEncounterID)) then
if (not bossRepeated[dungeonEncounterID]) then
5 months ago
---@type details_encounterinfo
local encounterInfo = Details:GetEncounterInfo(dungeonEncounterID)
---@type details_instanceinfo
local instanceInfo = Details:GetInstanceInfo(encounterInfo and encounterInfo.instanceId)
5 months ago
if (encounterInfo and instanceInfo) then
local instanceId = instanceInfo.instanceId
if (raidSelected == instanceId) then
5 months ago
table.insert(bossList, {value = dungeonEncounterID, label = encounterInfo.name, icon = encounterInfo.creatureIcon, onclick = onSelectBoss})
bossRepeated[dungeonEncounterID] = true
end
4 years ago
5 months ago
if (not raidRepeated[instanceInfo.name]) then
local instanceName = instanceInfo.name
local raidIcon = instanceInfo.icon
local raidIconCoords = instanceInfo.iconCoords
table.insert(raidList, {value = instanceInfo.instanceId, label = instanceName, icon = raidIcon, texcoord = raidIconCoords, onclick = onRaidSelect})
raidRepeated[instanceInfo.name] = true
end
4 years ago
end
end
3 years ago
--add guild name to the dropdown
if (playerGuildName) then
if (not guildRepeated[playerGuildName]) then
table.insert(guildList, {value = playerGuildName, label = playerGuildName, icon = icon, onclick = onGuildSelect})
guildRepeated[playerGuildName] = true
end
else
5 months ago
for index, encounter in ipairs(encounterKillsTable) do
local guild = encounter.guild
if (not guildRepeated[guild]) then
table.insert(guildList, {value = guild, label = guild, icon = icon, onclick = onGuildSelect})
guildRepeated[guild] = true
end
4 years ago
end
end
3 years ago
--add the difficult to the dropdown
5 months ago
fillDifficultyDropdown(difficulty)
4 years ago
end
end
end
end
3 years ago
table.sort(bossList, function(t1, t2) return t1.label < t2.label end)
3 years ago
difficultyDropdown:Refresh()
guildDropdown:Refresh()
5 months ago
if (not bDoNotSelectRaid) then
raidDropdown:Refresh()
4 years ago
end
bossDropdown:Refresh()
3 years ago
C_Timer.After(1, function()
if (not bDoNotSelectRaid) then
raidDropdown:Select(1, true)
end
difficultyDropdown:Select(1, true)
if (currentGuild) then
guildDropdown:Select(currentGuild)
else
guildDropdown:Select(1, true)
end
bossDropdown:Select(1, true)
end)
5 months ago
end --end of UpdateDropdowns()
3 years ago
function statisticsFrame.UpdateBossDropdown()
4 years ago
local raidSelected = DetailsRaidHistoryWindow.select_raid:GetValue()
local bossRepeated = {}
Details:Destroy(bossList)
Details:Destroy(difficultyList)
3 years ago
for difficulty, encounterIdTable in pairs(db) do
5 months ago
---@cast difficulty details_raid_difficulties
if (difficultyNames[difficulty]) then
---@cast encounterIdTable table<encounterid, details_encounterkillinfo[]>
for dungeonEncounterID, encounterKillsTable in pairs(encounterIdTable) do
if (Details222.EJCache.IsCurrentContent(dungeonEncounterID)) then
if (not bossRepeated[dungeonEncounterID]) then
5 months ago
---@type details_encounterinfo
local encounterInfo = Details:GetEncounterInfo(dungeonEncounterID)
---@type details_instanceinfo
local instanceInfo = Details:GetInstanceInfo(encounterInfo and encounterInfo.instanceId)
if (encounterInfo and instanceInfo) then
if (raidSelected == instanceInfo.instanceId) then
table.insert(bossList, {value = dungeonEncounterID, label = encounterInfo.name, icon = encounterInfo.creatureIcon, onclick = onSelectBoss})
bossRepeated[dungeonEncounterID] = true
end
end
4 years ago
end
--add the difficult to the dropdown
5 months ago
fillDifficultyDropdown(difficulty)
4 years ago
end
end
end
end
3 years ago
table.sort(bossList, function(t1, t2) return t1.label < t2.label end)
bossDropdown:Refresh()
4 years ago
end
3 years ago
--anchors:
raidString:SetPoint("topleft", statisticsFrame, "topleft", 10, -70)
raidDropdown:SetPoint("topleft", statisticsFrame, "topleft", 10, -85)
3 years ago
bossString:SetPoint("topleft", statisticsFrame, "topleft", 10, -110)
bossDropdown:SetPoint("topleft", statisticsFrame, "topleft", 10, -125)
3 years ago
difficultyString:SetPoint("topleft", statisticsFrame, "topleft", 10, -150)
difficultyDropdown:SetPoint("topleft", statisticsFrame, "topleft", 10, -165)
3 years ago
role_string:SetPoint("topleft", statisticsFrame, "topleft", 10, -190)
role_dropdown:SetPoint("topleft", statisticsFrame, "topleft", 10, -205)
3 years ago
guildString:SetPoint("topleft", statisticsFrame, "topleft", 10, -230)
guildDropdown:SetPoint("topleft", statisticsFrame, "topleft", 10, -245)
3 years ago
player_string:SetPoint("topleft", statisticsFrame, "topleft", 10, -270)
player_dropdown:SetPoint("topleft", statisticsFrame, "topleft", 10, -285)
3 years ago
player2String:SetPoint("topleft", statisticsFrame, "topleft", 10, -310)
player2Dropdown:SetPoint("topleft", statisticsFrame, "topleft", 10, -325)
player2String:Hide()
player2Dropdown:Hide()
3 years ago
5 months ago
---@class details_stats_gframe_data
---@field text string
---@field value number
---@field utext string
---@field data details_storage_unitresult
---@field fulldate string
---@field elapsed number
3 years ago
5 months ago
function statisticsFrame:BuildPlayerTable(thisPlayerName)
local encounterTable, selectedGuildName, role = unpack(statisticsFrame.build_player2_data or {})
---@cast encounterTable details_encounterkillinfo[]
3 years ago
5 months ago
---@type details_stats_gframe_data[]
4 years ago
local data = {}
3 years ago
5 months ago
if (type(thisPlayerName) == "string" and string.len(thisPlayerName) > 1) then
for encounterIndex, encounterKillInfo in ipairs(encounterTable) do
if (encounterKillInfo.guild == selectedGuildName) then
---@type table<string, details_storage_unitresult>
local roleTable = encounterKillInfo[role]
3 years ago
5 months ago
local date = encounterKillInfo.date
3 years ago
date = date:gsub(".*%s", "")
5 months ago
date = date:sub(1, -4)
3 years ago
5 months ago
local playerTable = roleTable[thisPlayerName]
if (playerTable) then
table.insert(data, {text = date, value = playerTable.total, utext = Details:ToK2(playerTable.total/encounterKillInfo.elapsed), data = playerTable, fulldate = encounterKillInfo.date, elapsed = encounterKillInfo.elapsed})
4 years ago
end
end
end
3 years ago
--update graphic
if (not statisticsFrame.gframe) then
3 years ago
local onenter = function(self)
4 years ago
GameCooltip:Reset()
GameCooltip:SetType("tooltip")
3 years ago
GameCooltip:Preset(2)
4 years ago
5 months ago
---@type details_stats_gframe_data
local thisData = self.data
GameCooltip:AddLine("Total Done:", Details:ToK2(thisData.value), 1, "white")
GameCooltip:AddLine("Dps:", Details:ToK2(thisData.value / thisData.elapsed), 1, "white")
GameCooltip:AddLine("Item Level:", floor(thisData.data.itemLevel), 1, "white")
GameCooltip:AddLine("Date:", thisData.fulldate:gsub(".*%s", ""), 1, "white")
4 years ago
3 years ago
GameCooltip:SetOwner(self.ball.tooltip_anchor)
4 years ago
GameCooltip:Show()
end
3 years ago
local onleave = function(self)
4 years ago
GameCooltip:Hide()
end
3 years ago
statisticsFrame.gframe = DF:CreateGFrame(statisticsFrame, 650, 400, 35, onenter, onleave, "gframe", "$parentGF")
statisticsFrame.gframe:SetPoint("topleft", statisticsFrame, "topleft", 190, -65)
4 years ago
end
3 years ago
statisticsFrame.gframe:Reset()
statisticsFrame.gframe:UpdateLines(data)
4 years ago
end
end
3 years ago
local fillpanel = DF:NewFillPanel(statisticsFrame, {}, "$parentFP", "fillpanel", 710, 501, false, false, true, nil)
fillpanel:SetPoint("topleft", statisticsFrame, "topleft", 195, -65)
4 years ago
5 months ago
function statisticsFrame:BuildGuildRankTable(encounterKillsTable, selectedGuildName, role)
local header = {
{name = "Player Name", type = "text"},
{name = "Per Second", type = "text"},
{name = "Total", type = "text"},
{name = "Length", type = "text"},
{name = "Item Level", type = "text"},
{name = "Date", type = "text"}
}
---@cast encounterKillsTable details_encounterkillinfo[]
--print(encounterTable, guild, role)
--dumpt(encounterKillsTable) --encounterTable is empty at the first run when the panel is shown, coorect data after selecting a dropdown
3 years ago
4 years ago
local players = {}
local players_index = {}
3 years ago
5 months ago
---@type table<unitname, details_stats_playerinfo>
4 years ago
local playerScore = {}
3 years ago
5 months ago
---@class details_stats_playerinfo
---@field total number
---@field ps number
---@field ilvl number
---@field date string
---@field class number
---@field length number
4 years ago
--get the best of each player
5 months ago
for encounterIndex, encounterKillInfo in ipairs(encounterKillsTable) do
if (encounterKillInfo.guild == selectedGuildName) then
local roleTable = encounterKillInfo[role]
3 years ago
5 months ago
local date = encounterKillInfo.date
3 years ago
date = date:gsub(".*%s", "")
5 months ago
date = date:sub(1, -4)
3 years ago
5 months ago
---@cast roleTable table<actorname, details_storage_unitresult>
for thisPlayerName, playerTable in pairs(roleTable) do
if (not playerScore[thisPlayerName]) then
playerScore[thisPlayerName] = {
4 years ago
total = 0,
ps = 0,
ilvl = 0,
5 months ago
date = "",
4 years ago
class = 0,
length = 0,
}
end
3 years ago
5 months ago
local total = playerTable.total
local dps = total / encounterKillInfo.elapsed
if (dps > playerScore[thisPlayerName].ps) then
playerScore[thisPlayerName].total = total
playerScore[thisPlayerName].ps = total / encounterKillInfo.elapsed
playerScore[thisPlayerName].ilvl = playerTable.itemLevel
playerScore[thisPlayerName].length = encounterKillInfo.elapsed
playerScore[thisPlayerName].date = date
playerScore[thisPlayerName].class = playerTable.classId
4 years ago
end
end
end
end
3 years ago
4 years ago
local sortTable = {}
5 months ago
for thisPlayerName, playerInfo in pairs(playerScore) do
local className = select(2, GetClassInfo(playerInfo.class or 0))
4 years ago
local classColor = "FFFFFFFF"
if (className) then
classColor = RAID_CLASS_COLORS[className] and RAID_CLASS_COLORS[className].colorStr
4 years ago
end
3 years ago
5 months ago
local playerNameFormated = Details:GetOnlyName(thisPlayerName)
table.insert(sortTable, {
4 years ago
"|c" .. classColor .. playerNameFormated .. "|r",
5 months ago
Details:ToK2(playerInfo.ps),
Details:ToK2(playerInfo.total),
DF:IntegerToTimer(playerInfo.length),
floor(playerInfo.ilvl),
playerInfo.date,
playerInfo.total,
playerInfo.ps,
4 years ago
})
end
3 years ago
table.sort(sortTable, function(a, b) return a[8] > b[8] end)
3 years ago
--add the number before the player name
4 years ago
for i = 1, #sortTable do
local t = sortTable [i]
t[1] = i .. ". " .. t[1]
4 years ago
end
3 years ago
fillpanel:SetFillFunction(function(index) return sortTable [index] end)
fillpanel:SetTotalFunction(function() return #sortTable end)
fillpanel:UpdateRows(header)
4 years ago
fillpanel:Refresh()
3 years ago
statisticsFrame.LatestResourceTable = sortTable
4 years ago
end
3 years ago
5 months ago
---@param encounterKillsTable details_encounterkillinfo[]
---@param selectedGuildName string
---@param role string
function statisticsFrame:BuildRaidTable(encounterKillsTable, selectedGuildName, role)
if (statisticsFrame.Mode == 2) then
5 months ago
statisticsFrame:BuildGuildRankTable(encounterKillsTable, selectedGuildName, role)
4 years ago
return
end
3 years ago
4 years ago
local header = {{name = "Player Name", type = "text"}} -- , width = 90
local players = {}
3 years ago
5 months ago
---@type table<unitname, number>
local playerIndex = {}
3 years ago
5 months ago
---@type table<unitname, number>
local playerClassTable = {}
local encounterAmount = 0
for encounterIndex, encounterKillInfo in ipairs(encounterKillsTable) do
if (encounterKillInfo.guild == selectedGuildName) then
---@type table<actorname, details_storage_unitresult>
local roleTable = encounterKillInfo[role]
local date = encounterKillInfo.date
3 years ago
date = date:gsub(".*%s", "")
5 months ago
date = date:sub(1, -4)
encounterAmount = encounterAmount + 1
3 years ago
table.insert(header, {name = date, type = "text"})
3 years ago
5 months ago
for thisPlayerName, playerTable in pairs(roleTable) do
local index = playerIndex[thisPlayerName]
3 years ago
4 years ago
if (not index) then
5 months ago
local playerInfo = {thisPlayerName}
playerClassTable[thisPlayerName] = playerTable.classId
for i = 1, encounterAmount-1 do
table.insert(playerInfo, "")
4 years ago
end
5 months ago
table.insert(playerInfo, Details:ToK2(playerTable.total / encounterKillInfo.elapsed))
table.insert(players, playerInfo)
playerIndex[thisPlayerName] = #players
4 years ago
else
5 months ago
local player = players[index]
for i = #player+1, encounterAmount-1 do
table.insert(player, "")
4 years ago
end
5 months ago
table.insert(player, Details:ToK2(playerTable.total / encounterKillInfo.elapsed))
4 years ago
end
3 years ago
4 years ago
end
end
end
3 years ago
--sort alphabetical
5 months ago
table.sort(players, function(a, b) return a[1] < b[1] end)
3 years ago
for index, playerTable in ipairs(players) do
5 months ago
for i = #playerTable, encounterAmount do
table.insert(playerTable, "")
4 years ago
end
5 months ago
local className = select(2, GetClassInfo(playerClassTable[playerTable[1]] or 0))
4 years ago
if (className) then
3 years ago
local playerNameFormated = Details:GetOnlyName(playerTable[1])
5 months ago
local classColor = RAID_CLASS_COLORS[className] and RAID_CLASS_COLORS[className].colorStr
4 years ago
playerTable [1] = "|c" .. classColor .. playerNameFormated .. "|r"
end
end
3 years ago
5 months ago
fillpanel:SetFillFunction(function(index) return players [index] end)
fillpanel:SetTotalFunction(function() return #players end)
3 years ago
5 months ago
fillpanel:UpdateRows(header)
3 years ago
4 years ago
fillpanel:Refresh()
fillpanel:SetPoint("topleft", statisticsFrame, "topleft", 200, -65)
4 years ago
end
3 years ago
5 months ago
function statisticsFrame:Refresh(player_name) --called when any dropdown is selected
3 years ago
--build the main table
local diff = difficultyDropdown.value
local boss = bossDropdown.value
4 years ago
local role = role_dropdown.value
5 months ago
local selectedGuildName = guildDropdown.value
4 years ago
local player = player_dropdown.value
3 years ago
5 months ago
---@type table<number, details_encounterkillinfo[]>
local encounterIdTable = db[diff]
3 years ago
statisticsFrame:SetBackgroundImage(boss)
3 years ago
5 months ago
--[=[ if (difficultyNames[difficulty]) then
---@cast encounterIdTable table<encounterid, details_encounterkillinfo[]>
for dungeonEncounterID, encounterKillsTable in pairs(encounterIdTable) do
if (Details222.EJCache.IsCurrentContent(dungeonEncounterID)) then
if (not bossRepeated[dungeonEncounterID]) then
---@type details_encounterinfo
local encounterInfo = Details:GetEncounterInfo(dungeonEncounterID)
---@type details_instanceinfo
local instanceInfo = Details:GetInstanceInfo(encounterInfo and encounterInfo.instanceId)
]=]
if (encounterIdTable) then
local encounterKillsTable = encounterIdTable[boss]
if (encounterKillsTable) then
3 years ago
if (player == 1) then --raid
4 years ago
fillpanel:Show()
5 months ago
if (statisticsFrame.gframe) then
statisticsFrame.gframe:Hide()
4 years ago
end
5 months ago
player2String:Hide()
player2Dropdown:Hide()
5 months ago
statisticsFrame:BuildRaidTable(encounterKillsTable, selectedGuildName, role) --calling here
4 years ago
3 years ago
elseif (player == 2) then --only one player
4 years ago
fillpanel:Hide()
5 months ago
if (statisticsFrame.gframe) then
statisticsFrame.gframe:Show()
4 years ago
end
5 months ago
player2String:Show()
player2Dropdown:Show()
5 months ago
statisticsFrame.build_player2_data = {encounterKillsTable, selectedGuildName, role}
player2Dropdown:Refresh()
3 years ago
player_name = statisticsFrame.latest_player_selected or player_name
3 years ago
4 years ago
if (player_name) then
player2Dropdown:Select(player_name)
4 years ago
else
player2Dropdown:Select(1, true)
4 years ago
end
3 years ago
statisticsFrame:BuildPlayerTable (player2Dropdown.value)
4 years ago
end
else
3 years ago
if (player == 1) then --raid
4 years ago
fillpanel:Show()
if (statisticsFrame.gframe) then
statisticsFrame.gframe:Hide()
4 years ago
end
player2String:Hide()
player2Dropdown:Hide()
5 months ago
statisticsFrame:BuildRaidTable({}, selectedGuildName, role)
4 years ago
3 years ago
elseif (player == 2) then --only one player
4 years ago
fillpanel:Hide()
if (statisticsFrame.gframe) then
statisticsFrame.gframe:Show()
4 years ago
end
player2String:Show()
player2Dropdown:Show()
5 months ago
statisticsFrame.build_player2_data = {{}, selectedGuildName, role}
player2Dropdown:Refresh()
player2Dropdown:Select(1, true)
statisticsFrame:BuildPlayerTable (player2Dropdown.value)
4 years ago
end
end
end
end
statisticsFrame.FirstRun = true
4 years ago
end --end of DetailsRaidHistoryWindow creation
local statsWindow = _G.DetailsRaidHistoryWindow
3 years ago
--table means some button send the request - nil for other ways
if (type(raidName) == "table" or (not raidName and not bossEncounterId and not difficultyId and not playerRole and not guildName and not playerBase and not playerName)) then
4 years ago
local f = statsWindow
if (f.LatestSelection) then
raidName = f.LatestSelection.Raid
bossEncounterId = f.LatestSelection.Boss
difficultyId = f.LatestSelection.Diff
playerRole = f.LatestSelection.Role
guildName = f.LatestSelection.Guild
playerBase = f.LatestSelection.PlayerBase
playerName = f.LatestSelection.PlayerBase
4 years ago
end
end
if (statsWindow.FirstRun) then
5 months ago
if (type(Details.rank_window.last_difficulty) == "number") then
Details.rank_window.last_difficulty = "normal"
end
difficultyId = Details.rank_window.last_difficulty or difficultyId
4 years ago
if (IsInGuild()) then
local guildName = GetGuildInfo("player")
if (guildName) then
guildName = guildName
4 years ago
end
end
if (Details.rank_window.last_raid ~= "") then
raidName = Details.rank_window.last_raid or raidName
4 years ago
end
end
if (not statsWindow.UpdateDropdowns) then
Details:Msg("Failled to load statistics, Details! Storage is disabled?")
return
end
statsWindow:UpdateDropdowns()
statsWindow:Refresh()
statsWindow:Show()
if (historyType == 1 or historyType == 2) then
statsWindow.Mode = historyType
4 years ago
if (statsWindow.Mode == 1) then
--overall
3 years ago
statsWindow.HistoryCheckBox:SetValue(true)
statsWindow.GuildRankCheckBox:SetValue(false)
4 years ago
elseif (statsWindow.Mode == 2) then
--guild rank
3 years ago
statsWindow.GuildRankCheckBox:SetValue(true)
statsWindow.HistoryCheckBox:SetValue(false)
4 years ago
end
end
5 months ago
print("raidName", raidName)
print("bossEncounterId", bossEncounterId)
print("difficultyId", difficultyId)
print("playerRole", playerRole)
print("guildName", guildName)
print("playerBase", playerBase)
print("playerName", playerName)
if (raidName) then
statsWindow.select_raid:Select(raidName)
4 years ago
statsWindow:Refresh()
statsWindow.UpdateBossDropdown()
end
if (bossEncounterId) then
statsWindow.select_boss:Select(bossEncounterId)
4 years ago
statsWindow:Refresh()
end
if (difficultyId) then
statsWindow.select_diff:Select(difficultyId)
4 years ago
statsWindow:Refresh()
end
if (playerRole) then
statsWindow.select_role:Select(playerRole)
4 years ago
statsWindow:Refresh()
end
if (guildName) then
if (type(guildName) == "boolean") then
guildName = GetGuildInfo("player")
4 years ago
end
statsWindow.select_guild:Select(guildName)
4 years ago
statsWindow:Refresh()
end
if (playerBase) then
statsWindow.select_player:Select(playerBase)
4 years ago
statsWindow:Refresh()
end
if (playerName) then
4 years ago
statsWindow.select_player2:Refresh()
statsWindow.select_player2:Select(playerName)
5 months ago
statsWindow:Refresh(playerName)
4 years ago
end
DetailsPluginContainerWindow.OpenPlugin(statsWindow)
end