annotate BindingsFrame.lua @ 76:6623b7f2c1ca v7.1.5-78-release

Added: - key assignment and unbinding for inactive talents Bug Fixes: - fixed spell access check for talents - fixed detection of Legion PvP talents - fixed unbind command not clearing assigned key text - fixed frame content not loading after combat Miscellaneous: - bindings are determined from the button's assignment list - increment profile version to remove deprecated talents list
author Nenue
date Mon, 23 Jan 2017 20:07:30 -0500
parents 9824d524a661
children d4c100b0fd01
rev   line source
Nenue@70 1 -- KrakTool
Nenue@70 2 -- BindingsFrame.lua
Nenue@70 3 -- Created: 7/28/2016 3:39 PM
Nenue@70 4 -- %file-revision%
Nenue@70 5 -- Handles the arrangement of and interaction with the SkeletonKey frame
Nenue@70 6 --[=[
Nenue@70 7 -- some useful texture paths
Nenue@70 8 [[Interface\PaperDollInfoFrame\UI-GearManager-Undo]]
Nenue@70 9 [[Interface\PetPaperDollFrame\UI-PetHappiness]]
Nenue@70 10 [[Interface\RAIDFRAME\ReadyCheck-Waiting]]
Nenue@70 11 [[Interface\RAIDFRAME\ReadyCheck-Read]]
Nenue@70 12 [[Interface\RAIDFRAME\ReadyCheck-NotReady]]
Nenue@70 13 [[Interface\TradeSkillFrame\UI-TradeSkill-LinkButton]]
Nenue@70 14 [[Interface\TUTORIALFRAME\UI-TUTORIAL-FRAME]]
Nenue@70 15 [[Interface\UI-TutorialFrame-QuestGiver\UI-TutorialFrame-QuestGray]]
Nenue@70 16 --]=]
Nenue@70 17
Nenue@70 18 SkeletonKeyButtonMixin = {}
Nenue@70 19 local _, kb = ...
Nenue@74 20 local print = (DEVIAN_PNAME == 'SkeletonKey') and function(...) _G.print('SKUI', ...) end or nop
Nenue@74 21 local gprint = (DEVIAN_PNAME == 'SkeletonKey') and function(...) _G.print('SK', ...) end or nop
Nenue@70 22 local L = kb.L
Nenue@70 23 local BINDS_PER_ROW = 2
Nenue@70 24 local BINDING_TYPE_SPECIALIZATION = 3
Nenue@70 25 local BINDING_TYPE_CHARACTER = 2
Nenue@70 26 local BINDING_TYPE_GLOBAL = 1
Nenue@70 27 local BUTTON_HSPACING = 128
Nenue@70 28 local BUTTON_SPACING = 4
Nenue@70 29 local BUTTON_PADDING = 12
Nenue@70 30 local TAB_HEIGHT = 24
Nenue@70 31 local KEY_BUTTON_SIZE = 48
Nenue@70 32 local NUM_KEY_SLOTS = BINDS_PER_ROW * 8
Nenue@70 33 local TAB_HEIGHT = 40
Nenue@70 34 local BG_INSET = 4
Nenue@70 35
Nenue@70 36 local BINDING_SCHEME_COLOR = {
Nenue@70 37 [BINDING_TYPE_GLOBAL] = {0,.125,.5,.8},
Nenue@70 38 [BINDING_TYPE_CHARACTER] = {0,0.25,0,0.8},
Nenue@70 39 [BINDING_TYPE_SPECIALIZATION] = {.25,0,0,0.8},
Nenue@70 40 }
Nenue@70 41 local BINDING_SCHEME_VERTEX = {
Nenue@70 42 [BINDING_TYPE_GLOBAL] = {0,.5,1,1},
Nenue@70 43 [BINDING_TYPE_CHARACTER] = {0,1,0,1},
Nenue@70 44 [BINDING_TYPE_SPECIALIZATION] = {1,1,1,1},
Nenue@70 45 }
Nenue@70 46 local BINDING_SCHEME_TEXT = {
Nenue@70 47 [BINDING_TYPE_SPECIALIZATION] = {0, 1, 1},
Nenue@70 48 [BINDING_TYPE_CHARACTER] = {0, 1, 0},
Nenue@70 49 [BINDING_TYPE_GLOBAL] = {0, 1, 1}
Nenue@70 50 }
Nenue@70 51
Nenue@70 52 local match, strupper = string.match, string.upper
Nenue@70 53 local tremove, tinsert, ipairs, pairs, unpack = table.remove, table.insert, ipairs, pairs, unpack
Nenue@70 54 local tonumber, tostring = tonumber, tostring
Nenue@70 55 local GetCursorInfo, ClearCursor, ResetCursor = GetCursorInfo, ClearCursor, ResetCursor
Nenue@70 56 local IsShiftKeyDown, IsControlKeyDown, IsAltKeyDown = IsShiftKeyDown, IsControlKeyDown, IsAltKeyDown
Nenue@70 57 local GetBindingAction, GetBindingKey, GetCurrentBindingSet = GetBindingAction, GetBindingKey, GetCurrentBindingSet
Nenue@70 58 local SetBinding, SaveBindings = SetBinding, SaveBindings
Nenue@70 59 local GetSpellInfo, InCombatLockdown = GetSpellInfo, InCombatLockdown
Nenue@70 60
Nenue@70 61
Nenue@70 62 local ActionListPanel = {
Nenue@70 63 tabButtons = {
Nenue@70 64 [BINDING_TYPE_GLOBAL] = {
Nenue@70 65 icon = "Interface\\WORLDMAP\\WorldMap-Icon",
Nenue@70 66 label = "Global",
Nenue@70 67 },
Nenue@70 68 [BINDING_TYPE_CHARACTER] ={
Nenue@70 69 func = function(self, index)
Nenue@70 70 SetPortraitTexture(self.Icon, 'player')
Nenue@70 71 self.Label:SetText(kb.configHeaders[index])
Nenue@70 72 self.tooltipText = kb.configHeaders[index]
Nenue@70 73 end
Nenue@70 74 },
Nenue@70 75 [BINDING_TYPE_SPECIALIZATION] = {
Nenue@70 76 func = function(self, index)
Nenue@70 77 self.Icon:SetTexture(kb.specInfo.texture)
Nenue@70 78 self.Label:SetText(kb.configHeaders[index])
Nenue@70 79 self.tooltipText = kb.configHeaders[index]
Nenue@70 80 end
Nenue@70 81 },
Nenue@70 82 }
Nenue@70 83 }
Nenue@70 84 local SystemBindingsPanel = {
Nenue@70 85 tabButtons = {
Nenue@70 86 {label = "Global"},
Nenue@70 87 {label = "Character"}
Nenue@70 88 }
Nenue@70 89 }
Nenue@70 90 function SkeletonKeyMixin:ProcessInput (key)
Nenue@70 91 if self.currentPanel then
Nenue@70 92 if self.currentPanel:OnInput(key) then
Nenue@70 93 self:Update(true)
Nenue@70 94 end
Nenue@70 95 end
Nenue@70 96 end
Nenue@70 97
Nenue@70 98 local lastFolder
Nenue@70 99 local restingAlpha = 0.7
Nenue@70 100 local fadeTime, fadeDelay = .30, 0.15
Nenue@70 101 local saveButton
Nenue@70 102
Nenue@70 103
Nenue@70 104
Nenue@70 105 local frameCount = 0
Nenue@70 106 local lastCheckFrame
Nenue@70 107 local KeyBinder_CheckButton = function(frame ,enableText, disableText, dbKey, tooltipText, callback, header)
Nenue@70 108 if kb.db[dbKey] then
Nenue@70 109 frame:SetChecked(true)
Nenue@70 110 end
Nenue@70 111
Nenue@70 112 frame.header:SetText(header)
Nenue@70 113
Nenue@70 114 frame:SetScript('OnClick', function(self)
Nenue@70 115 kb.db[dbKey] = self:GetChecked()
Nenue@70 116 if callback then
Nenue@70 117 callback(self)
Nenue@70 118 end
Nenue@70 119 kb.ui()
Nenue@70 120 end)
Nenue@70 121
Nenue@70 122 frame:SetScript('OnEnter', function(self)
Nenue@70 123 if tooltipText then
Nenue@70 124 GameTooltip:SetOwner(self)
Nenue@70 125 GameTooltip:SetText(tooltipText)
Nenue@70 126 GameTooltip:Show()
Nenue@70 127 end
Nenue@70 128 end)
Nenue@70 129
Nenue@70 130 frame:SetScript('OnLeave', function(self)
Nenue@70 131 if tooltipText and GameTooltip:GetOwner() == self then
Nenue@70 132 GameTooltip:Hide()
Nenue@70 133 end
Nenue@70 134 end)
Nenue@70 135
Nenue@70 136 if frame:GetID() == 0 then
Nenue@70 137 frameCount = frameCount + 1
Nenue@70 138 frame:SetID(frameCount)
Nenue@70 139 print('checkbutton #', frameCount)
Nenue@70 140 if frameCount == 1 then
Nenue@70 141 frame:ClearAllPoints()
Nenue@70 142 frame:SetPoint('TOP', KeyBinderInventoryButton, 'BOTTOM', 0, -22)
Nenue@70 143 frame:SetPoint('LEFT', SkeletonKey 'LEFT', 2, 0)
Nenue@70 144 else
Nenue@70 145 frame:ClearAllPoints()
Nenue@70 146 frame:SetPoint('TOPLEFT', lastCheckFrame, 'BOTTOMLEFT', 0, -2)
Nenue@70 147 end
Nenue@70 148
Nenue@70 149 frame.header:ClearAllPoints()
Nenue@70 150 frame.header:SetPoint('LEFT', frame, 'RIGHT', 2, 0)
Nenue@70 151
Nenue@70 152 lastCheckFrame = frame
Nenue@70 153 end
Nenue@70 154 end
Nenue@70 155
Nenue@70 156
Nenue@70 157
Nenue@70 158 function SkeletonKeyMixin:OnMouseWheel(delta)
Nenue@70 159
Nenue@70 160 -- let the updaters handle range
Nenue@70 161 if IsControlKeyDown() then
Nenue@70 162 self.zoomScale = self.zoomScale - (delta/10)
Nenue@70 163 else
Nenue@70 164 self.scrollOffset = ceil(self.scrollOffset - delta)
Nenue@70 165 end
Nenue@70 166
Nenue@70 167 self:Update(true)
Nenue@70 168 print(self.zoomScale, self.scrollOffset)
Nenue@70 169 end
Nenue@70 170
Nenue@76 171 function SkeletonKeyMixin:OnShow()
Nenue@76 172 self:Update()
Nenue@76 173 end
Nenue@70 174 function SkeletonKeyMixin:OnHide()
Nenue@76 175
Nenue@70 176 end
Nenue@70 177
Nenue@70 178
Nenue@70 179 local tabID = 0
Nenue@70 180 local prevTab
Nenue@70 181
Nenue@70 182 function SkeletonKeyMixin:SetupTabButton (index, text, icon, func)
Nenue@70 183 print('|cFF00FFFF'..self:GetName()..':SetupTabButton()', index, text, icon, func)
Nenue@70 184 local tabName = 'SkeletonKeyProfileTab'..index
Nenue@70 185 local tab = _G[tabName]
Nenue@70 186
Nenue@70 187 if not tab then
Nenue@70 188 tab = CreateFrame('Button', tabName, self, 'SkeletonKeyTabTemplate')
Nenue@70 189 self.numTabs = self.numTabs + 1
Nenue@70 190 tab:SetID(self.numTabs)
Nenue@70 191 TAB_HEIGHT = tab:GetHeight()
Nenue@70 192
Nenue@70 193 if self.numTabs == 1 then
Nenue@70 194 tab:SetPoint('TOPLEFT', self.profilebg, 'TOPLEFT', BUTTON_PADDING, -BUTTON_SPACING)
Nenue@70 195 else
Nenue@70 196 tab:SetPoint('TOPLEFT', self.lastTab,'TOPRIGHT', BUTTON_SPACING, 0)
Nenue@70 197 end
Nenue@70 198
Nenue@70 199 tab.tooltipText = text
Nenue@70 200 tab:SetScript('OnEnter', function(button)
Nenue@70 201 if button.tooltipText then
Nenue@70 202 GameTooltip:SetOwner(button)
Nenue@70 203 GameTooltip:SetText(button.tooltipText)
Nenue@70 204 GameTooltip:Show()
Nenue@70 205 end
Nenue@70 206 end)
Nenue@70 207
Nenue@70 208 tab:SetScript('OnLeave', function(button)
Nenue@70 209 if GameTooltip:IsOwned(button) then
Nenue@70 210 GameTooltip:Hide()
Nenue@70 211 end
Nenue@70 212 end)
Nenue@70 213
Nenue@70 214 tab:SetScript('OnClick', function(button)
Nenue@70 215 self.selectedTabIndex = button:GetID()
Nenue@70 216 self:Update(true)
Nenue@70 217 end)
Nenue@70 218 self.lastTab = tab
Nenue@70 219 end
Nenue@70 220 if text then
Nenue@70 221
Nenue@70 222 tab.Label:SetText(text)
Nenue@70 223 end
Nenue@70 224
Nenue@70 225 if icon then
Nenue@70 226 tab.Icon:SetTexture(icon)
Nenue@70 227 end
Nenue@70 228 if func then
Nenue@70 229 func(tab, index, text)
Nenue@70 230 end
Nenue@70 231
Nenue@70 232 local selected = (index == self.selectedTabIndex)
Nenue@70 233 if selected then
Nenue@70 234 tab.Icon:SetDesaturated(false)
Nenue@70 235 tab.Label:SetTextColor(0,1,0, 1)
Nenue@70 236 else
Nenue@70 237
Nenue@70 238 tab.Icon:SetDesaturated(true)
Nenue@70 239 tab.Label:SetTextColor(1,1,1,0.7)
Nenue@70 240 end
Nenue@70 241
Nenue@70 242 tab.used = true
Nenue@70 243
Nenue@70 244 tab:SetSize(tab.Icon:GetWidth()+tab.Label:GetStringWidth()+3, tab.Icon:GetHeight())
Nenue@70 245 tab:Show()
Nenue@70 246 print(tab:GetPoint(1))
Nenue@70 247 print(tab:GetSize())
Nenue@70 248
Nenue@70 249 return tab
Nenue@70 250 end
Nenue@70 251
Nenue@70 252
Nenue@70 253
Nenue@70 254 --- push current information into living UI
Nenue@70 255 function SkeletonKeyMixin:Update(force)
Nenue@74 256 gprint('|cFFFF8800'..self:GetName()..':Update()|r', InCombatLockdown() and 'combat', self:IsShown())
Nenue@70 257 for index, frame in ipairs(self.Plugins) do
Nenue@70 258 if frame.Update then
Nenue@70 259 frame:Update(force)
Nenue@70 260 end
Nenue@70 261 end
Nenue@70 262
Nenue@70 263 self.currentPanel = self.currentPanel or self.Panels[1]
Nenue@70 264 if InCombatLockdown() or not self:IsShown() then
Nenue@70 265 return
Nenue@70 266 end
Nenue@70 267
Nenue@70 268 self.numTabs = 0
Nenue@70 269 for index, tab in ipairs(self.tabButtons) do
Nenue@70 270 tab.used = nil
Nenue@70 271 tab:Hide()
Nenue@70 272 end
Nenue@70 273
Nenue@70 274 for index, panel in ipairs(self.Panels) do
Nenue@70 275 print(panel:GetName())
Nenue@70 276 if panel == self.currentPanel then
Nenue@70 277 print('Updating panel:', panel:GetName())
Nenue@70 278 panel:SetAllPoints(self.bg)
Nenue@70 279 self.selectedTabIndex, self.scrollOffset = panel:Update(force)
Nenue@70 280 panel:Show()
Nenue@70 281
Nenue@70 282 for tabIndex, info in ipairs(panel.tabButtons) do
Nenue@70 283 self:SetupTabButton(tabIndex, info.label, info.icon, info.func)
Nenue@70 284 end
Nenue@70 285
Nenue@70 286 else
Nenue@70 287 panel:Hide()
Nenue@70 288 end
Nenue@70 289 end
Nenue@70 290
Nenue@70 291
Nenue@70 292
Nenue@70 293 --- Frame Sizing
Nenue@70 294 self.profilebg:SetHeight(TAB_HEIGHT + BUTTON_PADDING * 2 + self.profiletext:GetStringHeight())
Nenue@70 295
Nenue@70 296 self.bg:SetWidth((KEY_BUTTON_SIZE + BUTTON_HSPACING + BUTTON_SPACING) * BINDS_PER_ROW + BUTTON_PADDING*2 - BUTTON_SPACING - BG_INSET*2)
Nenue@70 297 local numRows = NUM_KEY_SLOTS/BINDS_PER_ROW
Nenue@70 298
Nenue@70 299 self.bg:SetHeight((KEY_BUTTON_SIZE + BUTTON_SPACING) * numRows + BUTTON_PADDING*2 - BUTTON_SPACING - BG_INSET*2)
Nenue@70 300
Nenue@70 301
Nenue@70 302 self:SetHeight(self.headerbg:GetHeight() + self.profilebg:GetHeight() + self.bg:GetHeight() + self.footer:GetHeight()+BG_INSET*2)
Nenue@70 303 self:SetWidth(((BINDS_PER_ROW * (KEY_BUTTON_SIZE + BUTTON_HSPACING) + (BINDS_PER_ROW - 1) * BUTTON_SPACING + BUTTON_PADDING * 2) ))
Nenue@70 304
Nenue@70 305
Nenue@70 306 self.backdrop.insets.left = BG_INSET
Nenue@70 307 self.backdrop.insets.right = BG_INSET
Nenue@70 308 self.backdrop.insets.top = BG_INSET
Nenue@70 309 self.backdrop.insets.bottom = BG_INSET
Nenue@70 310 self:SetBackdrop(self.backdrop)
Nenue@70 311 self:SetBackdropColor(unpack(self.backdropColor))
Nenue@70 312 self:SetBackdropBorderColor(unpack(self.backdropBorder))
Nenue@70 313
Nenue@70 314 self:SetScale(self.zoomScale)
Nenue@70 315
Nenue@70 316 self.profiletext:SetText(kb.configHeaders[kb.db.bindMode])
Nenue@70 317 print(kb.db.bindMode, kb.configHeaders[kb.db.bindMode], self:GetSize())
Nenue@70 318 print(self:GetPoint(1))
Nenue@70 319
Nenue@70 320
Nenue@70 321 self:EnableKeyboard((kb.saveTarget and true) or false)
Nenue@70 322 print('keyboard input:', (kb.saveTarget and true) or false)
Nenue@70 323
Nenue@70 324 -- Reset this so talent cache can be rebuilt
Nenue@70 325 kb.talentsPushed = nil
Nenue@70 326 end
Nenue@70 327
Nenue@70 328 local SkeletonKeyPanel = {}
Nenue@70 329 function SkeletonKeyPanel:OnShow()
Nenue@70 330 print('|cFFFFFF00'..self:GetName()..':OnShow()|r')
Nenue@70 331 end
Nenue@70 332
Nenue@70 333 function ActionListPanel:OnLoad()
Nenue@70 334
Nenue@70 335
Nenue@70 336 self.UnbindButton:SetScript('OnClick', function()
Nenue@70 337 self:UnbindSlot(kb.saveTarget)
Nenue@70 338 SkeletonKey:Update()
Nenue@70 339 end)
Nenue@70 340 end
Nenue@70 341
Nenue@70 342 function ActionListPanel:Update(force)
Nenue@70 343 local parent = self:GetParent()
Nenue@70 344 local tabID = parent.selectedTabIndex
Nenue@70 345 local scrollOffset = parent.scrollOffset
Nenue@70 346 if not tabID then
Nenue@70 347 tabID = kb.db.bindMode or BINDING_TYPE_GLOBAL
Nenue@70 348 end
Nenue@70 349 print('|cFF0088FF'..self:GetName()..':Update()|r', 'tab', parent.selectedTabIndex, 'scroll', parent.scrollOffset)
Nenue@70 350
Nenue@70 351 local selectedProfile = kb.loadedProfiles[tabID]
Nenue@70 352 if selectedProfile then
Nenue@70 353 kb.currentProfile = selectedProfile
Nenue@70 354 kb.db.bindMode = tabID
Nenue@70 355 else
Nenue@70 356 tabID = BINDING_TYPE_GLOBAL
Nenue@70 357 end
Nenue@74 358 print(selectedProfile)
Nenue@70 359 scrollOffset = scrollOffset or 0
Nenue@70 360
Nenue@70 361 local leftSlot, upSlot
Nenue@70 362 local buttonTable = self.buttons or {}
Nenue@70 363 for index = 1, NUM_KEY_SLOTS do
Nenue@70 364 if not buttonTable[index] then
Nenue@70 365 local button = CreateFrame('CheckButton', 'KeyBinderSlot'..index, self, 'KeyButton')
Nenue@70 366 local newRow = (mod(index, BINDS_PER_ROW) == 1)
Nenue@70 367
Nenue@70 368 if index == 1 then
Nenue@70 369 button:SetPoint('TOPLEFT', self, 'TOPLEFT', BUTTON_PADDING, - BUTTON_PADDING)
Nenue@70 370 upSlot = button
Nenue@70 371 elseif newRow then
Nenue@70 372 button:SetPoint('TOPLEFT', upSlot, 'BOTTOMLEFT', 0, -BUTTON_SPACING)
Nenue@70 373 upSlot = button
Nenue@70 374 else
Nenue@70 375 button:SetPoint('TOPLEFT', leftSlot, 'TOPRIGHT', BUTTON_HSPACING, 0)
Nenue@70 376 end
Nenue@70 377
Nenue@70 378 button:SetSize(KEY_BUTTON_SIZE, KEY_BUTTON_SIZE)
Nenue@70 379 button:Show()
Nenue@70 380 buttonTable[index] = button
Nenue@70 381 leftSlot = button
Nenue@70 382 end
Nenue@70 383 end
Nenue@70 384 self.buttons = buttonTable
Nenue@70 385
Nenue@70 386 local startIndex = scrollOffset * BINDS_PER_ROW
Nenue@70 387 for i, button in ipairs(self.buttons) do
Nenue@70 388 button:SetID(startIndex+i)
Nenue@70 389 button:UpdateSlot(force)
Nenue@70 390 button:SetFrameLevel(50 + i + (button.isActive and #self.buttons or 0))
Nenue@70 391 end
Nenue@70 392
Nenue@70 393
Nenue@70 394 local r,g,b,a = unpack(BINDING_SCHEME_COLOR[kb.db.bindMode])
Nenue@70 395 self.profileStripe:SetColorTexture(r,g,b)
Nenue@70 396 if kb.saveTarget then
Nenue@70 397 self.bg:SetColorTexture(.2,.5, .2, .5)
Nenue@70 398 self.UnbindButton:SetFrameLevel(kb.saveTarget:GetFrameLevel()-1)
Nenue@70 399 self.UnbindButton:SetPoint('TOPLEFT', kb.saveTarget, 'BOTTOMLEFT', 0, -1)
Nenue@70 400 self.UnbindButton:Show()
Nenue@70 401
Nenue@70 402 else
Nenue@70 403 self.bg:SetColorTexture(.2,.2,.2,1)
Nenue@70 404 self.UnbindButton:Hide()
Nenue@70 405 end
Nenue@70 406
Nenue@70 407 return tabID, scrollOffset
Nenue@70 408 end
Nenue@70 409
Nenue@70 410
Nenue@70 411 function ActionListPanel:ActivateSlot (button)
Nenue@70 412 if kb.saveTarget then
Nenue@70 413 kb.saveTarget.isActive = nil
Nenue@70 414 end
Nenue@70 415 button.isActive = true
Nenue@70 416 kb.saveTarget = button
Nenue@70 417 return true
Nenue@70 418 end
Nenue@70 419
Nenue@70 420 function ActionListPanel:DeactivateSlot (button)
Nenue@70 421 button.isActive = nil
Nenue@70 422 kb.saveTarget = nil
Nenue@70 423 return true
Nenue@70 424 end
Nenue@70 425
Nenue@70 426 function ActionListPanel:OnInput(key)
Nenue@70 427
Nenue@70 428 if key == 'ESCAPE' then
Nenue@70 429 return self:DeactivateSlot(kb.saveTarget)
Nenue@70 430 end
Nenue@70 431
Nenue@70 432 if (match(key, '[RL]SHIFT') or match(key, '[RL]ALT') or match(key, '[RL]CTRL')) then
Nenue@70 433 return
Nenue@70 434 end
Nenue@70 435
Nenue@70 436 if kb.saveTarget then
Nenue@70 437 if kb.saveTarget:SaveSlot(key) then
Nenue@70 438 if not (kb.db.stickyMode or kb.db.hoverInput) then
Nenue@70 439 return self:DeactivateSlot(kb.saveTarget)
Nenue@70 440 end
Nenue@70 441 return true
Nenue@70 442 end
Nenue@70 443 end
Nenue@70 444 end
Nenue@70 445
Nenue@70 446
Nenue@70 447 function SystemBindingsPanel:Update(force)
Nenue@70 448 end
Nenue@70 449
Nenue@70 450 --- Associate processed input with the given slot's metadata
Nenue@70 451 function SkeletonKeyButtonMixin:SaveSlot (key)
Nenue@70 452
Nenue@70 453 if not self.command then
Nenue@70 454 return
Nenue@70 455 end
Nenue@70 456 if InCombatLockdown() then
Nenue@70 457 kb:print(L('Bindings cannot be changed during combat.'))
Nenue@70 458 return
Nenue@70 459 end
Nenue@70 460
Nenue@70 461 local spellName = self.actionName
Nenue@70 462
Nenue@70 463 print('|cFFFFFF00received|cFFFFFF00', self:GetID(), '|cFF00FFFF', key)
Nenue@70 464
Nenue@70 465 local modifier = ''
Nenue@70 466 if IsAltKeyDown() then
Nenue@70 467 modifier = 'ALT-'
Nenue@70 468 end
Nenue@70 469 if IsControlKeyDown() then
Nenue@70 470 modifier = modifier.. 'CTRL-'
Nenue@70 471 end
Nenue@70 472 if IsShiftKeyDown() then
Nenue@70 473 modifier = modifier..'SHIFT-'
Nenue@70 474 end
Nenue@70 475 local binding = modifier..key
Nenue@70 476
Nenue@70 477 -- check for system bindings
Nenue@70 478 --bprint('|cFFFFFF00SaveBind|r', 'protectKeys', kb.db.protectBlizKeys)
Nenue@70 479 if kb.db.protectBlizKeys and kb.SystemBindings[binding] then
Nenue@70 480 kb:print(L('BINDING_FAILED_PROTECTED', binding, kb.SystemBindings[binding]))
Nenue@70 481 return false
Nenue@70 482 end
Nenue@70 483
Nenue@70 484 -- check for other keys
Nenue@70 485 local previousCommand = GetBindingAction(binding)
Nenue@70 486 if previousCommand ~= "" and previousCommand ~= self.command then
Nenue@70 487 local actionType, actionID, name = kb.GetCommandAction(previousCommand)
Nenue@70 488 if actionType then
Nenue@70 489 local keys = {GetBindingKey(previousCommand) }
Nenue@70 490 local i = 1
Nenue@70 491 while keys[i] do
Nenue@70 492 if keys[i] == binding then
Nenue@70 493 tremove(keys, i)
Nenue@70 494 kb.UpdateBindingsCache(actionType, actionID, keys)
Nenue@70 495 break
Nenue@70 496 end
Nenue@70 497 i = i + 1
Nenue@70 498 end
Nenue@70 499 end
Nenue@70 500 end
Nenue@70 501
Nenue@70 502
Nenue@70 503 if self.isAvailable then
Nenue@70 504 print('Binding available spell', binding, self.command)
Nenue@70 505 SetBinding(binding, self.command)
Nenue@70 506 SaveBindings(GetCurrentBindingSet())
Nenue@70 507 self.assignedKeys = {GetBindingKey(self.command) }
Nenue@70 508
Nenue@70 509 kb:print(L('BINDING_ASSIGNED', binding, self.actionName, kb.currentHeader))
Nenue@70 510 else
Nenue@70 511 kb:print(L('UNSELECTED_TALENT_ASSIGNED', binding, self.actionName, kb.currentHeader))
Nenue@70 512 end
Nenue@70 513
Nenue@70 514 if not tContains(self.assignedKeys, binding) then
Nenue@70 515 tinsert(self.assignedKeys, 1, binding)
Nenue@70 516 end
Nenue@70 517
Nenue@70 518
Nenue@70 519 for _, key in ipairs(self.assignedKeys) do
Nenue@70 520 if not kb.currentProfile.bindings[key] then
Nenue@70 521 kb.currentProfile.bindings[key] = self.command
Nenue@70 522 end
Nenue@70 523 end
Nenue@70 524
Nenue@70 525 for level, profile in ipairs(kb.orderedProfiles) do
Nenue@70 526 if (level > kb.db.bindMode) then
Nenue@70 527 profile.bindings[binding] = nil
Nenue@70 528 profile.commands[self.command] = nil
Nenue@70 529 profile.bound[self.command] = nil
Nenue@70 530 end
Nenue@70 531 end
Nenue@70 532
Nenue@70 533 kb.UpdateBindingsCache(self.actionType, self.actionID, self.assignedKeys)
Nenue@70 534
Nenue@70 535 self.binding = binding
Nenue@70 536
Nenue@70 537 return true
Nenue@70 538 end
Nenue@70 539
Nenue@70 540 function SkeletonKeyMixin:OnKeyDown(key)
Nenue@70 541 self:ProcessInput(key)
Nenue@70 542 end
Nenue@70 543 function SkeletonKeyMixin:OnKeyUp(key)
Nenue@70 544 end
Nenue@70 545
Nenue@70 546 function SkeletonKeyMixin:OnDragStart()
Nenue@70 547 self:StartMoving()
Nenue@70 548 end
Nenue@70 549 function SkeletonKeyMixin:OnDragStop()
Nenue@70 550 self:StopMovingOrSizing()
Nenue@70 551 end
Nenue@70 552
Nenue@70 553 function ActionListPanel:UnbindSlot (button)
Nenue@70 554
Nenue@76 555 local configTable = kb.currentProfile.buttons[button:GetID()]
Nenue@70 556 local button = button or kb.saveTarget
Nenue@70 557 if not button then
Nenue@70 558 return
Nenue@70 559 end
Nenue@70 560
Nenue@70 561 local command = button.command
Nenue@70 562 local actionType = button.actionType
Nenue@70 563 local actionID = button.actionID
Nenue@70 564
Nenue@70 565
Nenue@70 566 local talentName = button.actionName
Nenue@70 567 if actionType == 'macro' then
Nenue@70 568 local spellName, _, spellID = GetMacroSpell(actionID)
Nenue@70 569 talentName = spellName
Nenue@70 570 end
Nenue@70 571
Nenue@76 572 local keys = {GetBindingKey(command) }
Nenue@76 573 if configTable and configTable.assignedKeys then
Nenue@76 574 for _, key in ipairs(configTable.assignedKeys) do
Nenue@76 575 if not tContains(keys, key) then
Nenue@76 576 tinsert(keys, key)
Nenue@76 577 end
Nenue@76 578 end
Nenue@76 579 end
Nenue@70 580
Nenue@76 581 -- only manipulate bindings if its an available ability
Nenue@76 582 if button.isAvailable then
Nenue@76 583 --print('detected', #keys, 'bindings')
Nenue@76 584
Nenue@76 585 if #keys >= 1 then
Nenue@76 586 kb.UpdateBindingsCache(actionType, actionID, {})
Nenue@70 587 end
Nenue@70 588
Nenue@76 589 for i, key in pairs(keys) do
Nenue@76 590 --print('clearing', key)
Nenue@76 591 SetBinding(key, nil)
Nenue@76 592 kb.bindings[tostring(actionType)..'_'..tostring(actionID)] = nil
Nenue@76 593 end
Nenue@76 594 SaveBindings(GetCurrentBindingSet())
Nenue@70 595 end
Nenue@76 596
Nenue@76 597
Nenue@76 598 if configTable and configTable.assignedKeys then
Nenue@76 599 table.wipe(configTable.assignedKeys)
Nenue@76 600 end
Nenue@76 601
Nenue@70 602 if kb.currentProfile.bound[command] then
Nenue@70 603 kb.currentProfile.bound[command] = nil
Nenue@70 604 --kb:print(BINDING_REMOVED:format(self.actionName, configHeaders[db.bindMode]))
Nenue@70 605 end
Nenue@70 606 kb.saveTarget = nil
Nenue@76 607 button:UpdateSlot(true)
Nenue@70 608 return true
Nenue@70 609 end
Nenue@70 610
Nenue@70 611 kb.AcceptAssignment = function(self, ...)
Nenue@70 612 local popup = StaticPopupDialogs["SKELETONKEY_CONFIRM_ASSIGN_SLOT"]
Nenue@70 613 local source = kb. loadedProfiles[popup.oldProfile]
Nenue@70 614 popup.slot:SetSlot(unpack(popup.args))
Nenue@70 615 popup.slot:UpdateSlot()
Nenue@70 616 --kb:SetScript('OnMouseWheel', KeyBinder_OnMouseWheel) -- re-enable scrolling
Nenue@70 617 ClearCursor()
Nenue@70 618 ResetCursor()
Nenue@70 619 end
Nenue@70 620
Nenue@70 621 --- Add to blizzard interfaces
Nenue@70 622 StaticPopupDialogs["SKELETONKEY_CONFIRM_ASSIGN_SLOT"] = {
Nenue@70 623 text = "Confirm moving an assigned command.",
Nenue@70 624 button1 = OKAY,
Nenue@70 625 button2 = CANCEL,
Nenue@70 626 timeout = 0,
Nenue@70 627 whileDead = 1,
Nenue@70 628 showAlert = 1,
Nenue@70 629 OnAccept = kb.AcceptAssignment,
Nenue@70 630 --OnCancel = function() kb:SetScript('OnMouseWheel', KeyBinder_OnMouseWheel) end
Nenue@70 631 }
Nenue@70 632
Nenue@70 633
Nenue@70 634
Nenue@70 635
Nenue@70 636 SkeletonKeyActionListMixin = Mixin(ActionListPanel, SkeletonKeyPanel)
Nenue@70 637 SkeletonKeySystemBindingsMixin = Mixin(SystemBindingsPanel, SkeletonKeyPanel)