ImGUI меню

Slava Stetem

Участник
Автор темы
106
5
Версия MoonLoader
.027.0-preview
Я создать ImGUI меню но не могу подключить к своему скрипту по одельности работает а вместе нет вот мой код:
Lua:
require "lib.moonloader"

local imgui = require 'imgui'
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8

function theme()
    imgui.SwitchContext()
    local style = imgui.GetStyle()
    local colors = style.Colors
    local clr = imgui.Col
    local ImVec4 = imgui.ImVec4
    local ImVec2 = imgui.ImVec2

    style.WindowPadding = imgui.ImVec2(8, 8)
    style.WindowRounding = 6
    style.ChildWindowRounding = 5
    style.FramePadding = imgui.ImVec2(5, 3)
    style.FrameRounding = 3.0
    style.ItemSpacing = imgui.ImVec2(5, 4)
    style.ItemInnerSpacing = imgui.ImVec2(4, 4)
    style.IndentSpacing = 21
    style.ScrollbarSize = 10.0
    style.ScrollbarRounding = 13
    style.GrabMinSize = 8
    style.GrabRounding = 1
    style.WindowTitleAlign = imgui.ImVec2(0.5, 0.5)
    style.ButtonTextAlign = imgui.ImVec2(0.5, 0.5)

    colors[clr.Text]                   = ImVec4(0.95, 0.96, 0.98, 1.00);
    colors[clr.TextDisabled]           = ImVec4(0.29, 0.29, 0.29, 1.00);
    colors[clr.WindowBg]               = ImVec4(0.14, 0.14, 0.14, 1.00);
    colors[clr.ChildWindowBg]          = ImVec4(0.12, 0.12, 0.12, 1.00);
    colors[clr.PopupBg]                = ImVec4(0.08, 0.08, 0.08, 0.94);
    colors[clr.Border]                 = ImVec4(0.14, 0.14, 0.14, 1.00);
    colors[clr.BorderShadow]           = ImVec4(1.00, 1.00, 1.00, 0.10);
    colors[clr.FrameBg]                = ImVec4(0.22, 0.22, 0.22, 1.00);
    colors[clr.FrameBgHovered]         = ImVec4(0.18, 0.18, 0.18, 1.00);
    colors[clr.FrameBgActive]          = ImVec4(0.09, 0.12, 0.14, 1.00);
    colors[clr.TitleBg]                = ImVec4(0.14, 0.14, 0.14, 0.81);
    colors[clr.TitleBgActive]          = ImVec4(0.14, 0.14, 0.14, 1.00);
    colors[clr.TitleBgCollapsed]       = ImVec4(0.00, 0.00, 0.00, 0.51);
    colors[clr.MenuBarBg]              = ImVec4(0.20, 0.20, 0.20, 1.00);
    colors[clr.ScrollbarBg]            = ImVec4(0.02,2 0.02, 0.02, 0.39);
    colors[clr.ScrollbarGrab]          = ImVec4(0.36, 0.36, 0.36, 1.00);
    colors[clr.ScrollbarGrabHovered]   = ImVec4(0.18, 0.22, 0.25, 1.00);
    colors[clr.ScrollbarGrabActive]    = ImVec4(0.24, 0.24, 0.24, 1.00);
    colors[clr.ComboBg]                = ImVec4(0.24, 0.24, 0.24, 1.00);
    colors[clr.CheckMark]              = ImVec4(1.00, 0.28, 0.28, 1.00);
    colors[clr.SliderGrab]             = ImVec4(1.00, 0.28, 0.28, 1.00);
    colors[clr.SliderGrabActive]       = ImVec4(1.00, 0.28, 0.28, 1.00);
    colors[clr.Button]                 = ImVec4(1.00, 0.28, 0.28, 1.00);
    colors[clr.ButtonHovered]          = ImVec4(1.00, 0.39, 0.39, 1.00);
    colors[clr.ButtonActive]           = ImVec4(1.00, 0.21, 0.21, 1.00);
    colors[clr.Header]                 = ImVec4(1.00, 0.28, 0.28, 1.00);
    colors[clr.HeaderHovered]          = ImVec4(1.00, 0.39, 0.39, 1.00);
    colors[clr.HeaderActive]           = ImVec4(1.00, 0.21, 0.21, 1.00);
    colors[clr.ResizeGrip]             = ImVec4(1.00, 0.28, 0.28, 1.00);
    colors[clr.ResizeGripHovered]      = ImVec4(1.00, 0.39, 0.39, 1.00);
    colors[clr.ResizeGripActive]       = ImVec4(1.00, 0.19, 0.19, 1.00);
    colors[clr.CloseButton]            = ImVec4(0.40, 0.39, 0.38, 0.16);
    colors[clr.CloseButtonHovered]     = ImVec4(0.40, 0.39, 0.38, 0.39);
    colors[clr.CloseButtonActive]      = ImVec4(0.40, 0.39, 0.38, 1.00);
    colors[clr.PlotLines]              = ImVec4(0.61, 0.61, 0.61, 1.00);
    colors[clr.PlotLinesHovered]       = ImVec4(1.00, 0.43, 0.35, 1.00);
    colors[clr.PlotHistogram]          = ImVec4(1.00, 0.21, 0.21, 1.00);
    colors[clr.PlotHistogramHovered]   = ImVec4(1.00, 0.18, 0.18, 1.00);
    colors[clr.TextSelectedBg]         = ImVec4(1.00, 0.32, 0.32, 1.00);
    colors[clr.ModalWindowDarkening]   = ImVec4(0.26, 0.26, 0.26, 0.60);
end
theme()

local main_window_state = imgui.ImBool(false)
local text_buffer = imgui.ImBuffer(256)

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


    sampRegisterChatCommand("imgui", cmd_imgui)

    imgui.Process = false



    while true do
    wait(0)

    if main_window_state.v == false then
      imgui.Process = false
    end

        if isKeyJustPressed(VK_P) then
        sampSendChat("/w привет")
        wait(2100)
        sampSendChat("/w пока")
        end
    end
    end


  function cmd_imgui(arg)
    main_window_state.v = not main_window_state.v
    imgui.Process = main_window_state.v
  end
А вот код ImGUI:
Lua:
require "lib.moonloader"

local imgui = require 'imgui'
local key = require 'vkeys'
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8

local imgui = require 'mimgui';
local ffi = require 'ffi';
local encoding = require 'encoding';
encoding.default = 'CP1251';
local u8 = encoding.UTF8;

local pWindow = imgui.new.bool(true)
local button0Callback = function() end

local main_window_state = imgui.new.bool(false)
local text_buffer = imgui.ImBuffer(256)

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


    sampRegisterChatCommand("imgui", cmd_imgui)

    imgui.Process = false



    while true do
    wait(0)
        if main_window_state.v == false then
            imgui.Process = false
            img = imgui.CreateTextureFromFile(getWorkingDirectory() .. "\\moonloader\\images\\officer.jpg")
            imgui.Image(img, imgui.ImVec2(300, 441))
        end


        if isKeyJustPressed(VK_P) then
        sampSendChat("/w привет")
        wait(2100)
        sampSendChat("/w пока")
        end
    end
    end

imgui.OnInitialize(function()
    imgui.StyleColorsLight();
    imgui.GetIO().IniFilename = nil
    scrX, scrY = getScreenResolution()
    local glyph_ranges = imgui.GetIO().Fonts:GetGlyphRangesCyrillic();
    --imgui.GetIO().Fonts:Clear();
    imgui.GetIO().Fonts:AddFontFromFileTTF(getFolderPath(0x14) .. '\arial.ttf', 16, nil, glyph_ranges);
    imgui.InvalidateFontsTexture();
end);

imgui.OnFrame(function() return pWindow[0] end,
function(self)
    self.HideCursor = false;
    self.LockPlayer = true;
    imgui.SetNextWindowPos(imgui.ImVec2(scrX / 2, scrY / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5));
    imgui.SetNextWindowSize(imgui.ImVec2(840.000000, 650.000000), imgui.Cond.FirstUseEver);
    imgui.PushStyleColor(imgui.Col.TitleBgActive, imgui.ImVec4(0.949020,0.956863,0.976471,1.000000));
    imgui.PushStyleColor(imgui.Col.WindowBg, imgui.ImVec4(0.607843,0.607843,0.607843,1.000000));
    imgui.Begin('New Window', pWindow, imgui.WindowFlags.NoCollapse);
    imgui.PushStyleColor(imgui.Col.Button, imgui.ImVec4(0.797468,0.094216,0.094216,1.000000));
    imgui.PushStyleColor(imgui.Col.ButtonActive, imgui.ImVec4(0.054902,0.054902,0.054902,0.003922));
    imgui.PushStyleColor(imgui.Col.ButtonHovered, imgui.ImVec4(0.109804,0.109804,0.109804,0.003922));
    imgui.PushStyleColor(imgui.Col.Text, imgui.ImVec4(1.000000,1.000000,1.000000,1.000000));
    imgui.SetCursorPos(imgui.ImVec2(0.000000,100.000000));
    if(imgui.Button('hcfgh', imgui.ImVec2(150.000000,100.000000))) then
        button0Callback();
    end
    imgui.PopStyleColor(4);
    imgui.End();
    imgui.PopStyleColor(2);
end);
    img = imgui.CreateTextureFromFile(getWorkingDirectory() .. "\\moonloader\\images\\officer.jpg");
    imgui.Image(img, imgui.ImVec2(300, 441));