Вопрос Кто может переписать на никсвар

Начинающий
Статус
Оффлайн
Регистрация
19 Июн 2022
Сообщения
13
Реакции[?]
1
Поинты[?]
0
local menu_callbacks = {}

function ui.set_callback(item_type, name, item, func)
client.register_callback("paint", function()
if menu_callbacks[name] == nil then
menu_callbacks[name] = {
itmes = {}, data = {}, clicked_value = 0
}
end

if item_type == "multi_selection" then
if item ~= nil then
local items = item:get_items()

for key, value in ipairs(items) do
if menu_callbacks[name].data[value] == nil then
menu_callbacks[name].data[value] = 0
end

if item:get(value) then
menu_callbacks[name].data[value] = math.min(#items, menu_callbacks[name].data[value] + 1)
else
menu_callbacks[name].data[value] = math.max(0, menu_callbacks[name].data[value] - 1)
end

if menu_callbacks[name].data[value] == 2 then
func()
end
end
end
elseif item_type == "checkbox" then
if item:get() then
menu_callbacks[name].clicked_value = math.min(3, menu_callbacks[name].clicked_value + 1)
elseif not item:get() then
menu_callbacks[name].clicked_value = math.max(0, menu_callbacks[name].clicked_value - 1)
end

if menu_callbacks[name].clicked_value == 2 then
func()
end
elseif item_type == "selection" or item_type == "list" or item_type == "slider" then
local value = item:get()

if menu_callbacks[name].clicked_value and menu_callbacks[name].clicked_value == value then
goto skip
end

func()

menu_callbacks[name].clicked_value = value
::skip::
end
end)
end

local menu_item_c = {}
local menu_item_mt = { __index = menu_item_c }

local menu_item_callbacks = {}

function menu_item_c.new(e_type, element, group, name, to_save, condition, ...)
local reference
local is_menu_reference = false

if ((type(element)) == "function") then
local do_ui_new = {pcall(element, group, name, ...)}

assert(do_ui_new[1], 4, "Cannot create ui item because: %s", do_ui_new[2])

reference = do_ui_new[2]
else
reference = element
is_menu_reference = true
end

return setmetatable({
e_type = e_type,
group = group,
name = name,
reference = reference,
is_menu_reference = is_menu_reference,

to_save = to_save,
condition = condition,
}, menu_item_mt)
end


function menu_item_c:set(...)
local args = {...}

if (type(self.reference) == "table") then
self.reference[2]:set(unpack(args))
else
self.reference:set(unpack(args))
end
end


function menu_item_c:set_callback(func)
return ui.set_callback(self.e_type, ("%s_%s_%s"):format(self.name, self.e_type, self.group), type(self.reference) == "table" and self.reference[2] or self.reference, func)
end


function menu_item_c:set_items(...)
local args = {...}

if (type(args[1]) == "table") then
args = args[1]
end

if (type(self.reference) == "table") then
self.reference[2]:set_items(args)
else
self.reference:set_items(args)
end
end


function menu_item_c:get_items()
if (type(self.reference) == "table") then
return self.reference[2]:get_items()
else
return self.reference:get_items()
end
end


function menu_item_c:get(...)
local args = {...}

if (type(self.reference) == "table") then
return self.reference[2]:get(unpack(args))
else
return self.reference:get(unpack(args))
end
end


function menu_item_c:set_visible(value)
if (type(self.reference) == "table") then
self.reference[1]:set_visible(value)
self.reference[2]:set_visible(value)
else
self.reference:set_visible(value)
end
end


function menu_item_c.new_color_picker(group, name, default_color, alpha)
local color_picker_text = ui.add_text(group, name)
local color_picker_item = color_picker_text:add_color_picker(("Color %s"):format(name), default_color, alpha)

return {color_picker_text, color_picker_item}
end

local menu_manager_c = {}
local menu_manager_mt = { __index = menu_manager_c }

local menu_manager_current_tab = ui.add_combo_box("Main", "Current_Tab", {"none"}, 0)
local menu_manager_tabs = {}
local menu_manager_items = {}


function menu_manager_c.new(tab, group, name, to_save, condition)
return setmetatable({
tab = tab == nil and "Global" or tab,
group = group == nil and "Main" or group,
name = name,

to_save = to_save == nil and true or to_save,

condition = condition == nil and function()
return true
end or condition,
}, menu_manager_mt)
end


function menu_manager_c.reference(tab, group, name)
return menu_manager_items
[group][name].reference
end


function menu_manager_c:set_condition(cond)
self.condition = cond
end

function menu_manager_c:checkbox(default_value)
local item = self:_create_item("checkbox", ui.add_check_box, false)
if (default_value ~= nil) then
item:set_value(default_value)
end

return item
end


function menu_manager_c:text()
self.to_save = false

return self:_create_item("text", ui.add_text, false)
end

function menu_manager_c:button(callback)
assert(type(callback) == "function", 3, "Cannot set button callback because the callback argument must be a function.")

self.to_save = false

return self:_create_item("button", ui.add_button, false, callback)
end


function menu_manager_c:slider(min, max, default_value)
assert(type(min) == "number", 3, "Slider min value must be a number.")
assert(type(max) == "number", 3, "Slider max value must be a number.")
assert(min < max, 3, "Slider min value must be below the max value.")

local item = self:_create_item("slider", ui.add_slider, false, min, max)
if (default_value ~= nil) then
item:set(default_value)
end

return item
end

function menu_manager_c:color_picker(r, g, b, a)
r = r or 255
g = g or 255
b = b or 255
a = a or 255

assert(type(r) == "number" and r >= 0 and r <= 255, 3, "Cannot set color picker red channel value. It must be between 0 and 255.")
assert(type(g) == "number" and g >= 0 and g <= 255, 3, "Cannot set color picker green channel value. It must be between 0 and 255.")
assert(type(b) == "number" and b >= 0 and b <= 255, 3, "Cannot set color picker blue channel value. It must be between 0 and 255.")
assert(type(a) == "number" and a >= 0 and a <= 255, 3, "Cannot set color picker alpha channel value. It must be between 0 and 255.")

return self:_create_item("color_picker", menu_item_c.new_color_picker, false, color_t(r, g, b, a), true)
end


function menu_manager_c:selection(...)
local args = {...}

if (type(args[1]) == "table") then
args = args[1]
end

return self:_create_item("selection", ui.add_selection, false, args)
end


function menu_manager_c:multi_selection(...)
local args = {...}

if (type(args[1]) == "table") then
args = args[1]
end

return self:_create_item("multi_selection", ui.add_multi_selection, true, args)
end

function menu_manager_c.global_update_callback()
for tab_name, group_value in pairs(menu_manager_items) do
for group_name, item_value in pairs(group_value) do
for item_name, value in pairs(item_value) do
local tabs = menu_manager_current_tab:get_items()
local condition = tabs[menu_manager_current_tab:get()] == tab_name and value.condition()

if (type(value.reference) == "table") then
value.reference[1]:set_visible(condition)
value.reference[2]:set_visible(condition)
else
value.reference:set_visible(condition)
end
end
end
end
end

function menu_manager_c:_create_item(e_type, element, is_multi_selection, ...)
assert(type(self.name) == "string" and self.name ~= "", 3, "Cannot create ui item: name must be a non-empty string.")

local item = menu_item_c.new(e_type, element, self.group, self.name, self.to_save, self.condition, ...)

if (menu_manager_items[self.tab] == nil) then
menu_manager_items[self.tab] = {}

table.insert(menu_manager_tabs, self.tab)
menu_manager_current_tab:set_items(menu_manager_tabs)
end

if (menu_manager_items[self.tab][self.group] == nil) then
menu_manager_items[self.tab][self.group] = {}
end

menu_manager_items[self.tab][self.group][self.name] = {
reference = item.reference,
to_save = self.to_save,
condition = self.condition,
is_multi_selection = is_multi_selection,
e_type = e_type
}

local update_value = function()
menu_manager_c.global_update_callback()
end
item:set_callback(update_value)
update_value()

menu_manager_c.global_update_callback()

return item
end

ui.set_callback("selection", "menu_manager_current_tab", menu_manager_current_tab, function()
menu_manager_c.global_update_callback()
end)

local ui_ragebot = {}

ui_ragebot.switch = menu_manager_c.new("Ragebot", "Ragebot", "Master Switch"):checkbox()
 
Сверху Снизу