View Single Post
04-25-24, 11:50 AM   #4
Sharpedge
A Theradrim Guardian
 
Sharpedge's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2022
Posts: 68
Welp, it is kinda working lol. I did use the GetPersonalRatedInfo. See the code below:

Code:
local CONQUEST_CURRENCY_ID = 1602
local HONOR_CURRENCY_ID = 1792

-- Main GUI Frame
local IncCallout = CreateFrame("Frame", "IncCalloutMainFrame", UIParent, "BackdropTemplate")
IncCallout:SetSize(225, 240)  
IncCallout:SetPoint("CENTER")
IncCallout:SetMovable(true)
IncCallout:EnableMouse(true)
IncCallout:RegisterForDrag("LeftButton")
IncCallout:SetScript("OnDragStart", IncCallout.StartMoving)
IncCallout:SetScript("OnDragStop", IncCallout.StopMovingOrSizing)

local closeButton = CreateFrame("Button", nil, IncCallout, "UIPanelCloseButton")
closeButton:SetPoint("TOPRIGHT", IncCallout, "TOPRIGHT", -5, -5)
closeButton:SetSize(24, 24)  
closeButton:SetScript("OnClick", function()
    IncCallout:Hide()  
end)

closeButton:SetScript("OnEnter", function(self)
    GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
    GameTooltip:SetText("Close the Window", nil, nil, nil, nil, true)
    GameTooltip:Show()
end)
closeButton:SetScript("OnLeave", function()
    GameTooltip:Hide()
end)

-- Create the PVP Stats window frame
local pvpStatsFrame = CreateFrame("Frame", "PVPStatsFrame", UIParent, "BasicFrameTemplateWithInset")
pvpStatsFrame:SetSize(220, 200)
pvpStatsFrame:SetPoint("CENTER")
pvpStatsFrame:SetMovable(true)
pvpStatsFrame:EnableMouse(true)
pvpStatsFrame:RegisterForDrag("LeftButton")
pvpStatsFrame:SetScript("OnDragStart", pvpStatsFrame.StartMoving)
pvpStatsFrame:SetScript("OnDragStop", pvpStatsFrame.StopMovingOrSizing)
pvpStatsFrame:Hide()

pvpStatsFrame.title = pvpStatsFrame:CreateFontString(nil, "OVERLAY")
pvpStatsFrame.title:SetFontObject("GameFontHighlight")
pvpStatsFrame.title:SetPoint("TOP", pvpStatsFrame, "TOP", 0, -7)
pvpStatsFrame.title:SetText("PVP Stats")

local LEFT_MARGIN = -70
local VERTICAL_GAP = -15

local function createStatLabelAndValue(parent, labelText, previousElement, yOffset, textColor)
    local label = parent:CreateFontString(nil, "OVERLAY", "GameFontNormal")
    label:SetPoint("TOPLEFT", previousElement, "BOTTOMLEFT", previousElement == parent.title and LEFT_MARGIN or 0, yOffset)
    label:SetText(labelText)
    label:SetTextColor(unpack(textColor))
    
    local value = parent:CreateFontString(nil, "OVERLAY", "GameFontNormal")
    value:SetPoint("LEFT", label, "RIGHT", 5, 0)
    value:SetTextColor(1, 0.84, 0)
    return label, value
end

-- Creating labels and values with custom colors for each category
pvpStatsFrame.honorableKillsLabel, pvpStatsFrame.honorableKillsValue = createStatLabelAndValue(pvpStatsFrame, "Lifetime Honorable Kills:", pvpStatsFrame.title, VERTICAL_GAP, {0, 1, 0})  -- Green
pvpStatsFrame.conquestLabel, pvpStatsFrame.conquestValue = createStatLabelAndValue(pvpStatsFrame, "Conquest Points:", pvpStatsFrame.honorableKillsLabel, VERTICAL_GAP, {0, 0.75, 1})  -- Light blue
pvpStatsFrame.honorLabel, pvpStatsFrame.honorValue = createStatLabelAndValue(pvpStatsFrame, "Honor Points:", pvpStatsFrame.conquestLabel, VERTICAL_GAP, {1, 0.5, 0})  -- Orange
pvpStatsFrame.honorLevelLabel, pvpStatsFrame.honorLevelValue = createStatLabelAndValue(pvpStatsFrame, "Honor Level:", pvpStatsFrame.honorLabel, VERTICAL_GAP, {0.58, 0, 0.82})  -- Purple
pvpStatsFrame.conquestCapLabel, pvpStatsFrame.conquestCapValue = createStatLabelAndValue(pvpStatsFrame, "Conquest Cap:", pvpStatsFrame.honorLevelLabel, VERTICAL_GAP, {1, 0, 0})  -- Red
pvpStatsFrame.soloShuffleRatingLabel, pvpStatsFrame.soloShuffleRatingValue = createStatLabelAndValue(pvpStatsFrame, "Solo Shuffle Rating:", pvpStatsFrame.conquestCapLabel, VERTICAL_GAP, {1, 0.84, 0})  -- Gold color for value)

local SOLO_SHUFFLE_INDEX = 7  

local lastPlayerName = nil  

local function RefreshPvPStats()
    local conquestInfo = C_CurrencyInfo.GetCurrencyInfo(Constants.CurrencyConsts.CONQUEST_CURRENCY_ID)
    local weeklyProgress = C_WeeklyRewards.GetConquestWeeklyProgress()
    local honorInfo = C_CurrencyInfo.GetCurrencyInfo(HONOR_CURRENCY_ID)
    local lifetimeHonorableKills, _ = GetPVPLifetimeStats()
    local honorLevel = UnitHonorLevel("player")
    local currentConquestPoints = conquestInfo.quantity
    local conquestCap = weeklyProgress.maxProgress or 1350

    if conquestCap == 1250 then
        conquestCap = 1350
    end

    local rating = GetPersonalRatedInfo(SOLO_SHUFFLE_INDEX)
    local soloShuffleRating = rating or "N/A"

    pvpStatsFrame.honorableKillsValue:SetText(lifetimeHonorableKills)
    pvpStatsFrame.conquestValue:SetText(currentConquestPoints)
    pvpStatsFrame.conquestCapValue:SetText(currentConquestPoints .. " / " .. conquestCap)
    pvpStatsFrame.honorValue:SetText(honorInfo.quantity)
    pvpStatsFrame.honorLevelValue:SetText(honorLevel)
    pvpStatsFrame.soloShuffleRatingValue:SetText(soloShuffleRating)
end

pvpStatsFrame:RegisterEvent("PVP_RATED_STATS_UPDATE")
pvpStatsFrame:SetScript("OnEvent", function(self, event)
    if event == "PVP_RATED_STATS_UPDATE" then
        RefreshPvPStats()
    end
end)

pvpStatsFrame:RegisterEvent("PLAYER_LOGIN")
pvpStatsFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
pvpStatsFrame:RegisterEvent("CURRENCY_DISPLAY_UPDATE")
pvpStatsFrame:RegisterEvent("WEEKLY_REWARDS_UPDATE")
pvpStatsFrame:SetScript("OnEvent", UpdatePvPStatsFrame)
pvpStatsFrame:SetScript("OnShow", RefreshPvPStats)  ]
So here is where I think I messed up or left out something. I can log in, click on the PVP Stat button on my GUI and it shows the Solo Shuffle Rating as 0. So then I go to Group Finder/Player vs Player, and leave that open. I then open the PVP Stat window again and it shows the correct rating. If I log out, and then into another toon it's the same senario.

I have just shown this part of my code. If needed I can post the entire thing. The changes are not on my Github. And it's like 1500 lines.I just think I'm missing something for it to have this type of behaviour.
  Reply With Quote