From 6eb1b601e966db51167db222a80262e303d9c292 Mon Sep 17 00:00:00 2001 From: rubin Date: Thu, 27 Oct 2022 11:30:29 +0300 Subject: [PATCH] add menu settings update --- easy-cruise.lua | 63 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 61 insertions(+), 2 deletions(-) diff --git a/easy-cruise.lua b/easy-cruise.lua index 5a4db7e..16dc858 100644 --- a/easy-cruise.lua +++ b/easy-cruise.lua @@ -15,7 +15,6 @@ cruise = false function main() repeat wait(0) until isSampAvailable() - lua_thread.create(script_update.main) -->> Удалить чтобы скрипт не проверял обновления while true do wait(0) @@ -96,6 +95,7 @@ script_update = { end end end + script_update.menu.init() end, command = function() lua_thread.create(function() @@ -112,7 +112,66 @@ script_update = { end end end) - end + end, + menu = { + text = {}, + dialog = {}, + init = function() + if not sampIsChatCommandDefined("rubin-mods") then + sampRegisterChatCommand("rubin-mods",script_update.menu.show) + while true do + wait(0) + local result, button, list, input = sampHasDialogRespond(2160) + if result and button == 1 then + if script_update.menu.text[list+1] ~= nil and script_update.menu.dialog[list+1] ~= nil then + script_update.menu.dialog[list+1]() + end + end + end + end + end, + show = function() + script_update.menu.text = {} + script_update.menu.dialog = {} + local ini = inicfg.load({}, script_update.address_ini) + for k,v in pairs(ini) do + script_update.menu.text[#script_update.menu.text+1] = string.format(" ") + script_update.menu.dialog[#script_update.menu.dialog+1] = function() + script_update.menu.show() + end + + script_update.menu.text[#script_update.menu.text+1] = string.format("> %s", k) + script_update.menu.dialog[#script_update.menu.dialog+1] = function() + script_update.menu.show() + end + script_update.menu.text[#script_update.menu.text+1] = string.format("\tcheck update %s", (ini[k].check_update and "on" or "off")) + script_update.menu.dialog[#script_update.menu.dialog+1] = function() + ini[k].check_update = not ini[k].check_update + inicfg.save(ini, script_update.address_ini) + script_update.menu.show() + end + if ini[k].check_update then + script_update.menu.text[#script_update.menu.text+1] = string.format("\tauto update %s", (ini[k].auto_update and "on" or "off")) + script_update.menu.dialog[#script_update.menu.dialog+1] = function() + ini[k].auto_update = not ini[k].auto_update + inicfg.save(ini, script_update.address_ini) + script_update.menu.show() + end + end + script_update.menu.text[#script_update.menu.text+1] = string.format("\tdelete update settings") + script_update.menu.dialog[#script_update.menu.dialog+1] = function() + ini[k] = nil + inicfg.save(ini, script_update.address_ini) + script_update.menu.show() + end + end + local text = "" + for i = 1, #script_update.menu.text do + text = text..u8:decode(script_update.menu.text[i]).."\n" + end + sampShowDialog(2160,"rubin-mods update settings",text,"Enter","Exit",2) + end + } } function openURL(url, fpath)