• Print

Author Topic: [XGUI] Opening Client Settings tab via command  (Read 5614 times)

0 Members and 1 Guest are viewing this topic.

Offline roastchicken

  • Respected Community Member
  • Sr. Member
  • *****
  • Posts: 476
  • Karma: 84
  • I write code
[XGUI] Opening Client Settings tab via command
« on: June 30, 2015, 03:46:26 am »
I am trying to create a command that when run will open a certain submodule in the client settings. My latest attempt was to just copy+paste the code of the function that is called when a row is selected, but I get the same error as with previous tries:
Code: [Select]
[ERROR] addons/ulx/lua/ulx/modules/cl/xlib.lua:1113: attempt to index field 'panel' (a nil value)
I assume this is because I am setting nPanel to the wrong thing. I have tried the name of a submodule ("General Settings") and the acutal panel (genpnl) but neither seem to work.

Here is the function I copy+pasted, it is in addons/ulx/lua/ulx/xgui/settings/client.lua:
Code: [Select]
function changeClientSettingsTab( nPanel )
if nPanel ~= client.curPanel then
nPanel:SetZPos( 0 )
xlib.addToAnimQueue( "pnlSlide", { panel=nPanel, startx=-435, starty=0, endx=0, endy=0, setvisible=true } )
if client.curPanel then
client.curPanel:SetZPos( -1 )
xlib.addToAnimQueue( client.curPanel.SetVisible, client.curPanel, false )
end
xlib.animQueue_start()
client.curPanel = nPanel
else
xlib.addToAnimQueue( "pnlSlide", { panel=nPanel, startx=0, starty=0, endx=-435, endy=0, setvisible=false } )
self:ClearSelection()
client.curPanel = nil
xlib.animQueue_start()
end
if nPanel.onOpen then nPanel.onOpen() end --If the panel has it, call a function when it's opened
end

And here is the code where I call that function, located in addons/ulx/lua/ulx/modules/cl/xgui_client.lua:
Code: [Select]
ULib.cmds.addCommandClient( "ulx opentab", function( ply, cmd, args )
                                            xgui.show( "client" )
                                            changeClientSettingsTab( genpnl )
                                          end )

Any help is appreciated!
Give a man some code and you help him for a day; teach a man to code and you help him for a lifetime.

Offline Stickly Man!

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 1270
  • Karma: 164
  • What even IS software anymore?
    • XGUI
Re: [XGUI] Opening Client Settings tab via command
« Reply #1 on: June 30, 2015, 12:22:42 pm »
Whoo, this is some old code you're digging through. It's fun to see what you've done with it, though! ;)

This might be something I'd be interested in including with XGUI by default- it's a useful feature for those who need it. However, it might take me a while to get around to implementing it lol.

For now, it appears that xlib is choking on some animation-type stuff. Could you paste the full stack trace of the error, and which line the error is occuring on in xlib.lua and settings/client.lua? Try commenting out the three animation-related lines below, and see if it works for you:

Code: Lua
  1. function changeClientSettingsTab( nPanel )
  2.         if nPanel ~= client.curPanel then
  3.                 nPanel:SetZPos( 0 )
  4.                 --xlib.addToAnimQueue( "pnlSlide", { panel=nPanel, startx=-435, starty=0, endx=0, endy=0, setvisible=true } )
  5.                 if client.curPanel then
  6.                         client.curPanel:SetZPos( -1 )
  7.                         --xlib.addToAnimQueue( client.curPanel.SetVisible, client.curPanel, false )
  8.                 end
  9.                 --xlib.animQueue_start()
  10.                 client.curPanel = nPanel
  11.         end
  12.         if nPanel.onOpen then nPanel.onOpen() end --If the panel has it, call a function when it's opened
  13. end

You'll notice I removed the "else" part of the big if statement- that code is for closing an already open tab, so you can leave it out entirely. (If it's already the open tab, you won't have to do anything).

You may not want animations, since you're likely wanting XGUI to open immediately to the given module. If that's the case, you can remove the lines I commented out (and *maybe* the SetZPos lines), and then you might need to manually hide client.curPanel and show nPanel. ... Additionally, you may have to set the position of nPanel to 0,0 as well.

Hope that helps you out- It's quite hard to code from the top of my head without being able to test. :P
Join our Team Ulysses community discord! https://discord.gg/gR4Uye6

Offline roastchicken

  • Respected Community Member
  • Sr. Member
  • *****
  • Posts: 476
  • Karma: 84
  • I write code
Re: [XGUI] Opening Client Settings tab via command
« Reply #2 on: June 30, 2015, 02:37:01 pm »
Here is the full error, including another error about the "else" part:
Code: Lua
  1. [ERROR] addons/ulx/lua/ulx/xgui/settings/client.lua:68: attempt to index global 'self' (a nil value)
  2.   1. changeClientSettingsTab - addons/ulx/lua/ulx/xgui/settings/client.lua:68
  3.    2. __fn - addons/ulx/lua/ulx/modules/cl/xgui_client.lua:536
  4.     3. unknown - addons/ulib/lua/ulib/shared/commands.lua:1296
  5.      4. unknown - lua/includes/modules/concommand.lua:54
  6.  
  7.  
  8. [ERROR] addons/ulx/lua/ulx/modules/cl/xlib.lua:1113: attempt to index field 'panel' (a nil value)
  9.   1. startFunc - addons/ulx/lua/ulx/modules/cl/xlib.lua:1113
  10.    2. Start - addons/ulx/lua/ulx/modules/cl/xlib.lua:1001
  11.     3. func - addons/ulx/lua/ulx/modules/cl/xlib.lua:1097
  12.      4. animQueue_call - addons/ulx/lua/ulx/modules/cl/xlib.lua:1073
  13.       5. animQueue_start - addons/ulx/lua/ulx/modules/cl/xlib.lua:1060
  14.        6. animQueue_call - addons/ulx/lua/ulx/modules/cl/xlib.lua:1080
  15.         7. Stop - addons/ulx/lua/ulx/modules/cl/xlib.lua:1020
  16.          8. Run - addons/ulx/lua/ulx/modules/cl/xlib.lua:1027
  17.           9. fn - addons/ulx/lua/ulx/modules/cl/xlib.lua:1037
  18.            10. Call - addons/ulib/lua/ulib/shared/hook.lua:179
  19.             11. unknown - addons/ulx/lua/ulx/modules/cl/xgui_helpers.lua:31
  20.  

The first error isn't that useful because as you said it deals with closing an open tab, which I won't need to do. I'll test the code you posted now, and will report back shortly.

EDIT:

Here is the error I get from the code you posted above. Tomorrow I will try the other edits you proposed and see if that works.
Code: Lua
  1. [ERROR] addons/ulx/lua/ulx/xgui/settings/client.lua:67: attempt to index local '
  2. nPanel' (a nil value)
  3.   1. changeClientSettingsTab - addons/ulx/lua/ulx/xgui/settings/client.lua:67
  4.    2. __fn - addons/ulx/lua/ulx/modules/cl/xgui_client.lua:536
  5.     3. unknown - addons/ulib/lua/ulib/shared/commands.lua:1296
  6.      4. unknown - lua/includes/modules/concommand.lua:54
« Last Edit: June 30, 2015, 03:04:46 pm by roastchicken »
Give a man some code and you help him for a day; teach a man to code and you help him for a lifetime.

Offline Stickly Man!

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 1270
  • Karma: 164
  • What even IS software anymore?
    • XGUI
Re: [XGUI] Opening Client Settings tab via command
« Reply #3 on: July 01, 2015, 07:49:36 am »
Hmm interesting.. Could you also post the code of how you're calling this? You might not have the correct value for nPanel (or at least, it appears to be nil).

One way you can make sure you're getting the correct panel would be to iterate through xgui's submodules and find the one that matches the module name you're looking for. Here's some mockup code (might need a few things fixed):
Code: Lua
  1. for i = 1, #xgui.modules.submodule do
  2.   local module = xgui.modules.submodule[i]
  3.   if module.mtype == "client" and module.name == "General Settings" then
  4.     changeClientSettingsTab( module.panel )
  5.     break
  6.   end
  7. end
Join our Team Ulysses community discord! https://discord.gg/gR4Uye6

Offline roastchicken

  • Respected Community Member
  • Sr. Member
  • *****
  • Posts: 476
  • Karma: 84
  • I write code
Re: [XGUI] Opening Client Settings tab via command
« Reply #4 on: July 01, 2015, 10:25:50 am »
Here is the code I used:
Code: Lua
  1. ULib.cmds.addCommandClient( "ulx utime", function( ply, cmd, args )
  2.                                             xgui.show( "client" )
  3.                                             changeClientSettingsTab( genpnl )
  4.                                           end )
  5.  

I also tried
Code: [Select]
changeClientSettingsTab( genpnl.panel ) and
Code: [Select]
changeClientSettingsTab( "General Settings" )both to no avail.

I'll try your suggestion, I just changed your for loop:

Code: Lua
  1. for k, v in pairs(xgui.modules.submodule) do
  2.   if v.mtype == "client" and v.name == "General Settings" then
  3.     changeClientSettingsTab( v.panel )
  4.     break
  5.   end
  6. end
  7.  
« Last Edit: July 01, 2015, 11:41:55 am by roastchicken »
Give a man some code and you help him for a day; teach a man to code and you help him for a lifetime.

Offline roastchicken

  • Respected Community Member
  • Sr. Member
  • *****
  • Posts: 476
  • Karma: 84
  • I write code
Re: [XGUI] Opening Client Settings tab via command
« Reply #5 on: July 01, 2015, 01:23:53 pm »
Sadly that didn't seem to work. No errors, but it just opens the client settings and doesn't open any tab.
Give a man some code and you help him for a day; teach a man to code and you help him for a lifetime.

Offline Stickly Man!

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 1270
  • Karma: 164
  • What even IS software anymore?
    • XGUI
Re: [XGUI] Opening Client Settings tab via command
« Reply #6 on: July 06, 2015, 10:17:12 am »
Hmm, I'll have to play around with this on my own time and see what I can come up with. Finding free time is the hard part though :P
Join our Team Ulysses community discord! https://discord.gg/gR4Uye6

Offline Stickly Man!

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 1270
  • Karma: 164
  • What even IS software anymore?
    • XGUI
Re: [XGUI] Opening Client Settings tab via command
« Reply #7 on: July 31, 2015, 06:09:45 pm »
I just pushed a commit that added a couple helper functions to do the features you asked for:
https://github.com/Nayruden/Ulysses/commit/5a146705c58e875750152281ce7ea62c4c057eee

You should now just be able to call "xgui.openClientModule("General Settings")" after opening up the client tab, and it should work fine! :)
Join our Team Ulysses community discord! https://discord.gg/gR4Uye6

Offline roastchicken

  • Respected Community Member
  • Sr. Member
  • *****
  • Posts: 476
  • Karma: 84
  • I write code
Re: [XGUI] Opening Client Settings tab via command
« Reply #8 on: August 01, 2015, 03:25:44 pm »
Thank you so much! This works like a charm and is a much better solution than telling people how to manually open a settings module.
Give a man some code and you help him for a day; teach a man to code and you help him for a lifetime.

  • Print