Mercurial > wow > askmrrobot
comparison ui/AmrUiButton.lua @ 57:01b63b8ed811 v21
total rewrite to version 21
| author | yellowfive |
|---|---|
| date | Fri, 05 Jun 2015 11:05:15 -0700 |
| parents | |
| children | 0515882856f1 |
comparison
equal
deleted
inserted
replaced
| 56:75431c084aa0 | 57:01b63b8ed811 |
|---|---|
| 1 --[[----------------------------------------------------------------------------- | |
| 2 Button Widget | |
| 3 Based on the AceGUI button, but with a custom look for AMR. | |
| 4 -------------------------------------------------------------------------------]] | |
| 5 local Type, Version = "AmrUiButton", 1 | |
| 6 local AceGUI = LibStub and LibStub("AceGUI-3.0", true) | |
| 7 if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end | |
| 8 | |
| 9 local Amr = LibStub("AceAddon-3.0"):GetAddon("AskMrRobot") | |
| 10 | |
| 11 -- Lua APIs | |
| 12 local pairs = pairs | |
| 13 | |
| 14 -- WoW APIs | |
| 15 local _G = _G | |
| 16 local PlaySound, CreateFrame, UIParent = PlaySound, CreateFrame, UIParent | |
| 17 | |
| 18 | |
| 19 --[[----------------------------------------------------------------------------- | |
| 20 Scripts | |
| 21 -------------------------------------------------------------------------------]] | |
| 22 local function buttonOnClick(frame, ...) | |
| 23 AceGUI:ClearFocus() | |
| 24 PlaySound("igMainMenuOption") | |
| 25 frame.obj:Fire("OnClick", ...) | |
| 26 end | |
| 27 | |
| 28 --[[----------------------------------------------------------------------------- | |
| 29 Methods | |
| 30 -------------------------------------------------------------------------------]] | |
| 31 local methods = { | |
| 32 ["OnAcquire"] = function(self) | |
| 33 -- restore default values | |
| 34 self:SetHeight(24) | |
| 35 self:SetWidth(200) | |
| 36 self:SetDisabled(false) | |
| 37 self:SetText() | |
| 38 self:SetBackgroundColor({R = 0, G = 0, B = 0}) | |
| 39 self:SetFont(Amr.CreateFont("Regular", 16, Amr.Colors.White)) | |
| 40 self.frame:ClearAllPoints() | |
| 41 end, | |
| 42 | |
| 43 ["SetText"] = function(self, text) | |
| 44 self.frame:SetText(text) | |
| 45 end, | |
| 46 | |
| 47 ["SetFont"] = function(self, font) | |
| 48 self.frame:SetNormalFontObject(font) | |
| 49 end, | |
| 50 | |
| 51 -- color is an object with R, G, B | |
| 52 ["SetBackgroundColor"] = function(self, color) | |
| 53 self.texNormal:SetTexture(color.R, color.G, color.B, 1) | |
| 54 self.texPush:SetTexture(color.R, color.G, color.B, 1) | |
| 55 end, | |
| 56 | |
| 57 ["SetDisabled"] = function(self, disabled) | |
| 58 self.disabled = disabled | |
| 59 if disabled then | |
| 60 self.frame:Disable() | |
| 61 self.frame:SetAlpha(0.2) | |
| 62 else | |
| 63 self.frame:Enable() | |
| 64 self.frame:SetAlpha(1) | |
| 65 end | |
| 66 end, | |
| 67 | |
| 68 ["SetVisible"] = function(self, visible) | |
| 69 if visible then | |
| 70 self.frame:Show() | |
| 71 else | |
| 72 self.frame:Hide() | |
| 73 end | |
| 74 end | |
| 75 } | |
| 76 | |
| 77 --[[----------------------------------------------------------------------------- | |
| 78 Constructor | |
| 79 -------------------------------------------------------------------------------]] | |
| 80 local function Constructor() | |
| 81 local name = "AmrUiButton" .. AceGUI:GetNextWidgetNum(Type) | |
| 82 local frame = CreateFrame("Button", name, UIParent) | |
| 83 frame:Hide() | |
| 84 | |
| 85 frame:EnableMouse(true) | |
| 86 frame:SetScript("OnClick", buttonOnClick) | |
| 87 | |
| 88 Amr.DropShadow(frame) | |
| 89 | |
| 90 -- normal bg color, can be set with SetBackgroundColor | |
| 91 local texNormal = frame:CreateTexture(nil, "BORDER") | |
| 92 texNormal:SetAllPoints(true) | |
| 93 frame:SetNormalTexture(texNormal) | |
| 94 | |
| 95 -- gives a 1px down+right animation on press | |
| 96 local texPush = frame:CreateTexture(nil, "BORDER") | |
| 97 texPush:SetPoint("TOPLEFT", frame, "TOPLEFT", 1, -1) | |
| 98 texPush:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", 1, -1) | |
| 99 frame:SetPushedTexture(texPush) | |
| 100 | |
| 101 -- not perfect, but more or less achieves the effect of lightening the bg color slightly on hover | |
| 102 local texHigh = frame:CreateTexture(nil, "BORDER") | |
| 103 texHigh:SetTexture(1, 1, 1, 0.1) | |
| 104 texHigh:SetAllPoints(true) | |
| 105 frame:SetHighlightTexture(texHigh) | |
| 106 | |
| 107 local widget = { | |
| 108 texNormal = texNormal, | |
| 109 texPush = texPush, | |
| 110 frame = frame, | |
| 111 type = Type | |
| 112 } | |
| 113 for method, func in pairs(methods) do | |
| 114 widget[method] = func | |
| 115 end | |
| 116 | |
| 117 return AceGUI:RegisterAsWidget(widget) | |
| 118 end | |
| 119 | |
| 120 AceGUI:RegisterWidgetType(Type, Constructor, Version) |
