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 -- 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 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
-------------------------------------------------- local text = AreAllHeadersExpanded() and "- All" or "+ All"
-- Resize search box to fit button if button:GetText() ~= text then
-------------------------------------------------- button:SetText(text)
local function ResizeSearchBox()
local sb = QuestScrollFrame and QuestScrollFrame.SearchBox
if sb then
sb:SetWidth(150)
end end
end end
if QuestScrollFrame and QuestScrollFrame.SearchBox then local searchBoxHooked = false
QuestScrollFrame.SearchBox:HookScript("OnShow", ResizeSearchBox)
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 end
ResizeSearchBox()
for i = 1, numEntries do local function UpdateButton()
local info = C_QuestLog.GetInfo(i) if not button then return end
if info and info.isHeader and info.isCollapsed then ResizeSearchBox()
return false
end
end
return true local text = AreAllHeadersExpanded() and "- All" or "+ All"
end 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 if AreAllHeadersExpanded() then
button:SetText("- All") CollapseQuestHeader(0)
else else
button:SetText("+ All") ExpandQuestHeader(0)
end end
end end)
-------------------------------------------------- button:SetScript("OnEnter", function(self)
-- Create Button 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 UpdateButton()
return end
end
-- Wait until the Quest Map exists --------------------------------------------------
if not QuestMapFrame or not QuestMapFrame.QuestsFrame then -- Events
return --------------------------------------------------
end
local parent = QuestMapFrame.QuestsFrame addon:RegisterEvent("PLAYER_LOGIN")
addon:RegisterEvent("QUEST_LOG_UPDATE")
local button = CreateFrame( addon:SetScript("OnEvent", function(self, event)
"Button", if event == "PLAYER_LOGIN" then
"QuestExpandAllButton", self:UnregisterEvent("PLAYER_LOGIN")
parent, CreateExpandButton()
"UIPanelButtonTemplate" else
) UpdateButton()
end
button:SetSize(50,20) end)
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)
+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