- 41
- 6
- Версия MoonLoader
- Другое
Привет, у меня возникла проблема с добавлением фона, который не соответствует кнопке, и когда я навожу курсор мыши на нужную кнопку, он часто не соответствует отображаемому тексту или значку.
cr> https://www.blast.hk/threads/13380/post-814506
Это то, что я пытаюсь создать.
cr> https://www.blast.hk/threads/13380/post-814506
Это то, что я пытаюсь создать.
Lua:
function imgui.HeaderBottom(bool, str_id)
local DL = imgui.GetWindowDrawList()
local ToU32 = imgui.ColorConvertFloat4ToU32
local result = false
local label = string.gsub(str_id, "##.*$", "")
local duration = { 0.5, 0.3 }
local cols = {
idle = imgui.GetStyle().Colors[imgui.Col.TextDisabled],
hovr = imgui.GetStyle().Colors[imgui.Col.Text],
slct = imgui.GetStyle().Colors[imgui.Col.ButtonActive],
bg_idle = imgui.ImVec4(0.2, 0.2, 0.2, 1.0), -- สีพื้นหลังปกติ
bg_hovr = imgui.ImVec4(0.4, 0.4, 0.4, 1.0), -- สีพื้นหลังเมื่อชี้เมาส์
bg_slct = imgui.ImVec4(0.1, 0.5, 0.8, 1.0) -- สีพื้นหลังเมื่อเลือก
}
local spacing = 10
if not AI_HEADERBUT then AI_HEADERBUT = {} end
if not AI_HEADERBUT[str_id] then
AI_HEADERBUT[str_id] = {
color = bool and cols.slct or cols.idle,
clock = os.clock() + duration[1],
h = {
state = bool,
alpha = bool and 1.00 or 0.00,
clock = os.clock() + duration[2],
}
}
end
local pool = AI_HEADERBUT[str_id]
local degrade = function(before, after, start_time, duration)
local result = before
local timer = os.clock() - start_time
if timer >= 0.00 then
local offs = {
x = after.x - before.x,
y = after.y - before.y,
z = after.z - before.z,
w = after.w - before.w
}
result.x = result.x + ( (offs.x / duration) * timer )
result.y = result.y + ( (offs.y / duration) * timer )
result.z = result.z + ( (offs.z / duration) * timer )
result.w = result.w + ( (offs.w / duration) * timer )
end
return result
end
local pushFloatTo = function(p1, p2, clock, duration)
local result = p1
local timer = os.clock() - clock
if timer >= 0.00 then
local offs = p2 - p1
result = result + ((offs / duration) * timer)
end
return result
end
local set_alpha = function(color, alpha)
return imgui.ImVec4(color.x, color.y, color.z, alpha or 1.00)
end
imgui.BeginGroup()
local pos = imgui.GetCursorPos()
local p = imgui.GetCursorScreenPos()
local s = imgui.CalcTextSize(label)
local hovered = imgui.IsItemHovered()
local clicked = imgui.IsItemClicked()
-- กำหนดสีพื้นหลังตามสถานะ
local bg_color = bool and cols.bg_slct or (hovered and cols.bg_hovr or cols.bg_idle)
DL:AddRectFilled(imgui.ImVec2(p.x, p.y), imgui.ImVec2(p.x + s.x + spacing * 2, p.y + s.y), ToU32(bg_color))
imgui.SetCursorPosX(pos.x + spacing)
imgui.TextColored(pool.color, label)
if pool.h.state ~= hovered and not bool then
pool.h.state = hovered
pool.h.clock = os.clock()
end
if clicked then
pool.clock = os.clock()
result = true
end
if os.clock() - pool.clock <= duration[1] then
pool.color = degrade(
imgui.ImVec4(pool.color),
bool and cols.slct or (hovered and cols.hovr or cols.idle),
pool.clock,
duration[1]
)
else
pool.color = bool and cols.slct or (hovered and cols.hovr or cols.idle)
end
if pool.h.clock ~= nil then
if os.clock() - pool.h.clock <= duration[2] then
pool.h.alpha = pushFloatTo(
pool.h.alpha,
pool.h.state and 1.00 or 0.00,
pool.h.clock,
duration[2]
)
else
pool.h.alpha = pool.h.state and 1.00 or 0.00
if not pool.h.state then
pool.h.clock = nil
end
end
local max = s.x / 2
local Y = p.y + s.y + spacing
local mid = p.x + max
DL:AddLine(imgui.ImVec2(mid, Y), imgui.ImVec2(mid + (max * pool.h.alpha), Y), ToU32(set_alpha(pool.color, pool.h.alpha)), 3)
DL:AddLine(imgui.ImVec2(mid, Y), imgui.ImVec2(mid - (max * pool.h.alpha), Y), ToU32(set_alpha(pool.color, pool.h.alpha)), 3)
end
imgui.EndGroup()
return result
end