Skip to content

Commit

Permalink
Fix keystone announce.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kkthnx committed Nov 24, 2024
1 parent 8c05ac3 commit 5640824
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 47 deletions.
87 changes: 42 additions & 45 deletions KkthnxUI/Modules/Announcements/Elements/Keystone.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ local IsPartyLFG = IsPartyLFG
local COOLDOWN_DURATION = 30
local lastKeystoneMessageTime = 0
local lastKeystoneLinkTime = 0
local keystoneCache = {}

-- Helper function to get keystone link
local function getKeystoneLink()
Expand All @@ -40,83 +41,79 @@ local function sendKeystoneLink(channel)
end

-- Main function to handle keystone announcements
function Module:Keystone(event)
local currentTime = GetTime()
if currentTime - lastKeystoneMessageTime < COOLDOWN_DURATION then
return
end
lastKeystoneMessageTime = currentTime

function Module.Keystone(event)
local mapID = C_MythicPlus_GetOwnedKeystoneChallengeMapID()
local keystoneLevel = C_MythicPlus_GetOwnedKeystoneLevel()

if Module.keystoneCache.mapID ~= mapID or Module.keystoneCache.keystoneLevel ~= keystoneLevel then
Module.keystoneCache.mapID = mapID
Module.keystoneCache.keystoneLevel = keystoneLevel
if event == "PLAYER_ENTERING_WORLD" then
keystoneCache.mapID = mapID
keystoneCache.keystoneLevel = keystoneLevel
elseif event == "CHALLENGE_MODE_COMPLETED" or event == "ITEM_CHANGED" then
if keystoneCache.mapID ~= mapID or keystoneCache.keystoneLevel ~= keystoneLevel then
keystoneCache.mapID = mapID
keystoneCache.keystoneLevel = keystoneLevel

local link = getKeystoneLink()
if link then
local message = string.gsub("My new keystone is %keystone%.", "%%keystone%%", link)
K.Delay(1, function()
if IsPartyLFG() then
SendChatMessage(message, "INSTANCE_CHAT")
elseif IsInGroup() then
SendChatMessage(message, "PARTY")
end
end)
local link = getKeystoneLink()
if link then
local message = string.gsub("My new keystone is %keystone%.", "%%keystone%%", link)
K.Delay(1, function()
if IsPartyLFG() then
SendChatMessage(message, "INSTANCE_CHAT")
elseif IsInGroup() then
SendChatMessage(message, "PARTY")
end
end)
end
end
end
end

-- Function to handle keystone link requests
function Module:KeystoneLink(message, sender)
function Module:KeystoneLink(channelType, _, text, sender)
local currentTime = GetTime()
if currentTime - lastKeystoneMessageTime < 1 then
return
end

if currentTime - lastKeystoneLinkTime < COOLDOWN_DURATION then
return
end
lastKeystoneLinkTime = currentTime

if strlower(sender) == "!keys" then
local channel
if message == "CHAT_MSG_PARTY" or message == "CHAT_MSG_PARTY_LEADER" then
channel = "PARTY"
elseif message == "CHAT_MSG_GUILD" then
channel = "GUILD"
elseif message == "CHAT_MSG_OFFICER" then
channel = "OFFICER"
end

if channel then
if strlower(text or "") == "!keys" then
if channelType then
lastKeystoneLinkTime = currentTime
lastKeystoneMessageTime = GetTime()
K.Delay(1, function()
sendKeystoneLink(channel)
sendKeystoneLink(channelType)
end)
end
end
end

-- Function to set up the keystone announcement system
function Module:CreateKeystoneAnnounce()
-- Check if MythicKeyReporter is loaded or if KeystoneAlert is disabled
if C_AddOns.IsAddOnLoaded("MythicKeyReporter") or not C["Announcements"].KeystoneAlert then
-- Unregister events if the feature is disabled
K:UnregisterEvent("CHAT_MSG_PARTY", Module.KeystoneLink)
K:UnregisterEvent("CHAT_MSG_PARTY_LEADER", Module.KeystoneLink)
K:UnregisterEvent("CHAT_MSG_GUILD", Module.KeystoneLink)
K:UnregisterEvent("CHAT_MSG_OFFICER", Module.KeystoneLink)

K:UnregisterEvent("ITEM_CHANGED", Module.Keystone)
K:UnregisterEvent("PLAYER_ENTERING_WORLD", Module.Keystone)
K:UnregisterEvent("CHALLENGE_MODE_COMPLETED", Module.Keystone)
return
end

-- Initialize keystone cache
Module.keystoneCache = Module.keystoneCache or {}
K:RegisterEvent("CHAT_MSG_PARTY", function(...)
Module:KeystoneLink("PARTY", ...)
end)

K:RegisterEvent("CHAT_MSG_PARTY_LEADER", function(...)
Module:KeystoneLink("PARTY", ...)
end)

K:RegisterEvent("CHAT_MSG_GUILD", function(...)
Module:KeystoneLink("GUILD", ...)
end)

-- Register events if the feature is enabled
K:RegisterEvent("CHAT_MSG_PARTY", Module.KeystoneLink)
K:RegisterEvent("CHAT_MSG_PARTY_LEADER", Module.KeystoneLink)
K:RegisterEvent("CHAT_MSG_GUILD", Module.KeystoneLink)
K:RegisterEvent("CHAT_MSG_OFFICER", Module.KeystoneLink)
K:RegisterEvent("ITEM_CHANGED", Module.Keystone)
K:RegisterEvent("PLAYER_ENTERING_WORLD", Module.Keystone)
K:RegisterEvent("CHALLENGE_MODE_COMPLETED", Module.Keystone)
Expand Down
14 changes: 12 additions & 2 deletions KkthnxUI/Modules/Miscellaneous/Elements/MissingStats.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@ function Module:CreateMissingStats()
local statPanel = CreateFrame("Frame", nil, CharacterFrameInsetRight)
statPanel:SetSize(200, 350)
statPanel:SetPoint("TOP", 0, -5)

local scrollFrame = CreateFrame("ScrollFrame", nil, statPanel, "UIPanelScrollFrameTemplate")
scrollFrame:SetAllPoints()
scrollFrame.ScrollBar:Hide()
scrollFrame.ScrollBar.Show = K.Noop

local stat = CreateFrame("Frame", nil, scrollFrame)
stat:SetSize(200, 1)
scrollFrame:SetScrollChild(stat)
Expand Down Expand Up @@ -134,5 +132,17 @@ function Module:CreateMissingStats()
statFrame.Value:SetFormattedText("%.2f%%", statFrame.numericValue)
end
end)

hooksecurefunc("PaperDollFrame_UpdateStats", function()
for statFrame in CharacterStatsPane.statsFramePool:EnumerateActive() do
if not statFrame.styled then
statFrame.Label:SetFontObject(Game11Font)
statFrame.Value:SetFontObject(Game11Font)

statFrame.styled = true
end
end
end)
end

Module:RegisterMisc("MissingStats", Module.CreateMissingStats)

0 comments on commit 5640824

Please sign in to comment.