Advertisement
Creepinson

test

Sep 14th, 2019
376
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. local w,h = term.getSize()
  2.  
  3. function drawSquare( borderCol, boxCol, textCol, xStart, xEnd, yStart, ... )
  4.  
  5. --[[ Defines the max amount of characters that can be printed within
  6. the box. If exceeded, it will error.
  7. --]]
  8. local maxLength = xEnd - xStart - 2
  9.  
  10. --[[ This part does the border of the box ]]--
  11. term.setBackgroundColour(borderCol)
  12. for x = xStart, xEnd do
  13. term.setCursorPos(x, yStart)
  14. write(" ")
  15. term.setCursorPos(x, yStart+#arg+2)
  16. write(" ")
  17. end
  18. for y = yStart + 1, yStart + #arg + 1 do
  19. term.setCursorPos(xStart, y)
  20. write(" ")
  21. term.setCursorPos(xEnd, y)
  22. write(" ")
  23. end
  24.  
  25. --[[ This writes the title, which is the first string within
  26. the '...'
  27. --]]
  28. term.setTextColour(textCol)
  29. term.setCursorPos((xEnd - xStart - #arg[1])/2 + xStart + 1, yStart)
  30. write(arg[1])
  31.  
  32. --[[ This part fills the insides of the box with the desired
  33. colour
  34. --]]
  35. term.setBackgroundColour(boxCol)
  36. for x = xStart + 1, xEnd - 1 do
  37. for y = yStart + 1, yStart + #arg + 1 do
  38. term.setCursorPos(x, y)
  39. write(" ")
  40. end
  41. end
  42.  
  43. --[[ arg is '...' and accepts as many as you want, but of course - having
  44. more than 16? would be silly.
  45. It centeres each text within the box
  46. --]]
  47. for i = 2, #arg do
  48. if #arg[i] > maxLength then error("Length of arg #" .. i .. " exceeds max limit of " .. maxLength .. " characters.") end
  49. term.setCursorPos((xEnd - xStart - #arg[i])/2 + xStart + 1, yStart + i)
  50. write(arg[i])
  51. end
  52.  
  53. --[[ Resets the variables and sets the cursorpos to be after the box. --]]
  54. term.setBackgroundColour(colours.black)
  55. term.setTextColour(colours.white)
  56. term.setCursorPos(1, yStart + #arg + 4)
  57. end
  58.  
  59.  
  60. function printCentered(y, s)
  61. local x = math.floor((w - string.len(s)/2)
  62. term.setCursorPos(x, y)
  63. term.clearLine()
  64. term.write(s)
  65. end
  66.  
  67. local function drawMenu()
  68. term.clear()
  69. drawSquare(colours.lime, colours.lightBlue, colours.red, 10,30,2, "Warning", "It works!", "lssssssssssssstol", "Line 3", "Line 4")
  70. end
  71. drawMenu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement