po imgui oknu

Kegwineye.

Участник
Автор темы
478
20
@ik0nka как сделать чтобы каждая кнопка по отдельности вклюлась в меню menu == 3 ?
И как сделать там например после нажатия Stats появлялось имгуи окно на экране ?

Lua:
require "lib.moonloader"
local key = require "vkeys"
local imgui = require 'imgui'
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8
local fa = require 'fAwesome5'
local themes = import "resource/imgui_themes.lua"

local main_window_state = imgui.ImBool(false)
local text_buffer = imgui.ImBuffer(256) -- Зачем тебе он тут если нету ImGui.InputText(name, buffer)
local menu = 0
local Buttonaver = imgui.ImBool(false)
local PrintNick = imgui.ImBool(false)
local PrintID = imgui.ImBool(false)
local PrintPing = imgui.ImBool(false)
local PrintHeart = imgui.ImBool(false)


function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end

    sampRegisterChatCommand("plh", cmdimgui)

    handle, id = sampGetPlayerIdByCharHandle(PLAYER_PED)
    nick = sampGetPlayerNickname(id)

    imgui.Process = false -- его можно вынести до функции при желании

  while true do
        wait(0)
        if isKeyDown(key.VK_LMENU) and isKeyJustPressed(key.VK_M) then
         main_window_state.v = not main_window_state.v
         imgui.Process = main_window_state.v
        end
        if main_window_state.v == false then
        imgui.Process = false -- зачем тебе их два?
        imgui.SwitchContext()
        themes.SwitchColorTheme(3)
    end
  end
end -- добавил ещё end который закрывает функцию маин
function cmdimgui() -- не правильный аргумент cmd_imgui заменен на cmdimgui и тут не обязательно вписывать (arg) можно обойтись и ()
     main_window_state.v = not main_window_state.v
     imgui.Process = main_window_state.v
 end

function onWindowMessage(msg, wparam, lparam)
    if msg == 0x100 or msg == 0x101 then
        if (wparam == key.VK_ESCAPE and (main_window_state.v)) and not isPauseMenuActive() and not isSampfuncsConsoleActive() then
            consumeWindowMessage(true, false)
            if msg == 0x101 then
                main_window_state.v = false
            end
        end
    end
end

function imgui.CenterTextColoredRGB(text)
    local width = imgui.GetWindowWidth()
    local style = imgui.GetStyle()
    local colors = style.Colors
    local ImVec4 = imgui.ImVec4

    local explode_argb = function(argb)
    local a = bit.band(bit.rshift(argb, 24), 0xFF)
    local r = bit.band(bit.rshift(argb, 16), 0xFF)
    local g = bit.band(bit.rshift(argb, 8), 0xFF)
    local b = bit.band(argb, 0xFF)
    return a, r, g, b
    end

    local getcolor = function(color)
    if color:sub(1, 6):upper() == 'SSSSSS' then
    local r, g, b = colors[1].x, colors[1].y, colors[1].z
    local a = tonumber(color:sub(7, 8), 16) or colors[1].w * 255
    return ImVec4(r, g, b, a / 255)
    end
    local color = type(color) == 'string' and tonumber(color, 16) or color
    if type(color) ~= 'number' then return end
    local r, g, b, a = explode_argb(color)
    return imgui.ImColor(r, g, b, a):GetVec4()
    end

    local render_text = function(text_)
    for w in text_:gmatch('[^\r\n]+') do
    local textsize = w:gsub('{.-}', '')
    local text_width = imgui.CalcTextSize(u8(textsize))
    imgui.SetCursorPosX( width / 2 - text_width .x / 2 )
    local text, colors_, m = {}, {}, 1
    w = w:gsub('{(......)}', '{%1FF}')
    while w:find('{........}') do
    local n, k = w:find('{........}')
    local color = getcolor(w:sub(n + 1, k - 1))
    if color then
    text[#text], text[#text + 1] = w:sub(m, n - 1), w:sub(k + 1, #w)
    colors_[#colors_ + 1] = color
    m = n
    end
    w = w:sub(1, n - 1) .. w:sub(k + 1, #w)
    end
    if text[0] then
    for i = 0, #text do
    imgui.TextColored(colors_[i] or colors[1], u8(text[i]))
    imgui.SameLine(nil, 0)
    end
    imgui.NewLine()
    else
    imgui.Text(u8(w))
    end
    end
    end
    render_text(text)
end

local fa_font = nil
local fa_glyph_ranges = imgui.ImGlyphRanges({ fa.min_range, fa.max_range })
function imgui.BeforeDrawFrame()
    if fa_font == nil then
        local font_config = imgui.ImFontConfig()
        font_config.MergeMode = true

        fa_font = imgui.GetIO().Fonts:AddFontFromFileTTF('moonloader/resource/fonts/fa-solid-900.ttf', 50.0, font_config, fa_glyph_ranges)
        if fontsize == nil then
        fontsize = imgui.GetIO().Fonts:AddFontFromFileTTF(getFolderPath(0x14) .. '\\trebucbd.ttf', 47.0, nil, imgui.GetIO().Fonts:GetGlyphRangesCyrillic()) -- вместо 30 любой нужный размеp
        end
    end
end

function imgui.TextColoredRGB(text)
    local style = imgui.GetStyle()
    local colors = style.Colors
    local ImVec4 = imgui.ImVec4

    local explode_argb = function(argb)
    local a = bit.band(bit.rshift(argb, 24), 0xFF)
    local r = bit.band(bit.rshift(argb, 16), 0xFF)
    local g = bit.band(bit.rshift(argb, 8), 0xFF)
    local b = bit.band(argb, 0xFF)
    return a, r, g, b
    end

    local getcolor = function(color)
    if color:sub(1, 6):upper() == 'SSSSSS' then
    local r, g, b = colors[1].x, colors[1].y, colors[1].z
    local a = tonumber(color:sub(7, 8), 16) or colors[1].w * 255
    return ImVec4(r, g, b, a / 255)
    end
    local color = type(color) == 'string' and tonumber(color, 16) or color
    if type(color) ~= 'number' then return end
    local r, g, b, a = explode_argb(color)
    return imgui.ImColor(r, g, b, a):GetVec4()
    end

    local render_text = function(text_)
    for w in text_:gmatch('[^\r\n]+') do
    local text, colors_, m = {}, {}, 1
    w = w:gsub('{(......)}', '{%1FF}')
    while w:find('{........}') do
    local n, k = w:find('{........}')
    local color = getcolor(w:sub(n + 1, k - 1))
    if color then
    text[#text], text[#text + 1] = w:sub(m, n - 1), w:sub(k + 1, #w)
    colors_[#colors_ + 1] = color
    m = n
    end
    w = w:sub(1, n - 1) .. w:sub(k + 1, #w)
    end
    if text[0] then
    for i = 0, #text do
    imgui.TextColored(colors_[i] or colors[1], u8(text[i]))
    imgui.SameLine(nil, 0)
    end
    imgui.NewLine()
    else imgui.Text(u8(w)) end
    end
    end
    render_text(text)
end

function imgui.SelectButton(name, bool, size)
    if Buttonaver.v then
        imgui.PushStyleColor(imgui.Col.Button, imgui.ImVec4(0.0, 0.6, 0.0, 0.40))
        imgui.PushStyleColor(imgui.Col.ButtonHovered, imgui.ImVec4(0.0, 0.8, 0.0, 1.0))
        imgui.PushStyleColor(imgui.Col.ButtonActive, imgui.ImVec4(0.0, 1.0, 0.0, 1.0))
    else
        imgui.PushStyleColor(imgui.Col.Button, imgui.ImVec4(0.6, 0.0, 0.0, 0.40))
        imgui.PushStyleColor(imgui.Col.ButtonHovered, imgui.ImVec4(0.8, 0.0, 0.0, 1.0))
        imgui.PushStyleColor(imgui.Col.ButtonActive, imgui.ImVec4(1.0, 0.0, 0.0, 1.0))
    end
    if not size then size = imgui.ImVec2(0, 0) end
    local result = imgui.Button(name, size)
    imgui.PopStyleColor(3)
    if result then Buttonaver.v = not Buttonaver.v end
    return result
end

function imgui.OnDrawFrame() -- не Flame а Frame!!
  local sw, sh = getScreenResolution()
        imgui.SetNextWindowPos(imgui.ImVec2(sw / 2, sh / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
        imgui.SetNextWindowSize(imgui.ImVec2(900, 535))
        imgui.Begin('##localwindow',  main_window_state, imgui.WindowFlags.AlwaysAutoResize + imgui.WindowFlags.NoCollapse + imgui.WindowFlags.NoTitleBar + imgui.WindowFlags.NoMove)
     imgui.NewLine()
     imgui.SetCursorPosY(0)
     imgui.NewLine()
     imgui.NewLine()
     imgui.NewLine()
     imgui.Text(fa.ICON_FA_USER_SHIELD .. "")
     imgui.SameLine()
     imgui.SetCursorPosY(20)
     imgui.PushFont(fontsize)
     imgui.TextColoredRGB("{0000CB}POLICE HELPER")
     imgui.PopFont()
     imgui.NewLine()
if menu == 0 then
        imgui.BeginChild('##localchild', imgui.ImVec2(890, 432), true)
        if imgui.Button(u8"Основное", imgui.ImVec2(291, 210)) then
            menu = 2 end
        imgui.SameLine()
        if imgui.Button(fa.ICON_FA_COG .. u8"Настройки", imgui.ImVec2(291, 210)) then
            menu = 3 end
        imgui.SameLine()
        if imgui.Button(u8"Донат", imgui.ImVec2(291, 210)) then
            menu = 4 end
        if imgui.Button(u8"Новости", imgui.ImVec2(291, 210)) then
            menu = 5 end
        imgui.SameLine()
        if imgui.Button(u8"Биндер", imgui.ImVec2(291, 210)) then
            menu = 6 end
        imgui.SameLine()
        if imgui.Button(u8"Мульти-настройки", imgui.ImVec2(291, 210)) then
            menu = 7 end
        imgui.EndChild()
    end
    if menu == 2 then
        imgui.BeginChild("", imgui.ImVec2(890, 402), true)
          imgui.Text("test")
          imgui.EndChild()
          if imgui.Button(u8"< Назад", imgui.ImVec2(100, 30)) then
          menu = 0
        end
    end
        if menu == 3 then
        imgui.BeginChild("", imgui.ImVec2(890, 402), true)
        if imgui.SelectButton('Stats', PrintNick, imgui.ImVec2(100, 30)) then end
          if imgui.SelectButton('Nick', PrintNick, imgui.ImVec2(100, 30)) then end
          if imgui.SelectButton('ID', PrintID, imgui.ImVec2(100, 30)) then end
          if imgui.SelectButton('Ping', PrintPing, imgui.ImVec2(100, 30)) then end
          if imgui.SelectButton('Heart', PrintHeart, imgui.ImVec2(100, 30)) then end
          imgui.EndChild()
          if imgui.Button(u8"< Назад", imgui.ImVec2(100, 30)) then
          menu = 0
        end
    end
        if menu == 4 then
        imgui.BeginChild("", imgui.ImVec2(890, 402), true)
          imgui.Text("test")
          imgui.EndChild()
          if imgui.Button(u8"< Назад", imgui.ImVec2(100, 30)) then
          menu = 0
        end
    end
        if menu == 5 then
        imgui.BeginChild("", imgui.ImVec2(890, 402), true)
          imgui.EndChild()
          if imgui.Button(u8"< Назад", imgui.ImVec2(100, 30)) then
          menu = 0
        end
    end
        if menu == 6 then
        imgui.BeginChild("", imgui.ImVec2(890, 402), true)
          imgui.Text("test")
          imgui.EndChild()
          if imgui.Button(u8"< Назад", imgui.ImVec2(100, 30)) then
          menu = 0
        end
    end
        if menu == 7 then
        imgui.BeginChild("", imgui.ImVec2(890, 402), true)
          imgui.Text("test")
          imgui.EndChild()
          if imgui.Button(u8"< Назад", imgui.ImVec2(100, 30)) then
          menu = 0
        end
    end
    imgui.End()
end
-- end он тут не нужен
 
Решение
@ik0nka как сделать чтобы каждая кнопка по отдельности вклюлась в меню menu == 3 ?
И как сделать там например после нажатия Stats появлялось имгуи окно на экране ?

Lua:
require "lib.moonloader"
local key = require "vkeys"
local imgui = require 'imgui'
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8
local fa = require 'fAwesome5'
local themes = import "resource/imgui_themes.lua"

local main_window_state = imgui.ImBool(false)
local text_buffer = imgui.ImBuffer(256) -- Зачем тебе он тут если нету ImGui.InputText(name, buffer)
local menu = 0
local Buttonaver = imgui.ImBool(false)
local PrintNick = imgui.ImBool(false)
local PrintID = imgui.ImBool(false)
local PrintPing = imgui.ImBool(false)
local...

ik0nka

Известный
750
342
@ik0nka как сделать чтобы каждая кнопка по отдельности вклюлась в меню menu == 3 ?
И как сделать там например после нажатия Stats появлялось имгуи окно на экране ?

Lua:
require "lib.moonloader"
local key = require "vkeys"
local imgui = require 'imgui'
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8
local fa = require 'fAwesome5'
local themes = import "resource/imgui_themes.lua"

local main_window_state = imgui.ImBool(false)
local text_buffer = imgui.ImBuffer(256) -- Зачем тебе он тут если нету ImGui.InputText(name, buffer)
local menu = 0
local Buttonaver = imgui.ImBool(false)
local PrintNick = imgui.ImBool(false)
local PrintID = imgui.ImBool(false)
local PrintPing = imgui.ImBool(false)
local PrintHeart = imgui.ImBool(false)


function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end

    sampRegisterChatCommand("plh", cmdimgui)

    handle, id = sampGetPlayerIdByCharHandle(PLAYER_PED)
    nick = sampGetPlayerNickname(id)

    imgui.Process = false -- его можно вынести до функции при желании

  while true do
        wait(0)
        if isKeyDown(key.VK_LMENU) and isKeyJustPressed(key.VK_M) then
         main_window_state.v = not main_window_state.v
         imgui.Process = main_window_state.v
        end
        if main_window_state.v == false then
        imgui.Process = false -- зачем тебе их два?
        imgui.SwitchContext()
        themes.SwitchColorTheme(3)
    end
  end
end -- добавил ещё end который закрывает функцию маин
function cmdimgui() -- не правильный аргумент cmd_imgui заменен на cmdimgui и тут не обязательно вписывать (arg) можно обойтись и ()
     main_window_state.v = not main_window_state.v
     imgui.Process = main_window_state.v
 end

function onWindowMessage(msg, wparam, lparam)
    if msg == 0x100 or msg == 0x101 then
        if (wparam == key.VK_ESCAPE and (main_window_state.v)) and not isPauseMenuActive() and not isSampfuncsConsoleActive() then
            consumeWindowMessage(true, false)
            if msg == 0x101 then
                main_window_state.v = false
            end
        end
    end
end

function imgui.CenterTextColoredRGB(text)
    local width = imgui.GetWindowWidth()
    local style = imgui.GetStyle()
    local colors = style.Colors
    local ImVec4 = imgui.ImVec4

    local explode_argb = function(argb)
    local a = bit.band(bit.rshift(argb, 24), 0xFF)
    local r = bit.band(bit.rshift(argb, 16), 0xFF)
    local g = bit.band(bit.rshift(argb, 8), 0xFF)
    local b = bit.band(argb, 0xFF)
    return a, r, g, b
    end

    local getcolor = function(color)
    if color:sub(1, 6):upper() == 'SSSSSS' then
    local r, g, b = colors[1].x, colors[1].y, colors[1].z
    local a = tonumber(color:sub(7, 8), 16) or colors[1].w * 255
    return ImVec4(r, g, b, a / 255)
    end
    local color = type(color) == 'string' and tonumber(color, 16) or color
    if type(color) ~= 'number' then return end
    local r, g, b, a = explode_argb(color)
    return imgui.ImColor(r, g, b, a):GetVec4()
    end

    local render_text = function(text_)
    for w in text_:gmatch('[^\r\n]+') do
    local textsize = w:gsub('{.-}', '')
    local text_width = imgui.CalcTextSize(u8(textsize))
    imgui.SetCursorPosX( width / 2 - text_width .x / 2 )
    local text, colors_, m = {}, {}, 1
    w = w:gsub('{(......)}', '{%1FF}')
    while w:find('{........}') do
    local n, k = w:find('{........}')
    local color = getcolor(w:sub(n + 1, k - 1))
    if color then
    text[#text], text[#text + 1] = w:sub(m, n - 1), w:sub(k + 1, #w)
    colors_[#colors_ + 1] = color
    m = n
    end
    w = w:sub(1, n - 1) .. w:sub(k + 1, #w)
    end
    if text[0] then
    for i = 0, #text do
    imgui.TextColored(colors_[i] or colors[1], u8(text[i]))
    imgui.SameLine(nil, 0)
    end
    imgui.NewLine()
    else
    imgui.Text(u8(w))
    end
    end
    end
    render_text(text)
end

local fa_font = nil
local fa_glyph_ranges = imgui.ImGlyphRanges({ fa.min_range, fa.max_range })
function imgui.BeforeDrawFrame()
    if fa_font == nil then
        local font_config = imgui.ImFontConfig()
        font_config.MergeMode = true

        fa_font = imgui.GetIO().Fonts:AddFontFromFileTTF('moonloader/resource/fonts/fa-solid-900.ttf', 50.0, font_config, fa_glyph_ranges)
        if fontsize == nil then
        fontsize = imgui.GetIO().Fonts:AddFontFromFileTTF(getFolderPath(0x14) .. '\\trebucbd.ttf', 47.0, nil, imgui.GetIO().Fonts:GetGlyphRangesCyrillic()) -- вместо 30 любой нужный размеp
        end
    end
end

function imgui.TextColoredRGB(text)
    local style = imgui.GetStyle()
    local colors = style.Colors
    local ImVec4 = imgui.ImVec4

    local explode_argb = function(argb)
    local a = bit.band(bit.rshift(argb, 24), 0xFF)
    local r = bit.band(bit.rshift(argb, 16), 0xFF)
    local g = bit.band(bit.rshift(argb, 8), 0xFF)
    local b = bit.band(argb, 0xFF)
    return a, r, g, b
    end

    local getcolor = function(color)
    if color:sub(1, 6):upper() == 'SSSSSS' then
    local r, g, b = colors[1].x, colors[1].y, colors[1].z
    local a = tonumber(color:sub(7, 8), 16) or colors[1].w * 255
    return ImVec4(r, g, b, a / 255)
    end
    local color = type(color) == 'string' and tonumber(color, 16) or color
    if type(color) ~= 'number' then return end
    local r, g, b, a = explode_argb(color)
    return imgui.ImColor(r, g, b, a):GetVec4()
    end

    local render_text = function(text_)
    for w in text_:gmatch('[^\r\n]+') do
    local text, colors_, m = {}, {}, 1
    w = w:gsub('{(......)}', '{%1FF}')
    while w:find('{........}') do
    local n, k = w:find('{........}')
    local color = getcolor(w:sub(n + 1, k - 1))
    if color then
    text[#text], text[#text + 1] = w:sub(m, n - 1), w:sub(k + 1, #w)
    colors_[#colors_ + 1] = color
    m = n
    end
    w = w:sub(1, n - 1) .. w:sub(k + 1, #w)
    end
    if text[0] then
    for i = 0, #text do
    imgui.TextColored(colors_[i] or colors[1], u8(text[i]))
    imgui.SameLine(nil, 0)
    end
    imgui.NewLine()
    else imgui.Text(u8(w)) end
    end
    end
    render_text(text)
end

function imgui.SelectButton(name, bool, size)
    if Buttonaver.v then
        imgui.PushStyleColor(imgui.Col.Button, imgui.ImVec4(0.0, 0.6, 0.0, 0.40))
        imgui.PushStyleColor(imgui.Col.ButtonHovered, imgui.ImVec4(0.0, 0.8, 0.0, 1.0))
        imgui.PushStyleColor(imgui.Col.ButtonActive, imgui.ImVec4(0.0, 1.0, 0.0, 1.0))
    else
        imgui.PushStyleColor(imgui.Col.Button, imgui.ImVec4(0.6, 0.0, 0.0, 0.40))
        imgui.PushStyleColor(imgui.Col.ButtonHovered, imgui.ImVec4(0.8, 0.0, 0.0, 1.0))
        imgui.PushStyleColor(imgui.Col.ButtonActive, imgui.ImVec4(1.0, 0.0, 0.0, 1.0))
    end
    if not size then size = imgui.ImVec2(0, 0) end
    local result = imgui.Button(name, size)
    imgui.PopStyleColor(3)
    if result then Buttonaver.v = not Buttonaver.v end
    return result
end

function imgui.OnDrawFrame() -- не Flame а Frame!!
  local sw, sh = getScreenResolution()
        imgui.SetNextWindowPos(imgui.ImVec2(sw / 2, sh / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
        imgui.SetNextWindowSize(imgui.ImVec2(900, 535))
        imgui.Begin('##localwindow',  main_window_state, imgui.WindowFlags.AlwaysAutoResize + imgui.WindowFlags.NoCollapse + imgui.WindowFlags.NoTitleBar + imgui.WindowFlags.NoMove)
     imgui.NewLine()
     imgui.SetCursorPosY(0)
     imgui.NewLine()
     imgui.NewLine()
     imgui.NewLine()
     imgui.Text(fa.ICON_FA_USER_SHIELD .. "")
     imgui.SameLine()
     imgui.SetCursorPosY(20)
     imgui.PushFont(fontsize)
     imgui.TextColoredRGB("{0000CB}POLICE HELPER")
     imgui.PopFont()
     imgui.NewLine()
if menu == 0 then
        imgui.BeginChild('##localchild', imgui.ImVec2(890, 432), true)
        if imgui.Button(u8"Основное", imgui.ImVec2(291, 210)) then
            menu = 2 end
        imgui.SameLine()
        if imgui.Button(fa.ICON_FA_COG .. u8"Настройки", imgui.ImVec2(291, 210)) then
            menu = 3 end
        imgui.SameLine()
        if imgui.Button(u8"Донат", imgui.ImVec2(291, 210)) then
            menu = 4 end
        if imgui.Button(u8"Новости", imgui.ImVec2(291, 210)) then
            menu = 5 end
        imgui.SameLine()
        if imgui.Button(u8"Биндер", imgui.ImVec2(291, 210)) then
            menu = 6 end
        imgui.SameLine()
        if imgui.Button(u8"Мульти-настройки", imgui.ImVec2(291, 210)) then
            menu = 7 end
        imgui.EndChild()
    end
    if menu == 2 then
        imgui.BeginChild("", imgui.ImVec2(890, 402), true)
          imgui.Text("test")
          imgui.EndChild()
          if imgui.Button(u8"< Назад", imgui.ImVec2(100, 30)) then
          menu = 0
        end
    end
        if menu == 3 then
        imgui.BeginChild("", imgui.ImVec2(890, 402), true)
        if imgui.SelectButton('Stats', PrintNick, imgui.ImVec2(100, 30)) then end
          if imgui.SelectButton('Nick', PrintNick, imgui.ImVec2(100, 30)) then end
          if imgui.SelectButton('ID', PrintID, imgui.ImVec2(100, 30)) then end
          if imgui.SelectButton('Ping', PrintPing, imgui.ImVec2(100, 30)) then end
          if imgui.SelectButton('Heart', PrintHeart, imgui.ImVec2(100, 30)) then end
          imgui.EndChild()
          if imgui.Button(u8"< Назад", imgui.ImVec2(100, 30)) then
          menu = 0
        end
    end
        if menu == 4 then
        imgui.BeginChild("", imgui.ImVec2(890, 402), true)
          imgui.Text("test")
          imgui.EndChild()
          if imgui.Button(u8"< Назад", imgui.ImVec2(100, 30)) then
          menu = 0
        end
    end
        if menu == 5 then
        imgui.BeginChild("", imgui.ImVec2(890, 402), true)
          imgui.EndChild()
          if imgui.Button(u8"< Назад", imgui.ImVec2(100, 30)) then
          menu = 0
        end
    end
        if menu == 6 then
        imgui.BeginChild("", imgui.ImVec2(890, 402), true)
          imgui.Text("test")
          imgui.EndChild()
          if imgui.Button(u8"< Назад", imgui.ImVec2(100, 30)) then
          menu = 0
        end
    end
        if menu == 7 then
        imgui.BeginChild("", imgui.ImVec2(890, 402), true)
          imgui.Text("test")
          imgui.EndChild()
          if imgui.Button(u8"< Назад", imgui.ImVec2(100, 30)) then
          menu = 0
        end
    end
    imgui.End()
end
-- end он тут не нужен
По первому вопросу я нихуя не понял
По второму -

Вообще, посмотри его уроки по имуги. А потом если что-то непонятно спрашивай.
 
  • Нравится
Реакции: Kegwineye.

Kegwineye.

Участник
Автор темы
478
20
По первому вопросу я нихуя не понял
По второму -

Вообще, посмотри его уроки по имуги. А потом если что-то непонятно спрашивай.
что не так? перепробывал даже всунуть из тем на бх.


Lua:
require "lib.moonloader"
local key = require "vkeys"
local imgui = require 'imgui'
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8
local fa = require 'fAwesome5'
local themes = import "resource/imgui_themes.lua"

local main_window_state = imgui.ImBool(false)
local window_state = imgui.ImBool(false)
local text_buffer = imgui.ImBuffer(256) -- Зачем тебе он тут если нету ImGui.InputText(name, buffer)
local menu = 0
local Buttonaver = imgui.ImBool(false)
local PrintNick = imgui.ImBool(false)
local PrintID = imgui.ImBool(false)
local PrintPing = imgui.ImBool(false)
local PrintHeart = imgui.ImBool(false)


function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end

    sampRegisterChatCommand("plh", cmdimgui)

    handle, id = sampGetPlayerIdByCharHandle(PLAYER_PED)
    nick = sampGetPlayerNickname(id)

    imgui.Process = false -- его можно вынести до функции при желании

  while true do
        wait(0)
        if isKeyDown(key.VK_LMENU) and isKeyJustPressed(key.VK_M) then
         main_window_state.v = not main_window_state.v
         imgui.Process = main_window_state.v
        end
        if main_window_state.v == false then
        imgui.Process = false -- зачем тебе их два?
        imgui.SwitchContext()
        themes.SwitchColorTheme(3)
    end
  end
end -- добавил ещё end который закрывает функцию маин
function cmdimgui() -- не правильный аргумент cmd_imgui заменен на cmdimgui и тут не обязательно вписывать (arg) можно обойтись и ()
     main_window_state.v = not main_window_state.v
     imgui.Process = main_window_state.v
 end

function onWindowMessage(msg, wparam, lparam)
    if msg == 0x100 or msg == 0x101 then
        if (wparam == key.VK_ESCAPE and (main_window_state.v)) and not isPauseMenuActive() and not isSampfuncsConsoleActive() then
            consumeWindowMessage(true, false)
            if msg == 0x101 then
                main_window_state.v = false
            end
        end
    end
end

function imgui.CenterTextColoredRGB(text)
    local width = imgui.GetWindowWidth()
    local style = imgui.GetStyle()
    local colors = style.Colors
    local ImVec4 = imgui.ImVec4

    local explode_argb = function(argb)
    local a = bit.band(bit.rshift(argb, 24), 0xFF)
    local r = bit.band(bit.rshift(argb, 16), 0xFF)
    local g = bit.band(bit.rshift(argb, 8), 0xFF)
    local b = bit.band(argb, 0xFF)
    return a, r, g, b
    end

    local getcolor = function(color)
    if color:sub(1, 6):upper() == 'SSSSSS' then
    local r, g, b = colors[1].x, colors[1].y, colors[1].z
    local a = tonumber(color:sub(7, 8), 16) or colors[1].w * 255
    return ImVec4(r, g, b, a / 255)
    end
    local color = type(color) == 'string' and tonumber(color, 16) or color
    if type(color) ~= 'number' then return end
    local r, g, b, a = explode_argb(color)
    return imgui.ImColor(r, g, b, a):GetVec4()
    end

    local render_text = function(text_)
    for w in text_:gmatch('[^\r\n]+') do
    local textsize = w:gsub('{.-}', '')
    local text_width = imgui.CalcTextSize(u8(textsize))
    imgui.SetCursorPosX( width / 2 - text_width .x / 2 )
    local text, colors_, m = {}, {}, 1
    w = w:gsub('{(......)}', '{%1FF}')
    while w:find('{........}') do
    local n, k = w:find('{........}')
    local color = getcolor(w:sub(n + 1, k - 1))
    if color then
    text[#text], text[#text + 1] = w:sub(m, n - 1), w:sub(k + 1, #w)
    colors_[#colors_ + 1] = color
    m = n
    end
    w = w:sub(1, n - 1) .. w:sub(k + 1, #w)
    end
    if text[0] then
    for i = 0, #text do
    imgui.TextColored(colors_[i] or colors[1], u8(text[i]))
    imgui.SameLine(nil, 0)
    end
    imgui.NewLine()
    else
    imgui.Text(u8(w))
    end
    end
    end
    render_text(text)
end

local fa_font = nil
local fa_glyph_ranges = imgui.ImGlyphRanges({ fa.min_range, fa.max_range })
function imgui.BeforeDrawFrame()
    if fa_font == nil then
        local font_config = imgui.ImFontConfig()
        font_config.MergeMode = true

        fa_font = imgui.GetIO().Fonts:AddFontFromFileTTF('moonloader/resource/fonts/fa-solid-900.ttf', 50.0, font_config, fa_glyph_ranges)
        if fontsize == nil then
        fontsize = imgui.GetIO().Fonts:AddFontFromFileTTF(getFolderPath(0x14) .. '\\trebucbd.ttf', 47.0, nil, imgui.GetIO().Fonts:GetGlyphRangesCyrillic()) -- вместо 30 любой нужный размеp
        end
    end
end

function imgui.TextColoredRGB(text)
    local style = imgui.GetStyle()
    local colors = style.Colors
    local ImVec4 = imgui.ImVec4

    local explode_argb = function(argb)
    local a = bit.band(bit.rshift(argb, 24), 0xFF)
    local r = bit.band(bit.rshift(argb, 16), 0xFF)
    local g = bit.band(bit.rshift(argb, 8), 0xFF)
    local b = bit.band(argb, 0xFF)
    return a, r, g, b
    end

    local getcolor = function(color)
    if color:sub(1, 6):upper() == 'SSSSSS' then
    local r, g, b = colors[1].x, colors[1].y, colors[1].z
    local a = tonumber(color:sub(7, 8), 16) or colors[1].w * 255
    return ImVec4(r, g, b, a / 255)
    end
    local color = type(color) == 'string' and tonumber(color, 16) or color
    if type(color) ~= 'number' then return end
    local r, g, b, a = explode_argb(color)
    return imgui.ImColor(r, g, b, a):GetVec4()
    end

    local render_text = function(text_)
    for w in text_:gmatch('[^\r\n]+') do
    local text, colors_, m = {}, {}, 1
    w = w:gsub('{(......)}', '{%1FF}')
    while w:find('{........}') do
    local n, k = w:find('{........}')
    local color = getcolor(w:sub(n + 1, k - 1))
    if color then
    text[#text], text[#text + 1] = w:sub(m, n - 1), w:sub(k + 1, #w)
    colors_[#colors_ + 1] = color
    m = n
    end
    w = w:sub(1, n - 1) .. w:sub(k + 1, #w)
    end
    if text[0] then
    for i = 0, #text do
    imgui.TextColored(colors_[i] or colors[1], u8(text[i]))
    imgui.SameLine(nil, 0)
    end
    imgui.NewLine()
    else imgui.Text(u8(w)) end
    end
    end
    render_text(text)
end

function imgui.SelectButton(name, bool, size)
    if Buttonaver.v then
        imgui.PushStyleColor(imgui.Col.Button, imgui.ImVec4(0.0, 0.6, 0.0, 0.40))
        imgui.PushStyleColor(imgui.Col.ButtonHovered, imgui.ImVec4(0.0, 0.8, 0.0, 1.0))
        imgui.PushStyleColor(imgui.Col.ButtonActive, imgui.ImVec4(0.0, 1.0, 0.0, 1.0))
    else
        imgui.PushStyleColor(imgui.Col.Button, imgui.ImVec4(0.6, 0.0, 0.0, 0.40))
        imgui.PushStyleColor(imgui.Col.ButtonHovered, imgui.ImVec4(0.8, 0.0, 0.0, 1.0))
        imgui.PushStyleColor(imgui.Col.ButtonActive, imgui.ImVec4(1.0, 0.0, 0.0, 1.0))
    end
    if not size then size = imgui.ImVec2(0, 0) end
    local result = imgui.Button(name, size)
    imgui.PopStyleColor(3)
    if result then Buttonaver.v = not Buttonaver.v end
    return result
end

function imgui.OnDrawFrame() -- не Flame а Frame!!
  if main_window_state.v then
  local sw, sh = getScreenResolution()
        imgui.SetNextWindowPos(imgui.ImVec2(sw / 2, sh / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
        imgui.SetNextWindowSize(imgui.ImVec2(900, 535))
        imgui.Begin('##localwindow',  main_window_state, imgui.WindowFlags.AlwaysAutoResize + imgui.WindowFlags.NoCollapse + imgui.WindowFlags.NoTitleBar + imgui.WindowFlags.NoMove)
     imgui.NewLine()
     imgui.SetCursorPosY(0)
     imgui.NewLine()
     imgui.NewLine()
     imgui.NewLine()
     imgui.Text(fa.ICON_FA_USER_SHIELD .. "")
     imgui.SameLine()
     imgui.SetCursorPosY(20)
     imgui.PushFont(fontsize)
     imgui.TextColoredRGB("{0000CB}POLICE HELPER")
     imgui.PopFont()
     imgui.NewLine()
if menu == 0 then
        imgui.BeginChild('##localchild', imgui.ImVec2(890, 432), true)
        if imgui.Button(u8"Основное", imgui.ImVec2(291, 210)) then
            menu = 2 end
        imgui.SameLine()
        if imgui.Button(fa.ICON_FA_COG .. u8"Настройки", imgui.ImVec2(291, 210)) then
            menu = 3 end
        imgui.SameLine()
        if imgui.Button(u8"Донат", imgui.ImVec2(291, 210)) then
            menu = 4 end
        if imgui.Button(u8"Новости", imgui.ImVec2(291, 210)) then
            menu = 5 end
        imgui.SameLine()
        if imgui.Button(u8"Биндер", imgui.ImVec2(291, 210)) then
            menu = 6 end
        imgui.SameLine()
        if imgui.Button(u8"Мульти-настройки", imgui.ImVec2(291, 210)) then
            menu = 7 end
        imgui.EndChild()
    end
    if menu == 2 then
        imgui.BeginChild("", imgui.ImVec2(890, 402), true)
          imgui.Text("test")
          imgui.EndChild()
          if imgui.Button(u8"< Назад", imgui.ImVec2(100, 30)) then
          menu = 0
        end
    end
        if menu == 3 then
        imgui.BeginChild("", imgui.ImVec2(890, 402), true)
        if imgui.Button(u8'Вкл/Выкл Статистику') then window_state.v = not window_state.v end
          if imgui.Checkbox('Nick', PrintNick) then end
          if imgui.Checkbox('ID', PrintID) then end
          if imgui.Checkbox('Ping', PrintPing) then end
          if imgui.Checkbox('Heart', PrintHeart) then end
          imgui.EndChild()
          if imgui.Button(u8"< Назад", imgui.ImVec2(100, 30)) then
          menu = 0
        end
    end
        if menu == 4 then
        imgui.BeginChild("", imgui.ImVec2(890, 402), true)
          imgui.Text("test")
          imgui.EndChild()
          if imgui.Button(u8"< Назад", imgui.ImVec2(100, 30)) then
          menu = 0
        end
    end
        if menu == 5 then
        imgui.BeginChild("", imgui.ImVec2(890, 402), true)
          imgui.EndChild()
          if imgui.Button(u8"< Назад", imgui.ImVec2(100, 30)) then
          menu = 0
        end
    end
        if menu == 6 then
        imgui.BeginChild("", imgui.ImVec2(890, 402), true)
          imgui.Text("test")
          imgui.EndChild()
          if imgui.Button(u8"< Назад", imgui.ImVec2(100, 30)) then
          menu = 0
        end
    end
        if menu == 7 then
        imgui.BeginChild("", imgui.ImVec2(890, 402), true)
          imgui.Text("test")
          imgui.EndChild()
          if imgui.Button(u8"< Назад", imgui.ImVec2(100, 30)) then
          menu = 0
            end
        end
    end
    imgui.End()
end
if window_state.v then
        imgui.Begin('Another window', another)
            imgui.Text('This is another window')
        imgui.End()
end
-- end он тут не нужен
 

Kegwineye.

Участник
Автор темы
478
20
как сделать так чтобы при включении чекбокса это появлялось в новом окне ?

и как сделать так чтобы при открытом первом меню была активна курсор, а при закрытом и открытом ток втором был убран ?
ты проверку на 2 окно делаешь не в imgui.OnDrawFrame()

Lua:
require "lib.moonloader"
local key = require "vkeys"
local imgui = require 'imgui'
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8
local fa = require 'fAwesome5'
local themes = import "resource/imgui_themes.lua"

local main_window_state = imgui.ImBool(false)
local window_state = imgui.ImBool(false)
local text_buffer = imgui.ImBuffer(256) -- Зачем тебе он тут если нету ImGui.InputText(name, buffer)
local menu = 0
local Buttonaver = imgui.ImBool(false)
local PrintNick = imgui.ImBool(false)
local PrintID = imgui.ImBool(false)
local PrintPing = imgui.ImBool(false)
local PrintHeart = imgui.ImBool(false)


function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end

    sampRegisterChatCommand("plh", function()
        main_window_state.v = not main_window_state.v
    end)
    sampRegisterChatCommand("plh2", function()
        window_state.v = not window_state.v
    end)

    imgui.SwitchContext()
    themes.SwitchColorTheme(1)

    handle, id = sampGetPlayerIdByCharHandle(PLAYER_PED)
    nick = sampGetPlayerNickname(id)

  while true do wait(0)
        if isKeyDown(key.VK_LMENU) and isKeyJustPressed(key.VK_M) then
            main_window_state.v = not main_window_state.v
        end

        imgui.Process = main_window_state.v or window_state.v

  end
end



function imgui.OnDrawFrame() -- не Flame а Frame!!
    if main_window_state.v then
        local sw, sh = getScreenResolution()
        imgui.SetNextWindowPos(imgui.ImVec2(sw / 2, sh / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
        imgui.SetNextWindowSize(imgui.ImVec2(900, 535))
        imgui.Begin('##localwindow',  main_window_state, imgui.WindowFlags.AlwaysAutoResize + imgui.WindowFlags.NoCollapse + imgui.WindowFlags.NoTitleBar + imgui.WindowFlags.NoMove)
        imgui.NewLine()
        imgui.SetCursorPosY(0)
        imgui.NewLine()
        imgui.NewLine()
        imgui.NewLine()
        imgui.Text(fa.ICON_FA_USER_SHIELD .. "")
        imgui.SameLine()
        imgui.SetCursorPosY(20)
        imgui.PushFont(fontsize)
        imgui.TextColoredRGB("{0000CB}POLICE HELPER")
        imgui.PopFont()
        imgui.NewLine()
        if menu == 0 then
            imgui.BeginChild('##localchild', imgui.ImVec2(890, 432), true)
            if imgui.Button(fa.ICON_FA_FOLDER .. u8"Основное", imgui.ImVec2(291, 210)) then menu = 2 end
            imgui.SameLine()
            if imgui.Button(fa.ICON_FA_COG .. u8"Настройки", imgui.ImVec2(291, 210)) then menu = 3 end
            imgui.SameLine()
            if imgui.Button(fa.ICON_FA_COINS .. u8"Пожертвования", imgui.ImVec2(291, 210)) then menu = 4 end
            if imgui.Button(fa.ICON_FA_NEWSPAPER .. u8"Новости", imgui.ImVec2(291, 210)) then menu = 5 end
            imgui.SameLine()
            if imgui.Button(fa.ICON_FA_KEYBOARD .. u8"Биндер", imgui.ImVec2(291, 210)) then menu = 6 end
            imgui.SameLine()
            if imgui.Button(fa.ICON_FA_TOOLS .. u8"Мульти-настройки", imgui.ImVec2(291, 210)) then menu = 7 end
            imgui.EndChild()
        end
        if menu == 2 then
            imgui.BeginChild("", imgui.ImVec2(890, 402), true)
            imgui.Text("test")
            imgui.EndChild()
            if imgui.Button(u8"< Назад", imgui.ImVec2(100, 30)) then menu = 0 end
        end
        if menu == 3 then
            imgui.BeginChild("", imgui.ImVec2(890, 402), true)
            if imgui.Button(u8'Вкл/Выкл Статистику') then window_state.v = not window_state.v end
            if imgui.Checkbox('Nick', PrintNick) then end
            if imgui.Checkbox('ID', PrintID) then end
            if imgui.Checkbox('Ping', PrintPing) then end
            if imgui.Checkbox('Heart', PrintHeart) then end
            imgui.EndChild()
            if imgui.Button(u8"< Назад", imgui.ImVec2(100, 30)) then menu = 0 end
        end

        if menu == 4 then
            imgui.BeginChild("", imgui.ImVec2(890, 402), true)
            imgui.Text("test")
            imgui.EndChild()
            if imgui.Button(u8"< Назад", imgui.ImVec2(100, 30)) then menu = 0 end
        end
        if menu == 5 then
            imgui.BeginChild("", imgui.ImVec2(890, 402), true)
            imgui.Text("Релиз скрипта - версия 1.0!")
            imgui.EndChild()
            if imgui.Button(u8"< Назад", imgui.ImVec2(100, 30)) then menu = 0 end
        end

        if menu == 6 then
            imgui.BeginChild("", imgui.ImVec2(890, 402), true)
            imgui.Text("test")
            imgui.EndChild()
            if imgui.Button(u8"< Назад", imgui.ImVec2(100, 30)) then menu = 0 end
        end

        if menu == 7 then
            imgui.BeginChild("", imgui.ImVec2(890, 402), true)
            imgui.Text(u8"Сменить цвет:")
            if  imgui.Button(u8"Ярко-Фиолетовый") then
                themes.SwitchColorTheme(1)
            end
            if  imgui.Button(u8"Тёмно-Фиолетовый") then
                themes.SwitchColorTheme(2)
            end
            if  imgui.Button(u8"Тёмно-Берюзовый") then
                themes.SwitchColorTheme(6)
            end
            if  imgui.Button(u8"Серый") then
                themes.SwitchColorTheme(5)
            end
            imgui.EndChild()
            if imgui.Button(u8"< Назад", imgui.ImVec2(100, 30)) then menu = 0 end
        end
        imgui.End()
    end
    if window_state.v then
        local sw, sh = getScreenResolution()
        imgui.SetNextWindowPos(imgui.ImVec2(sw / 1.09, sh / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
        imgui.SetNextWindowSize(imgui.ImVec2(260, 235))
        imgui.Begin('Your Statistic', window_state, imgui.WindowFlags.AlwaysAutoResize + imgui.WindowFlags.NoCollapse + imgui.WindowFlags.NoTitleBar + imgui.WindowFlags.NoMove)
        imgui.CenterTextColoredRGB('Your Statistic')
        imgui.Separator()

        imgui.End()
    end
end

function onWindowMessage(msg, wparam, lparam)
    if msg == 0x100 or msg == 0x101 then
        if (wparam == key.VK_ESCAPE and (main_window_state.v)) and not isPauseMenuActive() and not isSampfuncsConsoleActive() then
            consumeWindowMessage(true, false)
            if msg == 0x101 then
                main_window_state.v = false
            end
        end
    end
end

function imgui.CenterTextColoredRGB(text)
    local width = imgui.GetWindowWidth()
    local style = imgui.GetStyle()
    local colors = style.Colors
    local ImVec4 = imgui.ImVec4

    local explode_argb = function(argb)
    local a = bit.band(bit.rshift(argb, 24), 0xFF)
    local r = bit.band(bit.rshift(argb, 16), 0xFF)
    local g = bit.band(bit.rshift(argb, 8), 0xFF)
    local b = bit.band(argb, 0xFF)
    return a, r, g, b
    end

    local getcolor = function(color)
    if color:sub(1, 6):upper() == 'SSSSSS' then
    local r, g, b = colors[1].x, colors[1].y, colors[1].z
    local a = tonumber(color:sub(7, 8), 16) or colors[1].w * 255
    return ImVec4(r, g, b, a / 255)
    end
    local color = type(color) == 'string' and tonumber(color, 16) or color
    if type(color) ~= 'number' then return end
    local r, g, b, a = explode_argb(color)
    return imgui.ImColor(r, g, b, a):GetVec4()
    end

    local render_text = function(text_)
    for w in text_:gmatch('[^\r\n]+') do
    local textsize = w:gsub('{.-}', '')
    local text_width = imgui.CalcTextSize(u8(textsize))
    imgui.SetCursorPosX( width / 2 - text_width .x / 2 )
    local text, colors_, m = {}, {}, 1
    w = w:gsub('{(......)}', '{%1FF}')
    while w:find('{........}') do
    local n, k = w:find('{........}')
    local color = getcolor(w:sub(n + 1, k - 1))
    if color then
    text[#text], text[#text + 1] = w:sub(m, n - 1), w:sub(k + 1, #w)
    colors_[#colors_ + 1] = color
    m = n
    end
    w = w:sub(1, n - 1) .. w:sub(k + 1, #w)
    end
    if text[0] then
    for i = 0, #text do
    imgui.TextColored(colors_[i] or colors[1], u8(text[i]))
    imgui.SameLine(nil, 0)
    end
    imgui.NewLine()
    else
    imgui.Text(u8(w))
    end
    end
    end
    render_text(text)
end

local fa_font = nil
local fa_glyph_ranges = imgui.ImGlyphRanges({ fa.min_range, fa.max_range })
function imgui.BeforeDrawFrame()
    if fa_font == nil then
        local font_config = imgui.ImFontConfig()
        font_config.MergeMode = true

        fa_font = imgui.GetIO().Fonts:AddFontFromFileTTF('moonloader/resource/fonts/fa-solid-900.ttf', 50.0, font_config, fa_glyph_ranges)
        if fontsize == nil then
        fontsize = imgui.GetIO().Fonts:AddFontFromFileTTF(getFolderPath(0x14) .. '\\trebucbd.ttf', 47.0, nil, imgui.GetIO().Fonts:GetGlyphRangesCyrillic()) -- вместо 30 любой нужный размеp
        end
    end
end

function imgui.TextColoredRGB(text)
    local style = imgui.GetStyle()
    local colors = style.Colors
    local ImVec4 = imgui.ImVec4

    local explode_argb = function(argb)
    local a = bit.band(bit.rshift(argb, 24), 0xFF)
    local r = bit.band(bit.rshift(argb, 16), 0xFF)
    local g = bit.band(bit.rshift(argb, 8), 0xFF)
    local b = bit.band(argb, 0xFF)
    return a, r, g, b
    end

    local getcolor = function(color)
    if color:sub(1, 6):upper() == 'SSSSSS' then
    local r, g, b = colors[1].x, colors[1].y, colors[1].z
    local a = tonumber(color:sub(7, 8), 16) or colors[1].w * 255
    return ImVec4(r, g, b, a / 255)
    end
    local color = type(color) == 'string' and tonumber(color, 16) or color
    if type(color) ~= 'number' then return end
    local r, g, b, a = explode_argb(color)
    return imgui.ImColor(r, g, b, a):GetVec4()
    end

    local render_text = function(text_)
    for w in text_:gmatch('[^\r\n]+') do
    local text, colors_, m = {}, {}, 1
    w = w:gsub('{(......)}', '{%1FF}')
    while w:find('{........}') do
    local n, k = w:find('{........}')
    local color = getcolor(w:sub(n + 1, k - 1))
    if color then
    text[#text], text[#text + 1] = w:sub(m, n - 1), w:sub(k + 1, #w)
    colors_[#colors_ + 1] = color
    m = n
    end
    w = w:sub(1, n - 1) .. w:sub(k + 1, #w)
    end
    if text[0] then
    for i = 0, #text do
    imgui.TextColored(colors_[i] or colors[1], u8(text[i]))
    imgui.SameLine(nil, 0)
    end
    imgui.NewLine()
    else imgui.Text(u8(w)) end
    end
    end
    render_text(text)
end

function imgui.SelectButton(name, bool, size)
    if Buttonaver.v then
        imgui.PushStyleColor(imgui.Col.Button, imgui.ImVec4(0.0, 0.6, 0.0, 0.40))
        imgui.PushStyleColor(imgui.Col.ButtonHovered, imgui.ImVec4(0.0, 0.8, 0.0, 1.0))
        imgui.PushStyleColor(imgui.Col.ButtonActive, imgui.ImVec4(0.0, 1.0, 0.0, 1.0))
    else
        imgui.PushStyleColor(imgui.Col.Button, imgui.ImVec4(0.6, 0.0, 0.0, 0.40))
        imgui.PushStyleColor(imgui.Col.ButtonHovered, imgui.ImVec4(0.8, 0.0, 0.0, 1.0))
        imgui.PushStyleColor(imgui.Col.ButtonActive, imgui.ImVec4(1.0, 0.0, 0.0, 1.0))
    end
    if not size then size = imgui.ImVec2(0, 0) end
    local result = imgui.Button(name, size)
    imgui.PopStyleColor(3)
    if result then Buttonaver.v = not Buttonaver.v end
    return result
end
 

ik0nka

Известный
750
342
и как сделать так чтобы при открытом первом меню была активна курсор, а при закрытом и открытом ток втором был убран ?
imgui.ShowCursor = main_window_state.v

как сделать так чтобы при включении чекбокса это появлялось в новом окне ?

и как сделать так чтобы при открытом первом меню была активна курсор, а при закрытом и открытом ток втором был убран ?


Lua:
require "lib.moonloader"
local key = require "vkeys"
local imgui = require 'imgui'
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8
local fa = require 'fAwesome5'
local themes = import "resource/imgui_themes.lua"

local main_window_state = imgui.ImBool(false)
local window_state = imgui.ImBool(false)
local text_buffer = imgui.ImBuffer(256) -- Зачем тебе он тут если нету ImGui.InputText(name, buffer)
local menu = 0
local Buttonaver = imgui.ImBool(false)
local PrintNick = imgui.ImBool(false)
local PrintID = imgui.ImBool(false)
local PrintPing = imgui.ImBool(false)
local PrintHeart = imgui.ImBool(false)


function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end

    sampRegisterChatCommand("plh", function()
        main_window_state.v = not main_window_state.v
    end)
    sampRegisterChatCommand("plh2", function()
        window_state.v = not window_state.v
    end)

    imgui.SwitchContext()
    themes.SwitchColorTheme(1)

    handle, id = sampGetPlayerIdByCharHandle(PLAYER_PED)
    nick = sampGetPlayerNickname(id)

  while true do wait(0)
        if isKeyDown(key.VK_LMENU) and isKeyJustPressed(key.VK_M) then
            main_window_state.v = not main_window_state.v
        end

        imgui.Process = main_window_state.v or window_state.v

  end
end



function imgui.OnDrawFrame() -- не Flame а Frame!!
    if main_window_state.v then
        local sw, sh = getScreenResolution()
        imgui.SetNextWindowPos(imgui.ImVec2(sw / 2, sh / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
        imgui.SetNextWindowSize(imgui.ImVec2(900, 535))
        imgui.Begin('##localwindow',  main_window_state, imgui.WindowFlags.AlwaysAutoResize + imgui.WindowFlags.NoCollapse + imgui.WindowFlags.NoTitleBar + imgui.WindowFlags.NoMove)
        imgui.NewLine()
        imgui.SetCursorPosY(0)
        imgui.NewLine()
        imgui.NewLine()
        imgui.NewLine()
        imgui.Text(fa.ICON_FA_USER_SHIELD .. "")
        imgui.SameLine()
        imgui.SetCursorPosY(20)
        imgui.PushFont(fontsize)
        imgui.TextColoredRGB("{0000CB}POLICE HELPER")
        imgui.PopFont()
        imgui.NewLine()
        if menu == 0 then
            imgui.BeginChild('##localchild', imgui.ImVec2(890, 432), true)
            if imgui.Button(fa.ICON_FA_FOLDER .. u8"Основное", imgui.ImVec2(291, 210)) then menu = 2 end
            imgui.SameLine()
            if imgui.Button(fa.ICON_FA_COG .. u8"Настройки", imgui.ImVec2(291, 210)) then menu = 3 end
            imgui.SameLine()
            if imgui.Button(fa.ICON_FA_COINS .. u8"Пожертвования", imgui.ImVec2(291, 210)) then menu = 4 end
            if imgui.Button(fa.ICON_FA_NEWSPAPER .. u8"Новости", imgui.ImVec2(291, 210)) then menu = 5 end
            imgui.SameLine()
            if imgui.Button(fa.ICON_FA_KEYBOARD .. u8"Биндер", imgui.ImVec2(291, 210)) then menu = 6 end
            imgui.SameLine()
            if imgui.Button(fa.ICON_FA_TOOLS .. u8"Мульти-настройки", imgui.ImVec2(291, 210)) then menu = 7 end
            imgui.EndChild()
        end
        if menu == 2 then
            imgui.BeginChild("", imgui.ImVec2(890, 402), true)
            imgui.Text("test")
            imgui.EndChild()
            if imgui.Button(u8"< Назад", imgui.ImVec2(100, 30)) then menu = 0 end
        end
        if menu == 3 then
            imgui.BeginChild("", imgui.ImVec2(890, 402), true)
            if imgui.Button(u8'Вкл/Выкл Статистику') then window_state.v = not window_state.v end
            if imgui.Checkbox('Nick', PrintNick) then end
            if imgui.Checkbox('ID', PrintID) then end
            if imgui.Checkbox('Ping', PrintPing) then end
            if imgui.Checkbox('Heart', PrintHeart) then end
            imgui.EndChild()
            if imgui.Button(u8"< Назад", imgui.ImVec2(100, 30)) then menu = 0 end
        end

        if menu == 4 then
            imgui.BeginChild("", imgui.ImVec2(890, 402), true)
            imgui.Text("test")
            imgui.EndChild()
            if imgui.Button(u8"< Назад", imgui.ImVec2(100, 30)) then menu = 0 end
        end
        if menu == 5 then
            imgui.BeginChild("", imgui.ImVec2(890, 402), true)
            imgui.Text("Релиз скрипта - версия 1.0!")
            imgui.EndChild()
            if imgui.Button(u8"< Назад", imgui.ImVec2(100, 30)) then menu = 0 end
        end

        if menu == 6 then
            imgui.BeginChild("", imgui.ImVec2(890, 402), true)
            imgui.Text("test")
            imgui.EndChild()
            if imgui.Button(u8"< Назад", imgui.ImVec2(100, 30)) then menu = 0 end
        end

        if menu == 7 then
            imgui.BeginChild("", imgui.ImVec2(890, 402), true)
            imgui.Text(u8"Сменить цвет:")
            if  imgui.Button(u8"Ярко-Фиолетовый") then
                themes.SwitchColorTheme(1)
            end
            if  imgui.Button(u8"Тёмно-Фиолетовый") then
                themes.SwitchColorTheme(2)
            end
            if  imgui.Button(u8"Тёмно-Берюзовый") then
                themes.SwitchColorTheme(6)
            end
            if  imgui.Button(u8"Серый") then
                themes.SwitchColorTheme(5)
            end
            imgui.EndChild()
            if imgui.Button(u8"< Назад", imgui.ImVec2(100, 30)) then menu = 0 end
        end
        imgui.End()
    end
    if window_state.v then
        local sw, sh = getScreenResolution()
        imgui.SetNextWindowPos(imgui.ImVec2(sw / 1.09, sh / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
        imgui.SetNextWindowSize(imgui.ImVec2(260, 235))
        imgui.Begin('Your Statistic', window_state, imgui.WindowFlags.AlwaysAutoResize + imgui.WindowFlags.NoCollapse + imgui.WindowFlags.NoTitleBar + imgui.WindowFlags.NoMove)
        imgui.CenterTextColoredRGB('Your Statistic')
        imgui.Separator()

        imgui.End()
    end
end

function onWindowMessage(msg, wparam, lparam)
    if msg == 0x100 or msg == 0x101 then
        if (wparam == key.VK_ESCAPE and (main_window_state.v)) and not isPauseMenuActive() and not isSampfuncsConsoleActive() then
            consumeWindowMessage(true, false)
            if msg == 0x101 then
                main_window_state.v = false
            end
        end
    end
end

function imgui.CenterTextColoredRGB(text)
    local width = imgui.GetWindowWidth()
    local style = imgui.GetStyle()
    local colors = style.Colors
    local ImVec4 = imgui.ImVec4

    local explode_argb = function(argb)
    local a = bit.band(bit.rshift(argb, 24), 0xFF)
    local r = bit.band(bit.rshift(argb, 16), 0xFF)
    local g = bit.band(bit.rshift(argb, 8), 0xFF)
    local b = bit.band(argb, 0xFF)
    return a, r, g, b
    end

    local getcolor = function(color)
    if color:sub(1, 6):upper() == 'SSSSSS' then
    local r, g, b = colors[1].x, colors[1].y, colors[1].z
    local a = tonumber(color:sub(7, 8), 16) or colors[1].w * 255
    return ImVec4(r, g, b, a / 255)
    end
    local color = type(color) == 'string' and tonumber(color, 16) or color
    if type(color) ~= 'number' then return end
    local r, g, b, a = explode_argb(color)
    return imgui.ImColor(r, g, b, a):GetVec4()
    end

    local render_text = function(text_)
    for w in text_:gmatch('[^\r\n]+') do
    local textsize = w:gsub('{.-}', '')
    local text_width = imgui.CalcTextSize(u8(textsize))
    imgui.SetCursorPosX( width / 2 - text_width .x / 2 )
    local text, colors_, m = {}, {}, 1
    w = w:gsub('{(......)}', '{%1FF}')
    while w:find('{........}') do
    local n, k = w:find('{........}')
    local color = getcolor(w:sub(n + 1, k - 1))
    if color then
    text[#text], text[#text + 1] = w:sub(m, n - 1), w:sub(k + 1, #w)
    colors_[#colors_ + 1] = color
    m = n
    end
    w = w:sub(1, n - 1) .. w:sub(k + 1, #w)
    end
    if text[0] then
    for i = 0, #text do
    imgui.TextColored(colors_[i] or colors[1], u8(text[i]))
    imgui.SameLine(nil, 0)
    end
    imgui.NewLine()
    else
    imgui.Text(u8(w))
    end
    end
    end
    render_text(text)
end

local fa_font = nil
local fa_glyph_ranges = imgui.ImGlyphRanges({ fa.min_range, fa.max_range })
function imgui.BeforeDrawFrame()
    if fa_font == nil then
        local font_config = imgui.ImFontConfig()
        font_config.MergeMode = true

        fa_font = imgui.GetIO().Fonts:AddFontFromFileTTF('moonloader/resource/fonts/fa-solid-900.ttf', 50.0, font_config, fa_glyph_ranges)
        if fontsize == nil then
        fontsize = imgui.GetIO().Fonts:AddFontFromFileTTF(getFolderPath(0x14) .. '\\trebucbd.ttf', 47.0, nil, imgui.GetIO().Fonts:GetGlyphRangesCyrillic()) -- вместо 30 любой нужный размеp
        end
    end
end

function imgui.TextColoredRGB(text)
    local style = imgui.GetStyle()
    local colors = style.Colors
    local ImVec4 = imgui.ImVec4

    local explode_argb = function(argb)
    local a = bit.band(bit.rshift(argb, 24), 0xFF)
    local r = bit.band(bit.rshift(argb, 16), 0xFF)
    local g = bit.band(bit.rshift(argb, 8), 0xFF)
    local b = bit.band(argb, 0xFF)
    return a, r, g, b
    end

    local getcolor = function(color)
    if color:sub(1, 6):upper() == 'SSSSSS' then
    local r, g, b = colors[1].x, colors[1].y, colors[1].z
    local a = tonumber(color:sub(7, 8), 16) or colors[1].w * 255
    return ImVec4(r, g, b, a / 255)
    end
    local color = type(color) == 'string' and tonumber(color, 16) or color
    if type(color) ~= 'number' then return end
    local r, g, b, a = explode_argb(color)
    return imgui.ImColor(r, g, b, a):GetVec4()
    end

    local render_text = function(text_)
    for w in text_:gmatch('[^\r\n]+') do
    local text, colors_, m = {}, {}, 1
    w = w:gsub('{(......)}', '{%1FF}')
    while w:find('{........}') do
    local n, k = w:find('{........}')
    local color = getcolor(w:sub(n + 1, k - 1))
    if color then
    text[#text], text[#text + 1] = w:sub(m, n - 1), w:sub(k + 1, #w)
    colors_[#colors_ + 1] = color
    m = n
    end
    w = w:sub(1, n - 1) .. w:sub(k + 1, #w)
    end
    if text[0] then
    for i = 0, #text do
    imgui.TextColored(colors_[i] or colors[1], u8(text[i]))
    imgui.SameLine(nil, 0)
    end
    imgui.NewLine()
    else imgui.Text(u8(w)) end
    end
    end
    render_text(text)
end

function imgui.SelectButton(name, bool, size)
    if Buttonaver.v then
        imgui.PushStyleColor(imgui.Col.Button, imgui.ImVec4(0.0, 0.6, 0.0, 0.40))
        imgui.PushStyleColor(imgui.Col.ButtonHovered, imgui.ImVec4(0.0, 0.8, 0.0, 1.0))
        imgui.PushStyleColor(imgui.Col.ButtonActive, imgui.ImVec4(0.0, 1.0, 0.0, 1.0))
    else
        imgui.PushStyleColor(imgui.Col.Button, imgui.ImVec4(0.6, 0.0, 0.0, 0.40))
        imgui.PushStyleColor(imgui.Col.ButtonHovered, imgui.ImVec4(0.8, 0.0, 0.0, 1.0))
        imgui.PushStyleColor(imgui.Col.ButtonActive, imgui.ImVec4(1.0, 0.0, 0.0, 1.0))
    end
    if not size then size = imgui.ImVec2(0, 0) end
    local result = imgui.Button(name, size)
    imgui.PopStyleColor(3)
    if result then Buttonaver.v = not Buttonaver.v end
    return result
end
На большинство вопросов которые ты задаешь есть уже темы на бх, учись гуглить
 

Kegwineye.

Участник
Автор темы
478
20
imgui.ShowCursor = main_window_state.v


На большинство вопросов которые ты задаешь есть уже темы на бх, учись гуглить как сделать так чтобы при включении чекбокса это появлялось в новом окне ? Типо есть чек бокс ваш пинг и при его включении во втором окне появляется Ping: **ping**
как бы я не писал, не знаю как правильно изложить мысль гуглу. Если можешь найди