--[[ Author: Jarth Filename: CBs_Bindings.lua ]] -- ------------------------------------------------------------------------------------------------- -- VARIABLES -- ------------------------------------------------------------------------------------------------- local base = CollectionBars ------------------------------------------------------------------------------------------------- -- PUBLIC FUNCTIONS -- ------------------------------------------------------------------------------------------------- function CBs_Clicked(keyId) local control = base.WM:GetMouseOverControl() if control ~= nil and control.CBs then local newCId = control:GetId() local previousCId = base.Saved.Bindings[keyId] if previousCId ~= newCId then for _keyId, cid in pairs(base.Saved.Bindings) do if _keyId ~= keyId and cid == newCId then base.Saved.Bindings[_keyId] = 0 end end for cid, _keyId in pairs(base.Global.ReverseBindings) do if cid ~= newCId and _keyId == keyId then base.Global.ReverseBindings[cid] = nil base.SetbindingText(cid, "") end end base.Saved.Bindings[keyId] = newCId base.Global.ReverseBindings[newCId] = keyId if base.Buttons[newCId] then base.Buttons[newCId]:SetBindingText(base.Saved.ShowBinding, base.GetBindingNameFromCId(newCId)) end end elseif base.Saved.Bindings[keyId] > 0 and base.Buttons[base.Saved.Bindings[keyId]] then base.Activate(base.Buttons[base.Saved.Bindings[keyId]]) end end ------------------------------------------------------------------------------------------------- -- PRIVATE FUNCTIONS -- ------------------------------------------------------------------------------------------------- function base.SetbindingText(cid, text) if base.Buttons[cid] then base.Buttons[cid]:SetBindingText(base.Saved.ShowBinding, text) end end function base.InitializeBindings() for key, _ in ipairs(base.Saved.Bindings) do local abbreviation = base.Addon.Abbreviation ZO_CreateStringId("SI_BINDING_NAME_" .. abbreviation .. "_" .. key, abbreviation .. "_" .. key) end end function base.InitializeReverseBinding() for keyId, collectibleId in ipairs(base.Saved.Bindings) do if collectibleId > 0 then base.Global.ReverseBindings[collectibleId] = keyId end end end function base.GetBindingNameFromCId(cid) local result = "" local keyId = base.Global.ReverseBindings[cid] if keyId then for _, value in pairs({GetHighestPriorityActionBindingInfoFromName(base.Addon.Abbreviation .. "_" .. keyId)}) do if value > 0 then local bindingName = GetKeyName(value) if result ~= "" then result = string.format("%s+%s", bindingName, result) else result = bindingName end end end end return result end