Files
2take1-scripts/autoexec.lua
2021-06-23 13:58:11 -05:00

146 lines
4.8 KiB
Lua

simulated_resolution = v2(1920, 1080)
function round(n)
return n + 0.5 - (n + 0.5) % 1
end
function coords_to_screenwriter(coord1, coord2)
local x_left, x_right, y_top, y_bottom, width, height
x_left = math.min(coord1.x, coord2.x)
x_right = math.max(coord1.x, coord2.x)
y_top = math.min(coord1.y, coord2.y)
y_bottom = math.max(coord1.y, coord2.y)
width = x_right - x_left
height = y_bottom - y_top
return coords_partial_to_screenwriter(v2(x_left, x_top), v2(width, height), 1)
end
function coords_partial_to_screenwriter(pos_px, scale_px, anchor)
local x_px, y_px, x, y, width, height
if anchor == 1 then --top left
x_px = pos_px.x + scale_px.x / 2
y_px = pos_px.y - scale_px.y / 2
elseif anchor == 2 then --top right
x_px = pos_px.x - scale_px.x / 2
y_px = pos_px.y - scale_px.y / 2
elseif anchor == 3 then --bottom right
x_px = pos_px.x - scale_px.x / 2
y_px = pos_px.y + scale_px.y / 2
elseif anchor == 4 then --bottom left
x_px = pos_px.x + scale_px.x / 2
y_px = pos_px.y + scale_px.y / 2
else --center
x_px = pos_px.x
y_px = pos_px.y
end
x = x_px / simulated_resolution.x * 2 - 1
y = y_px / simulated_resolution.y * 2 - 1
width = scale_px.x / simulated_resolution.x * 2
height = scale_px.y / simulated_resolution.y * 2
return v2(x, y), v2(width, height)
end
function action_value_input(f)
local resp, str = input.get(f.name, bgcolor, 64, 3)
while (resp ~= 0) do system.wait(0) end
f.value_i = tonumber(resp)
end
local bgcolor = '000000'
local bgopacity = '000000'
local menu_options = menu.add_feature('session info', 'parent')
local menu_enable = menu.add_feature('enable', 'toggle', menu_options.id)
menu_enable.on = true
local menu_blank0 = menu.add_feature('', 'action', menu_options.id)
local options_textshadow = menu.add_feature('text shadow', 'toggle', menu_options.id)
local options_disablebg = menu.add_feature('disable background', 'toggle', menu_options.id)
local options_bgcolor = menu.add_feature('background color', 'action', menu_options.id, function(f)
local resp, str = input.get('background color', bgcolor, 6, 2)
while (resp ~= 0) do system.wait(0) end
local r = Regex('^([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$')
local m = r:search(str)
if m.count > 0 then
str = m.matches[1]
if (str:len() == 3) then
str = str:sub(1,1)..str:sub(1,1)..str:sub(2,2)..str:sub(2,2)..str:sub(3,3)..str:sub(3,3)
end
bgcolor = str
ui.notify_above_map(str, 'set background color to #' .. str, 140)
end
end)
local options_opacity = menu.add_feature('background opacity', 'action_value_i', menu_options.id, action_value_input)
options_opacity.min_i = 0
options_opacity.max_i = 100
options_opacity.value_i = 100
local options_pos = menu.add_feature('position', 'parent', menu_options.id)
local options_pos_x = menu.add_feature('x', 'action_value_i', options_pos.id, action_value_input)
options_pos_x.min_i = 0
options_pos_x.max_i = simulated_resolution.x
options_pos_x.value_i = 320
local options_pos_y = menu.add_feature('y', 'action_value_i', options_pos.id, action_value_input)
options_pos_y.min_i = 0
options_pos_y.max_i = simulated_resolution.y
options_pos_y.value_i = 20
local options_pos_width = menu.add_feature('width', 'action_value_i', options_pos.id, action_value_input)
options_pos_width.min_i = 0
options_pos_width.max_i = simulated_resolution.x
options_pos_width.value_i = 200
local options_pos_height = menu.add_feature('height', 'action_value_i', options_pos.id, action_value_input)
options_pos_height.min_i = 0
options_pos_height.max_i = simulated_resolution.y
options_pos_height.value_i = 200
local options_disp = menu.add_feature('display', 'parent', menu_options.id)
local options_disp_host = menu.add_feature('host', 'toggle', options_pos.id, action_value_input)
options_disp_host.on = true
menu.create_thread(function(f)
while true do
if menu_enable.on then
local base = v2(options_pos_x.value_i, options_pos_y.value_i)
if (not(options_disablebg.on)) then
local pos, scale = coords_partial_to_screenwriter(base, v2(options_pos_width.value_i, options_pos_height.value_i), 4)
local opacity = string.format('%x', round(options_opacity.value_i * 2.55))
while opacity:len() < 2 do
opacity = '0'..opacity
end
scriptdraw.draw_rect(pos, scale, tonumber('0x'..opacity..bgcolor))
end
local textFlags = 0
if options_textshadow.on then
textFlags = 2
end
local
--scriptdraw.draw_text(scale, v2(0, 0), v2(1, 1), 1, 0XFFFFFFFF, textFlags)
end
system.wait(0)
end
end, nil)