Xiiph@0: --[[----------------------------------------------------------------------------- Xiiph@0: Frame Container Xiiph@0: -------------------------------------------------------------------------------]] Xiiph@0: local Type, Version = "Frame", 22 Xiiph@0: local AceGUI = LibStub and LibStub("AceGUI-3.0", true) Xiiph@0: if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end Xiiph@0: Xiiph@0: -- Lua APIs Xiiph@0: local pairs, assert, type = pairs, assert, type Xiiph@0: local wipe = table.wipe Xiiph@0: Xiiph@0: -- WoW APIs Xiiph@0: local PlaySound = PlaySound Xiiph@0: local CreateFrame, UIParent = CreateFrame, UIParent Xiiph@0: Xiiph@0: -- Global vars/functions that we don't upvalue since they might get hooked, or upgraded Xiiph@0: -- List them here for Mikk's FindGlobals script Xiiph@0: -- GLOBALS: CLOSE Xiiph@0: Xiiph@0: --[[----------------------------------------------------------------------------- Xiiph@0: Scripts Xiiph@0: -------------------------------------------------------------------------------]] Xiiph@0: local function Button_OnClick(frame) Xiiph@0: PlaySound("gsTitleOptionExit") Xiiph@0: frame.obj:Hide() Xiiph@0: end Xiiph@0: Xiiph@0: local function Frame_OnClose(frame) Xiiph@0: frame.obj:Fire("OnClose") Xiiph@0: end Xiiph@0: Xiiph@0: local function Frame_OnMouseDown(frame) Xiiph@0: AceGUI:ClearFocus() Xiiph@0: end Xiiph@0: Xiiph@0: local function Title_OnMouseDown(frame) Xiiph@0: frame:GetParent():StartMoving() Xiiph@0: AceGUI:ClearFocus() Xiiph@0: end Xiiph@0: Xiiph@0: local function MoverSizer_OnMouseUp(mover) Xiiph@0: local frame = mover:GetParent() Xiiph@0: frame:StopMovingOrSizing() Xiiph@0: local self = frame.obj Xiiph@0: local status = self.status or self.localstatus Xiiph@0: status.width = frame:GetWidth() Xiiph@0: status.height = frame:GetHeight() Xiiph@0: status.top = frame:GetTop() Xiiph@0: status.left = frame:GetLeft() Xiiph@0: end Xiiph@0: Xiiph@0: local function SizerSE_OnMouseDown(frame) Xiiph@0: frame:GetParent():StartSizing("BOTTOMRIGHT") Xiiph@0: AceGUI:ClearFocus() Xiiph@0: end Xiiph@0: Xiiph@0: local function SizerS_OnMouseDown(frame) Xiiph@0: frame:GetParent():StartSizing("BOTTOM") Xiiph@0: AceGUI:ClearFocus() Xiiph@0: end Xiiph@0: Xiiph@0: local function SizerE_OnMouseDown(frame) Xiiph@0: frame:GetParent():StartSizing("RIGHT") Xiiph@0: AceGUI:ClearFocus() Xiiph@0: end Xiiph@0: Xiiph@0: local function StatusBar_OnEnter(frame) Xiiph@0: frame.obj:Fire("OnEnterStatusBar") Xiiph@0: end Xiiph@0: Xiiph@0: local function StatusBar_OnLeave(frame) Xiiph@0: frame.obj:Fire("OnLeaveStatusBar") Xiiph@0: end Xiiph@0: Xiiph@0: --[[----------------------------------------------------------------------------- Xiiph@0: Methods Xiiph@0: -------------------------------------------------------------------------------]] Xiiph@0: local methods = { Xiiph@0: ["OnAcquire"] = function(self) Xiiph@0: self.frame:SetParent(UIParent) Xiiph@0: self.frame:SetFrameStrata("FULLSCREEN_DIALOG") Xiiph@0: self:SetTitle() Xiiph@0: self:SetStatusText() Xiiph@0: self:ApplyStatus() Xiiph@0: self:Show() Xiiph@0: end, Xiiph@0: Xiiph@0: ["OnRelease"] = function(self) Xiiph@0: self.status = nil Xiiph@0: wipe(self.localstatus) Xiiph@0: end, Xiiph@0: Xiiph@0: ["OnWidthSet"] = function(self, width) Xiiph@0: local content = self.content Xiiph@0: local contentwidth = width - 34 Xiiph@0: if contentwidth < 0 then Xiiph@0: contentwidth = 0 Xiiph@0: end Xiiph@0: content:SetWidth(contentwidth) Xiiph@0: content.width = contentwidth Xiiph@0: end, Xiiph@0: Xiiph@0: ["OnHeightSet"] = function(self, height) Xiiph@0: local content = self.content Xiiph@0: local contentheight = height - 57 Xiiph@0: if contentheight < 0 then Xiiph@0: contentheight = 0 Xiiph@0: end Xiiph@0: content:SetHeight(contentheight) Xiiph@0: content.height = contentheight Xiiph@0: end, Xiiph@0: Xiiph@0: ["SetTitle"] = function(self, title) Xiiph@0: self.titletext:SetText(title) Xiiph@0: self.titlebg:SetWidth((self.titletext:GetWidth() or 0) + 10) Xiiph@0: end, Xiiph@0: Xiiph@0: ["SetStatusText"] = function(self, text) Xiiph@0: self.statustext:SetText(text) Xiiph@0: end, Xiiph@0: Xiiph@0: ["Hide"] = function(self) Xiiph@0: self.frame:Hide() Xiiph@0: end, Xiiph@0: Xiiph@0: ["Show"] = function(self) Xiiph@0: self.frame:Show() Xiiph@0: end, Xiiph@0: Xiiph@0: -- called to set an external table to store status in Xiiph@0: ["SetStatusTable"] = function(self, status) Xiiph@0: assert(type(status) == "table") Xiiph@0: self.status = status Xiiph@0: self:ApplyStatus() Xiiph@0: end, Xiiph@0: Xiiph@0: ["ApplyStatus"] = function(self) Xiiph@0: local status = self.status or self.localstatus Xiiph@0: local frame = self.frame Xiiph@0: self:SetWidth(status.width or 700) Xiiph@0: self:SetHeight(status.height or 500) Xiiph@0: frame:ClearAllPoints() Xiiph@0: if status.top and status.left then Xiiph@0: frame:SetPoint("TOP", UIParent, "BOTTOM", 0, status.top) Xiiph@0: frame:SetPoint("LEFT", UIParent, "LEFT", status.left, 0) Xiiph@0: else Xiiph@0: frame:SetPoint("CENTER") Xiiph@0: end Xiiph@0: end Xiiph@0: } Xiiph@0: Xiiph@0: --[[----------------------------------------------------------------------------- Xiiph@0: Constructor Xiiph@0: -------------------------------------------------------------------------------]] Xiiph@0: local FrameBackdrop = { Xiiph@0: bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background", Xiiph@0: edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border", Xiiph@0: tile = true, tileSize = 32, edgeSize = 32, Xiiph@0: insets = { left = 8, right = 8, top = 8, bottom = 8 } Xiiph@0: } Xiiph@0: Xiiph@0: local PaneBackdrop = { Xiiph@0: bgFile = "Interface\\ChatFrame\\ChatFrameBackground", Xiiph@0: edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", Xiiph@0: tile = true, tileSize = 16, edgeSize = 16, Xiiph@0: insets = { left = 3, right = 3, top = 5, bottom = 3 } Xiiph@0: } Xiiph@0: Xiiph@0: local function Constructor() Xiiph@0: local frame = CreateFrame("Frame", nil, UIParent) Xiiph@0: frame:Hide() Xiiph@0: Xiiph@0: frame:EnableMouse(true) Xiiph@0: frame:SetMovable(true) Xiiph@0: frame:SetResizable(true) Xiiph@0: frame:SetFrameStrata("FULLSCREEN_DIALOG") Xiiph@0: frame:SetBackdrop(FrameBackdrop) Xiiph@0: frame:SetBackdropColor(0, 0, 0, 1) Xiiph@0: frame:SetMinResize(400, 200) Xiiph@0: frame:SetToplevel(true) Xiiph@0: frame:SetScript("OnHide", Frame_OnClose) Xiiph@0: frame:SetScript("OnMouseDown", Frame_OnMouseDown) Xiiph@0: Xiiph@0: local closebutton = CreateFrame("Button", nil, frame, "UIPanelButtonTemplate") Xiiph@0: closebutton:SetScript("OnClick", Button_OnClick) Xiiph@0: closebutton:SetPoint("BOTTOMRIGHT", -27, 17) Xiiph@0: closebutton:SetHeight(20) Xiiph@0: closebutton:SetWidth(100) Xiiph@0: closebutton:SetText(CLOSE) Xiiph@0: Xiiph@0: local statusbg = CreateFrame("Button", nil, frame) Xiiph@0: statusbg:SetPoint("BOTTOMLEFT", 15, 15) Xiiph@0: statusbg:SetPoint("BOTTOMRIGHT", -132, 15) Xiiph@0: statusbg:SetHeight(24) Xiiph@0: statusbg:SetBackdrop(PaneBackdrop) Xiiph@0: statusbg:SetBackdropColor(0.1,0.1,0.1) Xiiph@0: statusbg:SetBackdropBorderColor(0.4,0.4,0.4) Xiiph@0: statusbg:SetScript("OnEnter", StatusBar_OnEnter) Xiiph@0: statusbg:SetScript("OnLeave", StatusBar_OnLeave) Xiiph@0: Xiiph@0: local statustext = statusbg:CreateFontString(nil, "OVERLAY", "GameFontNormal") Xiiph@0: statustext:SetPoint("TOPLEFT", 7, -2) Xiiph@0: statustext:SetPoint("BOTTOMRIGHT", -7, 2) Xiiph@0: statustext:SetHeight(20) Xiiph@0: statustext:SetJustifyH("LEFT") Xiiph@0: statustext:SetText("") Xiiph@0: Xiiph@0: local titlebg = frame:CreateTexture(nil, "OVERLAY") Xiiph@0: titlebg:SetTexture("Interface\\DialogFrame\\UI-DialogBox-Header") Xiiph@0: titlebg:SetTexCoord(0.31, 0.67, 0, 0.63) Xiiph@0: titlebg:SetPoint("TOP", 0, 12) Xiiph@0: titlebg:SetWidth(100) Xiiph@0: titlebg:SetHeight(40) Xiiph@0: Xiiph@0: local title = CreateFrame("Frame", nil, frame) Xiiph@0: title:EnableMouse(true) Xiiph@0: title:SetScript("OnMouseDown", Title_OnMouseDown) Xiiph@0: title:SetScript("OnMouseUp", MoverSizer_OnMouseUp) Xiiph@0: title:SetAllPoints(titlebg) Xiiph@0: Xiiph@0: local titletext = title:CreateFontString(nil, "OVERLAY", "GameFontNormal") Xiiph@0: titletext:SetPoint("TOP", titlebg, "TOP", 0, -14) Xiiph@0: Xiiph@0: local titlebg_l = frame:CreateTexture(nil, "OVERLAY") Xiiph@0: titlebg_l:SetTexture("Interface\\DialogFrame\\UI-DialogBox-Header") Xiiph@0: titlebg_l:SetTexCoord(0.21, 0.31, 0, 0.63) Xiiph@0: titlebg_l:SetPoint("RIGHT", titlebg, "LEFT") Xiiph@0: titlebg_l:SetWidth(30) Xiiph@0: titlebg_l:SetHeight(40) Xiiph@0: Xiiph@0: local titlebg_r = frame:CreateTexture(nil, "OVERLAY") Xiiph@0: titlebg_r:SetTexture("Interface\\DialogFrame\\UI-DialogBox-Header") Xiiph@0: titlebg_r:SetTexCoord(0.67, 0.77, 0, 0.63) Xiiph@0: titlebg_r:SetPoint("LEFT", titlebg, "RIGHT") Xiiph@0: titlebg_r:SetWidth(30) Xiiph@0: titlebg_r:SetHeight(40) Xiiph@0: Xiiph@0: local sizer_se = CreateFrame("Frame", nil, frame) Xiiph@0: sizer_se:SetPoint("BOTTOMRIGHT") Xiiph@0: sizer_se:SetWidth(25) Xiiph@0: sizer_se:SetHeight(25) Xiiph@0: sizer_se:EnableMouse() Xiiph@0: sizer_se:SetScript("OnMouseDown",SizerSE_OnMouseDown) Xiiph@0: sizer_se:SetScript("OnMouseUp", MoverSizer_OnMouseUp) Xiiph@0: Xiiph@0: local line1 = sizer_se:CreateTexture(nil, "BACKGROUND") Xiiph@0: line1:SetWidth(14) Xiiph@0: line1:SetHeight(14) Xiiph@0: line1:SetPoint("BOTTOMRIGHT", -8, 8) Xiiph@0: line1:SetTexture("Interface\\Tooltips\\UI-Tooltip-Border") Xiiph@0: local x = 0.1 * 14/17 Xiiph@0: line1:SetTexCoord(0.05 - x, 0.5, 0.05, 0.5 + x, 0.05, 0.5 - x, 0.5 + x, 0.5) Xiiph@0: Xiiph@0: local line2 = sizer_se:CreateTexture(nil, "BACKGROUND") Xiiph@0: line2:SetWidth(8) Xiiph@0: line2:SetHeight(8) Xiiph@0: line2:SetPoint("BOTTOMRIGHT", -8, 8) Xiiph@0: line2:SetTexture("Interface\\Tooltips\\UI-Tooltip-Border") Xiiph@0: local x = 0.1 * 8/17 Xiiph@0: line2:SetTexCoord(0.05 - x, 0.5, 0.05, 0.5 + x, 0.05, 0.5 - x, 0.5 + x, 0.5) Xiiph@0: Xiiph@0: local sizer_s = CreateFrame("Frame", nil, frame) Xiiph@0: sizer_s:SetPoint("BOTTOMRIGHT", -25, 0) Xiiph@0: sizer_s:SetPoint("BOTTOMLEFT") Xiiph@0: sizer_s:SetHeight(25) Xiiph@0: sizer_s:EnableMouse(true) Xiiph@0: sizer_s:SetScript("OnMouseDown", SizerS_OnMouseDown) Xiiph@0: sizer_s:SetScript("OnMouseUp", MoverSizer_OnMouseUp) Xiiph@0: Xiiph@0: local sizer_e = CreateFrame("Frame", nil, frame) Xiiph@0: sizer_e:SetPoint("BOTTOMRIGHT", 0, 25) Xiiph@0: sizer_e:SetPoint("TOPRIGHT") Xiiph@0: sizer_e:SetWidth(25) Xiiph@0: sizer_e:EnableMouse(true) Xiiph@0: sizer_e:SetScript("OnMouseDown", SizerE_OnMouseDown) Xiiph@0: sizer_e:SetScript("OnMouseUp", MoverSizer_OnMouseUp) Xiiph@0: Xiiph@0: --Container Support Xiiph@0: local content = CreateFrame("Frame", nil, frame) Xiiph@0: content:SetPoint("TOPLEFT", 17, -27) Xiiph@0: content:SetPoint("BOTTOMRIGHT", -17, 40) Xiiph@0: Xiiph@0: local widget = { Xiiph@0: localstatus = {}, Xiiph@0: titletext = titletext, Xiiph@0: statustext = statustext, Xiiph@0: titlebg = titlebg, Xiiph@0: content = content, Xiiph@0: frame = frame, Xiiph@0: type = Type Xiiph@0: } Xiiph@0: for method, func in pairs(methods) do Xiiph@0: widget[method] = func Xiiph@0: end Xiiph@0: closebutton.obj, statusbg.obj = widget, widget Xiiph@0: Xiiph@0: return AceGUI:RegisterAsContainer(widget) Xiiph@0: end Xiiph@0: Xiiph@0: AceGUI:RegisterWidgetType(Type, Constructor, Version)