comparison Libs/AceGUI-3.0/widgets/AceGUIWidget-Keybinding.lua @ 106:e635cd648e01 v49

7.2 update
author yellowfive
date Tue, 28 Mar 2017 16:10:00 -0700
parents 01b63b8ed811
children
comparison
equal deleted inserted replaced
105:3ce266c86bd3 106:e635cd648e01
1 --[[----------------------------------------------------------------------------- 1 --[[-----------------------------------------------------------------------------
2 Keybinding Widget 2 Keybinding Widget
3 Set Keybindings in the Config UI. 3 Set Keybindings in the Config UI.
4 -------------------------------------------------------------------------------]] 4 -------------------------------------------------------------------------------]]
5 local Type, Version = "Keybinding", 24 5 local Type, Version = "Keybinding", 25
6 local AceGUI = LibStub and LibStub("AceGUI-3.0", true) 6 local AceGUI = LibStub and LibStub("AceGUI-3.0", true)
7 if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end 7 if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end
8 8
9 -- Lua APIs 9 -- Lua APIs
10 local pairs = pairs 10 local pairs = pairs
14 local CreateFrame, UIParent = CreateFrame, UIParent 14 local CreateFrame, UIParent = CreateFrame, UIParent
15 15
16 -- Global vars/functions that we don't upvalue since they might get hooked, or upgraded 16 -- Global vars/functions that we don't upvalue since they might get hooked, or upgraded
17 -- List them here for Mikk's FindGlobals script 17 -- List them here for Mikk's FindGlobals script
18 -- GLOBALS: NOT_BOUND 18 -- GLOBALS: NOT_BOUND
19
20 local wowMoP
21 do
22 local _, _, _, interface = GetBuildInfo()
23 wowMoP = (interface >= 50000)
24 end
25 19
26 --[[----------------------------------------------------------------------------- 20 --[[-----------------------------------------------------------------------------
27 Scripts 21 Scripts
28 -------------------------------------------------------------------------------]] 22 -------------------------------------------------------------------------------]]
29 23
38 local function Keybinding_OnClick(frame, button) 32 local function Keybinding_OnClick(frame, button)
39 if button == "LeftButton" or button == "RightButton" then 33 if button == "LeftButton" or button == "RightButton" then
40 local self = frame.obj 34 local self = frame.obj
41 if self.waitingForKey then 35 if self.waitingForKey then
42 frame:EnableKeyboard(false) 36 frame:EnableKeyboard(false)
37 frame:EnableMouseWheel(false)
43 self.msgframe:Hide() 38 self.msgframe:Hide()
44 frame:UnlockHighlight() 39 frame:UnlockHighlight()
45 self.waitingForKey = nil 40 self.waitingForKey = nil
46 else 41 else
47 frame:EnableKeyboard(true) 42 frame:EnableKeyboard(true)
43 frame:EnableMouseWheel(true)
48 self.msgframe:Show() 44 self.msgframe:Show()
49 frame:LockHighlight() 45 frame:LockHighlight()
50 self.waitingForKey = true 46 self.waitingForKey = true
51 end 47 end
52 end 48 end
77 keyPressed = "ALT-"..keyPressed 73 keyPressed = "ALT-"..keyPressed
78 end 74 end
79 end 75 end
80 76
81 frame:EnableKeyboard(false) 77 frame:EnableKeyboard(false)
78 frame:EnableMouseWheel(false)
82 self.msgframe:Hide() 79 self.msgframe:Hide()
83 frame:UnlockHighlight() 80 frame:UnlockHighlight()
84 self.waitingForKey = nil 81 self.waitingForKey = nil
85 82
86 if not self.disabled then 83 if not self.disabled then
101 button = "BUTTON5" 98 button = "BUTTON5"
102 end 99 end
103 Keybinding_OnKeyDown(frame, button) 100 Keybinding_OnKeyDown(frame, button)
104 end 101 end
105 102
103 local function Keybinding_OnMouseWheel(frame, direction)
104 local button
105 if direction >= 0 then
106 button = "MOUSEWHEELUP"
107 else
108 button = "MOUSEWHEELDOWN"
109 end
110 Keybinding_OnKeyDown(frame, button)
111 end
112
106 --[[----------------------------------------------------------------------------- 113 --[[-----------------------------------------------------------------------------
107 Methods 114 Methods
108 -------------------------------------------------------------------------------]] 115 -------------------------------------------------------------------------------]]
109 local methods = { 116 local methods = {
110 ["OnAcquire"] = function(self) 117 ["OnAcquire"] = function(self)
113 self:SetKey("") 120 self:SetKey("")
114 self.waitingForKey = nil 121 self.waitingForKey = nil
115 self.msgframe:Hide() 122 self.msgframe:Hide()
116 self:SetDisabled(false) 123 self:SetDisabled(false)
117 self.button:EnableKeyboard(false) 124 self.button:EnableKeyboard(false)
125 self.button:EnableMouseWheel(false)
118 end, 126 end,
119 127
120 -- ["OnRelease"] = nil, 128 -- ["OnRelease"] = nil,
121 129
122 ["SetDisabled"] = function(self, disabled) 130 ["SetDisabled"] = function(self, disabled)
178 186
179 local function Constructor() 187 local function Constructor()
180 local name = "AceGUI30KeybindingButton" .. AceGUI:GetNextWidgetNum(Type) 188 local name = "AceGUI30KeybindingButton" .. AceGUI:GetNextWidgetNum(Type)
181 189
182 local frame = CreateFrame("Frame", nil, UIParent) 190 local frame = CreateFrame("Frame", nil, UIParent)
183 local button = CreateFrame("Button", name, frame, wowMoP and "UIPanelButtonTemplate" or "UIPanelButtonTemplate2") 191 local button = CreateFrame("Button", name, frame, "UIPanelButtonTemplate")
184 192
185 button:EnableMouse(true) 193 button:EnableMouse(true)
194 button:EnableMouseWheel(false)
186 button:RegisterForClicks("AnyDown") 195 button:RegisterForClicks("AnyDown")
187 button:SetScript("OnEnter", Control_OnEnter) 196 button:SetScript("OnEnter", Control_OnEnter)
188 button:SetScript("OnLeave", Control_OnLeave) 197 button:SetScript("OnLeave", Control_OnLeave)
189 button:SetScript("OnClick", Keybinding_OnClick) 198 button:SetScript("OnClick", Keybinding_OnClick)
190 button:SetScript("OnKeyDown", Keybinding_OnKeyDown) 199 button:SetScript("OnKeyDown", Keybinding_OnKeyDown)
191 button:SetScript("OnMouseDown", Keybinding_OnMouseDown) 200 button:SetScript("OnMouseDown", Keybinding_OnMouseDown)
201 button:SetScript("OnMouseWheel", Keybinding_OnMouseWheel)
192 button:SetPoint("BOTTOMLEFT") 202 button:SetPoint("BOTTOMLEFT")
193 button:SetPoint("BOTTOMRIGHT") 203 button:SetPoint("BOTTOMRIGHT")
194 button:SetHeight(24) 204 button:SetHeight(24)
195 button:EnableKeyboard(false) 205 button:EnableKeyboard(false)
196 206