changeset 15:32d64e42ec9b

- resolve pet bar actions for binding slots - detect type of petaction (can be spell, stance, or 'PETACTION') - keep track of displayed pet ability slots and update them alongside pet cache refreshes
author Nenue
date Fri, 29 Jul 2016 03:27:15 -0400
parents 82170735e67c
children cdd387d39137
files SkeletonKey/BindingsUI.lua SkeletonKey/Cache.lua SkeletonKey/Events.lua SkeletonKey/KeyBinds.xml SkeletonKey/KeySlot.lua SkeletonKey/SkeletonKey.lua
diffstat 6 files changed, 227 insertions(+), 61 deletions(-) [+]
line wrap: on
line diff
--- a/SkeletonKey/BindingsUI.lua	Thu Jul 28 23:58:53 2016 -0400
+++ b/SkeletonKey/BindingsUI.lua	Fri Jul 29 03:27:15 2016 -0400
@@ -226,7 +226,6 @@
 --- Retrieves button at index; creates said button and instates any stored parameters
 do
   local leftSlot, upSlot
-  local buttonsDepth = 0
   kb.GetSlot = function(index)
 
     local slot  = index + kb.scrollOffset
@@ -245,11 +244,9 @@
       if index == 1 then
         button:SetPoint('TOPLEFT', kb.bg, 'TOPLEFT', BUTTON_PADDING, - BUTTON_PADDING)
         upSlot = button
-        buttonsDepth = KEY_BUTTON_SIZE + BUTTON_PADDING * 2
       elseif newRow then
         button:SetPoint('TOPLEFT', upSlot, 'BOTTOMLEFT', 0, -BUTTON_SPACING)
         upSlot = button
-        buttonsDepth = buttonsDepth + KEY_BUTTON_SIZE + BUTTON_SPACING
       else
         button:SetPoint('TOPLEFT', leftSlot, 'TOPRIGHT', BUTTON_HSPACING, 0)
       end
--- a/SkeletonKey/Cache.lua	Thu Jul 28 23:58:53 2016 -0400
+++ b/SkeletonKey/Cache.lua	Fri Jul 29 03:27:15 2016 -0400
@@ -5,6 +5,7 @@
 -- Cached data regarding talent options, pet spells, etc.
 local kb, print = LibStub('LibKraken').register(KeyBinder, 'PlayerInfo')
 
+local PET_SPECIAL_SUBTEXT = 'Special Ability'
 local BINDING_TYPE_SPECIALIZATION = 3
 local BINDING_TYPE_CHARACTER = 2
 local BINDING_TYPE_GLOBAL = 1
@@ -103,6 +104,112 @@
 end
 
 
+
 kb.UpdatePetInfo = function()
+  kb.PetCache.spell = kb.PetCache.spell or {}
+  kb.PetCache.spellslot = kb.PetCache.spellslot or {}
+  kb.PetCache.action = kb.PetCache.action or {}
+  kb.PetCache.special = kb.PetCache.action or {}
+  local hasPetSpells, petType = HasPetSpells()
+  if PetHasSpellbook() then
+    print('PET SPELLBOOK')
+    local i = 1
+    local specialNum = 0
+    repeat
+
+      local spellType, spellID = GetSpellBookItemInfo(i, BOOKTYPE_PET)
+      local spellName, subText = GetSpellBookItemName(i, BOOKTYPE_PET)
+      local isPassive = IsPassiveSpell(i, BOOKTYPE_PET)
+      if not isPassive then
+        if spellName then
+          kb.PetCache.spellslot[spellName] = {i, spellName, subText}
+          print('|cFF00FF88spellslot['..spellName..']|r', '=>', i, subText)
+
+          if subText == PET_SPECIAL_SUBTEXT then
+            specialNum = specialNum + 1
+            kb.PetCache.special[spellName] = {i, specialNum, spellID, subText }
+            print('|cFF00FFFFspecial['..spellName..']|r', '=>', i, specialNum, spellID, subText)
+          end
+
+          if spellID then
+            kb.PetCache.spell[i] = {spellID, spellName, subText}
+            print('|cFF0088FFspell['..i..']|r', '=>', spellID, spellName, subText)
+          end
+        end
+
+
+      end
+
+      i = i + 1
+    until spellType == nil
+  else
+    print('NO PET SPELLBOOK')
+    table.wipe(kb.PetCache.spell)
+    table.wipe(kb.PetCache.spellslot)
+  end
+
+  if PetHasActionBar() then
+    print('PET ACTION BAR')
+    for i = 1, 10 do
+
+
+      local name, subtext, texture, isToken, isActive = GetPetActionInfo(i)
+      if name then
+        kb.PetCache.action[i] = {name, subtext, texture, isToken, isActive }
+
+
+      end
+      print('|cFFFFFF00action['..i..']|r', name, subtext, texture)
+    end
+  else
+    print('NO PET ACTION BAR')
+    table.wipe(kb.PetCache.action)
+  end
+
+  kb.UpdateCacheButtons(kb.petFrames)
+
+end
+
+kb.SystemBinds = {}
+kb.UpdateSystemBinds = function()
+  table.wipe(kb.SystemBinds)
+  local n = GetNumBindings()
+  for i=1, n do
+    local command, key1, key2 = GetBinding(i)
+    if key1 then
+      kb.SystemBinds[key1] = command
+    end
+    if key2 then
+      kb.SystemBinds[key2] = command
+    end
+  end
+
+end
+
+do
+  local garbage = {}
+  kb.UpdateCacheButtons = function(pending)
+    for i, button in ipairs(pending) do
+      if button.isDynamic then
+        print('flushing button', button:GetID())
+          kb.UpdateSlot(button, true)
+      end
+    end
+  end
+end
+
+
+kb.RemoveCacheButton = function(pending, button)
+  local found
+  for index, frame in ipairs(pending) do
+    if button == frame then
+      found = index
+      break
+    end
+  end
+  if found then
+    print('|cFFFF4400pruning', button:GetName(), 'from update queue')
+    tremove(pending, found)
+  end
 
 end
\ No newline at end of file
--- a/SkeletonKey/Events.lua	Thu Jul 28 23:58:53 2016 -0400
+++ b/SkeletonKey/Events.lua	Fri Jul 29 03:27:15 2016 -0400
@@ -4,14 +4,16 @@
 -- %file-revision%
 -- Event handlers, and the init block that sets them up; nothing else should be here
 
-local kb = LibStub("LibKraken").register(KeyBinder)
+local kb, print = LibStub("LibKraken").register(KeyBinder)
 
 kb.init = function()
   kb:RegisterEvent('PLAYER_ENTERING_WORLD')
   kb:RegisterEvent('UPDATE_MACROS')
   kb:RegisterUnitEvent('PLAYER_SPECIALIZATION_CHANGED', 'player', 'pet')
   kb:RegisterUnitEvent('UNIT_PORTRAIT_UPDATE', 'player', 'pet')
+  kb:RegisterUnitEvent('SPELLS_CHANGED')
   kb:RegisterUnitEvent('TALENT_UPDATE', 'player', 'pet')
+
   kb:RegisterEvent('PLAYER_REGEN_DISABLED')
   kb:RegisterEvent('PLAYER_REGEN_ENABLED')
 end
@@ -52,10 +54,8 @@
   return true
 end
 
-kb.UNIT_PET = function(self, event, unit)
-  if unit ~= 'player' then
-    return
-  end
-
+-- only need to respond to this for pet actions
+kb.SPELLS_CHANGED = function(self, event, unit)
+  print('|cFFFF0088'.. event..'|r', unit)
   kb.UpdatePetInfo()
 end
\ No newline at end of file
--- a/SkeletonKey/KeyBinds.xml	Thu Jul 28 23:58:53 2016 -0400
+++ b/SkeletonKey/KeyBinds.xml	Fri Jul 29 03:27:15 2016 -0400
@@ -60,6 +60,13 @@
             <Anchor point="RIGHT" x="128" y="0" />
           </Anchors>
         </FontString>
+
+        <Texture parentKey="ignoreTexture" file="Interface\PaperDollInfoFrame\UI-GearManager-LeaveItem-Transparent" hidden="true">
+          <Anchors>
+            <Anchor point="TOPLEFT" x="0" y="0" />
+            <Anchor point="BOTTOMRIGHT" x="0" y="0" />
+          </Anchors>
+        </Texture>
       </Layer>
     </Layers>
     <HighlightTexture file="Interface\BUTTONS\UI-Button-Outline" alphaMode="ADD">
--- a/SkeletonKey/KeySlot.lua	Thu Jul 28 23:58:53 2016 -0400
+++ b/SkeletonKey/KeySlot.lua	Fri Jul 29 03:27:15 2016 -0400
@@ -7,8 +7,8 @@
 local kb, print = LibStub('LibKraken').register(KeyBinder, 'Slot')
 local CURSOR_SPELLSLOT, CURSOR_BOOKTYPE, CURSOR_PETACTION
 local SUMMON_RANDOM_FAVORITE_MOUNT_SPELL = 150544
-local BORDER_UNASSIGNED = {0.2,0.2,0.2,1 }
-local BORDER_ASSIGNED = {0.5,0.5,0.5,1 }
+local BORDER_UNASSIGNED = {0.2,0.2,0.2,1}
+local BORDER_ASSIGNED = {1,1,1,1}
 local BORDER_DYNAMIC = {1,1,0,1}
 local BORDER_PENDING = {1,0.5,0,1 }
 
@@ -39,9 +39,30 @@
   local isPickup
   hooksecurefunc("PickupPetAction", function(slot, ...)
     isPickup = GetCursorInfo()
+    print(slot, ...)
 
-    CURSOR_PETACTION = isPickup and slot
+
+    if kb.PetCache.action[slot] then
+      if isPickup then
+        local key = kb.PetCache.action[slot][1]
+        local spellName = _G[key] or key
+        if spellName and kb.PetCache.spellslot[spellName] then
+          print('picked up', spellName, kb.PetCache.spellslot[spellName][1])
+          CURSOR_SPELLSLOT = kb.PetCache.spellslot[spellName][1]
+          CURSOR_BOOKTYPE = BOOKTYPE_PET
+        end
+
+      else
+        print('Dropped pet action =', GetPetActionInfo(slot))
+      end
     print('|cFFFF4400PickupPetAction|r', isPickup, CURSOR_PETACTION)
+    end
+
+    local name, subtext, texture, isToken = GetPetActionInfo(slot)
+    if name then
+        kb.PetCache.action[slot] = {name, subtext, texture, isToken}
+    end
+
   end)
 end
 
@@ -59,8 +80,7 @@
     end
 
 
-    local macroName, macroText
-    local command, name, icon, _
+    local name, icon, _
     local pickupID, pickupBook
 
     if actionType == 'spell' then
@@ -70,17 +90,23 @@
     elseif actionType == 'macro' then
       name, icon = GetMacroInfo(actionID)
     elseif actionType == 'petaction' then
-      if not (CURSOR_SPELLSLOT and CURSOR_BOOKTYPE) then
+      if CURSOR_SPELLSLOT and CURSOR_BOOKTYPE then
 
-        ClearCursor()
-        ResetCursor()
+        local spellType, spellID = GetSpellBookItemInfo(CURSOR_SPELLSLOT, CURSOR_BOOKTYPE)
+        local spellName, spellText = GetSpellBookItemName(CURSOR_SPELLSLOT, CURSOR_BOOKTYPE)
+        if spellType == 'PETACTION' then
+          actionID = spellText
+        else
+          name, _, icon = GetSpellInfo(spellID)
+          actionID = spellID
+        end
+
+        pickupID = CURSOR_SPELLSLOT
+        pickupBook = CURSOR_BOOKTYPE
+      else
+
       end
 
-      local bookType, spellID = GetSpellBookItemInfo(CURSOR_SPELLSLOT, CURSOR_BOOKTYPE)
-      actionID = spellID
-      pickupID = CURSOR_SPELLSLOT
-      pickupBook = CURSOR_BOOKTYPE
-      name, _, icon = GetSpellInfo(spellID)
     elseif actionType == 'mount' then
       if subType == 0 then
         name, _, icon = GetSpellInfo(SUMMON_RANDOM_FAVORITE_MOUNT_SPELL)
@@ -99,7 +125,7 @@
       icon = petIcon
 
     end
-    macroName, macroText, command = kb.RegisterAction(actionType, actionID, name)
+    local macroName, macroText, command = kb.RegisterAction(actionType, actionID, name)
 
 
     local isAssigned, isBound, assignedBy, boundBy = kb.IsCommandBound(self, command)
@@ -135,7 +161,7 @@
     petaction = function(self) return self.pickupSlot, self.pickupBook end,
   }
   kb.PickupSlot = function(self)
-    if not self.command then
+    if not (self.command and self.isAvailable) then
       return
     end
     print(self.actionType)
@@ -175,14 +201,22 @@
   if self.command then
     print('['..slot..'] =', self.command, GetBindingKey(self.command))
 
-    if self.pending then
-      self.border:SetColorTexture(unpack(BORDER_PENDING))
-    elseif self.isDynamic then
-      self.border:SetColorTexture(unpack(BORDER_DYNAMIC))
+    if not self.isAvailable then
+      self.border:SetColorTexture(1,0,0,1)
+      self.ignoreTexture:Show()
     else
-      self.border:SetColorTexture(unpack(BORDER_ASSIGNED))
+      self.ignoreTexture:Hide()
+
+      if self.pending then
+        self.border:SetColorTexture(unpack(BORDER_PENDING))
+      elseif self.isDynamic then
+        self.border:SetColorTexture(unpack(BORDER_DYNAMIC))
+      else
+        self.border:SetColorTexture(unpack(BORDER_ASSIGNED))
+      end
     end
 
+
     if self.actionType == 'macro' then
       self.macro:Show()
     else
@@ -199,7 +233,7 @@
     end
 
     if self.isDynamic then
-      print('|cFFFFBB00UpdateSlot|r: ', self.isDynamic, self.isAvailable, self.actionID)
+      print('|cFF00BBFFUpdateSlot|r:', self.isDynamic, self.isAvailable, self.actionID)
     end
 
     if self.isDynamic == 'profession'  then
@@ -226,6 +260,9 @@
         end
 
       end
+    elseif self.isDynamic == 'petaction' and self.command:match("special") then
+      self.statusText = '|cFF00FF00Pet Special|r'
+      self.bindingText = kb.BindingString(GetBindingKey(self.command))
     else
       self.statusText = '|cFF00FF00'.. (BUTTON_HEADERS[self.actionType] and BUTTON_HEADERS[self.actionType] or self.actionType) .. '|r'
       self.bindingText = kb.BindingString(GetBindingKey(self.command))
@@ -300,6 +337,7 @@
   self.border:SetColorTexture(unpack(BORDER_UNASSIGNED))
   self:EnableKeyboard(false)
   self:SetScript('OnKeyDown', nil)
+  self.ignoreTexture:Hide()
 end
 
 kb.SetSlot = function(self, command, name, icon, actionType, actionID, macroName, macroText, pickupSlot, pickupBook)
@@ -336,6 +374,15 @@
 
         isAvailable = GetSpellInfo(name)
       end
+    elseif actionType == 'petaction' then
+      isDynamic = 'petaction'
+      if kb.PetCache.spellslot and kb.PetCache.spellslot[name] then
+        isAvailable = true
+        kb.RemoveCacheButton(kb.petFrames, self)
+      else
+        print('|cFFFF4400OnCacheUpdate, re-do #', slot)
+        tinsert(kb.petFrames, self)
+      end
     elseif actionType == 'macro' then
       if not actionID then
         actionID = GetMacroIndexByName(name)
@@ -366,17 +413,10 @@
       kb.LoadBinding(command, name, icon, actionType, actionID, macroName, macroText)
     end
 
-    if actionType == 'petaction' then
-      self.pickupSlot = pickupSlot
-      self.pickupBook = pickupBook
-    else
-      self.pickupSlot = nil
-      self.pickupBook = nil
-    end
 
     actionID = actionID or 0
     self:EnableKeyboard(true)
-    print(' |cFF00FF00kb.currentProfile.buttons['..slot..'] |cFF00FFFF=|r |cFF00FFFF"'.. command.. '"|r |cFF00FF00"'.. name, '"|r |cFFFFFF00icon:'.. icon .. '|r |cFFFF8800"'.. actionType, '"|r |cFFFF0088id:'.. actionID ..'|r |cFF00FF00"'.. macroName .. '"|r')
+    print(' |cFF00FF00kb.currentProfile.buttons['..slot..'] |cFF00FFFF=|r |cFF00FFFF"'.. command.. '"|r |cFF00FF00"'.. name.. '"|r |cFFFFFF00icon:'.. icon .. '|r |cFFFF8800"'.. actionType, '"|r |cFFFF0088id:'.. actionID ..'|r |cFF00FF00"'.. macroName .. '"|r')
     kb.currentProfile.buttons[slot] = {command, name, icon, actionType, actionID, macroName, macroText, pickupSlot, pickupBook}
 
     -- Clean up conflicting entries for loaded button
@@ -390,6 +430,8 @@
   self.isAvailable = isAvailable
   self.isDynamic = isDynamic
 
+  self.pickupSlot = pickupSlot
+  self.pickupBook = pickupBook
   self.macroText = macroText
   self.macroName = macroName
   self.actionType = actionType
--- a/SkeletonKey/SkeletonKey.lua	Thu Jul 28 23:58:53 2016 -0400
+++ b/SkeletonKey/SkeletonKey.lua	Fri Jul 29 03:27:15 2016 -0400
@@ -49,6 +49,18 @@
   ['item'] = "/use %s"
 }
 
+
+local PETACTION_SCRIPT = {
+  [PET_ACTION_MOVE_TO] = SLASH_PET_MOVE_TO1,
+  [PET_ACTION_ATTACK] = SLASH_PET_ATTACK1,
+  [PET_ACTION_FOLLOW] = SLASH_PET_FOLLOW1,
+  [PET_ACTION_WAIT] = SLASH_PET_STAY1,
+  [PET_MODE_AGGRESSIVE] = SLASH_PET_AGGRESSIVE1,
+  [PET_MODE_DEFENSIVE] = SLASH_PET_DEFENSIVE1,
+  [PET_MODE_PASSIVE] = SLASH_PET_PASSIVE1,
+  [PET_MODE_ASSIST] = SLASH_PET_ASSIST1,
+}
+
 local professionMappings = {
   [5] = 3,
   [7] = 4,
@@ -74,6 +86,9 @@
 kb.orderedProfiles = {}
 kb.buttons = {}
 kb.macros = {}
+kb.petFrames = {} -- pet data is slightly delayed, their buttons are indexed here so they can be refreshed
+kb.talentFrames = {}
+kb.professionFrames = {}
 
 -- these are sent to plugin
 
@@ -208,6 +223,18 @@
   end
   print('|cFFFFFF00received|cFFFFFF00', self:GetID(), '|cFF00FFFF', key)
 
+  local modifier = ''
+  if IsAltKeyDown() then
+    modifier = 'ALT-'
+  end
+  if IsControlKeyDown() then
+    modifier = modifier.. 'CTRL-'
+  end
+  if IsShiftKeyDown() then
+    modifier = modifier..'SHIFT-'
+  end
+  local binding = modifier..key
+
   if key == 'ESCAPE' then
     local keys = {GetBindingKey(self.command) }
     --print('detected', #keys, 'bindings')
@@ -232,30 +259,22 @@
     bindsCommitted = false
     self.active = false
   else
-
-    local modifier = ''
-    if IsAltKeyDown() then
-      modifier = 'ALT-'
-    end
-    if IsControlKeyDown() then
-      modifier = modifier.. 'CTRL-'
-    end
-    if IsShiftKeyDown() then
-      modifier = modifier..'SHIFT-'
+    if kb.SystemBinds[binding] then
+      kb.statustext:SetText(L('BINDING_FAILED_PROTECTED', key, kb.SystemBinds[binding]))
+      return
     end
 
 
     if self.command then
-      self.binding = modifier..key
 
       local previousKeys
-      local previousAction = GetBindingAction(self.binding)
+      local previousAction = GetBindingAction(binding)
       local binding1, binding2, new1, new2
       print(type(previousAction), previousAction)
       if previousAction ~= "" and previousAction ~= self.command then
         if protected[previousAction] then
           -- bounce out if trying to use a protected key
-          kb.statustext:SetText(L('BINDING_FAILED_PROTECTED', key, GetBindingAction(previousAction)))
+          kb.statustext:SetText(L('BINDING_FAILED_PROTECTED', key, GetBindingAction(binding)))
           kb.bindingstext:SetText(nil)
           return
         else
@@ -265,6 +284,7 @@
       end
 
       self.pending = true
+      self.binding = binding
 
       bindsCommitted = false
       SetBinding(self.binding, self.command)
@@ -387,6 +407,7 @@
 kb.ApplyAllBindings =function ()
   table.wipe(kb.inactiveTalentBindings)
 
+
   -- reflect action key settings
   if GetCVarBool("ActionButtonUseKeyDown") then
     KeyBinderMacro:RegisterForClicks("AnyDown")
@@ -493,7 +514,7 @@
   kb.UpdateTalentInfo()
 
   kb.orderedProfiles = {kb.loadedProfiles[BINDING_TYPE_GLOBAL], kb.loadedProfiles[BINDING_TYPE_CHARACTER], kb.loadedProfiles[BINDING_TYPE_SPECIALIZATION]}
-  if db.bindMode and (not kb.configTitle[db.bindMode]) then
+  if (not db.bindMode) or (not kb.configTitle[db.bindMode]) then
     print('fixing bad bindMode value, was', db.bindMode)
     db.bindMode = defaultMode
   end
@@ -527,15 +548,8 @@
 end
 
 kb.ConfirmBindings = function()
-  SaveBindings(GetCurrentBindingSet())
-  bindsCommitted = true
-  for i, button in ipairs(buttons) do
-    button.pending = false
-  end
   kb.ApplyAllBindings()
-
   kb.ui()
-  kb:print('Keybinds saved.')
 end
 
 
@@ -553,8 +567,7 @@
   kb.SelectProfileSet(kb.profileName)
   -- todo: redo import checking
 
-
-
+  kb.UpdateSystemBinds()
   kb.ApplyAllBindings()
 
   kb.ui(true)