annotate BindingsFrame.lua @ 74:9824d524a661

- binding slot mixin: - store key binding definitions under their slot's data table - apply action button attributes when a slot is assigned - obtain correct macro body text when a macro is slotted - fix algorithm for resolving renamed macro indices - move spell detail lookup code out of mixin script - event chains: - initialize addon from PLAYER_LOGIN - reload keybinds from PLAYER_SPECIALIZATION_CHANGED, after spec profile is resolved - refresh interface content from SPELLS_CHANGED - hotkey text: - restore communication and detection of key binding updates and reflect them accordingly - properly respond to dynamic bindings that result from talent updates
author Nenue
date Sat, 14 Jan 2017 02:29:33 -0500
parents c48913c5924c
children 6623b7f2c1ca
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@70 171 function SkeletonKeyMixin:OnHide()
Nenue@70 172 KeyBinderImportLog:Hide()
Nenue@70 173 end
Nenue@70 174
Nenue@70 175
Nenue@70 176 local tabID = 0
Nenue@70 177 local prevTab
Nenue@70 178
Nenue@70 179 function SkeletonKeyMixin:SetupTabButton (index, text, icon, func)
Nenue@70 180 print('|cFF00FFFF'..self:GetName()..':SetupTabButton()', index, text, icon, func)
Nenue@70 181 local tabName = 'SkeletonKeyProfileTab'..index
Nenue@70 182 local tab = _G[tabName]
Nenue@70 183
Nenue@70 184 if not tab then
Nenue@70 185 tab = CreateFrame('Button', tabName, self, 'SkeletonKeyTabTemplate')
Nenue@70 186 self.numTabs = self.numTabs + 1
Nenue@70 187 tab:SetID(self.numTabs)
Nenue@70 188 TAB_HEIGHT = tab:GetHeight()
Nenue@70 189
Nenue@70 190 if self.numTabs == 1 then
Nenue@70 191 tab:SetPoint('TOPLEFT', self.profilebg, 'TOPLEFT', BUTTON_PADDING, -BUTTON_SPACING)
Nenue@70 192 else
Nenue@70 193 tab:SetPoint('TOPLEFT', self.lastTab,'TOPRIGHT', BUTTON_SPACING, 0)
Nenue@70 194 end
Nenue@70 195
Nenue@70 196 tab.tooltipText = text
Nenue@70 197 tab:SetScript('OnEnter', function(button)
Nenue@70 198 if button.tooltipText then
Nenue@70 199 GameTooltip:SetOwner(button)
Nenue@70 200 GameTooltip:SetText(button.tooltipText)
Nenue@70 201 GameTooltip:Show()
Nenue@70 202 end
Nenue@70 203 end)
Nenue@70 204
Nenue@70 205 tab:SetScript('OnLeave', function(button)
Nenue@70 206 if GameTooltip:IsOwned(button) then
Nenue@70 207 GameTooltip:Hide()
Nenue@70 208 end
Nenue@70 209 end)
Nenue@70 210
Nenue@70 211 tab:SetScript('OnClick', function(button)
Nenue@70 212 self.selectedTabIndex = button:GetID()
Nenue@70 213 self:Update(true)
Nenue@70 214 end)
Nenue@70 215 self.lastTab = tab
Nenue@70 216 end
Nenue@70 217 if text then
Nenue@70 218
Nenue@70 219 tab.Label:SetText(text)
Nenue@70 220 end
Nenue@70 221
Nenue@70 222 if icon then
Nenue@70 223 tab.Icon:SetTexture(icon)
Nenue@70 224 end
Nenue@70 225 if func then
Nenue@70 226 func(tab, index, text)
Nenue@70 227 end
Nenue@70 228
Nenue@70 229 local selected = (index == self.selectedTabIndex)
Nenue@70 230 if selected then
Nenue@70 231 tab.Icon:SetDesaturated(false)
Nenue@70 232 tab.Label:SetTextColor(0,1,0, 1)
Nenue@70 233 else
Nenue@70 234
Nenue@70 235 tab.Icon:SetDesaturated(true)
Nenue@70 236 tab.Label:SetTextColor(1,1,1,0.7)
Nenue@70 237 end
Nenue@70 238
Nenue@70 239 tab.used = true
Nenue@70 240
Nenue@70 241 tab:SetSize(tab.Icon:GetWidth()+tab.Label:GetStringWidth()+3, tab.Icon:GetHeight())
Nenue@70 242 tab:Show()
Nenue@70 243 print(tab:GetPoint(1))
Nenue@70 244 print(tab:GetSize())
Nenue@70 245
Nenue@70 246 return tab
Nenue@70 247 end
Nenue@70 248
Nenue@70 249
Nenue@70 250
Nenue@70 251 --- push current information into living UI
Nenue@70 252 function SkeletonKeyMixin:Update(force)
Nenue@74 253 gprint('|cFFFF8800'..self:GetName()..':Update()|r', InCombatLockdown() and 'combat', self:IsShown())
Nenue@70 254 for index, frame in ipairs(self.Plugins) do
Nenue@70 255 if frame.Update then
Nenue@70 256 frame:Update(force)
Nenue@70 257 end
Nenue@70 258 end
Nenue@70 259
Nenue@70 260 self.currentPanel = self.currentPanel or self.Panels[1]
Nenue@70 261 if InCombatLockdown() or not self:IsShown() then
Nenue@70 262 return
Nenue@70 263 end
Nenue@70 264
Nenue@70 265 self.numTabs = 0
Nenue@70 266 for index, tab in ipairs(self.tabButtons) do
Nenue@70 267 tab.used = nil
Nenue@70 268 tab:Hide()
Nenue@70 269 end
Nenue@70 270
Nenue@70 271 for index, panel in ipairs(self.Panels) do
Nenue@70 272 print(panel:GetName())
Nenue@70 273 if panel == self.currentPanel then
Nenue@70 274 print('Updating panel:', panel:GetName())
Nenue@70 275 panel:SetAllPoints(self.bg)
Nenue@70 276 self.selectedTabIndex, self.scrollOffset = panel:Update(force)
Nenue@70 277 panel:Show()
Nenue@70 278
Nenue@70 279 for tabIndex, info in ipairs(panel.tabButtons) do
Nenue@70 280 self:SetupTabButton(tabIndex, info.label, info.icon, info.func)
Nenue@70 281 end
Nenue@70 282
Nenue@70 283 else
Nenue@70 284 panel:Hide()
Nenue@70 285 end
Nenue@70 286 end
Nenue@70 287
Nenue@70 288
Nenue@70 289
Nenue@70 290 --- Frame Sizing
Nenue@70 291 self.profilebg:SetHeight(TAB_HEIGHT + BUTTON_PADDING * 2 + self.profiletext:GetStringHeight())
Nenue@70 292
Nenue@70 293 self.bg:SetWidth((KEY_BUTTON_SIZE + BUTTON_HSPACING + BUTTON_SPACING) * BINDS_PER_ROW + BUTTON_PADDING*2 - BUTTON_SPACING - BG_INSET*2)
Nenue@70 294 local numRows = NUM_KEY_SLOTS/BINDS_PER_ROW
Nenue@70 295
Nenue@70 296 self.bg:SetHeight((KEY_BUTTON_SIZE + BUTTON_SPACING) * numRows + BUTTON_PADDING*2 - BUTTON_SPACING - BG_INSET*2)
Nenue@70 297
Nenue@70 298
Nenue@70 299 self:SetHeight(self.headerbg:GetHeight() + self.profilebg:GetHeight() + self.bg:GetHeight() + self.footer:GetHeight()+BG_INSET*2)
Nenue@70 300 self:SetWidth(((BINDS_PER_ROW * (KEY_BUTTON_SIZE + BUTTON_HSPACING) + (BINDS_PER_ROW - 1) * BUTTON_SPACING + BUTTON_PADDING * 2) ))
Nenue@70 301
Nenue@70 302
Nenue@70 303 self.backdrop.insets.left = BG_INSET
Nenue@70 304 self.backdrop.insets.right = BG_INSET
Nenue@70 305 self.backdrop.insets.top = BG_INSET
Nenue@70 306 self.backdrop.insets.bottom = BG_INSET
Nenue@70 307 self:SetBackdrop(self.backdrop)
Nenue@70 308 self:SetBackdropColor(unpack(self.backdropColor))
Nenue@70 309 self:SetBackdropBorderColor(unpack(self.backdropBorder))
Nenue@70 310
Nenue@70 311 self:SetScale(self.zoomScale)
Nenue@70 312
Nenue@70 313 self.profiletext:SetText(kb.configHeaders[kb.db.bindMode])
Nenue@70 314 print(kb.db.bindMode, kb.configHeaders[kb.db.bindMode], self:GetSize())
Nenue@70 315 print(self:GetPoint(1))
Nenue@70 316
Nenue@70 317
Nenue@70 318 self:EnableKeyboard((kb.saveTarget and true) or false)
Nenue@70 319 print('keyboard input:', (kb.saveTarget and true) or false)
Nenue@70 320
Nenue@70 321 -- Reset this so talent cache can be rebuilt
Nenue@70 322 kb.talentsPushed = nil
Nenue@70 323 end
Nenue@70 324
Nenue@70 325 local SkeletonKeyPanel = {}
Nenue@70 326 function SkeletonKeyPanel:OnShow()
Nenue@70 327 print('|cFFFFFF00'..self:GetName()..':OnShow()|r')
Nenue@70 328 end
Nenue@70 329
Nenue@70 330 function ActionListPanel:OnLoad()
Nenue@70 331
Nenue@70 332
Nenue@70 333 self.UnbindButton:SetScript('OnClick', function()
Nenue@70 334 self:UnbindSlot(kb.saveTarget)
Nenue@70 335 SkeletonKey:Update()
Nenue@70 336 end)
Nenue@70 337 end
Nenue@70 338
Nenue@70 339 function ActionListPanel:Update(force)
Nenue@70 340 local parent = self:GetParent()
Nenue@70 341 local tabID = parent.selectedTabIndex
Nenue@70 342 local scrollOffset = parent.scrollOffset
Nenue@70 343 if not tabID then
Nenue@70 344 tabID = kb.db.bindMode or BINDING_TYPE_GLOBAL
Nenue@70 345 end
Nenue@70 346 print('|cFF0088FF'..self:GetName()..':Update()|r', 'tab', parent.selectedTabIndex, 'scroll', parent.scrollOffset)
Nenue@70 347
Nenue@70 348 local selectedProfile = kb.loadedProfiles[tabID]
Nenue@70 349 if selectedProfile then
Nenue@70 350 kb.currentProfile = selectedProfile
Nenue@70 351 kb.db.bindMode = tabID
Nenue@70 352 else
Nenue@70 353 tabID = BINDING_TYPE_GLOBAL
Nenue@70 354 end
Nenue@74 355 print(selectedProfile)
Nenue@70 356 scrollOffset = scrollOffset or 0
Nenue@70 357
Nenue@70 358 local leftSlot, upSlot
Nenue@70 359 local buttonTable = self.buttons or {}
Nenue@70 360 for index = 1, NUM_KEY_SLOTS do
Nenue@70 361 if not buttonTable[index] then
Nenue@70 362 local button = CreateFrame('CheckButton', 'KeyBinderSlot'..index, self, 'KeyButton')
Nenue@70 363 local newRow = (mod(index, BINDS_PER_ROW) == 1)
Nenue@70 364
Nenue@70 365 if index == 1 then
Nenue@70 366 button:SetPoint('TOPLEFT', self, 'TOPLEFT', BUTTON_PADDING, - BUTTON_PADDING)
Nenue@70 367 upSlot = button
Nenue@70 368 elseif newRow then
Nenue@70 369 button:SetPoint('TOPLEFT', upSlot, 'BOTTOMLEFT', 0, -BUTTON_SPACING)
Nenue@70 370 upSlot = button
Nenue@70 371 else
Nenue@70 372 button:SetPoint('TOPLEFT', leftSlot, 'TOPRIGHT', BUTTON_HSPACING, 0)
Nenue@70 373 end
Nenue@70 374
Nenue@70 375 button:SetSize(KEY_BUTTON_SIZE, KEY_BUTTON_SIZE)
Nenue@70 376 button:Show()
Nenue@70 377 buttonTable[index] = button
Nenue@70 378 leftSlot = button
Nenue@70 379 end
Nenue@70 380 end
Nenue@70 381 self.buttons = buttonTable
Nenue@70 382
Nenue@70 383 local startIndex = scrollOffset * BINDS_PER_ROW
Nenue@70 384 for i, button in ipairs(self.buttons) do
Nenue@70 385 button:SetID(startIndex+i)
Nenue@70 386 button:UpdateSlot(force)
Nenue@70 387 button:SetFrameLevel(50 + i + (button.isActive and #self.buttons or 0))
Nenue@70 388 end
Nenue@70 389
Nenue@70 390
Nenue@70 391 local r,g,b,a = unpack(BINDING_SCHEME_COLOR[kb.db.bindMode])
Nenue@70 392 self.profileStripe:SetColorTexture(r,g,b)
Nenue@70 393 if kb.saveTarget then
Nenue@70 394 self.bg:SetColorTexture(.2,.5, .2, .5)
Nenue@70 395 self.UnbindButton:SetFrameLevel(kb.saveTarget:GetFrameLevel()-1)
Nenue@70 396 self.UnbindButton:SetPoint('TOPLEFT', kb.saveTarget, 'BOTTOMLEFT', 0, -1)
Nenue@70 397 self.UnbindButton:Show()
Nenue@70 398
Nenue@70 399 else
Nenue@70 400 self.bg:SetColorTexture(.2,.2,.2,1)
Nenue@70 401 self.UnbindButton:Hide()
Nenue@70 402 end
Nenue@70 403
Nenue@70 404 return tabID, scrollOffset
Nenue@70 405 end
Nenue@70 406
Nenue@70 407
Nenue@70 408 function ActionListPanel:ActivateSlot (button)
Nenue@70 409 if kb.saveTarget then
Nenue@70 410 kb.saveTarget.isActive = nil
Nenue@70 411 end
Nenue@70 412 button.isActive = true
Nenue@70 413 kb.saveTarget = button
Nenue@70 414 return true
Nenue@70 415 end
Nenue@70 416
Nenue@70 417 function ActionListPanel:DeactivateSlot (button)
Nenue@70 418 button.isActive = nil
Nenue@70 419 kb.saveTarget = nil
Nenue@70 420 return true
Nenue@70 421 end
Nenue@70 422
Nenue@70 423 function ActionListPanel:OnInput(key)
Nenue@70 424
Nenue@70 425 if key == 'ESCAPE' then
Nenue@70 426 return self:DeactivateSlot(kb.saveTarget)
Nenue@70 427 end
Nenue@70 428
Nenue@70 429 if (match(key, '[RL]SHIFT') or match(key, '[RL]ALT') or match(key, '[RL]CTRL')) then
Nenue@70 430 return
Nenue@70 431 end
Nenue@70 432
Nenue@70 433 if kb.saveTarget then
Nenue@70 434 if kb.saveTarget:SaveSlot(key) then
Nenue@70 435 if not (kb.db.stickyMode or kb.db.hoverInput) then
Nenue@70 436 return self:DeactivateSlot(kb.saveTarget)
Nenue@70 437 end
Nenue@70 438 return true
Nenue@70 439 end
Nenue@70 440 end
Nenue@70 441 end
Nenue@70 442
Nenue@70 443
Nenue@70 444 function SystemBindingsPanel:Update(force)
Nenue@70 445 end
Nenue@70 446
Nenue@70 447 --- Associate processed input with the given slot's metadata
Nenue@70 448 function SkeletonKeyButtonMixin:SaveSlot (key)
Nenue@70 449
Nenue@70 450 if not self.command then
Nenue@70 451 return
Nenue@70 452 end
Nenue@70 453 if InCombatLockdown() then
Nenue@70 454 kb:print(L('Bindings cannot be changed during combat.'))
Nenue@70 455 return
Nenue@70 456 end
Nenue@70 457
Nenue@70 458 local spellName = self.actionName
Nenue@70 459
Nenue@70 460 print('|cFFFFFF00received|cFFFFFF00', self:GetID(), '|cFF00FFFF', key)
Nenue@70 461
Nenue@70 462 local modifier = ''
Nenue@70 463 if IsAltKeyDown() then
Nenue@70 464 modifier = 'ALT-'
Nenue@70 465 end
Nenue@70 466 if IsControlKeyDown() then
Nenue@70 467 modifier = modifier.. 'CTRL-'
Nenue@70 468 end
Nenue@70 469 if IsShiftKeyDown() then
Nenue@70 470 modifier = modifier..'SHIFT-'
Nenue@70 471 end
Nenue@70 472 local binding = modifier..key
Nenue@70 473
Nenue@70 474 -- check for system bindings
Nenue@70 475 --bprint('|cFFFFFF00SaveBind|r', 'protectKeys', kb.db.protectBlizKeys)
Nenue@70 476 if kb.db.protectBlizKeys and kb.SystemBindings[binding] then
Nenue@70 477 kb:print(L('BINDING_FAILED_PROTECTED', binding, kb.SystemBindings[binding]))
Nenue@70 478 return false
Nenue@70 479 end
Nenue@70 480
Nenue@70 481 -- check for other keys
Nenue@70 482 local previousCommand = GetBindingAction(binding)
Nenue@70 483 if previousCommand ~= "" and previousCommand ~= self.command then
Nenue@70 484 local actionType, actionID, name = kb.GetCommandAction(previousCommand)
Nenue@70 485 if actionType then
Nenue@70 486 local keys = {GetBindingKey(previousCommand) }
Nenue@70 487 local i = 1
Nenue@70 488 while keys[i] do
Nenue@70 489 if keys[i] == binding then
Nenue@70 490 tremove(keys, i)
Nenue@70 491 kb.UpdateBindingsCache(actionType, actionID, keys)
Nenue@70 492 break
Nenue@70 493 end
Nenue@70 494 i = i + 1
Nenue@70 495 end
Nenue@70 496 end
Nenue@70 497 end
Nenue@70 498
Nenue@70 499
Nenue@70 500 if self.isAvailable then
Nenue@70 501 print('Binding available spell', binding, self.command)
Nenue@70 502 SetBinding(binding, self.command)
Nenue@70 503 SaveBindings(GetCurrentBindingSet())
Nenue@70 504 self.assignedKeys = {GetBindingKey(self.command) }
Nenue@70 505
Nenue@70 506 kb:print(L('BINDING_ASSIGNED', binding, self.actionName, kb.currentHeader))
Nenue@70 507 else
Nenue@70 508 kb:print(L('UNSELECTED_TALENT_ASSIGNED', binding, self.actionName, kb.currentHeader))
Nenue@70 509 end
Nenue@70 510
Nenue@70 511 if not tContains(self.assignedKeys, binding) then
Nenue@70 512 tinsert(self.assignedKeys, 1, binding)
Nenue@70 513 end
Nenue@70 514
Nenue@71 515 local talentInfo = kb.DynamicSpells[spellName]
Nenue@71 516 if spellName and talentInfo then
Nenue@70 517 print('store dynamicType talent')
Nenue@71 518 if talentInfo.dynamicType == 'talent' then
Nenue@71 519 talentInfo = {
Nenue@71 520 macroName = self.macroName,
Nenue@71 521 actionName = self.actionName,
Nenue@71 522 actionType = self.actionType,
Nenue@71 523 actionID = self.actionID,
Nenue@71 524 assignedKeys = self.assignedKeys
Nenue@71 525 }
Nenue@71 526 kb.currentProfile.talents[spellName] = talentInfo
Nenue@71 527 end
Nenue@70 528 end
Nenue@70 529
Nenue@70 530 for _, key in ipairs(self.assignedKeys) do
Nenue@70 531 if not kb.currentProfile.bindings[key] then
Nenue@70 532 kb.currentProfile.bindings[key] = self.command
Nenue@70 533 end
Nenue@70 534 end
Nenue@70 535
Nenue@70 536 for level, profile in ipairs(kb.orderedProfiles) do
Nenue@70 537 if (level > kb.db.bindMode) then
Nenue@70 538 profile.bindings[binding] = nil
Nenue@70 539 profile.commands[self.command] = nil
Nenue@70 540 profile.bound[self.command] = nil
Nenue@70 541 if spellName then
Nenue@70 542 profile.talents[spellName] = nil
Nenue@70 543 end
Nenue@70 544 end
Nenue@70 545 end
Nenue@70 546
Nenue@70 547 kb.UpdateBindingsCache(self.actionType, self.actionID, self.assignedKeys)
Nenue@70 548
Nenue@70 549 self.binding = binding
Nenue@70 550
Nenue@70 551 return true
Nenue@70 552 end
Nenue@70 553
Nenue@70 554 function SkeletonKeyMixin:OnKeyDown(key)
Nenue@70 555 self:ProcessInput(key)
Nenue@70 556 end
Nenue@70 557 function SkeletonKeyMixin:OnKeyUp(key)
Nenue@70 558 end
Nenue@70 559
Nenue@70 560 function SkeletonKeyMixin:OnDragStart()
Nenue@70 561 self:StartMoving()
Nenue@70 562 end
Nenue@70 563 function SkeletonKeyMixin:OnDragStop()
Nenue@70 564 self:StopMovingOrSizing()
Nenue@70 565 end
Nenue@70 566
Nenue@70 567 function ActionListPanel:UnbindSlot (button)
Nenue@70 568
Nenue@70 569 local button = button or kb.saveTarget
Nenue@70 570 if not button then
Nenue@70 571 return
Nenue@70 572 end
Nenue@70 573
Nenue@70 574 local command = button.command
Nenue@70 575 local actionType = button.actionType
Nenue@70 576 local actionID = button.actionID
Nenue@70 577
Nenue@70 578 local keys = {GetBindingKey(command) }
Nenue@70 579 if #keys >= 1 then
Nenue@70 580 kb.UpdateBindingsCache(actionType, actionID, {})
Nenue@70 581 end
Nenue@70 582
Nenue@70 583 local talentName = button.actionName
Nenue@70 584 if actionType == 'macro' then
Nenue@70 585 local spellName, _, spellID = GetMacroSpell(actionID)
Nenue@70 586 talentName = spellName
Nenue@70 587 end
Nenue@70 588
Nenue@70 589
Nenue@70 590 --print('detected', #keys, 'bindings')
Nenue@70 591 for i, key in pairs(keys) do
Nenue@70 592 --print('clearing', key)
Nenue@70 593 SetBinding(key, nil)
Nenue@70 594 SaveBindings(GetCurrentBindingSet())
Nenue@70 595 if kb.currentProfile.bindings[key] then
Nenue@70 596 --kb:print(L('BINDING_REMOVED', self.actionName, kb.currentHeader))
Nenue@70 597 kb.currentProfile.bindings[key] = nil
Nenue@70 598 end
Nenue@70 599 if kb.currentProfile.talents[talentName] then
Nenue@70 600 kb.currentProfile.talents[talentName] = nil
Nenue@70 601 end
Nenue@70 602
Nenue@70 603 kb.bindings[tostring(actionType)..'_'..tostring(actionID)] = nil
Nenue@70 604 end
Nenue@70 605 if kb.currentProfile.bound[command] then
Nenue@70 606 kb.currentProfile.bound[command] = nil
Nenue@70 607 --kb:print(BINDING_REMOVED:format(self.actionName, configHeaders[db.bindMode]))
Nenue@70 608 end
Nenue@70 609 kb.saveTarget = nil
Nenue@70 610
Nenue@70 611 return true
Nenue@70 612 end
Nenue@70 613
Nenue@70 614 kb.AcceptAssignment = function(self, ...)
Nenue@70 615 local popup = StaticPopupDialogs["SKELETONKEY_CONFIRM_ASSIGN_SLOT"]
Nenue@70 616 local source = kb. loadedProfiles[popup.oldProfile]
Nenue@70 617 popup.slot:SetSlot(unpack(popup.args))
Nenue@70 618 popup.slot:UpdateSlot()
Nenue@70 619 --kb:SetScript('OnMouseWheel', KeyBinder_OnMouseWheel) -- re-enable scrolling
Nenue@70 620 ClearCursor()
Nenue@70 621 ResetCursor()
Nenue@70 622 end
Nenue@70 623
Nenue@70 624 --- Add to blizzard interfaces
Nenue@70 625 StaticPopupDialogs["SKELETONKEY_CONFIRM_ASSIGN_SLOT"] = {
Nenue@70 626 text = "Confirm moving an assigned command.",
Nenue@70 627 button1 = OKAY,
Nenue@70 628 button2 = CANCEL,
Nenue@70 629 timeout = 0,
Nenue@70 630 whileDead = 1,
Nenue@70 631 showAlert = 1,
Nenue@70 632 OnAccept = kb.AcceptAssignment,
Nenue@70 633 --OnCancel = function() kb:SetScript('OnMouseWheel', KeyBinder_OnMouseWheel) end
Nenue@70 634 }
Nenue@70 635
Nenue@70 636
Nenue@70 637
Nenue@70 638
Nenue@70 639 SkeletonKeyActionListMixin = Mixin(ActionListPanel, SkeletonKeyPanel)
Nenue@70 640 SkeletonKeySystemBindingsMixin = Mixin(SystemBindingsPanel, SkeletonKeyPanel)