From 0c258b368007153ead247db43aecb2cf9a69d276 Mon Sep 17 00:00:00 2001 From: teknomunk Date: Fri, 21 Jun 2024 19:28:02 -0500 Subject: [PATCH] Start GUI --- mods/CORE/vl_tuning/gui.lua | 48 ++++++++++++++++++++++++++++++++++++ mods/CORE/vl_tuning/init.lua | 2 ++ 2 files changed, 50 insertions(+) create mode 100644 mods/CORE/vl_tuning/gui.lua diff --git a/mods/CORE/vl_tuning/gui.lua b/mods/CORE/vl_tuning/gui.lua new file mode 100644 index 000000000..778b9e442 --- /dev/null +++ b/mods/CORE/vl_tuning/gui.lua @@ -0,0 +1,48 @@ +local modname = "vl_tuning" +local modpath = minetest.get_modpath(modname) +local S = minetest.get_translator(modname) +local F = function(f) return minetest.formspec_escape(S(f)) end + +function vl_tuning.show_formspec(player_name, tab) + if not tab then tab = 1 end + + local gamerules = {} + local settings = {} + for name,_ in pairs(vl_tuning.registered_settings) do + if name:sub(0,#"gamerule:") == "gamerule:" then + table.insert(gamerules, name) + else + table.insert(settings, name) + end + end + local formspec = + "formspec_version[4]".. + "size[25,15,true]".. + "tabheader[0,0;tab;".. + F("Game Rules")..",".. + F("Settings").. + ";"..tab..";false;false]" + + minetest.show_formspec(player_name, "vl_tuning:settings", formspec) +end +minetest.register_on_player_receive_fields(function(player, formname, fields) + if formname ~= "vl_tuning:settings" then return end + + minetest.log("action",dump({ + player = player, + fields = fields, + formname = formname, + })) + if fields.quit then + return + end + vl_tuning.show_formspec(player:get_player_name(), fields.tab) +end) + +minetest.register_chatcommand("settings",{ + func = function(player_name, param) + dofile(modpath.."/gui.lua") + vl_tuning.show_formspec(player_name) + end +}) + diff --git a/mods/CORE/vl_tuning/init.lua b/mods/CORE/vl_tuning/init.lua index b3122e584..fe3210798 100644 --- a/mods/CORE/vl_tuning/init.lua +++ b/mods/CORE/vl_tuning/init.lua @@ -7,6 +7,7 @@ vl_tuning = mod -- All registered tunable parameters local tunables = {} +vl_tuning.registered_settings = tunables -- Supported variable types local tunable_types = { @@ -153,3 +154,4 @@ minetest.register_chatcommand("gamerule", { }) dofile(modpath.."/settings.lua") +dofile(modpath.."/gui.lua")