2020-12-18 20:55:00 +00:00
|
|
|
util.init_hosted()
|
|
|
|
|
|
|
|
local json = require "json"
|
|
|
|
local services = {}
|
2020-12-19 07:39:46 +00:00
|
|
|
local rotate_before = nil
|
|
|
|
local transform = nil
|
2020-12-18 20:55:00 +00:00
|
|
|
|
|
|
|
local c_hard = {}
|
2021-03-27 10:18:01 +00:00
|
|
|
c_hard[0] = resource.create_colored_texture(0, 0.666, 0, 1)
|
|
|
|
c_hard[1] = resource.create_colored_texture(0.8, 0.466, 0, 1)
|
|
|
|
c_hard[2] = resource.create_colored_texture(0.8, 0, 0, 1)
|
|
|
|
c_hard[3] = resource.create_colored_texture(0.8, 0, 0.8, 1)
|
2020-12-18 20:55:00 +00:00
|
|
|
|
|
|
|
local c_soft = {}
|
2021-03-27 10:18:01 +00:00
|
|
|
c_soft[0] = resource.create_colored_texture(0, 0.666, 0, 0.6)
|
|
|
|
c_soft[1] = resource.create_colored_texture(0.8, 0.466, 0, 0.75)
|
|
|
|
c_soft[2] = resource.create_colored_texture(0.8, 0, 0, 0.6)
|
|
|
|
c_soft[3] = resource.create_colored_texture(0.8, 0, 0.8, 0.6)
|
2020-12-18 20:55:00 +00:00
|
|
|
|
|
|
|
local c_text = {}
|
|
|
|
c_text[0] = {1, 1, 1}
|
|
|
|
c_text[1] = {0, 0, 0}
|
|
|
|
c_text[2] = {1, 1, 1}
|
|
|
|
c_text[3] = {1, 1, 1}
|
|
|
|
|
|
|
|
gl.setup(NATIVE_WIDTH, NATIVE_HEIGHT)
|
|
|
|
|
|
|
|
util.file_watch("services.json", function(content)
|
|
|
|
services = json.decode(content)
|
|
|
|
end)
|
|
|
|
|
|
|
|
local white = resource.create_colored_texture(1,1,1,1)
|
|
|
|
local base_time = N.base_time or 0
|
|
|
|
|
|
|
|
function node.render()
|
2020-12-19 07:39:46 +00:00
|
|
|
if rotate_before ~= CONFIG.rotate then
|
|
|
|
transform = util.screen_transform(CONFIG.rotate)
|
|
|
|
rotate_before = CONFIG.rotate
|
2021-02-24 13:56:38 +00:00
|
|
|
end
|
2020-12-19 07:39:46 +00:00
|
|
|
|
2021-02-24 13:56:38 +00:00
|
|
|
if rotate_before == 90 or rotate_before == 270 then
|
|
|
|
real_width = NATIVE_HEIGHT
|
|
|
|
real_height = NATIVE_WIDTH
|
|
|
|
else
|
|
|
|
real_width = NATIVE_WIDTH
|
|
|
|
real_height = NATIVE_HEIGHT
|
2020-12-19 07:39:46 +00:00
|
|
|
end
|
|
|
|
|
2020-12-19 08:23:40 +00:00
|
|
|
if CONFIG.instance_name ~= "" then
|
|
|
|
titlebar = CONFIG.instance_name .. " - " .. services.prettytime
|
|
|
|
else
|
|
|
|
titlebar = servics.prettytime
|
|
|
|
end
|
|
|
|
|
2020-12-19 08:32:14 +00:00
|
|
|
local title_width = CONFIG.header_font:width(titlebar, CONFIG.output_size)
|
2020-12-19 08:08:53 +00:00
|
|
|
local host_width = 0
|
|
|
|
|
2020-12-18 21:05:10 +00:00
|
|
|
transform()
|
2020-12-18 20:55:00 +00:00
|
|
|
CONFIG.background_color.clear()
|
2020-12-19 08:32:14 +00:00
|
|
|
CONFIG.header_font:write(real_width/2-title_width/2, CONFIG.output_size*0.5, titlebar, CONFIG.output_size, 1,1,1,1)
|
2020-12-18 20:55:00 +00:00
|
|
|
|
2020-12-19 08:08:53 +00:00
|
|
|
for idx, service in ipairs(services.services) do
|
2020-12-19 08:32:14 +00:00
|
|
|
host_width = math.max(host_width, CONFIG.header_font:width(service.host, CONFIG.header_size))
|
2020-12-19 08:08:53 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
local y = CONFIG.output_size*2
|
2020-12-18 20:55:00 +00:00
|
|
|
for idx, serv in ipairs(services.services) do
|
2023-03-06 05:40:50 +00:00
|
|
|
header_font_size = CONFIG.header_size
|
2021-02-24 13:56:38 +00:00
|
|
|
margin = math.min(CONFIG.output_size, 20)
|
2020-12-19 07:41:02 +00:00
|
|
|
|
2023-03-06 05:40:50 +00:00
|
|
|
header_width = real_width-20-margin*2
|
|
|
|
while (CONFIG.header_font:width(serv.host, header_font_size) + CONFIG.header_font:width(serv.service, header_font_size)) > header_width do
|
|
|
|
header_font_size = header_font_size - 1
|
2020-12-19 07:41:02 +00:00
|
|
|
end
|
|
|
|
|
2023-03-06 05:40:50 +00:00
|
|
|
my_height = (#serv.output*CONFIG.output_size*1.5) + margin*3 + CONFIG.header_size
|
2020-12-18 20:55:00 +00:00
|
|
|
|
|
|
|
if serv.type == 0 then
|
2021-02-24 13:56:38 +00:00
|
|
|
c_soft[serv.state]:draw(0, y, real_width, y+my_height)
|
2020-12-18 20:55:00 +00:00
|
|
|
else
|
2021-02-24 13:56:38 +00:00
|
|
|
c_hard[serv.state]:draw(0, y, real_width, y+my_height)
|
2020-12-18 20:55:00 +00:00
|
|
|
end
|
|
|
|
|
2023-03-06 05:40:50 +00:00
|
|
|
y = y + margin
|
2020-12-18 20:55:00 +00:00
|
|
|
|
2023-03-06 05:40:50 +00:00
|
|
|
service_x = real_width - margin - CONFIG.header_font:width(serv.service, header_font_size)
|
2020-12-18 20:55:00 +00:00
|
|
|
|
2023-03-06 05:40:50 +00:00
|
|
|
CONFIG.header_font:write(margin, y, serv.host, header_font_size, c_text[serv.state][1],c_text[serv.state][2],c_text[serv.state][2],1)
|
|
|
|
CONFIG.header_font:write(service_x, y, serv.service, header_font_size, c_text[serv.state][1],c_text[serv.state][2],c_text[serv.state][3],1)
|
2020-12-18 20:55:00 +00:00
|
|
|
|
2023-03-06 05:40:50 +00:00
|
|
|
y = y + CONFIG.header_size + margin
|
2020-12-19 07:45:40 +00:00
|
|
|
|
2020-12-18 20:55:00 +00:00
|
|
|
for idx, line in ipairs(serv.output) do
|
2023-03-06 05:40:50 +00:00
|
|
|
CONFIG.output_font:write(margin, y, line, CONFIG.output_size, c_text[serv.state][1],c_text[serv.state][2],c_text[serv.state][3],1)
|
|
|
|
y = y + CONFIG.output_size * 1.5
|
2020-12-18 20:55:00 +00:00
|
|
|
end
|
|
|
|
|
2023-03-06 05:40:50 +00:00
|
|
|
y = y + margin + 2
|
2020-12-19 07:44:05 +00:00
|
|
|
|
|
|
|
if y > real_height then
|
|
|
|
break
|
|
|
|
end
|
2020-12-18 20:55:00 +00:00
|
|
|
end
|
|
|
|
end
|