DrFair

board

Jan 26th, 2013
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. rednet.open("right")
  2. m = peripheral.wrap("top")
  3. w,h = m.getSize()
  4. w = w+1
  5. h = h+1
  6. menu = "main"
  7. col = { ["white"]=1, ["orange"]=2, ["magenta"]=4, ["lightblue"]=8, ["yellow"]=16, ["lime"]=32, ["pink"]=64, ["gray"]=128, ["lightgray"]=256, ["cyan"]=512, ["purple"]=1024, ["blue"]=2048, ["brown"]=4096, ["green"]=8192, ["red"]=16384, ["black"]=32768 }
  8.  
  9. function swrite(str,x,y,color)
  10. m.setCursorPos(x,y)
  11. m.setTextColor(col[color])
  12. m.write(str)
  13. end
  14.  
  15. function drawbox(str,x1,x2,y1,y2,strcol,color)
  16. m.setCursorPos(x1,y1)
  17. m.setBackgroundColor(col[color])
  18. m.setTextColor(col[strcol])
  19. local bw = x2-x1
  20. local bh = y2-y1
  21. local bstr = " "
  22. while #bstr < bw do
  23. bstr = bstr.." "
  24. end
  25. for i=1,bh do
  26. m.setCursorPos(x1,y1+i-1)
  27. m.write(bstr)
  28. end
  29. m.setCursorPos(x1+bw/2-#str/2,y1+bh/2)
  30. m.write(str)
  31. m.setBackgroundColor(col["black"])
  32. return { [1]=x1, [2]=x2, [3]=y1, [4]=y2 }
  33. end
  34.  
  35. function press(but)
  36. if event == "monitor_touch" then
  37. if pr2 >= but[1] and pr2 < but[2] and pr3 >= but[3] and pr3 < but[4] then
  38. return true
  39. else
  40. return false
  41. end
  42. end
  43. end
  44.  
  45. function drawoutline(str,strcol,color)
  46. m.setBackgroundColor(col[color])
  47. m.setTextColor(col[strcol])
  48. drawbox(str,1,w,1,2,strcol,color)
  49. drawbox("",1,2,1,h,strcol,color)
  50. drawbox("",w-1,w,1,h,strcol,color)
  51. drawbox("",1,w,h-1,h,strcol,color)
  52. end
  53.  
  54. function drawmainmenu()
  55. drawoutline("Welcome to Fair's base!","black","white")
  56. smain = drawbox("Storage",4,w-4,4,7,"black","yellow")
  57. pmain = drawbox("Production",4,w-4,9,12,"black","green")
  58. omain = drawbox("Other",4,w-4,14,17,"black","blue")
  59. menu = "main"
  60. end
  61.  
  62. m.clear()
  63. drawmainmenu()
  64.  
  65. while true do
  66. event,pr1,pr2,pr3 = os.pullEvent()
  67. if press(smain) then
  68. print("Pressed storage!")
  69. elseif press(pmain) then
  70. print("Pressed production!")
  71. elseif press(omain) then
  72. print("Pressed other!")
  73. end
  74. end
Advertisement
Add Comment
Please, Sign In to add comment