курсор mimgui

akitann

Новичок
Автор темы
9
0
Версия SA-MP
  1. 0.3.7 (R1)
  2. 0.3.7-R3
как в mimgui сделать так что бы при зажатии альта был виден курсор, а когда отжимаю нет. вот код, у меня не воркает

lua:
local imgui = require "mimgui"
local sampev = require "lib.samp.events"
local vkeys = require "vkeys"

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

local new = imgui.new
local WinState = new.bool()
local checkboxnew = new.bool()

function imgui.CenterText(text)
    local width = imgui.GetWindowWidth()
    local calc = imgui.CalcTextSize(text)
    imgui.SetCursorPosX( width / 2 - calc.x / 2 )
    imgui.Text(text)
end

imgui.OnFrame(function() return WinState[0] end,
    function(player)
        player.HideCursor = true

        if isKeyDown(VK_C) then
            player.HideCursor = false
        end
        imgui.SetNextWindowPos(imgui.ImVec2(0, 0), imgui.Cond.FirstUseEver, imgui.ImVec2(1, 1))
        imgui.SetNextWindowSize(imgui.ImVec2(270, 200), imgui.Cond.Always)
        imgui.Begin(u8"Ограбление - Karuso.", WinState, imgui.WindowFlags.NoResize)
        imgui.CenterText(u8"Бинды")

        imgui.Separator()

        if imgui.Checkbox(u8"Переключатель", checkboxnew) then
            sampAddChatMessage('{ffffff}Переключатель: ' .. (checkboxnew[0] and "{00ff00}выключен" or "{ff0000}включен"), 0x5a90ce)
        end
        imgui.End()

    end
)

function main()
    sampRegisterChatCommand("cmd", function() WinState[0] = not WinState[0] end)
    wait(-1)
end
















function theme()
    imgui.SwitchContext()
    local ImVec4 = imgui.ImVec4
    imgui.GetStyle().WindowRounding = 10
    imgui.GetStyle().ChildRounding = 10
    imgui.GetStyle().FrameRounding = 6.0
    imgui.GetStyle().ItemSpacing = imgui.ImVec2(3.0, 3.0)
    imgui.GetStyle().ItemInnerSpacing = imgui.ImVec2(3.0, 3.0)
    imgui.GetStyle().FramePadding = imgui.ImVec2(4.0, 3.0)
    imgui.GetStyle().IndentSpacing = 21
    imgui.GetStyle().ScrollbarSize = 10.0
    imgui.GetStyle().ScrollbarRounding = 13
    imgui.GetStyle().GrabMinSize = 17.0
    imgui.GetStyle().GrabRounding = 16.0
    imgui.GetStyle().WindowTitleAlign = imgui.ImVec2(0.5, 0.5)
    imgui.GetStyle().ButtonTextAlign = imgui.ImVec2(0.5, 0.5)

    imgui.GetStyle().Colors[imgui.Col.Text]                       = ImVec4(0.95, 0.96, 0.98, 1.00);
    imgui.GetStyle().Colors[imgui.Col.TextDisabled]               = ImVec4(1.00, 0.28, 0.28, 1.00);
    imgui.GetStyle().Colors[imgui.Col.WindowBg]                   = ImVec4(0.14, 0.14, 0.14, 1.00);
    imgui.GetStyle().Colors[imgui.Col.ChildBg]                   = ImVec4(0.12, 0.12, 0.12, 0.40);
    imgui.GetStyle().Colors[imgui.Col.PopupBg]                   = ImVec4(0.08, 0.08, 0.08, 0.94);
    imgui.GetStyle().Colors[imgui.Col.Border]                      = ImVec4(0.14, 0.14, 0.14, 1.00);
    imgui.GetStyle().Colors[imgui.Col.BorderShadow]               = ImVec4(1.00, 1.00, 1.00, 0.00);
    imgui.GetStyle().Colors[imgui.Col.FrameBg]                   = ImVec4(0.22, 0.22, 0.22, 1.00);
    imgui.GetStyle().Colors[imgui.Col.FrameBgHovered]           = ImVec4(0.18, 0.18, 0.18, 1.00);
    imgui.GetStyle().Colors[imgui.Col.FrameBgActive]           = ImVec4(0.09, 0.12, 0.14, 1.00);
    imgui.GetStyle().Colors[imgui.Col.TitleBg]                   = ImVec4(0.14, 0.14, 0.14, 0.81);
    imgui.GetStyle().Colors[imgui.Col.TitleBgActive]           = ImVec4(0.14, 0.14, 0.14, 1.00);
    imgui.GetStyle().Colors[imgui.Col.TitleBgCollapsed]           = ImVec4(0.00, 0.00, 0.00, 0.51);
    imgui.GetStyle().Colors[imgui.Col.MenuBarBg]               = ImVec4(0.20, 0.20, 0.20, 1.00);
    imgui.GetStyle().Colors[imgui.Col.ScrollbarBg]               = ImVec4(0.02, 0.02, 0.02, 0.39);
    imgui.GetStyle().Colors[imgui.Col.ScrollbarGrab]           = ImVec4(0.36, 0.36, 0.36, 1.00);
    imgui.GetStyle().Colors[imgui.Col.ScrollbarGrabHovered]    = ImVec4(0.18, 0.22, 0.25, 1.00);
    imgui.GetStyle().Colors[imgui.Col.ScrollbarGrabActive]       = ImVec4(0.24, 0.24, 0.24, 1.00);
    imgui.GetStyle().Colors[imgui.Col.CheckMark]               = ImVec4(1.00, 0.28, 0.28, 1.00);
    imgui.GetStyle().Colors[imgui.Col.SliderGrab]               = ImVec4(1.00, 0.28, 0.28, 1.00);
    imgui.GetStyle().Colors[imgui.Col.SliderGrabActive]           = ImVec4(1.00, 0.28, 0.28, 1.00);
    imgui.GetStyle().Colors[imgui.Col.Button]                   = ImVec4(1.00, 0.28, 0.28, 1.00);
    imgui.GetStyle().Colors[imgui.Col.ButtonHovered]           = ImVec4(1.00, 0.39, 0.39, 1.00);
    imgui.GetStyle().Colors[imgui.Col.ButtonActive]               = ImVec4(1.00, 0.21, 0.21, 1.00);
    imgui.GetStyle().Colors[imgui.Col.Header]                   = ImVec4(1.00, 0.28, 0.28, 1.00);
    imgui.GetStyle().Colors[imgui.Col.HeaderHovered]           = ImVec4(1.00, 0.39, 0.39, 1.00);
    imgui.GetStyle().Colors[imgui.Col.HeaderActive]               = ImVec4(1.00, 0.21, 0.21, 1.00);
    imgui.GetStyle().Colors[imgui.Col.ResizeGrip]               = ImVec4(1.00, 0.28, 0.28, 1.00);
    imgui.GetStyle().Colors[imgui.Col.ResizeGripHovered]       = ImVec4(1.00, 0.39, 0.39, 1.00);
    imgui.GetStyle().Colors[imgui.Col.PlotLines]               = ImVec4(0.61, 0.61, 0.61, 1.00);
    imgui.GetStyle().Colors[imgui.Col.PlotLinesHovered]           = ImVec4(1.00, 0.43, 0.35, 1.00);
    imgui.GetStyle().Colors[imgui.Col.PlotHistogram]           = ImVec4(1.00, 0.21, 0.21, 1.00);
    imgui.GetStyle().Colors[imgui.Col.PlotHistogramHovered]    = ImVec4(1.00, 0.18, 0.18, 1.00);
    imgui.GetStyle().Colors[imgui.Col.TextSelectedBg]           = ImVec4(1.00, 0.32, 0.32, 1.00);
    imgui.GetStyle().Colors[imgui.Col.ModalWindowDimBg]        = ImVec4(0.26, 0.26, 0.26, 0.60);
end
imgui.OnInitialize(function()
    theme()
end)
 
D

deleted-user-139653

Гость
Lua:
function main()
    while true do wait(0)
        if isKeyDown(18) then
            sampToggleCursor(true)
        else
            sampToggleCursor(false)
        end
    end
end

или же вот твой код, ты вообще указал не ту клавишу

Lua:
local imgui = require "mimgui"
local sampev = require "lib.samp.events"
local vkeys = require "vkeys"

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

local new = imgui.new
local WinState = new.bool()
local checkboxnew = new.bool()

function imgui.CenterText(text)
    local width = imgui.GetWindowWidth()
    local calc = imgui.CalcTextSize(text)
    imgui.SetCursorPosX( width / 2 - calc.x / 2 )
    imgui.Text(text)
end

imgui.OnFrame(function() return WinState[0] end,
    function(player)
        player.HideCursor = true

        if isKeyDown(18) then -- левый alt
            player.HideCursor = false
        end

        imgui.SetNextWindowPos(imgui.ImVec2(0, 0), imgui.Cond.FirstUseEver, imgui.ImVec2(1, 1))
        imgui.SetNextWindowSize(imgui.ImVec2(270, 200), imgui.Cond.Always)
        imgui.Begin(u8"Ограбление - Karuso.", WinState, imgui.WindowFlags.NoResize)
        imgui.CenterText(u8"Бинды")

        imgui.Separator()

        if imgui.Checkbox(u8"Переключатель", checkboxnew) then
            sampAddChatMessage('{ffffff}Переключатель: ' .. (checkboxnew[0] and "{00ff00}выключен" or "{ff0000}включен"), 0x5a90ce)
        end
        imgui.End()

    end
)

function main()
    sampRegisterChatCommand("cmd", function() WinState[0] = not WinState[0] end)
    wait(-1)
end

function theme()
    imgui.SwitchContext()
    local ImVec4 = imgui.ImVec4
    imgui.GetStyle().WindowRounding = 10
    imgui.GetStyle().ChildRounding = 10
    imgui.GetStyle().FrameRounding = 6.0
    imgui.GetStyle().ItemSpacing = imgui.ImVec2(3.0, 3.0)
    imgui.GetStyle().ItemInnerSpacing = imgui.ImVec2(3.0, 3.0)
    imgui.GetStyle().FramePadding = imgui.ImVec2(4.0, 3.0)
    imgui.GetStyle().IndentSpacing = 21
    imgui.GetStyle().ScrollbarSize = 10.0
    imgui.GetStyle().ScrollbarRounding = 13
    imgui.GetStyle().GrabMinSize = 17.0
    imgui.GetStyle().GrabRounding = 16.0
    imgui.GetStyle().WindowTitleAlign = imgui.ImVec2(0.5, 0.5)
    imgui.GetStyle().ButtonTextAlign = imgui.ImVec2(0.5, 0.5)

    imgui.GetStyle().Colors[imgui.Col.Text]                       = ImVec4(0.95, 0.96, 0.98, 1.00);
    imgui.GetStyle().Colors[imgui.Col.TextDisabled]               = ImVec4(1.00, 0.28, 0.28, 1.00);
    imgui.GetStyle().Colors[imgui.Col.WindowBg]                   = ImVec4(0.14, 0.14, 0.14, 1.00);
    imgui.GetStyle().Colors[imgui.Col.ChildBg]                   = ImVec4(0.12, 0.12, 0.12, 0.40);
    imgui.GetStyle().Colors[imgui.Col.PopupBg]                   = ImVec4(0.08, 0.08, 0.08, 0.94);
    imgui.GetStyle().Colors[imgui.Col.Border]                      = ImVec4(0.14, 0.14, 0.14, 1.00);
    imgui.GetStyle().Colors[imgui.Col.BorderShadow]               = ImVec4(1.00, 1.00, 1.00, 0.00);
    imgui.GetStyle().Colors[imgui.Col.FrameBg]                   = ImVec4(0.22, 0.22, 0.22, 1.00);
    imgui.GetStyle().Colors[imgui.Col.FrameBgHovered]           = ImVec4(0.18, 0.18, 0.18, 1.00);
    imgui.GetStyle().Colors[imgui.Col.FrameBgActive]           = ImVec4(0.09, 0.12, 0.14, 1.00);
    imgui.GetStyle().Colors[imgui.Col.TitleBg]                   = ImVec4(0.14, 0.14, 0.14, 0.81);
    imgui.GetStyle().Colors[imgui.Col.TitleBgActive]           = ImVec4(0.14, 0.14, 0.14, 1.00);
    imgui.GetStyle().Colors[imgui.Col.TitleBgCollapsed]           = ImVec4(0.00, 0.00, 0.00, 0.51);
    imgui.GetStyle().Colors[imgui.Col.MenuBarBg]               = ImVec4(0.20, 0.20, 0.20, 1.00);
    imgui.GetStyle().Colors[imgui.Col.ScrollbarBg]               = ImVec4(0.02, 0.02, 0.02, 0.39);
    imgui.GetStyle().Colors[imgui.Col.ScrollbarGrab]           = ImVec4(0.36, 0.36, 0.36, 1.00);
    imgui.GetStyle().Colors[imgui.Col.ScrollbarGrabHovered]    = ImVec4(0.18, 0.22, 0.25, 1.00);
    imgui.GetStyle().Colors[imgui.Col.ScrollbarGrabActive]       = ImVec4(0.24, 0.24, 0.24, 1.00);
    imgui.GetStyle().Colors[imgui.Col.CheckMark]               = ImVec4(1.00, 0.28, 0.28, 1.00);
    imgui.GetStyle().Colors[imgui.Col.SliderGrab]               = ImVec4(1.00, 0.28, 0.28, 1.00);
    imgui.GetStyle().Colors[imgui.Col.SliderGrabActive]           = ImVec4(1.00, 0.28, 0.28, 1.00);
    imgui.GetStyle().Colors[imgui.Col.Button]                   = ImVec4(1.00, 0.28, 0.28, 1.00);
    imgui.GetStyle().Colors[imgui.Col.ButtonHovered]           = ImVec4(1.00, 0.39, 0.39, 1.00);
    imgui.GetStyle().Colors[imgui.Col.ButtonActive]               = ImVec4(1.00, 0.21, 0.21, 1.00);
    imgui.GetStyle().Colors[imgui.Col.Header]                   = ImVec4(1.00, 0.28, 0.28, 1.00);
    imgui.GetStyle().Colors[imgui.Col.HeaderHovered]           = ImVec4(1.00, 0.39, 0.39, 1.00);
    imgui.GetStyle().Colors[imgui.Col.HeaderActive]               = ImVec4(1.00, 0.21, 0.21, 1.00);
    imgui.GetStyle().Colors[imgui.Col.ResizeGrip]               = ImVec4(1.00, 0.28, 0.28, 1.00);
    imgui.GetStyle().Colors[imgui.Col.ResizeGripHovered]       = ImVec4(1.00, 0.39, 0.39, 1.00);
    imgui.GetStyle().Colors[imgui.Col.PlotLines]               = ImVec4(0.61, 0.61, 0.61, 1.00);
    imgui.GetStyle().Colors[imgui.Col.PlotLinesHovered]           = ImVec4(1.00, 0.43, 0.35, 1.00);
    imgui.GetStyle().Colors[imgui.Col.PlotHistogram]           = ImVec4(1.00, 0.21, 0.21, 1.00);
    imgui.GetStyle().Colors[imgui.Col.PlotHistogramHovered]    = ImVec4(1.00, 0.18, 0.18, 1.00);
    imgui.GetStyle().Colors[imgui.Col.TextSelectedBg]           = ImVec4(1.00, 0.32, 0.32, 1.00);
    imgui.GetStyle().Colors[imgui.Col.ModalWindowDimBg]        = ImVec4(0.26, 0.26, 0.26, 0.60);
end
imgui.OnInitialize(function()
    theme()
end)
 
Последнее редактирование модератором:
  • Нравится
Реакции: YarikVL и akitann