положение второго окна lua

Kegwineye.

Участник
Автор темы
478
20
допустим у меня есть два окна , window and infowindow и я хочу чтобы человек мог сам изменить
Сверху допустим сверху появиться полу прозрачная черная мини минюшка, и там красным будет "Откатить" , а зеленым "Принять".

Lua:
local vkeys = require("vkeys")
local imgui = require('imgui')
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8
local inicfg = require 'inicfg'
local sampev = require 'lib.samp.events'
        
local fa = require 'fAwesome5' -- ICONS LIST: https://fontawesome.com/v5.15/icons?d=gallery&s=solid&m=free

local pokaz = false
local sbiv = imgui.ImBool(false)
local fh = imgui.ImBool(false)
local fb = imgui.ImBool(false)
local uds = imgui.ImBool(false)
local autologin = imgui.ImBool(false)

local window = imgui.ImBool(false)
local infowindow = imgui.ImBool(false)

local mainIni = inicfg.load({
    config =
    {
    sbiv = false,
    fh = false,
    fb = false,
    password = "",
    uds = false,
    autologin = false,
    carhelp = false,
    }
    }, "Helper for Arizona")

    --
    local sbiv = imgui.ImBool(mainIni.config.sbiv)
    local fh = imgui.ImBool(mainIni.config.fh)
    local fb = imgui.ImBool(mainIni.config.fb)
    local carhelp = imgui.ImBool(mainIni.config.fb)
    local autologin = imgui.ImBool(mainIni.config.autologin)
    local password = imgui.ImBuffer(''..mainIni.config.password, 256)
    local uds = imgui.ImBool(mainIni.config.uds)

    local menu = 0

function main()
    while not isSampAvailable() do wait(200) end
    sampRegisterChatCommand('lh', openwindowsourse)
    imgui.Process = false
    window.v = true  --show window on start
        while true do
            wait(0)
            imgui.Process = window.v
    -- sampRegisterChatCommand('testh', function()
    -- sampShowDialog(6405, "", "Джага-Джага\nДжин\nКувшин", "OK", "", DIALOG_STYLE_LIST)
    -- while sampIsDialogActive(6405) do wait(100) end
    -- local _, button, list, _ = sampHasDialogRespond(6405) end)
    if isKeyDown(vkeys.VK_MENU) and isKeyJustPressed(vkeys.VK_R) then
        window.v = not window.v
    end

    if fh.v then
        if isKeyDown(vkeys.VK_LMENU) and isKeyJustPressed(vkeys.VK_G) then
            sampSetChatInputEnabled(true)
            sampSetChatInputText("/findihouse ")
        end
    end

    if fb.v then
        if isKeyDown(vkeys.VK_LMENU) and isKeyJustPressed(vkeys.VK_B) then
            sampSetChatInputEnabled(true)
            sampSetChatInputText("/findibiz ")
        end
    end

    if uds.v and isKeyJustPressed(vkeys.VK_X) and not isCharInAnyCar(PLAYER_PED) and not sampIsDialogActive() then
        local hp = getCharHealth(1)
        if hp <= 40 then
            sampSendChat('/usedrugs 3')
        elseif hp <= 60 then
            sampSendChat('/usedrugs 2')
        elseif hp <= 80 then
            sampSendChat('/usedrugs 1')
        elseif hp > 100 then
            sampAddChatMessage('{Ff0000}[ERROR/WARNING]: {ffffff} Тебе достаточно.', 0x00FFFF00)
        end
    end

  if carhelp.v then
    if isKeyJustPressed(vkeys.VK_X) and isCharInAnyCar(PLAYER_PED) and not sampIsDialogActive() then
        sampSendChat('/style')
    end

    if isKeyJustPressed(vkeys.VK_K) and isCharInAnyCar(PLAYER_PED) and not sampIsDialogActive() then
        sampSendChat('/key')
    end

    if isKeyJustPressed(vkeys.VK_L) and not sampIsDialogActive() then
        sampSendChat('/lock')
    end
  end


    if sbiv.v then
              if isKeyDown(vkeys.VK_R) and not isKeyDown(vkeys.VK_MENU) then
                wait(10)
                if not isCharInAnyCar(PLAYER_PED)  and not sampIsDialogActive() and not isCharOnAnyBike(PLAYER_PED) and not sampIsChatInputActive() then toggle = not toggle if toggle then freezeCharPosition(PLAYER_PED, true) else freezeCharPosition(PLAYER_PED, false) end end
                wait(10)
                    if not isCharInAnyCar(PLAYER_PED) and not sampIsDialogActive() and not isCharOnAnyBike(PLAYER_PED) and not sampIsChatInputActive() then
                        clearCharTasksImmediately(PLAYER_PED) setPlayerControl(playerHandle, 1) freezeCharPosition(PLAYER_PED, false) restoreCameraJumpcut()
                    end
                end
            end
    end
end

function openwindowsourse()
    window.v = not window.v
end

function imgui.OnDrawFrame()
    if window.v then
        local resX, resY = getScreenResolution()
        local sizeX, sizeY = 920, 430 -- WINDOW SIZE
        imgui.SetNextWindowPos(imgui.ImVec2(resX / 2 - sizeX / 2, resY / 2 - sizeY / 2), imgui.Cond.FirstUseEver)
        imgui.SetNextWindowSize(imgui.ImVec2(sizeX, sizeY), imgui.Cond.FirstUseEver)
        imgui.Begin('Lovlya Helper | by Batter', window, imgui.WindowFlags.NoResize + imgui.WindowFlags.NoCollapse + imgui.WindowFlags.NoScrollbar + imgui.WindowFlags.NoTitleBar + imgui.WindowFlags.NoMove)
        imgui.PushFont(fa_font23)
        imgui.TextColoredRGB('  Ловля |{0000ff}Helper')
        imgui.PopFont()
        imgui.SameLine()
        imgui.SetCursorPosX(886)
        if imgui.Button(fa.ICON_FA_WINDOW_CLOSE .. '', imgui.ImVec2(25, 25)) then window.v = not window.v end
        imgui.BeginChild('##left', imgui.ImVec2(150, 200), false, imgui.WindowFlags.NoScrollbar)
        if imgui.Button(fa.ICON_FA_INFO_CIRCLE .. u8" Основное", imgui.ImVec2(149, 30)) then menu = 1 end
        if imgui.Button(fa.ICON_FA_CODE .. u8' Софт', imgui.ImVec2(149, 30)) then menu = 2 end
        if imgui.Button(fa.ICON_FA_QUESTION .. u8 ' О скрипте', imgui.ImVec2(149, 30)) then menu = 3 end
        imgui.EndChild()
        imgui.SameLine()
        imgui.SetCursorPosX(180)
        imgui.BeginChild('##localchild', imgui.ImVec2(870, 390), false, imgui.WindowFlags.NoScrollbar)
        if menu == 0 then
            imgui.SetCursorPosX(140)
            imgui.PushFont(fa_font17)
            imgui.Text(u8'\n\n\n Приветствую вас пользователь данного скрипта, хотел бы сказать..\nЧто если вы найдёте ошибку, то ищите в описании скрипта ссылку на мой ВК\nНаписав сообщение в ВК и прикрепив скриншот ошибки, я постараюсь \n                        в скорем времени исправить')
            imgui.PopFont() -- заканчиваем обработку фонта, иначе всё остальное будет иметь такой-же размер
        end
        if menu == 1 then
        imgui.Text(u8"Сбив анимации на R")
        imgui.SameLine()
        imgui.Checkbox('##sbiv', sbiv)
        imgui.Text(u8'Авто findihouse в чат на сочитание ALT + G')
        imgui.SameLine()
        imgui.Checkbox('##findih', fh)
        imgui.Text(u8'Авто findibiz в чат на сочитание ALT + B')
        imgui.SameLine()
        imgui.Checkbox('##findibiz', fb)
        imgui.Text(u8'Хелпер по управлению машиной')
        imgui.SameLine()
        imgui.Checkbox('##carhelp', carhelp)
        imgui.Text(u8' Принятие наркотиков на X')
        imgui.SameLine()
        imgui.Checkbox('##usedrugs', uds)
        imgui.Checkbox(u8 " Автологин", autologin)
        if pokaz then
            imgui.InputText(u8" ", password)
          else
            imgui.InputText(u8" ", password, imgui.InputTextFlags.Password)
        end
        imgui.SameLine()
        if imgui.Button(pokaz and fa.ICON_FA_EYE_SLASH .. u8'' or fa.ICON_FA_EYE .. u8'') then
            pokaz = not pokaz
        end
        if imgui.Button('Clear Chat') then
            for i=0,150 do
                sampAddChatMessage('',-1)
            end
        end
        if imgui.Button(u8'Отображать инфо', imgui.ImVec2(150, 30)) then infowindow.v = not infowindow.v end
    end
    if menu == 2 then
        if imgui.Button('test', imgui.ImVec2(150, 30)) then end
        imgui.Hint(u8'Ну привет дорогой')
        
    end
    if menu == 3 then

    end
        --window code
        imgui.EndChild()
        imgui.SetCursorPosY(370)
        if imgui.Button(u8'Сохранить настройки', imgui.ImVec2(148,30)) then
            mainIni.config.sbiv = sbiv.v
            mainIni.config.autologin = autologin.v
            mainIni.config.password = password.v
            mainIni.config.carhelp = carhelp.v
            mainIni.config.fh = fh.v
            mainIni.config.fb = fb.v
            mainIni.config.uds = uds.v
            inicfg.save(mainIni, 'Helper for Arizona.ini')
        end
        imgui.End()
    end
    if infowindow.v then
        local resX, resY = getScreenResolution()
        local sizeX, sizeY = 60, 80 -- WINDOW SIZE
        imgui.SetNextWindowPos(imgui.ImVec2(resX / 2 - sizeX / 2, resY / 2 - sizeY / 2), imgui.Cond.FirstUseEver)
        imgui.SetNextWindowSize(imgui.ImVec2(sizeX, sizeY), imgui.Cond.FirstUseEver)
        imgui.Begin('##helperwindow', window, imgui.WindowFlags.NoResize + imgui.WindowFlags.NoCollapse + imgui.WindowFlags.NoScrollbar + imgui.WindowFlags.NoTitleBar + imgui.WindowFlags.NoMove)
        imgui.End()
    end
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', 13.0, font_config, fa_glyph_ranges)
        fa_font17 = imgui.GetIO().Fonts:AddFontFromFileTTF(getFolderPath(0x14) .. '\\trebucbd.ttf', 17, nil, imgui.GetIO().Fonts:GetGlyphRangesCyrillic()) -- вместо 17 любой нужный размер
        fa_font23 = imgui.GetIO().Fonts:AddFontFromFileTTF(getFolderPath(0x14) .. '\\trebucbd.ttf', 23, nil, imgui.GetIO().Fonts:GetGlyphRangesCyrillic()) -- вместо 17 любой нужный размер
    end
end

if autologin.v then
    function onReceiveRpc(id,bitStream)
    if id == 61 then
    dialogId = raknetBitStreamReadInt16(bitStream)
  style = raknetBitStreamReadInt8(bitStream)
    str = raknetBitStreamReadInt8(bitStream)
    title = raknetBitStreamReadString(bitStream, str)
    if title:find("Авторизация") then
    sampSendDialogResponse(dialogId,1,0,""..mainIni.config.password)
    end
    end
    end
end

function imgui.Hint(text, delay, action)
    if imgui.IsItemHovered() then
        if go_hint == nil then go_hint = os.clock() + (delay and delay or 0.0) end
        local alpha = (os.clock() - go_hint) * 5
        if os.clock() >= go_hint then
            imgui.PushStyleVar(imgui.StyleVar.WindowPadding, imgui.ImVec2(10, 10))
            imgui.PushStyleVar(imgui.StyleVar.Alpha, (alpha <= 1.0 and alpha or 1.0))
                imgui.PushStyleColor(imgui.Col.PopupBg, imgui.ImVec4(0.11, 0.11, 0.11, 1.00))
                    imgui.BeginTooltip()
                    imgui.PushTextWrapPos(450)
                    imgui.TextColored(imgui.GetStyle().Colors[imgui.Col.ButtonHovered], u8' Подсказка:')
                    imgui.TextUnformatted(text)
                    if action ~= nil then
                        imgui.TextColored(imgui.GetStyle().Colors[imgui.Col.TextDisabled], '\n '..action)
                    end
                    if not imgui.IsItemVisible() and imgui.GetStyle().Alpha == 1.0 then go_hint = nil end
                    imgui.PopTextWrapPos()
                    imgui.EndTooltip()
                imgui.PopStyleColor()
            imgui.PopStyleVar(2)
        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 bluetheme()
    imgui.SwitchContext()
    local colors = imgui.GetStyle().Colors;
    local icol = imgui.Col
    local ImVec4 = imgui.ImVec4

    imgui.GetStyle().WindowPadding = imgui.ImVec2(8, 8)
    imgui.GetStyle().WindowRounding = 16.0
    imgui.GetStyle().FramePadding = imgui.ImVec2(5, 3)
    imgui.GetStyle().ItemSpacing = imgui.ImVec2(4, 4)
    imgui.GetStyle().ItemInnerSpacing = imgui.ImVec2(5, 5)
    imgui.GetStyle().IndentSpacing = 9.0
    imgui.GetStyle().ScrollbarSize = 17.0
    imgui.GetStyle().ScrollbarRounding = 16.0
    imgui.GetStyle().GrabMinSize = 7.0
    imgui.GetStyle().GrabRounding = 6.0
    imgui.GetStyle().ChildWindowRounding = 6.0
    imgui.GetStyle().FrameRounding = 6.0

    colors[icol.Text]                   = ImVec4(0.90, 0.90, 0.90, 1.00);
    colors[icol.TextDisabled]           = ImVec4(0.60, 0.60, 0.60, 1.00);
    colors[icol.WindowBg]               = ImVec4(0.11, 0.11, 0.11, 1.00);
    colors[icol.ChildWindowBg]          = ImVec4(0.13, 0.13, 0.13, 1.00);
    colors[icol.PopupBg]                = ImVec4(0.11, 0.11, 0.11, 1.00);
    colors[icol.Border]                 = ImVec4(0.26, 0.46, 0.82, 1.00);
    colors[icol.BorderShadow]           = ImVec4(0.26, 0.46, 0.82, 1.00);
    colors[icol.FrameBg]                = ImVec4(0.26, 0.46, 0.82, 0.59);
    colors[icol.FrameBgHovered]         = ImVec4(0.26, 0.46, 0.82, 0.88);
    colors[icol.FrameBgActive]          = ImVec4(0.28, 0.53, 1.00, 1.00);
    colors[icol.TitleBg]                = ImVec4(0.26, 0.46, 0.82, 1.00);
    colors[icol.TitleBgActive]          = ImVec4(0.26, 0.46, 0.82, 1.00);
    colors[icol.TitleBgCollapsed]       = ImVec4(0.26, 0.46, 0.82, 1.00);
    colors[icol.MenuBarBg]              = ImVec4(0.26, 0.46, 0.82, 0.75);
    colors[icol.ScrollbarBg]            = ImVec4(0.11, 0.11, 0.11, 1.00);
    colors[icol.ScrollbarGrab]          = ImVec4(0.26, 0.46, 0.82, 0.68);
    colors[icol.ScrollbarGrabHovered]   = ImVec4(0.26, 0.46, 0.82, 1.00);
    colors[icol.ScrollbarGrabActive]    = ImVec4(0.26, 0.46, 0.82, 1.00);
    colors[icol.ComboBg]                = ImVec4(0.26, 0.46, 0.82, 0.79);
    colors[icol.CheckMark]              = ImVec4(1.000, 0.000, 0.000, 1.000)
    colors[icol.SliderGrab]             = ImVec4(0.263, 0.459, 0.824, 1.000)
    colors[icol.SliderGrabActive]       = ImVec4(0.66, 0.66, 0.66, 1.00);
    colors[icol.Button]                 = ImVec4(0.26, 0.46, 0.82, 1.00);
    colors[icol.ButtonHovered]          = ImVec4(0.26, 0.46, 0.82, 0.59);
    colors[icol.ButtonActive]           = ImVec4(0.26, 0.46, 0.82, 1.00);
    colors[icol.Header]                 = ImVec4(0.26, 0.46, 0.82, 1.00);
    colors[icol.HeaderHovered]          = ImVec4(0.26, 0.46, 0.82, 0.74);
    colors[icol.HeaderActive]           = ImVec4(0.26, 0.46, 0.82, 1.00);
    colors[icol.Separator]              = ImVec4(0.37, 0.37, 0.37, 1.00);
    colors[icol.SeparatorHovered]       = ImVec4(0.60, 0.60, 0.70, 1.00);
    colors[icol.SeparatorActive]        = ImVec4(0.70, 0.70, 0.90, 1.00);
    colors[icol.ResizeGrip]             = ImVec4(1.00, 1.00, 1.00, 0.30);
    colors[icol.ResizeGripHovered]      = ImVec4(1.00, 1.00, 1.00, 0.60);
    colors[icol.ResizeGripActive]       = ImVec4(1.00, 1.00, 1.00, 0.90);
    colors[icol.CloseButton]            = ImVec4(0.00, 0.00, 0.00, 1.00);
    colors[icol.CloseButtonHovered]     = ImVec4(0.00, 0.00, 0.00, 0.60);
    colors[icol.CloseButtonActive]      = ImVec4(0.35, 0.35, 0.35, 1.00);
    colors[icol.PlotLines]              = ImVec4(1.00, 1.00, 1.00, 1.00);
    colors[icol.PlotLinesHovered]       = ImVec4(0.90, 0.70, 0.00, 1.00);
    colors[icol.PlotHistogram]          = ImVec4(0.90, 0.70, 0.00, 1.00);
    colors[icol.PlotHistogramHovered]   = ImVec4(1.00, 0.60, 0.00, 1.00);
    colors[icol.TextSelectedBg]         = ImVec4(0.00, 0.00, 1.00, 0.35);
    colors[icol.ModalWindowDarkening]   = ImVec4(0.20, 0.20, 0.20, 0.35);
end
bluetheme()