Mercurial > wow > askmrrobot
comparison ui/AmrUiCheckBox.lua @ 124:e31b02b24488
Updated for 8.0 pre-patch and BfA.
author | yellowfive |
---|---|
date | Tue, 17 Jul 2018 09:57:39 -0700 |
parents | 57c6cac5143c |
children | a0894ffebd15 |
comparison
equal
deleted
inserted
replaced
123:7a6364917f86 | 124:e31b02b24488 |
---|---|
18 --[[----------------------------------------------------------------------------- | 18 --[[----------------------------------------------------------------------------- |
19 Scripts | 19 Scripts |
20 -------------------------------------------------------------------------------]] | 20 -------------------------------------------------------------------------------]] |
21 local function buttonOnClick(frame, ...) | 21 local function buttonOnClick(frame, ...) |
22 AceGUI:ClearFocus() | 22 AceGUI:ClearFocus() |
23 frame.obj:SetChecked(not frame.obj.isChecked) | |
24 | |
23 --PlaySound("igMainMenuOption") | 25 --PlaySound("igMainMenuOption") |
24 frame.obj:Fire("OnClick", ...) | 26 frame.obj:Fire("OnClick", ...) |
25 end | 27 end |
26 | 28 |
27 --[[----------------------------------------------------------------------------- | 29 --[[----------------------------------------------------------------------------- |
35 self:SetText() | 37 self:SetText() |
36 self:SetChecked(false) | 38 self:SetChecked(false) |
37 self.frame:ClearAllPoints() | 39 self.frame:ClearAllPoints() |
38 end, | 40 end, |
39 | 41 |
42 --["OnRelease"] = function(self) | |
43 -- print(self.name .. " released") | |
44 --end, | |
45 | |
40 ["SetText"] = function(self, text) | 46 ["SetText"] = function(self, text) |
41 self.label:SetText(text) | 47 self.label:SetText(text) |
42 self.frame:SetWidth(16 + 6 + self.label:GetStringWidth()) | 48 self.frame:SetWidth(16 + 6 + self.label:GetStringWidth()) |
43 end, | 49 end, |
44 | 50 |
45 ["SetFont"] = function(self, font) | 51 ["SetFont"] = function(self, font) |
46 self.label:SetFontObject(font) | 52 self.label:SetFontObject(font) |
47 end, | 53 end, |
48 | 54 |
49 ["SetChecked"] = function(self, checked) | 55 ["SetChecked"] = function(self, checked) |
50 -- not sure if WoW expects boolean type or not, too lazy to find out so just cast it | 56 self.isChecked = not not checked |
51 self.frame:SetChecked(not not checked) | 57 if checked then |
58 self.texNormal:Hide() | |
59 self.texCheck:Show() | |
60 else | |
61 self.texCheck:Hide() | |
62 self.texNormal:Show() | |
63 end | |
52 end, | 64 end, |
53 | 65 |
54 ["GetChecked"] = function(self) | 66 ["GetChecked"] = function(self) |
55 return self.frame:GetChecked() | 67 return self.isChecked |
56 end, | 68 end, |
57 | 69 |
58 ["GetWidth"] = function(self) | 70 ["GetWidth"] = function(self) |
59 return self.frame:GetWidth() | 71 return self.frame:GetWidth() |
60 end, | 72 end, |
80 --[[----------------------------------------------------------------------------- | 92 --[[----------------------------------------------------------------------------- |
81 Constructor | 93 Constructor |
82 -------------------------------------------------------------------------------]] | 94 -------------------------------------------------------------------------------]] |
83 local function Constructor() | 95 local function Constructor() |
84 local name = "AmrUiCheckBox" .. AceGUI:GetNextWidgetNum(Type) | 96 local name = "AmrUiCheckBox" .. AceGUI:GetNextWidgetNum(Type) |
85 local frame = CreateFrame("CheckButton", name, UIParent) | 97 local frame = CreateFrame("Button", nil, UIParent) |
86 frame:SetHeight(16) | 98 frame:SetHeight(16) |
87 frame:SetPushedTextOffset(0, 0) | 99 frame:SetPushedTextOffset(0, 0) |
88 frame:Hide() | 100 frame:Hide() |
89 | 101 |
90 frame:EnableMouse(true) | 102 frame:EnableMouse(true) |
91 frame:SetScript("OnClick", buttonOnClick) | 103 frame:SetScript("OnClick", buttonOnClick) |
92 | 104 |
93 -- unchecked texture | 105 -- unchecked texture |
94 local texNormal = frame:CreateTexture(nil, "BACKGROUND") | 106 local texNormal = frame:CreateTexture(nil, "BACKGROUND") |
107 texNormal.name = name | |
95 texNormal:SetWidth(16) | 108 texNormal:SetWidth(16) |
96 texNormal:SetHeight(16) | 109 texNormal:SetHeight(16) |
97 texNormal:SetTexture("Interface\\AddOns\\" .. Amr.ADDON_NAME .. "\\Media\\check-off") | 110 texNormal:SetTexture("Interface\\AddOns\\" .. Amr.ADDON_NAME .. "\\Media\\check-off") |
98 texNormal:SetPoint("LEFT", frame, "LEFT") | 111 texNormal:SetPoint("LEFT", frame, "LEFT") |
99 frame:SetNormalTexture(texNormal) | |
100 | 112 |
101 -- checked texture | 113 -- checked texture |
102 local texCheck = frame:CreateTexture(nil, "BORDER") | 114 local texCheck = frame:CreateTexture(nil, "BACKGROUND") |
115 texCheck.name = name | |
116 texCheck:SetWidth(16) | |
117 texCheck:SetHeight(16) | |
103 texCheck:SetTexture("Interface\\AddOns\\" .. Amr.ADDON_NAME .. "\\Media\\check-on") | 118 texCheck:SetTexture("Interface\\AddOns\\" .. Amr.ADDON_NAME .. "\\Media\\check-on") |
104 texCheck:SetPoint("LEFT", frame, "LEFT") | 119 texCheck:SetPoint("LEFT", frame, "LEFT") |
105 frame:SetCheckedTexture(texCheck) | 120 texCheck:Hide() |
106 | 121 |
107 -- label | 122 -- label |
108 local lbl = frame:CreateFontString(nil, "ARTWORK") | 123 local lbl = frame:CreateFontString(nil, "BACKGROUND") |
109 lbl:SetJustifyV("MIDDLE") | 124 lbl:SetJustifyV("MIDDLE") |
110 lbl:SetPoint("LEFT", texNormal, "RIGHT", 8, 0) | 125 lbl:SetPoint("LEFT", texNormal, "RIGHT", 8, 0) |
111 frame:SetFontString(lbl) | |
112 | 126 |
113 local widget = { | 127 local widget = { |
114 texNormal = texNormal, | 128 texNormal = texNormal, |
129 texCheck = texCheck, | |
115 label = lbl, | 130 label = lbl, |
116 frame = frame, | 131 frame = frame, |
117 type = Type | 132 type = Type, |
133 isChecked = false, | |
134 name = name | |
118 } | 135 } |
119 for method, func in pairs(methods) do | 136 for method, func in pairs(methods) do |
120 widget[method] = func | 137 widget[method] = func |
121 end | 138 end |
122 | 139 |