diff --git a/data/ui_scripts/settings/__init__.lua b/data/ui_scripts/settings/__init__.lua new file mode 100644 index 00000000..04c200ce --- /dev/null +++ b/data/ui_scripts/settings/__init__.lua @@ -0,0 +1,168 @@ +function createdivider(menu, text) + local element = LUI.UIElement.new({ + leftAnchor = true, + rightAnchor = true, + left = 0, + right = 0, + topAnchor = true, + bottomAnchor = false, + top = 0, + bottom = 33.33 + }) + + element.scrollingToNext = true + element:addElement(LUI.MenuBuilder.BuildRegisteredType("h1_option_menu_titlebar", { + title_bar_text = Engine.ToUpperCase(Engine.Localize(text)) + })) + + menu.list:addElement(element) +end + +LUI.addmenubutton("pc_controls", { + index = 4, + text = "$_GENERAL", + description = "Set the client's settings.", + callback = function() + LUI.FlowManager.RequestAddMenu(nil, "settings_menu") + end +}) + +LUI.MenuBuilder.m_types_build["settings_menu"] = function(a1) + local menu = LUI.MenuTemplate.new(a1, { + menu_title = "$_GENERAL", + menu_list_divider_top_offset = -(LUI.H1MenuTab.tabChangeHoldingElementHeight + luiglobals.H1MenuDims.spacing), + menu_width = luiglobals.GenericMenuDims.OptionMenuWidth + }) + + Engine.SetDvarFromString("ui_cg_autoUpdate", Engine.GetDvarBool("cg_autoUpdate") and "1" or "0") + Engine.SetDvarFromString("ui_cg_drawFps", Engine.GetDvarInt("cg_drawFps") .. "") + Engine.SetDvarFromString("ui_cg_speedGraph", Engine.GetDvarBool("cg_speedGraph") and "1" or "0") + Engine.SetDvarFromString("ui_cg_drawSpeed", Engine.GetDvarBool("cg_drawSpeed") and "1" or "0") + Engine.SetDvarFromString("ui_r_fullbright", Engine.GetDvarInt("r_fullbright") .. "") + + createdivider(menu, "$_UPDATES") + + LUI.Options.CreateOptionButton( + menu, + "ui_cg_autoUpdate", + "$_AUTOMATIC UPDATES", + "Enable or disable automatic updates on startup", + { + { + text = "$_ENABLED", + value = "1" + }, + { + text = "$_DISABLED", + value = "0" + } + }, nil, nil, function(value) + Engine.SetDvarBool("cg_autoUpdate", Engine.GetDvarString("ui_cg_autoUpdate") == "1") + end + ) + + menu:AddButton("$_CHECK FOR UPDATES", function() + LUI.tryupdating(false) + end, nil, true, nil, { + desc_text = "Check for updates." + }) + + createdivider(menu, "$_DRAWING") + + LUI.Options.CreateOptionButton( + menu, + "ui_cg_drawFps", + "$_DRAW FPS", + "Enable or disable fps and viewpos drawing on screen", + { + { + text = "$_DISABLED", + value = "0" + }, + { + text = "$_FPS ONLY", + value = "1" + }, + { + text = "$_FPS AND VIEWPOS", + value = "2" + } + }, nil, nil, function(value) + Engine.SetDvarInt("cg_drawFps", tonumber(Engine.GetDvarString("ui_cg_drawFps"))) + end + ) + + LUI.Options.CreateOptionButton( + menu, + "ui_cg_drawSpeed", + "$_DRAW SPEED", + "Enable or disable speed drawing on screen", + { + { + text = "$_DISABLED", + value = "0" + }, + { + text = "$_ENABLED", + value = "1" + } + }, nil, nil, function(value) + Engine.SetDvarBool("cg_drawSpeed", Engine.GetDvarString("ui_cg_drawSpeed") == "1") + end + ) + + LUI.Options.CreateOptionButton( + menu, + "ui_cg_speedGraph", + "$_DRAW SPEED GRAPH", + "Enable or disable speed graph drawing on screen", + { + { + text = "$_DISABLED", + value = "0" + }, + { + text = "$_ENABLED", + value = "1" + } + }, nil, nil, function(value) + Engine.SetDvarBool("cg_speedGraph", Engine.GetDvarString("ui_cg_speedGraph") == "1") + end + ) + + createdivider(menu, "$_RENDERING") + + LUI.Options.CreateOptionButton( + menu, + "ui_r_fullbright", + "$_FULLBRIGHT", + "Select the fullbright mode", + { + { + text = "$_DISABLED", + value = "0" + }, + { + text = "$_ENABLED", + value = "1" + }, + { + text = "$_MODE 2", + value = "2" + }, + { + text = "$_MODE 3", + value = "3" + } + }, nil, nil, function(value) + Engine.SetDvarInt("r_fullbright", tonumber(Engine.GetDvarString("ui_r_fullbright"))) + end + ) + + LUI.Options.InitScrollingList(menu.list, nil) + LUI.Options.AddOptionTextInfo(menu) + + menu:AddBackButton() + + return menu +end \ No newline at end of file diff --git a/src/client/component/config.cpp b/src/client/component/config.cpp new file mode 100644 index 00000000..799b3b13 --- /dev/null +++ b/src/client/component/config.cpp @@ -0,0 +1,24 @@ +#include +#include "loader/component_loader.hpp" + +#include "game/game.hpp" +#include "game/dvars.hpp" + +#include "command.hpp" +#include "game_console.hpp" + +#include + +namespace config +{ + class component final : public component_interface + { + public: + void post_unpack() override + { + dvars::register_bool("cg_autoUpdate", false, game::DvarFlags::DVAR_FLAG_SAVED); + } + }; +} + +REGISTER_COMPONENT(config::component) diff --git a/src/client/resources/updater.lua b/src/client/resources/updater.lua index a75f7b2e..3fc94a54 100644 --- a/src/client/resources/updater.lua +++ b/src/client/resources/updater.lua @@ -77,7 +77,7 @@ LUI.openpopupmenu = function(menu, args) end LUI.onmenuopen("main_lockout", function() - if (game:isdebugbuild()) then + if (game:isdebugbuild() or not Engine.GetDvarBool("cg_autoUpdate")) then return end @@ -89,14 +89,6 @@ LUI.onmenuopen("main_lockout", function() end end) -LUI.addmenubutton("pc_controls", { - text = "$_CHECK FOR UPDATES", - description = "Check for updates.", - callback = function() - tryupdate(false) - end -}) - stack = {} LUI.MenuBuilder.m_types_build["generic_waiting_popup_"] = function (menu, event) local oncancel = stack.oncancel