Add files via upload
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
|
||||
local button = {}
|
||||
local mon = peripheral.find("monitor")
|
||||
|
||||
function clearTable()
|
||||
button = {}
|
||||
end
|
||||
|
||||
function setButton(name, title, func, xmin, ymin, xmax, ymax, elem, elem2, color)
|
||||
button[name] = {}
|
||||
button[name]["title"] = title
|
||||
button[name]["func"] = func
|
||||
button[name]["active"] = false
|
||||
button[name]["xmin"] = xmin
|
||||
button[name]["ymin"] = ymin
|
||||
button[name]["xmax"] = xmax
|
||||
button[name]["ymax"] = ymax
|
||||
button[name]["color"] = color
|
||||
button[name]["elem"] = elem
|
||||
button[name]["elem2"] = elem2
|
||||
end
|
||||
|
||||
-- stuff and things for buttons
|
||||
|
||||
function fill(text, color, bData)
|
||||
mon.setBackgroundColor(color)
|
||||
mon.setTextColor(colors.white)
|
||||
local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2)
|
||||
local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(bData["title"])) /2) +1
|
||||
for j = bData["ymin"], bData["ymax"] do
|
||||
mon.setCursorPos(bData["xmin"], j)
|
||||
if j == yspot then
|
||||
for k = 0, bData["xmax"] - bData["xmin"] - string.len(bData["title"]) +1 do
|
||||
if k == xspot then
|
||||
mon.write(bData["title"])
|
||||
else
|
||||
mon.write(" ")
|
||||
end
|
||||
end
|
||||
else
|
||||
for i = bData["xmin"], bData["xmax"] do
|
||||
mon.write(" ")
|
||||
end
|
||||
end
|
||||
end
|
||||
mon.setBackgroundColor(colors.black)
|
||||
end
|
||||
|
||||
-- stuff and things for buttons
|
||||
|
||||
function screen()
|
||||
local currColor
|
||||
for name,data in pairs(button) do
|
||||
local on = data["active"]
|
||||
currColor = data["color"]
|
||||
fill(name, currColor, data)
|
||||
end
|
||||
end
|
||||
|
||||
-- magical handler for clicky clicks
|
||||
|
||||
function checkxy(x, y)
|
||||
for name, data in pairs(button) do
|
||||
if y>=data["ymin"] and y <= data["ymax"] then
|
||||
if x>=data["xmin"] and x<= data["xmax"] then
|
||||
data["func"](data["elem"], data["elem2"])
|
||||
--flash(data['name'])
|
||||
return true
|
||||
--data["active"] = not data["active"]
|
||||
--print(name)
|
||||
end
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function clickEvent()
|
||||
local myEvent={os.pullEvent("monitor_touch")}
|
||||
checkxy(myEvent[3], myEvent[4])
|
||||
end
|
||||
@@ -0,0 +1,93 @@
|
||||
|
||||
-- peripheral identification
|
||||
--
|
||||
function periphSearch(type)
|
||||
local names = peripheral.getNames()
|
||||
local i, name
|
||||
for i, name in pairs(names) do
|
||||
if peripheral.getType(name) == type then
|
||||
return peripheral.wrap(name)
|
||||
end
|
||||
end
|
||||
return null
|
||||
end
|
||||
|
||||
-- formatting
|
||||
|
||||
function format_int(number)
|
||||
|
||||
if number == nil then number = 0 end
|
||||
|
||||
local i, j, minus, int, fraction = tostring(number):find('([-]?)(%d+)([.]?%d*)')
|
||||
-- reverse the int-string and append a comma to all blocks of 3 digits
|
||||
int = int:reverse():gsub("(%d%d%d)", "%1,")
|
||||
|
||||
-- reverse the int-string back remove an optional comma and put the
|
||||
-- optional minus and fractional part back
|
||||
return minus .. int:reverse():gsub("^,", "") .. fraction
|
||||
end
|
||||
|
||||
-- monitor related
|
||||
|
||||
--display text text on monitor, "mon" peripheral
|
||||
function draw_text(mon, x, y, text, text_color, bg_color)
|
||||
mon.monitor.setBackgroundColor(bg_color)
|
||||
mon.monitor.setTextColor(text_color)
|
||||
mon.monitor.setCursorPos(x,y)
|
||||
mon.monitor.write(text)
|
||||
end
|
||||
|
||||
function draw_text_right(mon, offset, y, text, text_color, bg_color)
|
||||
mon.monitor.setBackgroundColor(bg_color)
|
||||
mon.monitor.setTextColor(text_color)
|
||||
mon.monitor.setCursorPos(mon.X-string.len(tostring(text))-offset,y)
|
||||
mon.monitor.write(text)
|
||||
end
|
||||
|
||||
function draw_text_lr(mon, x, y, offset, text1, text2, text1_color, text2_color, bg_color)
|
||||
draw_text(mon, x, y, text1, text1_color, bg_color)
|
||||
draw_text_right(mon, offset, y, text2, text2_color, bg_color)
|
||||
end
|
||||
|
||||
--draw line on computer terminal
|
||||
function draw_line(mon, x, y, length, color)
|
||||
if length < 0 then
|
||||
length = 0
|
||||
end
|
||||
mon.monitor.setBackgroundColor(color)
|
||||
mon.monitor.setCursorPos(x,y)
|
||||
mon.monitor.write(string.rep(" ", length))
|
||||
end
|
||||
|
||||
function draw_line_y(mon, x, y, length, color)
|
||||
|
||||
if length < 0 then
|
||||
length = 0
|
||||
end
|
||||
|
||||
mon.monitor.setBackgroundColor(color)
|
||||
for i=y, length do
|
||||
mon.monitor.setCursorPos(x, i)
|
||||
mon.monitor.write(" ")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
--create progress bar
|
||||
--draws two overlapping lines
|
||||
--background line of bg_color
|
||||
--main line of bar_color as a percentage of minVal/maxVal
|
||||
function progress_bar(mon, x, y, length, minVal, maxVal, bar_color, bg_color)
|
||||
draw_line(mon, x, y, length, bg_color) --backgoround bar
|
||||
local barSize = math.floor((minVal/maxVal) * length)
|
||||
draw_line(mon, x, y, barSize, bar_color) --progress so far
|
||||
end
|
||||
|
||||
|
||||
function clear(mon)
|
||||
term.clear()
|
||||
term.setCursorPos(1,1)
|
||||
mon.monitor.setBackgroundColor(colors.black)
|
||||
mon.monitor.clear()
|
||||
mon.monitor.setCursorPos(1,1)
|
||||
end
|
||||
Reference in New Issue
Block a user