Mercurial > wow > skeletonkey
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 51:d0ee4553061a | 52:81a7c71c4483 |
|---|---|
| 1 -- SkeletonKey | 1 -- SkeletonKey |
| 2 -- KeyButton.lua | 2 -- KeyButton.lua |
| 3 -- Created: 7/28/2016 11:26 PM | 3 -- Created: 7/28/2016 11:26 PM |
| 4 -- %file-revision% | 4 -- %file-revision% |
| 5 -- Code dealing with the slot button innards; they are invoked by frame script and should only chain to Set/Release | 5 -- Deals with display and manipulation of binding slots |
| 6 | 6 |
| 7 local kb, print = LibStub('LibKraken').register(KeyBinder, 'Slot') | 7 local kb, print = LibStub('LibKraken').register(KeyBinder, 'Slot') |
| 8 local L = kb.L | 8 local L = kb.L |
| 9 local type, tonumber, tostring, tinsert, tremove, ipairs, pairs = type, tonumber, tostring, tinsert, tremove, ipairs, pairs | |
| 10 local _G, unpack, select, tostring = _G, unpack, select, tostring | |
| 11 local GetSpellBookItemName, GetSpellBookItemTexture, GetSpellBookItemInfo, GetPetActionInfo = GetSpellBookItemName, GetSpellBookItemTexture, GetSpellBookItemInfo, GetPetActionInfo | |
| 12 local GetSpellInfo, GetMacroInfo, GetItemInfo, GetItemIcon = GetSpellInfo, GetMacroInfo, GetItemInfo, GetItemIcon | |
| 13 local GetCursorInfo, ClearCursor, ResetCursor = GetCursorInfo, ClearCursor, ResetCursor | |
| 14 local GetSpellTexture, IsTalentSpell, GetMacroIndexByName, IsAltKeyDown, IsControlKeyDown, IsShiftKeyDown = GetSpellTexture, IsTalentSpell, GetMacroIndexByName, IsAltKeyDown, IsControlKeyDown,IsShiftKeyDown | |
| 15 local GetBindingKey, GetProfessionInfo = GetBindingKey, GetProfessionInfo | |
| 16 local GetMountInfoByID, GetPetInfoByPetID = C_MountJournal.GetMountInfoByID, C_PetJournal.GetPetInfoByPetID | |
| 17 | |
| 9 local CURSOR_SPELLSLOT, CURSOR_BOOKTYPE, CURSOR_PETACTION, CURSOR_TEXTURE | 18 local CURSOR_SPELLSLOT, CURSOR_BOOKTYPE, CURSOR_PETACTION, CURSOR_TEXTURE |
| 10 local SUMMON_RANDOM_FAVORITE_MOUNT_SPELL = 150544 | 19 local SUMMON_RANDOM_FAVORITE_MOUNT_SPELL = 150544 |
| 11 local BORDER_UNASSIGNED = {0.2,0.2,0.2,1} | 20 local BORDER_UNASSIGNED = {0.2,0.2,0.2,1} |
| 12 local BORDER_ASSIGNED = {1,1,1,1} | 21 local BORDER_ASSIGNED = {1,1,1,1} |
| 13 local BORDER_DYNAMIC = {1,1,0,1} | 22 local BORDER_DYNAMIC = {1,1,0,1} |
| 126 elseif actionType == 'mount' then | 135 elseif actionType == 'mount' then |
| 127 if subType == 0 then | 136 if subType == 0 then |
| 128 name, _, icon = GetSpellInfo(SUMMON_RANDOM_FAVORITE_MOUNT_SPELL) | 137 name, _, icon = GetSpellInfo(SUMMON_RANDOM_FAVORITE_MOUNT_SPELL) |
| 129 actionID = 0 | 138 actionID = 0 |
| 130 else | 139 else |
| 131 name, _, icon = C_MountJournal.GetMountInfoByID(actionID) | 140 name, _, icon = GetMountInfoByID(actionID) |
| 132 end | 141 end |
| 133 elseif actionType == 'item' then | 142 elseif actionType == 'item' then |
| 134 name = GetItemInfo(actionID) | 143 name = GetItemInfo(actionID) |
| 135 icon = GetItemIcon(actionID) | 144 icon = GetItemIcon(actionID) |
| 136 actionID = name | 145 actionID = name |
| 137 elseif actionType == 'battlepet' then | 146 elseif actionType == 'battlepet' then |
| 138 | 147 |
| 139 local speciesID, customName, level, xp, maxXp, displayID, isFavorite, petName, petIcon, petType, creatureID = C_PetJournal.GetPetInfoByPetID(detail); | 148 local speciesID, customName, level, xp, maxXp, displayID, isFavorite, petName, petIcon, petType, creatureID = GetPetInfoByPetID(actionID) |
| 140 name = customName or petName | 149 name = customName or petName |
| 141 icon = petIcon | 150 icon = petIcon |
| 142 | 151 |
| 143 end | 152 end |
| 144 local macroName, macroText, command = kb.RegisterAction(actionType, actionID, name) | 153 local macroName, macroText, command = kb.RegisterAction(actionType, actionID, name) |
| 198 kb.UpdateSlot(self) | 207 kb.UpdateSlot(self) |
| 199 end | 208 end |
| 200 end | 209 end |
| 201 end | 210 end |
| 202 | 211 |
| 203 kb.UnbindSlot = function(self) | 212 |
| 204 | |
| 205 local keys = {GetBindingKey(self.command) } | |
| 206 if #keys >= 1 then | |
| 207 kb.UpdateBindingsCache(self.actionType, self.actionID, {}) | |
| 208 end | |
| 209 | |
| 210 | |
| 211 --print('detected', #keys, 'bindings') | |
| 212 for i, key in pairs(keys) do | |
| 213 --print('clearing', key) | |
| 214 SetBinding(key, nil) | |
| 215 SaveBindings(GetCurrentBindingSet()) | |
| 216 if kb.currentProfile.bindings[key] then | |
| 217 --kb:print(L('BINDING_REMOVED', self.actionName, kb.currentHeader)) | |
| 218 kb.currentProfile.bindings[key] = nil | |
| 219 end | |
| 220 if kb.currentProfile.talents[self.actionName] then | |
| 221 kb.currentProfile.talents[self.actionName] = nil | |
| 222 end | |
| 223 | |
| 224 kb.bindings[tostring(self.actionType)..'_'..tostring(self.actionID)] = nil | |
| 225 end | |
| 226 if kb.currentProfile.bound[self.command] then | |
| 227 kb.currentProfile.bound[self.command] = nil | |
| 228 --kb:print(BINDING_REMOVED:format(self.actionName, configHeaders[db.bindMode])) | |
| 229 end | |
| 230 | |
| 231 | |
| 232 self.active = false | |
| 233 kb.UpdateSlot(self, true) | |
| 234 end | |
| 235 | |
| 236 --- Updates the current KeyBinding for the button's command | |
| 237 kb.SaveSlot = function(self, key) | |
| 238 | |
| 239 if not self.command then | |
| 240 return | |
| 241 end | |
| 242 print('|cFFFFFF00received|cFFFFFF00', self:GetID(), '|cFF00FFFF', key) | |
| 243 | |
| 244 local modifier = '' | |
| 245 if IsAltKeyDown() then | |
| 246 modifier = 'ALT-' | |
| 247 end | |
| 248 if IsControlKeyDown() then | |
| 249 modifier = modifier.. 'CTRL-' | |
| 250 end | |
| 251 if IsShiftKeyDown() then | |
| 252 modifier = modifier..'SHIFT-' | |
| 253 end | |
| 254 local binding = modifier..key | |
| 255 | |
| 256 if key == 'ESCAPE' then | |
| 257 else | |
| 258 if kb.SystemBindings[binding] then | |
| 259 kb.statustext:SetText(L('BINDING_FAILED_PROTECTED', binding, kb.SystemBindings[binding])) | |
| 260 return | |
| 261 end | |
| 262 | |
| 263 | |
| 264 if self.command then | |
| 265 | |
| 266 local previousCommand = GetBindingAction(binding) | |
| 267 if previousCommand ~= "" and previousCommand ~= self.command then | |
| 268 if kb.SystemBindings[binding] then | |
| 269 -- bounce out if trying to use a protected key | |
| 270 kb.statustext:SetText(L('BINDING_FAILED_PROTECTED', key, GetBindingAction(binding))) | |
| 271 kb.bindingstext:SetText(nil) | |
| 272 return false | |
| 273 end | |
| 274 | |
| 275 local actionType, actionID, name = kb.GetCommandAction(previousCommand) | |
| 276 if actionType then | |
| 277 local keys = {GetBindingKey(previousCommand) } | |
| 278 local i = 1 | |
| 279 while keys[i] do | |
| 280 if keys[i] == binding then | |
| 281 table.remove(keys, i) | |
| 282 kb.UpdateBindingsCache(actionType, actionID, keys) | |
| 283 break | |
| 284 end | |
| 285 i = i + 1 | |
| 286 end | |
| 287 end | |
| 288 end | |
| 289 | |
| 290 local currentHotKeys = {GetBindingKey(self.command)} | |
| 291 local found | |
| 292 for i, key in ipairs(currentHotKeys) do | |
| 293 if key == binding then | |
| 294 found = true | |
| 295 kb:print('hotkey already assigned') | |
| 296 end | |
| 297 end | |
| 298 if not found then | |
| 299 table.insert(currentHotKeys, 1, binding) | |
| 300 kb.UpdateBindingsCache(self.actionType, self.actionID, currentHotKeys) | |
| 301 end | |
| 302 | |
| 303 self.binding = binding | |
| 304 | |
| 305 | |
| 306 print('SetBinding', binding, self.command) | |
| 307 SetBinding(self.binding, self.command) | |
| 308 SaveBindings(GetCurrentBindingSet()) | |
| 309 | |
| 310 | |
| 311 | |
| 312 local talentInfo | |
| 313 if self.actionType == 'spell' and kb.TalentCache[self.actionID] then | |
| 314 print('conditional binding (talent = "'..self.actionName..'")') | |
| 315 talentInfo = {self.macroName, self.actionName, self.actionType, self.actionID} | |
| 316 local bindings = {GetBindingKey(self.command) } | |
| 317 for i, key in ipairs(bindings) do | |
| 318 tinsert(talentInfo, key) | |
| 319 end | |
| 320 end | |
| 321 | |
| 322 for level, profile in ipairs(kb.orderedProfiles) do | |
| 323 if (level == kb.db.bindMode) then | |
| 324 profile.bound[self.command] = true | |
| 325 if talentInfo then | |
| 326 profile.bindings[self.binding] = nil | |
| 327 else | |
| 328 profile.bindings[self.binding] = self.command | |
| 329 end | |
| 330 profile.talents[self.actionName] = talentInfo | |
| 331 else | |
| 332 profile.bindings[self.binding] = nil | |
| 333 profile.bound[self.command] = nil | |
| 334 kb.currentProfile.talents[self.actionName] = nil | |
| 335 end | |
| 336 if kb.currentProfile.talents[self.actionID] then | |
| 337 kb.currentProfile.talents[self.actionID] = nil | |
| 338 end | |
| 339 end | |
| 340 | |
| 341 kb:print(L('BINDING_ASSIGNED', self.binding, self.actionName, kb.currentHeader)) | |
| 342 end | |
| 343 end | |
| 344 kb.UpdateSlot(self, true) | |
| 345 return true | |
| 346 end | |
| 347 | 213 |
| 348 | 214 |
| 349 --- Updates profile assignment and button contents | 215 --- Updates profile assignment and button contents |
| 350 kb.UpdateSlot = function(self, force) | 216 kb.UpdateSlot = function(self, force) |
| 351 local slot = self:GetID() | 217 local slot = self:GetID() |
| 667 end | 533 end |
| 668 end | 534 end |
| 669 end | 535 end |
| 670 end | 536 end |
| 671 | 537 |
| 672 | |
| 673 --- Add to blizzard interfaces | |
| 674 StaticPopupDialogs["SKELETONKEY_CONFIRM_ASSIGN_SLOT"] = { | |
| 675 text = "Confirm moving an assigned command.", | |
| 676 button1 = OKAY, | |
| 677 button2 = CANCEL, | |
| 678 timeout = 0, | |
| 679 whileDead = 1, | |
| 680 showAlert = 1, | |
| 681 OnAccept = kb.AcceptAssignment, | |
| 682 OnCancel = function() kb:SetScript('OnMouseWheel', KeyBinder_OnMouseWheel) end | |
| 683 } |
