ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   Lua/XML Help (https://www.esoui.com/forums/forumdisplay.php?f=175)
-   -   Add Checkbox to Keybinding category (https://www.esoui.com/forums/showthread.php?t=7668)

Phuein 03/13/18 06:58 PM

[SOLVED] Add Checkbox to Keybinding category
 
tl;dr I just want to add an option checkbox somewhere that toggles a variable.

Hey. I'm entirely new to this. I wanted to update and improve the Junkee addon. I like having a keybind for Junk/Destroy items.

I've slowly used the forums and other addons to figure out how to update it, and then to make it save variables and load them. I'm trying to have an option (toggle) to display the keybindings when the Inventory is open; the keybindings are always active, but the descriptions can be toggled on/off.

The actual toggling works fine with a variable. I just can't figure out how to create and display the Checkbox correctly. I tried taking code from VotansKeybinder, but it's over my head. I'm not even sure what/how to adapt.

How do I add a Checkbox to the Keybinding menu, either next to the category title ("Junkee") or next to a Keybinding option ("Show bindings in Inventory" keybind)?

Baertram 03/14/18 01:31 AM

If you want to use settings for your addon you shouldn't put them into the game's keybindings menu, but use libAddonMenu2.0 instead to put the checkbox there. Ppl are used to it and won't enable addon related stuff into the keyninds list.

Check the addons section here for this library and how to use it. Or check Dustman code how you can add LAM.

Phuein 03/14/18 04:42 PM

Thanks for the advice. It's good. I've been trying to do that, but I keep getting:
Code:

EsoUI/Libraries/Utility/ZO_Hook.lua:33: function expected instead of nil
stack traceback:
        EsoUI/Libraries/Utility/ZO_Hook.lua:33: in function '(anonymous)'

Is it outdated? Am I missing some Lua fundamental? I come from Python or JS. I can't tell what exactly is nil. I've avoided any undefined variables or functions, the order of definitions. And everything works fine when I comment out:
Code:

                LAM:RegisterAddonPanel("Junkee", panelData)
                LAM:RegisterOptionControls("Junkee", optionsTable)


Dolgubon 03/14/18 07:13 PM

Go into the lam files, and open the controls folder. Open panel.Lua and the files of the other controls you are using. There should be a comment at the start, make sure you have all the required fields. Also make sure the table is in the correct format

Phuein 03/15/18 03:13 PM

Quote:

Originally Posted by Dolgubon (Post 34137)
Go into the lam files, and open the controls folder. Open panel.Lua and the files of the other controls you are using. There should be a comment at the start, make sure you have all the required fields. Also make sure the table is in the correct format

I edited the example code that comes with it. It all seems correct. I tried simplifying it to make sure it's none of my code making trouble, too. Could it be an issue with the order of the code? Couldn't figure it out. I copied the LibStub.lua file to my main directory and use it in my addon, not sure if that's good practice either:
Code:

local wm = GetWindowManager()
local em = EVENT_MANAGER

local LAM = LibStub("LibAddonMenu-2.0")

Here's my code chunk:

Code:

local panelData = {
    type = "panel",
    name = "Junkee",
    displayName = "Junkee Settings",
    registerForRefresh = true,
    registerForDefaults = true,
}

local optionsTable = {
    [1] = {
        type = "checkbox",
        name = "Display Keybindings",
        tooltip = "Display the addon's keybindings when opening the Inventory. " ..
                "They appear on the bottom left.",
        getFunc = function() return Junkee.visible end,
        setFunc = function(v) Junkee.visible = v end,
        width = "full",        --or "half"
    },
}

Junkee.Loaded = function(eventCode, addonName)
        if (Junkee.name == addonName) then
                registerHooks()

                -- Load saved variables.
                Junkee.savedVars = ZO_SavedVars:New("JunkeeAddonSavedVariables", 1, nil,
                        {
                                visible = Junkee.visible,
                                firstRun = true -- OnActivated()
                        })

                LAM:RegisterAddonPanel("Junkee", panelData)
                LAM:RegisterOptionControls("Junkee", optionsTable)
        end
end

I don't see any issues. Must be missing something.

votan 03/15/18 03:25 PM

Did you include LibSub and all LAM files in your manifest.txt before your files?

Phuein 03/15/18 05:54 PM

Quote:

Originally Posted by votan (Post 34141)
Did you include LibSub and all LAM files in your manifest.txt before your files?

Yes, as instructed by the addon:

Code:

...
## OptionalDependsOn: LibAddonMenu-2.0

bindings.xml
keystrip.lua
localizations.lua
LibStub.lua
Junkee.lua


Dolgubon 03/16/18 12:17 AM

You haven't included any LAM files in your manifest!!! The manifest tells the game what files to load. So the game will load the files that are listed. If you don't list a file, it won't load. As instructed by the addon, you would have my tile lines of libs/libaddonmenu/controls/controlname.lua as well as lines for libstub. All rhe optional depends on does is say 'if the user has LAM as a standalone addon, load the standalone LAM first.'

Letho 03/16/18 01:10 AM

Uhm afaik LAM does not have 'true' checkboxes, yet, only those 'On......Off' controls? It's a feature that I suggested some time ago.

Phuein 03/16/18 09:37 AM

Quote:

Originally Posted by Letho (Post 34144)
Uhm afaik LAM does not have 'true' checkboxes, yet, only those 'On......Off' controls? It's a feature that I suggested some time ago.

True, but that works fine for my needs. :)

Phuein 03/16/18 09:55 AM

Quote:

Originally Posted by Dolgubon (Post 34143)
You haven't included any LAM files in your manifest!!! The manifest tells the game what files to load. So the game will load the files that are listed. If you don't list a file, it won't load. As instructed by the addon, you would have my tile lines of libs/libaddonmenu/controls/controlname.lua as well as lines for libstub. All rhe optional depends on does is say 'if the user has LAM as a standalone addon, load the standalone LAM first.'

I use Stub to load LAM, and LAM has its own files in its own manifest. This line:
Code:

local LAM = LibStub("LibAddonMenu-2.0")
It loads just fine. I see the menu option and my checkbox loaded just fine. It's only when I interact with my Inventory that it gives the error. I did, however, try your suggestion and it works the same with the same error in my op. :confused:

Phuein 03/16/18 10:24 AM

I redid it with the instructions more carefully, fixing my .txt file and how I add the LAM module. I followed the ZAM Stats module on how they load and use it, every part. Still same error. The menu is loaded, but when I interact with Inventory it errors.

Code:

## OptionalDependsOn: LibAddonMenu-2.0

bindings.xml
keystrip.lua
localizations.lua

LibStub\LibStub.lua

LibAddonMenu-2.0\LibAddonMenu-2.0.lua
LibAddonMenu-2.0\controls\panel.lua
LibAddonMenu-2.0\controls\submenu.lua
LibAddonMenu-2.0\controls\button.lua
LibAddonMenu-2.0\controls\checkbox.lua
LibAddonMenu-2.0\controls\colorpicker.lua
LibAddonMenu-2.0\controls\custom.lua
LibAddonMenu-2.0\controls\description.lua
LibAddonMenu-2.0\controls\dropdown.lua
LibAddonMenu-2.0\controls\editbox.lua
LibAddonMenu-2.0\controls\header.lua
LibAddonMenu-2.0\controls\slider.lua
LibAddonMenu-2.0\controls\texture.lua
LibAddonMenu-2.0\controls\iconpicker.lua
LibAddonMenu-2.0\controls\divider.lua

Junkee.lua

Code:

-- Add menu with options.
local panelData = {
    type = "panel",
    name = "Junkee",
    author = "Seerah",
    version = "1.1.3",
    displayName = "Junkee Settings",
    registerForRefresh = true,
    registerForDefaults = true,
}

local optionsTable = {
    [1] = {
        type = "checkbox",
        name = "Display Keybindings",
        tooltip = "Display the addon's keybindings when opening the Inventory. " ..
                "They appear on the bottom left.",
        getFunc = function() return Junkee.visible end,
        setFunc = function(v) Junkee.visible = v end,
        width = "full",        --or "half",
        default = true
    },
}

local function LoadMenu()
        LAM:RegisterAddonPanel("Junkee", panelData)
        LAM:RegisterOptionControls("Junkee", optionsTable)
end

Junkee.Loaded = function(eventCode, addonName)
        if (Junkee.name == addonName) then
                registerHooks()

                -- Load saved variables.
                Junkee.savedVars = ZO_SavedVars:New("JunkeeAddonSavedVariables", 1, nil,
                        {
                                visible = Junkee.visible,
                                firstRun = true -- OnActivated()
                        })

                LoadMenu()
        end
end
em:RegisterForEvent(Junkee.name, EVENT_ADD_ON_LOADED, Junkee.Loaded)


Phuein 03/16/18 11:05 AM

So, finally after debugging LAM, adding a printout of the actual error, it comes down to Junkee.savedVars being nil. Which makes no sense. My code sets/loads it as instructed in tutorials. In Loaded event:

Code:

Junkee.savedVars = ZO_SavedVars:New("JunkeeAddonSavedVars", 1, nil, Junkee.defaults)
Same name in .txt file. No error on that line, either.

Phuein 03/16/18 11:21 AM

Son of a gun, I found it.

Code:

local panelData = {
    type = "panel",
    name = "Junkee",

Code:

-- addonID = "string"; unique ID which will be the global name of your panel
The name had to be unique! Can't be "Junkee" too. >< So obvious! Foolish of me. I wish LAM reported this as an error, though. I changed it into "JunkeePanel" and now everything works. Thanks for being patient with me.


All times are GMT -6. The time now is 07:13 PM.

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