Thread Tools Display Modes
02/10/22, 10:12 PM   #1
TheScrew
Join Date: Feb 2022
Posts: 2
Detect changing tabs

TL;DR: I'm trying to keep a keybinding in the keybind strip of the crafting stations, all except alchemy and provisioning, that deconstructs stuff, but it vanishes when I change tabs in the interface. How can I detect the tab change events? I can't seem to find them in the docs.


I managed to get it there and remove by capturing the EVENT_CRAFTING_STATION_INTERACT and EVENT_END_CRAFTING_STATION_INTERACT events and using the KEYBIND_STRIP methods.
Whenever an item gets deconstructed, though, it seems to vanish. I made a bit of a workaround my removing it on EVENT_CRAFT_STARTED and re-adding on EVENT_CRAFT_COMPLETED. Is there some better way to keep it there permanently, both with crafting events and tab changes?
  Reply With Quote
02/11/22, 06:02 AM   #2
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,964
Nope, you do not need to do it via events!

As explanation (but not to be used for the keybind strip, but for other detection methods for UI changes):
The controls at the UI got some functins which you can add a SecurePosthook to e.g., like the default crafting tables use the keyboard table
SMITHING and there is a SetMode function which is used as the MainMenuBar buttons are clicked and change the tabs.
So one can add a hook there as the function is used, check the current mode that is passed in and if ift's the constant for the refine mode you know it's the refine tab, and so on.

Code of ZOs is here: https://github.com/esoui/esoui/blob/...board.lua#L225

These are the tabs that get created via the CreateModeData function above it, and the callback in that CreateModeData function shows you it will call self:SetMode which is SMITHING:SetMode (as SMITHING is the object created of the class ZO_Smithing here -> ObjectOriented coding).
The 2nd parameter e.g. SMITHING_MODE_REFINEMENT is the passed in mode constant (a number) which defines the mode that is set as the tab is activated. We can use this mode constant to check for the activae tab later on.
e.g. via function ZO_Smithing_GetActiveObject():GetMode() or at enchanting via ENCHANTING:GetEnchantingMode()

Keybinds:
Keybind strip added keybinds use a keybindDescripter table where you define the keybidn type (primary, secondary, ...) and the name, callback function, and they also got an attribute "visible" in their tabledata where you need to specify a boolean value OR a function that returs a boolean value. If this returns true the keybind will be shown at the strip where you have added they keybindDescripter table to.

They keybindstrip at the crafting tables should be using the same for all of the modes (refine, create, decon, improve, research, recipes) so you need to add it there once, define the visible as function and in that funciton check if it shoud be shown or not.
The keybindStrip contesn at the crafing tables are normally defined via the subtable ".keybindStripDescriptor", e.g. SMITHING.keybindStripDescriptor. So you could insert new entries to that table as your addon loads, with your defined keybindDescriptor table.

If your keybind is removed each time you switch tabs you have most porbably added it the wrong way (not via SMITHING.keybindStripDescriptor) to the strip or you have specified a visible function already that returns false for some of the tabs.


Example:
You need to define the keybindStrip description table for your keybind:
Lua Code:
  1. local keystripDef = {
  2.     name = function() return GetKeyStripName() end,
  3.     keybind = "SC_BANK_ALL",
  4.     callback = function() DoItAll.ExtractAll() end,
  5.     alignment = KEYBIND_STRIP_ALIGN_LEFT,
  6.     visible = function() return ShouldShow() end,
  7. }

Define the local function ShouldShow then and put your code in there which checks if the keybind shows or not:
Lua Code:
  1. local function ShouldShow()
  2.     local retVar = false
  3.     local currentScene = SCENE_MANAGER.currentScene.name
  4.     if currentScene == "enchanting" or not ZO_EnchantingTopLevelExtractionSlotContainer:IsHidden() then
  5.         local enchantMode = ENCHANTING:GetEnchantingMode()
  6.         if enchantMode == ENCHANTING_MODE_EXTRACTION then
  7.             retVar = true
  8.         end
  9.     elseif currentScene == "smithing" then
  10.         local mode = ZO_Smithing_GetActiveObject():GetMode() --ZO_Smithing_GetActiveObject() will point to SMITHING in keyboard mode
  11.         if mode == SMITHING_MODE_REFINMENT then
  12.             retVar = true
  13.         elseif mode == SMITHING_MODE_DECONSTRUCTION then
  14.             retVar = true
  15.         end
  16.     end
  17.     return retVar
  18. end
The SMITHING.mode or ENCHANTING.enchantingMode are the modes that I had tied to explain at the start of my post, and tehy tell you which tab is currently active!

And then insert the keybindDescriptor to the keybindStrip of the crafting table object once:
Lua Code:
  1. table.insert(SMITHING.keybindStripDescriptor, keystripDef)
  2. table.insert(ENCHANTING.keybindStripDescriptor, keystripDef)

And each time you leave the crafting tables use the event for crafting table interact end to remove that keybindDescriptor again from the strip if you hve the need to do this,a nd add it again as you interact with a crafting table e.g.. Or leave them added all the time and just use the visible function callback to hide/show it.

To remove a keybindDescriptor again from the strip:
Lua Code:
  1. KEYBIND_STRIP:RemoveKeybindButtonGroup(keystripDef)

-> This code above should be put to a funciton which you call from your addon's EVENT_ADD_ON_LOADED once.
And it's all about KEYBAORD input mode, not gamepad! If you need gamepad stuff it's quite different as the objects differ, the tables, other scene names, and so on :-(

Compatibility with other addons
Please keep in mind that your addon is not the only one adding keybinds to the crafting UI!
Try to find others (e.g. DoItAll) and add compatibilty if possible.
e.g. add your ekybind as a secondary if the primary was already added by other addons.
You can detect other addons, if you add them to your txt file's ## OptionalDependsOn: DoItAll e.g.,
at your EVENT_ADD_ON_LOADED callback as this will fire AFTER the other addon was loaded due to the dependency then.
You can detect the other addons via their global variables, if they provide any. DoItAll is the global for the addon DoItAll so
checking for
if DoItAll ~= nil then end will show you if the addon is loaded.
Or you can use your EVENT_ADD_ON_LOADED callback functions's parameter 2 "addOnName" to check if another addons is loaded.
If it's in your depndency list it will load BEFORE your addon so you will defnately be able to compare the name there (name = exact same folder/txt filename of the other addon respecting capital characters!).
if addOnNam == "OtherAddonName" then end

Last edited by Baertram : 02/11/22 at 06:59 AM.
  Reply With Quote
02/11/22, 04:57 PM   #3
TheScrew
Join Date: Feb 2022
Posts: 2
Thanks, that was really helpful!

I got it working properly now. I didn't have a "visible" argument in my descriptor and assumed that would have it always set to true. The way I had them being added was through KEYBIND_STRIP:AddKeybindButtonGroup. Changed to inserting directly to the tables you mentioned and now it's working perfectly.
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » Detect changing tabs


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