Quantcast How to add a keybind for existing addon? - ESOUI
Thread Tools Display Modes
08/13/17, 01:48 AM   #1
p6kocka
Join Date: Apr 2014
Posts: 19
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)
  Reply With Quote
08/13/17, 09:17 AM   #2
Rhyono
AddOn Author - Click to view addons
Join Date: Sep 2016
Posts: 355
Take a look at my interaction addon, since it's small and has keybindings.
  Reply With Quote
08/13/17, 11:50 AM   #3
p6kocka
Join Date: Apr 2014
Posts: 19
Ive tried but with lua errors...
It must be a way to toggle spinning with a key...
  Reply With Quote
08/14/17, 03:56 AM   #4
Ayantir
 
Ayantir's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 1,003
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
__________________
Obsessive Compulsive Coder

My little french Guild: Cercle de l'Eveil

Last edited by Ayantir : 08/14/17 at 03:59 AM.
  Reply With Quote
08/15/17, 12:47 PM   #5
p6kocka
Join Date: Apr 2014
Posts: 19
OK. Ive 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?
  Reply With Quote
08/15/17, 02:59 PM   #6
Baertram
 
Baertram's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 1,362
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.
  Reply With Quote
08/16/17, 01:54 AM   #7
p6kocka
Join Date: Apr 2014
Posts: 19
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?
  Reply With Quote
08/17/17, 04:42 PM   #8
Baertram
 
Baertram's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 1,362
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()
  Reply With Quote

ESOUI » AddOns » AddOn Help/Support » How to add a keybind for existing addon?

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off