177 lines
5.4 KiB
Lua
177 lines
5.4 KiB
Lua
local ADDON_NAME = "HailMaryGuildTools"
|
|
local HMGT = _G[ADDON_NAME]
|
|
if not HMGT then return end
|
|
|
|
local AceGUI = LibStub("AceGUI-3.0", true)
|
|
if not AceGUI then return end
|
|
|
|
local WindowPrototype = {}
|
|
|
|
local function ResolveFrame(target)
|
|
if not target then
|
|
return nil
|
|
end
|
|
if type(target) == "table" and target.frame then
|
|
return target.frame
|
|
end
|
|
return target
|
|
end
|
|
|
|
function WindowPrototype:GetContent()
|
|
return self.content
|
|
end
|
|
|
|
function WindowPrototype:SetTitle(text)
|
|
if self.widget and self.widget.SetTitle then
|
|
self.widget:SetTitle(tostring(text or ""))
|
|
end
|
|
end
|
|
|
|
function WindowPrototype:SetStatusText(text)
|
|
if self.widget and self.widget.SetStatusText then
|
|
self.widget:SetStatusText(tostring(text or ""))
|
|
end
|
|
end
|
|
|
|
function WindowPrototype:Show()
|
|
if self.widget and self.widget.Show then
|
|
self.widget:Show()
|
|
elseif self.frame then
|
|
self.frame:Show()
|
|
end
|
|
end
|
|
|
|
function WindowPrototype:Hide()
|
|
if self.widget and self.widget.Hide then
|
|
self.widget:Hide()
|
|
elseif self.frame then
|
|
self.frame:Hide()
|
|
end
|
|
end
|
|
|
|
function WindowPrototype:Raise()
|
|
if self.frame and self.frame.Raise then
|
|
self.frame:Raise()
|
|
end
|
|
end
|
|
|
|
function WindowPrototype:IsShown()
|
|
return self.frame and self.frame:IsShown() or false
|
|
end
|
|
|
|
function WindowPrototype:RegisterMinimizeTarget(target)
|
|
self.minimizeTargets = self.minimizeTargets or {}
|
|
self.minimizeTargets[#self.minimizeTargets + 1] = target
|
|
end
|
|
|
|
function WindowPrototype:SetMinimized(minimized)
|
|
minimized = minimized and true or false
|
|
if not self.minimizable then
|
|
minimized = false
|
|
end
|
|
|
|
self.statusTable = self.statusTable or {}
|
|
self.statusTable.minimized = minimized
|
|
if minimized then
|
|
self.statusTable.restoreHeight = self.statusTable.height or (self.frame and self.frame:GetHeight()) or self.height or 360
|
|
end
|
|
|
|
local targetHeight = minimized
|
|
and (self.minimizedHeight or 64)
|
|
or (self.statusTable.restoreHeight or self.statusTable.height or self.height or 360)
|
|
|
|
if self.widget and self.widget.EnableResize then
|
|
self.widget:EnableResize(not minimized)
|
|
self.widget:SetHeight(targetHeight)
|
|
elseif self.frame then
|
|
self.frame:SetHeight(targetHeight)
|
|
end
|
|
|
|
if self.minimizeButton and self.minimizeButton.SetText then
|
|
self.minimizeButton:SetText(minimized and "+" or "-")
|
|
end
|
|
|
|
for _, target in ipairs(self.minimizeTargets or {}) do
|
|
local frame = ResolveFrame(target)
|
|
if frame and frame.SetShown then
|
|
frame:SetShown(not minimized)
|
|
end
|
|
end
|
|
end
|
|
|
|
function WindowPrototype:ToggleMinimized()
|
|
self:SetMinimized(not (self.statusTable and self.statusTable.minimized))
|
|
end
|
|
|
|
function HMGT:CreateAceWindow(key, options)
|
|
self._aceWindows = self._aceWindows or {}
|
|
if self._aceWindows[key] then
|
|
return self._aceWindows[key]
|
|
end
|
|
|
|
if not AceGUI then
|
|
return nil
|
|
end
|
|
|
|
options = options or {}
|
|
local statusTable = options.statusTable or {}
|
|
local widget = AceGUI:Create("Frame")
|
|
widget:SetTitle(tostring(options.title or ""))
|
|
widget:SetStatusText(tostring(options.statusText or ""))
|
|
widget:SetStatusTable(statusTable)
|
|
widget:SetWidth(tonumber(options.width) or 800)
|
|
widget:SetHeight(tonumber(options.height) or 360)
|
|
widget:EnableResize(options.resizable ~= false)
|
|
widget.frame:SetClampedToScreen(true)
|
|
widget.frame:SetToplevel(true)
|
|
widget.frame:SetFrameStrata(options.strata or "FULLSCREEN_DIALOG")
|
|
widget:Hide()
|
|
widget:SetCallback("OnClose", function()
|
|
widget:Hide()
|
|
end)
|
|
|
|
local window = setmetatable({
|
|
key = key,
|
|
widget = widget,
|
|
frame = widget.frame,
|
|
content = widget.content,
|
|
statusTable = statusTable,
|
|
width = tonumber(options.width) or 800,
|
|
height = tonumber(options.height) or 360,
|
|
minimizable = options.minimizable == true,
|
|
minimizedHeight = tonumber(options.minimizedHeight) or 64,
|
|
minimizeTargets = {},
|
|
}, { __index = WindowPrototype })
|
|
|
|
if options.backgroundTexture then
|
|
local texture = window.content:CreateTexture(nil, "BACKGROUND")
|
|
texture:SetPoint("CENTER", window.content, "CENTER", tonumber(options.backgroundOffsetX) or 0, tonumber(options.backgroundOffsetY) or 0)
|
|
texture:SetSize(tonumber(options.backgroundWidth) or 220, tonumber(options.backgroundHeight) or 120)
|
|
texture:SetTexture(tostring(options.backgroundTexture))
|
|
texture:SetAlpha(tonumber(options.backgroundAlpha) or 0.12)
|
|
window.backgroundTexture = texture
|
|
end
|
|
|
|
if window.minimizable then
|
|
local minimizeButton = AceGUI:Create("Button")
|
|
minimizeButton:SetText((statusTable and statusTable.minimized) and "+" or "-")
|
|
minimizeButton:SetWidth(24)
|
|
minimizeButton:SetCallback("OnClick", function()
|
|
window:ToggleMinimized()
|
|
end)
|
|
minimizeButton.frame:SetParent(window.frame)
|
|
minimizeButton.frame:ClearAllPoints()
|
|
minimizeButton.frame:SetPoint("TOPRIGHT", window.frame, "TOPRIGHT", -34, -4)
|
|
minimizeButton.frame:SetHeight(20)
|
|
minimizeButton.frame:Show()
|
|
window.minimizeButton = minimizeButton
|
|
end
|
|
|
|
self._aceWindows[key] = window
|
|
if options.onCreate then
|
|
options.onCreate(window, window.content, widget)
|
|
end
|
|
window:SetMinimized(statusTable and statusTable.minimized)
|
|
return window
|
|
end
|