Mercurial > wow > skeletonkey
comparison SkeletonKey/ActionTypes.lua @ 17:500f9b2bd9ac
- for RegisterAction, use a function table instead of that if/then rats nest
- consequently pet bar actions work now
- unlocalize bindings data
- activate keyslot input manually instead of on mouse over
- activate checkbox to keep input mode active
- dynamic buttons update in real time for petaction/talent/profession spells
| author | Nenue |
|---|---|
| date | Sat, 30 Jul 2016 00:08:00 -0400 |
| parents | cdd387d39137 |
| children | 67db6b712bf3 |
comparison
equal
deleted
inserted
replaced
| 16:cdd387d39137 | 17:500f9b2bd9ac |
|---|---|
| 2 -- ActionTypes.lua | 2 -- ActionTypes.lua |
| 3 -- Created: 7/29/2016 9:14 PM | 3 -- Created: 7/29/2016 9:14 PM |
| 4 -- %file-revision% | 4 -- %file-revision% |
| 5 -- | 5 -- |
| 6 local kb, print, wrap = LibStub('LibKraken').register(KeyBinder) | 6 local kb, print, wrap = LibStub('LibKraken').register(KeyBinder) |
| 7 local cprint = DEVIAN_WORKSPACE and function(...) _G.print('Cfg', ...) end or function() end | |
| 7 | 8 |
| 8 local SUMMON_RANDOM_FAVORITE_MOUNT_SPELL = 150544 | 9 local SUMMON_RANDOM_FAVORITE_MOUNT_SPELL = 150544 |
| 10 local CLICK_KEYBINDER_MACRO = "CLICK KeyBinderMacro:" | |
| 11 local CLICK_KEYBINDER_KEY = "CLICK KeyBinderKey:" | |
| 9 | 12 |
| 10 local PETACTION_SCRIPT = { | 13 local PETACTION_SCRIPT = { |
| 11 [PET_ACTION_MOVE_TO] = {SLASH_PET_MOVE_TO1, 'pet_move_to'}, | 14 [PET_ACTION_MOVE_TO] = {SLASH_PET_MOVE_TO1, 'pet_move_to'}, |
| 12 [PET_ACTION_ATTACK] = {SLASH_PET_ATTACK1, 'pet_attack'}, | 15 [PET_ACTION_ATTACK] = {SLASH_PET_ATTACK1, 'pet_attack'}, |
| 13 [PET_ACTION_FOLLOW] = {SLASH_PET_FOLLOW1, 'pet_follow'}, | 16 [PET_ACTION_FOLLOW] = {SLASH_PET_FOLLOW1, 'pet_follow'}, |
| 16 [PET_MODE_DEFENSIVE] = {SLASH_PET_DEFENSIVE1, 'pet_defensive'}, | 19 [PET_MODE_DEFENSIVE] = {SLASH_PET_DEFENSIVE1, 'pet_defensive'}, |
| 17 [PET_MODE_PASSIVE] = {SLASH_PET_PASSIVE1, 'pet_passive'}, | 20 [PET_MODE_PASSIVE] = {SLASH_PET_PASSIVE1, 'pet_passive'}, |
| 18 [PET_MODE_ASSIST] = {SLASH_PET_ASSIST1, 'pet_assist'}, | 21 [PET_MODE_ASSIST] = {SLASH_PET_ASSIST1, 'pet_assist'}, |
| 19 } | 22 } |
| 20 | 23 |
| 21 --- Caps Lock derivatives | 24 --- Caps Lock |
| 22 local ACTION_HANDLERS = {} | 25 local ACTION_HANDLERS = {} |
| 23 ACTION_HANDLERS['mount'] = function(id, name) | 26 ACTION_HANDLERS['mount'] = function(id, name) |
| 24 return "/script C_MountJournal.SummonByID("..id..")" | 27 if id == SUMMON_RANDOM_FAVORITE_MOUNT_SPELL then |
| 28 return 'mount_random', "/script C_MountJournal.SummonByID(0)", CLICK_KEYBINDER_MACRO | |
| 29 else | |
| 30 return 'mount_'..id, "/script C_MountJournal.SummonByID("..id..")", CLICK_KEYBINDER_MACRO | |
| 31 end | |
| 25 end | 32 end |
| 26 ACTION_HANDLERS['macro'] = "%s" | 33 ACTION_HANDLERS['macro'] = function(id, name) |
| 27 ACTION_HANDLERS['equipset'] = "/script UseEquipmentSet(%d)" | 34 return CLICK_KEYBINDER_MACRO, 'macro_' .. tostring(name), id |
| 28 ACTION_HANDLERS['spell'] = "/cast %s" | 35 end |
| 29 ACTION_HANDLERS['petaction'] = function(id, name) | 36 ACTION_HANDLERS['equipset'] = function(id, name) |
| 30 return PETACTION_SCRIPT[name] or "/cast ".. name | 37 return CLICK_KEYBINDER_MACRO, 'equipset_'..tostring(name), "/script UseEquipmentSet("..tostring(id)..")" |
| 38 end | |
| 39 ACTION_HANDLERS['spell'] = function(id, name) | |
| 40 local attributeName = name | |
| 41 if kb.ProfessionCache[id] then | |
| 42 attributeName = "profession_".. kb.ProfessionCache[id].profOffset .. '_' .. kb.ProfessionCache[id].spellNum | |
| 43 end | |
| 44 return CLICK_KEYBINDER_KEY, attributeName, name | |
| 45 end | |
| 46 ACTION_HANDLERS['petaction'] = function(_, name) | |
| 47 -- ID doesn't exist for basic commands, even though they can be picked up | |
| 48 local attributeName, attributeValue = "petaction_" .. tostring(name), "/cast "..tostring(name) | |
| 49 if PETACTION_SCRIPT[name] then | |
| 50 attributeValue, attributeName = unpack(PETACTION_SCRIPT[name]) | |
| 51 end | |
| 52 | |
| 53 return CLICK_KEYBINDER_MACRO, attributeName, attributeValue | |
| 31 end | 54 end |
| 32 | 55 |
| 33 ACTION_HANDLERS['battlepet'] = SLASH_SUMMON_BATTLE_PET1 .. " %s" | 56 ACTION_HANDLERS['battlepet'] = function(id, name) |
| 34 ACTION_HANDLERS['item'] = "/use %s" | 57 return CLICK_KEYBINDER_MACRO, 'battlepet_' .. tostring(name), SLASH_SUMMON_BATTLE_PET1 .. " " .. tostring(name) |
| 35 local professionMappings = { | 58 end |
| 36 [5] = 3, | 59 ACTION_HANDLERS['item'] = function(id, name) |
| 37 [7] = 4, | 60 return CLICK_KEYBINDER_KEY, 'item_' .. tostring(name), id |
| 38 [9] = 5, | 61 end |
| 39 [10] = 6 | |
| 40 } | |
| 41 | 62 |
| 42 | 63 |
| 43 --- Generates the command strings needed to assign different abilities | 64 --- Resolves the SecureActionButton attribute names used for the given action |
| 44 kb.RegisterAction = function(actionType, id, name) | 65 kb.RegisterAction = function(actionType, id, name) |
| 45 local macroText, macroName, command = '', '', '' | |
| 46 | 66 |
| 47 if actionType == 'spell' then | 67 assert(ACTION_HANDLERS[actionType], 'Missing actionType handler for `'..tostring(actionType)..'`') |
| 48 if kb.ProfessionCache[id] then | 68 local target, attributeName, attributeValue = ACTION_HANDLERS[actionType](id, name) |
| 49 command = CLICK_KEYBINDER_KEY .. "profession_".. kb.ProfessionCache[id].profOffset .. '_' .. kb.ProfessionCache[id].spellNum | 69 |
| 70 local command = target .. attributeName | |
| 71 local baseName, iterative = attributeName, 1 | |
| 72 while (kb.macros[attributeName] and kb.macros[attributeName][1] ~= attributeValue) do | |
| 73 print(' * cannot use|cFF00FF00', attributeName, '|r"'.. tostring(kb.macros[attributeName][1]) .. '"') | |
| 74 attributeName = baseName .. '_' .. iterative | |
| 75 iterative = iterative + 1 | |
| 76 end | |
| 77 if macroName ~= baseName then | |
| 78 print(' * Creating|cFF00FF00', macroName) | |
| 79 else | |
| 80 print(' * Re-using|cFF00FF00', macroName) | |
| 81 end | |
| 82 kb.macros[attributeName] = {attributeValue, command} | |
| 83 | |
| 84 | |
| 85 print('RegisterAction', actionType, id, '->', attributeName, attributeValue, target .. attributeName) | |
| 86 return attributeName, attributeValue, command | |
| 87 end | |
| 88 | |
| 89 | |
| 90 | |
| 91 | |
| 92 kb.inactiveTalentBindings = {} | |
| 93 kb.ApplyTalentBinding = function(talentInfo, cache) | |
| 94 for i = 5, #talentInfo do | |
| 95 local command = CLICK_KEYBINDER_KEY.. talentInfo[2] | |
| 96 SetBinding(talentInfo[i], command) | |
| 97 cprint(' **', talentInfo[i], '->', command) | |
| 98 tinsert(cache, talentInfo[i]) | |
| 99 end | |
| 100 end | |
| 101 kb.CacheTalentBinding = function(talentInfo, cache) | |
| 102 | |
| 103 local spellID = talentInfo[4] | |
| 104 kb.inactiveTalentBindings[spellID] = kb.inactiveTalentBindings[spellID] or {} | |
| 105 kb.inactiveTalentBindings[spellID] = {select(5,unpack(talentInfo)) } | |
| 106 --cprint(spellID, unpack(kb.inactiveTalentBindings[spellID])) | |
| 107 end | |
| 108 | |
| 109 do | |
| 110 local bindings = kb.bindings | |
| 111 local key, macro = KeyBinderKey, KeyBinderMacro | |
| 112 kb.LoadBinding = function(command, name, icon, actionType, actionID, macroName, macroText ) | |
| 113 | |
| 114 if actionType == 'spell' then | |
| 115 key:SetAttribute("*type-"..name, actionType) | |
| 116 key:SetAttribute("*"..actionType.."-"..name, name) | |
| 117 elseif actionType == 'item' then | |
| 118 key:SetAttribute("*type-"..name, actionType) | |
| 119 key:SetAttribute("*"..actionType.."-"..name, name) | |
| 120 elseif actionType == 'macro' then | |
| 121 macro:SetAttribute("*macro-"..macroName, actionID) | |
| 50 else | 122 else |
| 51 command = CLICK_KEYBINDER_KEY ..name | 123 macro:SetAttribute("*macrotext-"..macroName, macroText) |
| 52 end | |
| 53 else | |
| 54 | |
| 55 if type(ACTION_SCRIPT[actionType]) == 'function' then | |
| 56 macroName, macroText = ACTION_SCRIPT[actionType](id, name) | |
| 57 else | |
| 58 macroName = actionType .. ' ' .. name | |
| 59 macroText = ACTION_SCRIPT[actionType]:format(name) | |
| 60 end | 124 end |
| 61 | 125 |
| 62 local baseName, iterative = macroName, 1 | 126 cprint('Loading binding', actionType, actionID) |
| 63 while (macros[macroName] and macros[macroName][1] ~= macroText) do | 127 bindings[actionType] = bindings[actionType] or {} |
| 64 print(' * cannot use|cFF00FF00', macroName, '|r"'.. (macros[macroName][1] or '') .. '"') | 128 bindings[actionType][actionID] = bindings[actionType][actionID] or {} |
| 65 macroName = baseName .. '_' .. iterative | 129 bindings[command] = bindings[actionType][actionID] |
| 66 iterative = iterative + 1 | 130 return bindings[actionType], actionID |
| 67 end | |
| 68 if macroName ~= baseName then | |
| 69 print(' * Creating|cFF00FF00', macroName) | |
| 70 else | |
| 71 print(' * Re-using|cFF00FF00', macroName) | |
| 72 end | |
| 73 command = 'CLICK KeyBinderMacro:'.. macroName | |
| 74 macros[macroName] = {macroText, command } | |
| 75 end | 131 end |
| 76 | 132 |
| 77 print('RegisterAction', actionType, id, '->', command , macroText) | 133 kb.ApplyBindings = function (profile) |
| 78 return macroName, macroText, command | 134 cprint('binding profile', profile) |
| 135 for slot, data in pairs(profile.buttons) do | |
| 136 kb.LoadBinding(unpack(data)) | |
| 137 end | |
| 138 | |
| 139 for key, command in pairs(profile.bindings) do | |
| 140 | |
| 141 cprint(' *', key, '->', command) | |
| 142 | |
| 143 --_G.print('HotKey','loading', key, command) | |
| 144 SetBinding(key, command) | |
| 145 if bindings[command] and not tContains(bindings[command], key) then | |
| 146 tinsert(bindings[command], key) | |
| 147 end | |
| 148 end | |
| 149 | |
| 150 for spellName, talentInfo in pairs(profile.talents) do | |
| 151 local dummy = GetSpellInfo(spellName) | |
| 152 local func = kb.CacheTalentBinding | |
| 153 local dest = kb.inactiveTalentBindings | |
| 154 if dummy then | |
| 155 cprint('|cFFBBFF00Active:|r', dummy) | |
| 156 local macroName, spellName, actionType, actionID = unpack(talentInfo) | |
| 157 bindings[actionType] = bindings[actionType] or {} | |
| 158 bindings[actionType][actionID] = {} | |
| 159 func = kb.ApplyTalentBinding | |
| 160 dest = kb.bindings[actionType][actionID] | |
| 161 else | |
| 162 | |
| 163 cprint('|cFFFF4400Inactive:|r', talentInfo[2]) | |
| 164 end | |
| 165 func(talentInfo, dest) | |
| 166 end | |
| 167 | |
| 168 end | |
| 169 | |
| 170 kb.ApplyAllBindings =function () | |
| 171 table.wipe(kb.inactiveTalentBindings) | |
| 172 | |
| 173 | |
| 174 -- reflect action key settings | |
| 175 if GetCVarBool("ActionButtonUseKeyDown") then | |
| 176 KeyBinderMacro:RegisterForClicks("AnyDown") | |
| 177 KeyBinderKey:RegisterForClicks("AnyDown") | |
| 178 else | |
| 179 KeyBinderMacro:RegisterForClicks("AnyUp") | |
| 180 KeyBinderKey:RegisterForClicks("AnyUp") | |
| 181 end | |
| 182 | |
| 183 for i, profile in ipairs(kb.orderedProfiles) do | |
| 184 kb.ApplyBindings(profile) | |
| 185 end | |
| 186 -- do this after to ensure that profession binds are properly overridden | |
| 187 kb.UpdateProfessionInfo() | |
| 188 | |
| 189 | |
| 190 SaveBindings(GetCurrentBindingSet()) | |
| 191 end | |
| 79 end | 192 end |
