круглый биндер (на колесико)

w99zzl1

Участник
Автор темы
129
12
Версия MoonLoader
.026-beta
Заинтересовался написать биндер, который, при нажатии на колесико мыши будет проявлять "менюшку", по задумке, она круглая, а кнопочки - поделены на "дольки" этого круга, и скрипт триггерится когда я навел на нужную себе кнопку и отпустил СКМ. Написал код, мало того, что меню не появляется (появляется окно debug, которое, кстати, работает как "маска", если перетащить его в центр - появляется походу то самое полудохлое "меню" биндера. И мало того, появляется не круг, а злоебучий многоугольник какой то. Гайдов или открытых кодов с таким биндером не нашел, так что пишу сюда ибо вообще теперь не понимаю, как это организовать. Подскажите пожалуйста. Вот код:


Код:
local menu = imgui.new.bool(false)  -- окно (открыто / закрыто)
local key_m3 = 0x04  -- Средняя кнопка мыши
local sectors = 6  -- Количество кнопок ("долек")
local radius = 120  -- Радиус меню
local selected = nil  -- Выбранная "долька"

-- Опции команд, соответствующие "долькам"
local options = {
    {label = "Привет", action = function() sampSendChat("Привет") end},
    {label = "Как дела?", action = function() sampSendChat("Как дела?") end}
}

function main()
    while not isSampAvailable() do wait(100) end

    while true do
        wait(0)

        -- Открытие меню при зажатии СКМ
        if isKeyDown(key_m3) then
            menu[0] = true
            showCursor(true)
        end

        -- Закрытие меню при отпускании СКМ + выполнение команды
        if wasKeyReleased(key_m3) then
            menu[0] = false
            showCursor(false)
            if selected then
                selected.action()
                selected = nil
            end
        end
    end
end

imgui.OnFrame(function() return menu[0] end, function()
    local sx, sy = getScreenResolution()  -- Размер экрана
    local cx, cy = sx / 2, sy / 2  -- Центр экрана
    local draw = imgui.GetWindowDrawList()

    -- Невидимое окно
    imgui.SetNextWindowPos(imgui.ImVec2(0, 0), imgui.Cond.Always)
    imgui.SetNextWindowSize(imgui.ImVec2(0, 0))
    imgui.Begin("###RadialMenu", nil, imgui.WindowFlags.NoBackground + imgui.WindowFlags.NoDecoration + imgui.WindowFlags.NoMove + imgui.WindowFlags.NoInputs)

    -- Координаты курсора
    local success, mx, my = getCursorPos()
    if success and mx and my then
        -- Вычисляем угол курсора относительно центра
        local angle = math.atan2(my - cy, mx - cx)
        if angle < 0 then angle = angle + 2 * math.pi end

        -- В какой сектор попал курсор
        local sector_size = (2 * math.pi) / sectors
        local index = math.floor(angle / sector_size) + 1
        selected = options[index]
    end

    -- Радиальное меню
    for i, opt in ipairs(options) do
        local start_angle = (i - 1) * (2 * math.pi / sectors)
        local end_angle = i * (2 * math.pi / sectors)

        local p1 = imgui.ImVec2(cx, cy)
        local p2 = imgui.ImVec2(cx + math.cos(start_angle) * radius, cy + math.sin(start_angle) * radius)
        local p3 = imgui.ImVec2(cx + math.cos(end_angle) * radius, cy + math.sin(end_angle) * radius)

        local color = imgui.ColorConvertFloat4ToU32({0.2, 0.2, 0.2, 0.8})
        if selected == opt then
            color = imgui.ColorConvertFloat4ToU32({0.8, 0.2, 0.2, 0.8}) -- Подсветка выбранного сектора
        end

        draw:AddTriangleFilled(p1, p2, p3, color)
    end

    imgui.End()
end)
 
Решение
Lua:
local imgui     = require "mimgui"
local encoding  = require "encoding"

encoding.default = "CP1251"
u8 = encoding.UTF8

-- Pie меню
local pie       = require "imgui_piemenu"
local pie_mode  = imgui.new.bool(true)
local pie_keyId = 1 -- 0 ЛКМ, 1 ПКМ, 2 СКМ

local pie_elements = {
    --[[
        name    = Название кнопки
        action  = Действие кнопки
        next    = Подменю этой кнопки. Если nil - подменю не будет
    ]]

    {name = "Привет", action = function() sampAddChatMessage("Привет!", -1) end, next = nil},
    {name = "Пока", action = function() sampAddChatMessage("Пока", -1) end, next = nil},
    {name = "Биндер", action = function() end, next = {
        -- Подменю...

w99zzl1

Участник
Автор темы
129
12
Lua:
function main()
 while not isSampAvailable() do wait(100) end
 wait(500)

while true do wait(0)
  if isKeyJustPressed(88) then
     piemenu[0] = not piemenu[0]
  end
end
Lua:
local imgui = require 'mimgui'
local pie = require 'imgui_piemenu'

local piemenu = imgui.new.bool(false)

function main()
    while not isSampAvailable() do wait(100) end
    wait(500)
  
   while true do wait(0)
        if isKeyJustPressed(88) then
            piemenu[0] = not piemenu[0]
        end
    end
end

imgui.OnFrame(function() return piemenu[0] end, function()
    imgui.OpenPopup('PieMenu')

    if pie.BeginPiePopup('PieMenu', 1) then
        if pie.PieMenuItem('Test1') then
            sampAddChatMessage("Выбран Test1")
        end
        pie.EndPiePopup()
    end

    return true
end)
БЛЯТЬ, КАК ЭТО СЛОЖНО. Всё безуспешно(

[ML] (system) alt enter.lua: Loaded successfully. и всё
 

Dmitriy Makarov

25.05.2021
Проверенный
2,508
1,136
Lua:
local imgui     = require "mimgui"
local encoding  = require "encoding"

encoding.default = "CP1251"
u8 = encoding.UTF8

-- Pie меню
local pie       = require "imgui_piemenu"
local pie_mode  = imgui.new.bool(true)
local pie_keyId = 1 -- 0 ЛКМ, 1 ПКМ, 2 СКМ

local pie_elements = {
    --[[
        name    = Название кнопки
        action  = Действие кнопки
        next    = Подменю этой кнопки. Если nil - подменю не будет
    ]]

    {name = "Привет", action = function() sampAddChatMessage("Привет!", -1) end, next = nil},
    {name = "Пока", action = function() sampAddChatMessage("Пока", -1) end, next = nil},
    {name = "Биндер", action = function() end, next = {
        -- Подменю кнопки "Биндер"
        {name = "/lock", action = function() sampAddChatMessage("/lock", -1) end, next = nil},
        {name = "Маска", action = function() sampAddChatMessage("/mask", -1) end, next = nil},
        {name = "Аптечка", action = function()
            sampAddChatMessage("/healme", -1)
            -- Тут отыгровка /healme, если надо
        end, next = nil},
    }},
    {name = "Ещё что-то", action = function() sampAddChatMessage("Что-то", -1) end, next = nil},
}

imgui.OnInitialize(function()
    imgui.GetIO().IniFilename = nil
end)

imgui.OnFrame(function() return pie_mode[0] end, function(self)
    if imgui.IsMouseClicked(pie_keyId) then
        imgui.OpenPopup("PieMenu")
    end
    
    if pie.BeginPiePopup("PieMenu", pie_keyId) then
        for k, v in ipairs(pie_elements) do
            if v.next == nil then
                if pie.PieMenuItem(u8(v.name)) then
                    v.action()
                end
            elseif type(v.next) == "table" then
                drawPieSub(v)
            end
        end
        pie.EndPiePopup()
    end
    self.HideCursor = (not imgui.IsMouseDown(pie_keyId))
end)

-- Pie меню
function drawPieSub(v)
    if pie.BeginPieMenu(u8(v.name)) then
        for i, l in ipairs(v.next) do
            if l.next == nil then
                if pie.PieMenuItem(u8(l.name)) then
                    l.action()
                end
            elseif type(l.next) == "table" then
                drawPieSub(l)
            end
        end
        pie.EndPieMenu()
    end
end
1739441806407.png
 
  • Влюблен
Реакции: w99zzl1