Сохранение оформления (mimgui)

$Mr.R1ch$

Активный
Автор темы
243
33
Версия MoonLoader
Другое
Пытался сделать сохранение темы для мимгуи. Записал всё в inicfg, но при перезагрузке скрипта тема сбрасывается, сохраняется только значение комбо. Что тут не так в коде, подскажите?

Lua:
local inicfg = require 'inicfg'
local ini = inicfg.load({
theme = "blue"
selected = 0
}, "MVD.ini")

local selected_theme = new.int(ini.theme.selected)
local theme_a = {u8'Синий', u8'Оранжевый'}
local theme_t = {u8'blue', u8'orange'}
local itemtheme = imgui.new['const char*'][#theme_a](theme_a)

function apply_n_t()
    if ini.theme.theme == 'blue' then
        blue_theme()
        inicfg.save(ini, "MVD.ini")
    elseif ini.theme.theme == 'orange' then
      orange_theme()
      inicfg.save(ini, "MVD.ini")
 end
      end

imgui.OnFrame(function() return WinStateM[0] end, function(player)
    local sizeX, sizeY = getScreenResolution()
    imgui.SetNextWindowPos(imgui.ImVec2(sizeX / 2, sizeY / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
    imgui.SetNextWindowSize(imgui.ImVec2(1800, 800), imgui.Cond.Always)
    imgui.PushStyleColor(imgui.Col.WindowBg, imgui.ImVec4(0, 0, 0, 1))
    imgui.Begin(u8'Title!', WinStateM, imgui.WindowFlags.NoResize) 
--apply_n_t()-- вставлял эту функцию сюда но фпс до 1 присаживается 
if imgui.Combo(u8'##theme', selected_theme, itemtheme, #theme_a) then
                themeta = theme_t[selected_theme[0]+1]
                ini.theme.theme = themeta
                ini.theme.selected = selected_theme[0]
                inicfg.save(ini, "MVD.ini")
                apply_n_t()
            end
imgui.End()
end)

imgui.OnInitialize(function()
blue_theme()
end)


function blue_theme()
    imgui.SwitchContext()
    local style = imgui.GetStyle()
    local colors = style.Colors
    local clr = imgui.Col
    local ImVec4 = imgui.ImVec4

    imgui.GetStyle().WindowPadding = imgui.ImVec2(5, 5)
    imgui.GetStyle().WindowTitleAlign = imgui.ImVec2(0.5, 0.5) -- заголовок окна
    imgui.GetStyle().FramePadding = imgui.ImVec2(5, 5)
    imgui.GetStyle().ItemSpacing = imgui.ImVec2(5, 4)
    imgui.GetStyle().ItemInnerSpacing = imgui.ImVec2(2, 2)
    imgui.GetStyle().TouchExtraPadding = imgui.ImVec2(0, 0)
    imgui.GetStyle().IndentSpacing = 0
    imgui.GetStyle().ScrollbarSize = 23 -- размер скролла (ползунка)
    imgui.GetStyle().GrabMinSize = 15

    --==[ BORDER ]==--
    imgui.GetStyle().WindowBorderSize = 1
    imgui.GetStyle().ChildBorderSize = 2
    imgui.GetStyle().PopupBorderSize = 0
    imgui.GetStyle().FrameBorderSize = 0 --обводка кнопок, импутов, чекбоксов и тп
    imgui.GetStyle().TabBorderSize = 0

    --==[ ROUNDING ]==--
    imgui.GetStyle().WindowRounding = 6 --  края окон
    imgui.GetStyle().ChildRounding = 6 -- края begin child
    imgui.GetStyle().FrameRounding = 4 -- края кнопок
    imgui.GetStyle().PopupRounding = 0
    imgui.GetStyle().ScrollbarRounding = 1 -- края ползунка
    imgui.GetStyle().GrabRounding = 1
    imgui.GetStyle().TabRounding = 8

    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.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.CheckMark]              = 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)
    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.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.Separator]              = colors[clr.Border]
    colors[clr.SeparatorHovered]       = ImVec4(0.26, 0.59, 0.98, 0.78)
    colors[clr.SeparatorActive]        = ImVec4(0.26, 0.59, 0.98, 1.00)
    colors[clr.ResizeGrip]             = ImVec4(0.26, 0.59, 0.98, 0.25)
    colors[clr.ResizeGripHovered]      = ImVec4(0.26, 0.59, 0.98, 0.67)
    colors[clr.ResizeGripActive]       = ImVec4(0.26, 0.59, 0.98, 0.95)
    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.TextDisabled]           = ImVec4(0.50, 0.50, 0.50, 1.00)
    colors[clr.WindowBg]               = ImVec4(0.06, 0.06, 0.06, 0.94)
    colors[clr.ChildBg]          = ImVec4(1.00, 1.00, 1.00, 0.00)
    colors[clr.PopupBg]                = ImVec4(0.08, 0.08, 0.08, 0.94)
    colors[clr.Border]                 = ImVec4(0.43, 0.43, 0.50, 0.50)
    colors[clr.BorderShadow]           = ImVec4(0.00, 0.00, 0.00, 0.00)
    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.26, 0.59, 0.98, 0.40)
    colors[clr.ScrollbarGrabHovered]   = ImVec4(0.41, 0.41, 0.41, 1.00)
    colors[clr.ScrollbarGrabActive]    = ImVec4(0.26, 0.59, 0.98, 0.80)
    colors[clr.PlotLines]              = ImVec4(0.61, 0.61, 0.61, 1.00)
    colors[clr.PlotLinesHovered]       = ImVec4(1.00, 0.43, 0.35, 1.00)
    colors[clr.PlotHistogram]          = ImVec4(0.90, 0.70, 0.00, 1.00)
    colors[clr.PlotHistogramHovered]   = ImVec4(1.00, 0.60, 0.00, 1.00)
    end

function orange_theme()
    imgui.SwitchContext()
    local style = imgui.GetStyle()
    local colors = style.Colors
    local clr = imgui.Col
    local ImVec4 = imgui.ImVec4

    imgui.GetStyle().WindowPadding = imgui.ImVec2(5, 5)
    imgui.GetStyle().WindowTitleAlign = imgui.ImVec2(0.5, 0.5) -- заголовок окна
    imgui.GetStyle().FramePadding = imgui.ImVec2(5, 5)
    imgui.GetStyle().ItemSpacing = imgui.ImVec2(5, 4)
    imgui.GetStyle().ItemInnerSpacing = imgui.ImVec2(2, 2)
    imgui.GetStyle().TouchExtraPadding = imgui.ImVec2(0, 0)
    imgui.GetStyle().IndentSpacing = 0
    imgui.GetStyle().ScrollbarSize = 23 -- размер скролла (ползунка)
    imgui.GetStyle().GrabMinSize = 15

    --==[ BORDER ]==--
    imgui.GetStyle().WindowBorderSize = 1
    imgui.GetStyle().ChildBorderSize = 2
    imgui.GetStyle().PopupBorderSize = 0
    imgui.GetStyle().FrameBorderSize = 0 --обводка кнопок, импутов, чекбоксов и тп
    imgui.GetStyle().TabBorderSize = 0

    --==[ ROUNDING ]==--
    imgui.GetStyle().WindowRounding = 6 --  края окон
    imgui.GetStyle().ChildRounding = 6 -- края begin child
    imgui.GetStyle().FrameRounding = 4 -- края кнопок
    imgui.GetStyle().PopupRounding = 0
    imgui.GetStyle().ScrollbarRounding = 1 -- края ползунка
    imgui.GetStyle().GrabRounding = 1
    imgui.GetStyle().TabRounding = 8

    colors[clr.FrameBg]                = ImVec4(0.52, 0.21, 0.18, 0.54)
    colors[clr.FrameBgHovered]         = ImVec4(0.93, 0.45, 0.33, 0.40)
    colors[clr.FrameBgActive]          = ImVec4(0.93, 0.45, 0.33, 0.67)
    colors[clr.TitleBg]                = ImVec4(0.04, 0.04, 0.04, 0.40)
    colors[clr.TitleBgActive]          = ImVec4(0.93, 0.45, 0.33, 1.00)
    colors[clr.TitleBgCollapsed]       = ImVec4(0.00, 0.00, 0.00, 0.51)
    colors[clr.CheckMark]              = ImVec4(0.93, 0.45, 0.33, 1.00)
    colors[clr.SliderGrab]             = ImVec4(0.92, 0.44, 0.32, 1.00)
    colors[clr.SliderGrabActive]       = ImVec4(0.93, 0.45, 0.98, 1.00)
    colors[clr.Button]                 = ImVec4(0.93, 0.45, 0.33, 0.40)
    colors[clr.ButtonHovered]          = ImVec4(0.93, 0.45, 0.33, 1.00)
    colors[clr.ButtonActive]           = ImVec4(0.93, 0.45, 0.33, 1.00)
    colors[clr.Header]                 = ImVec4(0.83, 0.35, 0.23, 0.50)
    colors[clr.HeaderHovered]          = ImVec4(0.93, 0.45, 0.33, 0.80)
    colors[clr.HeaderActive]           = ImVec4(0.93, 0.45, 0.33, 1.00)
    colors[clr.Separator]              = colors[clr.Border]
    colors[clr.SeparatorHovered]       = ImVec4(0.93, 0.45, 0.33, 0.78)
    colors[clr.SeparatorActive]        = ImVec4(0.93, 0.45, 0.33, 1.00)
    colors[clr.ResizeGrip]             = ImVec4(0.93, 0.45, 0.33, 0.25)
    colors[clr.ResizeGripHovered]      = ImVec4(0.93, 0.45, 0.33, 0.67)
    colors[clr.ResizeGripActive]       = ImVec4(0.93, 0.45, 0.33, 0.95)
    colors[clr.TextSelectedBg]         = ImVec4(0.93, 0.45, 0.33, 0.35)
    colors[clr.Text]                   = ImVec4(1.00, 1.00, 1.00, 1.00)
    colors[clr.TextDisabled]           = ImVec4(0.50, 0.50, 0.50, 1.00)
    colors[clr.WindowBg]               = ImVec4(0.06, 0.06, 0.06, 0.94)
    colors[clr.ChildBg]          = ImVec4(1.00, 1.00, 1.00, 0.00)
    colors[clr.PopupBg]                = ImVec4(0.08, 0.08, 0.08, 0.94)
    colors[clr.Border]                 = ImVec4(0.43, 0.43, 0.50, 0.50)
    colors[clr.BorderShadow]           = ImVec4(0.00, 0.00, 0.00, 0.00)
    colors[clr.MenuBarBg]              = ImVec4(0.93, 0.45, 0.33, 1.00)
    colors[clr.ScrollbarBg]            = ImVec4(0.02, 0.02, 0.02, 0.53)
    colors[clr.ScrollbarGrab]          = ImVec4(0.93, 0.45, 0.33, 1.00)
    colors[clr.ScrollbarGrabHovered]   = ImVec4(0.41, 0.41, 0.41, 1.00)
    colors[clr.ScrollbarGrabActive]    = ImVec4(0.93, 0.45, 0.33, 0.80)
    colors[clr.PlotLines]              = ImVec4(0.61, 0.61, 0.61, 1.00)
    colors[clr.PlotLinesHovered]       = ImVec4(1.00, 0.43, 0.35, 1.00)
    colors[clr.PlotHistogram]          = ImVec4(0.90, 0.70, 0.00, 1.00)
    colors[clr.PlotHistogramHovered]   = ImVec4(1.00, 0.60, 0.00, 1.00)
    end
 
Последнее редактирование:
  • Ха-ха
  • Эм
Реакции: Vespan и MLycoris

MLycoris

На вид оружие массового семяизвержения
Проверенный
1,993
2,181
 

$Mr.R1ch$

Активный
Автор темы
243
33
Обновил немного код
 

MLycoris

На вид оружие массового семяизвержения
Проверенный
1,993
2,181
  • Нравится
Реакции: $Mr.R1ch$