Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- mon = peripheral.wrap("top")
- mouseHeight = 0
- mouseWidth = 0
- local buttons = 3
- button={}
- button[1] = {2,2,2}
- button[2] = {2,6,10}
- button[3] = {"Lamp","Spawner","lanterns"}
- button[4] = {colors.lime}
- button[5] = {colors.red}
- button[6] = {0,0,0}
- function clear()
- mon.setBackgroundColor(colors.black)
- mon.clear()
- end
- -- xmin,ymin,text,bgc,tbgc,state
- function DrawButton(x,y,text,bgc,tbgc,state)
- -- setting the background colour
- if state == 1 then
- mon.setBackgroundColor(bgc)
- else
- mon.setBackgroundColor(tbgc)
- end
- -- setting the position to write the text
- mon.setCursorPos(x,y)
- mon.write(string.rep(" ", string.len(text) + 2))
- mon.setCursorPos(x,y + 1)
- mon.write(" ")
- mon.write(text)
- mon.write(" ")
- mon.setCursorPos(x,y+2)
- mon.write(string.rep(" ", string.len(text) + 2))
- end
- clear()
- function fill(amount)
- for i = 1,amount do
- DrawButton(button[1][i],button[2][i],button[3][i],button[4][1],button[5][1],button[6][i])
- end
- end
- -- filling the screen with buttons
- fill(buttons)
- -- button clicks
- function CP(amount)
- for i = 1,amount do
- if mouseWidth > button[1][i] - 1 and mouseWidth < string.len(button[3][i]) + 4 and mouseHeight > button[2][i] - 1 and mouseHeight < button[2][i] + 3 then
- button[6][i] = button[6][i] + 1
- if button[6][i] >= 2 then
- button[6][i] = 0
- end
- fill(buttons)
- end
- end
- end
- repeat
- event,p1,p2,p3 = os.pullEvent()
- if event == "monitor_touch" then
- mouseWidth = p2
- mouseHeight = p3
- CP(buttons)
- end
- until event=="char" and p1==("x")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement