IMGUI | Не берёт данные из конфига.

CHAPPLE

Участник
Автор темы
97
15
Версия MoonLoader
.026-beta
При перезагруке скрипта, imgui не берёт данные из конфига.

Безымянный1.png
Как должно быть
Безымянный2.png
Как получается при перезагрузке

Вот код:

LUA:
script_name("Test")
script_author("DonHomka")
script_version("0.1.0-beta")

require "lib.moonloader"
local vkeys = require 'vkeys'
local imgui = require 'imgui'
local encoding = require "encoding"
encoding.default = "CP1251"
u8 = encoding.UTF8
imgui.Process = false

local fontsize = nil
function imgui.BeforeDrawFrame()
    if fontsize == nil then
        fontsize = imgui.GetIO().Fonts:AddFontFromFileTTF(getFolderPath(0x14) .. '\\trebucbd.ttf', 15.0, nil, imgui.GetIO().Fonts:GetGlyphRangesCyrillic()) -- вместо 30 любой нужный размер
    end
end

local label = 0
--////////////////////////////////////////// CONFIG
local inicfg = require "inicfg"
local directIni = "moonloader\\TEST\\test.ini"

local mainIni =
{                                                                                                                         -- задаем значения для data.** на случай, если потребуется создать файл конфига
    config =
        {
        rusname = u8"Имя Фамилия",
                rang = u8"Ранг"
    }
}
cfg = inicfg.load(nil, 'moonloader\\TEST\\test.ini') -- загружаем конфиг
if cfg == nil then -- проверяем, все ли в порядке. Если нет - создаем конфиг из заданных значений, иначе - загружаем
    print('Не найден файл конфига, создаю.')
    if inicfg.save(mainIni, 'moonloader\\TEST\\test.ini') then
        print('Файл был с настройками был создан, ошибок нет.')
        cfg = inicfg.load(nil, 'moonloader\\TEST\\test.ini')
    end
end

--//////////////////////////////////////////
local main_color = 0x00BFFF
local main_color_text = 0xFFFAFA
local main_window_state = imgui.ImBool(false)
local rusname = imgui.ImBuffer(256)
local rang = imgui.ImBuffer(256)
local arrSelectable = {false, false}
local pid = imgui.ImBuffer(256)
rusname.v = mainIni.config.rusname
rang.v = mainIni.config.rang



--///////////////////////////////////////Style
function imgui.TextColoredRGB(text, render_text)
    local max_float = imgui.GetWindowWidth()
    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

            local length = imgui.CalcTextSize(w)
            if render_text == 2 then
                imgui.NewLine()
                imgui.SameLine(max_float / 2 - ( length.x / 2 ))
            elseif render_text == 3 then
                imgui.NewLine()
                imgui.SameLine(max_float - length.x - 5 )
            end
            if text[0] then
                for i = 0, #text do
                    imgui.TextColored(colors_[i] or colors[1], text[i])
                    imgui.SameLine(nil, 0)
                end
                imgui.NewLine()
            else imgui.Text(w) end


        end
    end

    render_text(text)
end

function SetStyle()
    imgui.SwitchContext()
    local style = imgui.GetStyle()
    local colors = style.Colors
    local clr = imgui.Col
    local ImVec4 = imgui.ImVec4
    style.ScrollbarSize = 13.0
    style.ScrollbarRounding = 0
    style.ChildWindowRounding = 4.0
    colors[clr.PopupBg]                = ImVec4(0.08, 0.08, 0.08, 0.94)
    colors[clr.ComboBg]                = colors[clr.PopupBg]
    colors[clr.Button]                 = ImVec4(0.26, 0.59, 0.98, 0.40)
    colors[clr.ButtonHovered]          = ImVec4(0.26, 0.59, 0.98, 1.00)
    colors[clr.ButtonActive]           = ImVec4(0.06, 0.53, 0.98, 1.00)
    colors[clr.TitleBg]                = ImVec4(0.04, 0.04, 0.04, 1.00)
    colors[clr.TitleBgActive]          = ImVec4(0.16, 0.29, 0.48, 1.00)
    colors[clr.TitleBgCollapsed]       = ImVec4(0.00, 0.00, 0.00, 0.51)
    colors[clr.CloseButton]            = ImVec4(0.41, 0.41, 0.41, 0.50)-- (0.1, 0.9, 0.1, 1.0)
    colors[clr.CloseButtonHovered]     = ImVec4(0.98, 0.39, 0.36, 1.00)
    colors[clr.CloseButtonActive]      = ImVec4(0.98, 0.39, 0.36, 1.00)
    colors[clr.TextSelectedBg]         = ImVec4(0.26, 0.59, 0.98, 0.35)
    colors[clr.Text]                   = ImVec4(1.00, 1.00, 1.00, 1.00)
    colors[clr.FrameBg]                = ImVec4(0.16, 0.29, 0.48, 0.54)
    colors[clr.FrameBgHovered]         = ImVec4(0.26, 0.59, 0.98, 0.40)
    colors[clr.FrameBgActive]          = ImVec4(0.26, 0.59, 0.98, 0.67)
    colors[clr.MenuBarBg]              = ImVec4(0.14, 0.14, 0.14, 1.00)
    colors[clr.ScrollbarBg]            = ImVec4(0.02, 0.02, 0.02, 0.53)
    colors[clr.ScrollbarGrab]          = ImVec4(0.31, 0.31, 0.31, 1.00)
    colors[clr.ScrollbarGrabHovered]   = ImVec4(0.41, 0.41, 0.41, 1.00)
    colors[clr.ScrollbarGrabActive]    = ImVec4(0.51, 0.51, 0.51, 1.00)
    colors[clr.CheckMark]              = ImVec4(0.26, 0.59, 0.98, 1.00)
    colors[clr.Header]                 = ImVec4(0.26, 0.59, 0.98, 0.31)
    colors[clr.HeaderHovered]          = ImVec4(0.26, 0.59, 0.98, 0.80)
    colors[clr.HeaderActive]           = ImVec4(0.26, 0.59, 0.98, 1.00)
    colors[clr.SliderGrab]             = ImVec4(0.24, 0.52, 0.88, 1.00)
    colors[clr.SliderGrabActive]       = ImVec4(0.26, 0.59, 0.98, 1.00)
end

SetStyle()

--\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end

    sampAddChatMessage("Тест скрипт", main_color_text)
    sampRegisterChatCommand("test", cmd_imgui)

--////////////////////////////////////////// CONFIG
    sampRegisterChatCommand("getsinfoo", cmd_getsinfo)
    sampRegisterChatCommand("getinfoo", cmd_getinfo)
    sampRegisterChatCommand("settname", cmd_settname)
    sampRegisterChatCommand("settrusn", cmd_settrusn)
--//////////////////////////////////////////
    while true do
        wait(0)
if main_window_state.v == false then
    imgui.Process = false
end
    end
end
--////////////////////////////////////////// CONFIG
function cmd_getinfo(arg)
    mainIni = inicfg.load(nil, directIni)
    sampAddChatMessage("{FFFFFF}Ник:{00BFFF} " .. mainIni.config.rang, 0x00BFFF)
    sampAddChatMessage("{FFFFFF}Русский Ник:{00BFFF} " .. mainIni.config.rusname, 0x00BFFF)
end
function cmd_getsinfo(arg)
mainIni = inicfg.load(arg, directIni)
if arg == "rusname" then
sampAddChatMessage(mainIni.config.rusname, -1)
end
if arg == "rang" then
sampAddChatMessage(mainIni.config.rang, -1)
end
end
function cmd_settname(arg)
mainIni.config.rang = arg
if inicfg.save(mainIni, directIni) then
    sampAddChatMessage("Сохранено! 1", -1)
end
end
function cmd_settrusn(arg)
mainIni.config.rusname = arg
if inicfg.save(mainIni, directIni) then
    sampAddChatMessage("Сохранено! 2", -1)
end
end
--//////////////////////////////////////////

function cmd_imgui(arg)
    main_window_state.v = not main_window_state.v
    imgui.Process = main_window_state.v
end

function imgui.OnDrawFrame()

            if not main_window_state.v then
                imgui.Process = false
            end

    if main_window_state.v then
        local sw, sh = getScreenResolution()
        imgui.SetNextWindowPos(imgui.ImVec2(sw / 2, sh / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
        imgui.SetNextWindowSize(imgui.ImVec2(600, 300), imgui.Cond.FirstUseEver)
        imgui.Begin(u8"Собеседование", main_window_state, imgui.WindowFlags.NoResize)

--//////////////////////////////////////////////////////////////////////BUTTONS
imgui.SetCursorPos(imgui.ImVec2(4.000000,25.000000));
imgui.BeginChild("child", imgui.ImVec2(130, 265), true)
imgui.SetCursorPos(imgui.ImVec2(5.000000,5.000000));
if imgui.Button(u8"НАСТРОЙКИ", imgui.ImVec2(120, 40)) then menu = 1 end
imgui.SetCursorPos(imgui.ImVec2(5.000000,50.000000));
if imgui.Button(u8"CОБЕСЕДОВАНИЕ", imgui.ImVec2(120, 40)) then menu = 2 end
imgui.SetCursorPos(imgui.ImVec2(5.000000,220.000000));
if imgui.Button(u8"ИНФО", imgui.ImVec2(120, 40)) then menu = 3 end
imgui.EndChild()

imgui.SameLine()
if menu == 1 then
        imgui.SetCursorPos(imgui.ImVec2(139.000000,25.000000));
    imgui.BeginChild("child2", imgui.ImVec2(450, 265), true)

        imgui.SetCursorPos(imgui.ImVec2(35.000000,22.500000));
        imgui.PushFont(fontsize)
        imgui.Text(u8"Ваш ник (RUS): ")
        imgui.PopFont()

        imgui.SetCursorPos(imgui.ImVec2(135.000000,20.000000));
        imgui.PushItemWidth(150)
        imgui.SameLine()
    if imgui.InputText('', rusname) then
            cfg.config.rusname = u8:decode(rusname.v)
        end
        imgui.PopItemWidth()

        imgui.SetCursorPos(imgui.ImVec2(35.000000,47.500000));
        imgui.PushFont(fontsize)
        imgui.Text(u8"Ваша должность: ")
        imgui.PopFont()

        imgui.SetCursorPos(imgui.ImVec2(150.000000,45.000000));
        imgui.PushItemWidth(135)
        imgui.SameLine()
        if imgui.InputText(' ', rang) then
            cfg.config.rusname = u8:decode(rang.v)
        end
        imgui.PopItemWidth()

        imgui.SetCursorPos(imgui.ImVec2(176.000000,240.000000));
        if imgui.Button(u8"Сохранить", imgui.ImVec2(100, 20)) then
            mainIni.config.rusname = u8:decode(rusname.v)
            mainIni.config.rang = u8:decode(rang.v)
            sampAddChatMessage("{FFFFFF}Вы успешно изменили ник на:{00BFFF} " .. u8:decode(rusname.v), -1)
            sampAddChatMessage("{FFFFFF}Ваш ранг:{00BFFF} " .. u8:decode(rang.v), -1)
            if inicfg.save(mainIni, directIni) then
                sampAddChatMessage("Сохранено! 2", -1)
            end
        end
    imgui.EndChild()
end
imgui.SameLine()
if menu == 2 then
      imgui.SetCursorPos(imgui.ImVec2(139.000000,25.000000));
    imgui.BeginChild("child2", imgui.ImVec2(450, 265), true)
        imgui.BeginChild("child3", imgui.ImVec2(125, 30), true)
        imgui.SetCursorPos(imgui.ImVec2(17.000000,5.000000));
        imgui.PushItemWidth(30)
        imgui.InputText(u8"ID игрока", pid)
        imgui.PopItemWidth()
        imgui.EndChild()
        imgui.BeginChild("child4", imgui.ImVec2(125, 215), true)
        if imgui.Button(u8"Начать", imgui.ImVec2(100, 20)) then
            sampSendChat("Здравствуйте, я, " .. u8:decode(rang.v) .. " " .. u8:decode(rusname.v) .. " проведу для вас.")
        end

      imgui.EndChild()
    imgui.EndChild()
end
imgui.SameLine()
if menu == 3 then
      imgui.SetCursorPos(imgui.ImVec2(139.000000,25.000000));
    imgui.BeginChild("child2", imgui.ImVec2(450, 265), true)
    imgui.Text("3")
    imgui.EndChild()
end

--         imgui.SetCursorPos(imgui.ImVec2(8.000000,25.000000));
--     if imgui.Button(u8"НАСТРОЙКИ", imgui.ImVec2(125, 40)) then
--         sampSendChat("/n test")
--     end
--         imgui.SetCursorPos(imgui.ImVec2(8.000000,75.000000));
--     if imgui.Button(u8"СОБЕСЕДОВАНИЕ", imgui.ImVec2(125, 40)) then
--
--     end
--     imgui.SetCursorPos(imgui.ImVec2(8.000000,250.000000));
-- if imgui.Button(u8"ИНФО", imgui.ImVec2(125, 40)) then
--     sampSendChat("/n test")
-- end
--//////////////////////////////////////////////////////////////////////BUTTONS




    end

    imgui.End()

end


--sampSendChat("/n test")
 
Решение
Сделал всё, как ты сказал, убрал везде заменил cfg на mainIni, обновил код, но после перезагрузки вот эти знаки вопроса... Сохраняет текст только на Английском.
LUA:
script_name("Test")
script_author("DonHomka")
script_version("0.1.0-beta")

require "lib.moonloader"
local vkeys = require 'vkeys'
local imgui = require 'imgui'
local encoding = require "encoding"
encoding.default = "CP1251"
u8 = encoding.UTF8
imgui.Process = false

local fontsize = nil
function imgui.BeforeDrawFrame()
    if fontsize == nil then
        fontsize = imgui.GetIO().Fonts:AddFontFromFileTTF(getFolderPath(0x14) .. '\\trebucbd.ttf', 15.0, nil, imgui.GetIO().Fonts:GetGlyphRangesCyrillic()) -- вместо 30 любой нужный размер
    end
end

local label = 0...

Fomikus

Известный
Проверенный
472
341
При перезагруке скрипта, imgui не берёт данные из конфига.

Посмотреть вложение 99790 Как должно быть
Посмотреть вложение 99791Как получается при перезагрузке

Вот код:

LUA:
script_name("Test")
script_author("DonHomka")
script_version("0.1.0-beta")

require "lib.moonloader"
local vkeys = require 'vkeys'
local imgui = require 'imgui'
local encoding = require "encoding"
encoding.default = "CP1251"
u8 = encoding.UTF8
imgui.Process = false

local fontsize = nil
function imgui.BeforeDrawFrame()
    if fontsize == nil then
        fontsize = imgui.GetIO().Fonts:AddFontFromFileTTF(getFolderPath(0x14) .. '\\trebucbd.ttf', 15.0, nil, imgui.GetIO().Fonts:GetGlyphRangesCyrillic()) -- вместо 30 любой нужный размер
    end
end

local label = 0
--////////////////////////////////////////// CONFIG
local inicfg = require "inicfg"
local directIni = "moonloader\\TEST\\test.ini"

local mainIni =
{                                                                                                                         -- задаем значения для data.** на случай, если потребуется создать файл конфига
    config =
        {
        rusname = u8"Имя Фамилия",
                rang = u8"Ранг"
    }
}
cfg = inicfg.load(nil, 'moonloader\\TEST\\test.ini') -- загружаем конфиг
if cfg == nil then -- проверяем, все ли в порядке. Если нет - создаем конфиг из заданных значений, иначе - загружаем
    print('Не найден файл конфига, создаю.')
    if inicfg.save(mainIni, 'moonloader\\TEST\\test.ini') then
        print('Файл был с настройками был создан, ошибок нет.')
        cfg = inicfg.load(nil, 'moonloader\\TEST\\test.ini')
    end
end

--//////////////////////////////////////////
local main_color = 0x00BFFF
local main_color_text = 0xFFFAFA
local main_window_state = imgui.ImBool(false)
local rusname = imgui.ImBuffer(256)
local rang = imgui.ImBuffer(256)
local arrSelectable = {false, false}
local pid = imgui.ImBuffer(256)
rusname.v = mainIni.config.rusname
rang.v = mainIni.config.rang



--///////////////////////////////////////Style
function imgui.TextColoredRGB(text, render_text)
    local max_float = imgui.GetWindowWidth()
    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

            local length = imgui.CalcTextSize(w)
            if render_text == 2 then
                imgui.NewLine()
                imgui.SameLine(max_float / 2 - ( length.x / 2 ))
            elseif render_text == 3 then
                imgui.NewLine()
                imgui.SameLine(max_float - length.x - 5 )
            end
            if text[0] then
                for i = 0, #text do
                    imgui.TextColored(colors_[i] or colors[1], text[i])
                    imgui.SameLine(nil, 0)
                end
                imgui.NewLine()
            else imgui.Text(w) end


        end
    end

    render_text(text)
end

function SetStyle()
    imgui.SwitchContext()
    local style = imgui.GetStyle()
    local colors = style.Colors
    local clr = imgui.Col
    local ImVec4 = imgui.ImVec4
    style.ScrollbarSize = 13.0
    style.ScrollbarRounding = 0
    style.ChildWindowRounding = 4.0
    colors[clr.PopupBg]                = ImVec4(0.08, 0.08, 0.08, 0.94)
    colors[clr.ComboBg]                = colors[clr.PopupBg]
    colors[clr.Button]                 = ImVec4(0.26, 0.59, 0.98, 0.40)
    colors[clr.ButtonHovered]          = ImVec4(0.26, 0.59, 0.98, 1.00)
    colors[clr.ButtonActive]           = ImVec4(0.06, 0.53, 0.98, 1.00)
    colors[clr.TitleBg]                = ImVec4(0.04, 0.04, 0.04, 1.00)
    colors[clr.TitleBgActive]          = ImVec4(0.16, 0.29, 0.48, 1.00)
    colors[clr.TitleBgCollapsed]       = ImVec4(0.00, 0.00, 0.00, 0.51)
    colors[clr.CloseButton]            = ImVec4(0.41, 0.41, 0.41, 0.50)-- (0.1, 0.9, 0.1, 1.0)
    colors[clr.CloseButtonHovered]     = ImVec4(0.98, 0.39, 0.36, 1.00)
    colors[clr.CloseButtonActive]      = ImVec4(0.98, 0.39, 0.36, 1.00)
    colors[clr.TextSelectedBg]         = ImVec4(0.26, 0.59, 0.98, 0.35)
    colors[clr.Text]                   = ImVec4(1.00, 1.00, 1.00, 1.00)
    colors[clr.FrameBg]                = ImVec4(0.16, 0.29, 0.48, 0.54)
    colors[clr.FrameBgHovered]         = ImVec4(0.26, 0.59, 0.98, 0.40)
    colors[clr.FrameBgActive]          = ImVec4(0.26, 0.59, 0.98, 0.67)
    colors[clr.MenuBarBg]              = ImVec4(0.14, 0.14, 0.14, 1.00)
    colors[clr.ScrollbarBg]            = ImVec4(0.02, 0.02, 0.02, 0.53)
    colors[clr.ScrollbarGrab]          = ImVec4(0.31, 0.31, 0.31, 1.00)
    colors[clr.ScrollbarGrabHovered]   = ImVec4(0.41, 0.41, 0.41, 1.00)
    colors[clr.ScrollbarGrabActive]    = ImVec4(0.51, 0.51, 0.51, 1.00)
    colors[clr.CheckMark]              = ImVec4(0.26, 0.59, 0.98, 1.00)
    colors[clr.Header]                 = ImVec4(0.26, 0.59, 0.98, 0.31)
    colors[clr.HeaderHovered]          = ImVec4(0.26, 0.59, 0.98, 0.80)
    colors[clr.HeaderActive]           = ImVec4(0.26, 0.59, 0.98, 1.00)
    colors[clr.SliderGrab]             = ImVec4(0.24, 0.52, 0.88, 1.00)
    colors[clr.SliderGrabActive]       = ImVec4(0.26, 0.59, 0.98, 1.00)
end

SetStyle()

--\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end

    sampAddChatMessage("Тест скрипт", main_color_text)
    sampRegisterChatCommand("test", cmd_imgui)

--////////////////////////////////////////// CONFIG
    sampRegisterChatCommand("getsinfoo", cmd_getsinfo)
    sampRegisterChatCommand("getinfoo", cmd_getinfo)
    sampRegisterChatCommand("settname", cmd_settname)
    sampRegisterChatCommand("settrusn", cmd_settrusn)
--//////////////////////////////////////////
    while true do
        wait(0)
if main_window_state.v == false then
    imgui.Process = false
end
    end
end
--////////////////////////////////////////// CONFIG
function cmd_getinfo(arg)
    mainIni = inicfg.load(nil, directIni)
    sampAddChatMessage("{FFFFFF}Ник:{00BFFF} " .. mainIni.config.rang, 0x00BFFF)
    sampAddChatMessage("{FFFFFF}Русский Ник:{00BFFF} " .. mainIni.config.rusname, 0x00BFFF)
end
function cmd_getsinfo(arg)
mainIni = inicfg.load(arg, directIni)
if arg == "rusname" then
sampAddChatMessage(mainIni.config.rusname, -1)
end
if arg == "rang" then
sampAddChatMessage(mainIni.config.rang, -1)
end
end
function cmd_settname(arg)
mainIni.config.rang = arg
if inicfg.save(mainIni, directIni) then
    sampAddChatMessage("Сохранено! 1", -1)
end
end
function cmd_settrusn(arg)
mainIni.config.rusname = arg
if inicfg.save(mainIni, directIni) then
    sampAddChatMessage("Сохранено! 2", -1)
end
end
--//////////////////////////////////////////

function cmd_imgui(arg)
    main_window_state.v = not main_window_state.v
    imgui.Process = main_window_state.v
end

function imgui.OnDrawFrame()

            if not main_window_state.v then
                imgui.Process = false
            end

    if main_window_state.v then
        local sw, sh = getScreenResolution()
        imgui.SetNextWindowPos(imgui.ImVec2(sw / 2, sh / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
        imgui.SetNextWindowSize(imgui.ImVec2(600, 300), imgui.Cond.FirstUseEver)
        imgui.Begin(u8"Собеседование", main_window_state, imgui.WindowFlags.NoResize)

--//////////////////////////////////////////////////////////////////////BUTTONS
imgui.SetCursorPos(imgui.ImVec2(4.000000,25.000000));
imgui.BeginChild("child", imgui.ImVec2(130, 265), true)
imgui.SetCursorPos(imgui.ImVec2(5.000000,5.000000));
if imgui.Button(u8"НАСТРОЙКИ", imgui.ImVec2(120, 40)) then menu = 1 end
imgui.SetCursorPos(imgui.ImVec2(5.000000,50.000000));
if imgui.Button(u8"CОБЕСЕДОВАНИЕ", imgui.ImVec2(120, 40)) then menu = 2 end
imgui.SetCursorPos(imgui.ImVec2(5.000000,220.000000));
if imgui.Button(u8"ИНФО", imgui.ImVec2(120, 40)) then menu = 3 end
imgui.EndChild()

imgui.SameLine()
if menu == 1 then
        imgui.SetCursorPos(imgui.ImVec2(139.000000,25.000000));
    imgui.BeginChild("child2", imgui.ImVec2(450, 265), true)

        imgui.SetCursorPos(imgui.ImVec2(35.000000,22.500000));
        imgui.PushFont(fontsize)
        imgui.Text(u8"Ваш ник (RUS): ")
        imgui.PopFont()

        imgui.SetCursorPos(imgui.ImVec2(135.000000,20.000000));
        imgui.PushItemWidth(150)
        imgui.SameLine()
    if imgui.InputText('', rusname) then
            cfg.config.rusname = u8:decode(rusname.v)
        end
        imgui.PopItemWidth()

        imgui.SetCursorPos(imgui.ImVec2(35.000000,47.500000));
        imgui.PushFont(fontsize)
        imgui.Text(u8"Ваша должность: ")
        imgui.PopFont()

        imgui.SetCursorPos(imgui.ImVec2(150.000000,45.000000));
        imgui.PushItemWidth(135)
        imgui.SameLine()
        if imgui.InputText(' ', rang) then
            cfg.config.rusname = u8:decode(rang.v)
        end
        imgui.PopItemWidth()

        imgui.SetCursorPos(imgui.ImVec2(176.000000,240.000000));
        if imgui.Button(u8"Сохранить", imgui.ImVec2(100, 20)) then
            mainIni.config.rusname = u8:decode(rusname.v)
            mainIni.config.rang = u8:decode(rang.v)
            sampAddChatMessage("{FFFFFF}Вы успешно изменили ник на:{00BFFF} " .. u8:decode(rusname.v), -1)
            sampAddChatMessage("{FFFFFF}Ваш ранг:{00BFFF} " .. u8:decode(rang.v), -1)
            if inicfg.save(mainIni, directIni) then
                sampAddChatMessage("Сохранено! 2", -1)
            end
        end
    imgui.EndChild()
end
imgui.SameLine()
if menu == 2 then
      imgui.SetCursorPos(imgui.ImVec2(139.000000,25.000000));
    imgui.BeginChild("child2", imgui.ImVec2(450, 265), true)
        imgui.BeginChild("child3", imgui.ImVec2(125, 30), true)
        imgui.SetCursorPos(imgui.ImVec2(17.000000,5.000000));
        imgui.PushItemWidth(30)
        imgui.InputText(u8"ID игрока", pid)
        imgui.PopItemWidth()
        imgui.EndChild()
        imgui.BeginChild("child4", imgui.ImVec2(125, 215), true)
        if imgui.Button(u8"Начать", imgui.ImVec2(100, 20)) then
            sampSendChat("Здравствуйте, я, " .. u8:decode(rang.v) .. " " .. u8:decode(rusname.v) .. " проведу для вас.")
        end

      imgui.EndChild()
    imgui.EndChild()
end
imgui.SameLine()
if menu == 3 then
      imgui.SetCursorPos(imgui.ImVec2(139.000000,25.000000));
    imgui.BeginChild("child2", imgui.ImVec2(450, 265), true)
    imgui.Text("3")
    imgui.EndChild()
end

--         imgui.SetCursorPos(imgui.ImVec2(8.000000,25.000000));
--     if imgui.Button(u8"НАСТРОЙКИ", imgui.ImVec2(125, 40)) then
--         sampSendChat("/n test")
--     end
--         imgui.SetCursorPos(imgui.ImVec2(8.000000,75.000000));
--     if imgui.Button(u8"СОБЕСЕДОВАНИЕ", imgui.ImVec2(125, 40)) then
--
--     end
--     imgui.SetCursorPos(imgui.ImVec2(8.000000,250.000000));
-- if imgui.Button(u8"ИНФО", imgui.ImVec2(125, 40)) then
--     sampSendChat("/n test")
-- end
--//////////////////////////////////////////////////////////////////////BUTTONS




    end

    imgui.End()

end


--sampSendChat("/n test")
mainIni = cfg
 
  • Нравится
Реакции: darkmeleee

CHAPPLE

Участник
Автор темы
97
15
Ты загружаешь конфиг в переменную cfg, а значения берешь из mainIni
Сделай
local mainIni = inicfg.load(mainIni, 'moonloader\\TEST\\test.ini')
вместо
cfg = inicfg.load(nil, 'moonloader\\TEST\\test.ini') (33 строка)
Сделал всё, как ты сказал, убрал везде заменил cfg на mainIni, обновил код, но после перезагрузки вот эти знаки вопроса... Сохраняет текст только на Английском.
LUA:
script_name("Test")
script_author("DonHomka")
script_version("0.1.0-beta")

require "lib.moonloader"
local vkeys = require 'vkeys'
local imgui = require 'imgui'
local encoding = require "encoding"
encoding.default = "CP1251"
u8 = encoding.UTF8
imgui.Process = false

local fontsize = nil
function imgui.BeforeDrawFrame()
    if fontsize == nil then
        fontsize = imgui.GetIO().Fonts:AddFontFromFileTTF(getFolderPath(0x14) .. '\\trebucbd.ttf', 15.0, nil, imgui.GetIO().Fonts:GetGlyphRangesCyrillic()) -- вместо 30 любой нужный размер
    end
end

local label = 0
--////////////////////////////////////////// CONFIG
local inicfg = require "inicfg"
local directIni = "moonloader\\TEST\\test.ini"

local data =
{                                                                                                                         -- задаем значения для data.** на случай, если потребуется создать файл конфига
    config =
        {
        rusname = u8"Имя Фамилия",
                rang = u8"Ранг"
    }
}
local mainIni = inicfg.load(data, 'moonloader\\TEST\\test.ini') -- загружаем конфиг
if mainIni == nil then -- проверяем, все ли в порядке. Если нет - создаем конфиг из заданных значений, иначе - загружаем
    print('Не найден файл конфига, создаю.')
    if inicfg.save(mainIni, 'moonloader\\TEST\\test.ini') then
        print('Файл был с настройками был создан, ошибок нет.')
        mainIni = inicfg.load(nil, 'moonloader\\TEST\\test.ini')
    end
end

--//////////////////////////////////////////
local main_color = 0x00BFFF
local main_color_text = 0xFFFAFA
local main_window_state = imgui.ImBool(false)
local rusname = imgui.ImBuffer(256)
local rang = imgui.ImBuffer(256)
local arrSelectable = {false, false}
local pid = imgui.ImBuffer(256)
rusname.v = mainIni.config.rusname
rang.v = mainIni.config.rang



--///////////////////////////////////////Style
function imgui.TextColoredRGB(text, render_text)
    local max_float = imgui.GetWindowWidth()
    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

            local length = imgui.CalcTextSize(w)
            if render_text == 2 then
                imgui.NewLine()
                imgui.SameLine(max_float / 2 - ( length.x / 2 ))
            elseif render_text == 3 then
                imgui.NewLine()
                imgui.SameLine(max_float - length.x - 5 )
            end
            if text[0] then
                for i = 0, #text do
                    imgui.TextColored(colors_[i] or colors[1], text[i])
                    imgui.SameLine(nil, 0)
                end
                imgui.NewLine()
            else imgui.Text(w) end


        end
    end

    render_text(text)
end

function SetStyle()
    imgui.SwitchContext()
    local style = imgui.GetStyle()
    local colors = style.Colors
    local clr = imgui.Col
    local ImVec4 = imgui.ImVec4
    style.ScrollbarSize = 13.0
    style.ScrollbarRounding = 0
    style.ChildWindowRounding = 4.0
    colors[clr.PopupBg]                = ImVec4(0.08, 0.08, 0.08, 0.94)
    colors[clr.ComboBg]                = colors[clr.PopupBg]
    colors[clr.Button]                 = ImVec4(0.26, 0.59, 0.98, 0.40)
    colors[clr.ButtonHovered]          = ImVec4(0.26, 0.59, 0.98, 1.00)
    colors[clr.ButtonActive]           = ImVec4(0.06, 0.53, 0.98, 1.00)
    colors[clr.TitleBg]                = ImVec4(0.04, 0.04, 0.04, 1.00)
    colors[clr.TitleBgActive]          = ImVec4(0.16, 0.29, 0.48, 1.00)
    colors[clr.TitleBgCollapsed]       = ImVec4(0.00, 0.00, 0.00, 0.51)
    colors[clr.CloseButton]            = ImVec4(0.41, 0.41, 0.41, 0.50)-- (0.1, 0.9, 0.1, 1.0)
    colors[clr.CloseButtonHovered]     = ImVec4(0.98, 0.39, 0.36, 1.00)
    colors[clr.CloseButtonActive]      = ImVec4(0.98, 0.39, 0.36, 1.00)
    colors[clr.TextSelectedBg]         = ImVec4(0.26, 0.59, 0.98, 0.35)
    colors[clr.Text]                   = ImVec4(1.00, 1.00, 1.00, 1.00)
    colors[clr.FrameBg]                = ImVec4(0.16, 0.29, 0.48, 0.54)
    colors[clr.FrameBgHovered]         = ImVec4(0.26, 0.59, 0.98, 0.40)
    colors[clr.FrameBgActive]          = ImVec4(0.26, 0.59, 0.98, 0.67)
    colors[clr.MenuBarBg]              = ImVec4(0.14, 0.14, 0.14, 1.00)
    colors[clr.ScrollbarBg]            = ImVec4(0.02, 0.02, 0.02, 0.53)
    colors[clr.ScrollbarGrab]          = ImVec4(0.31, 0.31, 0.31, 1.00)
    colors[clr.ScrollbarGrabHovered]   = ImVec4(0.41, 0.41, 0.41, 1.00)
    colors[clr.ScrollbarGrabActive]    = ImVec4(0.51, 0.51, 0.51, 1.00)
    colors[clr.CheckMark]              = ImVec4(0.26, 0.59, 0.98, 1.00)
    colors[clr.Header]                 = ImVec4(0.26, 0.59, 0.98, 0.31)
    colors[clr.HeaderHovered]          = ImVec4(0.26, 0.59, 0.98, 0.80)
    colors[clr.HeaderActive]           = ImVec4(0.26, 0.59, 0.98, 1.00)
    colors[clr.SliderGrab]             = ImVec4(0.24, 0.52, 0.88, 1.00)
    colors[clr.SliderGrabActive]       = ImVec4(0.26, 0.59, 0.98, 1.00)
end

SetStyle()

--\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end

    sampAddChatMessage("Тест скрипт", main_color_text)
    sampRegisterChatCommand("test", cmd_imgui)

--////////////////////////////////////////// CONFIG
    sampRegisterChatCommand("getsinfoo", cmd_getsinfo)
    sampRegisterChatCommand("getinfoo", cmd_getinfo)
    sampRegisterChatCommand("settname", cmd_settname)
    sampRegisterChatCommand("settrusn", cmd_settrusn)
--//////////////////////////////////////////
    while true do
        wait(0)
if main_window_state.v == false then
    imgui.Process = false
end
    end
end
--////////////////////////////////////////// CONFIG
function cmd_getinfo(arg)
    mainIni = inicfg.load(nil, directIni)
    sampAddChatMessage("{FFFFFF}Ник:{00BFFF} " .. mainIni.config.rang, 0x00BFFF)
    sampAddChatMessage("{FFFFFF}Русский Ник:{00BFFF} " .. mainIni.config.rusname, 0x00BFFF)
end
function cmd_getsinfo(arg)
mainIni = inicfg.load(arg, directIni)
if arg == "rusname" then
sampAddChatMessage(mainIni.config.rusname, -1)
end
if arg == "rang" then
sampAddChatMessage(mainIni.config.rang, -1)
end
end
function cmd_settname(arg)
mainIni.config.rang = arg
if inicfg.save(mainIni, directIni) then
    sampAddChatMessage("Сохранено! 1", -1)
end
end
function cmd_settrusn(arg)
mainIni.config.rusname = arg
if inicfg.save(mainIni, directIni) then
    sampAddChatMessage("Сохранено! 2", -1)
end
end
--//////////////////////////////////////////

function cmd_imgui(arg)
    main_window_state.v = not main_window_state.v
    imgui.Process = main_window_state.v
end

function imgui.OnDrawFrame()

            if not main_window_state.v then
                imgui.Process = false
            end

    if main_window_state.v then
        local sw, sh = getScreenResolution()
        imgui.SetNextWindowPos(imgui.ImVec2(sw / 2, sh / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
        imgui.SetNextWindowSize(imgui.ImVec2(600, 300), imgui.Cond.FirstUseEver)
        imgui.Begin(u8"Собеседование", main_window_state, imgui.WindowFlags.NoResize)

--//////////////////////////////////////////////////////////////////////BUTTONS
imgui.SetCursorPos(imgui.ImVec2(4.000000,25.000000));
imgui.BeginChild("child", imgui.ImVec2(130, 265), true)
imgui.SetCursorPos(imgui.ImVec2(5.000000,5.000000));
if imgui.Button(u8"НАСТРОЙКИ", imgui.ImVec2(120, 40)) then menu = 1 end
imgui.SetCursorPos(imgui.ImVec2(5.000000,50.000000));
if imgui.Button(u8"CОБЕСЕДОВАНИЕ", imgui.ImVec2(120, 40)) then menu = 2 end
imgui.SetCursorPos(imgui.ImVec2(5.000000,220.000000));
if imgui.Button(u8"ИНФО", imgui.ImVec2(120, 40)) then menu = 3 end
imgui.EndChild()

imgui.SameLine()
if menu == 1 then
        imgui.SetCursorPos(imgui.ImVec2(139.000000,25.000000));
    imgui.BeginChild("child2", imgui.ImVec2(450, 265), true)

        imgui.SetCursorPos(imgui.ImVec2(35.000000,22.500000));
        imgui.PushFont(fontsize)
        imgui.Text(u8"Ваш ник (RUS): ")
        imgui.PopFont()

        imgui.SetCursorPos(imgui.ImVec2(135.000000,20.000000));
        imgui.PushItemWidth(150)
        imgui.SameLine()
    if imgui.InputText('', rusname) then
            mainIni.config.rusname = u8:decode(rusname.v)
        end
        imgui.PopItemWidth()

        imgui.SetCursorPos(imgui.ImVec2(35.000000,47.500000));
        imgui.PushFont(fontsize)
        imgui.Text(u8"Ваша должность: ")
        imgui.PopFont()

        imgui.SetCursorPos(imgui.ImVec2(150.000000,45.000000));
        imgui.PushItemWidth(135)
        imgui.SameLine()
        if imgui.InputText(' ', rang) then
            mainIni.config.rusname = u8:decode(rang.v)
        end
        imgui.PopItemWidth()

        imgui.SetCursorPos(imgui.ImVec2(176.000000,240.000000));
        if imgui.Button(u8"Сохранить", imgui.ImVec2(100, 20)) then
            mainIni.config.rusname = u8:decode(rusname.v)
            mainIni.config.rang = u8:decode(rang.v)
            sampAddChatMessage("{FFFFFF}Вы успешно изменили ник на:{00BFFF} " .. u8:decode(rusname.v), -1)
            sampAddChatMessage("{FFFFFF}Ваш ранг:{00BFFF} " .. u8:decode(rang.v), -1)
            if inicfg.save(mainIni, directIni) then
                sampAddChatMessage("Сохранено! 2", -1)
            end
        end
    imgui.EndChild()
end
imgui.SameLine()
if menu == 2 then
      imgui.SetCursorPos(imgui.ImVec2(139.000000,25.000000));
    imgui.BeginChild("child2", imgui.ImVec2(450, 265), true)
        imgui.BeginChild("child3", imgui.ImVec2(125, 30), true)
        imgui.SetCursorPos(imgui.ImVec2(17.000000,5.000000));
        imgui.PushItemWidth(30)
        imgui.InputText(u8"ID игрока", pid)
        imgui.PopItemWidth()
        imgui.EndChild()
        imgui.BeginChild("child4", imgui.ImVec2(125, 215), true)
        if imgui.Button(u8"Начать", imgui.ImVec2(100, 20)) then
            sampSendChat("Здравствуйте, я, " .. u8:decode(rang.v) .. " " .. u8:decode(rusname.v) .. " проведу для вас.")
        end

      imgui.EndChild()
    imgui.EndChild()
end
imgui.SameLine()
if menu == 3 then
      imgui.SetCursorPos(imgui.ImVec2(139.000000,25.000000));
    imgui.BeginChild("child2", imgui.ImVec2(450, 265), true)
    imgui.Text("3")
    imgui.EndChild()
end

--         imgui.SetCursorPos(imgui.ImVec2(8.000000,25.000000));
--     if imgui.Button(u8"НАСТРОЙКИ", imgui.ImVec2(125, 40)) then
--         sampSendChat("/n test")
--     end
--         imgui.SetCursorPos(imgui.ImVec2(8.000000,75.000000));
--     if imgui.Button(u8"СОБЕСЕДОВАНИЕ", imgui.ImVec2(125, 40)) then
--
--     end
--     imgui.SetCursorPos(imgui.ImVec2(8.000000,250.000000));
-- if imgui.Button(u8"ИНФО", imgui.ImVec2(125, 40)) then
--     sampSendChat("/n test")
-- end
--//////////////////////////////////////////////////////////////////////BUTTONS




    end

    imgui.End()

end


--sampSendChat("/n test")
 

Вложения

  • Безымянный3.png
    Безымянный3.png
    148.2 KB · Просмотры: 18

Tol4ek

Активный
217
56
Сделал всё, как ты сказал, убрал везде заменил cfg на mainIni, обновил код, но после перезагрузки вот эти знаки вопроса... Сохраняет текст только на Английском.
LUA:
script_name("Test")
script_author("DonHomka")
script_version("0.1.0-beta")

require "lib.moonloader"
local vkeys = require 'vkeys'
local imgui = require 'imgui'
local encoding = require "encoding"
encoding.default = "CP1251"
u8 = encoding.UTF8
imgui.Process = false

local fontsize = nil
function imgui.BeforeDrawFrame()
    if fontsize == nil then
        fontsize = imgui.GetIO().Fonts:AddFontFromFileTTF(getFolderPath(0x14) .. '\\trebucbd.ttf', 15.0, nil, imgui.GetIO().Fonts:GetGlyphRangesCyrillic()) -- вместо 30 любой нужный размер
    end
end

local label = 0
--////////////////////////////////////////// CONFIG
local inicfg = require "inicfg"
local directIni = "moonloader\\TEST\\test.ini"

local data =
{                                                                                                                         -- задаем значения для data.** на случай, если потребуется создать файл конфига
    config =
        {
        rusname = u8"Имя Фамилия",
                rang = u8"Ранг"
    }
}
local mainIni = inicfg.load(data, 'moonloader\\TEST\\test.ini') -- загружаем конфиг
if mainIni == nil then -- проверяем, все ли в порядке. Если нет - создаем конфиг из заданных значений, иначе - загружаем
    print('Не найден файл конфига, создаю.')
    if inicfg.save(mainIni, 'moonloader\\TEST\\test.ini') then
        print('Файл был с настройками был создан, ошибок нет.')
        mainIni = inicfg.load(nil, 'moonloader\\TEST\\test.ini')
    end
end

--//////////////////////////////////////////
local main_color = 0x00BFFF
local main_color_text = 0xFFFAFA
local main_window_state = imgui.ImBool(false)
local rusname = imgui.ImBuffer(256)
local rang = imgui.ImBuffer(256)
local arrSelectable = {false, false}
local pid = imgui.ImBuffer(256)
rusname.v = mainIni.config.rusname
rang.v = mainIni.config.rang



--///////////////////////////////////////Style
function imgui.TextColoredRGB(text, render_text)
    local max_float = imgui.GetWindowWidth()
    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

            local length = imgui.CalcTextSize(w)
            if render_text == 2 then
                imgui.NewLine()
                imgui.SameLine(max_float / 2 - ( length.x / 2 ))
            elseif render_text == 3 then
                imgui.NewLine()
                imgui.SameLine(max_float - length.x - 5 )
            end
            if text[0] then
                for i = 0, #text do
                    imgui.TextColored(colors_[i] or colors[1], text[i])
                    imgui.SameLine(nil, 0)
                end
                imgui.NewLine()
            else imgui.Text(w) end


        end
    end

    render_text(text)
end

function SetStyle()
    imgui.SwitchContext()
    local style = imgui.GetStyle()
    local colors = style.Colors
    local clr = imgui.Col
    local ImVec4 = imgui.ImVec4
    style.ScrollbarSize = 13.0
    style.ScrollbarRounding = 0
    style.ChildWindowRounding = 4.0
    colors[clr.PopupBg]                = ImVec4(0.08, 0.08, 0.08, 0.94)
    colors[clr.ComboBg]                = colors[clr.PopupBg]
    colors[clr.Button]                 = ImVec4(0.26, 0.59, 0.98, 0.40)
    colors[clr.ButtonHovered]          = ImVec4(0.26, 0.59, 0.98, 1.00)
    colors[clr.ButtonActive]           = ImVec4(0.06, 0.53, 0.98, 1.00)
    colors[clr.TitleBg]                = ImVec4(0.04, 0.04, 0.04, 1.00)
    colors[clr.TitleBgActive]          = ImVec4(0.16, 0.29, 0.48, 1.00)
    colors[clr.TitleBgCollapsed]       = ImVec4(0.00, 0.00, 0.00, 0.51)
    colors[clr.CloseButton]            = ImVec4(0.41, 0.41, 0.41, 0.50)-- (0.1, 0.9, 0.1, 1.0)
    colors[clr.CloseButtonHovered]     = ImVec4(0.98, 0.39, 0.36, 1.00)
    colors[clr.CloseButtonActive]      = ImVec4(0.98, 0.39, 0.36, 1.00)
    colors[clr.TextSelectedBg]         = ImVec4(0.26, 0.59, 0.98, 0.35)
    colors[clr.Text]                   = ImVec4(1.00, 1.00, 1.00, 1.00)
    colors[clr.FrameBg]                = ImVec4(0.16, 0.29, 0.48, 0.54)
    colors[clr.FrameBgHovered]         = ImVec4(0.26, 0.59, 0.98, 0.40)
    colors[clr.FrameBgActive]          = ImVec4(0.26, 0.59, 0.98, 0.67)
    colors[clr.MenuBarBg]              = ImVec4(0.14, 0.14, 0.14, 1.00)
    colors[clr.ScrollbarBg]            = ImVec4(0.02, 0.02, 0.02, 0.53)
    colors[clr.ScrollbarGrab]          = ImVec4(0.31, 0.31, 0.31, 1.00)
    colors[clr.ScrollbarGrabHovered]   = ImVec4(0.41, 0.41, 0.41, 1.00)
    colors[clr.ScrollbarGrabActive]    = ImVec4(0.51, 0.51, 0.51, 1.00)
    colors[clr.CheckMark]              = ImVec4(0.26, 0.59, 0.98, 1.00)
    colors[clr.Header]                 = ImVec4(0.26, 0.59, 0.98, 0.31)
    colors[clr.HeaderHovered]          = ImVec4(0.26, 0.59, 0.98, 0.80)
    colors[clr.HeaderActive]           = ImVec4(0.26, 0.59, 0.98, 1.00)
    colors[clr.SliderGrab]             = ImVec4(0.24, 0.52, 0.88, 1.00)
    colors[clr.SliderGrabActive]       = ImVec4(0.26, 0.59, 0.98, 1.00)
end

SetStyle()

--\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end

    sampAddChatMessage("Тест скрипт", main_color_text)
    sampRegisterChatCommand("test", cmd_imgui)

--////////////////////////////////////////// CONFIG
    sampRegisterChatCommand("getsinfoo", cmd_getsinfo)
    sampRegisterChatCommand("getinfoo", cmd_getinfo)
    sampRegisterChatCommand("settname", cmd_settname)
    sampRegisterChatCommand("settrusn", cmd_settrusn)
--//////////////////////////////////////////
    while true do
        wait(0)
if main_window_state.v == false then
    imgui.Process = false
end
    end
end
--////////////////////////////////////////// CONFIG
function cmd_getinfo(arg)
    mainIni = inicfg.load(nil, directIni)
    sampAddChatMessage("{FFFFFF}Ник:{00BFFF} " .. mainIni.config.rang, 0x00BFFF)
    sampAddChatMessage("{FFFFFF}Русский Ник:{00BFFF} " .. mainIni.config.rusname, 0x00BFFF)
end
function cmd_getsinfo(arg)
mainIni = inicfg.load(arg, directIni)
if arg == "rusname" then
sampAddChatMessage(mainIni.config.rusname, -1)
end
if arg == "rang" then
sampAddChatMessage(mainIni.config.rang, -1)
end
end
function cmd_settname(arg)
mainIni.config.rang = arg
if inicfg.save(mainIni, directIni) then
    sampAddChatMessage("Сохранено! 1", -1)
end
end
function cmd_settrusn(arg)
mainIni.config.rusname = arg
if inicfg.save(mainIni, directIni) then
    sampAddChatMessage("Сохранено! 2", -1)
end
end
--//////////////////////////////////////////

function cmd_imgui(arg)
    main_window_state.v = not main_window_state.v
    imgui.Process = main_window_state.v
end

function imgui.OnDrawFrame()

            if not main_window_state.v then
                imgui.Process = false
            end

    if main_window_state.v then
        local sw, sh = getScreenResolution()
        imgui.SetNextWindowPos(imgui.ImVec2(sw / 2, sh / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
        imgui.SetNextWindowSize(imgui.ImVec2(600, 300), imgui.Cond.FirstUseEver)
        imgui.Begin(u8"Собеседование", main_window_state, imgui.WindowFlags.NoResize)

--//////////////////////////////////////////////////////////////////////BUTTONS
imgui.SetCursorPos(imgui.ImVec2(4.000000,25.000000));
imgui.BeginChild("child", imgui.ImVec2(130, 265), true)
imgui.SetCursorPos(imgui.ImVec2(5.000000,5.000000));
if imgui.Button(u8"НАСТРОЙКИ", imgui.ImVec2(120, 40)) then menu = 1 end
imgui.SetCursorPos(imgui.ImVec2(5.000000,50.000000));
if imgui.Button(u8"CОБЕСЕДОВАНИЕ", imgui.ImVec2(120, 40)) then menu = 2 end
imgui.SetCursorPos(imgui.ImVec2(5.000000,220.000000));
if imgui.Button(u8"ИНФО", imgui.ImVec2(120, 40)) then menu = 3 end
imgui.EndChild()

imgui.SameLine()
if menu == 1 then
        imgui.SetCursorPos(imgui.ImVec2(139.000000,25.000000));
    imgui.BeginChild("child2", imgui.ImVec2(450, 265), true)

        imgui.SetCursorPos(imgui.ImVec2(35.000000,22.500000));
        imgui.PushFont(fontsize)
        imgui.Text(u8"Ваш ник (RUS): ")
        imgui.PopFont()

        imgui.SetCursorPos(imgui.ImVec2(135.000000,20.000000));
        imgui.PushItemWidth(150)
        imgui.SameLine()
    if imgui.InputText('', rusname) then
            mainIni.config.rusname = u8:decode(rusname.v)
        end
        imgui.PopItemWidth()

        imgui.SetCursorPos(imgui.ImVec2(35.000000,47.500000));
        imgui.PushFont(fontsize)
        imgui.Text(u8"Ваша должность: ")
        imgui.PopFont()

        imgui.SetCursorPos(imgui.ImVec2(150.000000,45.000000));
        imgui.PushItemWidth(135)
        imgui.SameLine()
        if imgui.InputText(' ', rang) then
            mainIni.config.rusname = u8:decode(rang.v)
        end
        imgui.PopItemWidth()

        imgui.SetCursorPos(imgui.ImVec2(176.000000,240.000000));
        if imgui.Button(u8"Сохранить", imgui.ImVec2(100, 20)) then
            mainIni.config.rusname = u8:decode(rusname.v)
            mainIni.config.rang = u8:decode(rang.v)
            sampAddChatMessage("{FFFFFF}Вы успешно изменили ник на:{00BFFF} " .. u8:decode(rusname.v), -1)
            sampAddChatMessage("{FFFFFF}Ваш ранг:{00BFFF} " .. u8:decode(rang.v), -1)
            if inicfg.save(mainIni, directIni) then
                sampAddChatMessage("Сохранено! 2", -1)
            end
        end
    imgui.EndChild()
end
imgui.SameLine()
if menu == 2 then
      imgui.SetCursorPos(imgui.ImVec2(139.000000,25.000000));
    imgui.BeginChild("child2", imgui.ImVec2(450, 265), true)
        imgui.BeginChild("child3", imgui.ImVec2(125, 30), true)
        imgui.SetCursorPos(imgui.ImVec2(17.000000,5.000000));
        imgui.PushItemWidth(30)
        imgui.InputText(u8"ID игрока", pid)
        imgui.PopItemWidth()
        imgui.EndChild()
        imgui.BeginChild("child4", imgui.ImVec2(125, 215), true)
        if imgui.Button(u8"Начать", imgui.ImVec2(100, 20)) then
            sampSendChat("Здравствуйте, я, " .. u8:decode(rang.v) .. " " .. u8:decode(rusname.v) .. " проведу для вас.")
        end

      imgui.EndChild()
    imgui.EndChild()
end
imgui.SameLine()
if menu == 3 then
      imgui.SetCursorPos(imgui.ImVec2(139.000000,25.000000));
    imgui.BeginChild("child2", imgui.ImVec2(450, 265), true)
    imgui.Text("3")
    imgui.EndChild()
end

--         imgui.SetCursorPos(imgui.ImVec2(8.000000,25.000000));
--     if imgui.Button(u8"НАСТРОЙКИ", imgui.ImVec2(125, 40)) then
--         sampSendChat("/n test")
--     end
--         imgui.SetCursorPos(imgui.ImVec2(8.000000,75.000000));
--     if imgui.Button(u8"СОБЕСЕДОВАНИЕ", imgui.ImVec2(125, 40)) then
--
--     end
--     imgui.SetCursorPos(imgui.ImVec2(8.000000,250.000000));
-- if imgui.Button(u8"ИНФО", imgui.ImVec2(125, 40)) then
--     sampSendChat("/n test")
-- end
--//////////////////////////////////////////////////////////////////////BUTTONS




    end

    imgui.End()

end


--sampSendChat("/n test")
Когда выводишь текст в окне imgui, то кодируй его в u8, а когда сохраняешь, то декодируй из u8
 

CHAPPLE

Участник
Автор темы
97
15
Когда выводишь текст в окне imgui, то кодируй его в u8, а когда сохраняешь, то декодируй из u8
Ты загружаешь конфиг в переменную cfg, а значения берешь из mainIni
Сделай
local mainIni = inicfg.load(mainIni, 'moonloader\\TEST\\test.ini')
вместо
cfg = inicfg.load(nil, 'moonloader\\TEST\\test.ini') (33 строка)
Спасибо Вам!!! ❤️️