yellowfive@57
|
1 --[[-----------------------------------------------------------------------------
|
yellowfive@57
|
2 CheckBox Widget
|
yellowfive@57
|
3 -------------------------------------------------------------------------------]]
|
yellowfive@57
|
4 local Type, Version = "AmrUiCheckBox", 1
|
yellowfive@57
|
5 local AceGUI = LibStub and LibStub("AceGUI-3.0", true)
|
yellowfive@57
|
6 if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end
|
yellowfive@57
|
7
|
yellowfive@57
|
8 local Amr = LibStub("AceAddon-3.0"):GetAddon("AskMrRobot")
|
yellowfive@57
|
9
|
yellowfive@57
|
10 -- Lua APIs
|
yellowfive@57
|
11 local pairs = pairs
|
yellowfive@57
|
12
|
yellowfive@57
|
13 -- WoW APIs
|
yellowfive@57
|
14 local _G = _G
|
yellowfive@133
|
15 local CreateFrame, UIParent = CreateFrame, UIParent
|
yellowfive@57
|
16
|
yellowfive@57
|
17
|
yellowfive@57
|
18 --[[-----------------------------------------------------------------------------
|
yellowfive@57
|
19 Scripts
|
yellowfive@57
|
20 -------------------------------------------------------------------------------]]
|
yellowfive@57
|
21 local function buttonOnClick(frame, ...)
|
yellowfive@57
|
22 AceGUI:ClearFocus()
|
yellowfive@124
|
23 frame.obj:SetChecked(not frame.obj.isChecked)
|
yellowfive@124
|
24
|
yellowfive@112
|
25 --PlaySound("igMainMenuOption")
|
yellowfive@57
|
26 frame.obj:Fire("OnClick", ...)
|
yellowfive@57
|
27 end
|
yellowfive@57
|
28
|
yellowfive@57
|
29 --[[-----------------------------------------------------------------------------
|
yellowfive@57
|
30 Methods
|
yellowfive@57
|
31 -------------------------------------------------------------------------------]]
|
yellowfive@57
|
32 local methods = {
|
yellowfive@57
|
33 ["OnAcquire"] = function(self)
|
yellowfive@57
|
34 -- restore default values
|
yellowfive@57
|
35 self:SetDisabled(false)
|
yellowfive@57
|
36 self:SetFont(Amr.CreateFont("Regular", 14, Amr.Colors.Text))
|
yellowfive@189
|
37 self:SetText("")
|
yellowfive@57
|
38 self:SetChecked(false)
|
yellowfive@57
|
39 self.frame:ClearAllPoints()
|
yellowfive@57
|
40 end,
|
yellowfive@57
|
41
|
yellowfive@124
|
42 --["OnRelease"] = function(self)
|
yellowfive@124
|
43 -- print(self.name .. " released")
|
yellowfive@124
|
44 --end,
|
yellowfive@124
|
45
|
yellowfive@189
|
46 ["GetText"] = function(self)
|
yellowfive@189
|
47 return self.label:GetText()
|
yellowfive@189
|
48 end,
|
yellowfive@189
|
49
|
yellowfive@57
|
50 ["SetText"] = function(self, text)
|
yellowfive@189
|
51 self.label:SetText(text or "")
|
yellowfive@57
|
52 self.frame:SetWidth(16 + 6 + self.label:GetStringWidth())
|
yellowfive@57
|
53 end,
|
yellowfive@57
|
54
|
yellowfive@57
|
55 ["SetFont"] = function(self, font)
|
yellowfive@57
|
56 self.label:SetFontObject(font)
|
yellowfive@57
|
57 end,
|
yellowfive@57
|
58
|
yellowfive@57
|
59 ["SetChecked"] = function(self, checked)
|
yellowfive@124
|
60 self.isChecked = not not checked
|
yellowfive@189
|
61 if self.isChecked then
|
yellowfive@124
|
62 self.texNormal:Hide()
|
yellowfive@124
|
63 self.texCheck:Show()
|
yellowfive@124
|
64 else
|
yellowfive@124
|
65 self.texCheck:Hide()
|
yellowfive@124
|
66 self.texNormal:Show()
|
yellowfive@124
|
67 end
|
yellowfive@57
|
68 end,
|
yellowfive@57
|
69
|
yellowfive@124
|
70 ["GetChecked"] = function(self)
|
yellowfive@124
|
71 return self.isChecked
|
yellowfive@57
|
72 end,
|
yellowfive@57
|
73
|
yellowfive@57
|
74 ["GetWidth"] = function(self)
|
yellowfive@57
|
75 return self.frame:GetWidth()
|
yellowfive@57
|
76 end,
|
yellowfive@57
|
77
|
yellowfive@57
|
78 ["SetDisabled"] = function(self, disabled)
|
yellowfive@57
|
79 self.disabled = disabled
|
yellowfive@57
|
80 if disabled then
|
yellowfive@57
|
81 self.frame:Disable()
|
yellowfive@57
|
82 else
|
yellowfive@57
|
83 self.frame:Enable()
|
yellowfive@57
|
84 end
|
yellowfive@57
|
85 end,
|
yellowfive@57
|
86
|
yellowfive@57
|
87 ["SetVisible"] = function(self, visible)
|
yellowfive@57
|
88 if visible then
|
yellowfive@57
|
89 self.frame:Show()
|
yellowfive@57
|
90 else
|
yellowfive@57
|
91 self.frame:Hide()
|
yellowfive@57
|
92 end
|
yellowfive@57
|
93 end
|
yellowfive@57
|
94 }
|
yellowfive@57
|
95
|
yellowfive@57
|
96 --[[-----------------------------------------------------------------------------
|
yellowfive@57
|
97 Constructor
|
yellowfive@57
|
98 -------------------------------------------------------------------------------]]
|
yellowfive@57
|
99 local function Constructor()
|
yellowfive@57
|
100 local name = "AmrUiCheckBox" .. AceGUI:GetNextWidgetNum(Type)
|
yellowfive@124
|
101 local frame = CreateFrame("Button", nil, UIParent)
|
yellowfive@57
|
102 frame:SetHeight(16)
|
yellowfive@57
|
103 frame:SetPushedTextOffset(0, 0)
|
yellowfive@57
|
104 frame:Hide()
|
yellowfive@57
|
105
|
yellowfive@57
|
106 frame:EnableMouse(true)
|
yellowfive@57
|
107 frame:SetScript("OnClick", buttonOnClick)
|
yellowfive@57
|
108
|
yellowfive@57
|
109 -- unchecked texture
|
yellowfive@57
|
110 local texNormal = frame:CreateTexture(nil, "BACKGROUND")
|
yellowfive@124
|
111 texNormal.name = name
|
yellowfive@57
|
112 texNormal:SetWidth(16)
|
yellowfive@57
|
113 texNormal:SetHeight(16)
|
yellowfive@57
|
114 texNormal:SetTexture("Interface\\AddOns\\" .. Amr.ADDON_NAME .. "\\Media\\check-off")
|
yellowfive@57
|
115 texNormal:SetPoint("LEFT", frame, "LEFT")
|
yellowfive@57
|
116
|
yellowfive@57
|
117 -- checked texture
|
yellowfive@124
|
118 local texCheck = frame:CreateTexture(nil, "BACKGROUND")
|
yellowfive@124
|
119 texCheck.name = name
|
yellowfive@124
|
120 texCheck:SetWidth(16)
|
yellowfive@124
|
121 texCheck:SetHeight(16)
|
yellowfive@57
|
122 texCheck:SetTexture("Interface\\AddOns\\" .. Amr.ADDON_NAME .. "\\Media\\check-on")
|
yellowfive@57
|
123 texCheck:SetPoint("LEFT", frame, "LEFT")
|
yellowfive@124
|
124 texCheck:Hide()
|
yellowfive@57
|
125
|
yellowfive@57
|
126 -- label
|
yellowfive@124
|
127 local lbl = frame:CreateFontString(nil, "BACKGROUND")
|
yellowfive@57
|
128 lbl:SetJustifyV("MIDDLE")
|
yellowfive@57
|
129 lbl:SetPoint("LEFT", texNormal, "RIGHT", 8, 0)
|
yellowfive@57
|
130
|
yellowfive@57
|
131 local widget = {
|
yellowfive@57
|
132 texNormal = texNormal,
|
yellowfive@124
|
133 texCheck = texCheck,
|
yellowfive@57
|
134 label = lbl,
|
yellowfive@57
|
135 frame = frame,
|
yellowfive@124
|
136 type = Type,
|
yellowfive@124
|
137 isChecked = false,
|
yellowfive@124
|
138 name = name
|
yellowfive@57
|
139 }
|
yellowfive@57
|
140 for method, func in pairs(methods) do
|
yellowfive@57
|
141 widget[method] = func
|
yellowfive@57
|
142 end
|
yellowfive@57
|
143
|
yellowfive@57
|
144 return AceGUI:RegisterAsWidget(widget)
|
yellowfive@57
|
145 end
|
yellowfive@57
|
146
|
yellowfive@57
|
147 AceGUI:RegisterWidgetType(Type, Constructor, Version)
|