Как в скрипте менять темы?

McR

Участник
Автор темы
257
14
  • Привет, мне нужно код который в скрипте делает вкладку темы где есть разные темы и их можно было менять прямо в игре
    Снимок.PNG
 

chapo

🫡 В армии с 17.10.2023. В ЛС НЕ ОТВЕЧАЮ
Друг
8,747
11,157
Думаю разберешься
Lua:
local imgui = require 'imgui'
local encoding = require "encoding"
encoding.default = "CP1251"
u8 = encoding.UTF8

local main_window_state = imgui.ImBool(false)
local state = false
local themes = import 'resource/imgui_themes.lua'


function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end
    sampRegisterChatCommand('imgui', cmd_test)
  
    imgui.SwitchContext()
    themes.SwitchColorTheme(4) -- изначальная тема

    while true do
      wait(0)
    
if main_window_state.v == false then
    imgui.Process = false
    end
  end
end

function cmd_test()
    main_window_state.v = not main_window_state.v
    imgui.Process = main_window_state.v
end

function imgui.OnDrawFrame()
    local ex, ey = getScreenResolution()
        imgui.SetNextWindowSize(imgui.ImVec2(400, 200), imgui.Cond.FirstUseEver)
        imgui.SetNextWindowPos(imgui.ImVec2(ex / 2, ey / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))

    imgui.Begin('Imgui window ', main_window_state)

    if imgui.Button('BLUE') then -- при нажатии на кнопку будет эта тема
    imgui.SwitchContext()
    themes.SwitchColorTheme(1)
    end
  
    imgui.SameLine()
  
    if imgui.Button('RED') then
    imgui.SwitchContext()
    themes.SwitchColorTheme(2)
    end
  
    imgui.SameLine()
  
    if imgui.Button('BROWN') then
    imgui.SwitchContext()
    themes.SwitchColorTheme(3)
    end
  
    imgui.SameLine()
  
    if imgui.Button('AQUA') then
    imgui.SwitchContext()
    themes.SwitchColorTheme(4)
    end
  
    imgui.SameLine()
  
    if imgui.Button('BLACK') then
    imgui.SwitchContext()
    themes.SwitchColorTheme(5)
    end
  
    imgui.SameLine()
  
    if imgui.Button('PURPLE') then
    imgui.SwitchContext()
    themes.SwitchColorTheme(6)
    end
  
    imgui.SameLine()
  
    if imgui.Button('ORANGE') then
    imgui.SwitchContext()
    themes.SwitchColorTheme(7)
    end
    imgui.End()
end
imgui_thems в папку resource, если нету - создаешь
зачем тащить за собой файл с темами если все это можно сделать в самом скрипте?
 

McR

Участник
Автор темы
257
14
Думаю разберешься
Lua:
local imgui = require 'imgui'
local encoding = require "encoding"
encoding.default = "CP1251"
u8 = encoding.UTF8

local main_window_state = imgui.ImBool(false)
local state = false
local themes = import 'resource/imgui_themes.lua'


function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end
    sampRegisterChatCommand('imgui', cmd_test)
  
    imgui.SwitchContext()
    themes.SwitchColorTheme(4) -- изначальная тема

    while true do
      wait(0)
    
if main_window_state.v == false then
    imgui.Process = false
    end
  end
end

function cmd_test()
    main_window_state.v = not main_window_state.v
    imgui.Process = main_window_state.v
end

function imgui.OnDrawFrame()
    local ex, ey = getScreenResolution()
        imgui.SetNextWindowSize(imgui.ImVec2(400, 200), imgui.Cond.FirstUseEver)
        imgui.SetNextWindowPos(imgui.ImVec2(ex / 2, ey / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))

    imgui.Begin('Imgui window ', main_window_state)

    if imgui.Button('BLUE') then -- при нажатии на кнопку будет эта тема
    imgui.SwitchContext()
    themes.SwitchColorTheme(1)
    end
  
    imgui.SameLine()
  
    if imgui.Button('RED') then
    imgui.SwitchContext()
    themes.SwitchColorTheme(2)
    end
  
    imgui.SameLine()
  
    if imgui.Button('BROWN') then
    imgui.SwitchContext()
    themes.SwitchColorTheme(3)
    end
  
    imgui.SameLine()
  
    if imgui.Button('AQUA') then
    imgui.SwitchContext()
    themes.SwitchColorTheme(4)
    end
  
    imgui.SameLine()
  
    if imgui.Button('BLACK') then
    imgui.SwitchContext()
    themes.SwitchColorTheme(5)
    end
  
    imgui.SameLine()
  
    if imgui.Button('PURPLE') then
    imgui.SwitchContext()
    themes.SwitchColorTheme(6)
    end
  
    imgui.SameLine()
  
    if imgui.Button('ORANGE') then
    imgui.SwitchContext()
    themes.SwitchColorTheme(7)
    end
    imgui.End()
end
imgui_thems в папку resource, если нету - создаешь
мне нужно чтобы было в самом скрипте без сторонних скриптов
Теперь вот такая ошибка
 

Вложения

  • изображение_2021-09-01_115602.png
    изображение_2021-09-01_115602.png
    17.6 KB · Просмотры: 14
Последнее редактирование: