require 'lib.moonloader'
local imgui = require 'mimgui'
local ffi = require 'ffi'
local vkeys = require 'vkeys'
local bit = require 'bit'
local wm = require 'windows.message'
local encoding = require 'encoding'
encoding.default = 'CP1251'
local u8 = encoding.UTF8
local new, str, sizeof = imgui.new, ffi.string, ffi.sizeof
local renderWindow, freezePlayer, removeCursor = new.bool(), new.bool(), new.bool()
local inputField = new.char[256]()
local sizeX, sizeY = getScreenResolution()
local function isDown(vk) return isKeyDown(vk) end
local function setNav(io, nav, down)
io.NavInputs[nav] = down and 1.0 or 0.0
end
local function clearNav(io)
for i = 0, imgui.NavInput.COUNT - 1 do
io.NavInputs[i] = 0.0
end
end
imgui.OnInitialize(function()
local io = imgui.GetIO()
io.IniFilename = nil
-- Включаем навигацию с клавиатуры (важно)
io.ConfigFlags = bit.bor(io.ConfigFlags, imgui.ConfigFlags.NavEnableKeyboard)
end)
local frame = imgui.OnFrame(
function() return renderWindow[0] end,
-- BEFORE FRAME: тут задаём NavInputs (каждый кадр!)
function()
local io = imgui.GetIO()
-- NavInputs очищаются после кадра, поэтому выставляем заново каждый раз
clearNav(io)
-- Навигацию “включаем” только когда курсор скрыт
if removeCursor[0] then
setNav(io, imgui.NavInput.DpadUp, isDown(vkeys.VK_UP))
setNav(io, imgui.NavInput.DpadDown, isDown(vkeys.VK_DOWN))
setNav(io, imgui.NavInput.DpadLeft, isDown(vkeys.VK_LEFT))
setNav(io, imgui.NavInput.DpadRight, isDown(vkeys.VK_RIGHT))
local tab = isDown(vkeys.VK_TAB)
local shift = isDown(vkeys.VK_SHIFT)
setNav(io, imgui.NavInput.FocusNext, tab and not shift)
setNav(io, imgui.NavInput.FocusPrev, tab and shift)
setNav(io, imgui.NavInput.Activate, isDown(vkeys.VK_RETURN)) -- Enter
setNav(io, imgui.NavInput.Cancel, isDown(vkeys.VK_ESCAPE)) -- Esc
end
end,
-- DRAW
function(player)
imgui.SetNextWindowPos(imgui.ImVec2(sizeX / 2, sizeY / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
imgui.SetNextWindowSize(imgui.ImVec2(480, 230), imgui.Cond.FirstUseEver)
imgui.Begin("Main Window", renderWindow)
imgui.Text("Подсказка: включи 'Скрыть курсор' и ходи по UI стрелками/Tab, Enter, Esc")
if imgui.InputText("Привет", inputField, sizeof(inputField)) then
print(u8:decode(str(inputField)))
end
if imgui.Button("Очистить поле") then
imgui.StrCopy(inputField, '')
end
if imgui.Checkbox('Заморозить игрока', freezePlayer) then
player.LockPlayer = freezePlayer[0]
end
if imgui.Checkbox('Скрыть курсор', removeCursor) then
player.HideCursor = removeCursor[0]
if removeCursor[0] then
-- чтобы сразу было удобно: фокус на первый следующий элемент
imgui.SetKeyboardFocusHere()
end
end
if player.HideCursor then
imgui.Text('Курсор скрыт')
end
imgui.End()
end
)
function main()
addEventHandler('onWindowMessage', function(msg, wparam, lparam)
if msg == wm.WM_KEYDOWN or msg == wm.WM_SYSKEYDOWN then
if wparam == vkeys.VK_X then
renderWindow[0] = not renderWindow[0]
end
end
end)
wait(-1)
end