ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   General Authoring Discussion (https://www.esoui.com/forums/forumdisplay.php?f=174)
-   -   Disable key from standard ESO keystrip? (https://www.esoui.com/forums/showthread.php?t=2126)

Baertram 08/14/14 12:41 PM

Disable key from standard ESO keystrip?
 
Is it possible to disable a key from the standard ESO gui's keystrip, so nothing happens if a user presses the key?

I'd like to react on something and after this disable the following keybindings:
UI_SHORTCUT_PRIMARY -- Primary action/Accept
UI_SHORTCUT_SECONDARY -- Secondary Action
UI_SHORTCUT_TERTIARY -- Tertiary Action

I've searched a while now and all I found is how you are able to change the texture, make them invisible, not mouse clickable (but they still work then, if someone presses the shortcut on his keybord/controller).

With zgoo I found methods like SetKeybind() and SetKeybindEnabled() for controls. But they only seem to set the keybind to the control. I wasn't able to disable them with it.

I also found a function you could use, if you stay out of combat:
UnbindKeyFromAction protected (luaindex layerIndex, luaindex categoryIndex, luaindex actionIndex, luaindex bindingIndex)
But I did not manage to get all needed parameters to unbind something. Maybe it's the wrong function too.
And I would have to rebind the unbound keys afterwards again.

Thanks for any help.

Fyrakin 08/14/14 03:40 PM

Did you try making a toplevel control and enable keyboard on it?

Seerah 08/14/14 04:05 PM

I have not had any luck with this.

sirinsidiator 08/14/14 04:48 PM

Haven't tested this myself, but you could try something like this:

init:
Code:

local keybindButtonDescriptor = KEYBIND_STRIP.keybinds["UI_SHORTCUT_PRIMARY"]
local oldEnabled = keybindButtonDescriptor.enabled

disable:
Code:

keybindButtonDescriptor.enabled = false -- can also be a function that returns a boolean
KEYBIND_STRIP:UpdateKeybindButton(keybindButtonDescriptor)

enable:
Code:

keybindButtonDescriptor.enabled = oldEnabled
KEYBIND_STRIP:UpdateKeybindButton(keybindButtonDescriptor)

if this does not work, you could also replace keybindButtonDescriptor.callback with an empty function

Baertram 08/15/14 08:15 AM

Quote:

Originally Posted by sirinsidiator (Post 11529)
Haven't tested this myself, but you could try something like this:

init:
Code:

local keybindButtonDescriptor = KEYBIND_STRIP.keybinds["UI_SHORTCUT_PRIMARY"]
local oldEnabled = keybindButtonDescriptor.enabled

disable:
Code:

keybindButtonDescriptor.enabled = false -- can also be a function that returns a boolean
KEYBIND_STRIP:UpdateKeybindButton(keybindButtonDescriptor)

enable:
Code:

keybindButtonDescriptor.enabled = oldEnabled
KEYBIND_STRIP:UpdateKeybindButton(keybindButtonDescriptor)

if this does not work, you could also replace keybindButtonDescriptor.callback with an empty function

I've tested it but it will only remove the text next to the keybind button and deactivate the onclick method (which leads to an error if you press the button).
So you'll see the buttons on the keybind strip at the bottom, for example [E] and [R]. But No text next to it anymore.
If you click them or press the key on your keayboard a lua error occurs:

Code:

EsoUI/Libraries/ZO_KeybindStrip/ZO_KeybindStrip.lua:20: attempt to index a boolean value
stack traceback:
        EsoUI/Libraries/ZO_KeybindStrip/ZO_KeybindStrip.lua:20: in function 'OnButtonClicked'
        EsoUI/Libraries/ZO_KeybindStrip/ZO_KeybindStrip.lua:234: in function 'ZO_KeybindStrip:TryHandlingKeybindDown'
        (tail call): ?
        (tail call): ?

But it's a good attempt. Maybe one can remove the controls from the keybind strip bar at the bottom (or make them invisible) and overwrite the onclick handler somehowe to let it do nothing.

I'll try to play around with
ZO_KeybindStrip_HandleKeybindDown
ZO_KeybindStrip_HandleKeybindUp

sirinsidiator 08/15/14 11:57 AM

After some experimenting I got a working example:
Code:

        local button = nil
        TRADING_HOUSE_SCENE:RegisterCallback("StateChange", function()
                d("state change")
                zo_callLater(function()
                        if(button) then return end
                        button = KEYBIND_STRIP.keybinds["UI_SHORTCUT_TERTIARY"]
                        local keybindButtonDescriptor = button.keybindButtonDescriptor
                        local oldEnabled = keybindButtonDescriptor.enabled
                        local oldCallback = keybindButtonDescriptor.callback

                        d("disable")
                        keybindButtonDescriptor.enabled = false
                        keybindButtonDescriptor.callback = function() end
                        KEYBIND_STRIP:UpdateKeybindButton(keybindButtonDescriptor)

                        zo_callLater(function()
                                d("enable")
                                keybindButtonDescriptor.enabled = oldEnabled
                                keybindButtonDescriptor.callback = oldCallback
                                KEYBIND_STRIP:UpdateKeybindButton(keybindButtonDescriptor)
                        end, 5000)
                end, 200)
        end)

It disables the guild switch keybind strip in the guild store for 5 seconds and then enables it again.

Fyrakin 08/15/14 12:02 PM

I'm not sure if that would help you but I would do the following
Code:

ZO_PreHook(KEYBIND_STRIP, "TryHandlingKeybindDown", function(keybind)
-- code which decides where you need to do something about keybind and return truwe which tells that you handled it and original function doesn't have to be called or return false or nil so it acts as normal
 end)


Baertram 02/01/15 11:47 AM

Just an update:

I got my wanted behaviour now by removing the item's context menu entries.
If you remove the context menu entry the ralting keybind will be automatically removed too.

I did this by pre-hooking the contexnt menu actions ZO_InventorySlotActions, function "AddSlotAction":

Lua Code:
  1. --======== RIGHT CLICK / CONTEXT MENU ==========================================
  2.     --Pre Hook the right click/context menu addition of items
  3.     ZO_PreHook(ZO_InventorySlotActions, "AddSlotAction", preAddSlotAction)

The function called:
Lua Code:
  1. --Pre Hook function for adding right click/context menu entries.
  2. --Attention: Will be executed on mouse enter on a slot in inventories
  3. --AND if you open the context menu by a mouse righ-click
  4. --To distinguish these two "events" you can use: if self.m_contextMenuMode == true then
  5. --true: Context-menu is open, false: Only mouse hoevered over the item
  6. local function preAddSlotAction(self, actionStringId, ...)
  7.  
  8. --------------------------------------------------------------------------------
  9. --Get the parent control and bag + slotIndex
  10.     local parentControl
  11.     --Chracter equipment, or normal slot?
  12.     if (not ZO_Character:IsHidden()) then
  13.         parentControl = self.m_inventorySlot
  14.     else
  15.         parentControl = self.m_inventorySlot:GetParent()
  16.     end
  17.     --No parent found? Abort
  18.     if parentControl == nil then return false end
  19.  
  20.     local bag
  21.     local slotIndex
  22.     --gotta do this in case deconstruction, or player equipment
  23.     local dataEntry = parentControl.dataEntry
  24.     --case to handle equiped items
  25.     if(not dataEntry) then
  26.         bagId = parentControl.bagId
  27.         slotIndex = parentControl.slotIndex
  28.     else
  29.         bagId = dataEntry.data.bagId
  30.         slotIndex = dataEntry.data.slotIndex
  31.     end
  32.     --case to handle list dialog, list dialog uses index instead of slotIndex and bag instead of bagId...?
  33.     if(dataEntry and not bagId and not slotIndex) then
  34.         bagId = parentControl.dataEntry.data.bag
  35.         slotIndex = parentControl.dataEntry.data.index
  36.     end
  37.  
  38. --------------------------------------------------------------------------------
  39. --CHECKING THE CONTEXT MENU ENTRIES HERE:
  40. --If you want to hide this context-menu entry you need to return TRUE, otherwise FALSE
  41.  
  42.     --Destroy item?
  43.     if    actionStringId == SI_ITEM_ACTION_DESTROY then
  44.  
  45.         --Only execute if context menu is visible?
  46.         if self.m_contextMenuMode == false then
  47.             return
  48.         end
  49.  
  50.  
  51.  
  52.         --This here will hide the "Destroy" contetx-menu entry and the keybinding in the keybind stip as well!
  53.         return true
  54.  
  55.     --Add item to crafting station, improvement, enchanting table
  56.     elseif actionStringId == SI_ITEM_ACTION_ADD_TO_CRAFT or actionStringId == SI_ITEM_ACTION_RESEARCH then
  57.  
  58.         --This here will hide the "Add to craft" and "Research" context-menu entries and the keybindings as well!
  59.         return true
  60.  
  61.     --Trade an item, mark item as junk, attach item to mail, sell item
  62.     elseif actionStringId == SI_ITEM_ACTION_TRADE_ADD or actionStringId == SI_ITEM_ACTION_MARK_AS_JUNK
  63.        or actionStringId == SI_ITEM_ACTION_MAIL_ATTACH or actionStringId == SI_ITEM_ACTION_SELL
  64.        --sell in guild shop
  65.        or actionStringId == SI_TRADING_HOUSE_ADD_ITEM_TO_LISTING then
  66.         --Is item marked with any of the FCOItemSaver icons? Then don't show the actionStringId in the contextmenu
  67.  
  68.         --This here will hide the "Add to trade", "Add to mail", "Mark as Junk", "Sell" and "Add to sell list" context-menu entries and the keybindings as well!
  69.         return true
  70.  
  71.     --Equip an item
  72.     elseif actionStringId == SI_ITEM_ACTION_EQUIP then
  73.  
  74.         --This here will hide the "Equip" context-menu entries and the keybindings as well!
  75.         return true
  76.  
  77.     --Unequip an item
  78.     elseif actionStringId == SI_ITEM_ACTION_UNEQUIP then
  79.         --Only execute if context menu is visible?
  80.         if self.m_contextMenuMode == false then
  81.             return
  82.         end
  83.  
  84.         --Only for character items
  85.         if( bag ~= nil and slotIndex ~= nil and bag == BAG_WORN) then
  86.             --Update the character window after item was unequipped
  87.             zo_callLater(function() checkMyCharacterWindowNowFunction(bag, slotIndex) end, 200)
  88.         end
  89.         return
  90.  
  91.     --Debugging:   Gives you the action string Id if you hover an item
  92.     else
  93.         d("actionStringId: " .. actionStringId .. " = " .. GetString(actionStringId))
  94.     end
  95. end

If you return true the context-menu entry and the relating keybinding will be hidden.
If you return false the context-menu entry and the relating keybinding will be shown/kept.
If you just return (nil) nothing will be changed. Maybe the same as returning false.

circonian 02/01/15 07:58 PM

Quote:

Originally Posted by Baertram (Post 11512)
I'd like to react on something and after this disable the following keybindings:
UI_SHORTCUT_PRIMARY -- Primary action/Accept
UI_SHORTCUT_SECONDARY -- Secondary Action
UI_SHORTCUT_TERTIARY -- Tertiary Action

You can just change the callback function to do whatever you want by rewriting the keybindStripDescriptor or just remove the button from the keybindStripDescriptor completely.

Just rewrite the keybindStripDescriptor for whatever window you want to change the keybindStrip buttons in.
You don't need to hook anything, mess with context menus, or worry about "when" windows are opened or closed. Each time the window opens the keybindStripDescriptor gets automatically loaded into the keybindStrip control, so its all handled for you automatically.

You can look at: TweakIt
Example: STORE_WINDOW.keybindStripDescriptor (changing the keybindStrip for the store window)
File: TweakIt/RepairIt/TweakIt_Repair.lua
function: TweakIt.InitStoreKeybindStripDescriptors()
function: local function GetRepairEquippedDescriptor()

And you can see how I modified the keybindStripDescriptors for the store window to change the "Repair All" items to "Repair Equipped" items, which includes changing the callback to my own custom dialog box, but you could change it to do whatever you wanted...or remove the button completely.

Let me know if you have any questions.

Baertram 02/02/15 01:53 AM

This was an older thread and I just updated it with the info of my solution, if anybode wants to know about it.

Thanks for your inout as well circonian.
In the meantime I learned about the keybind strips too ;-)

My solution was the better one as the context menu entrys must be removed too (to secure items from beeing deconstructed e.g.)

remosito 04/18/22 02:25 AM

for what it's worth....
 
more necro bounties :-)

might be useful to somebody else:

I wanted to get rid of the "Sell all Junk" button in the store window...

surprisingly just changing visibility was enough. Hitting the associated keybind "x" does nothing anymore....

Code:

        local storekeybindstrip = STORE_WINDOW.keybindStripDescriptor
        for k,v in pairs(storekeybindstrip) do
                if type(v) == "table" and v["keybind"] == "UI_SHORTCUT_NEGATIVE" then
                        STORE_WINDOW.keybindStripDescriptor[k]["visible"] = function() return false end
                end
        end

thanks circonian for pointing me the way of the STORE_WINDOW.keybindStripDescriptor!

Now to hunt down the inventory window keybindstrip to get rid of the "Destroy all junk" keybind

if that one behaves differently I'll come back to update my post..

remosito 05/01/22 09:11 AM

Quote:

Originally Posted by remosito (Post 45710)

Now to hunt down the inventory window keybindstrip to get rid of the "Destroy all junk" keybind

if that one behaves differently I'll come back to update my post..

That was fruitless... :-/

When following down data structures always ended up at some strange UserData values...

google made me think this is where it all goes over into C coded functionality...


But found a workaround, ESO calls a predefined Dialog upon pressing that button from ingame/globals/ingamedialogs.lua

So I just overwrote that one in my code:

Code:

        ESO_Dialogs["DESTROY_ALL_JUNK"] = {
                title =        { text = SI_PROMPT_TITLE_DESTROY_ITEMS, },
                mainText = { text = "Functionality disabled by Addon",},
                buttons = {        [1] = {        text =      SI_DIALOG_DECLINE,        },},
        }

Not as nice, but works....


All times are GMT -6. The time now is 10:41 PM.

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