Code cleanup and reducing CPU usage

This commit is contained in:
bepis
2026-09-30 22:38:45 +10:00
parent 0873aabd6c
commit d47536007d
2 changed files with 84 additions and 102 deletions
+83 -101
View File
@@ -2,127 +2,109 @@
-- Interface: 16001
local addon = CreateFrame("Frame")
local button -- set in CreateExpandButton
--------------------------------------------------
-- Helpers
--------------------------------------------------
local function AreAllHeadersExpanded()
for i = 1, C_QuestLog.GetNumQuestLogEntries() do
local info = C_QuestLog.GetInfo(i)
if info and info.isHeader and info.isCollapsed then
return false
end
end
return true
end
local numEntries = C_QuestLog.GetNumQuestLogEntries()
local function UpdateButton()
if not button then return end
--------------------------------------------------
-- Resize search box to fit button
--------------------------------------------------
local function ResizeSearchBox()
local sb = QuestScrollFrame and QuestScrollFrame.SearchBox
if sb then
sb:SetWidth(150)
local text = AreAllHeadersExpanded() and "- All" or "+ All"
if button:GetText() ~= text then
button:SetText(text)
end
end
if QuestScrollFrame and QuestScrollFrame.SearchBox then
QuestScrollFrame.SearchBox:HookScript("OnShow", ResizeSearchBox)
local searchBoxHooked = false
local function ResizeSearchBox()
local sb = QuestScrollFrame and QuestScrollFrame.SearchBox
if not sb then return end
if sb:GetWidth() ~= 150 then
sb:SetWidth(150)
end
if not searchBoxHooked then
searchBoxHooked = true
sb:HookScript("OnShow", ResizeSearchBox)
end
end
ResizeSearchBox()
for i = 1, numEntries do
local info = C_QuestLog.GetInfo(i)
local function UpdateButton()
if not button then return end
if info and info.isHeader and info.isCollapsed then
return false
end
end
ResizeSearchBox()
return true
end
local text = AreAllHeadersExpanded() and "- All" or "+ All"
if button:GetText() ~= text then
button:SetText(text)
end
end
local function UpdateButton(button)
--------------------------------------------------
-- Create Button
--------------------------------------------------
local function CreateExpandButton()
if button then return end
local parent = QuestMapFrame and QuestMapFrame.QuestsFrame
if not parent then return end
button = CreateFrame("Button", "QuestExpandAllButton", parent, "UIPanelButtonTemplate")
button:SetSize(50, 20)
if QuestLogQuestCount then
button:SetPoint("RIGHT", QuestLogQuestCount, "RIGHT", 54, 0)
else
button:SetPoint("TOPRIGHT", parent, "TOPRIGHT", -10, 24)
end
button:SetScript("OnClick", function()
if AreAllHeadersExpanded() then
button:SetText("- All")
else
button:SetText("+ All")
end
end
CollapseQuestHeader(0)
else
ExpandQuestHeader(0)
end
end)
--------------------------------------------------
-- Create Button
--------------------------------------------------
button:SetScript("OnEnter", function(self)
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
GameTooltip:SetText("Quest Headers")
GameTooltip:AddLine("Left click to toggle all zone headers.", 1, 1, 1, true)
GameTooltip:Show()
end)
local function CreateExpandButton()
button:SetScript("OnLeave", GameTooltip_Hide)
if QuestExpandAllButton then
return
end
UpdateButton()
end
-- Wait until the Quest Map exists
if not QuestMapFrame or not QuestMapFrame.QuestsFrame then
return
end
--------------------------------------------------
-- Events
--------------------------------------------------
local parent = QuestMapFrame.QuestsFrame
addon:RegisterEvent("PLAYER_LOGIN")
addon:RegisterEvent("QUEST_LOG_UPDATE")
local button = CreateFrame(
"Button",
"QuestExpandAllButton",
parent,
"UIPanelButtonTemplate"
)
button:SetSize(50,20)
button:SetPoint("RIGHT", QuestLogQuestCount, "RIGHT", 54, 0)
button:SetScript("OnClick", function(self)
if AreAllHeadersExpanded() then
CollapseQuestHeader(0)
else
ExpandQuestHeader(0)
end
C_Timer.After(0, function()
UpdateButton(self)
end)
end)
button:SetScript("OnEnter", function(self)
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
GameTooltip:AddLine("Quest Headers")
GameTooltip:AddLine(" ")
GameTooltip:AddLine("Left Click to toggle all zone headers.",1,1,1,true)
GameTooltip:Show()
end)
button:SetScript("OnLeave", function()
GameTooltip:Hide()
end)
UpdateButton(button)
end
--------------------------------------------------
-- Events
--------------------------------------------------
addon:RegisterEvent("PLAYER_LOGIN")
addon:RegisterEvent("QUEST_LOG_UPDATE")
addon:SetScript("OnEvent", function(self, event)
if event == "PLAYER_LOGIN" then
CreateExpandButton()
elseif event == "QUEST_LOG_UPDATE" then
if QuestExpandAllButton then
UpdateButton(QuestExpandAllButton)
end
end
end)
addon:SetScript("OnEvent", function(self, event)
if event == "PLAYER_LOGIN" then
self:UnregisterEvent("PLAYER_LOGIN")
CreateExpandButton()
else
UpdateButton()
end
end)
+1 -1
View File
@@ -2,6 +2,6 @@
## Title: Quest Expand All
## Notes: Adds an Expand All button to the quest log.
## Author: Drink_Bepis
## Version: 0.1
## Version: 0.2
QuestExpandAll.lua