annotate BindingsFrame.lua @ 80:b9a53385462c

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