Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Look throughout the code for comments like this. They explain what to do to change things.
- --What side the monitor will be on (change this if needed)
- side = "right"
- -- Create table of connected monitors
- local myPeripherals = {}
- for _, name in pairs(peripheral.getNames()) do
- if peripheral.getType(name) == "monitor" then --# change "monitor" to your peripheral type.
- table.insert(myPeripherals, name)
- end
- end
- --wrap monitor as display
- m = peripheral.wrap(myPeripherals[1])
- --button on/off color
- bactive = colors.green
- binactive=colors.red
- --text on/off color
- tactive=colors.white
- tinactive=colors.black
- --Background color
- bgcolor = colors.black
- buttons = {}
- function newButton(id,xmin,xmax,ymin,ymax,text,func)
- buttons[id] = {}
- buttons[id]["xmin"] = xmin
- buttons[id]["xmax"] = xmax
- buttons[id]["ymin"] = ymin
- buttons[id]["ymax"] = ymax
- buttons[id]["active"] = false
- buttons[id]["text"] = text
- buttons[id]["func"] = func
- end
- ---------------------------------------------------------------------------------
- function printButton(id)
- ymin = buttons[id]["ymin"]
- ymax = buttons[id]["ymax"]
- xmin = buttons[id]["xmin"]
- xmax = buttons[id]["xmax"]
- text = buttons[id]["text"]
- ia = buttons[id]["active"]
- width = xmax - xmin
- height = ymax - ymin
- if ia then m.setBackgroundColor(bactive) m.setTextColor(tactive)
- else m.setBackgroundColor(binactive) m.setTextColor(tinactive) end
- for j = ymin,ymax do
- m.setCursorPos(xmin,j)
- for i = xmin,xmax do
- m.write(" ")
- end
- end
- m.setCursorPos(xmin + width / 2 - #text / 2 + 1,ymin + height / 2)
- m.write(text)
- m.setBackgroundColor(bgcolor)
- end
- ----------------------------------------------------------------------------------
- function refreshButtons()
- for i = 1,#buttons do
- printButton(i)
- end
- end
- function checkxy( x,y )
- for i = 1, #buttons do
- if y >= buttons[i]["ymin"] and y <= buttons[i]["ymax"] then
- if x >= buttons[i]["xmin"] and x <= buttons[i]["xmax"] then
- buttons[i]["active"] = not buttons[i]["active"]
- clicked = i
- if buttons[i]["func"] ~= nil then
- buttons[i]["func"]()
- end
- end
- end
- end
- end
- bool1 = false
- bool2 = false
- bool3 = false
- bool4 = false
- bool5 = false
- bool6 = false
- bool8 = false
- bool9 = false
- rs.setBundledOutput("left",0)
- --functions for buttons, need to be added for more Buttons to work
- function func1()
- current = rs.getBundledOutput("left")
- bool1 = not bool1
- if bool1 then
- rs.setBundledOutput("left",current+colors.white)
- else
- rs.setBundledOutput("left",current-colors.white)
- end
- end
- function func2()
- current = rs.getBundledOutput("left")
- bool2 = not bool2
- if bool2 then
- rs.setBundledOutput("left",current+colors.blue)
- else
- rs.setBundledOutput("left",current-colors.blue)
- end
- end
- function func3()
- current = rs.getBundledOutput("left")
- bool3 = not bool3
- if bool3 then
- rs.setBundledOutput("left",current+colors.red)
- else
- rs.setBundledOutput("left",current-colors.red)
- end
- end
- function func4()
- current = rs.getBundledOutput("left")
- bool4 = not bool4
- if bool4 then
- rs.setBundledOutput("left",current+colors.green)
- else
- rs.setBundledOutput("left",current-colors.green)
- end
- end
- function func5()
- current = rs.getBundledOutput("left")
- bool5 = not bool5
- if bool5 then
- rs.setBundledOutput("left",current+colors.yellow)
- else
- rs.setBundledOutput("left",current-colors.yellow)
- end
- end
- function func6()
- current = rs.getBundledOutput("left")
- bool6 = not bool6
- if bool6 then
- rs.setBundledOutput("left",current+colors.black)
- else
- rs.setBundledOutput("left",current-colors.black)
- end
- end
- function func7()
- current = rs.getBundledOutput("left")
- bool7 = not bool7
- if bool7 then
- rs.setBundledOutput("left",current+colors.cyan)
- else
- rs.setBundledOutput("left",current-colors.cyan)
- end
- end
- function func8()
- current = rs.getBundledOutput("left")
- bool8 = not bool8
- if bool8 then
- rs.setBundledOutput("left",current+colors.gray)
- else
- rs.setBundledOutput("left",current-colors.gray)
- end
- end
- --You can add more buttons and also change the size of them. The format is startingx,startingy,endingx,endingy,text,function
- --The buttons
- newButton(1, 3,24,2,9,"Farm 1",func2)
- newButton(2, 27,48,2,9,"Farm 2",func3)
- newButton(3, 3,24,11,18,"Farm 3",func4)
- newButton(4, 27,48,11,18,"Farm 4",func5)
- ------------------------------------------------
- m.clear()
- refreshButtons()
- --main loop
- while true do
- e,side,x,y = os.pullEvent("monitor_touch")
- checkxy(x,y)
- refreshButtons()
- end
Advertisement
Comments
-
- Am I right in assuming that this is a variable button system for ComputerCraft? because if it is this is amazing.
Add Comment
Please, Sign In to add comment
Advertisement