Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- A program to control multiple mining turtles.
- -- For UnbrokenMotion and Friends.
- -- Version 0.1.
- local termWidth, termHeight = term.getSize()
- local termHalfWidth = termWidth / 2
- local termHalfHeight = termHeight / 2
- -- Setup start.
- -- Self explanatory, prints text centered on the screen.
- -- Or at least, it tries to.
- function centeredText(y, text)
- local textLength = string.len(text)
- local cursorXPos = termHalfWidth - (textLength / 2)
- term.setCursorPos(cursorXPos, y)
- term.write(text)
- end
- -- A standard dialog screen.
- function dialog(text, bgColor, fgColor, btColor)
- -- Set background color.
- paintutils.drawFilledBox(1, 2, termWidth, termHeight, bgColor)
- term.setBackgroundColor(bgColor)
- term.setTextColor(fgColor)
- centeredText(termHalfHeight, text)
- --draw buttons.
- local buttonEnd = (termHalfWidth + 2)
- local buttonStart = (termHalfWidth - 2)
- local yPos = (termHalfHeight + 2)
- paintutils.drawLine(buttonStart, yPos, buttonEnd, yPos, btColor)
- term.setCursorPos(buttonStart+1, yPos)
- term.write("Okay")
- --wait for input.
- while true do
- -- sets multiple variables using os.pullEvent, if the mouse if clicked.
- local event, button, x, y = os.pullEvent("mouse_click")
- -- Basic logic to check which button has been pressed.
- if y == yPos then
- break
- end
- end
- end
- -- A y/n dialog screen.
- function truthDialog(text, bgColor, fgColor, btColor)
- -- Set background color.
- paintutils.drawFilledBox(1, 2, termWidth, termHeight, bgColor)
- term.setBackgroundColor(bgColor)
- term.setTextColor(fgColor)
- centeredText(termHalfHeight, text)
- --draw buttons.
- local yesEnd = (termHalfWidth - 1)
- local yesStart = (yesEnd - 4)
- local noStart = (termHalfWidth + 1)
- local noEnd = (noStart + 3)
- local yPos = (termHalfHeight + 2)
- paintutils.drawLine(yesStart, yPos, yesEnd, yPos, btColor)
- paintutils.drawLine(noStart, yPos, noEnd, yPos, btColor)
- term.setCursorPos(yesStart+1, yPos)
- term.write("yes")
- term.setCursorPos(noStart+1, yPos)
- term.write("no")
- --wait for input.
- while true do
- -- sets multiple variables using os.pullEvent, if the mouse is clicked.
- local event, button, x, y = os.pullEvent("mouse_click")
- -- Basic logic to check which button has been pressed.
- if y == yPos then
- if x >= yesStart and x <= yesEnd then
- return true
- elseif x >= noStart and x <= noEnd then
- return false
- end
- end
- end
- end
- -- Testing functions, TEMPORARY
- dialog("Hello, world!", colors.blue, colors.white, colors.lightBlue)
- local value = truthDialog("Hello, world!", colors.blue, colors.white, colors.lightBlue)
- -- Setup End.
- term.setCursorPos(1, termHeight)
- print(value)
- sleep(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement