Mercurial > wow > itemauditor
comparison Libs/AceGUI-3.0/widgets/AceGUIWidget-Keybinding.lua @ 0:169f5211fc7f
First public revision.
At this point ItemAuditor watches mail for auctions sold or purchased, watches for buy/sell (money and 1 item type change) and conversions/tradeskills. Milling isn't working yet because there is too much time between the first event and the last event.
author | Asa Ayers <Asa.Ayers@Gmail.com> |
---|---|
date | Thu, 20 May 2010 19:22:19 -0700 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:169f5211fc7f |
---|---|
1 local AceGUI = LibStub("AceGUI-3.0") | |
2 | |
3 -- Lua APIs | |
4 | |
5 -- WoW APIs | |
6 local IsShiftKeyDown, IsControlKeyDown, IsAltKeyDown = IsShiftKeyDown, IsControlKeyDown, IsAltKeyDown | |
7 local CreateFrame, UIParent = CreateFrame, UIParent | |
8 | |
9 -- Global vars/functions that we don't upvalue since they might get hooked, or upgraded | |
10 -- List them here for Mikk's FindGlobals script | |
11 -- GLOBALS: NOT_BOUND | |
12 | |
13 -------------------------- | |
14 -- Keybinding -- | |
15 -------------------------- | |
16 | |
17 do | |
18 local Type = "Keybinding" | |
19 local Version = 13 | |
20 | |
21 local ControlBackdrop = { | |
22 bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", | |
23 edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", | |
24 tile = true, tileSize = 16, edgeSize = 16, | |
25 insets = { left = 3, right = 3, top = 3, bottom = 3 } | |
26 } | |
27 | |
28 local function Control_OnEnter(this) | |
29 this.obj:Fire("OnEnter") | |
30 end | |
31 | |
32 local function Control_OnLeave(this) | |
33 this.obj:Fire("OnLeave") | |
34 end | |
35 | |
36 local function keybindingMsgFixWidth(this) | |
37 this:SetWidth(this.msg:GetWidth()+10) | |
38 this:SetScript("OnUpdate",nil) | |
39 end | |
40 | |
41 local function Keybinding_OnClick(this, button) | |
42 if button == "LeftButton" or button == "RightButton" then | |
43 local self = this.obj | |
44 if self.waitingForKey then | |
45 this:EnableKeyboard(false) | |
46 self.msgframe:Hide() | |
47 this:UnlockHighlight() | |
48 self.waitingForKey = nil | |
49 else | |
50 this:EnableKeyboard(true) | |
51 self.msgframe:Show() | |
52 this:LockHighlight() | |
53 self.waitingForKey = true | |
54 end | |
55 end | |
56 AceGUI:ClearFocus() | |
57 end | |
58 | |
59 local ignoreKeys = nil | |
60 local function Keybinding_OnKeyDown(this, key) | |
61 local self = this.obj | |
62 if self.waitingForKey then | |
63 local keyPressed = key | |
64 if keyPressed == "ESCAPE" then | |
65 keyPressed = "" | |
66 else | |
67 if not ignoreKeys then | |
68 ignoreKeys = { | |
69 ["BUTTON1"] = true, ["BUTTON2"] = true, | |
70 ["UNKNOWN"] = true, | |
71 ["LSHIFT"] = true, ["LCTRL"] = true, ["LALT"] = true, | |
72 ["RSHIFT"] = true, ["RCTRL"] = true, ["RALT"] = true, | |
73 } | |
74 end | |
75 if ignoreKeys[keyPressed] then return end | |
76 if IsShiftKeyDown() then | |
77 keyPressed = "SHIFT-"..keyPressed | |
78 end | |
79 if IsControlKeyDown() then | |
80 keyPressed = "CTRL-"..keyPressed | |
81 end | |
82 if IsAltKeyDown() then | |
83 keyPressed = "ALT-"..keyPressed | |
84 end | |
85 end | |
86 | |
87 this:EnableKeyboard(false) | |
88 self.msgframe:Hide() | |
89 this:UnlockHighlight() | |
90 self.waitingForKey = nil | |
91 | |
92 if not self.disabled then | |
93 self:SetKey(keyPressed) | |
94 self:Fire("OnKeyChanged",keyPressed) | |
95 end | |
96 end | |
97 end | |
98 | |
99 local function Keybinding_OnMouseDown(this, button) | |
100 if button == "LeftButton" or button == "RightButton" then | |
101 return | |
102 elseif button == "MiddleButton" then | |
103 button = "BUTTON3" | |
104 elseif button == "Button4" then | |
105 button = "BUTTON4" | |
106 elseif button == "Button5" then | |
107 button = "BUTTON5" | |
108 end | |
109 Keybinding_OnKeyDown(this, button) | |
110 end | |
111 | |
112 local function OnAcquire(self) | |
113 self:SetWidth(200) | |
114 self:SetHeight(44) | |
115 self:SetLabel("") | |
116 self:SetKey("") | |
117 end | |
118 | |
119 local function OnRelease(self) | |
120 self.frame:ClearAllPoints() | |
121 self.frame:Hide() | |
122 self.waitingForKey = nil | |
123 self.msgframe:Hide() | |
124 self:SetDisabled(false) | |
125 end | |
126 | |
127 local function SetDisabled(self, disabled) | |
128 self.disabled = disabled | |
129 if disabled then | |
130 self.button:Disable() | |
131 self.label:SetTextColor(0.5,0.5,0.5) | |
132 else | |
133 self.button:Enable() | |
134 self.label:SetTextColor(1,1,1) | |
135 end | |
136 end | |
137 | |
138 local function SetKey(self, key) | |
139 if (key or "") == "" then | |
140 self.button:SetText(NOT_BOUND) | |
141 self.button:SetNormalFontObject("GameFontNormal") | |
142 else | |
143 self.button:SetText(key) | |
144 self.button:SetNormalFontObject("GameFontHighlight") | |
145 end | |
146 end | |
147 | |
148 local function SetLabel(self, label) | |
149 self.label:SetText(label or "") | |
150 if (label or "") == "" then | |
151 self.alignoffset = nil | |
152 self:SetHeight(24) | |
153 else | |
154 self.alignoffset = 30 | |
155 self:SetHeight(44) | |
156 end | |
157 end | |
158 | |
159 local function Constructor() | |
160 local num = AceGUI:GetNextWidgetNum(Type) | |
161 local frame = CreateFrame("Frame",nil,UIParent) | |
162 | |
163 local button = CreateFrame("Button","AceGUI-3.0 KeybindingButton"..num,frame,"UIPanelButtonTemplate2") | |
164 | |
165 local self = {} | |
166 self.type = Type | |
167 self.num = num | |
168 | |
169 local text = button:GetFontString() | |
170 text:SetPoint("LEFT",button,"LEFT",7,0) | |
171 text:SetPoint("RIGHT",button,"RIGHT",-7,0) | |
172 | |
173 button:SetScript("OnClick",Keybinding_OnClick) | |
174 button:SetScript("OnKeyDown",Keybinding_OnKeyDown) | |
175 button:SetScript("OnEnter",Control_OnEnter) | |
176 button:SetScript("OnLeave",Control_OnLeave) | |
177 button:SetScript("OnMouseDown",Keybinding_OnMouseDown) | |
178 button:RegisterForClicks("AnyDown") | |
179 button:EnableMouse() | |
180 | |
181 button:SetHeight(24) | |
182 button:SetWidth(200) | |
183 button:SetPoint("BOTTOMLEFT", frame, "BOTTOMLEFT",0,0) | |
184 button:SetPoint("BOTTOMRIGHT",frame,"BOTTOMRIGHT",0,0) | |
185 | |
186 frame:SetWidth(200) | |
187 frame:SetHeight(44) | |
188 | |
189 self.alignoffset = 30 | |
190 | |
191 self.button = button | |
192 | |
193 local label = frame:CreateFontString(nil,"OVERLAY","GameFontHighlight") | |
194 label:SetPoint("TOPLEFT",frame,"TOPLEFT",0,0) | |
195 label:SetPoint("TOPRIGHT",frame,"TOPRIGHT",0,0) | |
196 label:SetJustifyH("CENTER") | |
197 label:SetHeight(18) | |
198 self.label = label | |
199 | |
200 local msgframe = CreateFrame("Frame",nil,UIParent) | |
201 msgframe:SetHeight(30) | |
202 msgframe:SetBackdrop(ControlBackdrop) | |
203 msgframe:SetBackdropColor(0,0,0) | |
204 msgframe:SetFrameStrata("FULLSCREEN_DIALOG") | |
205 msgframe:SetFrameLevel(1000) | |
206 self.msgframe = msgframe | |
207 local msg = msgframe:CreateFontString(nil,"OVERLAY","GameFontNormal") | |
208 msg:SetText("Press a key to bind, ESC to clear the binding or click the button again to cancel") | |
209 msgframe.msg = msg | |
210 msg:SetPoint("TOPLEFT",msgframe,"TOPLEFT",5,-5) | |
211 msgframe:SetScript("OnUpdate", keybindingMsgFixWidth) | |
212 msgframe:SetPoint("BOTTOM",button,"TOP",0,0) | |
213 msgframe:Hide() | |
214 | |
215 self.OnRelease = OnRelease | |
216 self.OnAcquire = OnAcquire | |
217 self.SetLabel = SetLabel | |
218 self.SetDisabled = SetDisabled | |
219 self.SetKey = SetKey | |
220 | |
221 self.frame = frame | |
222 frame.obj = self | |
223 button.obj = self | |
224 | |
225 AceGUI:RegisterAsWidget(self) | |
226 return self | |
227 end | |
228 | |
229 AceGUI:RegisterWidgetType(Type,Constructor,Version) | |
230 end |