annotate ui/AmrUiTextButton.lua @ 93:177391341e26

added back in automatic combat logging feature, useful for upload to any log site
author yellowfive
date Wed, 21 Sep 2016 11:25:11 -0700
parents 0515882856f1
children 57c6cac5143c
rev   line source
yellowfive@57 1 --[[-----------------------------------------------------------------------------
yellowfive@57 2 Text Button Widget
yellowfive@57 3 Based on the AceGUI button, but a custom look that just shows text.
yellowfive@57 4 -------------------------------------------------------------------------------]]
yellowfive@57 5 local Type, Version = "AmrUiTextButton", 1
yellowfive@57 6 local AceGUI = LibStub and LibStub("AceGUI-3.0", true)
yellowfive@57 7 if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end
yellowfive@57 8
yellowfive@57 9 local Amr = LibStub("AceAddon-3.0"):GetAddon("AskMrRobot")
yellowfive@57 10
yellowfive@57 11 -- Lua APIs
yellowfive@57 12 local pairs = pairs
yellowfive@57 13
yellowfive@57 14 -- WoW APIs
yellowfive@57 15 local _G = _G
yellowfive@57 16 local PlaySound, CreateFrame, UIParent = PlaySound, CreateFrame, UIParent
yellowfive@57 17
yellowfive@57 18
yellowfive@57 19 --[[-----------------------------------------------------------------------------
yellowfive@57 20 Scripts
yellowfive@57 21 -------------------------------------------------------------------------------]]
yellowfive@57 22 local function buttonOnClick(frame, ...)
yellowfive@57 23 AceGUI:ClearFocus()
yellowfive@57 24 PlaySound("igMainMenuOption")
yellowfive@57 25 frame.obj:Fire("OnClick", ...)
yellowfive@57 26 end
yellowfive@57 27
yellowfive@57 28 local function buttonOnEnter(frame)
yellowfive@57 29 frame.obj.bg:Hide()
yellowfive@57 30 frame.obj.hover:Show()
yellowfive@57 31 frame.obj:Fire("OnEnter")
yellowfive@57 32 end
yellowfive@57 33
yellowfive@57 34 local function buttonOnLeave(frame)
yellowfive@57 35 frame.obj.bg:Show()
yellowfive@57 36 frame.obj.hover:Hide()
yellowfive@57 37 frame.obj:Fire("OnLeave")
yellowfive@57 38 end
yellowfive@57 39
yellowfive@57 40 --[[-----------------------------------------------------------------------------
yellowfive@57 41 Methods
yellowfive@57 42 -------------------------------------------------------------------------------]]
yellowfive@57 43 local methods = {
yellowfive@57 44 ["OnAcquire"] = function(self)
yellowfive@57 45 -- restore default values
yellowfive@57 46 self:SetHeight(24)
yellowfive@57 47 self:SetWidth(200)
yellowfive@57 48 self:SetBackgroundColor(Amr.Colors.Black, 0)
yellowfive@57 49 self:SetHoverBackgroundColor(Amr.Colors.Black, 0)
yellowfive@57 50 self:SetDisabled(false)
yellowfive@57 51
yellowfive@57 52 self:SetFont(Amr.CreateFont("Regular", 16, Amr.Colors.Text))
yellowfive@57 53 self:SetHoverFont(Amr.CreateFont("Regular", 16, Amr.Colors.TextHover))
yellowfive@57 54 self:SetText("")
yellowfive@57 55 self:SetWordWrap(true)
yellowfive@57 56 self:SetJustifyH("CENTER")
yellowfive@57 57 self:SetJustifyV("MIDDLE")
yellowfive@57 58 self:SetTextPadding()
yellowfive@57 59
yellowfive@57 60 self:SetSubtextFont(Amr.CreateFont("Regular", 16, Amr.Colors.Text))
yellowfive@57 61 self:SetSubtext()
yellowfive@57 62 self:SetSubtextWordWrap(true)
yellowfive@57 63 self:SetSubtextJustifyH("CENTER")
yellowfive@57 64 self:SetSubtextJustifyV("MIDDLE")
yellowfive@57 65 self:SetSubtextPadding()
yellowfive@57 66
yellowfive@57 67 self.frame:ClearAllPoints()
yellowfive@57 68 self.bg:Show()
yellowfive@57 69 self.hover:Hide()
yellowfive@57 70 end,
yellowfive@57 71
yellowfive@57 72 ["OnWidthSet"] = function(self, width)
yellowfive@57 73 self.frame:GetFontString():SetWidth(width)
yellowfive@57 74 end,
yellowfive@57 75
yellowfive@57 76 ["OnHeightSet"] = function(self, height)
yellowfive@57 77 self.frame:GetFontString():SetHeight(height)
yellowfive@57 78 end,
yellowfive@57 79
yellowfive@57 80 ["SetBackgroundColor"] = function(self, color, alpha)
yellowfive@81 81 self.bg:SetColorTexture(color.R, color.G, color.B, alpha)
yellowfive@57 82 end,
yellowfive@57 83
yellowfive@57 84 ["SetBackgroundImage"] = function(self, image)
yellowfive@57 85 self.bg:SetTexture(image)
yellowfive@57 86 self.bg:SetDesaturated(false)
yellowfive@57 87 end,
yellowfive@57 88
yellowfive@57 89 ["SetHoverBackgroundColor"] = function(self, color, alpha)
yellowfive@81 90 self.hover:SetColorTexture(color.R, color.G, color.B, alpha)
yellowfive@57 91 end,
yellowfive@57 92
yellowfive@57 93 ["SetHoverBackgroundImage"] = function(self, image)
yellowfive@57 94 self.hover:SetTexture(image)
yellowfive@57 95 end,
yellowfive@57 96
yellowfive@57 97 ["SetText"] = function(self, text)
yellowfive@57 98 self.frame:SetText(text)
yellowfive@57 99 end,
yellowfive@57 100
yellowfive@57 101 ["SetWordWrap"] = function(self, enable)
yellowfive@57 102 self.frame:GetFontString():SetWordWrap(enable)
yellowfive@57 103 end,
yellowfive@57 104
yellowfive@57 105 ["SetJustifyH"] = function(self, val)
yellowfive@57 106 self.frame:GetFontString():SetJustifyH(val)
yellowfive@57 107 end,
yellowfive@57 108
yellowfive@57 109 ["SetJustifyV"] = function(self, val)
yellowfive@57 110 self.frame:GetFontString():SetJustifyV(val)
yellowfive@57 111 end,
yellowfive@57 112
yellowfive@57 113 ["SetTextPadding"] = function(self, top, right, bottom, left)
yellowfive@57 114 local f = self.frame:GetFontString()
yellowfive@57 115 f:ClearAllPoints()
yellowfive@57 116
yellowfive@57 117 if not top and not right and not bottom and not left then
yellowfive@57 118 f:SetPoint("CENTER")
yellowfive@57 119 end
yellowfive@57 120
yellowfive@57 121 if top then f:SetPoint("TOP", self.frame, "TOP", 0, -top) end
yellowfive@57 122 if right then f:SetPoint("RIGHT", self.frame, "RIGHT", -right, 0) end
yellowfive@57 123 if bottom then f:SetPoint("BOTTOM", self.frame, "BOTTOM", 0, bottom) end
yellowfive@57 124 if left then f:SetPoint("LEFT", self.frame, "LEFT", left, 0) end
yellowfive@57 125 end,
yellowfive@57 126
yellowfive@57 127 ["SetFont"] = function(self, font)
yellowfive@57 128 self.frame:SetNormalFontObject(font)
yellowfive@57 129 end,
yellowfive@57 130
yellowfive@57 131 ["SetHoverFont"] = function(self, font)
yellowfive@57 132 self.frame:SetHighlightFontObject(font)
yellowfive@57 133 end,
yellowfive@57 134
yellowfive@57 135 ["SetSubtext"] = function(self, text)
yellowfive@57 136 self.subtxt:SetText(text)
yellowfive@57 137 if text then
yellowfive@57 138 self.subtxt:Show()
yellowfive@57 139 else
yellowfive@57 140 self.subtxt:Hide()
yellowfive@57 141 end
yellowfive@57 142 end,
yellowfive@57 143
yellowfive@57 144 ["SetSubtextWordWrap"] = function(self, enable)
yellowfive@57 145 self.subtxt:SetWordWrap(enable)
yellowfive@57 146 end,
yellowfive@57 147
yellowfive@57 148 ["SetSubtextJustifyH"] = function(self, val)
yellowfive@57 149 self.subtxt:SetJustifyH(val)
yellowfive@57 150 end,
yellowfive@57 151
yellowfive@57 152 ["SetSubtextJustifyV"] = function(self, val)
yellowfive@57 153 self.subtxt:SetJustifyV(val)
yellowfive@57 154 end,
yellowfive@57 155
yellowfive@57 156 ["SetSubtextPadding"] = function(self, top, right, bottom, left)
yellowfive@57 157 local f = self.subtxt
yellowfive@57 158 f:ClearAllPoints()
yellowfive@57 159 if top then f:SetPoint("TOP", self.frame, "TOP", 0, -top) end
yellowfive@57 160 if right then f:SetPoint("RIGHT", self.frame, "RIGHT", -right, 0) end
yellowfive@57 161 if bottom then f:SetPoint("BOTTOM", self.frame, "BOTTOM", 0, bottom) end
yellowfive@57 162 if left then f:SetPoint("LEFT", self.frame, "LEFT", left, 0) end
yellowfive@57 163 end,
yellowfive@57 164
yellowfive@57 165 ["SetSubtextFont"] = function(self, font)
yellowfive@57 166 self.subtxt:SetFontObject(font)
yellowfive@57 167 end,
yellowfive@57 168
yellowfive@57 169 ["SetDisabled"] = function(self, disabled)
yellowfive@57 170 self.disabled = disabled
yellowfive@57 171 if disabled then
yellowfive@57 172 self.frame:Disable()
yellowfive@57 173 else
yellowfive@57 174 self.frame:Enable()
yellowfive@57 175 end
yellowfive@57 176 end,
yellowfive@57 177
yellowfive@57 178 ["SetVisible"] = function(self, visible)
yellowfive@57 179 if visible then
yellowfive@57 180 self.frame:Show()
yellowfive@57 181 else
yellowfive@57 182 self.frame:Hide()
yellowfive@57 183 end
yellowfive@57 184 end
yellowfive@57 185 }
yellowfive@57 186
yellowfive@57 187 --[[-----------------------------------------------------------------------------
yellowfive@57 188 Constructor
yellowfive@57 189 -------------------------------------------------------------------------------]]
yellowfive@57 190 local function Constructor()
yellowfive@57 191 local name = "AmrUiTextButton" .. AceGUI:GetNextWidgetNum(Type)
yellowfive@57 192 local frame = CreateFrame("Button", name, UIParent)
yellowfive@57 193 frame:Hide()
yellowfive@57 194
yellowfive@57 195 local txt = frame:CreateFontString()
yellowfive@57 196 frame:SetFontString(txt)
yellowfive@57 197
yellowfive@57 198 local subtxt = frame:CreateFontString()
yellowfive@57 199 subtxt:Hide()
yellowfive@57 200
yellowfive@57 201 frame:EnableMouse(true)
yellowfive@57 202 frame:SetScript("OnEnter", buttonOnEnter)
yellowfive@57 203 frame:SetScript("OnLeave", buttonOnLeave)
yellowfive@57 204 frame:SetScript("OnClick", buttonOnClick)
yellowfive@57 205
yellowfive@57 206 local bg = frame:CreateTexture()
yellowfive@57 207 bg:SetAllPoints()
yellowfive@57 208
yellowfive@57 209 local hover = frame:CreateTexture()
yellowfive@57 210 hover:SetAllPoints()
yellowfive@57 211
yellowfive@57 212 local widget = {
yellowfive@57 213 bg = bg,
yellowfive@57 214 subtxt = subtxt,
yellowfive@57 215 hover = hover,
yellowfive@57 216 frame = frame,
yellowfive@57 217 type = Type
yellowfive@57 218 }
yellowfive@57 219 for method, func in pairs(methods) do
yellowfive@57 220 widget[method] = func
yellowfive@57 221 end
yellowfive@57 222
yellowfive@57 223 return AceGUI:RegisterAsWidget(widget)
yellowfive@57 224 end
yellowfive@57 225
yellowfive@57 226 AceGUI:RegisterWidgetType(Type, Constructor, Version)