• Creating a GUI to edit config file
    7 replies, posted
I'm trying to create a GUI that lets an superadmin and whoever else they add edit items in my addon's config file. Sadly, i'm gorrible with creating GUIs and would like to see if anyone would be able to help me. Below this is what I have written. [CODE] if MainWindow then MainWindow:Remove() MainWindow = nil end -- Creates the DFrame MainWindow = vgui.Create('DFrame') -- Sets the title of the DFrame MainWindow:SetTitle('AntiSpam Configuration Menu') -- Centers the DFrame on the screen MainWindow:Center() -- Sets the size of the DFrame (not proportional) MainWindow:SetSize(300, 600) -- Enables the mouse and keyboard on the DFrame MainWindow:MakePopup() -- Creates the category list and sets the Frame as it's parent local Categories = vgui.Create('DCategoryList', MainWindow) -- Puts the Category list on the top right of the DFrame Categories:SetPos(0, 20) -- Sets to the same size as the DFrame as nothing else will be put on it Categories:SetSize(MainWindow:GetWide(), MainWindow:GetTall() - 20) local Categories_General = Categories:Add('General') -- Adds a category -- Creates a DCheckBox and adds the Categories list as it's parent local ToggleAntiSpam = vgui.Create('DCheckBox', Categories_General) -- If the AntiSpam is enabled, then mark it, else unmark it -- ToggleAntiSpam:SetValue( AntiSpam.Settings.AntiSpam.Enabled ) -- Changes the settings when the user marks/unmarks it function ToggleAntiSpam:OnChange( checked ) -- AntiSpam.Settings.AntiSpam.Enabled = checked end [/CODE]
First of all, if you want your config to be saved across restarts, use sql(ite), data folder or convars.
[QUOTE=Kevlon;49424612]First of all, if you want your config to be saved across restarts, use sql(ite), data folder or convars.[/QUOTE] The config file is saved in the data folder. The script above is only the GUI.
Read the config(EG from json to table), make the OnChange edit the specifc var in the table, and write the whole config upon removing the frame/clicking "apply".
[QUOTE=whitestar;49425270]Read the config(EG from json to table), make the OnChange edit the specifc var in the table, and write the whole config upon removing the frame/clicking "apply".[/QUOTE] Sorry, I may not have been clear in the original post. I need help with the GUI itself, I have the .TXT to table taken care of with vON.
Why use vON? Simpyl use util.jsonEncode/Decode, to write/read, then let the gui read the decoded json(aka a "config table"), and lets say you want to enable the anticheat, then make the OnChange() do config.enableac = true.
[QUOTE=whitestar;49425310]Why use vON? Simpyl use util.jsonEncode/Decode, to write/read, then let the gui read the decoded json(aka a "config table"), and lets say you want to enable the anticheat, then make the OnChange() do config.enableac = true.[/QUOTE] He asked a menu question, why the hell are you discussing about the way he's saving the configs -.- What he wants is basically why I asked on my other [url=https://facepunch.com/showthread.php?t=1458227&p=49425204&viewfull=1#post49425204]question[/url]
[QUOTE=whitestar;49425310]Why use vON? Simpyl use util.jsonEncode/Decode, to write/read, then let the gui read the decoded json(aka a "config table"), and lets say you want to enable the anticheat, then make the OnChange() do config.enableac = true.[/QUOTE] Because vON is faster and more efficient.
Sorry, you need to Log In to post a reply to this thread.