DrFair

Miningbore control

Jun 21st, 2013
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.73 KB | None | 0 0
  1. m = peripheral.wrap("top")
  2. w,h = m.getSize()
  3. w = w+1
  4. h = h+1
  5. 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 }
  6. active = false
  7. timeleft = 0
  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 drawbackground(str,strcol,color)
  46. drawbox("",1,w,1,h,strcol,color)
  47. drawbox("",2,w-1,2,h-1,"black","black")
  48. drawbox(str,1,w,1,2,strcol,color)
  49. end
  50.  
  51. function drawMenu()
  52. m.clear()
  53. drawbackground("Fair's Miningbore control","black","white")
  54. drawbox("Pick time active",4,w-3,3,3,"white","black")
  55. five = drawbox("5 min",4,w-3,5,8,"black","green")
  56. onefive = drawbox("15 min",4,w-3,10,13,"black","green")
  57. threezero = drawbox("30 min",4,w-3,15,18,"black","green")
  58. sixzero = drawbox("60 min",4,w-3,20,23,"black","green")
  59. end
  60.  
  61. function drawTimer()
  62. m.clear()
  63. drawbackground("Fair's Miningbore control","black","white")
  64. drawbox("Timer active.",4,w-3,3,3,"white","black")
  65. drawbox("Seconds left:",4,w-3,5,5,"white","black")
  66. drawbox(tostring(timeleft),4,w-3,6,6,"green","black")
  67. cancel = drawbox("Cancel",4,w-3,10,13,"black","red")
  68.  
  69. end
  70.  
  71. drawMenu()
  72.  
  73. while true do
  74. event,pr1,pr2,pr3 = os.pullEvent()
  75. if active then
  76. rs.setOutput("right",true)
  77. if press(cancel) or timeleft == 0 then
  78. rs.setOutput("right",false)
  79. active = false
  80. timeleft = 0
  81. drawMenu()
  82. end
  83. else
  84. rs.setOutput("right",false)
  85. if press(five) then
  86. timeleft = 300
  87. os.startTimer(1)
  88. drawTimer()
  89. active = true
  90. elseif press(onefive) then
  91. timeleft = 900
  92. os.startTimer(1)
  93. drawTimer()
  94. active = true
  95. elseif press(threezero) then
  96. timeleft = 1800
  97. os.startTimer(1)
  98. drawTimer()
  99. active = true
  100. elseif press(sixzero) then
  101. timeleft = 3600
  102. os.startTimer(1)
  103. drawTimer()
  104. active = true
  105. end
  106. end
  107. if event == "timer" and timeleft > 0 then
  108. timeleft = timeleft - 1
  109. drawTimer()
  110. os.startTimer(1)
  111. end
  112. end
Advertisement
Add Comment
Please, Sign In to add comment