Advertisement
natie3

Turned vilager

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