Kodit izke
-
Автор темы
- #1
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
Внимание, присутствует говнокод, ибо делалось как только пришла идея на быструю руку.
Использование:
Скриншоты:
Смотрите на кейбинды.
Sponsored by idealyaw.lua & Weave.su
code_language.lua:
helpers = {
drag = {},
animation = {data = {}},
render = {}
}
helpers.animation.lerp = function(start, end_pos, time) if type(start) == 'userdata' then local color_data = {0, 0, 0, 0} for i, color_key in ipairs({'r', 'g', 'b', 'a'}) do color_data[i] = helpers.animation.lerp(start[color_key], end_pos[color_key], time) end return color_t(unpack(color_data)) end return (end_pos - start) * (globals_var.frame_time() * time * 175) + start end
helpers.animation.new = function(name, value, time, start) if helpers.animation.data[name] == nil then helpers.animation.data[name] = start end helpers.animation.data[name] = helpers.animation.lerp(helpers.animation.data[name], value, time) return helpers.animation.data[name] end
helpers.drag.list = {}
helpers.drag.names = {}
helpers.drag.enables = {}
helpers.drag.standart_anim = {}
helpers.drag.func = function(id, x_var, y_var, size, standarts)
if not menu.is_open() then return end
if input.is_mouse_in_bounds(menu.get_pos(), menu.get_size()) then return end
local mouse_position = input.get_mouse_pos()
local is_clicked = input.is_key_held(e_keys.MOUSE_LEFT)
local pos = vec2_t(x_var:get(), y_var:get())
if not helpers.drag.enables[id] then helpers.drag.enables[id] = false end
if not helpers.drag.standart_anim[id] then helpers.drag.standart_anim[id] = nil end
if not helpers.drag.list[id] then helpers.drag.list[id] = vec2_t(0, 0) end
local is_exist = false
for i = 1, #helpers.drag.names do
if helpers.drag.names[i] == id then is_exist = true end
end
if not is_exist then helpers.drag.names[#helpers.drag.names+1] = id end
local in_box = function(pos, start, stop)
return pos.x + 1 > start.x and pos.x - 1 < start.x + stop.x and pos.y + 1 > start.y and pos.y - 1 < start.y + stop.y
end
local draggings = 0
for i = 1, #helpers.drag.names do
if helpers.drag.enables[helpers.drag.names[i]] then
draggings = draggings + 1
if draggings >= 2 then helpers.drag.enables[helpers.drag.names[i]] = false end
end
end
local standart = nil
if #standarts > 0 then
local anim = helpers.animation.new(id .. "standart", helpers.drag.enables[id] and 1 or 0.001, 0.1, 0)
if anim >= 0.01 then
for i = 1, #standarts do
local standart_position = standarts[i]
local if_in_box = in_box(pos, standart_position, size)
or in_box(pos + vec2_t(size.x, 0), standart_position, size)
or in_box(pos + vec2_t(0, size.y), standart_position, size)
or in_box(pos + size, standart_position, size)
local anim_in_box = helpers.animation.new(id .. "standart" .. i, if_in_box and 1 or 0.5, 0.1, 0)
render.rect_filled(standart_position, size, color_t(255, 255, 255, math.floor(50 * anim_in_box * anim)), 3)
if if_in_box then
standart = standart_position
end
end
end
end
local anim = helpers.animation.new(id .. "hint", (input.is_mouse_in_bounds(pos, size)) and 1 or 0.001, 0.1, 0)
if anim > 0.01 then
render.rect(pos - vec2_t(2, 2), size + vec2_t(3, 3), color_t(120, 120, 120, math.floor(255 * anim)), 3)
render.text(globals.small_font, "Use LMB for dragging element", pos + vec2_t(0, size.y + 4), color_t(255, 255, 255, math.floor(255 * anim)))
-- render.rect_outline(pos - vector(2, 2), pos + size + vector(2, 2), color(120, 120, 120, 255 * anim), 1, 6)
-- render.text(small_font, pos + vector(0, size.y + 4), color(200, 200, 200, 255 * anim), '', "Use LMB for dragging element")
end
if input.is_mouse_in_bounds(pos, size) and is_clicked then
if not helpers.drag.enables[id] then
helpers.drag.list[id] = mouse_position - pos
helpers.drag.enables[id] = true
end
elseif not is_clicked and helpers.drag.enables[id] then
if standart ~= nil then
helpers.drag.standart_anim[id] = standart
end
helpers.drag.enables[id] = false
end
if helpers.drag.enables[id] then
helpers.drag.standart_anim[id] = nil
new_pos = mouse_position - helpers.drag.list[id]
x_var:set(new_pos.x)
y_var:set(new_pos.y)
end
local animation_x = helpers.animation.new(id .. "standart_x", helpers.drag.standart_anim[id] ~= nil and helpers.drag.standart_anim[id].x or x_var:get(), 0.05, x_var:get())
local animation_y = helpers.animation.new(id .. "standart_y", helpers.drag.standart_anim[id] ~= nil and helpers.drag.standart_anim[id].y or y_var:get(), 0.05, y_var:get())
if not helpers.drag.enables[id] and helpers.drag.standart_anim[id] ~= nil then
x_var:set(animation_x)
y_var:set(animation_y)
local diff_x = x_var:get() - helpers.drag.standart_anim[id].x
local diff_y = y_var:get() - helpers.drag.standart_anim[id].y
if diff_x < 0 then diff_x = diff_x * -1 end
if diff_y < 0 then diff_y = diff_y * -1 end
if diff_x < 1 and diff_y < 1 then
standart = nil
helpers.drag.standart_anim[id] = nil
end
end
end
Возможно не хватает каких-либо функиций, пишите в тему, обновлю.
Использование:
code_language.lua:
helpers.drag.func("your_drag_id",
your_slider_x, -- ссылается на слайдер
your_slider_y, -- ссылается на слайдер
size, -- размер вашего драг-бокса
{vec2_t(globals.screen_size[1] - size.x - 10, 10)}
-- позиция к которой будет *приклеиваться* ваш драг-элемент
)
Смотрите на кейбинды.
Sponsored by idealyaw.lua & Weave.su