сохранение позиции окна

Kegwineye.

Участник
Автор темы
478
20
как сделать на луа сохранение позиции окна в ini файле ? попытался сделать так. Не вышло.


Lua:
local imgui = require('imgui')
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8

local posX = 400
local posY = 400

local inicfg = require 'inicfg'
local directIni = 'testlessen.ini'
local ini = inicfg.load(inicfg.load({
    main = {
        posX = 400,
        posY = 400,
    },
}, directIni))
inicfg.save(ini, directIni)
        
local window = imgui.ImBool(false)
        
function main()
    while not isSampAvailable() do wait(200) end
    imgui.Process = false
    window.v = true  --show window on start
    while true do
        wait(0)
        imgui.Process = window.v
    end
end
        
function imgui.OnDrawFrame()
    if window.v then
        local resX, resY = getScreenResolution()
        local sizeX, sizeY = 300, 300 -- WINDOW SIZE
        imgui.SetNextWindowPos(imgui.ImVec2(resX / ini.main.posX - sizeX / 2, resY / ini.main.posY - sizeY / 2), imgui.Cond.FirstUseEver)
        imgui.SetNextWindowSize(imgui.ImVec2(sizeX, sizeY), imgui.Cond.FirstUseEver)
        imgui.Begin('Window Title', window)
        if imgui.Button('save pos', imgui.ImVec2(150, 40)) then
            sampAddChatMessage('Sucspend!', -1)
            ini.main.posX =
            ini.main.PosY =
        end
        --window code
        imgui.End()
    end
end

@Rice. @chapo
 
Последнее редактирование:
Решение
как сделать на луа сохранение позиции окна в ini файле ? попытался сделать так. Не вышло.


Lua:
local imgui = require('imgui')
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8

local posX = 400
local posY = 400

local inicfg = require 'inicfg'
local directIni = 'testlessen.ini'
local ini = inicfg.load(inicfg.load({
    main = {
        posX = 400,
        posY = 400,
    },
}, directIni))
inicfg.save(ini, directIni)
      
local window = imgui.ImBool(false)
      
function main()
    while not isSampAvailable() do wait(200) end
    imgui.Process = false
    window.v = true  --show window on start
    while true do
        wait(0)
        imgui.Process = window.v
    end
end
      
function...

Rice.

https://t.me/riceoff
Модератор
1,689
1,430
как сделать на луа сохранение позиции окна в ini файле ? попытался сделать так. Не вышло.


Lua:
local imgui = require('imgui')
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8

local posX = 400
local posY = 400

local inicfg = require 'inicfg'
local directIni = 'testlessen.ini'
local ini = inicfg.load(inicfg.load({
    main = {
        posX = 400,
        posY = 400,
    },
}, directIni))
inicfg.save(ini, directIni)
      
local window = imgui.ImBool(false)
      
function main()
    while not isSampAvailable() do wait(200) end
    imgui.Process = false
    window.v = true  --show window on start
    while true do
        wait(0)
        imgui.Process = window.v
    end
end
      
function imgui.OnDrawFrame()
    if window.v then
        local resX, resY = getScreenResolution()
        local sizeX, sizeY = 300, 300 -- WINDOW SIZE
        imgui.SetNextWindowPos(imgui.ImVec2(resX / ini.main.posX - sizeX / 2, resY / ini.main.posY - sizeY / 2), imgui.Cond.FirstUseEver)
        imgui.SetNextWindowSize(imgui.ImVec2(sizeX, sizeY), imgui.Cond.FirstUseEver)
        imgui.Begin('Window Title', window)
        if imgui.Button('save pos', imgui.ImVec2(150, 40)) then
            sampAddChatMessage('Sucspend!', -1)
            ini.main.posX =
            ini.main.PosY =
        end
        --window code
        imgui.End()
    end
end

@Rice. @chapo
Lua:
----- LOCAL: -----
local posX, posY = ini.main.posX, ini.main.posY
----- IMGUI: -----
if imgui.Button(u8'Местоположение', imgui.ImVec2(150, 20)) then
    lua_thread.create(function ()
        showCursor(true, true)
        checkCursor = true
        sampSetCursorMode(4)
        sampAddChatMessage('Нажмите {32CD32}SPACE{FFFFFF} что-бы сохранить позицию', -1)
        while checkCursor do
            local cX, cY = getCursorPos()
            posX, posY = cX, cY
            if isKeyDown(32) then -- 32 = Space
                sampSetCursorMode(0)
                ini.main.posX, ini.main.posY = posX, posY
                checkCursor = false
                showCursor(false, false)
                if inicfg.save(ini, directIni) then sampAddChatMessage('Сохранено!', -1) end
            end
            wait(0)
        end
    end)
end
Окно Imgui:
Lua:
imgui.SetNextWindowPos(imgui.ImVec2(posX, posY), imgui.Cond.Always)
 
  • Влюблен
Реакции: Стэнфорд