Как правильно открыть окно-оверлей с помощью imgui.Checkbox?

Ninthmoon

Известный
Автор темы
463
127
Версия MoonLoader
.026-beta
Как оставить окно, которое активировалось с помощью чекбокса, активным даже когда главное окно закрыто?
Вопрос в том как этом сделать правильно
Мой вариант ниже, он работает, но он говно, как сделать правильно?
Lua:
local imgui = require 'imgui'
local main_window_state = imgui.ImBool(false)
local overlay_window_state = imgui.ImBool(false)
local key = require 'vkeys'

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

function main()
    while true do wait(0)
        if isKeyDown(key.VK_MENU) and wasKeyPressed(key.VK_X) then
            main_window_state.v = not main_window_state.v
            imgui.Process = main_window_state.v
        end
    end
end

function imgui.OnDrawFrame()
    if not main_window_state.v and overlay_window_state.v then
        showCursor(false, false)
        imgui.Process = overlay_window_state.v
    elseif not main_window_state.v and not overlay_window_state.v then
        imgui.Process = false
    end
    if main_window_state.v then
        showCursor(true, true)
        w, h = getScreenResolution()
        imgui.SetNextWindowSize(imgui.ImVec2(w/3, h/2), imgui.Cond.FirstUseEver)
        imgui.SetNextWindowPos( imgui.ImVec2(w/3, h/2), imgui.Cond.FirstUseEver)
        imgui.Begin(u8'Главное окно', main_window_state, imgui.WindowFlags.NoResize)
        if imgui.CollapsingHeader(u8'Открой меня') then
            imgui.Text(u8'Привет')
        end
        imgui.Checkbox('FPS Overlay', overlay_window_state)
        imgui.End()
    end
    if overlay_window_state.v then
        imgui.SetNextWindowSize(imgui.ImVec2(300, 30), imgui.Cond.FirstUseEver)
        imgui.SetNextWindowPos( imgui.ImVec2(0, h-30), imgui.Cond.FirstUseEver)
        imgui.Begin(u8'##FPS Overlay', overlay_window_state, imgui.WindowFlags.NoResize + imgui.WindowFlags.NoTitleBar)
        local framerate = imgui.GetIO().Framerate
        imgui.Text(string.format('Application average %.3f ms/frame (%.1f FPS)', 1000.0 / framerate, framerate))
        imgui.End()
    end
end
 
Последнее редактирование:
Решение
не проверял
(перейдите уже на mimgui, хватит срать в потоке своими imgui.process)

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

local main_window_state = imgui.ImBool(false)
local overlay_window_state = imgui.ImBool(false)

function main()
    while not isSampAvailable() do wait(0) end
   
    while true do
        wait(0)
        if isKeyDown(key.VK_MENU) and isKeyJustPressed(key.VK_X) then
            main_window_state.v = not main_window_state.v
        end
       
        imgui.Process = main_window_state.v or overlay_window_state.v
    end
end

function imgui.OnDrawFrame()
    if main_window_state.v then
        local w, h =...

meowprd

Тот самый Котовский
Проверенный
1,280
712
не проверял
(перейдите уже на mimgui, хватит срать в потоке своими imgui.process)

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

local main_window_state = imgui.ImBool(false)
local overlay_window_state = imgui.ImBool(false)

function main()
    while not isSampAvailable() do wait(0) end
   
    while true do
        wait(0)
        if isKeyDown(key.VK_MENU) and isKeyJustPressed(key.VK_X) then
            main_window_state.v = not main_window_state.v
        end
       
        imgui.Process = main_window_state.v or overlay_window_state.v
    end
end

function imgui.OnDrawFrame()
    if main_window_state.v then
        local w, h = getScreenResolution()
        imgui.SetNextWindowSize(imgui.ImVec2(w/3, h/2), imgui.Cond.FirstUseEver)
        imgui.SetNextWindowPos( imgui.ImVec2(w/3, h/2), imgui.Cond.FirstUseEver)
        imgui.ShowCursor = true
        imgui.Begin(u8'Главное окно', main_window_state, imgui.WindowFlags.NoResize)
        if imgui.CollapsingHeader(u8'Открой меня') then
            imgui.Text(u8'Привет')
        end
        imgui.Checkbox('FPS Overlay', overlay_window_state)
        imgui.End()
    end
   
    if overlay_window_state.v then
        imgui.SetNextWindowSize(imgui.ImVec2(300, 30), imgui.Cond.FirstUseEver)
        imgui.SetNextWindowPos( imgui.ImVec2(0, h-30), imgui.Cond.FirstUseEver)
        imgui.ShowCursor = false
        imgui.Begin(u8'##FPS Overlay', overlay_window_state, imgui.WindowFlags.NoResize + imgui.WindowFlags.NoTitleBar)
        local framerate = imgui.GetIO().Framerate
        imgui.Text(string.format('Application average %.3f ms/frame (%.1f FPS)', 1000.0 / framerate, framerate))
        imgui.End()
    end
end
 
  • Нравится
Реакции: xionerme

Ninthmoon

Известный
Автор темы
463
127
не проверял
(перейдите уже на mimgui, хватит срать в потоке своими imgui.process)

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

local main_window_state = imgui.ImBool(false)
local overlay_window_state = imgui.ImBool(false)

function main()
    while not isSampAvailable() do wait(0) end
  
    while true do
        wait(0)
        if isKeyDown(key.VK_MENU) and isKeyJustPressed(key.VK_X) then
            main_window_state.v = not main_window_state.v
        end
      
        imgui.Process = main_window_state.v or overlay_window_state.v
    end
end

function imgui.OnDrawFrame()
    if main_window_state.v then
        local w, h = getScreenResolution()
        imgui.SetNextWindowSize(imgui.ImVec2(w/3, h/2), imgui.Cond.FirstUseEver)
        imgui.SetNextWindowPos( imgui.ImVec2(w/3, h/2), imgui.Cond.FirstUseEver)
        imgui.ShowCursor = true
        imgui.Begin(u8'Главное окно', main_window_state, imgui.WindowFlags.NoResize)
        if imgui.CollapsingHeader(u8'Открой меня') then
            imgui.Text(u8'Привет')
        end
        imgui.Checkbox('FPS Overlay', overlay_window_state)
        imgui.End()
    end
  
    if overlay_window_state.v then
        imgui.SetNextWindowSize(imgui.ImVec2(300, 30), imgui.Cond.FirstUseEver)
        imgui.SetNextWindowPos( imgui.ImVec2(0, h-30), imgui.Cond.FirstUseEver)
        imgui.ShowCursor = false
        imgui.Begin(u8'##FPS Overlay', overlay_window_state, imgui.WindowFlags.NoResize + imgui.WindowFlags.NoTitleBar)
        local framerate = imgui.GetIO().Framerate
        imgui.Text(string.format('Application average %.3f ms/frame (%.1f FPS)', 1000.0 / framerate, framerate))
        imgui.End()
    end
end
чучуть доделал, работает нормально
как для человека который пол месяца ковыряется в луа особой разницы нет, поэтому сначала пробую Moon ImGui, потом может буду думать на счёт перехода, чтобы перейти куда-то надо сначала куда-то прийти)
Lua:
local imgui = require 'imgui'
local key = require 'vkeys'

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

local main_window_state = imgui.ImBool(false)
local overlay_window_state = imgui.ImBool(false)

function main()
    while true do wait(0)
        if isKeyDown(key.VK_MENU) and wasKeyPressed(key.VK_X) then
            main_window_state.v = not main_window_state.v
        end
        imgui.Process = main_window_state.v or overlay_window_state.v
    end
end

function imgui.OnDrawFrame()
    if not main_window_state.v then
        imgui.ShowCursor = false
    end
    if main_window_state.v then
        imgui.ShowCursor = true
        w, h = getScreenResolution()
        imgui.SetNextWindowSize(imgui.ImVec2(w/3, h/2), imgui.Cond.FirstUseEver)
        imgui.SetNextWindowPos( imgui.ImVec2(w/3, h/2), imgui.Cond.FirstUseEver)
        imgui.Begin(u8'Главное окно', main_window_state, imgui.WindowFlags.NoResize)
        if imgui.CollapsingHeader(u8'Открой меня') then
            imgui.Text(u8'Привет')
        end
        imgui.Checkbox('FPS Overlay', overlay_window_state)
        imgui.End()
    end
    if overlay_window_state.v then
        imgui.SetNextWindowSize(imgui.ImVec2(300, 30), imgui.Cond.FirstUseEver)
        imgui.SetNextWindowPos( imgui.ImVec2(0, h-30), imgui.Cond.FirstUseEver)
        imgui.Begin(u8'##FPS Overlay', overlay_window_state, imgui.WindowFlags.NoResize + imgui.WindowFlags.NoTitleBar)
        local framerate = imgui.GetIO().Framerate
        imgui.Text(string.format('Application average %.3f ms/frame (%.1f FPS)', 1000.0 / framerate, framerate))
        imgui.End()
    end
end