From 64bfeaea23cf92a7ab8fa49b5ae208161d6fb02f Mon Sep 17 00:00:00 2001 From: rubin Date: Mon, 23 Jan 2023 01:06:25 +0300 Subject: [PATCH] add dialog module & create dialog menu --- corn-hud.lua | 169 +++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 143 insertions(+), 26 deletions(-) diff --git a/corn-hud.lua b/corn-hud.lua index 12e02fe..58a1521 100644 --- a/corn-hud.lua +++ b/corn-hud.lua @@ -3,6 +3,7 @@ script_author("Serhiy_Rubin") script_version("22/09/2019") require 'lib.sampfuncs' require 'lib.moonloader' +local vkeys = require "lib.vkeys" local sampev, inicfg = require 'lib.samp.events', require 'inicfg' local render, antiflood = false, 0 local zerno, urojai, narko, priceZerno, priceUrojai, priceNarko, finfoCheck = 0, 0, 0, 0, 0, 0, 0 @@ -90,13 +91,7 @@ function main() inicfg.save(ini, iniName) sampfuncsLog(' {FFFFFF}corn-hud loaded. CMD: /corn | /corn hud. | Key combo: '..ini.Settings.Key1:gsub("VK_", '')..' + '..ini.Settings.Key2:gsub("VK_", '')) font = renderCreateFont(ini.Render.FontName, ini.Render.FontSize, ini.Render.FontFlag) - sampRegisterChatCommand('corn', function(param) - if render and param:lower():find('pos') then - SetPos() - else - render = not render - end - end) + lua_thread.create(menu.loop) while true do wait(0) points = '' @@ -137,7 +132,7 @@ function main() end end end - if isKeyDown(ini.Settings.Key1) and (isCharInModel(PLAYER_PED, 440) or isKeyDown(ini.Settings.Key2)) then + if isKeyDown(vkeys[ini.Settings.Key1]) and (isCharInModel(PLAYER_PED, 440) or isKeyDown(vkeys[ini.Settings.Key2])) then sampSetCursorMode(3) mouse = 1 local posX, posY = getScreenResolution() @@ -278,24 +273,6 @@ function CheckCoord() return '' end -function SetPos() - lua_thread.create(function() - wait(100) - repeat - wait(0) - pos = true - sampSetCursorMode(3) - local X, Y = getCursorPos() - ini.Settings.X = X - ini.Settings.Y = Y - inicfg.save(ini, iniName) - until isKeyJustPressed(1) - sampSetCursorMode(0) - wait(100) - pos = false - end) -end - function drawClickableText(text, posX, posY, Color1, Color2) if text ~= nil and posX ~= nil and posY ~= nil then renderFontDrawText(font, text, posX, posY, Color1) @@ -313,4 +290,144 @@ function drawClickableText(text, posX, posY, Color1, Color2) else return false end +end + + +-->> MENU +menu = {} + +function menu.get() + return { + { + settings = {title = "corn-hud" ,style = 4 ,btn1 = "Выбрать" ,btn2 = "Закрыть" ,forward = "{ffffff}" ,backwards = "\n" ,score = true}, + { + { + title = 'HUD\t'..(render and "ON" or "OFF"), + click = function(button, list, input , outs) + if button ~= 1 then return end + render = not render + showMenu = true + end + }, + { + title = 'Сменить позицию\t', + click = function(button, list, input , outs) + if button ~= 1 then return end + if not render then + render = true + end + wait(200) + repeat + wait(0) + sampSetCursorMode(3) + local X, Y = getCursorPos() + ini.Settings.X = X + ini.Settings.Y = Y + until isKeyJustPressed(1) + inicfg.save(ini, iniName) + sampSetCursorMode(0) + showMenu = true + end + }, + { + title = 'Клавиша №1\t'..ini.Settings.Key1:gsub("VK_", ""), + click = function(button, list, input , outs) + if button ~= 1 then return end + wait(200) + local key = "" + repeat + wait(0) + if not sampIsDialogActive() then + sampShowDialog(0, "Смена активации", "Нажмите на любую клавишу", "Выбрать", "Закрыть", 0) + end + for k, v in pairs(vkeys) do + if wasKeyPressed(v) and k ~= "VK_ESCAPE" and k ~= "VK_RETURN" then + key = k + end + end + until key ~= "" + ini.Settings.Key1 = key + inicfg.save(ini, iniName) + showMenu = true + end + }, + { + title = 'Клавиша №2\t'..ini.Settings.Key2:gsub("VK_", ""), + click = function(button, list, input , outs) + if button ~= 1 then return end + wait(200) + local key = "" + repeat + wait(0) + if not sampIsDialogActive() then + sampShowDialog(0, "Смена активации", "Нажмите на любую клавишу", "Выбрать", "Закрыть", 0) + end + for k, v in pairs(vkeys) do + if wasKeyPressed(v) and k ~= "VK_ESCAPE" and k ~= "VK_RETURN" then + key = k + end + end + until key ~= "" + ini.Settings.Key2 = key + inicfg.save(ini, iniName) + showMenu = true + end + }, + } + } + } +end + +function menu.loop() + showMenu = false + sampRegisterChatCommand('corn', function(param) + showMenu = true + end) + while true do + wait(0) + if showMenu then + showMenu = false + menu.dialog = menu.get() + start_dialog(menu.dialog[1]) + end + end +end + +function start_dialog(menu) -- module by trefa + function _dialog(menu, id, outs) + sampShowDialog(id, menu.settings.title, tbl_split(menu.settings.style, menu, menu.settings.forward ,menu.settings.backwards ,menu.settings.score), menu.settings.btn1, (menu.settings.btn2 ~= nil and menu.settings.btn2 or _), menu.settings.style) + repeat + wait(0) + local result, button, list, input = sampHasDialogRespond(id) + if result then + local out, outs = menu[((menu.settings.style == 0 or menu.settings.style == 1 or menu.settings.style == 3) and 1 or ((list + 1) > #menu[1] and 2 or 1))][((menu.settings.style == 0 or menu.settings.style == 1 or menu.settings.style == 3) and 1 or ((list + 1) > #menu[1] and (list - #menu[1]) + 1 or list + 1))].click(button, list, input, outs) + if type(out) == "table" then + return _dialog(out, id - 1, outs) + elseif type(out) == "boolean" then + if not out then + return out + end + return _dialog(menu, id, outs) + end + end + until result + end + + function tbl_split(style, tbl, forward ,backwards ,score) + if style == 2 or style == 4 or style == 5 then + text = (style == 5 and tbl[1].text.."\n" or "") + for i, val in ipairs(tbl[1]) do + text = text..""..forward..""..(score and "["..(i-1).."] " or "")..""..val.title..""..backwards + end + if tbl[2] ~= nil then + for _, val in ipairs(tbl[2]) do + text = text..""..forward..""..val.title..""..backwards + end + end + return text + end + return tbl[1].text + end + + return _dialog(menu, 1337, outs) end \ No newline at end of file