changeset 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 04c23ceaf9e0
children 178d489f387c
files SkeletonKey/ActionTemplates.lua SkeletonKey/BindingsFrame.lua SkeletonKey/HotKey.lua SkeletonKey/KeyButton.lua
diffstat 4 files changed, 94 insertions(+), 56 deletions(-) [+]
line wrap: on
line diff
--- a/SkeletonKey/ActionTemplates.lua	Mon Sep 05 14:56:38 2016 -0400
+++ b/SkeletonKey/ActionTemplates.lua	Thu Sep 08 16:52:55 2016 -0400
@@ -147,10 +147,12 @@
 
 
 do
+  local commandActions = {}
   local bindings = kb.bindings
   local key, macro = KeyBinderKey, KeyBinderMacro
   kb.LoadBinding = function(command, name, icon, actionType, actionID, macroName, macroText )
 
+    local indexKey = actionType..'_'..actionID
     local buttonTypeKey, buttonTypeValue = "*type-"..name, actionType
     local buttonActionKey, buttonActionValue = "*"..actionType.."-"..name, actionID
     local button = key
@@ -177,33 +179,31 @@
     end
 
     --cprint(actionType, actionID, name)
-    --cprint(button:GetName(), buttonTypeKey,'=', buttonTypeValue)
     kb.SecureAttribute(button, buttonTypeKey, buttonTypeValue)
     if buttonActionKey then
       --cprint(button:GetName(), buttonActionKey,'=', buttonActionValue)
       kb.SecureAttribute(button, buttonActionKey, buttonActionValue)
     end
 
-    local indexKey = actionType..'_'..actionID
-    bindings[indexKey] = bindings[indexKey] or {}
-    bindings[command] = bindings[indexKey]
+    kb.bindings[indexKey] = kb.bindings[indexKey] or {}
+    kb.bindings[command] = kb.bindings[indexKey]
+    commandActions[command] = indexKey
     return bindings[indexKey], actionID
   end
 
   kb.ApplyBindings = function (profile)
     --cprint('binding profile', profile)
+
     for slot, data in pairs(profile.buttons) do
-      kb.LoadBinding(unpack(data))
+      local bindsTable, actionID = kb.LoadBinding(unpack(data))
+      local command = data[1]
     end
 
     for key, command in pairs(profile.bindings) do
-
-      --cprint(' *', key, '->', command)
-
-      --_G.print('HotKey','loading', key, command)
+      cprint('|cFF00FFFF'.. key .. '|r to|cFF00FF00', command, commandActions[command])
       SetBinding(key, command)
-      if bindings[command] and not tContains(bindings[command], key) then
-        tinsert(bindings[command], key)
+      if kb.bindings[command] then
+        tinsert(kb.bindings[command], key)
       end
     end
 
@@ -215,7 +215,7 @@
         --cprint('|cFFBBFF00Active:|r', dummy)
         local macroName, spellName, actionType, actionID = unpack(talentInfo)
         local indexKey = actionType .. '_' .. actionID
-        bindings[indexKey] = {}
+        kb.bindings[indexKey] = {}
         func = kb.ApplyTalentBinding
         dest = kb.bindings[indexKey]
       else
@@ -230,7 +230,7 @@
   kb.ApplyAllBindings =function ()
     wipe(kb.TalentBindings)
     wipe(kb.bindings)
-    kb:print('Loading binding profile', kb.profileName)
+    --kb:print('Loading binding profile', kb.profileName)
 
     -- reflect action key settings
     if GetCVarBool("ActionButtonUseKeyDown") then
@@ -247,7 +247,6 @@
     -- do this after to ensure that profession binds are properly overridden
     kb.UpdateProfessionInfo()
 
-
     SaveBindings(GetCurrentBindingSet())
   end
 end
@@ -259,6 +258,13 @@
   kb.specInfo.globalID, kb.specInfo.name, kb.specInfo.desc, kb.specInfo.texture = GetSpecializationInfo(kb.specInfo.id)
 end
 
+kb.UpdateMacroInfo =  function()
+  for i = 1, GetNumMacros() do
+    local name = GetMacroInfo(index)
+    kb.SecureAttribute(KeyBinderMacro, "*macro_"..tostring(name), i)
+  end
+end
+
 kb.UpdateTalentInfo = function()
   if kb.talentsPushed then
     return
@@ -488,7 +494,7 @@
 
   else
 
-    --print(target:GetName(), 'attribute', '"'.. tostring(name)..'" = "'..tostring(value)..'"')
+    cprint('|cFFFF4444' .. target:GetName()..'|r.|cFFFFFF00'.. tostring(name)..'|r = "'..tostring(value)..'"')
     target:SetAttribute(name, value)
   end
 end
@@ -499,6 +505,7 @@
     while args do
       local target, name, value = unpack(args)
       --print(target:GetName(), 'attribute', '"'.. tostring(name)..'" = "'..tostring(value)..'"')
+      cprint('deferred', target:GetName(), 'attribute', '"'.. tostring(name)..'" = "'..tostring(value)..'"')
       target:SetAttribute(name, value)
       args = tremove(kb.pendingAttributes)
     end
--- a/SkeletonKey/BindingsFrame.lua	Mon Sep 05 14:56:38 2016 -0400
+++ b/SkeletonKey/BindingsFrame.lua	Thu Sep 08 16:52:55 2016 -0400
@@ -595,8 +595,13 @@
   SaveBindings(GetCurrentBindingSet())
   self.binding = binding
 
+  local talentName = self.actionName
+  if self.actionType == 'macro' then
+    talentName = GetMacroSpell(self.actionID)
+  end
+
   local talentInfo
-  if self.actionType == 'spell' and kb.TalentCache[self.actionID] then
+  if talentName and kb.TalentCache[talentName] then
     print('store dynamicType talent')
     talentInfo = {self.macroName, self.actionName, self.actionType, self.actionID}
     local bindings = {GetBindingKey(self.command) }
@@ -613,14 +618,11 @@
       else
         profile.bindings[self.binding] = self.command
       end
-      profile.talents[self.actionName] = talentInfo
+      profile.talents[talentName] = talentInfo
     else
       profile.bindings[self.binding] = nil
       profile.bound[self.command] = nil
-      kb.currentProfile.talents[self.actionName] = nil
-    end
-    if kb.currentProfile.talents[self.actionID] then
-      kb.currentProfile.talents[self.actionID] = nil
+      profile.talents[talentName] = nil
     end
   end
 
@@ -638,6 +640,12 @@
     kb.UpdateBindingsCache(self.actionType, self.actionID, {})
   end
 
+  local talentName = self.actionName
+  if self.actionType == 'macro' then
+    local spellName, _, spellID = GetMacroSpell(self.actionID)
+    talentName = spellName
+  end
+
 
   --print('detected', #keys, 'bindings')
   for i, key in pairs(keys) do
@@ -648,8 +656,8 @@
       --kb:print(L('BINDING_REMOVED', self.actionName, kb.currentHeader))
       kb.currentProfile.bindings[key] = nil
     end
-    if kb.currentProfile.talents[self.actionName] then
-      kb.currentProfile.talents[self.actionName] = nil
+    if kb.currentProfile.talents[talentName] then
+      kb.currentProfile.talents[talentName] = nil
     end
 
     kb.bindings[tostring(self.actionType)..'_'..tostring(self.actionID)] = nil
--- a/SkeletonKey/HotKey.lua	Mon Sep 05 14:56:38 2016 -0400
+++ b/SkeletonKey/HotKey.lua	Thu Sep 08 16:52:55 2016 -0400
@@ -113,63 +113,83 @@
 hotkey.UpdateHotKey = function(frame, actionType, actionID, hasAction)
   bindings = kb.GetBindings()
 
-  local indexKey = kb.FormatActionID(actionType, actionID)
-  --kprint(frame:GetName(), '|cFF88FF00'..indexKey..'|r',  hasAction)
+  if hasAction then
+    local indexKey = kb.FormatActionID(actionType, actionID)
+    kprint(frame:GetName(), '|cFF88FF00'..indexKey..'|r',  hasAction)
 
 
-  if bindings[indexKey] then
-    kprint(' |cFFFF0088', actionType ..'|r', actionID, hasAction)
+    local actionName
+    if actionType == 'spell' then
+      actionName = GetSpellInfo(actionID)
+    elseif actionType == 'macro' then
+      actionName = GetMacroInfo(actionID)
+    elseif actionType == 'summonmount' then
+      actionName = C_MountJournal.GetMountInfoByID(actionID)
+    elseif actionType == 'item' then
+      actionName = GetItemInfo(actionID)
+    end
+    kprint(' ', actionName)
+
     local binds = bindings[indexKey]
+    kprint(binds)
     if binds and (not frame.HotKey:IsVisible()) then
-      if hasAction then
-        local bindingsText = kb.BindingString(unpack(binds))
+      local bindingsText = kb.BindingString(unpack(binds))
 
-        if not hotkeyText[frame] then
-          kprint('-new hotkey element')
-          hotkeyText[frame] = frame:CreateFontString(frame:GetName()..'SkeletonKey', 'OVERLAY')
-          hotkeyText[frame]:SetFont(frame.HotKey:GetFont())
-          hotkeyText[frame]:SetTextColor(frame.HotKey:GetTextColor())
-          hotkeyText[frame]:SetPoint('TOPRIGHT', frame.HotKey, 'TOPRIGHT')
+      if not hotkeyText[frame] then
+        kprint('-new hotkey element')
+        hotkeyText[frame] = frame:CreateFontString(frame:GetName()..'SkeletonKey', 'OVERLAY')
+        hotkeyText[frame]:SetFont(frame.HotKey:GetFont())
+        hotkeyText[frame]:SetTextColor(frame.HotKey:GetTextColor())
+        hotkeyText[frame]:SetPoint('TOPRIGHT', frame.HotKey, 'TOPRIGHT')
 
-          hooksecurefunc(frame.HotKey, 'SetVertexColor', function(self, r,g,b,a)
-            hotkeyText[frame]:SetTextColor(r,g,b,a)
-          end)
-        end
+        hooksecurefunc(frame.HotKey, 'SetVertexColor', function(self, r,g,b,a)
+          hotkeyText[frame]:SetTextColor(r,g,b,a)
+        end)
+      end
 
-        hotkeyText[frame]:SetText(bindingsText)
-        hotkeyText[frame]:Show()
-        kprint('   |cFF00FFFF', frame:GetName(), '|cFFFFFF00'..tostring(bindingsText)..'|r')
+      hotkeyText[frame]:SetText(bindingsText)
+      hotkeyText[frame]:Show()
+      kprint('   |cFF00FFFF', frame:GetName(), '|cFFFFFF00'..tostring(bindingsText)..'|r')
 
-        return
-      end
+      return
     end
   end
 
   if hotkeyText[frame] then
+    local oldText = hotkeyText[frame]:GetText()
+    if oldText then
     hotkeyText[frame]:SetText(nil)
-    print('|cFFFF4400' .. frame:GetName() .. '|r', 'remove text')
+    print('|cFFFF4400' .. frame:GetName() .. '|r', 'removed text', oldText)
+    end
+
   end
 end
 
 hotkey.actionbar = function()
-  wipe(actionFrames)
   -- reset frames list
   print('actionbar')
+  wipe(actionFrames)
   if ActionBarButtonEventsFrame.frames then
     for index, frame in ipairs(ActionBarButtonEventsFrame.frames) do
-
       local slot = frame.action
       local actionType, actionID = GetActionInfo(slot)
       local hasAction = HasAction(slot)
-      local indexKey = kb.FormatActionID(actionType, actionID)
 
       actionSlots[slot] = frame
-      actionFrames[indexKey] = actionFrames[indexKey] or {}
-      if not tContains(actionFrames[indexKey]) then
-        tinsert(actionFrames[indexKey], frame)
-        actionIndex[slot] = indexKey
+      if hasAction then
+        local indexKey = kb.FormatActionID(actionType, actionID)
+
+        actionFrames[indexKey] = actionFrames[indexKey] or {}
+        local result = ''
+        if not tContains(actionFrames[indexKey], frame) then
+          tinsert(actionFrames[indexKey], frame)
+          actionIndex[slot] = indexKey
+          result = 'added'
+        end
+        print('#'..index, frame:GetName(), indexKey, result)
       end
 
+
       hotkey.UpdateHotKey(frame, actionType, actionID, hasAction)
     end
   end
--- a/SkeletonKey/KeyButton.lua	Mon Sep 05 14:56:38 2016 -0400
+++ b/SkeletonKey/KeyButton.lua	Thu Sep 08 16:52:55 2016 -0400
@@ -357,10 +357,13 @@
   if self.command then
     kb.currentProfile.commands[self.command] = nil
   end
-  if self.actionType == 'spell' and IsTalentSpell(self.actionName) then
-    if kb.currentProfile.talents[self.actionID] then
-      kb.currentProfile.talents[self.actionID] = nil
-    end
+  local talentName = self.actionID
+  if self.actionType == 'macro' then
+    talentName = GetMacroSpell(self.actionID)
+  end
+    -- remove any matching talent data
+  if talentName and kb.currentProfile.talents[talentName] then
+    kb.currentProfile.talents[talentName] = nil
   end
   local droppedKeys = {}