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@57
|
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@57
|
46 ["SetText"] = function(self, text)
|
yellowfive@57
|
47 self.label:SetText(text)
|
yellowfive@57
|
48 self.frame:SetWidth(16 + 6 + self.label:GetStringWidth())
|
yellowfive@57
|
49 end,
|
yellowfive@57
|
50
|
yellowfive@57
|
51 ["SetFont"] = function(self, font)
|
yellowfive@57
|
52 self.label:SetFontObject(font)
|
yellowfive@57
|
53 end,
|
yellowfive@57
|
54
|
yellowfive@57
|
55 ["SetChecked"] = function(self, checked)
|
yellowfive@124
|
56 self.isChecked = not not checked
|
yellowfive@124
|
57 if checked then
|
yellowfive@124
|
58 self.texNormal:Hide()
|
yellowfive@124
|
59 self.texCheck:Show()
|
yellowfive@124
|
60 else
|
yellowfive@124
|
61 self.texCheck:Hide()
|
yellowfive@124
|
62 self.texNormal:Show()
|
yellowfive@124
|
63 end
|
yellowfive@57
|
64 end,
|
yellowfive@57
|
65
|
yellowfive@124
|
66 ["GetChecked"] = function(self)
|
yellowfive@124
|
67 return self.isChecked
|
yellowfive@57
|
68 end,
|
yellowfive@57
|
69
|
yellowfive@57
|
70 ["GetWidth"] = function(self)
|
yellowfive@57
|
71 return self.frame:GetWidth()
|
yellowfive@57
|
72 end,
|
yellowfive@57
|
73
|
yellowfive@57
|
74 ["SetDisabled"] = function(self, disabled)
|
yellowfive@57
|
75 self.disabled = disabled
|
yellowfive@57
|
76 if disabled then
|
yellowfive@57
|
77 self.frame:Disable()
|
yellowfive@57
|
78 else
|
yellowfive@57
|
79 self.frame:Enable()
|
yellowfive@57
|
80 end
|
yellowfive@57
|
81 end,
|
yellowfive@57
|
82
|
yellowfive@57
|
83 ["SetVisible"] = function(self, visible)
|
yellowfive@57
|
84 if visible then
|
yellowfive@57
|
85 self.frame:Show()
|
yellowfive@57
|
86 else
|
yellowfive@57
|
87 self.frame:Hide()
|
yellowfive@57
|
88 end
|
yellowfive@57
|
89 end
|
yellowfive@57
|
90 }
|
yellowfive@57
|
91
|
yellowfive@57
|
92 --[[-----------------------------------------------------------------------------
|
yellowfive@57
|
93 Constructor
|
yellowfive@57
|
94 -------------------------------------------------------------------------------]]
|
yellowfive@57
|
95 local function Constructor()
|
yellowfive@57
|
96 local name = "AmrUiCheckBox" .. AceGUI:GetNextWidgetNum(Type)
|
yellowfive@124
|
97 local frame = CreateFrame("Button", nil, UIParent)
|
yellowfive@57
|
98 frame:SetHeight(16)
|
yellowfive@57
|
99 frame:SetPushedTextOffset(0, 0)
|
yellowfive@57
|
100 frame:Hide()
|
yellowfive@57
|
101
|
yellowfive@57
|
102 frame:EnableMouse(true)
|
yellowfive@57
|
103 frame:SetScript("OnClick", buttonOnClick)
|
yellowfive@57
|
104
|
yellowfive@57
|
105 -- unchecked texture
|
yellowfive@57
|
106 local texNormal = frame:CreateTexture(nil, "BACKGROUND")
|
yellowfive@124
|
107 texNormal.name = name
|
yellowfive@57
|
108 texNormal:SetWidth(16)
|
yellowfive@57
|
109 texNormal:SetHeight(16)
|
yellowfive@57
|
110 texNormal:SetTexture("Interface\\AddOns\\" .. Amr.ADDON_NAME .. "\\Media\\check-off")
|
yellowfive@57
|
111 texNormal:SetPoint("LEFT", frame, "LEFT")
|
yellowfive@57
|
112
|
yellowfive@57
|
113 -- checked texture
|
yellowfive@124
|
114 local texCheck = frame:CreateTexture(nil, "BACKGROUND")
|
yellowfive@124
|
115 texCheck.name = name
|
yellowfive@124
|
116 texCheck:SetWidth(16)
|
yellowfive@124
|
117 texCheck:SetHeight(16)
|
yellowfive@57
|
118 texCheck:SetTexture("Interface\\AddOns\\" .. Amr.ADDON_NAME .. "\\Media\\check-on")
|
yellowfive@57
|
119 texCheck:SetPoint("LEFT", frame, "LEFT")
|
yellowfive@124
|
120 texCheck:Hide()
|
yellowfive@57
|
121
|
yellowfive@57
|
122 -- label
|
yellowfive@124
|
123 local lbl = frame:CreateFontString(nil, "BACKGROUND")
|
yellowfive@57
|
124 lbl:SetJustifyV("MIDDLE")
|
yellowfive@57
|
125 lbl:SetPoint("LEFT", texNormal, "RIGHT", 8, 0)
|
yellowfive@57
|
126
|
yellowfive@57
|
127 local widget = {
|
yellowfive@57
|
128 texNormal = texNormal,
|
yellowfive@124
|
129 texCheck = texCheck,
|
yellowfive@57
|
130 label = lbl,
|
yellowfive@57
|
131 frame = frame,
|
yellowfive@124
|
132 type = Type,
|
yellowfive@124
|
133 isChecked = false,
|
yellowfive@124
|
134 name = name
|
yellowfive@57
|
135 }
|
yellowfive@57
|
136 for method, func in pairs(methods) do
|
yellowfive@57
|
137 widget[method] = func
|
yellowfive@57
|
138 end
|
yellowfive@57
|
139
|
yellowfive@57
|
140 return AceGUI:RegisterAsWidget(widget)
|
yellowfive@57
|
141 end
|
yellowfive@57
|
142
|
yellowfive@57
|
143 AceGUI:RegisterWidgetType(Type, Constructor, Version)
|