Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local arg = {...}
- if arg[1] == "func" then
- print(
- "FEATURES:\nb.API(): function to make your own button APIs\nb.counter(): function too add counter buttons\na function to add really ;simple buttons"
- )
- end
- out = 0
- local function API(ins, cord1, cord2, length, height)
- if ins == true then
- ins = {os.pullEvent("monitor_touch")}
- end
- out = 0
- for x = 0, height - 1 do
- for i = 0, length - 1 do
- if (ins[3] == cord1 + i) and (ins[4] == cord2 + x) then
- out = 1
- return true
- end
- end
- end
- if out ~= 1 then
- return false
- end
- end
- local function button(ins, cord1, cord2, lenght, height)
- return API(ins, cord1, cord2, length, height)
- end
- local function counter(monitor, ins, cc, cord1, cord2, cv, max, min, col)
- local m = peripheral.wrap(monitor)
- if data == nil then
- data = {}
- for is = 0, 1000 do
- data[is] = 0
- end
- end
- m.setCursorPos(cord1, cord2)
- m.write("\24" .. " " .. data[cc])
- m.setCursorPos(cord1, cord2 + 1)
- m.write("\25")
- if API(ins, cord1, cord2, 1, 1) == true then
- if data[cc] < max then
- data[cc] = data[cc] + cv
- m.setCursorPos(cord1, cord2)
- m.setTextColor(colors.green)
- m.write("\24" .. " " .. data[cc] .. " ")
- m.setCursorPos(cord1, cord2 + 1)
- m.setTextColor(colors.red)
- m.write("\25")
- m.setTextColor(colors[col])
- end
- end
- if API(ins, cord1, cord2 + 1, 1, 1) == true then
- if data[cc] > min then
- data[cc] = data[cc] - cv
- m.setCursorPos(cord1, cord2)
- m.setTextColor(colors.green)
- m.write("\24" .. " " .. data[cc] .. " ")
- m.setCursorPos(cord1, cord2 + 1)
- m.setTextColor(colors.red)
- m.write("\25")
- m.setTextColor(colors[col])
- end
- return data[cc]
- end
- end
- local function switch(monitor, cc, ins, pos1, pos2, col1, col2, col3, text)
- local m = peripheral.wrap(monitor)
- if data1 == nil then
- data1 = {}
- for is = 0, 1000 do
- data1[is] = false
- end
- end
- local function ff()
- data1[cc] = not data1[cc]
- end
- if API(ins, pos1, pos2, string.len(text), 1) == true then
- ff()
- end
- local oldcol1 = m.getTextColor()
- local oldcol2 = m.getBackgroundColor()
- if data1[cc] == true then
- m.setBackgroundColor(colors[col2])
- else
- m.setBackgroundColor(colors[col1])
- end
- m.setCursorPos(pos1, pos2)
- m.write(text)
- m.setTextColor(oldcol1)
- m.setBackgroundColor(oldcol2)
- return (data1[cc])
- end
- local function switchn(monitor, cc, ins, pos1, pos2, col1, col2, col3, text, text2)
- if string.len(text) ~= string.len(text2) then
- if string.len(text) > string.len(text2) then
- re = string.len(text)
- else
- re = string.len(text2)
- end
- end
- print(re)
- local m = peripheral.wrap(monitor)
- if data2 == nil then
- data2 = {}
- for is = 0, 1000 do
- data2[is] = false
- end
- end
- local function ff()
- data2[cc] = not data2[cc]
- end
- if API(ins, pos1, pos2, re, 1) == true then
- print()
- ff()
- end
- local oldcol1 = m.getTextColor()
- local oldcol2 = m.getBackgroundColor()
- if data2[cc] == true then
- m.setCursorPos(pos1, pos2)
- if string.len(text) ~= string.len(text2) then
- m.write(string.rep(" ", re))
- end
- m.setBackgroundColor(colors[col2])
- m.setCursorPos(pos1, pos2)
- m.write(text2)
- else
- m.setCursorPos(pos1, pos2)
- if string.len(text) ~= string.len(text2) then
- m.write(string.rep(" ", re))
- end
- m.setBackgroundColor(colors[col1])
- m.setCursorPos(pos1, pos2)
- m.write(text)
- end
- m.setTextColor(oldcol1)
- m.setBackgroundColor(oldcol2)
- return (data2[cc])
- end
- return {
- API = API,
- counter = counter,
- switch = switch,
- button = button,
- switchn = switchn
- --slider = slider,
- --timeswitch = timeswitch,
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement