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
+53 -71
View File
@@ -2,47 +2,55 @@
-- Interface: 16001 -- Interface: 16001
local addon = CreateFrame("Frame") local addon = CreateFrame("Frame")
local button -- set in CreateExpandButton
-------------------------------------------------- --------------------------------------------------
-- Helpers -- Helpers
-------------------------------------------------- --------------------------------------------------
local function AreAllHeadersExpanded() local function AreAllHeadersExpanded()
for i = 1, C_QuestLog.GetNumQuestLogEntries() do
local numEntries = C_QuestLog.GetNumQuestLogEntries()
--------------------------------------------------
-- Resize search box to fit button
--------------------------------------------------
local function ResizeSearchBox()
local sb = QuestScrollFrame and QuestScrollFrame.SearchBox
if sb then
sb:SetWidth(150)
end
end
if QuestScrollFrame and QuestScrollFrame.SearchBox then
QuestScrollFrame.SearchBox:HookScript("OnShow", ResizeSearchBox)
end
ResizeSearchBox()
for i = 1, numEntries do
local info = C_QuestLog.GetInfo(i) local info = C_QuestLog.GetInfo(i)
if info and info.isHeader and info.isCollapsed then if info and info.isHeader and info.isCollapsed then
return false return false
end end
end end
return true return true
end end
local function UpdateButton(button) local function UpdateButton()
if AreAllHeadersExpanded() then if not button then return end
button:SetText("- All")
else local text = AreAllHeadersExpanded() and "- All" or "+ All"
button:SetText("+ All") if button:GetText() ~= text then
button:SetText(text)
end
end
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
local function UpdateButton()
if not button then return end
ResizeSearchBox()
local text = AreAllHeadersExpanded() and "- All" or "+ All"
if button:GetText() ~= text then
button:SetText(text)
end end
end end
@@ -51,57 +59,38 @@ for i = 1, numEntries do
-------------------------------------------------- --------------------------------------------------
local function CreateExpandButton() local function CreateExpandButton()
if button then return end
if QuestExpandAllButton then local parent = QuestMapFrame and QuestMapFrame.QuestsFrame
return if not parent then return end
end
-- Wait until the Quest Map exists
if not QuestMapFrame or not QuestMapFrame.QuestsFrame then
return
end
local parent = QuestMapFrame.QuestsFrame
local button = CreateFrame(
"Button",
"QuestExpandAllButton",
parent,
"UIPanelButtonTemplate"
)
button = CreateFrame("Button", "QuestExpandAllButton", parent, "UIPanelButtonTemplate")
button:SetSize(50, 20) button:SetSize(50, 20)
button:SetPoint("RIGHT", QuestLogQuestCount, "RIGHT", 54, 0)
button:SetScript("OnClick", function(self)
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 if AreAllHeadersExpanded() then
CollapseQuestHeader(0) CollapseQuestHeader(0)
else else
ExpandQuestHeader(0) ExpandQuestHeader(0)
end end
C_Timer.After(0, function()
UpdateButton(self)
end)
end) end)
button:SetScript("OnEnter", function(self) button:SetScript("OnEnter", function(self)
GameTooltip:SetOwner(self, "ANCHOR_RIGHT") GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
GameTooltip:AddLine("Quest Headers") GameTooltip:SetText("Quest Headers")
GameTooltip:AddLine(" ") GameTooltip:AddLine("Left click to toggle all zone headers.", 1, 1, 1, true)
GameTooltip:AddLine("Left Click to toggle all zone headers.",1,1,1,true)
GameTooltip:Show() GameTooltip:Show()
end) end)
button:SetScript("OnLeave", function() button:SetScript("OnLeave", GameTooltip_Hide)
GameTooltip:Hide()
end)
UpdateButton(button)
UpdateButton()
end end
-------------------------------------------------- --------------------------------------------------
@@ -112,17 +101,10 @@ for i = 1, numEntries do
addon:RegisterEvent("QUEST_LOG_UPDATE") addon:RegisterEvent("QUEST_LOG_UPDATE")
addon:SetScript("OnEvent", function(self, event) addon:SetScript("OnEvent", function(self, event)
if event == "PLAYER_LOGIN" then if event == "PLAYER_LOGIN" then
self:UnregisterEvent("PLAYER_LOGIN")
CreateExpandButton() CreateExpandButton()
else
elseif event == "QUEST_LOG_UPDATE" then UpdateButton()
if QuestExpandAllButton then
UpdateButton(QuestExpandAllButton)
end end
end
end) end)
+1 -1
View File
@@ -2,6 +2,6 @@
## Title: Quest Expand All ## Title: Quest Expand All
## Notes: Adds an Expand All button to the quest log. ## Notes: Adds an Expand All button to the quest log.
## Author: Drink_Bepis ## Author: Drink_Bepis
## Version: 0.1 ## Version: 0.2
QuestExpandAll.lua QuestExpandAll.lua