local sf = require 'sampfuncs'

function submenus_show(menu, caption, select_button, close_button, back_button)
	select_button, close_button, back_button = select_button or 'Select', close_button or 'Close', back_button or 'Back'
	prev_menus = {}
	function display(menu, id, caption)
		local string_list = {}
		for i, v in ipairs(menu) do
			table.insert(string_list, type(v.submenu) == 'table' and v.title .. '  >>' or v.title)
		end
		sampShowDialog(id, caption, table.concat(string_list, '\n'), select_button, (#prev_menus > 0) and back_button or close_button, sf.DIALOG_STYLE_LIST)
		repeat
			wait(0)
			local result, button, list = sampHasDialogRespond(id)
			if result then
				if button == 1 and list ~= -1 then
					local item = menu[list + 1]
					if type(item.submenu) == 'table' then -- submenu
						table.insert(prev_menus, {menu = menu, caption = caption})
						if type(item.onclick) == 'function' then
							item.onclick(menu, list + 1, item.submenu)
						end
						return display(item.submenu, id + 1, item.submenu.title and item.submenu.title or item.title)
					elseif type(item.onclick) == 'function' then
						local result = item.onclick(menu, list + 1)
						if not result then return result end
						return display(menu, id, caption)
					end
				else -- if button == 0
					if #prev_menus > 0 then
						local prev_menu = prev_menus[#prev_menus]
						prev_menus[#prev_menus] = nil
						return display(prev_menu.menu, id - 1, prev_menu.caption)
					end
					return false
				end
			end
		until result
  end
	return display(menu, 31337, caption or menu.title)
end








-- Цвета
local WHITE = "{FFFFFF}"
local GREEN = "{5cb85c}"
local RED   = "{d9534f}"

-- Типы размещения
local typeNames = {
  [0] = "Линия",
  [1] = "Сетка",
  [2] = "Фигура",
  [3] = "Рандом",
}

-- Фейковые обработчики для демонстрации
local function temporary_placeholder() return true end

-- Опции по типам с уникальными onclick
local typeOptions = {
  [0] = {
    { title = " - Line specific option 1", onclick = temporary_placeholder },
    { title = " - Line specific option 4", onclick = temporary_placeholder },
    { title = " - Line specific option 3", onclick = temporary_placeholder },
    { title = " - Line specific option 2", onclick = temporary_placeholder },
  },
  [1] = {
    { title = " - Grid specific option 1", onclick = temporary_placeholder },
    { title = " - Grid specific option 3", onclick = temporary_placeholder },
    { title = " - Grid specific option 2", onclick = temporary_placeholder },
  },
  [2] = {
    { title = " - Shape specific option 1", onclick = temporary_placeholder },
    { title = " - Shape specific option 2", onclick = temporary_placeholder },
  },
  [3] = {
    { title = " - Область рандома \t\t\t [ Радиус ]", onclick = temporary_placeholder },
    { title = " - Random specific option 5", onclick = temporary_placeholder },
    { title = " - Random specific option 4", onclick = temporary_placeholder },
    { title = " - Random specific option 3", onclick = temporary_placeholder },
    { title = " - Random specific option 2", onclick = temporary_placeholder },
  },
}

-- Переменные состояния
local typeId = 3
local allign = false

-- Меню
local menu = {}

-- Построить динамические элементы
local function insertDynamicOptions(menu)
  local opts = typeOptions[typeId]
  for i = #opts, 1, -1 do
    local item = opts[i]
    item.dynamic = true
    table.insert(menu, 2, item)
  end
end

-- Обновление меню при смене типа
local function switchType(menu, row)
  typeId = (typeId + 1) % 4
  menu[1].title = string.format(" - Тип размещения \t\t\t [ %s ]", typeNames[typeId])

  -- удалить динамику
  for i = #menu, 2, -1 do
    if menu[i].dynamic then table.remove(menu, i) end
  end

  insertDynamicOptions(menu)
  return true
end

-- Обновление меню при смене выравнивания
local function switchAllign(menu, row)
  allign = not allign
  menu[row].title = string.format(" - Выравнивание по поверхности \t [ %s%s%s ]", allign and GREEN or RED, allign and "ON" or "OFF", WHITE)
  return true
end

-- Инициализация меню
local function buildMenu()
  menu = {
    {
      title = string.format(" - Тип размещения \t\t\t [ %s ]", typeNames[typeId]),
      onclick = switchType,
    },
    {
      title = string.format(" - Выравнивание по поверхности \t [ %sOFF%s ]", RED, WHITE),
      onclick = switchAllign,
    },
    { title = " - NON-dynamic item" },
    { title = " - NON-dynamic item" },
    { title = " - NON-dynamic item" },
  }

  insertDynamicOptions(menu)
end

-- Основной цикл
function main()
  local _ = require 'game.weapons' -- пусть будет

  buildMenu()

  while true do
    wait(0)
    if testCheat("plplpl") then --
      submenus_show(menu, "", "Y", "X", "<")
    end
  end
end


возможно ли изменить submenus_show так чтобы была возможность открыть сабменю стиля отличного от sf.DIALOG_STYLE_LIST?