Guest User

Untitled

a guest
Mar 24th, 2013
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 KB | None | 0 0
  1. local m = peripheral.wrap( "SIDE" )
  2. local w, h = m.getSize()
  3. local divx = math.floor((w-3) / 3)
  4. local divy = math.floor((y-1) / 2)
  5. local butColor = colors.red
  6. local usedColor = colors.pink
  7. local colorBUND = 0
  8. local tCoords = {
  9. -- xMin, xMax, yMin, yMax, numb
  10. [1] = {1, 1+divx, 1, 1+divy, text = "1", used = false, colorVal = 1},
  11. [2] = {2+divx, 3+divx, 2+divy, 3+divy, text = "2", used = false, colorVal = 2},
  12. [3] = {4+divx, 5+divx, 2+divy, 3+divy, text = "3", used = false, colorVal = 4},
  13. [4] = {6+divx, 7+divx, 4+divy, 5+divy, text = "4", used = false, colorVal = 8},
  14. [5] = {8+divx, 9+divx, 4+divy, 5+divy, text = "5", used = false, colorVal = 16},
  15. [6] = {10+divx, 11+divx, 4+divy, 5+divy, text = "6", used = false, colorVal = 32}
  16. }
  17.  
  18. function fillButton( xMin, xMax, yMin, yMax, color)
  19. local color = color or colors.black
  20. m.setBackgroundColor( color )
  21. for i = 1, yMax - yMin do
  22. term.setCursorPos( xMin, i )
  23. m.write( string.rep( " ", xMax - xMin ))
  24. end
  25. m.setBackgroundColor( colors.black )
  26. end
  27. function cWrite( str, yPos, color)
  28. local color = color or colors.white
  29. local w, h = m.getSize()
  30. m.setCursorPos( math.floor( (w - #str)\2), yPos)
  31. m.setTextColor( color )
  32. m.write( str )
  33. m.setTextColor( colors.white )
  34. end
  35. function cWriteBound( xMin, xMax, str)
  36. local bound = xMax - xMin
  37. return xMin + math.floor( (bound - #str )/2 )
  38. end
  39.  
  40. while true do
  41. cWrite( "Activate", math.floor(y/2), colors.white)
  42. fillButton( w-(w-1), w-1, y-(y-1), y-1, colors.red)
  43. local evt = { os.pullEvent( "monitor_touch") }
  44. if evt[3] >= w - (w - 1) and evt[3] <= w - 1 and evt[4] >= y - (y - 1) and evt[4] <= y - 1 then
  45. break
  46. end
  47. end
  48.  
  49. m.clear()
  50. for i = 1, #tCoords do
  51. fillButton( tCoords[i][1], tCoords[i][2], tCoords[i][3], tCoords[i][4], butColor)
  52. if i <= 3 then
  53. term.setCursorPos( cWriteBound(tCoords[i][1], tCoords[i][2], tCoords[i].text ), math.floor(divy/2) )
  54. else
  55. term.setCursorPos( cWriteBound(tCoords[i][1], tCoords[i][2], tCoords[i].text ), math.floor(divy/2) + divy )
  56. end
  57. write(tCoords[i].text)
  58. end
  59.  
  60. while true do
  61. local evt = {os.pullEvent("monitor_touch")}
  62. local button
  63. for i = 1, #tCoords do
  64. if evt[3] >= tCoords[i][1] and evt[3] <= tCoords[i][2] and evt[4] >= tCoords[i][3] and evt[4] <= tCoords[i][4] then
  65. button = i
  66. end
  67. end
  68.  
  69. if type( button ) == "number" then
  70. if not tCoords[button].used then
  71. fillButton( tCoords[button][1], tCoords[button][2], tCoords[button][3], tCoords[button][4], usedColor)
  72. tCoords[button].used = true
  73. colorBUND = colorBUND + tCoords[button].colorVal
  74. elseif tCoords[button].used then
  75. fillButton( tCoords[button][1], tCoords[button][2], tCoords[button][3], tCoords[button][4], butColor)
  76. tCoords[button].used = false
  77. colorBUND = colorBUND - tCoords[button].colorVal
  78. end
  79. rs.setBundledOutput( "SIDE", colorBUND )
  80. end
  81. end
Advertisement
Add Comment
Please, Sign In to add comment