Nessiesson

test

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