ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   AddOn Help/Support (https://www.esoui.com/forums/forumdisplay.php?f=164)
-   -   How to add a keybind for existing addon? (https://www.esoui.com/forums/showthread.php?t=7289)

p6kocka 08/13/17 01:48 AM

How to add a keybind for existing addon?
 
There are couple of addons that disable spinning/zooming to character in menus. For example "no spin" or "no thank you" ...
How to add a keybind to that function? I know there must be a .xml file, but what exactly add to it? For example "no spin" addon has only this lines in its lua file:

EVENT_MANAGER:RegisterForEvent("SpinStop", EVENT_ADD_ON_LOADED,
function(eventCode, addon)
if (addon):find("^ZO_") then return end

for name, scene in pairs(SCENE_MANAGER.scenes) do
if not (name):find("market") and scene:HasFragment(FRAME_PLAYER_FRAGMENT) then
scene:RemoveFragment(FRAME_PLAYER_FRAGMENT)
end
end

EVENT_MANAGER:UnregisterForEvent("SpinStop", eventCode)
end)

Rhyono 08/13/17 09:17 AM

Take a look at my interaction addon, since it's small and has keybindings.

p6kocka 08/13/17 11:50 AM

I´ve tried but with lua errors...
It must be a way to toggle spinning with a key...

Ayantir 08/14/17 03:56 AM

You have dozens of addons which are very small and contains only 1 keybind.

To create a keybind :
  1. Add your Keybind definition file to your metafile (Keybinds should always be defined in last in mletafile)


    ex :

    Code:

    ## Title: MyAddon
    ## APIVersion: 100020
    ## Author: Me
    ## Description: Do something
    ## Version: 1

    MyAddon.lua
    Bindings.xml

  2. Create your keybind definition file it will link your Keybind to a function defined in your code. The function must be global (no "local keyword front of your function definition) :

    Code:

    <Bindings>
            <Layer name="SI_KEYBINDINGS_LAYER_GENERAL">
                    <Category name="MyAddon">
                            <Action name="PUSH_THE_BUTTON">
                                    <Down>MyAddon_SayHello()</Down>
                            </Action>
                    </Category>
            </Layer>
    </Bindings>

  3. Link your function defiined in your .lua File ( MyAddon.lua ) and add the Binding string to the code

    Lua Code:
    1. ZO_CreateStringId("SI_BINDING_NAME_PUSH_THE_BUTTON", "Press to say hello")
    2.  
    3. function MyAddon_SayHello()
    4.     d("Hello")
    5. end
  4. Set your key and push the button

p6kocka 08/15/17 12:47 PM

OK. I´ve already tried it. Could you help me with already existing lua file?:

EVENT_MANAGER:RegisterForEvent("SpinStop", EVENT_ADD_ON_LOADED,
function(eventCode, addon)
if (addon):find("^ZO_") then return end

for name, scene in pairs(SCENE_MANAGER.scenes) do
if not (name):find("market") and scene:HasFragment(FRAME_PLAYER_FRAGMENT) then
scene:RemoveFragment(FRAME_PLAYER_FRAGMENT)
end
end

EVENT_MANAGER:UnregisterForEvent("SpinStop", eventCode)
end)


How to bind this function to a keybind pls?

Baertram 08/15/17 02:59 PM

It's not possible as it would need the addon to reload afterwards (after presisng the keybind).
The addon is removing whole fragments from scenes which will stay removed until you do a reloadui.
So unfortunately this won't work by help of a keybind.

You'd need to load/unload the addon and do a /reloadui afterwards.

p6kocka 08/16/17 01:54 AM

OK. I see.
Those are another lines from great addon "No thank you":

local function DontRotateGameCamera()

local emotesFragments = {
FRAME_PLAYER_FRAGMENT,
FRAME_EMOTE_FRAGMENT_INVENTORY,
FRAME_EMOTE_FRAGMENT_SKILLS,
FRAME_EMOTE_FRAGMENT_JOURNAL,
FRAME_EMOTE_FRAGMENT_MAP,
FRAME_EMOTE_FRAGMENT_SOCIAL,
FRAME_EMOTE_FRAGMENT_AVA,
FRAME_EMOTE_FRAGMENT_SYSTEM,
FRAME_EMOTE_FRAGMENT_LOOT,
FRAME_EMOTE_FRAGMENT_CHAMPION,
}

local blacklistedScenes = {
market = false,
crownCrateGamepad = true,
crownCrateKeyboard = true,
keyboard_housing_furniture_scene = true,
gamepad_housing_furniture_scene = true,
dyeStampConfirmationGamepad = true,
dyeStampConfirmationKeyboard = true,
}

if SV.noCameraSpin then
for name, scene in pairs(SCENE_MANAGER.scenes) do
if not blacklistedScenes[name] then
local sceneToSave = true
for _, fragmentToRemove in ipairs(emotesFragments) do
if scene:HasFragment(fragmentToRemove) then
scene:RemoveFragment(fragmentToRemove)
if sceneToSave then
sceneToSave = false
scenes[name] = scene
scenes[name].toRestore = {}
end
table.insert(scenes[name].toRestore, fragmentToRemove)
end
end
end
end
else
for name, scene in pairs(scenes) do
if scene.toRestore then
for index, fragment in ipairs(scene.toRestore) do
scene:AddFragment(fragment)
end
end
end
end

end


You can enable or disable camera zooming by clicking this option in settings. How about binding a key to this function?

Baertram 08/17/17 04:42 PM

Use the post from Ayantir above to build a keybind for the function
"DontRotateGameCamera".

Attention:
The function is locally defined in the addon. You need to remove the local in fron of it so the keybindings is able to use it!

Code:

local function DontRotateGameCamera()
Change to:
Code:

function DontRotateGameCamera()


All times are GMT -6. The time now is 08:52 PM.

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