yellowfive@57: --[[----------------------------------------------------------------------------- yellowfive@57: AmrUiFrame container yellowfive@57: -------------------------------------------------------------------------------]] yellowfive@57: local Type, Version = "AmrUiFrame", 1 yellowfive@57: local AceGUI = LibStub and LibStub("AceGUI-3.0", true) yellowfive@57: if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end yellowfive@57: yellowfive@57: local L = LibStub("AceLocale-3.0"):GetLocale("AskMrRobot", true) yellowfive@57: local Amr = LibStub("AceAddon-3.0"):GetAddon("AskMrRobot") yellowfive@57: yellowfive@57: -- Lua APIs yellowfive@57: local pairs, assert, type = pairs, assert, type yellowfive@57: local wipe = table.wipe yellowfive@57: yellowfive@57: -- WoW APIs yellowfive@57: local PlaySound = PlaySound yellowfive@57: local CreateFrame, UIParent = CreateFrame, UIParent yellowfive@57: yellowfive@57: -- Global vars/functions that we don't upvalue since they might get hooked, or upgraded yellowfive@57: -- List them here for Mikk's FindGlobals script yellowfive@57: -- GLOBALS: CLOSE yellowfive@57: yellowfive@57: -- width of the frame border yellowfive@57: local _borderWidth = 1 yellowfive@57: yellowfive@57: yellowfive@57: --[[----------------------------------------------------------------------------- yellowfive@57: Scripts yellowfive@57: -------------------------------------------------------------------------------]] yellowfive@57: local function buttonOnClick(frame) yellowfive@57: PlaySound("gsTitleOptionExit") yellowfive@57: frame.obj:Hide() yellowfive@57: end yellowfive@57: yellowfive@57: local function frameOnClose(frame) yellowfive@57: frame.obj:Fire("OnClose") yellowfive@57: end yellowfive@57: yellowfive@57: local function frameOnMouseDown(frame) yellowfive@57: AceGUI:ClearFocus() yellowfive@57: end yellowfive@57: yellowfive@57: local function titleOnMouseDown(frame) yellowfive@57: frame.obj:StartMove() yellowfive@57: end yellowfive@57: yellowfive@57: local function titleOnMouseUp(frame) yellowfive@57: frame.obj:EndMove() yellowfive@57: end yellowfive@57: yellowfive@57: --[[----------------------------------------------------------------------------- yellowfive@57: Methods yellowfive@57: -------------------------------------------------------------------------------]] yellowfive@57: local methods = { yellowfive@57: ["OnAcquire"] = function(self) yellowfive@57: self:SetAutoAdjustHeight(false) yellowfive@57: self.frame:SetParent(UIParent) yellowfive@57: self.frame:SetFrameStrata("FULLSCREEN_DIALOG") yellowfive@57: self:ApplyStatus() yellowfive@57: self:Show() yellowfive@57: end, yellowfive@57: yellowfive@57: ["OnRelease"] = function(self) yellowfive@57: self.status = nil yellowfive@57: wipe(self.localstatus) yellowfive@57: end, yellowfive@57: yellowfive@57: ["Hide"] = function(self) yellowfive@57: self.frame:Hide() yellowfive@57: end, yellowfive@57: yellowfive@57: ["Show"] = function(self) yellowfive@57: self.frame:Show() yellowfive@57: end, yellowfive@57: yellowfive@57: -- called to set an external table to store status in yellowfive@57: ["SetStatusTable"] = function(self, status) yellowfive@57: assert(type(status) == "table") yellowfive@57: self.status = status yellowfive@57: self:ApplyStatus() yellowfive@57: end, yellowfive@57: yellowfive@57: ["ApplyStatus"] = function(self) yellowfive@57: local status = self.status or self.localstatus yellowfive@57: local frame = self.frame yellowfive@57: frame:ClearAllPoints() yellowfive@57: if status.top and status.left then yellowfive@57: frame:SetPoint("TOP", UIParent, "BOTTOM", 0, status.top) yellowfive@57: frame:SetPoint("LEFT", UIParent, "LEFT", status.left, 0) yellowfive@57: else yellowfive@57: frame:SetPoint("CENTER") yellowfive@57: end yellowfive@57: end, yellowfive@57: yellowfive@57: -- color is an object with R, G, B yellowfive@57: ["SetBackgroundColor"] = function(self, color) yellowfive@57: self.bg:SetTexture(color.R, color.G, color.B, 1) yellowfive@57: end, yellowfive@57: yellowfive@57: ["SetBorderColor"] = function(self, color) yellowfive@57: self.border:SetTexture(color.R, color.G, color.B, 1) yellowfive@57: end, yellowfive@57: yellowfive@57: ["Raise"] = function(self) yellowfive@57: self.frame:Raise() yellowfive@57: end, yellowfive@57: yellowfive@57: ["StartMove"] = function(self) yellowfive@57: self.frame:StartMoving() yellowfive@57: AceGUI:ClearFocus() yellowfive@57: end, yellowfive@57: yellowfive@57: ["EndMove"] = function(self) yellowfive@57: self.frame:StopMovingOrSizing() yellowfive@57: local status = self.status or self.localstatus yellowfive@57: status.top = self.frame:GetTop() yellowfive@57: status.left = self.frame:GetLeft() yellowfive@57: end, yellowfive@57: yellowfive@57: ["OnWidthSet"] = function(self, width) yellowfive@57: local content = self.content yellowfive@57: content.width = width yellowfive@57: end, yellowfive@57: yellowfive@57: ["OnHeightSet"] = function(self, height) yellowfive@57: local content = self.content yellowfive@57: content.height = height yellowfive@57: end yellowfive@57: } yellowfive@57: yellowfive@57: --[[----------------------------------------------------------------------------- yellowfive@57: Constructor yellowfive@57: -------------------------------------------------------------------------------]] yellowfive@57: local function Constructor() yellowfive@57: local num = AceGUI:GetNextWidgetNum(Type) yellowfive@57: local frame = CreateFrame("Frame", "AmrUiFrame" .. num, UIParent) yellowfive@57: frame:Hide() yellowfive@57: yellowfive@57: -- make escape key close this window yellowfive@57: table.insert(UISpecialFrames, frame:GetName()) yellowfive@57: yellowfive@57: frame:EnableMouse(true) yellowfive@57: frame:SetMovable(true) yellowfive@57: frame:SetResizable(false) yellowfive@57: frame:SetFrameStrata("FULLSCREEN_DIALOG") yellowfive@57: frame:SetToplevel(true) yellowfive@57: frame:SetScript("OnHide", frameOnClose) yellowfive@57: frame:SetScript("OnMouseDown", frameOnMouseDown) yellowfive@57: yellowfive@57: Amr.DropShadow(frame) yellowfive@57: yellowfive@57: local border = frame:CreateTexture(nil, "BACKGROUND", nil, 1) yellowfive@57: border:SetAllPoints(true) yellowfive@57: yellowfive@57: local bg = frame:CreateTexture(nil, "BORDER") yellowfive@57: bg:SetPoint("TOPLEFT", frame, "TOPLEFT", _borderWidth, -_borderWidth) yellowfive@57: bg:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -_borderWidth, _borderWidth) yellowfive@57: yellowfive@57: local btnClose = CreateFrame("Button", nil, frame) yellowfive@57: btnClose:SetNormalFontObject(Amr.CreateFont("Bold", 16, Amr.Colors.White)) yellowfive@57: btnClose:SetText("x") yellowfive@57: btnClose:SetWidth(22) yellowfive@57: btnClose:SetHeight(22) yellowfive@57: btnClose:SetPoint("TOPRIGHT", frame, "TOPRIGHT", -4, -4) yellowfive@57: btnClose:SetScript("OnClick", buttonOnClick) yellowfive@57: yellowfive@57: local lbl = btnClose:GetFontString() yellowfive@57: lbl:ClearAllPoints() yellowfive@57: lbl:SetPoint("TOP", btnClose, "TOP", -1, -2) yellowfive@57: yellowfive@57: -- style the button similar to AmrUiButton yellowfive@57: Amr.DropShadow(btnClose) yellowfive@57: yellowfive@57: local tex = Amr.CreateTexture(btnClose, Amr.Colors.Red) yellowfive@57: tex:SetAllPoints(true) yellowfive@57: btnClose:SetNormalTexture(tex) yellowfive@57: yellowfive@57: tex = Amr.CreateTexture(btnClose, Amr.Colors.Red) yellowfive@57: tex:SetPoint("TOPLEFT", btnClose, "TOPLEFT", 1, -1) yellowfive@57: tex:SetPoint("BOTTOMRIGHT", btnClose, "BOTTOMRIGHT", 1, -1) yellowfive@57: btnClose:SetPushedTexture(tex) yellowfive@57: yellowfive@57: tex = Amr.CreateTexture(btnClose, Amr.Colors.White, 0.1) yellowfive@57: tex:SetAllPoints(true) yellowfive@57: btnClose:SetHighlightTexture(tex) yellowfive@57: yellowfive@57: -- title yellowfive@57: local titleFrame = CreateFrame("Frame", nil, frame) yellowfive@57: titleFrame:SetPoint("TOPLEFT", frame, "TOPLEFT", 0, 0) yellowfive@57: titleFrame:SetPoint("BOTTOMRIGHT", frame, "TOPRIGHT", 0, -40) yellowfive@57: titleFrame:EnableMouse(true) yellowfive@57: titleFrame:SetScript("OnMouseDown", titleOnMouseDown) yellowfive@57: titleFrame:SetScript("OnMouseUp", titleOnMouseUp) yellowfive@57: yellowfive@57: --Container Support yellowfive@57: local content = CreateFrame("Frame", nil, frame) yellowfive@57: content:SetPoint("TOPLEFT", titleFrame, "BOTTOMLEFT", 20, 0) yellowfive@57: content:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -20, 20) yellowfive@57: yellowfive@57: local widget = { yellowfive@57: localstatus = {}, yellowfive@57: border = border, yellowfive@57: bg = bg, yellowfive@57: content = content, yellowfive@57: frame = frame, yellowfive@57: type = Type yellowfive@57: } yellowfive@57: for method, func in pairs(methods) do yellowfive@57: widget[method] = func yellowfive@57: end yellowfive@57: btnClose.obj, titleFrame.obj = widget, widget yellowfive@57: yellowfive@57: return AceGUI:RegisterAsContainer(widget) yellowfive@57: end yellowfive@57: yellowfive@57: AceGUI:RegisterWidgetType(Type, Constructor, Version)