yellowfive@57: --[[----------------------------------------------------------------------------- yellowfive@57: Button Widget yellowfive@57: Based on the AceGUI button, but with a custom look for AMR. yellowfive@57: -------------------------------------------------------------------------------]] yellowfive@57: local Type, Version = "AmrUiButton", 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@57: PlaySound("igMainMenuOption") yellowfive@57: frame.obj:Fire("OnClick", ...) 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:SetDisabled(false) yellowfive@57: self:SetText() yellowfive@57: self:SetBackgroundColor({R = 0, G = 0, B = 0}) yellowfive@57: self:SetFont(Amr.CreateFont("Regular", 16, Amr.Colors.White)) yellowfive@57: self.frame:ClearAllPoints() yellowfive@57: end, yellowfive@57: yellowfive@57: ["SetText"] = function(self, text) yellowfive@57: self.frame:SetText(text) yellowfive@57: end, yellowfive@57: yellowfive@57: ["SetFont"] = function(self, font) yellowfive@57: self.frame:SetNormalFontObject(font) yellowfive@57: end, yellowfive@57: yellowfive@57: -- color is an object with R, G, B yellowfive@57: ["SetBackgroundColor"] = function(self, color) yellowfive@57: self.texNormal:SetTexture(color.R, color.G, color.B, 1) yellowfive@57: self.texPush:SetTexture(color.R, color.G, color.B, 1) 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: self.frame:SetAlpha(0.2) yellowfive@57: else yellowfive@57: self.frame:Enable() yellowfive@57: self.frame:SetAlpha(1) 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 = "AmrUiButton" .. AceGUI:GetNextWidgetNum(Type) yellowfive@57: local frame = CreateFrame("Button", name, UIParent) yellowfive@57: frame:Hide() yellowfive@57: yellowfive@57: frame:EnableMouse(true) yellowfive@57: frame:SetScript("OnClick", buttonOnClick) yellowfive@57: yellowfive@57: Amr.DropShadow(frame) yellowfive@57: yellowfive@57: -- normal bg color, can be set with SetBackgroundColor yellowfive@57: local texNormal = frame:CreateTexture(nil, "BORDER") yellowfive@57: texNormal:SetAllPoints(true) yellowfive@57: frame:SetNormalTexture(texNormal) yellowfive@57: yellowfive@57: -- gives a 1px down+right animation on press yellowfive@57: local texPush = frame:CreateTexture(nil, "BORDER") yellowfive@57: texPush:SetPoint("TOPLEFT", frame, "TOPLEFT", 1, -1) yellowfive@57: texPush:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", 1, -1) yellowfive@57: frame:SetPushedTexture(texPush) yellowfive@57: yellowfive@57: -- not perfect, but more or less achieves the effect of lightening the bg color slightly on hover yellowfive@57: local texHigh = frame:CreateTexture(nil, "BORDER") yellowfive@57: texHigh:SetTexture(1, 1, 1, 0.1) yellowfive@57: texHigh:SetAllPoints(true) yellowfive@57: frame:SetHighlightTexture(texHigh) yellowfive@57: yellowfive@57: local widget = { yellowfive@57: texNormal = texNormal, yellowfive@57: texPush = texPush, 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)