dubbleM

My First Pogramm

May 24th, 2013
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.75 KB | None | 0 0
  1. local mon = peripheral.wrap("left")
  2. mon.setTextScale(0.5)
  3. mon.setTextColor(colors.white)
  4. local button={}
  5. mon.setBackgroundColor(colors.black)
  6.  
  7. function setTable(name, xmin, xmax, ymin, ymax, col)
  8. button[name] = {}
  9. button[name]["active"] = false
  10. button[name]["xmin"] = xmin
  11. button[name]["ymin"] = ymin
  12. button[name]["xmax"] = xmax
  13. button[name]["ymax"] = ymax
  14. button[name]["colour"] = col
  15. end
  16.  
  17. function fillTable()
  18. setTable("Einschalten", 2, 16, 10, 14, colours.blue)
  19. setTable("Ausschalten", 21, 35, 10, 14, colours.red)
  20. end
  21.  
  22. function fill(text, color, bData)
  23. mon.setBackgroundColor(color)
  24. local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2)
  25. local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(text)) /2) +1
  26. for j = bData["ymin"], bData["ymax"] do
  27. mon.setCursorPos(bData["xmin"], j)
  28. if j == yspot then
  29. for k = 0, bData["xmax"] - bData["xmin"] - string.len(text) +1 do
  30. if k == xspot then
  31. mon.write(text)
  32. else
  33. mon.write(" ")
  34. end
  35. end
  36. else
  37. for i = bData["xmin"], bData["xmax"] do
  38. mon.write(" ")
  39. end
  40. end
  41. end
  42. mon.setBackgroundColor(colors.black)
  43. end
  44.  
  45. function screen()
  46. local currColor
  47. for name,data in pairs(button) do
  48. local on = data["active"]
  49. if on == true then currColor = colors.lime else currColor = colors.lightGray end
  50. fill(name, currColor, data)
  51. end
  52. end
  53.  
  54. function checkxy(x, y)
  55. local new = false
  56. local newname
  57. for name, data in pairs(button) do
  58. data["active"] = false
  59. if y>=data["ymin"] and y <= data["ymax"] then
  60. if x>=data["xmin"] and x<= data["xmax"] then
  61. rs.setBundledOutput("bottom", data["colour"])
  62. new = true
  63. newname = name
  64. end
  65. end
  66. end
  67. if new then
  68. button[newname]["active"] = true
  69. end
  70. end
  71.  
  72. function heading(text)
  73. w, h = mon.getSize()
  74. mon.setCursorPos((w-string.len(text))/2+1, 1)
  75. mon.write(text)
  76. end
  77.  
  78. function checkRedstone()
  79. local c = rs.getBundledInput("back")
  80. if rs.getBundledOutput("bottom") ~= c then
  81. rs.setBundledOutput("bottom", 0)
  82. for name, data in pairs(button) do
  83. if data["colour"] == c then
  84. data["active"] = true
  85. else
  86. data["active"] = false
  87. end
  88. end
  89. end
  90. end
  91.  
  92. fillTable()
  93. while true do
  94. mon.clear()
  95. heading("Please Select Floor")
  96. screen()
  97. local e,side,x,y = os.pullEvent()
  98. if e == "monitor_touch" then
  99. checkxy(x,y)
  100. else
  101. if e == "redstone" then
  102. checkRedstone()
  103. else
  104. end
  105. end
  106. sleep(.1)
  107. end
Advertisement
Add Comment
Please, Sign In to add comment