Guest User

Untitled

a guest
Oct 29th, 2015
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 20.01 KB | None | 0 0
  1. --XGUI: A GUI for ULX -- by Stickly Man!
  2. xgui = {}
  3.  
  4. --Make a spot for modules to store data and hooks
  5. xgui.data = {}
  6. xgui.hook = { onProcessModules={}, onOpen={}, onClose={} }
  7. --Call this function in your client-side module code to ensure the data types have been instantiated on the client.
  8. function xgui.prepareDataType( dtype, location )
  9.     if not xgui.data[dtype] then
  10.         xgui.data[dtype] = location or {}
  11.         xgui.hook[dtype] = { clear={}, process={}, done={}, add={}, update={}, remove={}, data={} }
  12.     end
  13. end
  14.  
  15. --Set up various hooks modules can "hook" into.
  16. function xgui.hookEvent( dtype, event, func )
  17.     if not xgui.hook[dtype] or ( event and not xgui.hook[dtype][event] ) then
  18.         Msg( "XGUI: Attempted to add to invalid type or event to a hook! (" .. dtype .. ", " .. ( event or "nil" ) .. ")\n" )
  19.     else
  20.         if not event then
  21.             table.insert( xgui.hook[dtype], func )
  22.         else
  23.             table.insert( xgui.hook[dtype][event], func )
  24.         end
  25.     end
  26. end
  27.  
  28. --Set up tables and functions for creating and storing modules
  29. xgui.modules = {}
  30.  
  31. xgui.modules.tab={}
  32. function xgui.addModule( name, panel, icon, access, tooltip )
  33.     table.insert( xgui.modules.tab, { name=name, panel=panel, icon=icon, access=access, tooltip=tooltip } )
  34. end
  35.  
  36. xgui.modules.setting={}
  37. function xgui.addSettingModule( name, panel, icon, access, tooltip )
  38.     table.insert( xgui.modules.setting, { name=name, panel=panel, icon=icon, access=access, tooltip=tooltip } )
  39. end
  40.  
  41. xgui.modules.submodule={}
  42. function xgui.addSubModule( name, panel, access, mtype )
  43.     table.insert( xgui.modules.submodule, { name=name, panel=panel, access=access, mtype=mtype } )
  44. end
  45. --Set up a spot to store entries for autocomplete.
  46. xgui.tabcompletes = {}
  47. xgui.ulxmenucompletes = {}
  48.  
  49.  
  50. --Set up XGUI clientside settings, load settings from file if it exists
  51. xgui.settings = {}
  52. if ULib.fileExists( "data/ulx/xgui_settings.txt" ) then
  53.     local input = ULib.fileRead( "data/ulx/xgui_settings.txt" )
  54.     input = input:match( "^.-\n(.*)$" )
  55.     xgui.settings = ULib.parseKeyValues( input )
  56. end
  57. --Set default settings if they didn't get loaded
  58. if not xgui.settings.moduleOrder then xgui.settings.moduleOrder = { "Cmds", "Groups", "Maps", "Settings", "Bans" } end
  59. if not xgui.settings.settingOrder then xgui.settings.settingOrder = { "Sandbox", "Server", "XGUI" } end
  60. if not xgui.settings.animTime then xgui.settings.animTime = 0.22 else xgui.settings.animTime = tonumber( xgui.settings.animTime ) end
  61. if not xgui.settings.infoColor then
  62.     --Default color
  63.     xgui.settings.infoColor = Color( 100, 255, 255, 128 )
  64. else
  65.     --Ensure that the color contains numbers, not strings
  66.     xgui.settings.infoColor = Color(xgui.settings.infoColor.r, xgui.settings.infoColor.g, xgui.settings.infoColor.b, xgui.settings.infoColor.a)
  67. end
  68. if not xgui.settings.showLoadMsgs then xgui.settings.showLoadMsgs = true else xgui.settings.showLoadMsgs = ULib.toBool( xgui.settings.showLoadMsgs ) end
  69. if not xgui.settings.skin then xgui.settings.skin = "Default" end
  70. if not xgui.settings.xguipos then xgui.settings.xguipos = { pos=5, xoff=0, yoff=0 } end
  71. if not xgui.settings.animIntype then xgui.settings.animIntype = 1 end
  72. if not xgui.settings.animOuttype then xgui.settings.animOuttype = 1 end
  73.  
  74.  
  75. function xgui.init( ply )
  76.     xgui.load_helpers()
  77.  
  78.     --Initiate the base window (see xgui_helpers.lua for code)
  79.     xgui.makeXGUIbase{}
  80.  
  81.     --Create the bottom infobar
  82.     xgui.infobar = xlib.makepanel{ x=10, y=399, w=580, h=20, parent=xgui.anchor }
  83.     xgui.infobar:NoClipping( true )
  84.     xgui.infobar.Paint = function( self, w, h )
  85.         draw.RoundedBoxEx( 4, 0, 1, 580, 20, xgui.settings.infoColor, false, false, true, true )
  86.     end
  87.     local version_type = ulx.revision and ( ulx.revision > 0 and " SVN " .. ulx.revision or " Release") or (" N/A")
  88.     xlib.makelabel{ x=5, y=-10, label="\nULX Admin Mod :: XGUI - by Stickly Man! :: v15.3.9 |  ULX v" .. string.format("%.2f", ulx.version) .. version_type .. "  |  ULib v" .. ULib.VERSION, parent=xgui.infobar }:NoClipping( true )
  89.     xgui.thetime = xlib.makelabel{ x=515, y=-10, label="", parent=xgui.infobar }
  90.     xgui.thetime:NoClipping( true )
  91.     xgui.thetime.check = function()
  92.         xgui.thetime:SetText( os.date( "\n%I:%M:%S %p" ) )
  93.         xgui.thetime:SizeToContents()
  94.         timer.Simple( 1, xgui.thetime.check )
  95.     end
  96.     xgui.thetime.check()
  97.  
  98.     --Create an offscreen place to parent modules that the player can't access
  99.     xgui.null = xlib.makepanel{ x=-10, y=-10, w=0, h=0 }
  100.     xgui.null:SetVisible( false )
  101.  
  102.     --Load modules
  103.     local sm = xgui.settings.showLoadMsgs
  104.     if sm then
  105.         Msg( "\n///////////////////////////////////////\n" )
  106.         Msg( "//  ULX GUI -- Made by Stickly Man!  //\n" )
  107.         Msg( "///////////////////////////////////////\n" )
  108.         Msg( "// Loading GUI Modules...            //\n" )
  109.     end
  110.     for _, file in ipairs( file.Find( "ulx/xgui/*.lua", "LUA" ) ) do
  111.         include( "ulx/xgui/" .. file )
  112.         if sm then Msg( "//   " .. file .. string.rep( " ", 32 - file:len() ) .. "//\n" ) end
  113.     end
  114.     if sm then Msg( "// Loading Setting Modules...        //\n" ) end
  115.     for _, file in ipairs( file.Find( "ulx/xgui/settings/*.lua", "LUA" ) ) do
  116.         include( "ulx/xgui/settings/" .. file )
  117.         if sm then Msg( "//   " .. file .. string.rep( " ", 32 - file:len() ) .. "//\n" ) end
  118.     end
  119.     if sm then Msg( "// Loading Gamemode Module(s)...     //\n" ) end
  120.     if ULib.isSandbox() and GAMEMODE.FolderName ~= "sandbox" then -- If the gamemode sandbox-derived (but not sandbox, that will get added later), then add the sandbox Module
  121.         include( "ulx/xgui/gamemodes/sandbox.lua" )
  122.         if sm then Msg( "//   sandbox.lua                     //\n" ) end
  123.     end
  124.     for _, file in ipairs( file.Find( "ulx/xgui/gamemodes/*.lua", "LUA" ) ) do
  125.         if string.lower( file ) == string.lower( GAMEMODE.FolderName .. ".lua" ) then
  126.             include( "ulx/xgui/gamemodes/" .. file )
  127.             if sm then Msg( "//   " .. file .. string.rep( " ", 32 - file:len() ) .. "//\n" ) end
  128.             break
  129.         end
  130.         if sm then Msg( "//   No module found!                //\n" ) end
  131.     end
  132.     if sm then Msg( "// Modules Loaded!                   //\n" ) end
  133.     if sm then Msg( "///////////////////////////////////////\n\n" ) end
  134.  
  135.     --Find any existing modules that aren't listed in the requested order.
  136.     local function checkModulesOrder( moduleTable, sortTable )
  137.         for _, m in ipairs( moduleTable ) do
  138.             local notlisted = true
  139.             for _, existing in ipairs( sortTable ) do
  140.                 if m.name == existing then
  141.                     notlisted = false
  142.                     break
  143.                 end
  144.             end
  145.             if notlisted then
  146.                 table.insert( sortTable, m.name )
  147.             end
  148.         end
  149.     end
  150.     checkModulesOrder( xgui.modules.tab, xgui.settings.moduleOrder )
  151.     checkModulesOrder( xgui.modules.setting, xgui.settings.settingOrder )
  152.  
  153.     --Check if the server has XGUI installed
  154.     RunConsoleCommand( "_xgui", "getInstalled" )
  155.  
  156.     xgui.initialized = true
  157.  
  158.     xgui.processModules()
  159. end
  160. hook.Add( ULib.HOOK_LOCALPLAYERREADY, "InitXGUI", xgui.init, 20 )
  161.  
  162. function xgui.saveClientSettings()
  163.     local output = "// This file stores clientside settings for XGUI.\n"
  164.     output = output .. ULib.makeKeyValues( xgui.settings )
  165.     ULib.fileWrite( "data/ulx/xgui_settings.txt", output )
  166. end
  167.  
  168. function xgui.checkModuleExists( modulename, moduletable )
  169.     for k, v in ipairs( moduletable ) do
  170.         if v.name == modulename then
  171.             return k
  172.         end
  173.     end
  174.     return false
  175. end
  176.  
  177. function xgui.processModules()
  178.     local activetab = nil
  179.     if xgui.base:GetActiveTab() then
  180.         activetab = xgui.base:GetActiveTab():GetValue()
  181.     end
  182.  
  183.     local activesettingstab = nil
  184.     if xgui.settings_tabs:GetActiveTab() then
  185.         activesettingstab = xgui.settings_tabs:GetActiveTab():GetValue()
  186.     end
  187.  
  188.     xgui.base:Clear() --We need to remove any existing tabs in the GUI
  189.     xgui.tabcompletes = {}
  190.     xgui.ulxmenucompletes = {}
  191.     for _, modname in ipairs( xgui.settings.moduleOrder ) do
  192.         local module = xgui.checkModuleExists( modname, xgui.modules.tab )
  193.         if module then
  194.             module = xgui.modules.tab[module]
  195.             if module.xbutton == nil then
  196.                 module.xbutton = xlib.makebutton{ x=555, y=-5, w=32, h=32, btype="close", parent=module.panel }
  197.                 module.xbutton.DoClick = function()
  198.                     xgui.hide()
  199.                 end
  200.             end
  201.             if LocalPlayer():query( module.access ) then
  202.                 xgui.base:AddSheet( module.name, module.panel, module.icon, false, false, module.tooltip )
  203.                 module.tabpanel = xgui.base.Items[#xgui.base.Items].Tab
  204.                 table.insert( xgui.tabcompletes, "xgui show " .. modname )
  205.                 table.insert( xgui.ulxmenucompletes, "ulx menu " .. modname )
  206.             else
  207.                 module.tabpanel = nil
  208.                 module.panel:SetParent( xgui.null )
  209.             end
  210.         end
  211.     end
  212.  
  213.     xgui.settings_tabs:Clear() --Clear out settings tabs for reprocessing
  214.     for _, modname in ipairs( xgui.settings.settingOrder ) do
  215.         local module = xgui.checkModuleExists( modname, xgui.modules.setting )
  216.         if module then
  217.             module = xgui.modules.setting[module]
  218.             if LocalPlayer():query( module.access ) then
  219.                 xgui.settings_tabs:AddSheet( module.name, module.panel, module.icon, false, false, module.tooltip )
  220.                 module.tabpanel = xgui.settings_tabs.Items[#xgui.settings_tabs.Items].Tab
  221.                 table.insert( xgui.tabcompletes, "xgui show " .. modname )
  222.                 table.insert( xgui.ulxmenucompletes, "ulx menu " .. modname )
  223.             else
  224.                 module.tabpanel = nil
  225.                 module.panel:SetParent( xgui.null )
  226.             end
  227.         end
  228.     end
  229.  
  230.     --Call any functions that requested to be called when permissions change
  231.     xgui.callUpdate( "onProcessModules" )
  232.     table.sort( xgui.tabcompletes )
  233.     table.sort( xgui.ulxmenucompletes )
  234.  
  235.     local hasFound = false
  236.     if activetab then
  237.         for _, v in pairs( xgui.base.Items ) do
  238.             if v.Tab:GetValue() == activetab then
  239.                 xgui.base:SetActiveTab( v.Tab, true )
  240.                 hasFound = true
  241.                 break
  242.             end
  243.         end
  244.         if not hasFound then
  245.             xgui.base.m_pActiveTab = "none"
  246.             xgui.base:SetActiveTab( xgui.base.Items[1].Tab, true )
  247.         end
  248.     end
  249.  
  250.     hasFound = false
  251.     if activesettingstab then
  252.         for _, v in pairs( xgui.settings_tabs.Items ) do
  253.             if v.Tab:GetValue() == activesettingstab then
  254.                 xgui.settings_tabs:SetActiveTab( v.Tab, true )
  255.                 hasFound = true
  256.                 break
  257.             end
  258.         end
  259.         if not hasFound then
  260.             xgui.settings_tabs.m_pActiveTab = "none"
  261.             xgui.settings_tabs:SetActiveTab( xgui.settings_tabs.Items[1].Tab, true )
  262.         end
  263.     end
  264. end
  265.  
  266. function xgui.checkNotInstalled( tabname )
  267.     if xgui.notInstalledWarning then return end
  268.  
  269.     gui.EnableScreenClicker( true )
  270.     RestoreCursorPosition()
  271.     xgui.notInstalledWarning = xlib.makeframe{ label="XGUI Warning!", w=375, h=110, nopopup=true, showclose=false, skin=xgui.settings.skin }
  272.     xlib.makelabel{ x=10, y=30, wordwrap=true, w=365, label="XGUI has not initialized properly with the server. This could be caused by a heavy server load after a mapchange, a major error during XGUI server startup, or XGUI not being installed.", parent=xgui.notInstalledWarning }
  273.  
  274.     xlib.makebutton{ x=37, y=83, w=80, label="Offline Mode", parent=xgui.notInstalledWarning }.DoClick = function()
  275.         xgui.notInstalledWarning:Remove()
  276.         xgui.notInstalledWarning = nil
  277.         offlineWarning = xlib.makeframe{ label="XGUI Warning!", w=375, h=110, nopopup=true, showclose=false, skin=xgui.settings.skin }
  278.         xlib.makelabel{ x=10, y=30, wordwrap=true, w=365, label="XGUI will run locally in offline mode. Some features will not work, and information will be missing. You can attempt to reconnect to the server using the 'Refresh Server Data' button in the XGUI client menu.", parent=offlineWarning }
  279.         xlib.makebutton{ x=77, y=83, w=80, label="OK", parent=offlineWarning }.DoClick = function()
  280.             offlineWarning:Remove()
  281.             xgui.offlineMode = true
  282.             xgui.show( tabname )
  283.         end
  284.         xlib.makebutton{ x=217, y=83, w=80, label="Cancel", parent=offlineWarning }.DoClick = function()
  285.             offlineWarning:Remove()
  286.             RememberCursorPosition()
  287.             gui.EnableScreenClicker( false )
  288.         end
  289.     end
  290.  
  291.     xlib.makebutton{ x=257, y=83, w=80, label="Close", parent=xgui.notInstalledWarning }.DoClick = function()
  292.         xgui.notInstalledWarning:Remove()
  293.         xgui.notInstalledWarning = nil
  294.         RememberCursorPosition()
  295.         gui.EnableScreenClicker( false )
  296.     end
  297.  
  298.     xlib.makebutton{ x=147, y=83, w=80, label="Try Again", parent=xgui.notInstalledWarning }.DoClick = function()
  299.         xgui.notInstalledWarning:Remove()
  300.         xgui.notInstalledWarning = nil
  301.         RememberCursorPosition()
  302.         gui.EnableScreenClicker( false )
  303.         local reattempt = xlib.makeframe{ label="XGUI: Attempting reconnection...", w=200, h=20, nopopup=true, showclose=false, skin=xgui.settings.skin }
  304.         timer.Simple( 1, function()
  305.             RunConsoleCommand( "_xgui", "getInstalled" )
  306.             reattempt:Remove()
  307.             timer.Simple( 0.5, function() xgui.show( tabname ) end )
  308.         end )
  309.     end
  310. end
  311.  
  312. function xgui.show( tabname )
  313.     if not xgui.anchor then return end
  314.     if not xgui.initialized then return end
  315.  
  316.     --Check if XGUI is not installed, display the warning if hasn't been shown yet.
  317.     if not xgui.isInstalled and not xgui.offlineMode then
  318.         xgui.checkNotInstalled( tabname )
  319.         return
  320.     end
  321.  
  322.     if not game.SinglePlayer() and not ULib.ucl.authed[LocalPlayer():UniqueID()] then
  323.         local unauthedWarning = xlib.makeframe{ label="XGUI Error!", w=250, h=90, showclose=true, skin=xgui.settings.skin }
  324.         xlib.makelabel{ label="Your ULX player has not been Authed!", x=10, y=30, parent=unauthedWarning }
  325.         xlib.makelabel{ label="Please wait a couple seconds and try again.", x=10, y=45, parent=unauthedWarning }
  326.         xlib.makebutton{ x=50, y=63, w=60, label="Try Again", parent=unauthedWarning }.DoClick = function()
  327.             unauthedWarning:Remove()
  328.             xgui.show( tabname )
  329.         end
  330.         xlib.makebutton{ x=140, y=63, w=60, label="Close", parent=unauthedWarning }.DoClick = function()
  331.             unauthedWarning:Remove()
  332.         end
  333.         return
  334.     end
  335.  
  336.     if xgui.base.refreshSkin then
  337.         xgui.base:SetSkin( xgui.settings.skin )
  338.         xgui.base.refreshSkin = nil
  339.     end
  340.  
  341.     --In case the string name had spaces, it sent the whole argument table. Convert it to a string here!
  342.     if type( tabname ) == "table" then
  343.         tabname = table.concat( tabname, " " )
  344.     end
  345.     --Sets the active tab to tabname if it was specified
  346.     if tabname and tabname ~= "" then
  347.         local found, settingsTab
  348.         for _, v in ipairs( xgui.modules.tab ) do
  349.             if string.lower( v.name ) == "settings" then settingsTab = v.tabpanel end
  350.             if string.lower( v.name ) == string.lower( tabname ) and v.panel:GetParent() ~= xgui.null then
  351.                 xgui.base:SetActiveTab( v.tabpanel )
  352.                 if xgui.anchor:IsVisible() then return end
  353.                 found = true
  354.                 break
  355.             end
  356.         end
  357.         if not found then
  358.             for _, v in ipairs( xgui.modules.setting ) do
  359.                 if string.lower( v.name ) == string.lower( tabname ) and v.panel:GetParent() ~= xgui.null then
  360.                     xgui.base:SetActiveTab( settingsTab )
  361.                     xgui.settings_tabs:SetActiveTab( v.tabpanel )
  362.                     if xgui.anchor:IsVisible() then return end
  363.                     found = true
  364.                     break
  365.                 end
  366.             end
  367.         end
  368.         if not found then return end --If invalid input was taken, then do nothing.
  369.     end
  370.  
  371.     xgui.base.animOpen()
  372.     gui.EnableScreenClicker( true )
  373.     RestoreCursorPosition()
  374.     xgui.anchor:SetMouseInputEnabled( true )
  375.  
  376.     --Calls the functions requesting to hook when XGUI is opened
  377.     xgui.callUpdate( "onOpen" )
  378. end
  379.  
  380. function xgui.hide()
  381.     if not xgui.anchor then return end
  382.     if not xgui.anchor:IsVisible() then return end
  383.     RememberCursorPosition()
  384.     gui.EnableScreenClicker( false )
  385.     xgui.anchor:SetMouseInputEnabled( false )
  386.     xgui.base.animClose()
  387.     CloseDermaMenus()
  388.  
  389.     --Calls the functions requesting to hook when XGUI is closed
  390.     xgui.callUpdate( "onClose" )
  391. end
  392.  
  393. function xgui.toggle( tabname )
  394.     if xgui.anchor and ( not xgui.anchor:IsVisible() or ( tabname and #tabname ~= 0 ) ) then
  395.         xgui.show( tabname )
  396.     else
  397.         xgui.hide()
  398.     end
  399. end
  400.  
  401. --New XGUI Data stuff
  402. function xgui.expectChunks( numofchunks )
  403.     if xgui.isInstalled then
  404.         xgui.expectingdata = true
  405.         xgui.chunkbox.max = numofchunks
  406.         xgui.chunkbox.value = 0
  407.         xgui.chunkbox:SetFraction( 0 )
  408.         xgui.chunkbox.Label:SetText( "Getting data: Waiting for server..." )
  409.         xgui.chunkbox:SetVisible( true )
  410.         xgui.flushQueue( "chunkbox" ) --Remove the queue entry that would hide the chunkbox
  411.     end
  412. end
  413.  
  414. function xgui.getChunk( flag, datatype, data )
  415.     if xgui.expectingdata then
  416.         --print( datatype, flag ) --Debug
  417.         xgui.chunkbox:Progress( datatype )
  418.         if flag == -1 then return --Ignore these chunks
  419.         elseif flag == 0 then --Data should be purged
  420.             if xgui.data[datatype] then
  421.                 table.Empty( xgui.data[datatype] )
  422.             end
  423.             xgui.flushQueue( datatype )
  424.             xgui.callUpdate( datatype, "clear" )
  425.         elseif flag == 1 then
  426.             if not xgui.mergeData then --A full data table is coming in
  427.                 if not data then data = {} end --Failsafe for no table being sent
  428.                 xgui.flushQueue( datatype )
  429.                 table.Empty( xgui.data[datatype] )
  430.                 table.Merge( xgui.data[datatype], data )
  431.                 xgui.callUpdate( datatype, "clear" )
  432.                 xgui.callUpdate( datatype, "process", data )
  433.                 xgui.callUpdate( datatype, "done" )
  434.             else --A chunk of data is coming in
  435.                 table.Merge( xgui.data[datatype], data )
  436.                 xgui.callUpdate( datatype, "process", data )
  437.             end
  438.         elseif flag == 2 or flag == 3 then --Add/Update a portion of data
  439.             table.Merge( xgui.data[datatype], data )
  440.             xgui.callUpdate( datatype, flag == 2 and "add" or "update", data )
  441.         elseif flag == 4 then --Remove a key from the table
  442.             xgui.removeDataEntry( xgui.data[datatype], data ) --Needs to be called recursively!
  443.             xgui.callUpdate( datatype, "remove", data )
  444.         elseif flag == 5 then --Begin a set of chunks (Clear the old data, then flag to merge incoming data)
  445.             table.Empty( xgui.data[datatype] )
  446.             xgui.mergeData = true
  447.             xgui.flushQueue( datatype )
  448.             xgui.callUpdate( datatype, "clear" )
  449.         elseif flag == 6 then --End a set of chunks (Clear the merge flag)
  450.             xgui.mergeData = nil
  451.             xgui.callUpdate( datatype, "done" )
  452.         elseif flag == 7 then --Pass the data directly to the module to be handled.
  453.             xgui.callUpdate( datatype, "data", data )
  454.         end
  455.         xgui.callUpdate( datatype )
  456.     end
  457. end
  458.  
  459. function xgui.removeDataEntry( data, entry )
  460.     for k, v in pairs( entry ) do
  461.         if type( v ) == "table" then
  462.             xgui.removeDataEntry( data[k], v )
  463.         else
  464.             if type(v) == "number" then
  465.                 table.remove( data, v )
  466.             else
  467.                 data[v] = nil
  468.             end
  469.         end
  470.     end
  471. end
  472.  
  473. function xgui.callUpdate( dtype, event, data )
  474.     --Run any functions that request to be called when "curtable" is updated
  475.     if not xgui.hook[dtype] or ( event and not xgui.hook[dtype][event] ) then
  476.         Msg( "XGUI: Attempted to call non-existent type or event to a hook! (" .. dtype .. ", " .. ( event or "nil" ) .. ")\n" )
  477.     else
  478.         if not event then
  479.             for _, func in ipairs( xgui.hook[dtype] ) do func( data ) end
  480.         else
  481.             for _, func in ipairs( xgui.hook[dtype][event] ) do func( data ) end
  482.         end
  483.     end
  484. end
  485.  
  486. --If the player's group is changed, reprocess the XGUI modules for permissions, and request for extra data if needed
  487. function xgui.PermissionsChanged( ply )
  488.     if ply == LocalPlayer() and xgui.isInstalled then
  489.         xgui.processModules()
  490.         local types = {}
  491.         for dtype, data in pairs( xgui.data ) do
  492.             if table.Count( data ) > 0 then table.insert( types, dtype ) end
  493.         end
  494.         RunConsoleCommand( "xgui", "refreshdata", unpack( types ) )
  495.     end
  496. end
  497. hook.Add( "UCLAuthed", "XGUI_PermissionsChanged", xgui.PermissionsChanged )
  498.  
  499. function xgui.getInstalled()
  500.     if not xgui.isInstalled then
  501.         if xgui.notInstalledWarning then
  502.             xgui.notInstalledWarning:Remove()
  503.             xgui.notInstalledWarning = nil
  504.         end
  505.         xgui.isInstalled = true
  506.         xgui.offlineMode = false
  507.         RunConsoleCommand( "xgui", "getdata" )
  508.     end
  509. end
  510.  
  511. function xgui.cmd_base( ply, func, args )
  512.     if not args[ 1 ] then
  513.         xgui.toggle()
  514.     elseif xgui.isInstalled then --First check that it's installed
  515.         RunConsoleCommand( "_xgui", unpack( args ) )
  516.     end
  517. end
  518.  
  519. function xgui.tab_completes()
  520.     return xgui.tabcompletes
  521. end
  522.  
  523. function xgui.ulxmenu_tab_completes()
  524.     return xgui.ulxmenucompletes
  525. end
  526.  
  527. ULib.cmds.addCommandClient( "xgui", xgui.cmd_base )
  528. ULib.cmds.addCommandClient( "xgui show", function( ply, cmd, args ) xgui.show( args ) end, xgui.tab_completes )
  529. ULib.cmds.addCommandClient( "xgui hide", xgui.hide )
  530. ULib.cmds.addCommandClient( "xgui toggle", function() xgui.toggle() end )
  531.  
  532. --local ulxmenu = ulx.command( CATEGORY_NAME, "ulx menu", ulx.menu, "!menu" )
  533. ULib.cmds.addCommandClient( "ulx menu", function( ply, cmd, args ) xgui.toggle( args ) end, xgui.ulxmenu_tab_completes )
Advertisement
Add Comment
Please, Sign In to add comment