changeset 72:c48913c5924c

- Dynamic bindings properly update between talent choices, and the hotkey text is also correctly reflected.
author Nenue
date Sat, 07 Jan 2017 12:47:41 -0500
parents ca3118127e5e
children 68365bda5ab5
files ActionTemplates.lua BindingsFrame.lua Events.lua HotKey.lua KeyButton.lua SkeletonKey.lua
diffstat 6 files changed, 57 insertions(+), 74 deletions(-) [+]
line wrap: on
line diff
--- a/ActionTemplates.lua	Fri Jan 06 16:21:49 2017 -0500
+++ b/ActionTemplates.lua	Sat Jan 07 12:47:41 2017 -0500
@@ -150,23 +150,24 @@
     local indexKey = actionType..'_'..actionID
     local actionPrefix = "*"..actionType.."-"
     local button = SkeletonKeyKey
-    local isAvailable = true
+    local isAvailable
     local specialButtonType
     if actionType == 'spell' then
-      if not GetSpellInfo(actionID) then
-        isAvailable = nil
+      cprint(GetSpellInfo(actionID))
+      cprint(GetSpellInfo(name))
+      if GetSpellInfo(name) then
+        isAvailable = true
       end
       local dynamicInfo = kb.DynamicSpells[name]
       if dynamicInfo then
         configTable.assignedKeys = configTable.assignedKeys or {GetBindingKey(configTable.command)}
-        cprint('|cFF00FFFFDynamicInfo:|r', dynamicInfo.dynamicType, table.concat(configTable.assignedKeys or {}, ','))
+        cprint('|cFF00FFFFDynamicInfo:|r', dynamicInfo.dynamicType, table.concat(configTable.assignedKeys, ','))
         for k, v in pairs(dynamicInfo) do
           --cprint(' --', k, v)
           configTable[k] = v
         end
       end
 
-
     else
       if actionType ~= 'macro' then
         actionPrefix = '*macrotext-'
@@ -175,20 +176,26 @@
       specialButtonType = 'macro'
     end
 
-    local attributeSuffix, attributeValue, command, target, button =  kb.RegisterAction(actionType, actionID, name)
-    local actionKey = actionPrefix .. attributeSuffix
-    cprint('|cFF00FF88LoadBinding()|r', button:GetName(), "*type-"..attributeSuffix, actionType,  '|cFFFFFF00'..actionKey, attributeValue)
+    if isAvailable then
 
+      local attributeSuffix, attributeValue, command, target, button =  kb.RegisterAction(actionType, actionID, name)
+      local actionKey = actionPrefix .. attributeSuffix
+      cprint('|cFF00FF88LoadBinding()|r', button:GetName(), "*type-"..attributeSuffix, actionType,  '|cFFFFFF00'..actionKey, attributeValue, isAvailable)
 
 
-
-    if isAvailable then
       kb.SecureAttribute(button, "*type-"..attributeSuffix, specialButtonType or actionType)
       kb.SecureAttribute(button, actionKey, attributeValue)
+
+      cprint('|cFFFF4400add', name, isAvailable, indexKey, unpack(configTable.assignedKeys))
       kb.bindings[indexKey] = configTable.assignedKeys
       commandActions[command] = kb.bindings[indexKey]
       return command, kb.bindings[indexKey]
     else
+      if kb.bindings[indexKey] then
+        cprint('|cFFFF4400remove', name, isAvailable, indexKey, unpack(configTable.assignedKeys))
+        kb.bindings[indexKey] = nil
+      end
+
       return nil
     end
   end
@@ -304,11 +311,9 @@
         if not configTable.assignedKeys then
           configTable.assignedKeys = {GetBindingKey(configTable.command) }
         end
-        configTable.isAvailable = true
         if configTable.dynamicType then
           kb:print(table.concat(configTable.assignedKeys, ', ') .. ' bound to '.. configTable.actionName)
         end
-
       end
     end
   end
@@ -335,6 +340,7 @@
     kb.UpdateProfessionInfo()
 
     SaveBindings(GetCurrentBindingSet())
+
   end
 end
 
--- a/BindingsFrame.lua	Fri Jan 06 16:21:49 2017 -0500
+++ b/BindingsFrame.lua	Sat Jan 07 12:47:41 2017 -0500
@@ -633,22 +633,6 @@
 
 
 
-do
-  local MACRO_SELECTED_ID = 1
-  local MACRO_SELECTED_NAME = GetMacroInfo(1)
-  kb.CreateMacroHooks = function()
-    print('|cFF00FF00setting up MacroUI hooks')
-    hooksecurefunc("MacroFrame_SelectMacro", function(id)
-      print('|cFF0088FFMacroFrame_SelectMacro|r', id)
-      MACRO_SELECTED_ID = id
-      for k,v in pairs(kb.bindings) do
-        --print(k,v)
-      end
-
-    end)
-  end
-end
-
 
 SkeletonKeyActionListMixin = Mixin(ActionListPanel, SkeletonKeyPanel)
 SkeletonKeySystemBindingsMixin = Mixin(SystemBindingsPanel, SkeletonKeyPanel)
\ No newline at end of file
--- a/Events.lua	Fri Jan 06 16:21:49 2017 -0500
+++ b/Events.lua	Sat Jan 07 12:47:41 2017 -0500
@@ -8,11 +8,8 @@
 local print = (DEVIAN_PNAME == 'SkeletonKey') and function(...) _G.print('SkeletonKey', ...) end or function() end
 
 
-kb.ADDON_LOADED = function(_, _, addon)
+kb.PLAYER_LOGIN = function(_, _, addon)
 
-  if addon == 'Blizzard_MacroUI' then
-    kb.CreateMacroHooks()
-  end
 end
 
 kb.PLAYER_REGEN_DISABLED = function()
@@ -28,17 +25,19 @@
 end
 
 kb.PLAYER_SPECIALIZATION_CHANGED =  function(...)
+
   kb.UpdateSpecInfo()
   kb.UpdateTalentInfo()
+
   kb.SelectProfileSet(kb.profileName)
   kb.ApplyAllBindings()
   SkeletonKey:Update(true)
 end
 kb.PLAYER_TALENT_UPDATE = function()
-  kb.UpdateTalentInfo()
-  kb.SelectProfileSet(kb.profileName)
-  kb.ApplyAllBindings()
-  SkeletonKey:Update()
+  --kb.UpdateTalentInfo()
+  --kb.SelectProfileSet(kb.profileName)
+  --kb.ApplyAllBindings()
+  --SkeletonKey:Update()
 end
 kb.ACTIONBAR_SLOT_CHANGED = function(self, event, slot)
   --kb.HotKeyText(slot)
--- a/HotKey.lua	Fri Jan 06 16:21:49 2017 -0500
+++ b/HotKey.lua	Sat Jan 07 12:47:41 2017 -0500
@@ -34,7 +34,6 @@
   ["PLAYER_ENTERING_WORLD"] = {"world","all"},
   ["PET_UI_UPDATE"] = {"pet"},
   ["PLAYER_SPECIALIZATION_CHANGED"] = {"player"},
-  ["PLAYER_TALENTS_UPDATED"] = {"player"},
 }
 
 
@@ -91,14 +90,15 @@
 
 end
 
+
 function hotkey:Update()
   print('--|cFF00FF00ui|r')
   self:player()
   hotkey:pet()
   hotkey:binding()
+  kb.UpdateHotKeys = function() self:Update() end
 end
 
-
 function hotkey:world()
   print('--|cFF00FF00world|r')
   -- needs to be delayed so it isn't fired 50 times at login
@@ -115,7 +115,7 @@
 -- requires all these arguments since non-actionbar buttons don't have all of said methods
 local kprint = (DEVIAN_WORKSPACE and function(...) _G.print('HotKeyUpdate', ...) end) or function() end
 function hotkey:UpdateHotKey(frame, actionType, actionID, hasAction)
-  bindings = kb.GetBindings()
+
 
   if hasAction then
     local indexKey = kb.FormatActionID(actionType, actionID)
@@ -134,7 +134,7 @@
     end
     kprint('  actionKey:', indexKey)
 
-    local binds = bindings[indexKey]
+    local binds = kb.bindings[indexKey]
     if binds and (not frame.HotKey:IsVisible()) then
       kprint(frame:GetName(), '|cFF88FF00'..indexKey..'|r',  hasAction, actionName)
       local bindingsText = kb.BindingString(unpack(binds))
--- a/KeyButton.lua	Fri Jan 06 16:21:49 2017 -0500
+++ b/KeyButton.lua	Sat Jan 07 12:47:41 2017 -0500
@@ -312,6 +312,10 @@
 
   if self.command then
 
+    print('|cFFFF4400', self.actionName, #self.assignedKeys, self.assignedKeys)
+    print(table.concat(self.assignedKeys, ','))
+    print(self.actionID)
+    self.bindingText= kb.BindingString(unpack(self.assignedKeys))
     if not self.isAvailable then
       borderType = BORDER_DYNAMIC
       self.ignoreTexture:Show()
@@ -327,7 +331,6 @@
       end
     end
 
-
     if self.actionType == 'macro' then
       self.macro:Show()
     else
@@ -346,29 +349,14 @@
 
     if self.dynamicType == 'profession'  then
       if self.isAvailable then
-
         self.statusText = '|cFFFFFF00Profession|r'
-        self.bindingText = kb.BindingString(GetBindingKey(self.command))
       else
 
         self.statusText = '|cFFFF4400'..PROFESSION_HEADERS[self.dynamicIndex]..'|r'
         self.actionName = '(#'..self.dynamicIndex..')'
-        self.bindingText ='?'
       end
     elseif self.dynamicType == 'talent' then
       self.statusText = '|cFF00FFFF'.. TALENT .. '|r'
-      if self.isAvailable then
-        self.bindingText = kb.BindingString(GetBindingKey(self.command))
-      else
-
-        print('|cFFFF4400', self.actionName, #self.assignedKeys, self.assignedKeys)
-        print(self.actionID)
-        self.bindingText= kb.BindingString(self.assignedKeys)
-      end
-    elseif self.dynamicType == 'petaction' then
-      self.bindingText = kb.BindingString(GetBindingKey(self.command))
-    else
-      self.bindingText = kb.BindingString(GetBindingKey(self.command))
     end
 
     local locked, layer = kb.IsCommandBound(self)
@@ -493,14 +481,14 @@
   local spellName, spellID, command, icon = self.actionName, self.actionID, self.command, self.iconPath
 
 
-  cprint(' In:', spellName, spellID, command)
-  cprint(GetSpellInfo(spellName or spellID))
+  print(' In:', spellName, spellID, command)
+  print(GetSpellInfo(spellName or spellID))
   local internalName, _, internalIcon, _, _, _, _ = GetSpellInfo(spellName or spellID)
   local isAvailable = internalName and true
 
   if internalName and (internalName ~= spellName) then
     -- it's a binding for the originating spell, leave it as is
-    cprint('  |cFFFF4400spell is an override(', internalName, '~=', spellName,') leave the name info alone')
+    print('  |cFFFF4400spell is an override(', internalName, '~=', spellName,') leave the name info alone')
     self.statusText = '|cFFFFFF00Spell|r'
     self.isAvailable = true
     return
@@ -511,17 +499,17 @@
   if not info then
     local dynamicType, dynamicIndex, dynamicSubIndex = command:match("(%a+)_(%S+)_(%S+)")
     if kb.DynamicSpells[dynamicType] then
-      cprint('|cFFFF4400resolving dynamic type index:', internalName, spellName, command)
+      print('|cFFFF4400resolving dynamic type index:', internalName, spellName, command)
       dynamicIndex = tonumber(dynamicIndex)
       dynamicSubIndex = tonumber(dynamicSubIndex)
       local cache = kb.DynamicSpells[dynamicType]
-      cprint('type:', dynamicType)
+      print('type:', dynamicType)
       if dynamicIndex and cache[dynamicIndex] then
         info = kb.DynamicSpells[dynamicType][dynamicIndex]
-        cprint('index:', dynamicIndex)
+        print('index:', dynamicIndex)
         if dynamicSubIndex and info[dynamicSubIndex] then
           info = info[dynamicSubIndex]
-          cprint('sub-index:', dynamicSubIndex)
+          print('sub-index:', dynamicSubIndex)
         end
         isAvailable = true
       end
@@ -532,7 +520,7 @@
   end
   info.isAvailable = isAvailable
 
-  cprint('|cFF00FF88SpellDetails:|r', info.actionName, info.actionID, info.dynamicType, info.isAvailable)
+  print('|cFF00FF88SpellDetails:|r', info.actionName, info.actionID, info.dynamicType, info.isAvailable)
   for k,v in pairs(info) do
     --cprint(' ',k,v)
     self[k] = v
@@ -599,14 +587,16 @@
               if (searchName == name) and (searchBody == macroText) then
                 -- complete match
                 actionID = i
+                kb:print('Macro index changed: |cFFFFFF00', actionType, '|r', name, '(was '..tostring(prevIndex)..', now '..tostring(actionID)..')')
                 break
               elseif (searchName == name) or (searchBody == macroText) then
                 -- partial match, continue the search
                 actionID = i
+                kb:print('Macro index changed: |cFFFFFF00', actionType, '|r', name, '(was '..tostring(prevIndex)..', now '..tostring(actionID)..')')
               end
             end
           end
-          kb:print('Macro index changed: |cFFFFFF00', actionType, '|r', name, '(was '..tostring(prevIndex)..', now '..tostring(actionID)..')')
+
         end
       else
         actionID = GetMacroIndexByName(name)
@@ -621,18 +611,20 @@
     end
 
     if self.isAvailable then
-      local oldCommand = command
-      command = kb.LoadBinding(self)
-      if oldCommand ~= command then
+      --[[
+      local checkCommand = command
+      checkCommand = kb.LoadBinding(self)
+      if checkCommand and (checkCommand ~= command) then
         print('|cFFFF4400fixing command string', actionType, actionID, name)
-        kb.currentProfile.bound[oldCommand] = nil
-        kb.currentProfile.bound[command] = slot
+        kb.currentProfile.bound[command] = nil
+        kb.currentProfile.bound[checkCommand] = slot
         for k,v in pairs(kb.currentProfile.bindings) do
-          if v == oldCommand then
-            kb.currentProfile.bindings[k] = command
+          if v == command then
+            kb.currentProfile.bindings[k] = checkCommand
           end
         end
       end
+      --]]
     end
 
 
--- a/SkeletonKey.lua	Fri Jan 06 16:21:49 2017 -0500
+++ b/SkeletonKey.lua	Sat Jan 07 12:47:41 2017 -0500
@@ -8,7 +8,8 @@
 -- Header script
 
 local addonName, kb = ...
-local print = DEVIAN_WORKSPACE and function(...) print('SK',...) end or nop
+local print = DEVIAN_WORKSPACE and function(...) _G.print('SK',...) end or nop
+local cprint = DEVIAN_WORKSPACE and function(...) _G.print('Cfg',...) end or nop
 SkeletonKeyMixin = {
   scrollCache = {},
   tabButtons = {},
@@ -69,7 +70,7 @@
 kb.orderedProfiles = {}
 kb.buttons = {}
 kb.macros = {}
-kb.bindings = {}
+kb.bindings = setmetatable({}, {__newindex = function(t,k,v) rawset(t,k,v) cprint('adding', k, v) end})
 kb.petFrames = {} -- pet data is slightly delayed, their buttons are indexed here so they can be refreshed
 kb.talentFrames = {}
 kb.professionFrames = {}
@@ -316,6 +317,7 @@
   print('|cFF0088FF'..self:GetName()..':OnLoad()')
 
   self.CloseButton:SetScript('OnClick', CloseButton_OnClick)
+  self:RegisterEvent('PLAYER_LOGIN')
   self:RegisterEvent('PLAYER_ENTERING_WORLD')
   self:RegisterEvent('ADDON_LOADED')
   self:EnableKeyboard(false)