From 2e7c83ada8313257e1d5b80f71eaf2a76af12cb6 Mon Sep 17 00:00:00 2001 From: "Johnny C. Lam" Date: Tue, 26 Nov 2013 14:04:42 +0000 Subject: [PATCH] Fix ticket 208 - wrong key binding being displayed. Manage an additional mapping from slot number to action, and clear the mappings for a slot if an action is removed from that slot. git-svn-id: svn://svn.curseforge.net/wow/ovale/mainline/trunk@1206 d5049fe3-3747-40f7-a4b5-f36d6801af5f --- OvaleActionBar.lua | 185 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 114 insertions(+), 71 deletions(-) diff --git a/OvaleActionBar.lua b/OvaleActionBar.lua index 4b5c927..2b886d8 100644 --- a/OvaleActionBar.lua +++ b/OvaleActionBar.lua @@ -20,22 +20,100 @@ local API_GetActionInfo = GetActionInfo local API_GetActionText = GetActionText local API_GetBindingKey = GetBindingKey ---key: spell name / value: action icon id -local self_actionSpell = {} -local self_actionMacro = {} -local self_actionItem = {} +-- Maps each action slot (1..120) to the current action: self_action[slot] = action +local self_action = {} +-- Maps each action slot (1..120) to its current keybind: self_keybind[slot] = keybind local self_keybind = {} +-- Maps each spell/macro/item ID to its current action slot. +-- self_spell[spellId] = slot +local self_spell = {} +-- self_macro[macroName] = slot +local self_macro = {} +-- self_item[itemId] = slot +local self_item = {} + local OVALE_ACTIONBAR_DEBUG = "action_bar" -- +-- +local function GetKeyBinding(slot) + --[[ + ACTIONBUTTON1..12 => primary (1..12, 13..24, 73..108) + MULTIACTIONBAR1BUTTON1..12 => bottom left (61..72) + MULTIACTIONBAR2BUTTON1..12 => bottom right (49..60) + MULTIACTIONBAR3BUTTON1..12 => top right (25..36) + MULTIACTIONBAR4BUTTON1..12 => top left (37..48) + --]] + local name + if slot <= 24 or slot > 72 then + name = "ACTIONBUTTON" .. (((slot - 1)%12) + 1) + elseif slot <= 36 then + name = "MULTIACTIONBAR3BUTTON" .. (slot - 24) + elseif slot <= 48 then + name = "MULTIACTIONBAR4BUTTON" .. (slot - 36) + elseif slot <= 60 then + name = "MULTIACTIONBAR2BUTTON" .. (slot - 48) + else + name = "MULTIACTIONBAR1BUTTON" .. (slot - 60) + end + local key = name and API_GetBindingKey(name) + return key +end + +local function UpdateActionSlot(slot) + -- Clear old slot and associated actions. + local action = self_action[slot] + if self_spell[action] == slot then + self_spell[action] = nil + elseif self_item[action] == slot then + self_item[action] = nil + elseif self_macro[action] == slot then + self_macro[action] = nil + end + self_action[slot] = nil + + -- Map the current action in the slot. + local actionType, id, subType = API_GetActionInfo(slot) + if actionType == "spell" then + id = tonumber(id) + if id then + if self_spell[id] and slot < self_spell[id] then + self_spell[id] = slot + end + self_action[slot] = id + end + elseif actionType == "item" then + id = tonumber(id) + if id then + if self_item[id] and slot < self_item[id] then + self_item[id] = slot + end + self_action[slot] = id + end + elseif actionType == "macro" then + local actionText = API_GetActionText(slot) + if actionText then + if self_macro[actionText] and slot < self_macro[actionText] then + self_macro[actionText] = slot + end + self_action[slot] = actionText + end + end + Ovale:DebugPrintf(OVALE_ACTIONBAR_DEBUG, "Mapping button %s to %s", slot, self_action[slot]) + + -- Update the keybind for the slot. + self_keybind[slot] = GetKeyBinding(slot) +end +-- + -- function OvaleActionBar:OnEnable() self:RegisterEvent("ACTIONBAR_SLOT_CHANGED") - self:RegisterEvent("ACTIVE_TALENT_GROUP_CHANGED", "FillActionIndexes") - self:RegisterEvent("PLAYER_ENTERING_WORLD", "FillActionIndexes") - self:RegisterEvent("PLAYER_TALENT_UPDATE", "FillActionIndexes") - self:RegisterEvent("UPDATE_BINDINGS", "FillActionIndexes") + self:RegisterEvent("ACTIVE_TALENT_GROUP_CHANGED", "UpdateActionSlots") + self:RegisterEvent("PLAYER_ENTERING_WORLD", "UpdateActionSlots") + self:RegisterEvent("PLAYER_TALENT_UPDATE", "UpdateActionSlots") + self:RegisterEvent("UPDATE_BINDINGS") end function OvaleActionBar:OnDisable() @@ -45,86 +123,51 @@ function OvaleActionBar:OnDisable() self:UnregisterEvent("PLAYER_TALENT_UPDATE") self:UnregisterEvent("UPDATE_BINDINGS") end - -function OvaleActionBar:ACTIONBAR_SLOT_CHANGED(event, slot, unknown) - if (slot == 0) then - self:FillActionIndexes(event) - elseif (slot) then - -- on reçoit aussi si c'est une macro avec mouseover à chaque fois que la souris passe sur une cible! - self:FillActionIndex(tonumber(slot)) - Ovale:DebugPrintf(OVALE_ACTIONBAR_DEBUG, "Mapping button %s to spell/macro", slot) - end -end -function OvaleActionBar:FillActionIndexes(event) - Ovale:DebugPrintf(OVALE_ACTIONBAR_DEBUG, "Mapping buttons to spells/macros for %s", event) - wipe(self_actionSpell) - wipe(self_actionMacro) - wipe(self_actionItem) - wipe(self_keybind) - for i=1,120 do - self:FillActionIndex(i) +function OvaleActionBar:ACTIONBAR_SLOT_CHANGED(event, slot) + slot = tonumber(slot) + if slot == 0 then + self:UpdateActionSlots(event) + elseif slot then + UpdateActionSlot(slot) end end -function OvaleActionBar:FillActionIndex(i) - self_keybind[i] = self:FindKeyBinding(i) - local actionText = API_GetActionText(i) - if actionText then - self_actionMacro[actionText] = i - else - local type, spellId = API_GetActionInfo(i); - if (type=="spell") then - self_actionSpell[spellId] = i - elseif (type =="item") then - self_actionItem[spellId] = i - end +function OvaleActionBar:UPDATE_BINDINGS(event) + Ovale:DebugPrintf(OVALE_ACTIONBAR_DEBUG, "%s: Updating key bindings.", event) + for slot = 1, 120 do + self_keybind[slot] = GetKeyBinding(slot) end end -function OvaleActionBar:FindKeyBinding(id) --- ACTIONBUTTON1..12 => principale (1..12, 13..24, 73..108) --- MULTIACTIONBAR1BUTTON1..12 => bas gauche (61..72) --- MULTIACTIONBAR2BUTTON1..12 => bas droite (49..60) --- MULTIACTIONBAR3BUTTON1..12 => haut droit (25..36) --- MULTIACTIONBAR4BUTTON1..12 => haut gauche (37..48) - local name; - if (id<=24 or id>72) then - name = "ACTIONBUTTON"..(((id-1)%12)+1); - elseif (id<=36) then - name = "MULTIACTIONBAR3BUTTON"..(id-24); - elseif (id<=48) then - name = "MULTIACTIONBAR4BUTTON"..(id-36); - elseif (id<=60) then - name = "MULTIACTIONBAR2BUTTON"..(id-48); - else - name = "MULTIACTIONBAR1BUTTON"..(id-60); +function OvaleActionBar:UpdateActionSlots(event) + Ovale:DebugPrintf(OVALE_ACTIONBAR_DEBUG, "%s: Updating all action slot mappings.", event) + wipe(self_action) + wipe(self_item) + wipe(self_macro) + wipe(self_spell) + for slot = 1, 120 do + UpdateActionSlot(slot) end - local key = API_GetBindingKey(name); ---[[ if (not key) then - DEFAULT_CHAT_FRAME:AddMessage(id.."=>"..name.." introuvable") - else - DEFAULT_CHAT_FRAME:AddMessage(id.."=>"..name.."="..key) - end]] - return key; end --- Get the action id that match a spell id +-- Get the action slot that matches a spell ID. function OvaleActionBar:GetForSpell(spellId) - return self_actionSpell[spellId] + return self_spell[spellId] end --- Get the action id that match a macro id -function OvaleActionBar:GetForMacro(macroId) - return self_actionMacro[macroId] +-- Get the action slot that matches a macro name. +function OvaleActionBar:GetForMacro(macroName) + return self_macro[macroName] end --- Get the action id that match an item id +-- Get the action slot that matches an item ID. function OvaleActionBar:GetForItem(itemId) - return self_actionItem[itemId] + return self_item[itemId] end -function OvaleActionBar:GetBinding(actionId) - return self_keybind[actionId] +-- Get the keybinding for an action slot. +function OvaleActionBar:GetBinding(slot) + return self_keybind[slot] end -- -- 1.7.9.5