ToggleButton - как сохранить положение

Sedoj

Участник
Автор темы
56
1
Версия MoonLoader
.026-beta
12.PNG
- как сохранить положение ползунка после релога скрипта?

Функция создания:

Lua:
function imgui.ToggleButton(str_id, bool)

    local rBool = false

    if LastActiveTime == nil then
        LastActiveTime = {}
    end
    if LastActive == nil then
        LastActive = {}
    end

    local function ImSaturate(f)
        return f < 0.0 and 0.0 or (f > 1.0 and 1.0 or f)
    end
    
    local p = imgui.GetCursorScreenPos()
    local draw_list = imgui.GetWindowDrawList()

    local height = imgui.GetTextLineHeightWithSpacing() + (imgui.GetStyle().FramePadding.y / 2)
    local width = height * 1.55
    local radius = height * 0.50
    local ANIM_SPEED = 0.15

    if imgui.InvisibleButton(str_id, imgui.ImVec2(width, height)) then
        bool.v = not bool.v
        rBool = true
        LastActiveTime[tostring(str_id)] = os.clock()
        LastActive[str_id] = true
    end

    local t = bool.v and 1.0 or 0.0

    if LastActive[str_id] then
        local time = os.clock() - LastActiveTime[tostring(str_id)]
        if time <= ANIM_SPEED then
            local t_anim = ImSaturate(time / ANIM_SPEED)
            t = bool.v and t_anim or 1.0 - t_anim
        else
            LastActive[str_id] = false
        end
    end

    local col_bg
    if imgui.IsItemHovered() then
        col_bg = imgui.GetColorU32(imgui.GetStyle().Colors[imgui.Col.FrameBgHovered])
    else
        col_bg = imgui.GetColorU32(imgui.GetStyle().Colors[imgui.Col.FrameBg])
    end

    draw_list:AddRectFilled(p, imgui.ImVec2(p.x + width, p.y + height), col_bg, height * 0.5)
    draw_list:AddCircleFilled(imgui.ImVec2(p.x + radius + t * (width - radius * 2.0), p.y + radius), radius - 1.5, imgui.GetColorU32(bool.v and imgui.GetStyle().Colors[imgui.Col.ButtonActive] or imgui.GetStyle().Colors[imgui.Col.Button]))

    return rBool
end
 

neverlane

t.me/neverlane00
Друг
1,010
1,162
Посмотреть вложение 58670 - как сохранить положение ползунка после релога скрипта?

Функция создания:

Lua:
function imgui.ToggleButton(str_id, bool)

    local rBool = false

    if LastActiveTime == nil then
        LastActiveTime = {}
    end
    if LastActive == nil then
        LastActive = {}
    end

    local function ImSaturate(f)
        return f < 0.0 and 0.0 or (f > 1.0 and 1.0 or f)
    end
   
    local p = imgui.GetCursorScreenPos()
    local draw_list = imgui.GetWindowDrawList()

    local height = imgui.GetTextLineHeightWithSpacing() + (imgui.GetStyle().FramePadding.y / 2)
    local width = height * 1.55
    local radius = height * 0.50
    local ANIM_SPEED = 0.15

    if imgui.InvisibleButton(str_id, imgui.ImVec2(width, height)) then
        bool.v = not bool.v
        rBool = true
        LastActiveTime[tostring(str_id)] = os.clock()
        LastActive[str_id] = true
    end

    local t = bool.v and 1.0 or 0.0

    if LastActive[str_id] then
        local time = os.clock() - LastActiveTime[tostring(str_id)]
        if time <= ANIM_SPEED then
            local t_anim = ImSaturate(time / ANIM_SPEED)
            t = bool.v and t_anim or 1.0 - t_anim
        else
            LastActive[str_id] = false
        end
    end

    local col_bg
    if imgui.IsItemHovered() then
        col_bg = imgui.GetColorU32(imgui.GetStyle().Colors[imgui.Col.FrameBgHovered])
    else
        col_bg = imgui.GetColorU32(imgui.GetStyle().Colors[imgui.Col.FrameBg])
    end

    draw_list:AddRectFilled(p, imgui.ImVec2(p.x + width, p.y + height), col_bg, height * 0.5)
    draw_list:AddCircleFilled(imgui.ImVec2(p.x + radius + t * (width - radius * 2.0), p.y + radius), radius - 1.5, imgui.GetColorU32(bool.v and imgui.GetStyle().Colors[imgui.Col.ButtonActive] or imgui.GetStyle().Colors[imgui.Col.Button]))

    return rBool
end
сохранять в ини файле значение переменной и при следующем запуске скрипта записывать значение из ини в переенную
 

MaksQ

Известный
968
841
Lua:
require "lib.moonloader"

local togglebut = require 'imgui_addons'
local encoding = require 'encoding'
local inicfg = require 'inicfg'
encoding.default = 'CP1251'
u8 = encoding.UTF8


local mainini = inicfg.load({
    config =
    {
        render = false,

    }
    }, "FIle")

 


    local status = inicfg.load(mainini, 'FIle.ini')
    if not doesFileExist('moonloader/config/FIle.ini') then inicfg.save(mainini, 'FIle.ini') end


render = imgui.ImBool(mainini.config.render)


if togglebut.ToggleButton(u8"Что то", render) then
                mainini.config.render = render.v
                inicfg.save(mainini, 'FIle.ini')
            end
 

MaksQ

Известный
968
841
render = imgui.ImBool(mainini.config.render)
ошибку выдает

lua:64: sol: no matching function call takes this number of arguments and the specified types
stack traceback:
[C]: in function 'ImBool'
Как ты сделал? Я тебе же только часть скинул
 
  • Нравится
Реакции: Sedoj