Thread Tools Display Modes
03/13/18, 06:58 PM   #1
Phuein
 
Phuein's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2018
Posts: 132
[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)?

Last edited by Phuein : 03/16/18 at 11:22 AM.
  Reply With Quote
03/14/18, 01:31 AM   #2
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 4,912
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.
  Reply With Quote
03/14/18, 04:42 PM   #3
Phuein
 
Phuein's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2018
Posts: 132
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)

Last edited by Phuein : 03/14/18 at 04:48 PM.
  Reply With Quote
03/14/18, 07:13 PM   #4
Dolgubon
 
Dolgubon's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2016
Posts: 408
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
  Reply With Quote
03/15/18, 03:13 PM   #5
Phuein
 
Phuein's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2018
Posts: 132
Originally Posted by Dolgubon View Post
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.
  Reply With Quote
03/15/18, 03:25 PM   #6
votan
 
votan's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2014
Posts: 577
Did you include LibSub and all LAM files in your manifest.txt before your files?
  Reply With Quote
03/15/18, 05:54 PM   #7
Phuein
 
Phuein's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2018
Posts: 132
Originally Posted by votan View Post
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
  Reply With Quote
03/16/18, 12:17 AM   #8
Dolgubon
 
Dolgubon's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2016
Posts: 408
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.'
  Reply With Quote
03/16/18, 01:10 AM   #9
Letho
AddOn Author - Click to view addons
Join Date: Apr 2016
Posts: 238
Uhm afaik LAM does not have 'true' checkboxes, yet, only those 'On......Off' controls? It's a feature that I suggested some time ago.
  Reply With Quote
03/16/18, 09:37 AM   #10
Phuein
 
Phuein's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2018
Posts: 132
Originally Posted by Letho View Post
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.
  Reply With Quote
03/16/18, 09:55 AM   #11
Phuein
 
Phuein's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2018
Posts: 132
Originally Posted by Dolgubon View Post
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.
  Reply With Quote
03/16/18, 10:24 AM   #12
Phuein
 
Phuein's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2018
Posts: 132
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)
  Reply With Quote
03/16/18, 11:05 AM   #13
Phuein
 
Phuein's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2018
Posts: 132
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.
  Reply With Quote
03/16/18, 11:21 AM   #14
Phuein
 
Phuein's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2018
Posts: 132
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.
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » Add Checkbox to Keybinding category

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