Originally Posted by JohnnyKing94
I already tried in the past to use the ZO_KeybindStrip without having good results due to the lack of explainations on the wiki page and the missing knowledge on how to apply it correctly... if you have a good example of working code, you're just amazing... thx in advance
|
- When addon loads, you'll need to declare the descriptor.
- When you show your panel, you'll need to add your keybind strip
- When you hide your panel, you'll need to remove it.
When addon loads, you'll need to declare the descriptor.
Lua Code:
myaddon.keybindDescriptor = {
alignment = KEYBIND_STRIP_ALIGN_CENTER,
{
name = GetString(A_STRING_CREATED_WITH_ZO_CREATESTRINGID),
keybind = "UI_SHORTCUT_PRIMARY", -- or any other bindings. to create a binding, you'll need to write a small piece of xml and define it. but you can use standardui keybinds too.
control = self, -- don't change
callback = function(descriptor)
--function to execute when you'll click / push the keybind button.
end,
visible = function(descriptor)
-- returns a boolean to say if keybind is visible or not.
end
},
When you show your panel, you'll need to add your keybind strip
When you hide your panel, you'll need to remove it.
Lua Code:
local function showOrHide(oldState, newState)
if newState == SCENE_SHOWING then
KEYBIND_STRIP:AddKeybindButtonGroup(myaddon.keybindDescriptor)
elseif newState == SCENE_HIDDEN then
if KEYBIND_STRIP:HasKeybindButtonGroup(myaddon.keybindDescriptor) then
KEYBIND_STRIP:RemoveKeybindButtonGroup(myaddon.keybindDescriptor)
end
end
end
myAddon.sceneWithKeybind = SCENE_MANAGER:GetScene("itsNameDefinedInSceneManager")
myAddon.sceneWithKeybind:RegisterCallback("StateChange", showOrHide)
You can also update your keybind. Eg you hover your mouse over a control, and you need to update your keybind strip :
Lua Code:
local function UpdateKeybind(control)
if KEYBIND_STRIP:HasKeybindButtonGroup(pChat.autoMsgDescriptor) then
KEYBIND_STRIP:UpdateKeybindButtonGroup(pChat.autoMsgDescriptor)
end
end
...
control:SetHandler("OnMouseEnter", function(self) UpdateKeybind(self) end)
control:SetHandler("OnMouseExit", function(self) UpdateKeybind(self) end)