Описание: Кнопка для навигации меню
Пример использования:
Код:
Возможно в вашем имгуи стиле цвет кнопки будет уебищный
Демонстрация:
Описание: Чекбокс с анимацией. Хотел сделать так, чтобы можно было переключать состояние во время анимации, но реализовать без багов, к сожалению, не получилось, поэтому выкладываю с кд на переключение
Пример использования:
Код:
Демонстрация:
Пример использования:
Lua:
local nav = {
sel = new.int(config.LastMenu),
list = {
{name = 'Onfoot', icon = 'USER'}, {name = 'Incar', icon = 'CAR'}, {name = 'Weapon', icon = 'GUN'}
}
}
imgui.OnFrame(
function() return renderWindow[0] end,
function(self)
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(400, 200), imgui.Cond.FirstUseEver)
imgui.Begin("Test", renderWindow)
for i, item in ipairs(nav.list) do
imgui.CustomMenuItem(i, item)
end
imgui.End()
end
)
Lua:
function imgui.CustomMenuItem(index, item, size, duration)
local function bringVec2To(from, to, start_time, duration) -- by Cosmo
local timer = os.clock() - start_time
if timer >= 0.00 and timer <= duration then
local count = timer / (duration / 100)
return imgui.ImVec2(
from.x + (count * (to.x - from.x) / 100),
from.y + (count * (to.y - from.y) / 100)
), true
end
return (timer > duration) and to or from, false
end
local DL = imgui.GetWindowDrawList()
local p = imgui.GetCursorScreenPos()
local size = size or imgui.ImVec2(150, 35)
local duration = duration or 0.2
local str_id = item.name .. '##' .. index
if UI_CUSTOM_MENU_ITEM == nil then UI_CUSTOM_MENU_ITEM = {} end
if UI_CUSTOM_MENU_ITEM[str_id] == nil then
UI_CUSTOM_MENU_ITEM[str_id] = {
pos1 = nav.sel[0] == index and imgui.ImVec2(p.x, p.y + size.y / 2) or imgui.ImVec2(p.x, p.y),
pos2 = nav.sel[0] == index and imgui.ImVec2(p.x + size.x, p.y + size.y / 2) or imgui.ImVec2(p.x + size.x, p.y + size.y),
pos3 = imgui.ImVec2(p.x + size.x - 5, p.y + size.y / 2),
pos4 = imgui.ImVec2(p.x + size.x - 1, p.y + size.y / 2),
hovered = false,
active = nav.sel[0] == index and true or false,
h_start = 0,
a_start = 0,
}
end
local pool = UI_CUSTOM_MENU_ITEM[str_id]
imgui.InvisibleButton(str_id, size)
local clicked = imgui.IsItemClicked()
local hovered = imgui.IsItemHovered()
if hovered ~= pool.hovered and nav.sel[0] ~= index then
pool.hovered = hovered
local timer = os.clock() - pool.h_start
if timer <= duration and timer >= 0 then
pool.h_start = os.clock() - (duration - timer)
else
pool.h_start = os.clock()
end
end
if clicked and nav.sel[0] ~= index then
pool.active = true
nav.sel[0] = index
local timer = os.clock() - pool.a_start
if timer <= duration and timer >= 0 then
pool.a_start = os.clock() - (duration - timer)
else
pool.a_start = os.clock()
end
elseif pool.active and nav.sel[0] ~= index then
pool.active = false
local timer = os.clock() - pool.a_start
if timer <= duration and timer >= 0 then
pool.a_start = os.clock() - (duration - timer)
else
pool.a_start = os.clock()
end
if pool.h_start == 0 then
pool.h_start = os.clock()
end
end
pool.pos1 = bringVec2To(
(pool.hovered or nav.sel[0] == index) and imgui.ImVec2(p.x, p.y + size.y / 2) or imgui.ImVec2(p.x, p.y),
(pool.hovered or nav.sel[0] == index) and imgui.ImVec2(p.x, p.y) or imgui.ImVec2(p.x, p.y + size.y / 2),
pool.h_start,
duration
)
pool.pos2 = bringVec2To(
(pool.hovered or nav.sel[0] == index) and imgui.ImVec2(p.x + size.x, p.y + size.y / 2) or imgui.ImVec2(p.x + size.x, p.y + size.y),
(pool.hovered or nav.sel[0] == index) and imgui.ImVec2(p.x + size.x, p.y + size.y) or imgui.ImVec2(p.x + size.x, p.y + size.y / 2),
pool.h_start,
duration
)
pool.pos3 = bringVec2To(
nav.sel[0] == index and imgui.ImVec2(p.x + size.x - 5, p.y + size.y / 2) or imgui.ImVec2(p.x + size.x - 5, p.y + size.y / 4),
nav.sel[0] == index and imgui.ImVec2(p.x + size.x - 5, p.y + size.y / 4) or imgui.ImVec2(p.x + size.x - 5, p.y + size.y / 2),
pool.a_start,
duration
)
pool.pos4 = bringVec2To(
nav.sel[0] == index and imgui.ImVec2(p.x + size.x - 1, p.y + size.y / 2) or imgui.ImVec2(p.x + size.x - 1, p.y + size.y / 4 + size.y / 2),
nav.sel[0] == index and imgui.ImVec2(p.x + size.x - 1, p.y + size.y / 4 + size.y / 2) or imgui.ImVec2(p.x + size.x - 1, p.y + size.y / 2),
pool.a_start,
duration
)
local color1 = (pool.hovered or nav.sel[0] == index or os.clock() - pool.h_start <= duration) and imgui.GetStyle().Colors[imgui.Col.SeparatorActive] or imgui.ImVec4(0,0,0,0)
local color2 = (nav.sel[0] == index or os.clock() - pool.a_start <= duration) and imgui.GetStyle().Colors[imgui.Col.Text] or imgui.ImVec4(0,0,0,0)
local color3 = imgui.GetStyle().Colors[imgui.Col.Text]
DL:AddRectFilled(pool.pos1, pool.pos2, imgui.GetColorU32Vec4(color1), 10, 15)
DL:AddRectFilled(pool.pos3, pool.pos4, imgui.GetColorU32Vec4(color2), 5, 15)
local si = imgui.CalcTextSize(faicons(item.icon))
local st = imgui.CalcTextSize(item.name)
DL:AddText(imgui.ImVec2(p.x + 15, p.y + size.y/2 - si.y/2), imgui.GetColorU32Vec4(color3), faicons(item.icon))
DL:AddText(imgui.ImVec2(p.x + 45, p.y + size.y/2 - st.y/2), imgui.GetColorU32Vec4(color3), item.name)
return clicked
end
Демонстрация:
Описание: Чекбокс с анимацией. Хотел сделать так, чтобы можно было переключать состояние во время анимации, но реализовать без багов, к сожалению, не получилось, поэтому выкладываю с кд на переключение
Пример использования:
Lua:
local checkbox = new.bool(false)
imgui.OnFrame(
function() return renderWindow[0] end,
function(self)
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(400, 200), imgui.Cond.FirstUseEver)
imgui.Begin("Test", renderWindow)
imgui.CustomCheckbox('Checkbox', checkbox)
imgui.End()
end
)
Lua:
function imgui.CustomCheckbox(str_id, bool, a_speed)
local p = imgui.GetCursorScreenPos()
local DL = imgui.GetWindowDrawList()
local label = str_id:gsub('##.+', '') or ""
local h = imgui.GetTextLineHeightWithSpacing() + 2
local speed = a_speed or 0.2
local function bringVec2To(from, to, start_time, duration)
local timer = os.clock() - start_time
if timer >= 0.00 and timer <= duration then
local count = timer / (duration / 100)
return imgui.ImVec2(
from.x + (count * (to.x - from.x) / 100),
from.y + (count * (to.y - from.y) / 100)
), true
end
return (timer > duration) and to or from, false
end
local function bringVec4To(from, to, start_time, duration)
local timer = os.clock() - start_time
if timer >= 0.00 and timer <= duration then
local count = timer / (duration / 100)
return imgui.ImVec4(
from.x + (count * (to.x - from.x) / 100),
from.y + (count * (to.y - from.y) / 100),
from.z + (count * (to.z - from.z) / 100),
from.w + (count * (to.w - from.w) / 100)
), true
end
return (timer > duration) and to or from, false
end
local c = {
{0.18536826495, 0.42833250947},
{0.44109925858, 0.70010380622},
{0.38825341901, 0.70010380622},
{0.81248970176, 0.28238693976},
}
if UI_CUSTOM_CHECKBOX == nil then UI_CUSTOM_CHECKBOX = {} end
if UI_CUSTOM_CHECKBOX[str_id] == nil then
UI_CUSTOM_CHECKBOX[str_id] = {
lines = {
{
from = imgui.ImVec2(0, 0),
to = imgui.ImVec2(h*c[1][1], h*c[1][2]),
start = 0,
anim = false,
},
{
from = imgui.ImVec2(0, 0),
to = bool[0] and imgui.ImVec2(h*c[2][1], h*c[2][2]) or imgui.ImVec2(h*c[1][1], h*c[1][2]),
start = 0,
anim = false,
},
{
from = imgui.ImVec2(0, 0),
to = imgui.ImVec2(h*c[3][1], h*c[3][2]),
start = 0,
anim = false,
},
{
from = imgui.ImVec2(0, 0),
to = bool[0] and imgui.ImVec2(h*c[4][1], h*c[4][2]) or imgui.ImVec2(h*c[3][1], h*c[3][2]),
start = 0,
anim = false,
},
},
hovered = false,
h_start = 0,
}
end
local pool = UI_CUSTOM_CHECKBOX[str_id]
imgui.BeginGroup()
imgui.InvisibleButton(str_id, imgui.ImVec2(h, h))
imgui.SameLine()
local pp = imgui.GetCursorPos()
imgui.SetCursorPos(imgui.ImVec2(pp.x, pp.y + h/2 - imgui.CalcTextSize(label).y/2))
imgui.Text(label)
imgui.EndGroup()
local clicked = imgui.IsItemClicked()
if pool.hovered ~= imgui.IsItemHovered() then
pool.hovered = imgui.IsItemHovered()
local timer = os.clock() - pool.h_start
if timer <= speed and timer >= 0 then
pool.h_start = os.clock() - (speed - timer)
else
pool.h_start = os.clock()
end
end
if clicked then
local isAnim = false
for i = 1, 4 do
if pool.lines[i].anim then
isAnim = true
end
end
if not isAnim then
bool[0] = not bool[0]
pool.lines[1].from = imgui.ImVec2(h*c[1][1], h*c[1][2])
pool.lines[1].to = bool[0] and imgui.ImVec2(h*c[1][1], h*c[1][2]) or imgui.ImVec2(h*c[2][1], h*c[2][2])
pool.lines[1].start = bool[0] and 0 or os.clock()
pool.lines[2].from = bool[0] and imgui.ImVec2(h*c[1][1], h*c[1][2]) or imgui.ImVec2(h*c[2][1], h*c[2][2])
pool.lines[2].to = bool[0] and imgui.ImVec2(h*c[2][1], h*c[2][2]) or imgui.ImVec2(h*c[2][1], h*c[2][2])
pool.lines[2].start = bool[0] and os.clock() or 0
pool.lines[3].from = imgui.ImVec2(h*c[3][1], h*c[3][2])
pool.lines[3].to = bool[0] and imgui.ImVec2(h*c[3][1], h*c[3][2]) or imgui.ImVec2(h*c[4][1], h*c[4][2])
pool.lines[3].start = bool[0] and 0 or os.clock() + speed
pool.lines[4].from = bool[0] and imgui.ImVec2(h*c[3][1], h*c[3][2]) or imgui.ImVec2(h*c[4][1], h*c[4][2])
pool.lines[4].to = imgui.ImVec2(h*c[4][1], h*c[4][2]) or imgui.ImVec2(h*c[4][1], h*c[4][2])
pool.lines[4].start = bool[0] and os.clock() + speed or 0
end
end
local pos = {}
for i = 1, 4 do
pos[i], pool.lines[i].anim = bringVec2To(
p + pool.lines[i].from,
p + pool.lines[i].to,
pool.lines[i].start,
speed
)
end
local color = imgui.GetStyle().Colors[imgui.Col.ButtonActive]
local c = imgui.GetStyle().Colors[imgui.Col.ButtonHovered]
local colorHovered = bringVec4To(
pool.hovered and imgui.ImVec4(c.x, c.y, c.z, 0) or imgui.ImVec4(c.x, c.y, c.z, 0.2),
pool.hovered and imgui.ImVec4(c.x, c.y, c.z, 0.2) or imgui.ImVec4(c.x, c.y, c.z, 0),
pool.h_start,
speed
)
DL:AddRectFilled(p, imgui.ImVec2(p.x + h, p.y + h), imgui.GetColorU32Vec4(colorHovered), h/15, 15)
DL:AddRect(p, imgui.ImVec2(p.x + h, p.y + h), imgui.GetColorU32Vec4(color), h/15, 15, 1.5)
DL:AddLine(pos[1], pos[2], imgui.GetColorU32Vec4(color), h/10)
DL:AddLine(pos[3], pos[4], imgui.GetColorU32Vec4(color), h/10)
return clicked
end
Последнее редактирование: