comparison SkeletonKey/BindingsUI.lua @ 17:500f9b2bd9ac

- for RegisterAction, use a function table instead of that if/then rats nest - consequently pet bar actions work now - unlocalize bindings data - activate keyslot input manually instead of on mouse over - activate checkbox to keep input mode active - dynamic buttons update in real time for petaction/talent/profession spells
author Nenue
date Sat, 30 Jul 2016 00:08:00 -0400
parents cdd387d39137
children 91398d284a99
comparison
equal deleted inserted replaced
16:cdd387d39137 17:500f9b2bd9ac
4 -- %file-revision% 4 -- %file-revision%
5 -- Code piecing the interface together 5 -- Code piecing the interface together
6 6
7 local kb, print = LibStub("LibKraken").register(KeyBinder, 'KeySlot') 7 local kb, print = LibStub("LibKraken").register(KeyBinder, 'KeySlot')
8 local BINDS_PER_ROW = 2 8 local BINDS_PER_ROW = 2
9 local BINDING_TYPE_SPECIALIZATION = 3
10 local BINDING_TYPE_CHARACTER = 2
11 local BINDING_TYPE_GLOBAL = 1
9 local BUTTON_HSPACING = 128 12 local BUTTON_HSPACING = 128
10 local BUTTON_SPACING = 4 13 local BUTTON_SPACING = 4
11 local BUTTON_PADDING = 12 14 local BUTTON_PADDING = 12
12 local BINDING_TYPE_SPECIALIZATION = 3
13 local BINDING_TYPE_CHARACTER = 2
14 local BINDING_TYPE_GLOBAL = 1
15 local KEY_BUTTON_SIZE = 48 15 local KEY_BUTTON_SIZE = 48
16 local MIN_BIND_SLOTS = 32 16 local NUM_KEY_SLOTS = BINDS_PER_ROW * 8
17 local TAB_OFFSET = 12
18 local TAB_HEIGHT = 40 17 local TAB_HEIGHT = 40
19 local TAB_SPACING = 2
20 18
21 local BINDING_SCHEME_COLOR = { 19 local BINDING_SCHEME_COLOR = {
22 [BINDING_TYPE_GLOBAL] = {0,.125,.5,.5}, 20 [BINDING_TYPE_GLOBAL] = {0,.125,.5,.5},
23 [BINDING_TYPE_CHARACTER] = {0,0.25,0,0.5}, 21 [BINDING_TYPE_CHARACTER] = {0,0.25,0,0.5},
24 [BINDING_TYPE_SPECIALIZATION] = {.25,0,0,0.5}, 22 [BINDING_TYPE_SPECIALIZATION] = {.25,0,0,0.5},
34 [BINDING_TYPE_GLOBAL] = {0, 1, 1} 32 [BINDING_TYPE_GLOBAL] = {0, 1, 1}
35 } 33 }
36 34
37 local restingAlpha = 0.7 35 local restingAlpha = 0.7
38 local fadeTime, fadeDelay = .30, 0.15 36 local fadeTime, fadeDelay = .30, 0.15
39 local numButtons = BINDS_PER_ROW * 8
40 local saveButton 37 local saveButton
41 local KeyButton_OnKey = function(self, key) 38
42 kb.StoreBinding(self.saveTarget, key) 39 local KeyButton_OnKeyDown = function(self, key)
43 kb:SetScript('OnKeyUp', nil) 40 end
44 kb:SetScript('OnKeyDown', nil) 41 local KeyButton_OnKeyUp = function(self, key)
42 if key == 'ESCAPE' then
43 kb.DeactivateSlot(kb.saveTarget)
44 else
45
46 if key:match('[RL]SHIFT') or key:match('[RL]ALT') or key:match('[RL]CTRL') then
47 return
48 end
49 kb.SaveSlot(kb.saveTarget, key)
50
51 if not kb.stickyMode then
52 kb:SetScript('OnKeyUp', nil)
53 kb:SetScript('OnKeyDown', nil)
54 kb.saveTarget = nil
55 end
56 end
57 kb.ui()
45 end 58 end
46 59
47 local KeyButton_OnClick = function(self, click) 60 local KeyButton_OnClick = function(self, click)
48 print(self:GetName(), 'OnMouseDown', click) 61 print(self:GetName(), 'OnMouseDown', click)
49 local cursorType = GetCursorInfo() 62 local cursorType = GetCursorInfo()
50 if click == 'LeftButton' then 63 if click == 'LeftButton' then
51 if cursorType then 64 if cursorType then
52 kb.DropToSlot(self) 65 kb.DropToSlot(self)
53 else 66 else
67 if IsShiftKeyDown() then
68 kb.stickyMode = true
69 KeyBinderStickyMode:SetChecked(true)
70
71 kb.saveTarget = button
72 kb:SetScript('OnKeyUp', KeyButton_OnKeyUp)
73 kb:SetScript('OnKeyDown', KeyButton_OnKeyDown)
74 end
75
54 kb.ActivateSlot(self) 76 kb.ActivateSlot(self)
77 kb.ui()
55 end 78 end
56 elseif click == 'RightButton' then 79 elseif click == 'RightButton' then
57 kb.ReleaseSlot(self) 80 kb.ReleaseSlot(self)
58 end 81 end
59 end 82 end
117 140
118 end 141 end
119 else 142 else
120 if self.active then 143 if self.active then
121 self.active = nil 144 self.active = nil
122 self:SetScript('OnKeyDown', nil)
123 end 145 end
124 end 146 end
125 end 147 end
126 148
127 local KeyBinder_OnMouseWheel = function(self, delta) 149 local KeyBinder_OnMouseWheel = function(self, delta)
139 return 161 return
140 end 162 end
141 kb.scrollOffset = ceil(kb.scrollOffset - (delta * BINDS_PER_ROW)) 163 kb.scrollOffset = ceil(kb.scrollOffset - (delta * BINDS_PER_ROW))
142 end 164 end
143 165
166 for i = 1, #kb.buttons do
167 kb.buttons[i]:SetSize(KEY_BUTTON_SIZE,KEY_BUTTON_SIZE)
168 end
169
144 kb.ui(true) 170 kb.ui(true)
145 end 171 end
146 172
147 local KeyBinder_OnHide = function() 173 local KeyBinder_OnHide = function()
148 KeyBinderImportLog:Hide() 174 KeyBinderImportLog:Hide()
157 end 183 end
158 local SaveButton_OnClick = function() 184 local SaveButton_OnClick = function()
159 kb.ConfirmBindings() 185 kb.ConfirmBindings()
160 end 186 end
161 187
188
162 local KeyBinder_Initialize = function() 189 local KeyBinder_Initialize = function()
163 190 do
164 191 local leftSlot, upSlot
165 kb.scrollOffset = 0 192 for index = 1, NUM_KEY_SLOTS do
166 kb.tabAnchor = {'TOPLEFT', kb.profilebg, 'TOPLEFT', BUTTON_PADDING, -BUTTON_SPACING} 193
167 kb.tabGrowth = {'TOPLEFT', nil,'TOPRIGHT', BUTTON_SPACING, 0}
168 kb.tabSize = {TAB_HEIGHT, TAB_HEIGHT }
169 kb.UIPanelAnchor = {'TOPLEFT', kb.sourcesbg, 'TOPLEFT', BUTTON_PADDING, -BUTTON_SPACING}
170 kb.UIPanelGrowth = {'TOPLEFT', nil, 'BOTTOMLEFT', 0, -2 }
171 kb.UIPanelSize = {84, 32 }
172 kb.UIPanelIcon = {24, 32, 'LEFT', -12, 0}
173 kb.controlsAnchor = {'BOTTOMLEFT', kb.footer, BUTTON_PADDING, BUTTON_PADDING }
174 kb.controlsGrowth = {'BOTTOMLEFT', nil, 'BOTTOMRIGHT', BUTTON_SPACING, 0}
175
176 -- order of these is important
177 kb:tab('KeyBinderGlobalTab',
178 kb.configTitle[BINDING_TYPE_GLOBAL] .. '\n' .. kb.configDescription[BINDING_TYPE_GLOBAL], "Interface\\ICONS\\item_azereansphere", {0.15,.85,.15,.85})
179 kb:tab('KeyBinderCharacterTab',
180 kb.configHeaders[BINDING_TYPE_CHARACTER] .. '\n' .. kb.configDescription[BINDING_TYPE_CHARACTER], nil)
181 kb:tab('KeyBinderSpecTab',
182 kb.configHeaders[BINDING_TYPE_SPECIALIZATION] .. '\n' .. kb.configDescription[BINDING_TYPE_SPECIALIZATION], kb.specInfo.texture)
183 KeyBinderCharacterTab.icon:SetTexCoord(0.15,.85,.15,.85)
184
185
186
187 --portraitLayers[1] = KeyBinderCharacterTab.icon
188
189 saveButton = kb:button('KeyBinderSaveButton', 'Refresh', 'Reload current bindings and refresh panel.', SaveButton_OnClick)
190 --restoreButton = kb:button('KeyBinderRestoreButton', 'Discard', 'Revert all changes.', CancelButton_OnClick)
191 --clearButton = kb:button('KeyBinderClearButton', 'Clear Page', 'Release all buttons.', ResetButton_OnClick)
192
193 kb:uibutton(
194 'KeyBinderSpellBookButton', 'SpellBook', nil,
195 function() ToggleSpellBook(BOOKTYPE_SPELL) end,
196 "Interface\\BUTTONS\\UI-MicroButton-Spellbook-Up", {0, 1, .4, 1})
197 kb:uibutton(
198 'KeyBinderTalentFrameButton', TALENTS, SPECIALIZATION,
199 function() ToggleTalentFrame() end,
200 "Interface\\BUTTONS\\UI-MicroButton-Talents-Up", {0, 1, .4, 1})
201
202 kb:uibutton(
203 'KeyBinderMacroFrameButton', 'Macros', nil,
204 function() if MacroFrame and MacroFrame:IsVisible() then
205 HideUIPanel(MacroFrame)
206 else
207 ShowMacroFrame() end
208 end,
209 "Interface\\BUTTONS\\UI-MicroButton-Help-Up", {0, 1, .4, 1})
210
211 kb:uibutton(
212 'KeyBinderInventoryButton', 'Bags', nil,
213 function() OpenAllBags() end,
214 "Interface\\BUTTONS\\UI-MicroButtonCharacter-Up", {0, 1, .4, 1})
215
216
217
218 kb.info:SetPoint('TOPLEFT', kb.UIPanels[1], 'BOTTOMLEFT', 0, -BUTTON_SPACING)
219 HEADER_OFFSET = kb.UIPanels[1]:GetHeight() + BUTTON_PADDING
220 + kb.info:GetHeight()
221 FOOTER_OFFSET = saveButton:GetHeight() + BUTTON_PADDING
222
223 kb:SetScript('OnHide', KeyBinder_OnHide)
224 kb:SetScript('OnMouseWheel', KeyBinder_OnMouseWheel)
225 kb.CloseButton:SetScript('OnClick', CloseButton_OnClick)
226
227 end
228
229
230 --- Retrieves button at index; creates said button and instates any stored parameters
231 do
232 local leftSlot, upSlot
233 kb.GetSlot = function(index)
234
235 local slot = index + kb.scrollOffset
236
237 if not kb.buttons[index] then
238 local button = CreateFrame('CheckButton', 'KeyBinderSlot'..index, kb, 'KeyButton') 194 local button = CreateFrame('CheckButton', 'KeyBinderSlot'..index, kb, 'KeyButton')
239 button:SetScript('OnClick', KeyButton_OnClick) 195 button:SetScript('OnClick', KeyButton_OnClick)
240 button:SetScript('OnUpdate', KeyButton_OnUpdate) 196 button:SetScript('OnUpdate', KeyButton_OnUpdate)
241 button:SetScript('OnDragStart', KeyButton_OnDragStart) 197 button:SetScript('OnDragStart', KeyButton_OnDragStart)
242 button:SetScript('OnReceiveDrag', KeyButton_OnReceiveDrag) 198 button:SetScript('OnReceiveDrag', KeyButton_OnReceiveDrag)
258 button:SetSize(KEY_BUTTON_SIZE, KEY_BUTTON_SIZE) 214 button:SetSize(KEY_BUTTON_SIZE, KEY_BUTTON_SIZE)
259 button:Show() 215 button:Show()
260 kb.buttons[index] = button 216 kb.buttons[index] = button
261 leftSlot = button 217 leftSlot = button
262 end 218 end
263 return kb.buttons[index] 219 end
264 end 220
265 end 221
266 222 kb.scrollOffset = 0
267 223 kb.tabAnchor = {'TOPLEFT', kb.profilebg, 'TOPLEFT', BUTTON_PADDING, -BUTTON_SPACING}
268 kb.ActivateSlot = function(self) 224 kb.tabGrowth = {'TOPLEFT', nil,'TOPRIGHT', BUTTON_SPACING, 0}
269 kb.saveTarget = self 225 kb.tabSize = {TAB_HEIGHT, TAB_HEIGHT }
270 kb:SetScript('OnKeyUp', KeyButton_OnKey) 226 kb.UIPanelAnchor = {'TOPLEFT', kb.sourcesbg, 'TOPLEFT', BUTTON_PADDING, -BUTTON_SPACING}
271 kb.bg:SetColorTexture(0,.5,0,1) 227 kb.UIPanelGrowth = {'TOPLEFT', nil, 'BOTTOMLEFT', 0, -2 }
272 end 228 kb.UIPanelSize = {84, 32 }
229 kb.UIPanelIcon = {24, 32, 'LEFT', -12, 0}
230 kb.controlsAnchor = {'BOTTOMRIGHT', kb.footer, -BUTTON_PADDING, BUTTON_PADDING }
231 kb.controlsGrowth = {'BOTTOMRIGHT', nil, 'BOTTOMLEFT', -BUTTON_SPACING, 0}
232
233 -- order of these is important
234 kb:tab('KeyBinderGlobalTab',
235 kb.configTitle[BINDING_TYPE_GLOBAL] .. '\n' .. kb.configDescription[BINDING_TYPE_GLOBAL], "Interface\\ICONS\\item_azereansphere", {0.15,.85,.15,.85})
236 kb:tab('KeyBinderCharacterTab',
237 kb.configHeaders[BINDING_TYPE_CHARACTER] .. '\n' .. kb.configDescription[BINDING_TYPE_CHARACTER], nil)
238 kb:tab('KeyBinderSpecTab',
239 kb.configHeaders[BINDING_TYPE_SPECIALIZATION] .. '\n' .. kb.configDescription[BINDING_TYPE_SPECIALIZATION], kb.specInfo.texture)
240 KeyBinderCharacterTab.icon:SetTexCoord(0.15,.85,.15,.85)
241
242
243
244 --portraitLayers[1] = KeyBinderCharacterTab.icon
245 -- todo: find some generic icons for refresh/key input,etc
246
247 saveButton = kb:button('KeyBinderSaveButton', 'Update', 'Reload current bindings and refresh panel.', SaveButton_OnClick)
248 --restoreButton = kb:button('KeyBinderRestoreButton', 'Discard', 'Revert all changes.', CancelButton_OnClick)
249 --clearButton = kb:button('KeyBinderClearButton', 'Clear Page', 'Release all buttons.', ResetButton_OnClick)
250
251 kb:uibutton(
252 'KeyBinderSpellBookButton', 'SpellBook', nil,
253 function() ToggleSpellBook(BOOKTYPE_SPELL) end,
254 "Interface\\BUTTONS\\UI-MicroButton-Spellbook-Up", {0, 1, .4, 1})
255 kb:uibutton(
256 'KeyBinderTalentFrameButton', TALENTS, SPECIALIZATION,
257 function() ToggleTalentFrame() end,
258 "Interface\\BUTTONS\\UI-MicroButton-Talents-Up", {0, 1, .4, 1})
259
260 kb:uibutton(
261 'KeyBinderMacroFrameButton', 'Macros', nil,
262 function() if MacroFrame and MacroFrame:IsVisible() then
263 HideUIPanel(MacroFrame)
264 else
265 ShowMacroFrame() end
266 end,
267 "Interface\\BUTTONS\\UI-MicroButton-Help-Up", {0, 1, .4, 1})
268
269 kb:uibutton(
270 'KeyBinderInventoryButton', 'Bags', nil,
271 function() OpenAllBags() end,
272 "Interface\\BUTTONS\\UI-MicroButtonCharacter-Up", {0, 1, .4, 1})
273
274 KeyBinderStickyMode:SetScript('OnClick', function(self)
275
276 kb.stickyMode = self:GetChecked()
277 if not kb.stickyMode then
278 if kb.saveTarget then
279 kb.DeactivateSlot(kb.saveTarget)
280 end
281 end
282
283 kb.ui()
284 end)
285
286 kb.info:SetPoint('TOPLEFT', kb.UIPanels[1], 'BOTTOMLEFT', 0, -BUTTON_SPACING)
287 HEADER_OFFSET = kb.UIPanels[1]:GetHeight() + BUTTON_PADDING
288 + kb.info:GetHeight()
289 FOOTER_OFFSET = saveButton:GetHeight() + BUTTON_PADDING
290
291 kb:SetScript('OnHide', KeyBinder_OnHide)
292 kb:SetScript('OnMouseWheel', KeyBinder_OnMouseWheel)
293 kb.CloseButton:SetScript('OnClick', CloseButton_OnClick)
294
295 end
296
297
298 --- Retrieves button at index; creates said button and instates any stored parameters
299
300
301 kb.ActivateSlot = function(button)
302 kb.saveTarget = button
303 kb:SetScript('OnKeyUp', KeyButton_OnKeyUp)
304 kb:SetScript('OnKeyDown', KeyButton_OnKeyDown)
305 kb.savingText:ClearAllPoints()
306 kb.savingText:SetParent(button)
307 kb.savingText:SetPoint('BOTTOMLEFT', button, 'TOPLEFT', 0, 0)
308 end
309
310 kb.DeactivateSlot = function(button)
311 kb.saveTarget = nil
312 kb:SetScript('OnKeyUp', nil)
313 kb:SetScript('OnKeyDown', nil)
314 end
315
273 316
274 --- push current information into living UI 317 --- push current information into living UI
275 kb.ui = function(force) 318 kb.ui = function(force)
276 for i, module in ipairs(kb.modules) do 319 for i, module in ipairs(kb.modules) do
277 if module.ui then 320 if module.ui then
285 end 328 end
286 if not kb.loaded then 329 if not kb.loaded then
287 KeyBinder_Initialize() 330 KeyBinder_Initialize()
288 kb.loaded = true 331 kb.loaded = true
289 end 332 end
290 for i = 1, numButtons do 333 for i, button in ipairs(kb.buttons) do
291 local button = kb.GetSlot(i)
292 button:SetID(i+kb.scrollOffset) 334 button:SetID(i+kb.scrollOffset)
293 kb.UpdateSlot(button, force) 335 kb.UpdateSlot(button, force)
294 end 336 end
295 337
296 338
297 --- Frame Sizing 339 --- Frame Sizing
298 kb.profilebg:SetHeight(kb.tabSize[2] + BUTTON_PADDING * 2 + kb.profiletext:GetStringHeight()) 340 kb.profilebg:SetHeight(kb.tabSize[2] + BUTTON_PADDING * 2 + kb.profiletext:GetStringHeight())
299 341
300 kb.bg:SetWidth((KEY_BUTTON_SIZE + BUTTON_HSPACING + BUTTON_SPACING) * BINDS_PER_ROW + BUTTON_PADDING*2 - BUTTON_SPACING) 342 kb.bg:SetWidth((KEY_BUTTON_SIZE + BUTTON_HSPACING + BUTTON_SPACING) * BINDS_PER_ROW + BUTTON_PADDING*2 - BUTTON_SPACING)
301 local numRows = numButtons/BINDS_PER_ROW 343 local numRows = NUM_KEY_SLOTS/BINDS_PER_ROW
302 344
303 kb.bg:SetHeight((KEY_BUTTON_SIZE + BUTTON_SPACING) * numRows + BUTTON_PADDING*2 - BUTTON_SPACING) 345 kb.bg:SetHeight((KEY_BUTTON_SIZE + BUTTON_SPACING) * numRows + BUTTON_PADDING*2 - BUTTON_SPACING)
304 346
305 kb:SetHeight(kb.headerbg:GetHeight() + kb.profilebg:GetHeight() + kb.bg:GetHeight() + kb.footer:GetHeight()) 347 kb:SetHeight(kb.headerbg:GetHeight() + kb.profilebg:GetHeight() + kb.bg:GetHeight() + kb.footer:GetHeight())
306 kb:SetWidth((kb.sourcesbg:GetWidth() +(BINDS_PER_ROW * (KEY_BUTTON_SIZE + BUTTON_HSPACING) + (BINDS_PER_ROW - 1) * BUTTON_SPACING + BUTTON_PADDING * 2) )) 348 kb:SetWidth((kb.sourcesbg:GetWidth() +(BINDS_PER_ROW * (KEY_BUTTON_SIZE + BUTTON_HSPACING) + (BINDS_PER_ROW - 1) * BUTTON_SPACING + BUTTON_PADDING * 2) ))
307 349
308 kb.bg:SetColorTexture(unpack(BINDING_SCHEME_COLOR[kb.db.bindMode])) 350 if kb.saveTarget then
351 kb.bg:SetColorTexture(.2,.5, .2, .5)
352 kb.savingText:Show()
353
354 else
355 kb.bg:SetColorTexture(unpack(BINDING_SCHEME_COLOR[kb.db.bindMode]))
356 kb.savingText:Hide()
357 end
358
309 for i, tab in ipairs(kb.tabButtons) do 359 for i, tab in ipairs(kb.tabButtons) do
310 local border = tab:GetNormalTexture() 360 local border = tab:GetNormalTexture()
311 local tabTexture = "Interface\\Buttons\\UI-Quickslot2" 361 local tabTexture = "Interface\\Buttons\\UI-Quickslot2"
312 local left, top, right, bottom = -12, 12, 13, -13 362 local left, top, right, bottom = -12, 12, 13, -13
313 if i == kb.db.bindMode then 363 if i == kb.db.bindMode then
335 print(kb.db.bindMode, kb.configHeaders[kb.db.bindMode], kb:GetSize()) 385 print(kb.db.bindMode, kb.configHeaders[kb.db.bindMode], kb:GetSize())
336 print(kb:GetPoint(1)) 386 print(kb:GetPoint(1))
337 387
338 kb:Show() 388 kb:Show()
339 389
390 if kb.saveTarget then
391 KeyBinderUnbindButton:SetParent(kb.saveTarget)
392 KeyBinderUnbindButton:SetPoint('TOPRIGHT', kb.saveTarget, 'TOPLEFT', -2,0)
393 KeyBinderUnbindButton:Show()
394 else
395 KeyBinderUnbindButton:Hide()
396 end
397
398
340 -- Reset this so talent cache can be rebuilt 399 -- Reset this so talent cache can be rebuilt
341 kb.talentsPushed = nil 400 kb.talentsPushed = nil
342 end 401 end
343 402
344 kb.AcceptAssignment = function(self, ...) 403 kb.AcceptAssignment = function(self, ...)