script_author("manul")
local ffi = require("ffi")
local imgui = require("mimgui")
local memory = require("memory")
local state = imgui.new.bool(false)
local name = imgui.new.char[25]("")
local colors = {
["Color"] = imgui.new.float[4](1, 1, 1, 1)
}
local list = {}
sampRegisterChatCommand("colorhud", function() state[0] = not state[0] end)
function get_color_u32(arr)
return imgui.GetColorU32Vec4(imgui.ImVec4(arr[0], arr[1], arr[2], arr[3]))
end
function set_colors(color)
memory.write(0xBAB230, color, 4, true)
end
function disable_other()
for key, val in pairs(list) do
val.s = false
end
end
function load_list()
local f = io.open(getWorkingDirectory() .. "\\colorhud.json", "r")
if f ~= nil then
list = decodeJson(f:read("*a"))
f:close()
end
end
function save_json()
local f = io.open(getWorkingDirectory() .. "\\colorhud.json", "w")
f:write(encodeJson(list))
f:close()
end
function main()
load_list()
for key, val in pairs(list) do
if val.s then
set_colors(val.m, val.h, val.w)
end
end
imgui.OnInitialize(init_handler)
imgui.OnFrame(function() return state[0] end, draw_handler)
end
function init_handler()
imgui.SwitchContext()
local style = imgui.GetStyle()
style.WindowPadding = imgui.ImVec2(4.00, 4.00)
style.ItemSpacing = imgui.ImVec2(3.00, 4.00)
style.WindowRounding = 0
style.ChildRounding = 0
style.FrameRounding = 0
end
function draw_handler(player)
imgui.SetNextWindowSize(imgui.ImVec2(400, 425), imgui.Cond.FirstUseEver)
imgui.Begin("Interface colors", state, imgui.WindowFlags.NoResize)
imgui.InputTextWithHint("###name", "Config name", name, 25)
imgui.SameLine()
if imgui.Button("Add", imgui.ImVec2(imgui.GetContentRegionAvail().x / 2, 20.0)) and ffi.string(name) ~= "" then
disable_other()
list[ffi.string(name)] = {
m = get_color_u32(colors["Color"]),
s = true,
}
save_json()
end
imgui.SameLine()
if imgui.Button("Delete", imgui.ImVec2(imgui.GetContentRegionAvail().x, 20.0)) and ffi.string(name) ~= "" then
list[ffi.string(name)] = nil
save_json()
end
for key, _ in pairs(colors) do
if imgui.ColorEdit4(key, colors[key], imgui.ColorEditFlags.AlphaBar) then
set_colors(get_color_u32(colors["Color"]), get_color_u32(colors["Color"]), get_color_u32(colors["Color"]))
end
end
imgui.BeginChild("###list", imgui.GetContentRegionAvail(), true)
for key, val in pairs(list) do
if imgui.Selectable(key, val.s) then
disable_other()
set_colors(val.m, val.h, val.w)
val.s = true
save_json()
end
end
imgui.EndChild()
imgui.End()
end