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 = "top"
- m = peripheral.wrap(side)
- --button on/off color
- bactive = colors.cyan
- binactive=colors.gray
- --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
- rs.setBundledOutput("back",0)
- --White is pigman, Orange is witch, purple is wither skele (Bundled cable)
- function pigman()
- current = rs.getBundledOutput("back")
- bool1 = not bool1
- if bool1 then
- rs.setBundledOutput("back",current+colors.white)
- else
- rs.setBundledOutput("back",current-colors.white)
- end
- end
- function witch()
- current = rs.getBundledOutput("back")
- bool2 = not bool2
- if bool2 then
- rs.setBundledOutput("back",current+colors.orange)
- else
- rs.setBundledOutput("back",current-colors.orange)
- end
- end
- function wither()
- current = rs.getBundledOutput("back")
- bool3 = not bool3
- if bool3 then
- rs.setBundledOutput("back",current+colors.magenta)
- else
- rs.setBundledOutput("back",current-colors.magenta)
- 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, 2,11,2,8,"Pigman",pigman)
- newButton(2, 13,22,2,8,"Witch",witch)
- newButton(3, 24,37,2,8,"Wither Skele",wither)
- ------------------------------------------------
- m.clear()
- refreshButtons()
- --main loop
- while true do
- e,side,x,y = os.pullEvent("monitor_touch")
- checkxy(x,y)
- refreshButtons()
- end
Add Comment
Please, Sign In to add comment