Thread Tools Display Modes
12-14-16, 10:26 AM   #1
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
Module options not displaying..

I am following along this thread to create modules for my latest build of SmartRes2. Obviously, I am missing something, because the options for SmartRes2_Chat are not showing up in SmartRes2, either by Interace/AddOns, or the LDB/minimap buttons.

I don't have SmartRes2_Chat set as LoadOnDemand, but I'd like to; I'm trying to debug first. There are no errors in either SmartRes2 or SR2C. BugSack is quiet.

About posting my code. While both the core and the module are tiny, I think it best to post both, because I can't tell which is not working. Therefore, I am attaching .zip files. Sorry about the SVN hooks and files, please ignore those. And I certainly do not expect anyone to make commits.

What I do see when opening Interface/AddOn is exactly what you'd expect with no modules. The main options tab and the profiles tab.

And yes, I know that SmartRes2_Chat currently does nothing, but at the very least its options should be displayed at this point.
Attached Files
File Type: zip SmartRes2.zip (29.7 KB, 128 views)
File Type: zip SmartRes2_Chat.zip (37.0 KB, 118 views)
  Reply With Quote
12-14-16, 01:25 PM   #2
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
I don't have much time at the moment, but look at sStats and its modules.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
12-15-16, 09:50 AM   #3
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
Seerah, thank you for the the tip. Because you handle modules differently, it didn't help me. I am using AceAddon-3.0 to handle modules.

As far as I can tell, because there are no errors unless I purposely break something, the module is being loaded.

The disconnect is getting the module options into the core display. I have tried putting in a saved variables line into SmartRes2_Chat's toc, and tried without. I have tried both an SV and matching it as the name in RegisterNamespace, and treating the name as a simple string. In the section 24 - 30, I have tried multiple variations of options.args.blah.

I have tried so many variants of line 28 it makes my head swim. Originally I had line 28 exactly as Phanx wrote in the linked thread above, only substituting name, module for k, v, but those are just variable names.

Except for the third argument for AceDialog, AddToBlizOptions has been passed SmartRes2, name, module, and a few combinations thereof. What you see is the latest iteration.

I am at a total loss as to why something so simple isn't working. And this is why I attached the whole addon zips.
Lua Code:
  1. function SmartRes2:OnInitialize()
  2.     -- register saved variables with AceDB
  3.     self.db = LibStub("AceDB-3.0"):New("SmartRes2DB", defaults, true)
  4.     db = self.db.profile
  5.  
  6.     -- db update callbacks
  7.     self.db.RegisterCallback(self, "OnProfileChanged", "Refresh")
  8.     self.db.RegisterCallback(self, "OnProfileCopied", "Refresh")
  9.     self.db.RegisterCallback(self, "OnProfileReset", "Refresh")
  10.  
  11.     local options = self:GetOptions()
  12.     Registry:RegisterOptionsTable("SmartRes2", options)
  13.  
  14.     options.args.profile = LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db)
  15.     options.args.profile.order = -1
  16.  
  17.     -- dual spec the options
  18.     LDS:EnhanceDatabase(self.db, "SmartRes2")
  19.     LDS:EnhanceOptions(options.args.profile, self.db)  
  20.  
  21.     Dialog:AddToBlizOptions("SmartRes2", "SmartRes2", nil, "general")
  22.  
  23.     -- now embed module options into SmartRes2's options
  24.     for name, module in self:IterateModules() do
  25.         if type(module.GetOptions) == "function" then
  26.             options.args[name] = module:GetOptions()
  27.             local displayName = options.args[name].name
  28.             Dialog:AddToBlizOptions("SmartRes2", displayName, "SmartRes2", options.args[name])
  29.         end
  30.     end
  31. end

... And the module's OnInit
Lua Code:
  1. function Chat:OnInitialize()
  2.     -- get our defaults table
  3.     local defaults = self:GetDefaults()
  4.  
  5.     self.db = SmartRes2.db:RegisterNamespace("Chat", defaults)
  6.     self:SetEnabledState(SmartRes2:GetModuleEnabled("Chat"))
  7. end
  Reply With Quote
12-15-16, 01:59 PM   #4
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Did you look at the GetModuleOptions function on line 353 of sStats.lua?

It's called in this bit in the OnInitialize function (lines 498-500)
Lua Code:
  1. for k,v in pairs(modules) do
  2.         GetModuleOptions(v:GetName())
  3.     end
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh


Last edited by Seerah : 12-15-16 at 02:01 PM.
  Reply With Quote
12-17-16, 10:14 PM   #5
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
I looked at your code, slept on it, mulled it over, looked at it again. While I did learn some things, I found myself confused because your code knows the module options, like X, Y, input text. Your options are static.

However, my options for the modules are dynamic, so I don't think I can borrow your code. If I am wrong, please elaborate!

In the meantime, I tried some things. For instance, I moved the defaults and options fetch functions for the module out of their own .lua files and into the core module code. Also, I adjusted the get/set functions to db[info[#info]] format.

That done, I made sure everything else exactly matched the code Phanx wrote for BasicUI, as cokedrivers said his Buffs module and core addon were working.

So far so good, except I still don't see my module's options displaying with SmartRes2 set as the parent.

Right, that means I added some print statements. In SmartRes2:OnInit()'s module iterator, it looks like this:
Lua Code:
  1. -- now embed module options into SmartRes2's options
  2. for name, module in self:IterateModules() do
  3.     self:Printf("module name is %s", name)
  4.     self:Printf("Module options type is %s", tostring(type(module.GetOptions)))
  5.     if type(module.GetOptions) == "function" then
  6.         options.args[name] = module:GetOptions()
  7.         local displayName = options.args[name].name
  8.         Dialog:AddToBlizOptions("SmartRes2", displayName, "SmartRes2", name)
  9.     end
  10. end
And lo and behold, neither of the self:Printf calls print anything. It's like the iterator isn't firing, or it isn't getting any data from the module.

That gives me something to work with, but I have no clue why it isn't picking up the module...
  Reply With Quote
12-18-16, 02:04 PM   #6
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
The insertion of module options is the same, no matter where it comes from. In sStats, the core provides the module options by inserting the data table into the main options table. Any module that wants to provide additional options that the core does not know about, would then insert into the appropriate table.

If the core does not handle the module options table, then the module itself would insert its options data table into the main options table.

Isolated out of my GetModuleOptions function.
Lua Code:
  1. local options = sStatsOptionsTable
  2. [...]
  3. options.args[module] = {
  4.     name = module,
  5.     type = "group",
  6.     args = {
  7.         [...]
  8.     }
  9. sStats.optionsFrame[module] = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("sStats", module, "sStats", module)


/edit: and what is your self:IterateModules() method doing? What does it return?
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh


Last edited by Seerah : 12-18-16 at 02:08 PM.
  Reply With Quote
12-20-16, 12:48 AM   #7
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
I'm still working on trying to get it to work, but now there will be a delay until after the holidays. Just wanted to say something so you weren't hanging, wonder if I have fixed it - I haven't yet.
  Reply With Quote
12-20-16, 11:48 AM   #8
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
Good news everyone! I got the slime flowing again!! Er, I mean I figured out how to get the chat module to display in the main options window after looking at KUI Nameplates code.

However, it is not obeying the default values. All the defaults for the Chat module that are Boolean are set to true, but the display has them as false, or empty checkboxes.

What I don't know for sure is whether that's because I have handler = module, or because the options table for the module get/set are wrong with self.db.profile.blah where "self" is module.db, or both are wrong.

I have not handled the SV random table code yet within Chat.lua, because it probably will be easier to find out how to do that once I figure out how/why the Booleans aren't working. Baby steps.

For reference, here is first the code for SmartRes2.lua, and then Chat.lua (the module code). Seerah, as muddled as my brain is, I want to thank you very much for your help to this point. Without your prompting, I would never have gotten this far.
Lua Code:
  1. function SmartRes2:OnInitialize()
  2.     -- register saved variables with AceDB
  3.     self.db = LibStub("AceDB-3.0"):New("SmartRes2DB", defaults, true)
  4.     db = self.db.profile
  5.  
  6.     -- db update callbacks
  7.     self.db.RegisterCallback(self, "OnProfileChanged", "Refresh")
  8.     self.db.RegisterCallback(self, "OnProfileCopied", "Refresh")
  9.     self.db.RegisterCallback(self, "OnProfileReset", "Refresh")
  10.  
  11.     local options = self:GetOptions()
  12.    
  13.     -- now embed module options into SmartRes2's options
  14.     function SmartRes2:InitializeModuleOptions(module)
  15.         if not module.GetOptions then
  16.             return
  17.         end
  18.         table_insert(modules, module) -- modules is file-scope
  19.         local opts = module:GetOptions()
  20.         local name = module.uiName or module:GetName()
  21.  
  22.         options.args[name] = {
  23.             name = name,
  24.             handler = module,
  25.             type = "group",
  26.             childGroups = "tab",
  27.             order = 10 + #self.modules,
  28.             args = opts
  29.         }
  30.     end
  31.  
  32.     -- add profiles to options table
  33.     options.args.profile = LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db)
  34.     options.args.profile.order = -1
  35.  
  36.     -- dual spec the options
  37.     LDS:EnhanceDatabase(self.db, "SmartRes2")
  38.     LDS:EnhanceOptions(options.args.profile, self.db)
  39.  
  40.     Registry:RegisterOptionsTable("SmartRes2", options)
  41.     Dialog:AddToBlizOptions("SmartRes2")
  42. end

Lua Code:
  1. -- upvalue the globals --------------------------------------------------------
  2. local _G = getfenv(0)
  3. local LibStub = _G.LibStub
  4. local math_random = _G.math.random
  5.  
  6. -- declare our module ---------------------------------------------------------
  7. local SmartRes2 = LibStub("AceAddon-3.0"):GetAddon("SmartRes2")
  8. local Chat = SmartRes2:NewModule("Chat", "AceConsole-3.0", "AceEvent-3.0")
  9. local L = LibStub("AceLocale-3.0"):GetLocale("SmartRes2")
  10. Chat.uiName = CHAT_OPTIONS_LABEL
  11.  
  12. -- update localization table --------------------------------------------------
  13. SmartRes2.L = L
  14.  
  15. -- get LibResInfo-1.0 ---------------------------------------------------------
  16. local LRI = LibStub("LibResInfo-1.0")
  17.  
  18. -- defaults table -------------------------------------------------------------
  19. function Chat:GetDefaults()
  20.     local defaults = {
  21.         profile = {
  22.             chatType = "GROUP",
  23.             enableModule = true,
  24.             massResMessage = {
  25.                 "I am casting %s",
  26.                 "Mass resurrection for you! And you! And you! For everybody!",
  27.                 "All your mass resurrections are belong to me!",
  28.                 "I am in your graves, casting %s",
  29.                 "Free mass resurrections for all of you!",
  30.                 "You are all getting mass resurrected. However, I do not guarantee all your parts are intact."
  31.             },
  32.             notifyCollision = "WHISPER",
  33.             notifyExpired = true,
  34.             notifyResCancelled = true,
  35.             notifyResEnded = true,
  36.             notifySelf = true,
  37.             randChatTbl = {
  38.                 "%p is bringing %t back to life!",
  39.                 "Filthy peon! %p has to resurrect %t!",
  40.                 "%p has to wake %t from eternal slumber.",
  41.                 "%p is ending %t's dirt nap.",
  42.                 "No fallen heroes! %p needs %t to march forward to victory!",
  43.                 "%p doesn't think %t is immortal, but after this res cast, it is close enough.",
  44.                 "Sleeping on the job? %p is disappointed in %t.",
  45.                 "%p knew %t couldn't stay out of the fire. *Sigh*",
  46.                 "Once again, %p pulls %t and their bacon out of the fire.",
  47.                 "%p thinks %t should work on their Dodge skill.",
  48.                 "%p refuses to accept blame for %t's death, but kindly undoes the damage.",
  49.                 "%p grabs a stick. A-ha! %t was only temporarily dead.",
  50.                 "%p is ressing %t",
  51.                 "%p knows %t is faking. It was only a flesh wound!",
  52.                 "Oh. My. God. %p has to breathe life back into %t AGAIN?!?",
  53.                 "%p knows that %t dying was just an excuse to see another silly random res message.",
  54.                 "Think that was bad? %p proudly shows %t the scar tissue caused by Hogger.",
  55.                 "Just to be silly, %p tickles %t until they get back up.",
  56.                 "FOR THE HORDE! FOR THE ALLIANCE! %p thinks %t should be more concerned about yelling FOR THE LICH KING! and prevents that from happening.",
  57.                 "And you thought the Scourge looked bad. In about 10 seconds, %p knows %t will want a comb, some soap, and a mirror.",
  58.                 "Somewhere, the Lich King is laughing at %p, because he knows %t will just die again eventually. More meat for the grinder!!",
  59.                 "%p doesn't want the Lich King to get another soldier, so is bringing %t back to life.",
  60.                 "%p wonders about these stupid res messages. %t should just be happy to be alive.",
  61.                 "%p prays over the corpse of %t, and a miracle happens!",
  62.                 "In a world of resurrection spells, why are NPC deaths permanent? It doesn't matter, since %p is making sure %t's death isn't permanent.",
  63.                 "%p performs a series of lewd acts on %t's still warm corpse. Ew."
  64.             },
  65.             restoreMassResMsgs = {},
  66.             restoreRndChatTbl = {}
  67.         }
  68.     }
  69.     return defaults
  70. end
  71.  
  72. -- options table --------------------------------------------------------------
  73. function Chat:GetOptions()
  74.     local options = {
  75.         enabled = {
  76.             name = ENABLE,
  77.             desc = L["Toggle module on/off."],
  78.             type = "toggle",
  79.             order = 10,
  80.             get = function() return self.db.profile.enableModule end,
  81.             set = function(info, value)
  82.                 self.db.profile.enableModule = value
  83.                 if value then
  84.                     self:Enable()
  85.                 else
  86.                     self:Disable()
  87.                 end
  88.             end
  89.         },
  90.         selfNotification = {
  91.             name = L["Self Notification"],
  92.             desc = L["This tab controls messages only you can see."],
  93.             type = "group",
  94.             order = 20,
  95.             args = {
  96.                 expired = {
  97.                     name = L["Victim Resurrected Expiration"],
  98.                     desc = L["Lets you know the victim did not accept their resurrection and can be resurrected again."],
  99.                     type = "toggle",
  100.                     order = 10,
  101.                     get = function() return self.db.profile.notifyExpired end,
  102.                     set = function(info, value)
  103.                         self.db.profile.notifyExpired = value
  104.                     end
  105.                 },
  106.                 cancelled = {
  107.                     name = L["Caster Cancelled Resurrection"],
  108.                     desc = L["Another caster (not you) cancelled their resurrection."],
  109.                     type = "toggle",
  110.                     order = 20,
  111.                     get = function() return self.db.profile.notifyResCancelled end,
  112.                     set = function(info, value)
  113.                         self.db.profile.notifyResCancelled = value
  114.                     end
  115.                 },
  116.                 ended = {
  117.                     name = L["Caster Finished Cast"],
  118.                     desc = L["Another caster (not you) completed casting their spell."],
  119.                     type = "toggle",
  120.                     order = 30,
  121.                     get = function() return self.db.profile.notifyResEnded end,
  122.                     set = function(info, value)
  123.                         self.db.profile.notifyResEnded = value
  124.                     end
  125.                 },
  126.                 myCasts = {
  127.                     name = L["My Resurrections"],
  128.                     desc = L["Tells you whom you are resurrecting, or casting a mass resurrection, or raising the Creator from the dead."],
  129.                     type = "toggle",
  130.                     order = 40,
  131.                     get = function() return self.db.profile.notifySelf end,
  132.                     set = function(info, value)
  133.                         self.db.profile.notifySelf = value
  134.                     end
  135.                 }
  136.             }
  137.         }
  138.     }
  139.     return options
  140. end
  141.  
  142. function Chat:OnInitialize()
  143.    self.db = SmartRes2.db:RegisterNamespace(Chat:GetName(), defaults)
  144.    SmartRes2:InitializeModuleOptions(self)
  145.    -- self:SetEnabledState(self.db.profile.enableModule)
  146. end
  147.  
  148. function Chat:OnEnable()
  149. end
  150.  
  151. function Chat:OnDisable()
  152.     -- LRI.UnregisterAllCallbacks(self)
  153. end
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Module options not displaying..


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