yellowfive@57: --[[----------------------------------------------------------------------------- yellowfive@57: Text Button Widget yellowfive@57: Based on the AceGUI button, but a custom look that just shows text. yellowfive@57: -------------------------------------------------------------------------------]] yellowfive@57: local Type, Version = "AmrUiTextButton", 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 Amr = LibStub("AceAddon-3.0"):GetAddon("AskMrRobot") yellowfive@57: yellowfive@57: -- Lua APIs yellowfive@57: local pairs = pairs yellowfive@57: yellowfive@57: -- WoW APIs yellowfive@57: local _G = _G yellowfive@57: local PlaySound, CreateFrame, UIParent = PlaySound, CreateFrame, UIParent yellowfive@57: yellowfive@57: yellowfive@57: --[[----------------------------------------------------------------------------- yellowfive@57: Scripts yellowfive@57: -------------------------------------------------------------------------------]] yellowfive@57: local function buttonOnClick(frame, ...) yellowfive@57: AceGUI:ClearFocus() yellowfive@112: --PlaySound("igMainMenuOption") yellowfive@57: frame.obj:Fire("OnClick", ...) yellowfive@57: end yellowfive@57: yellowfive@57: local function buttonOnEnter(frame) yellowfive@57: frame.obj.bg:Hide() yellowfive@57: frame.obj.hover:Show() yellowfive@57: frame.obj:Fire("OnEnter") yellowfive@57: end yellowfive@57: yellowfive@57: local function buttonOnLeave(frame) yellowfive@57: frame.obj.bg:Show() yellowfive@57: frame.obj.hover:Hide() yellowfive@57: frame.obj:Fire("OnLeave") yellowfive@57: end yellowfive@57: yellowfive@57: --[[----------------------------------------------------------------------------- yellowfive@57: Methods yellowfive@57: -------------------------------------------------------------------------------]] yellowfive@57: local methods = { yellowfive@57: ["OnAcquire"] = function(self) yellowfive@57: -- restore default values yellowfive@57: self:SetHeight(24) yellowfive@57: self:SetWidth(200) yellowfive@57: self:SetBackgroundColor(Amr.Colors.Black, 0) yellowfive@57: self:SetHoverBackgroundColor(Amr.Colors.Black, 0) yellowfive@57: self:SetDisabled(false) yellowfive@57: yellowfive@57: self:SetFont(Amr.CreateFont("Regular", 16, Amr.Colors.Text)) yellowfive@57: self:SetHoverFont(Amr.CreateFont("Regular", 16, Amr.Colors.TextHover)) yellowfive@57: self:SetText("") yellowfive@57: self:SetWordWrap(true) yellowfive@57: self:SetJustifyH("CENTER") yellowfive@57: self:SetJustifyV("MIDDLE") yellowfive@57: self:SetTextPadding() yellowfive@57: yellowfive@57: self:SetSubtextFont(Amr.CreateFont("Regular", 16, Amr.Colors.Text)) yellowfive@57: self:SetSubtext() yellowfive@57: self:SetSubtextWordWrap(true) yellowfive@57: self:SetSubtextJustifyH("CENTER") yellowfive@57: self:SetSubtextJustifyV("MIDDLE") yellowfive@57: self:SetSubtextPadding() yellowfive@57: yellowfive@57: self.frame:ClearAllPoints() yellowfive@57: self.bg:Show() yellowfive@57: self.hover:Hide() yellowfive@57: end, yellowfive@57: yellowfive@57: ["OnWidthSet"] = function(self, width) yellowfive@57: self.frame:GetFontString():SetWidth(width) yellowfive@57: end, yellowfive@57: yellowfive@57: ["OnHeightSet"] = function(self, height) yellowfive@57: self.frame:GetFontString():SetHeight(height) yellowfive@57: end, yellowfive@57: yellowfive@57: ["SetBackgroundColor"] = function(self, color, alpha) yellowfive@81: self.bg:SetColorTexture(color.R, color.G, color.B, alpha) yellowfive@57: end, yellowfive@57: yellowfive@57: ["SetBackgroundImage"] = function(self, image) yellowfive@57: self.bg:SetTexture(image) yellowfive@57: self.bg:SetDesaturated(false) yellowfive@57: end, yellowfive@57: yellowfive@57: ["SetHoverBackgroundColor"] = function(self, color, alpha) yellowfive@81: self.hover:SetColorTexture(color.R, color.G, color.B, alpha) yellowfive@57: end, yellowfive@57: yellowfive@57: ["SetHoverBackgroundImage"] = function(self, image) yellowfive@57: self.hover:SetTexture(image) yellowfive@57: end, yellowfive@57: yellowfive@57: ["SetText"] = function(self, text) yellowfive@57: self.frame:SetText(text) yellowfive@57: end, yellowfive@57: yellowfive@57: ["SetWordWrap"] = function(self, enable) yellowfive@57: self.frame:GetFontString():SetWordWrap(enable) yellowfive@57: end, yellowfive@57: yellowfive@57: ["SetJustifyH"] = function(self, val) yellowfive@57: self.frame:GetFontString():SetJustifyH(val) yellowfive@57: end, yellowfive@57: yellowfive@57: ["SetJustifyV"] = function(self, val) yellowfive@57: self.frame:GetFontString():SetJustifyV(val) yellowfive@57: end, yellowfive@57: yellowfive@57: ["SetTextPadding"] = function(self, top, right, bottom, left) yellowfive@57: local f = self.frame:GetFontString() yellowfive@57: f:ClearAllPoints() yellowfive@57: yellowfive@57: if not top and not right and not bottom and not left then yellowfive@57: f:SetPoint("CENTER") yellowfive@57: end yellowfive@57: yellowfive@57: if top then f:SetPoint("TOP", self.frame, "TOP", 0, -top) end yellowfive@57: if right then f:SetPoint("RIGHT", self.frame, "RIGHT", -right, 0) end yellowfive@57: if bottom then f:SetPoint("BOTTOM", self.frame, "BOTTOM", 0, bottom) end yellowfive@57: if left then f:SetPoint("LEFT", self.frame, "LEFT", left, 0) end yellowfive@57: end, yellowfive@57: yellowfive@57: ["SetFont"] = function(self, font) yellowfive@57: self.frame:SetNormalFontObject(font) yellowfive@57: end, yellowfive@57: yellowfive@57: ["SetHoverFont"] = function(self, font) yellowfive@57: self.frame:SetHighlightFontObject(font) yellowfive@57: end, yellowfive@57: yellowfive@57: ["SetSubtext"] = function(self, text) yellowfive@57: self.subtxt:SetText(text) yellowfive@57: if text then yellowfive@57: self.subtxt:Show() yellowfive@57: else yellowfive@57: self.subtxt:Hide() yellowfive@57: end yellowfive@57: end, yellowfive@57: yellowfive@57: ["SetSubtextWordWrap"] = function(self, enable) yellowfive@57: self.subtxt:SetWordWrap(enable) yellowfive@57: end, yellowfive@57: yellowfive@57: ["SetSubtextJustifyH"] = function(self, val) yellowfive@57: self.subtxt:SetJustifyH(val) yellowfive@57: end, yellowfive@57: yellowfive@57: ["SetSubtextJustifyV"] = function(self, val) yellowfive@57: self.subtxt:SetJustifyV(val) yellowfive@57: end, yellowfive@57: yellowfive@57: ["SetSubtextPadding"] = function(self, top, right, bottom, left) yellowfive@57: local f = self.subtxt yellowfive@57: f:ClearAllPoints() yellowfive@57: if top then f:SetPoint("TOP", self.frame, "TOP", 0, -top) end yellowfive@57: if right then f:SetPoint("RIGHT", self.frame, "RIGHT", -right, 0) end yellowfive@57: if bottom then f:SetPoint("BOTTOM", self.frame, "BOTTOM", 0, bottom) end yellowfive@57: if left then f:SetPoint("LEFT", self.frame, "LEFT", left, 0) end yellowfive@57: end, yellowfive@57: yellowfive@57: ["SetSubtextFont"] = function(self, font) yellowfive@57: self.subtxt:SetFontObject(font) yellowfive@57: end, yellowfive@57: yellowfive@57: ["SetDisabled"] = function(self, disabled) yellowfive@57: self.disabled = disabled yellowfive@57: if disabled then yellowfive@57: self.frame:Disable() yellowfive@57: else yellowfive@57: self.frame:Enable() yellowfive@57: end yellowfive@57: end, yellowfive@57: yellowfive@57: ["SetVisible"] = function(self, visible) yellowfive@57: if visible then yellowfive@57: self.frame:Show() yellowfive@57: else yellowfive@57: self.frame:Hide() yellowfive@57: end yellowfive@57: end yellowfive@57: } yellowfive@57: yellowfive@57: --[[----------------------------------------------------------------------------- yellowfive@57: Constructor yellowfive@57: -------------------------------------------------------------------------------]] yellowfive@57: local function Constructor() yellowfive@57: local name = "AmrUiTextButton" .. AceGUI:GetNextWidgetNum(Type) yellowfive@57: local frame = CreateFrame("Button", name, UIParent) yellowfive@57: frame:Hide() yellowfive@57: yellowfive@57: local txt = frame:CreateFontString() yellowfive@57: frame:SetFontString(txt) yellowfive@57: yellowfive@57: local subtxt = frame:CreateFontString() yellowfive@57: subtxt:Hide() yellowfive@57: yellowfive@57: frame:EnableMouse(true) yellowfive@57: frame:SetScript("OnEnter", buttonOnEnter) yellowfive@57: frame:SetScript("OnLeave", buttonOnLeave) yellowfive@57: frame:SetScript("OnClick", buttonOnClick) yellowfive@57: yellowfive@57: local bg = frame:CreateTexture() yellowfive@57: bg:SetAllPoints() yellowfive@57: yellowfive@57: local hover = frame:CreateTexture() yellowfive@57: hover:SetAllPoints() yellowfive@57: yellowfive@57: local widget = { yellowfive@57: bg = bg, yellowfive@57: subtxt = subtxt, yellowfive@57: hover = hover, 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: yellowfive@57: return AceGUI:RegisterAsWidget(widget) yellowfive@57: end yellowfive@57: yellowfive@57: AceGUI:RegisterWidgetType(Type, Constructor, Version)