-- 1. imgui_addons
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()
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[tostring(str_id)] = true
end
local t = bool.v and 1.0 or 0.0
if LastActive[tostring(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[tostring(str_id)] = false
end
end
local col_bg
if bool.v then
col_bg = imgui.GetColorU32(imgui.GetStyle().Colors[imgui.Col.FrameBgHovered])
else
col_bg = imgui.ImColor(100, 100, 100, 180):GetU32()
end
draw_list:AddRectFilled(imgui.ImVec2(p.x, p.y + (height / 6)), imgui.ImVec2(p.x + width - 1.0, p.y + (height - (height / 6))), col_bg, 5.0)
draw_list:AddCircleFilled(imgui.ImVec2(p.x + radius + t * (width - radius * 2.0), p.y + radius), radius - 0.75, imgui.GetColorU32(bool.v and imgui.GetStyle().Colors[imgui.Col.ButtonActive] or imgui.ImColor(150, 150, 150, 255):GetVec4()))
return rBool
end
-- 2. rkeys
local inicfg = require 'inicfg'
local vkeys = require 'vkeys'
local HLcfg = inicfg.load({
config = {
button = 72
}
}, "Test.ini")
inicfg.save(HLcfg, "Test.ini")
function main()
menu = { actMenu = HLcfg.config.button, buttonName = vkeys.key_names[HLcfg.config.button], edit = false, ticked = os.clock(), tickedState = false }
end
function getDownKeys()
local curkeys = ""
local bool = false
for k, v in pairs(vkeys) do
if isKeyDown(v) then
curkeys = v
bool = true
end
end
return curkeys, bool
end
-- imgui
if menu.edit then
local downKey = getDownKeys()
HLcfg.config.button = downKey
if downKey == '' then
if os.clock() - menu.ticked > 0.5 then
menu.ticked = os.clock()
menu.tickedState = not menu.tickedState
end
menu.buttonName = menu.tickedState and "No" or "##justClear"..menu.ticked
else
menu.buttonName = vkeys.key_names[menu.button]
menu.edit = false
save()
end
end
if imgui.Button(u8(tostring(menu.buttonName)), imgui.ImVec2(80, 0)) then
menu.edit = true
end imgui.SameLine() imgui.Text(u8"Активация открытия меню")
-- imgui
function save()
inicfg.save(HLcfg, "Test.ini")
end