ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   Tutorials & Other Helpful Info (https://www.esoui.com/forums/forumdisplay.php?f=172)
-   -   Custom Keybind Strip (https://www.esoui.com/forums/showthread.php?t=820)

Xrystal 04/12/14 07:05 PM

Custom Keybind Strip
 
1 Attachment(s)
Based on TheLabs query .. a quick break from gatherer to have a look as it would be great I'm sure if we could get those key bind strips working in our addons.

Here's the code I used to get it doing what it is currently doing and a screenshot of what it is showing. Not quite what I expected but hey .. it may have ignored my settings.

This code was exexute in the addon loaded event function. I deliberately made it global so I could see what happened. As you can see the keyLabel and nameLabel values didn't make a difference. Once I used the Set functions there was some difference but as the screenshot shows, key is not bound. So perhaps, this works alongside the keybind functionality to work fully. Neither the callback or onclicked handler worked, and no error reported.


EDIT: Correction. Just tested again and the callback function is what you use to handle the clicking of the button. The keybinding clearly has to be set up elsewhere.

EDIT 2 : Oh, and definitely can't forget to mention that this was all thanks to zgoo.


Just a little something to spark inspiration into our addons to make them feel part of the game.

Lua Code:
  1. testStrip = CreateTopLevelWindow("xmp_teststrip")
  2.     testStrip.Control1 = CreateControlFromVirtual("$(parent)_Control1",testStrip,"ZO_KeybindStripButtonTemplate")
  3.     testStrip.Control1:SetKeybind("SHIFT-H")
  4.     testStrip.Control1:SetText("SHHHHHH")
  5.     testStrip.Control1:SetCustomKeyText("Shift H")
  6.     testStrip.Control1:SetCallback(function(self) ChatMsg:AddMessage("SHHHHHH") end)
  7.     --testStrip.Control1.keyLabel:SetText("Q")
  8.     --testStrip.Control1.nameLabel:SetText("SHHHH")
  9.     testStrip.Control1:SetHandler("OnClicked", function(self,button) ChatMsg:SetMessage("SHHHHH") end)
  10.     testStrip:SetAnchor(CENTER)
  11.     testStrip:SetHidden(false)

Thenedus 04/24/14 09:52 AM

There is a nice function in KEYBIND_STRIP that takes care of all the details:

Code:

local stripDescriptor = {
  {
    alignment = KEYBIND_STRIP_ALIGN_RIGHT, // or _LEFT, _CENTER
    name = "Display name",
    keybind = "YOUR_KEYBIND_ACTION_NAME",
    callback = function(self) d("activated") end
  }
}
KEYBIND_STRIP:AddKeybindButtonGroup(stripDescriptor)
-- to remove it again
-- call with exactly the same descriptor or strange things will happen
KEYBIND_STRIP:RemoveKeybindButtonGroup(stripDescriptor)

The value for keybind must be defined for the SI_KEYBINDINGS_LAYER_USER_INTERFACE_SHORTCUTS layer.
The keybind overrides any general keybind as long the as button group is displayed. For example, I assigned "J" to the binding. When the keybind is displayed, "J" triggers the callback. Otherwise, "J" opens the journal.

DerVagabund 05/09/14 03:00 PM

Hello,

I just tried this and if I set it to J, it does ignore my command and opens the quest journal.


All times are GMT -6. The time now is 05:53 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2014 - 2022 MMOUI