Files
HailMaryGuildTools/Core/DevToolsWindow.lua
Torsten Brendgen fc5a8aa361 initial commit
2026-04-10 21:30:31 +02:00

255 lines
7.6 KiB
Lua

local ADDON_NAME = "HailMaryGuildTools"
local HMGT = _G[ADDON_NAME]
if not HMGT then return end
local L = HMGT.L or LibStub("AceLocale-3.0"):GetLocale(ADDON_NAME)
local AceGUI = LibStub("AceGUI-3.0", true)
if not AceGUI then return end
local function GetOrderedLevels()
return { "error", "trace" }
end
local function GetOrderedScopes()
local values = HMGT:GetDevToolsScopeOptions() or {}
local scopes = { "ALL" }
for scope in pairs(values) do
if scope ~= "ALL" then
scopes[#scopes + 1] = scope
end
end
table.sort(scopes, function(a, b)
if a == "ALL" then return true end
if b == "ALL" then return false end
return tostring(values[a] or a) < tostring(values[b] or b)
end)
return scopes, values
end
local function SetFilterButtonText(buttonWidget, prefix, valueLabel)
if not buttonWidget then
return
end
buttonWidget:SetText(string.format("%s: %s", tostring(prefix or ""), tostring(valueLabel or "")))
end
local function AdvanceLevel(step)
local levels = GetOrderedLevels()
local current = HMGT:GetConfiguredDevToolsLevel()
local nextIndex = 1
for index, value in ipairs(levels) do
if value == current then
nextIndex = index + (step or 1)
break
end
end
if nextIndex < 1 then
nextIndex = #levels
elseif nextIndex > #levels then
nextIndex = 1
end
HMGT:GetDevToolsSettings().level = levels[nextIndex]
HMGT:RefreshDevToolsWindow()
end
local function AdvanceScope(step)
local scopes = GetOrderedScopes()
local current = HMGT:GetDevToolsSettings().scope or "ALL"
local nextIndex = 1
for index, value in ipairs(scopes) do
if value == current then
nextIndex = index + (step or 1)
break
end
end
if nextIndex < 1 then
nextIndex = #scopes
elseif nextIndex > #scopes then
nextIndex = 1
end
HMGT:GetDevToolsSettings().scope = scopes[nextIndex]
HMGT:RefreshDevToolsWindow()
end
function HMGT:EnsureDevToolsWindow()
if self.devToolsWindow then
return self.devToolsWindow
end
local settings = self:GetDevToolsSettings()
local window = self:CreateAceWindow("devTools", {
title = L["DEVTOOLS_WINDOW_TITLE"] or "HMGT Developer Tools",
statusText = L["DEVTOOLS_WINDOW_HINT"] or "Structured developer events for the current session",
statusTable = settings.window,
width = settings.window.width or 920,
height = settings.window.height or 420,
minimizable = true,
minimizedHeight = 64,
})
if not window then
return nil
end
local content = window:GetContent()
local clearButton = AceGUI:Create("Button")
clearButton:SetText(L["OPT_DEVTOOLS_CLEAR"] or "Clear developer log")
clearButton:SetWidth(140)
clearButton:SetCallback("OnClick", function()
HMGT:ClearDevToolsLog()
end)
clearButton.frame:SetParent(content)
clearButton.frame:ClearAllPoints()
clearButton.frame:SetPoint("TOPRIGHT", content, "TOPRIGHT", 0, -2)
clearButton.frame:Show()
window.clearButton = clearButton
window:RegisterMinimizeTarget(clearButton)
local selectButton = AceGUI:Create("Button")
selectButton:SetText(L["OPT_DEVTOOLS_SELECT_ALL"] or "Select all")
selectButton:SetWidth(120)
selectButton:SetCallback("OnClick", function()
if window.editBox then
window.editBox:SetFocus()
window.editBox:HighlightText(0)
end
end)
selectButton.frame:SetParent(content)
selectButton.frame:ClearAllPoints()
selectButton.frame:SetPoint("TOPRIGHT", clearButton.frame, "TOPLEFT", -6, 0)
selectButton.frame:Show()
window.selectButton = selectButton
window:RegisterMinimizeTarget(selectButton)
local levelFilter = AceGUI:Create("Button")
levelFilter:SetWidth(150)
levelFilter:SetCallback("OnClick", function()
AdvanceLevel(1)
end)
levelFilter.frame:SetParent(content)
levelFilter.frame:ClearAllPoints()
levelFilter.frame:SetPoint("TOPLEFT", content, "TOPLEFT", 0, 0)
levelFilter.frame:Show()
window.levelFilter = levelFilter
window:RegisterMinimizeTarget(levelFilter)
local scopeFilter = AceGUI:Create("Button")
scopeFilter:SetWidth(200)
scopeFilter:SetCallback("OnClick", function()
AdvanceScope(1)
end)
scopeFilter.frame:SetParent(content)
scopeFilter.frame:ClearAllPoints()
scopeFilter.frame:SetPoint("TOPLEFT", levelFilter.frame, "TOPRIGHT", 8, 0)
scopeFilter.frame:Show()
window.scopeFilter = scopeFilter
window:RegisterMinimizeTarget(scopeFilter)
local logWidget = AceGUI:Create("MultiLineEditBox")
logWidget:SetLabel("")
logWidget:DisableButton(true)
logWidget:SetNumLines(20)
logWidget:SetText("")
logWidget.frame:SetParent(content)
logWidget.frame:ClearAllPoints()
logWidget.frame:SetPoint("TOPLEFT", content, "TOPLEFT", 0, -54)
logWidget.frame:SetPoint("BOTTOMRIGHT", content, "BOTTOMRIGHT", 0, 0)
logWidget.frame:Show()
logWidget.editBox:SetScript("OnKeyDown", function(selfBox, key)
if IsControlKeyDown() and (key == "A" or key == "a") then
selfBox:HighlightText(0)
end
end)
window.logWidget = logWidget
window.editBox = logWidget.editBox
window:RegisterMinimizeTarget(logWidget)
self.devToolsWindow = window
window:SetMinimized(settings.window.minimized)
return window
end
function HMGT:RefreshDevToolsWindow()
local window = self:EnsureDevToolsWindow()
if not window or not window.editBox or not window.logWidget then
return
end
local levelOptions = self:GetDevToolsLevelOptions()
SetFilterButtonText(window.levelFilter, L["OPT_DEVTOOLS_LEVEL"] or "Capture level", levelOptions[self:GetConfiguredDevToolsLevel()])
local scopeValues = self:GetDevToolsScopeOptions()
local currentScope = self:GetDevToolsSettings().scope or "ALL"
SetFilterButtonText(window.scopeFilter, L["OPT_DEVTOOLS_SCOPE"] or "Scope", scopeValues[currentScope] or currentScope)
local text = table.concat(self:GetFilteredDevToolsLines(), "\n")
window.logWidget:SetText(text)
window.editBox:SetCursorPosition(window.editBox:GetNumLetters())
end
function HMGT:OpenDevToolsWindow()
if not self:IsDevToolsEnabled() then
self:Print(L["OPT_DEVTOOLS_DISABLED"] or "HMGT: developer tools are not enabled.")
return
end
local window = self:EnsureDevToolsWindow()
if not window then
return
end
window:Show()
window:Raise()
self:RefreshDevToolsWindow()
end
function HMGT:ToggleDevToolsWindow()
if not self:IsDevToolsEnabled() then
self:Print(L["OPT_DEVTOOLS_DISABLED"] or "HMGT: developer tools are not enabled.")
return
end
local window = self:EnsureDevToolsWindow()
if not window then
return
end
if window:IsShown() then
window:Hide()
return
end
window:Show()
window:Raise()
self:RefreshDevToolsWindow()
end
function HMGT:UpdateDevToolsWindowVisibility()
local window = self.devToolsWindow
if not window then
return
end
if not self:IsDevToolsEnabled() then
window:Hide()
return
end
if window:IsShown() then
self:RefreshDevToolsWindow()
end
end
function HMGT:RefreshDebugWindow()
self:RefreshDevToolsWindow()
end
function HMGT:UpdateDebugWindowVisibility()
self:UpdateDevToolsWindowVisibility()
end
function HMGT:ClearDebugLog()
self:ClearDevToolsLog()
end
function HMGT:ToggleDebugWindowShortcut()
self:ToggleDevToolsWindow()
end
function HMGT:DumpDebugLog(maxLines)
self:DumpDevToolsLog(maxLines)
end