Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local monitor1 = peripheral.wrap('top')
- local monWidth, monHeight
- local buttCount = 0
- local buttLoc = {}
- local buttSize = {}
- local function nextLine()
- x, y = monitor1.getCursorPos()
- monitor1.setCursorPos(1 ,y+1)
- a, b = term.getCursorPos()
- term.setCursorPos(1 , y+1)
- end
- local function monStart()
- monitor1.clear()
- monWidth, monHeight = monitor1.getSize()
- monitor1.setCursorPos(1,1)
- monitor1.setTextScale(.5)
- monitor1.setTextColor(colors.black)
- monitor1.setBackgroundColor(colors.white)
- monitor1.clear()
- end
- local function center(str)
- local len = string.len(str)
- x = monWidth/2 - len/2
- y = monHeight/2
- if monWidth%2 ~= 0 and len%2 ~= 0 then
- x = x + 1
- end
- return x,y
- end
- local function drawButt(a, b, c)
- monitor1.setTextColor(colors.white)
- monitor1.setBackgroundColor(colors.black)
- monitor1.setCursorPos(a, b)
- monitor1.write(c)
- buttCount = buttCount + 1
- buttLoc[buttCount] = {}
- buttLoc[buttCount]["x"] = a
- buttLoc[buttCount]["y"] = b
- local buttLength = string.len(c)
- buttSize[buttCount] = buttLength
- end
- --Returns 0 if no button coord found, 1 if found
- local function checkButt(a, b)
- term.write(a..b)
- local i = 1
- while i <= buttCount do
- if buttLoc[i]["x"] == a and buttLoc[i]["y"] == b then
- return 1, i
- elseif buttLoc[i]["y"] == b and buttLoc[i]["x"] ~= a then
- for j=1,buttSize[i],1 do
- if buttLoc[i]["x"] == a - j then
- return 1, i
- else
- end
- end
- i = i + 1
- else
- i = i + 1
- end
- end
- return 0, 0
- end
- local function monWriteCen(c)
- monitor1.setTextColor(colors.black)
- monitor1.setBackgroundColor(colors.white)
- local d, e = center(c)
- monitor1.setCursorPos(d,e)
- monitor1.write(c)
- end
- local function monWrite(a, b, c)
- monitor1.setTextColor(colors.black)
- monitor1.setBackgroundColor(colors.white)
- monitor1.setCursorPos(a,b)
- monitor1.write(c)
- end
- monStart()
- local screenText = "Right Click Monitor To Begin"
- monWriteCen(screenText)
- --Wait for click
- os.pullEvent("monitor_touch")
- monStart()
- screenText = "Thanks! Welcome!"
- monWriteCen(screenText)
- --Draw Buttons
- drawButt(8,3," Button1 ")
- drawButt(8,8," Button2 ")
- --Wait for click
- local event,side,x,y = os.pullEvent("monitor_touch")
- local buttStatus, buttNumber = checkButt(x,y)
- if buttStatus == 1 then
- monStart()
- screenText = "Button #"..buttNumber.." Pressed!"
- monWriteCen(screenText)
- else
- monStart()
- screenText = "No Button Pressed!"
- monWriteCen(screenText)
- end
- --Debug
- --monWrite(1,8,x)
- --monWrite(1,11,y)
- --monWrite(1,9,buttStatus)
- --monWrite(1,11,buttNumber)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement