diff SkeletonKey/KeyButton.lua @ 52:81a7c71c4483

- fixed safety override - fixed pet journal drag/drop - fixed confirmation cancel button
author Nenue
date Fri, 19 Aug 2016 10:46:36 -0400
parents 1aba8a6fd4a9
children c416c9e6d212
line wrap: on
line diff
--- a/SkeletonKey/KeyButton.lua	Fri Aug 19 09:29:23 2016 -0400
+++ b/SkeletonKey/KeyButton.lua	Fri Aug 19 10:46:36 2016 -0400
@@ -2,10 +2,19 @@
 -- KeyButton.lua
 -- Created: 7/28/2016 11:26 PM
 -- %file-revision%
--- Code dealing with the slot button innards; they are invoked by frame script and should only chain to Set/Release
+-- Deals with display and manipulation of binding slots
 
 local kb, print = LibStub('LibKraken').register(KeyBinder, 'Slot')
 local L = kb.L
+local type, tonumber, tostring, tinsert, tremove, ipairs, pairs = type, tonumber, tostring, tinsert, tremove, ipairs, pairs
+local _G, unpack, select, tostring = _G, unpack, select, tostring
+local GetSpellBookItemName, GetSpellBookItemTexture, GetSpellBookItemInfo, GetPetActionInfo = GetSpellBookItemName, GetSpellBookItemTexture, GetSpellBookItemInfo, GetPetActionInfo
+local GetSpellInfo, GetMacroInfo, GetItemInfo, GetItemIcon = GetSpellInfo, GetMacroInfo, GetItemInfo, GetItemIcon
+local GetCursorInfo, ClearCursor, ResetCursor = GetCursorInfo, ClearCursor, ResetCursor
+local GetSpellTexture, IsTalentSpell, GetMacroIndexByName, IsAltKeyDown, IsControlKeyDown, IsShiftKeyDown = GetSpellTexture, IsTalentSpell, GetMacroIndexByName, IsAltKeyDown, IsControlKeyDown,IsShiftKeyDown
+local GetBindingKey, GetProfessionInfo = GetBindingKey, GetProfessionInfo
+local GetMountInfoByID, GetPetInfoByPetID = C_MountJournal.GetMountInfoByID, C_PetJournal.GetPetInfoByPetID
+
 local CURSOR_SPELLSLOT, CURSOR_BOOKTYPE, CURSOR_PETACTION, CURSOR_TEXTURE
 local SUMMON_RANDOM_FAVORITE_MOUNT_SPELL = 150544
 local BORDER_UNASSIGNED = {0.2,0.2,0.2,1}
@@ -128,7 +137,7 @@
         name, _, icon = GetSpellInfo(SUMMON_RANDOM_FAVORITE_MOUNT_SPELL)
         actionID = 0
       else
-        name, _, icon = C_MountJournal.GetMountInfoByID(actionID)
+        name, _, icon = GetMountInfoByID(actionID)
       end
     elseif actionType == 'item' then
       name = GetItemInfo(actionID)
@@ -136,7 +145,7 @@
       actionID = name
     elseif actionType == 'battlepet' then
 
-      local speciesID, customName, level, xp, maxXp, displayID, isFavorite, petName, petIcon, petType, creatureID = C_PetJournal.GetPetInfoByPetID(detail);
+      local speciesID, customName, level, xp, maxXp, displayID, isFavorite, petName, petIcon, petType, creatureID = GetPetInfoByPetID(actionID)
       name = customName or petName
       icon = petIcon
 
@@ -200,150 +209,7 @@
   end
 end
 
-kb.UnbindSlot = function(self)
 
-  local keys = {GetBindingKey(self.command) }
-  if #keys >= 1 then
-    kb.UpdateBindingsCache(self.actionType, self.actionID, {})
-  end
-
-
-  --print('detected', #keys, 'bindings')
-  for i, key in pairs(keys) do
-    --print('clearing', key)
-    SetBinding(key, nil)
-    SaveBindings(GetCurrentBindingSet())
-    if kb.currentProfile.bindings[key] then
-      --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
-    end
-
-    kb.bindings[tostring(self.actionType)..'_'..tostring(self.actionID)] = nil
-  end
-  if kb.currentProfile.bound[self.command] then
-    kb.currentProfile.bound[self.command] = nil
-    --kb:print(BINDING_REMOVED:format(self.actionName, configHeaders[db.bindMode]))
-  end
-
-
-  self.active = false
-  kb.UpdateSlot(self, true)
-end
-
---- Updates the current KeyBinding for the button's command
-kb.SaveSlot = function(self, key)
-
-  if not self.command then
-    return
-  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
-  else
-    if kb.SystemBindings[binding] then
-      kb.statustext:SetText(L('BINDING_FAILED_PROTECTED', binding, kb.SystemBindings[binding]))
-      return
-    end
-
-
-    if self.command then
-
-      local previousCommand = GetBindingAction(binding)
-      if previousCommand ~= "" and previousCommand ~= self.command then
-        if kb.SystemBindings[binding] then
-          -- bounce out if trying to use a protected key
-          kb.statustext:SetText(L('BINDING_FAILED_PROTECTED', key, GetBindingAction(binding)))
-          kb.bindingstext:SetText(nil)
-          return false
-        end
-
-        local actionType, actionID, name = kb.GetCommandAction(previousCommand)
-        if actionType then
-          local keys = {GetBindingKey(previousCommand) }
-          local  i = 1
-          while keys[i] do
-            if keys[i] == binding then
-              table.remove(keys, i)
-              kb.UpdateBindingsCache(actionType, actionID, keys)
-              break
-            end
-            i = i + 1
-          end
-        end
-      end
-
-      local currentHotKeys = {GetBindingKey(self.command)}
-      local found
-      for i, key in ipairs(currentHotKeys) do
-        if key == binding then
-          found = true
-          kb:print('hotkey already assigned')
-        end
-      end
-      if not found then
-        table.insert(currentHotKeys, 1, binding)
-        kb.UpdateBindingsCache(self.actionType, self.actionID, currentHotKeys)
-      end
-
-      self.binding = binding
-
-
-      print('SetBinding', binding, self.command)
-      SetBinding(self.binding, self.command)
-      SaveBindings(GetCurrentBindingSet())
-
-
-
-      local talentInfo
-      if self.actionType == 'spell' and kb.TalentCache[self.actionID] then
-        print('conditional binding (talent = "'..self.actionName..'")')
-        talentInfo = {self.macroName, self.actionName, self.actionType, self.actionID}
-        local bindings = {GetBindingKey(self.command) }
-        for i, key in ipairs(bindings) do
-          tinsert(talentInfo, key)
-        end
-      end
-
-      for level, profile in ipairs(kb.orderedProfiles) do
-        if (level == kb.db.bindMode) then
-          profile.bound[self.command] = true
-          if talentInfo then
-            profile.bindings[self.binding] = nil
-          else
-            profile.bindings[self.binding] = self.command
-          end
-          profile.talents[self.actionName] = 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
-        end
-      end
-
-      kb:print(L('BINDING_ASSIGNED', self.binding, self.actionName, kb.currentHeader))
-    end
-  end
-  kb.UpdateSlot(self, true)
-  return true
-end
 
 
 --- Updates profile assignment and button contents
@@ -669,15 +535,3 @@
   end
 end
 
-
---- Add to blizzard interfaces
-StaticPopupDialogs["SKELETONKEY_CONFIRM_ASSIGN_SLOT"] = {
-  text = "Confirm moving an assigned command.",
-  button1 = OKAY,
-  button2 = CANCEL,
-  timeout = 0,
-  whileDead = 1,
-  showAlert = 1,
-  OnAccept = kb.AcceptAssignment,
-  OnCancel = function() kb:SetScript('OnMouseWheel', KeyBinder_OnMouseWheel) end
-}
\ No newline at end of file