annotate SkeletonKey/BindingsFrame.lua @ 63:2409fe9b81e1

- check macro spells when considering whether a binding should be treated as a talent - clean up talent binding data when releasing/unbinding slots with a related macro/spell
author Nenue
date Thu, 08 Sep 2016 16:52:55 -0400
parents 9eebce04e69b
children 556e075983a6
rev   line source
Nenue@6 1 -- KrakTool
Nenue@27 2 -- BindingsFrame.lua
Nenue@6 3 -- Created: 7/28/2016 3:39 PM
Nenue@6 4 -- %file-revision%
Nenue@52 5 -- Handles the arrangement of and interaction with the SkeletonKey frame
Nenue@52 6 --[=[
Nenue@52 7 -- some useful texture paths
Nenue@52 8 [[Interface\PaperDollInfoFrame\UI-GearManager-Undo]]
Nenue@52 9 [[Interface\PetPaperDollFrame\UI-PetHappiness]]
Nenue@52 10 [[Interface\RAIDFRAME\ReadyCheck-Waiting]]
Nenue@52 11 [[Interface\RAIDFRAME\ReadyCheck-Read]]
Nenue@52 12 [[Interface\RAIDFRAME\ReadyCheck-NotReady]]
Nenue@52 13 [[Interface\TradeSkillFrame\UI-TradeSkill-LinkButton]]
Nenue@52 14 [[Interface\TUTORIALFRAME\UI-TUTORIAL-FRAME]]
Nenue@52 15 [[Interface\UI-TutorialFrame-QuestGiver\UI-TutorialFrame-QuestGray]]
Nenue@52 16 --]=]
Nenue@6 17
Nenue@52 18 local kb, print = LibStub("LibKraken").register(KeyBinder, 'BindingsUI')
Nenue@52 19 local L = kb.L
Nenue@6 20 local BINDS_PER_ROW = 2
Nenue@17 21 local BINDING_TYPE_SPECIALIZATION = 3
Nenue@17 22 local BINDING_TYPE_CHARACTER = 2
Nenue@17 23 local BINDING_TYPE_GLOBAL = 1
Nenue@6 24 local BUTTON_HSPACING = 128
Nenue@6 25 local BUTTON_SPACING = 4
Nenue@6 26 local BUTTON_PADDING = 12
Nenue@6 27 local KEY_BUTTON_SIZE = 48
Nenue@17 28 local NUM_KEY_SLOTS = BINDS_PER_ROW * 8
Nenue@6 29 local TAB_HEIGHT = 40
Nenue@6 30
Nenue@6 31 local BINDING_SCHEME_COLOR = {
Nenue@6 32 [BINDING_TYPE_GLOBAL] = {0,.125,.5,.5},
Nenue@6 33 [BINDING_TYPE_CHARACTER] = {0,0.25,0,0.5},
Nenue@6 34 [BINDING_TYPE_SPECIALIZATION] = {.25,0,0,0.5},
Nenue@6 35 }
Nenue@6 36 local BINDING_SCHEME_VERTEX = {
Nenue@6 37 [BINDING_TYPE_GLOBAL] = {0,.5,1,1},
Nenue@6 38 [BINDING_TYPE_CHARACTER] = {0,1,0,1},
Nenue@6 39 [BINDING_TYPE_SPECIALIZATION] = {1,1,1,1},
Nenue@6 40 }
Nenue@6 41 local BINDING_SCHEME_TEXT = {
Nenue@6 42 [BINDING_TYPE_SPECIALIZATION] = {0, 1, 1},
Nenue@6 43 [BINDING_TYPE_CHARACTER] = {0, 1, 0},
Nenue@6 44 [BINDING_TYPE_GLOBAL] = {0, 1, 1}
Nenue@6 45 }
Nenue@6 46
Nenue@52 47 local match, strupper = string.match, string.upper
Nenue@52 48 local tremove, tinsert, ipairs, pairs, unpack = table.remove, table.insert, ipairs, pairs, unpack
Nenue@52 49 local tonumber, tostring = tonumber, tostring
Nenue@52 50 local GetCursorInfo, ClearCursor, ResetCursor = GetCursorInfo, ClearCursor, ResetCursor
Nenue@52 51 local IsShiftKeyDown, IsControlKeyDown, IsAltKeyDown = IsShiftKeyDown, IsControlKeyDown, IsAltKeyDown
Nenue@52 52 local GetBindingAction, GetBindingKey, GetCurrentBindingSet = GetBindingAction, GetBindingKey, GetCurrentBindingSet
Nenue@52 53 local SetBinding, SaveBindings = SetBinding, SaveBindings
Nenue@57 54 local GetSpellInfo, InCombatLockdown = GetSpellInfo, InCombatLockdown
Nenue@52 55
Nenue@52 56 kb.ProcessInput = function(key)
Nenue@52 57 if key == 'ESCAPE' then
Nenue@52 58 kb.DeactivateSlot(kb.saveTarget)
Nenue@52 59 kb.ui()
Nenue@52 60 return
Nenue@52 61 end
Nenue@52 62
Nenue@52 63 if (match(key, '[RL]SHIFT') or match(key, '[RL]ALT') or match(key, '[RL]CTRL')) then
Nenue@52 64 return
Nenue@52 65 end
Nenue@52 66
Nenue@52 67 if kb.saveTarget then
Nenue@52 68 if kb.SaveSlot(kb.saveTarget, key) then
Nenue@52 69 if not (kb.db.stickyMode or kb.db.hoverInput) then
Nenue@52 70 kb.DeactivateSlot(kb.saveTarget)
Nenue@52 71 end
Nenue@52 72 end
Nenue@52 73 kb.ui()
Nenue@52 74 end
Nenue@34 75 end
Nenue@34 76
Nenue@52 77 local lastFolder
Nenue@6 78 local restingAlpha = 0.7
Nenue@6 79 local fadeTime, fadeDelay = .30, 0.15
Nenue@6 80 local saveButton
Nenue@17 81
Nenue@17 82 local KeyButton_OnKeyDown = function(self, key)
Nenue@52 83 local st = kb.saveTarget
Nenue@52 84 kb.ProcessInput(key)
Nenue@17 85 end
Nenue@17 86 local KeyButton_OnKeyUp = function(self, key)
Nenue@52 87 local st = kb.saveTarget
Nenue@6 88 end
Nenue@16 89
Nenue@6 90 local KeyButton_OnClick = function(self, click)
Nenue@6 91 print(self:GetName(), 'OnMouseDown', click)
Nenue@16 92 local cursorType = GetCursorInfo()
Nenue@6 93 if click == 'LeftButton' then
Nenue@16 94 if cursorType then
Nenue@16 95 kb.DropToSlot(self)
Nenue@16 96 else
Nenue@30 97 if self.command and self.isAvailable then
Nenue@30 98 if IsShiftKeyDown() then
Nenue@30 99 kb.db.stickyMode = true
Nenue@30 100 KeyBinderStickyMode:SetChecked(true)
Nenue@30 101 end
Nenue@30 102 kb.ActivateSlot(self)
Nenue@30 103 kb.ui()
Nenue@17 104 end
Nenue@16 105 end
Nenue@6 106 elseif click == 'RightButton' then
Nenue@6 107 kb.ReleaseSlot(self)
Nenue@34 108 kb.ui()
Nenue@52 109 else
Nenue@52 110 kb.ProcessInput(strupper(click))
Nenue@6 111 end
Nenue@6 112 end
Nenue@6 113
Nenue@6 114 local KeyButton_OnDragStart = function(self)
Nenue@6 115 kb.PickupSlot(self)
Nenue@6 116 end
Nenue@6 117
Nenue@6 118 local KeyButton_OnReceiveDrag = function(self, ...)
Nenue@6 119 kb.DropToSlot(self)
Nenue@6 120 end
Nenue@6 121
Nenue@6 122
Nenue@6 123 local KeyBinder_OnUpdate = function(self, elapsed)
Nenue@6 124 self.elapsed = self.elapsed + elapsed
Nenue@6 125 self.throttle = self.throttle + elapsed
Nenue@6 126
Nenue@6 127 if (self.throttle >= 0.032) then
Nenue@6 128 self.throttle = 0
Nenue@6 129 else
Nenue@6 130 return
Nenue@6 131 end
Nenue@6 132
Nenue@6 133 local progress = 1
Nenue@6 134 if self.elapsed > fadeTime then
Nenue@6 135 self.elapsed = 0
Nenue@6 136 self.fadeStep = 0
Nenue@6 137 --self.statustext:SetText(nil)
Nenue@6 138 --self.bindingstext:SetText(nil)
Nenue@6 139 self:SetScript('OnUpdate', nil)
Nenue@6 140 else
Nenue@6 141 if self.elapsed < fadeDelay then
Nenue@6 142 progress = 0
Nenue@6 143 else
Nenue@6 144 self.fadeStep = self.fadeStep + 1
Nenue@6 145 progress = (self.elapsed - fadeDelay) /(fadeTime - fadeDelay)
Nenue@6 146 end
Nenue@6 147 --print(self.fadeStep, format('%.02f/%.02f', (self.elapsed - fadeDelay) ,(fadeTime - fadeDelay)) , progress)
Nenue@6 148 end
Nenue@6 149
Nenue@6 150 local alpha = 1 - progress * (1- restingAlpha)
Nenue@6 151 self.statustext:SetAlpha(alpha)
Nenue@6 152 self.bindingstext:SetAlpha(alpha)
Nenue@6 153 end
Nenue@6 154
Nenue@6 155 local KeyButton_OnUpdate = function(self)
Nenue@6 156 if not self.command then
Nenue@6 157 return
Nenue@6 158 end
Nenue@6 159
Nenue@6 160 if self:IsMouseOver() then
Nenue@6 161 kb.elapsed = 0
Nenue@6 162 if not self.active then
Nenue@6 163 -- only set this handler when the button is activated/mouseOver
Nenue@6 164 self.active = true
Nenue@6 165 kb.statustext:SetText(self.statusText .. ': '..self.actionName)
Nenue@6 166 kb.bindingstext:SetText(self.bindingText)
Nenue@6 167 kb.fadeStep = 0
Nenue@6 168 kb.throttle = 0
Nenue@6 169 kb:SetScript('OnUpdate', KeyBinder_OnUpdate)
Nenue@6 170
Nenue@18 171 if kb.db.hoverInput and kb.saveTarget ~= self then
Nenue@18 172 kb.ActivateSlot(self)
Nenue@18 173 kb.ui()
Nenue@18 174 end
Nenue@18 175
Nenue@6 176 end
Nenue@6 177 else
Nenue@19 178 if self.active and kb.db.hoverInput then
Nenue@6 179 self.active = nil
Nenue@19 180 --kb.DeactivateSlot(self)
Nenue@19 181 --kb.ui()
Nenue@6 182 end
Nenue@6 183 end
Nenue@6 184 end
Nenue@6 185
Nenue@6 186 local KeyBinder_OnMouseWheel = function(self, delta)
Nenue@6 187 print(self, delta, self.scrollOffset, (self.scrollOffset <= 0))
Nenue@6 188
Nenue@6 189
Nenue@6 190 if IsControlKeyDown() then
Nenue@6 191 KEY_BUTTON_SIZE = KEY_BUTTON_SIZE - delta
Nenue@6 192 else
Nenue@6 193
Nenue@6 194
Nenue@6 195 if (delta > 0) and (self.scrollOffset <= 0) then
Nenue@6 196 return
Nenue@6 197 elseif delta < 0 and kb.scrollOffset >= 42 then
Nenue@6 198 return
Nenue@6 199 end
Nenue@6 200 kb.scrollOffset = ceil(kb.scrollOffset - (delta * BINDS_PER_ROW))
Nenue@6 201 end
Nenue@6 202
Nenue@17 203 for i = 1, #kb.buttons do
Nenue@17 204 kb.buttons[i]:SetSize(KEY_BUTTON_SIZE,KEY_BUTTON_SIZE)
Nenue@17 205 end
Nenue@17 206
Nenue@6 207 kb.ui(true)
Nenue@6 208 end
Nenue@6 209
Nenue@34 210 local frameCount = 0
Nenue@34 211 local lastCheckFrame
Nenue@34 212 local KeyBinder_CheckButton = function(frame ,enableText, disableText, dbKey, tooltipText, callback, header)
Nenue@19 213 if kb.db[dbKey] then
Nenue@19 214 frame:SetChecked(true)
Nenue@18 215 end
Nenue@34 216
Nenue@34 217 frame.header:SetText(header)
Nenue@18 218
Nenue@19 219 frame:SetScript('OnClick', function(self)
Nenue@52 220 kb.db[dbKey] = self:GetChecked()
Nenue@19 221 if callback then
Nenue@19 222 callback(self)
Nenue@19 223 end
Nenue@19 224 kb.ui()
Nenue@19 225 end)
Nenue@19 226
Nenue@19 227 frame:SetScript('OnEnter', function(self)
Nenue@19 228 if tooltipText then
Nenue@19 229 GameTooltip:SetOwner(self)
Nenue@19 230 GameTooltip:SetText(tooltipText)
Nenue@19 231 GameTooltip:Show()
Nenue@19 232 end
Nenue@19 233 end)
Nenue@19 234
Nenue@19 235 frame:SetScript('OnLeave', function(self)
Nenue@19 236 if tooltipText and GameTooltip:GetOwner() == self then
Nenue@19 237 GameTooltip:Hide()
Nenue@19 238 end
Nenue@19 239 end)
Nenue@34 240
Nenue@34 241 if frame:GetID() == 0 then
Nenue@34 242 frameCount = frameCount + 1
Nenue@34 243 frame:SetID(frameCount)
Nenue@34 244 print('checkbutton #', frameCount)
Nenue@34 245 if frameCount == 1 then
Nenue@34 246 frame:ClearAllPoints()
Nenue@34 247 frame:SetPoint('TOP', KeyBinderInventoryButton, 'BOTTOM', 0, -22)
Nenue@34 248 frame:SetPoint('LEFT', kb.sourcesbg, 'LEFT', 2, 0)
Nenue@34 249 else
Nenue@34 250 frame:ClearAllPoints()
Nenue@34 251 frame:SetPoint('TOPLEFT', lastCheckFrame, 'BOTTOMLEFT', 0, -2)
Nenue@34 252 end
Nenue@34 253
Nenue@34 254 frame.header:ClearAllPoints()
Nenue@34 255 frame.header:SetPoint('LEFT', frame, 'RIGHT', 2, 0)
Nenue@34 256
Nenue@34 257 lastCheckFrame = frame
Nenue@34 258 end
Nenue@18 259 end
Nenue@18 260
Nenue@6 261 local KeyBinder_OnHide = function()
Nenue@6 262 KeyBinderImportLog:Hide()
Nenue@6 263 end
Nenue@6 264
Nenue@6 265 local CloseButton_OnClick = function()
Nenue@10 266 kb.db.showUI = false
Nenue@6 267 kb:Hide()
Nenue@6 268 end
Nenue@6 269 local CancelButton_OnClick = function()
Nenue@6 270 kb.RevertBindings()
Nenue@6 271 end
Nenue@6 272 local SaveButton_OnClick = function()
Nenue@6 273 kb.ConfirmBindings()
Nenue@6 274 end
Nenue@6 275
Nenue@17 276
Nenue@6 277 local KeyBinder_Initialize = function()
Nenue@17 278 do
Nenue@17 279 local leftSlot, upSlot
Nenue@17 280 for index = 1, NUM_KEY_SLOTS do
Nenue@17 281
Nenue@17 282 local button = CreateFrame('CheckButton', 'KeyBinderSlot'..index, kb, 'KeyButton')
Nenue@17 283 button:SetScript('OnClick', KeyButton_OnClick)
Nenue@17 284 button:SetScript('OnUpdate', KeyButton_OnUpdate)
Nenue@17 285 button:SetScript('OnDragStart', KeyButton_OnDragStart)
Nenue@17 286 button:SetScript('OnReceiveDrag', KeyButton_OnReceiveDrag)
Nenue@17 287 button:RegisterForClicks('AnyUp')
Nenue@17 288
Nenue@17 289
Nenue@17 290 local newRow = (mod(index, BINDS_PER_ROW) == 1)
Nenue@17 291
Nenue@17 292 if index == 1 then
Nenue@17 293 button:SetPoint('TOPLEFT', kb.bg, 'TOPLEFT', BUTTON_PADDING, - BUTTON_PADDING)
Nenue@17 294 upSlot = button
Nenue@17 295 elseif newRow then
Nenue@17 296 button:SetPoint('TOPLEFT', upSlot, 'BOTTOMLEFT', 0, -BUTTON_SPACING)
Nenue@17 297 upSlot = button
Nenue@17 298 else
Nenue@17 299 button:SetPoint('TOPLEFT', leftSlot, 'TOPRIGHT', BUTTON_HSPACING, 0)
Nenue@17 300 end
Nenue@17 301
Nenue@17 302 button:SetSize(KEY_BUTTON_SIZE, KEY_BUTTON_SIZE)
Nenue@17 303 button:Show()
Nenue@17 304 kb.buttons[index] = button
Nenue@17 305 leftSlot = button
Nenue@17 306 end
Nenue@17 307 end
Nenue@6 308
Nenue@6 309
Nenue@6 310 kb.scrollOffset = 0
Nenue@6 311 kb.tabAnchor = {'TOPLEFT', kb.profilebg, 'TOPLEFT', BUTTON_PADDING, -BUTTON_SPACING}
Nenue@6 312 kb.tabGrowth = {'TOPLEFT', nil,'TOPRIGHT', BUTTON_SPACING, 0}
Nenue@6 313 kb.tabSize = {TAB_HEIGHT, TAB_HEIGHT }
Nenue@6 314 kb.UIPanelAnchor = {'TOPLEFT', kb.sourcesbg, 'TOPLEFT', BUTTON_PADDING, -BUTTON_SPACING}
Nenue@6 315 kb.UIPanelGrowth = {'TOPLEFT', nil, 'BOTTOMLEFT', 0, -2 }
Nenue@6 316 kb.UIPanelSize = {84, 32 }
Nenue@6 317 kb.UIPanelIcon = {24, 32, 'LEFT', -12, 0}
Nenue@17 318 kb.controlsAnchor = {'BOTTOMRIGHT', kb.footer, -BUTTON_PADDING, BUTTON_PADDING }
Nenue@17 319 kb.controlsGrowth = {'BOTTOMRIGHT', nil, 'BOTTOMLEFT', -BUTTON_SPACING, 0}
Nenue@6 320
Nenue@6 321 -- order of these is important
Nenue@6 322 kb:tab('KeyBinderGlobalTab',
Nenue@6 323 kb.configTitle[BINDING_TYPE_GLOBAL] .. '\n' .. kb.configDescription[BINDING_TYPE_GLOBAL], "Interface\\ICONS\\item_azereansphere", {0.15,.85,.15,.85})
Nenue@6 324 kb:tab('KeyBinderCharacterTab',
Nenue@6 325 kb.configHeaders[BINDING_TYPE_CHARACTER] .. '\n' .. kb.configDescription[BINDING_TYPE_CHARACTER], nil)
Nenue@6 326 kb:tab('KeyBinderSpecTab',
Nenue@6 327 kb.configHeaders[BINDING_TYPE_SPECIALIZATION] .. '\n' .. kb.configDescription[BINDING_TYPE_SPECIALIZATION], kb.specInfo.texture)
Nenue@6 328 KeyBinderCharacterTab.icon:SetTexCoord(0.15,.85,.15,.85)
Nenue@6 329
Nenue@6 330
Nenue@6 331
Nenue@6 332 --portraitLayers[1] = KeyBinderCharacterTab.icon
Nenue@17 333 -- todo: find some generic icons for refresh/key input,etc
Nenue@6 334
Nenue@17 335 saveButton = kb:button('KeyBinderSaveButton', 'Update', 'Reload current bindings and refresh panel.', SaveButton_OnClick)
Nenue@6 336 --restoreButton = kb:button('KeyBinderRestoreButton', 'Discard', 'Revert all changes.', CancelButton_OnClick)
Nenue@6 337 --clearButton = kb:button('KeyBinderClearButton', 'Clear Page', 'Release all buttons.', ResetButton_OnClick)
Nenue@6 338
Nenue@6 339 kb:uibutton(
Nenue@6 340 'KeyBinderSpellBookButton', 'SpellBook', nil,
Nenue@6 341 function() ToggleSpellBook(BOOKTYPE_SPELL) end,
Nenue@6 342 "Interface\\BUTTONS\\UI-MicroButton-Spellbook-Up", {0, 1, .4, 1})
Nenue@6 343 kb:uibutton(
Nenue@6 344 'KeyBinderTalentFrameButton', TALENTS, SPECIALIZATION,
Nenue@6 345 function() ToggleTalentFrame() end,
Nenue@6 346 "Interface\\BUTTONS\\UI-MicroButton-Talents-Up", {0, 1, .4, 1})
Nenue@6 347
Nenue@6 348 kb:uibutton(
Nenue@6 349 'KeyBinderMacroFrameButton', 'Macros', nil,
Nenue@6 350 function() if MacroFrame and MacroFrame:IsVisible() then
Nenue@6 351 HideUIPanel(MacroFrame)
Nenue@6 352 else
Nenue@6 353 ShowMacroFrame() end
Nenue@6 354 end,
Nenue@6 355 "Interface\\BUTTONS\\UI-MicroButton-Help-Up", {0, 1, .4, 1})
Nenue@6 356
Nenue@6 357 kb:uibutton(
Nenue@6 358 'KeyBinderInventoryButton', 'Bags', nil,
Nenue@6 359 function() OpenAllBags() end,
Nenue@6 360 "Interface\\BUTTONS\\UI-MicroButtonCharacter-Up", {0, 1, .4, 1})
Nenue@6 361
Nenue@52 362 KeyBinder_CheckButton(KeyBinderStickyMode, 'Enabled', 'Disabled', 'stickyMode', 'Keep input active after receiving a key.', function()
Nenue@52 363 if kb.saveTarget and (not kb.db.stickyMode) then
Nenue@52 364 kb.DeactivateSlot(kb.saveTarget)
Nenue@52 365 end
Nenue@52 366 end, 'Sticky:')
Nenue@34 367 KeyBinder_CheckButton(KeyBinderHoverInput, 'MouseOver', 'Click', 'hoverInput', 'Enable key input when the cursor is over a binding slot.', nil, 'Bind by:')
Nenue@34 368 KeyBinder_CheckButton(KeyBinderProtectBindings, 'Block', 'Allow', 'protectBlizKeys', 'Allow overwriting Blizzard UI bindings.', nil, 'Safety:')
Nenue@18 369
Nenue@18 370
Nenue@18 371 KeyBinderUnbindButton:SetScript('OnClick', function()
Nenue@18 372 if kb.saveTarget then
Nenue@18 373 kb.UnbindSlot(kb.saveTarget)
Nenue@18 374 end
Nenue@18 375 kb.ui()
Nenue@18 376 end)
Nenue@18 377
Nenue@6 378
Nenue@6 379 kb.info:SetPoint('TOPLEFT', kb.UIPanels[1], 'BOTTOMLEFT', 0, -BUTTON_SPACING)
Nenue@6 380 HEADER_OFFSET = kb.UIPanels[1]:GetHeight() + BUTTON_PADDING
Nenue@6 381 + kb.info:GetHeight()
Nenue@6 382 FOOTER_OFFSET = saveButton:GetHeight() + BUTTON_PADDING
Nenue@6 383
Nenue@6 384 kb:SetScript('OnHide', KeyBinder_OnHide)
Nenue@6 385 kb:SetScript('OnMouseWheel', KeyBinder_OnMouseWheel)
Nenue@6 386 kb.CloseButton:SetScript('OnClick', CloseButton_OnClick)
Nenue@6 387
Nenue@6 388 end
Nenue@6 389
Nenue@6 390
Nenue@6 391 --- Retrieves button at index; creates said button and instates any stored parameters
Nenue@6 392
Nenue@6 393
Nenue@17 394 kb.ActivateSlot = function(button)
Nenue@17 395 kb.saveTarget = button
Nenue@49 396 kb:SetScript('OnKeyUp', function(self, key) KeyButton_OnKeyUp(button, key) end)
Nenue@49 397 kb:SetScript('OnKeyDown', function(self, key) KeyButton_OnKeyDown(button, key) end)
Nenue@49 398 kb:SetScript('OnMouseUp', function(self, key) KeyButton_OnKeyUp(button, key) end)
Nenue@17 399 kb.savingText:ClearAllPoints()
Nenue@17 400 kb.savingText:SetParent(button)
Nenue@17 401 kb.savingText:SetPoint('BOTTOMLEFT', button, 'TOPLEFT', 0, 0)
Nenue@6 402 end
Nenue@6 403
Nenue@17 404 kb.DeactivateSlot = function(button)
Nenue@17 405 kb.saveTarget = nil
Nenue@17 406 kb:SetScript('OnKeyUp', nil)
Nenue@17 407 kb:SetScript('OnKeyDown', nil)
Nenue@49 408 kb:SetScript('OnMouseUp', nil)
Nenue@17 409 end
Nenue@6 410
Nenue@16 411
Nenue@6 412 --- push current information into living UI
Nenue@6 413 kb.ui = function(force)
Nenue@6 414 for i, module in ipairs(kb.modules) do
Nenue@6 415 if module.ui then
Nenue@6 416 module.ui(force)
Nenue@6 417 end
Nenue@6 418 end
Nenue@6 419
Nenue@6 420 if not kb.db.showUI then
Nenue@6 421 print('---end of refresh')
Nenue@6 422 return
Nenue@6 423 end
Nenue@6 424 if not kb.loaded then
Nenue@6 425 KeyBinder_Initialize()
Nenue@6 426 kb.loaded = true
Nenue@6 427 end
Nenue@17 428 for i, button in ipairs(kb.buttons) do
Nenue@6 429 button:SetID(i+kb.scrollOffset)
Nenue@6 430 kb.UpdateSlot(button, force)
Nenue@6 431 end
Nenue@6 432
Nenue@6 433
Nenue@6 434 --- Frame Sizing
Nenue@6 435 kb.profilebg:SetHeight(kb.tabSize[2] + BUTTON_PADDING * 2 + kb.profiletext:GetStringHeight())
Nenue@6 436
Nenue@6 437 kb.bg:SetWidth((KEY_BUTTON_SIZE + BUTTON_HSPACING + BUTTON_SPACING) * BINDS_PER_ROW + BUTTON_PADDING*2 - BUTTON_SPACING)
Nenue@17 438 local numRows = NUM_KEY_SLOTS/BINDS_PER_ROW
Nenue@6 439
Nenue@6 440 kb.bg:SetHeight((KEY_BUTTON_SIZE + BUTTON_SPACING) * numRows + BUTTON_PADDING*2 - BUTTON_SPACING)
Nenue@6 441
Nenue@6 442 kb:SetHeight(kb.headerbg:GetHeight() + kb.profilebg:GetHeight() + kb.bg:GetHeight() + kb.footer:GetHeight())
Nenue@6 443 kb:SetWidth((kb.sourcesbg:GetWidth() +(BINDS_PER_ROW * (KEY_BUTTON_SIZE + BUTTON_HSPACING) + (BINDS_PER_ROW - 1) * BUTTON_SPACING + BUTTON_PADDING * 2) ))
Nenue@6 444
Nenue@17 445 if kb.saveTarget then
Nenue@17 446 kb.bg:SetColorTexture(.2,.5, .2, .5)
Nenue@17 447 kb.savingText:Show()
Nenue@17 448
Nenue@17 449 else
Nenue@17 450 kb.bg:SetColorTexture(unpack(BINDING_SCHEME_COLOR[kb.db.bindMode]))
Nenue@17 451 kb.savingText:Hide()
Nenue@17 452 end
Nenue@17 453
Nenue@6 454 for i, tab in ipairs(kb.tabButtons) do
Nenue@6 455 local border = tab:GetNormalTexture()
Nenue@6 456 local tabTexture = "Interface\\Buttons\\UI-Quickslot2"
Nenue@6 457 local left, top, right, bottom = -12, 12, 13, -13
Nenue@6 458 if i == kb.db.bindMode then
Nenue@6 459 tabTexture = "Interface\\Buttons\\CheckButtonGlow"
Nenue@6 460 left, top, right, bottom = -14, 14, 15, -15
Nenue@6 461 tab.icon:SetDesaturated(false)
Nenue@6 462 if tab.icon2 then tab.icon2:SetDesaturated(false) end
Nenue@6 463 border:SetDesaturated(true)
Nenue@6 464 border:SetVertexColor(1,1,1, 1)
Nenue@6 465 else
Nenue@6 466 tab.icon:SetDesaturated(true)
Nenue@6 467 if tab.icon2 then tab.icon2:SetDesaturated(true) end
Nenue@6 468 border:SetDesaturated(false)
Nenue@6 469 border:SetVertexColor(1,1,1)
Nenue@6 470 end
Nenue@6 471 border:SetTexture(tabTexture)
Nenue@6 472 border:SetPoint('TOPLEFT', tab, 'TOPLEFT', left, top)
Nenue@6 473 border:SetPoint('BOTTOMRIGHT', tab, 'BOTTOMRIGHT', right, bottom)
Nenue@6 474 end
Nenue@6 475
Nenue@6 476 KeyBinderSpecTab.icon:SetTexture(kb.specInfo.texture)
Nenue@12 477 SetPortraitTexture(KeyBinderCharacterTab.icon, 'player')
Nenue@6 478
Nenue@6 479 kb.profiletext:SetText(kb.configHeaders[kb.db.bindMode])
Nenue@6 480 print(kb.db.bindMode, kb.configHeaders[kb.db.bindMode], kb:GetSize())
Nenue@6 481 print(kb:GetPoint(1))
Nenue@6 482
Nenue@6 483 kb:Show()
Nenue@6 484
Nenue@17 485 if kb.saveTarget then
Nenue@17 486 KeyBinderUnbindButton:SetParent(kb.saveTarget)
Nenue@19 487 KeyBinderUnbindButton:SetPoint('TOPLEFT', kb.saveTarget, 'BOTTOMLEFT', 0, -1)
Nenue@17 488 KeyBinderUnbindButton:Show()
Nenue@17 489 else
Nenue@17 490 KeyBinderUnbindButton:Hide()
Nenue@17 491 end
Nenue@17 492
Nenue@6 493 -- Reset this so talent cache can be rebuilt
Nenue@6 494 kb.talentsPushed = nil
Nenue@6 495 end
Nenue@6 496
Nenue@52 497 --- Associate processed input with the given slot's metadata
Nenue@52 498 kb.SaveSlot = function(self, key)
Nenue@52 499
Nenue@52 500 if not self.command then
Nenue@52 501 return
Nenue@52 502 end
Nenue@57 503 if InCombatLockdown() then
Nenue@57 504 kb:print(L('Bindings cannot be changed during combat.'))
Nenue@57 505 return
Nenue@57 506 end
Nenue@57 507
Nenue@57 508
Nenue@52 509 print('|cFFFFFF00received|cFFFFFF00', self:GetID(), '|cFF00FFFF', key)
Nenue@52 510
Nenue@52 511 local modifier = ''
Nenue@52 512 if IsAltKeyDown() then
Nenue@52 513 modifier = 'ALT-'
Nenue@52 514 end
Nenue@52 515 if IsControlKeyDown() then
Nenue@52 516 modifier = modifier.. 'CTRL-'
Nenue@52 517 end
Nenue@52 518 if IsShiftKeyDown() then
Nenue@52 519 modifier = modifier..'SHIFT-'
Nenue@52 520 end
Nenue@52 521 local binding = modifier..key
Nenue@52 522
Nenue@52 523 -- check for system bindings
Nenue@52 524 --bprint('|cFFFFFF00SaveBind|r', 'protectKeys', kb.db.protectBlizKeys)
Nenue@52 525 if kb.db.protectBlizKeys and kb.SystemBindings[binding] then
Nenue@52 526 kb.statustext:SetText(L('BINDING_FAILED_PROTECTED', binding, kb.SystemBindings[binding]))
Nenue@52 527 kb.bindingstext:SetText(nil)
Nenue@52 528 return false
Nenue@52 529 end
Nenue@52 530
Nenue@52 531 -- check for other keys
Nenue@52 532 local previousCommand = GetBindingAction(binding)
Nenue@52 533 if previousCommand ~= "" and previousCommand ~= self.command then
Nenue@52 534 local actionType, actionID, name = kb.GetCommandAction(previousCommand)
Nenue@52 535 if actionType then
Nenue@52 536 local keys = {GetBindingKey(previousCommand) }
Nenue@52 537 local i = 1
Nenue@52 538 while keys[i] do
Nenue@52 539 if keys[i] == binding then
Nenue@52 540 tremove(keys, i)
Nenue@52 541 kb.UpdateBindingsCache(actionType, actionID, keys)
Nenue@52 542 break
Nenue@52 543 end
Nenue@52 544 i = i + 1
Nenue@52 545 end
Nenue@52 546 end
Nenue@52 547 end
Nenue@52 548
Nenue@52 549 local currentHotKeys = {GetBindingKey(self.command)}
Nenue@52 550 local found
Nenue@52 551 for i, key in ipairs(currentHotKeys) do
Nenue@52 552 if key == binding then
Nenue@52 553 found = true
Nenue@57 554 print('|cFFFF4400key already bound to this')
Nenue@57 555 return true
Nenue@52 556 end
Nenue@52 557 end
Nenue@52 558 if not found then
Nenue@52 559 tinsert(currentHotKeys, 1, binding)
Nenue@52 560 kb.UpdateBindingsCache(self.actionType, self.actionID, currentHotKeys)
Nenue@52 561 end
Nenue@52 562
Nenue@57 563 -- scour profile data for any conflicting binds
Nenue@57 564 local currentAction = GetBindingAction(binding)
Nenue@57 565 if match(currentAction, 'KeyBinder') then
Nenue@57 566 if currentAction ~= self.command then
Nenue@57 567 print('|cFFFF4400removing bindings for:', currentAction)
Nenue@57 568 for profileID, profileData in ipairs(kb.loadedProfiles) do
Nenue@57 569 local buttonID = profileData.commands[currentAction]
Nenue@57 570 if buttonID then
Nenue@57 571 local buttonAction = profileData.buttons[buttonID][2]
Nenue@57 572 if buttonAction then
Nenue@57 573 local talentInfo = profileData.talents[buttonAction]
Nenue@57 574 if talentInfo and GetSpellInfo(buttonAction) then
Nenue@57 575 for i = #talentInfo, 5, -1 do
Nenue@57 576 if binding == talentInfo[i] then
Nenue@57 577 tremove(talentInfo, i)
Nenue@57 578 end
Nenue@57 579 end
Nenue@57 580 kb:print(L('Overwrote talent |cFF88FF00%s|r in |cFF00FFFF%s|r', buttonAction, kb.configHeaders[profileID]))
Nenue@57 581 else
Nenue@57 582
Nenue@57 583 kb:print(L('Overwrote |cFFFFFF00%s|r in |cFF00FFFF%s|r', buttonAction, kb.configHeaders[profileID]))
Nenue@57 584 end
Nenue@57 585 profileData.bindings[binding] = nil
Nenue@57 586 end
Nenue@57 587 end
Nenue@57 588 end
Nenue@57 589 end
Nenue@57 590 end
Nenue@52 591
Nenue@52 592
Nenue@52 593 print('SetBinding', binding, self.command)
Nenue@52 594 SetBinding(binding, self.command)
Nenue@52 595 SaveBindings(GetCurrentBindingSet())
Nenue@52 596 self.binding = binding
Nenue@52 597
Nenue@63 598 local talentName = self.actionName
Nenue@63 599 if self.actionType == 'macro' then
Nenue@63 600 talentName = GetMacroSpell(self.actionID)
Nenue@63 601 end
Nenue@63 602
Nenue@52 603 local talentInfo
Nenue@63 604 if talentName and kb.TalentCache[talentName] then
Nenue@52 605 print('store dynamicType talent')
Nenue@52 606 talentInfo = {self.macroName, self.actionName, self.actionType, self.actionID}
Nenue@52 607 local bindings = {GetBindingKey(self.command) }
Nenue@52 608 for i, key in ipairs(bindings) do
Nenue@52 609 tinsert(talentInfo, key)
Nenue@52 610 end
Nenue@52 611 end
Nenue@52 612
Nenue@52 613 for level, profile in ipairs(kb.orderedProfiles) do
Nenue@52 614 if (level == kb.db.bindMode) then
Nenue@52 615 profile.bound[self.command] = true
Nenue@52 616 if talentInfo then
Nenue@52 617 profile.bindings[self.binding] = nil
Nenue@52 618 else
Nenue@52 619 profile.bindings[self.binding] = self.command
Nenue@52 620 end
Nenue@63 621 profile.talents[talentName] = talentInfo
Nenue@52 622 else
Nenue@52 623 profile.bindings[self.binding] = nil
Nenue@52 624 profile.bound[self.command] = nil
Nenue@63 625 profile.talents[talentName] = nil
Nenue@52 626 end
Nenue@52 627 end
Nenue@52 628
Nenue@57 629
Nenue@52 630 kb:print(L('BINDING_ASSIGNED', self.binding, self.actionName, kb.currentHeader))
Nenue@57 631 kb.ui()
Nenue@52 632 return true
Nenue@52 633 end
Nenue@52 634
Nenue@52 635
Nenue@52 636 kb.UnbindSlot = function(self)
Nenue@52 637
Nenue@52 638 local keys = {GetBindingKey(self.command) }
Nenue@52 639 if #keys >= 1 then
Nenue@52 640 kb.UpdateBindingsCache(self.actionType, self.actionID, {})
Nenue@52 641 end
Nenue@52 642
Nenue@63 643 local talentName = self.actionName
Nenue@63 644 if self.actionType == 'macro' then
Nenue@63 645 local spellName, _, spellID = GetMacroSpell(self.actionID)
Nenue@63 646 talentName = spellName
Nenue@63 647 end
Nenue@63 648
Nenue@52 649
Nenue@52 650 --print('detected', #keys, 'bindings')
Nenue@52 651 for i, key in pairs(keys) do
Nenue@52 652 --print('clearing', key)
Nenue@52 653 SetBinding(key, nil)
Nenue@52 654 SaveBindings(GetCurrentBindingSet())
Nenue@52 655 if kb.currentProfile.bindings[key] then
Nenue@52 656 --kb:print(L('BINDING_REMOVED', self.actionName, kb.currentHeader))
Nenue@52 657 kb.currentProfile.bindings[key] = nil
Nenue@52 658 end
Nenue@63 659 if kb.currentProfile.talents[talentName] then
Nenue@63 660 kb.currentProfile.talents[talentName] = nil
Nenue@52 661 end
Nenue@52 662
Nenue@52 663 kb.bindings[tostring(self.actionType)..'_'..tostring(self.actionID)] = nil
Nenue@52 664 end
Nenue@52 665 if kb.currentProfile.bound[self.command] then
Nenue@52 666 kb.currentProfile.bound[self.command] = nil
Nenue@52 667 --kb:print(BINDING_REMOVED:format(self.actionName, configHeaders[db.bindMode]))
Nenue@52 668 end
Nenue@52 669
Nenue@52 670
Nenue@52 671 self.active = false
Nenue@52 672 kb.UpdateSlot(self, true)
Nenue@52 673 end
Nenue@52 674
Nenue@6 675 kb.AcceptAssignment = function(self, ...)
Nenue@6 676 local popup = StaticPopupDialogs["SKELETONKEY_CONFIRM_ASSIGN_SLOT"]
Nenue@30 677 local source = kb. loadedProfiles[popup.oldProfile]
Nenue@6 678 kb.SetSlot(popup.slot, unpack(popup.args))
Nenue@6 679 kb.UpdateSlot(popup.slot)
Nenue@6 680 kb:SetScript('OnMouseWheel', KeyBinder_OnMouseWheel) -- re-enable scrolling
Nenue@6 681 ClearCursor()
Nenue@6 682 ResetCursor()
Nenue@6 683 end
Nenue@52 684
Nenue@52 685 --- Add to blizzard interfaces
Nenue@52 686 StaticPopupDialogs["SKELETONKEY_CONFIRM_ASSIGN_SLOT"] = {
Nenue@52 687 text = "Confirm moving an assigned command.",
Nenue@52 688 button1 = OKAY,
Nenue@52 689 button2 = CANCEL,
Nenue@52 690 timeout = 0,
Nenue@52 691 whileDead = 1,
Nenue@52 692 showAlert = 1,
Nenue@52 693 OnAccept = kb.AcceptAssignment,
Nenue@52 694 OnCancel = function() kb:SetScript('OnMouseWheel', KeyBinder_OnMouseWheel) end
Nenue@52 695 }