Mercurial > wow > skeletonkey
changeset 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 | d0ee4553061a |
children | 29c89dbe07ac |
files | SkeletonKey/BindingsFrame.lua SkeletonKey/KeyButton.lua SkeletonKey/SkeletonKey.lua |
diffstat | 3 files changed, 212 insertions(+), 208 deletions(-) [+] |
line wrap: on
line diff
--- a/SkeletonKey/BindingsFrame.lua Fri Aug 19 09:29:23 2016 -0400 +++ b/SkeletonKey/BindingsFrame.lua Fri Aug 19 10:46:36 2016 -0400 @@ -2,9 +2,21 @@ -- BindingsFrame.lua -- Created: 7/28/2016 3:39 PM -- %file-revision% --- Code piecing the interface together +-- Handles the arrangement of and interaction with the SkeletonKey frame +--[=[ + -- some useful texture paths + [[Interface\PaperDollInfoFrame\UI-GearManager-Undo]] + [[Interface\PetPaperDollFrame\UI-PetHappiness]] + [[Interface\RAIDFRAME\ReadyCheck-Waiting]] + [[Interface\RAIDFRAME\ReadyCheck-Read]] + [[Interface\RAIDFRAME\ReadyCheck-NotReady]] + [[Interface\TradeSkillFrame\UI-TradeSkill-LinkButton]] + [[Interface\TUTORIALFRAME\UI-TUTORIAL-FRAME]] + [[Interface\UI-TutorialFrame-QuestGiver\UI-TutorialFrame-QuestGray]] +--]=] -local kb, print = LibStub("LibKraken").register(KeyBinder, 'KeySlot') +local kb, print = LibStub("LibKraken").register(KeyBinder, 'BindingsUI') +local L = kb.L local BINDS_PER_ROW = 2 local BINDING_TYPE_SPECIALIZATION = 3 local BINDING_TYPE_CHARACTER = 2 @@ -32,50 +44,46 @@ [BINDING_TYPE_GLOBAL] = {0, 1, 1} } ---[=[ - -- some useful texture paths - [[Interface\PaperDollInfoFrame\UI-GearManager-Undo]] - [[Interface\PetPaperDollFrame\UI-PetHappiness]] - [[Interface\RAIDFRAME\ReadyCheck-Waiting]] - [[Interface\RAIDFRAME\ReadyCheck-Read]] - [[Interface\RAIDFRAME\ReadyCheck-NotReady]] - [[Interface\TradeSkillFrame\UI-TradeSkill-LinkButton]] - [[Interface\TUTORIALFRAME\UI-TUTORIAL-FRAME]] - [[Interface\UI-TutorialFrame-QuestGiver\UI-TutorialFrame-QuestGray]] ---]=] -local lastFolder -local addT = function(frame, key, folder, name) - folder = folder or lastFolder - frame[key] = frame:CreateTexture() - frame[key]:SetTexture('Interface\\' .. folder .. '\\' .. name) - frame[key]:SetPoint('TOPLEFT') - lastFolder = folder +local match, strupper = string.match, string.upper +local tremove, tinsert, ipairs, pairs, unpack = table.remove, table.insert, ipairs, pairs, unpack +local tonumber, tostring = tonumber, tostring +local GetCursorInfo, ClearCursor, ResetCursor = GetCursorInfo, ClearCursor, ResetCursor +local IsShiftKeyDown, IsControlKeyDown, IsAltKeyDown = IsShiftKeyDown, IsControlKeyDown, IsAltKeyDown +local GetBindingAction, GetBindingKey, GetCurrentBindingSet = GetBindingAction, GetBindingKey, GetCurrentBindingSet +local SetBinding, SaveBindings = SetBinding, SaveBindings + +kb.ProcessInput = function(key) + if key == 'ESCAPE' then + kb.DeactivateSlot(kb.saveTarget) + kb.ui() + return + end + + if (match(key, '[RL]SHIFT') or match(key, '[RL]ALT') or match(key, '[RL]CTRL')) then + return + end + + if kb.saveTarget then + if kb.SaveSlot(kb.saveTarget, key) then + if not (kb.db.stickyMode or kb.db.hoverInput) then + kb.DeactivateSlot(kb.saveTarget) + end + end + kb.ui() + end end +local lastFolder local restingAlpha = 0.7 local fadeTime, fadeDelay = .30, 0.15 local saveButton local KeyButton_OnKeyDown = function(self, key) - kb.saveTarget.border:SetColorTexture(1,1,1,1) + local st = kb.saveTarget + kb.ProcessInput(key) end local KeyButton_OnKeyUp = function(self, key) - kb.UpdateSlot(kb.saveTarget) - if key == 'ESCAPE' then - kb.DeactivateSlot(kb.saveTarget) - kb.ui() - return - end - if key:match('[RL]SHIFT') or key:match('[RL]ALT') or key:match('[RL]CTRL') then - return - elseif kb.saveTarget then - if kb.SaveSlot(kb.saveTarget, key) then - if not (kb.db.stickyMode or kb.db.hoverInput) then - kb.DeactivateSlot(kb.saveTarget) - end - kb.ui() - end - end + local st = kb.saveTarget end local KeyButton_OnClick = function(self, click) @@ -97,13 +105,8 @@ elseif click == 'RightButton' then kb.ReleaseSlot(self) kb.ui() - elseif kb.saveTarget then - if kb.SaveSlot(kb.saveTarget, string.upper(click)) then - if not (kb.db.stickyMode or kb.db.hoverInput) then - kb.DeactivateSlot(kb.saveTarget) - end - kb.ui() - end + else + kb.ProcessInput(strupper(click)) end end @@ -213,15 +216,10 @@ frame.header:SetText(header) frame:SetScript('OnClick', function(self) + kb.db[dbKey] = self:GetChecked() if callback then callback(self) end - kb.db[dbKey] = self:GetChecked() - if not kb.db[dbKey] then - if kb.saveTarget then - kb.DeactivateSlot(kb.saveTarget) - end - end kb.ui() end) @@ -360,7 +358,11 @@ function() OpenAllBags() end, "Interface\\BUTTONS\\UI-MicroButtonCharacter-Up", {0, 1, .4, 1}) - KeyBinder_CheckButton(KeyBinderStickyMode, 'Enabled', 'Disabled', 'stickyMode', 'Keep input active after receiving a key.', nil, 'Sticky:') + KeyBinder_CheckButton(KeyBinderStickyMode, 'Enabled', 'Disabled', 'stickyMode', 'Keep input active after receiving a key.', function() + if kb.saveTarget and (not kb.db.stickyMode) then + kb.DeactivateSlot(kb.saveTarget) + end + end, 'Sticky:') KeyBinder_CheckButton(KeyBinderHoverInput, 'MouseOver', 'Click', 'hoverInput', 'Enable key input when the cursor is over a binding slot.', nil, 'Bind by:') KeyBinder_CheckButton(KeyBinderProtectBindings, 'Block', 'Allow', 'protectBlizKeys', 'Allow overwriting Blizzard UI bindings.', nil, 'Safety:') @@ -491,6 +493,140 @@ kb.talentsPushed = nil end +--- Associate processed input with the given slot's metadata +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 + + -- check for system bindings + --bprint('|cFFFFFF00SaveBind|r', 'protectKeys', kb.db.protectBlizKeys) + if kb.db.protectBlizKeys and kb.SystemBindings[binding] then + kb.statustext:SetText(L('BINDING_FAILED_PROTECTED', binding, kb.SystemBindings[binding])) + kb.bindingstext:SetText(nil) + return false + end + + -- check for other keys + local previousCommand = GetBindingAction(binding) + if previousCommand ~= "" and previousCommand ~= self.command then + 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 + tremove(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 + tinsert(currentHotKeys, 1, binding) + kb.UpdateBindingsCache(self.actionType, self.actionID, currentHotKeys) + end + + + + print('SetBinding', binding, self.command) + SetBinding(binding, self.command) + SaveBindings(GetCurrentBindingSet()) + self.binding = binding + + local talentInfo + if self.actionType == 'spell' and kb.TalentCache[self.actionID] then + print('store dynamicType talent') + 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)) + kb.UpdateSlot(self, true) + return true +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 + kb.AcceptAssignment = function(self, ...) local popup = StaticPopupDialogs["SKELETONKEY_CONFIRM_ASSIGN_SLOT"] local source = kb. loadedProfiles[popup.oldProfile] @@ -500,3 +636,15 @@ ClearCursor() ResetCursor() 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
--- 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
--- a/SkeletonKey/SkeletonKey.lua Fri Aug 19 09:29:23 2016 -0400 +++ b/SkeletonKey/SkeletonKey.lua Fri Aug 19 10:46:36 2016 -0400 @@ -25,7 +25,7 @@ local CLASS_ICON_TEXTURE = "Interface\\GLUES\\CHARACTERCREATE\\UI-CHARACTERCREATE-CLASSES" L.BINDING_ASSIGNED = '|cFF00FF00%s|r assigned to |cFFFFFF00%s|r (%s).' L.BINDING_REMOVED = '|cFFFFFF00%s|r (|cFF00FFFF%s|r) unbound.' -L.BINDING_FAILED_PROTECTED = '|cFFFF4400Unable to use |r|cFF00FF00%s|r|cFFFF4400 (currently |cFFFFFF00%s|r|cFFFF4400)|r' +L.BINDING_FAILED_PROTECTED = '|cFFFF4400Cannot use |r|cFF00FF00%s|r|cFFFF4400 (currently |cFFFFFF00%s|r|cFFFF4400). Uncheck "Safety" to ignore this restraint.|r' local BINDING_TYPE_SPECIALIZATION = 3