Advertisement
kurruk

grr

Feb 20th, 2013
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.95 KB | None | 0 0
  1. p = peripheral.wrap("back")
  2. rednet.open("right")
  3. p.setTextScale(1.5)
  4. p.setBackgroundColor(colors.black)
  5. button={}
  6.  
  7. function split(str, delim, maxNb)
  8.  
  9.   if string.find(str, delim) == nil then
  10.     return { str }
  11.   end
  12.  
  13.   if maxNb == nil or maxNb < 1 then
  14.     maxNb = 0
  15.   end
  16.  
  17.   local result = {}
  18.   local pat = "(.-)" ..delim.. "()"
  19.   local nb = 0
  20.   local lastPos
  21.  
  22.   for part, pos in string.gmatch(str, pat) do
  23.     nb = nb + 1
  24.     result[nb] = part
  25.     if nb == maxNb then
  26.       break
  27.     end
  28.   end
  29.  
  30.   return result
  31.  
  32. end
  33.  
  34. function setTable(name, func, xmin, xmax, ymin, ymax)
  35.    button[name] = {}
  36.    button[name]["func"] = func
  37.    button[name]["active"] = false
  38.    button[name]["xmin"] = xmin
  39.    button[name]["ymin"] = ymin
  40.    button[name]["xmax"] = xmax
  41.    button[name]["ymax"] = ymax
  42. end
  43.  
  44. function cobble()
  45.   run = 0
  46.   p.clear()
  47.   setTable("1", send, 14, 21, 5, 9)
  48.   screenNum()
  49.   sleep(0.5)
  50.   function2()
  51. end
  52.  
  53. function send()
  54.     print(thing)
  55.     run = 1
  56. end
  57.  
  58. function fillNum(text, color, bData)
  59.   p.setBackgroundColor(colors.lime)
  60.   local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2)
  61.   local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(text)) /2) +1
  62.   for j = bData["ymin"], bData["ymax"] do
  63.     p.setCursorPos(bData["xmin"], bData["ymin"])
  64.     if j == yspot then
  65.       for k = 0, bData["xmax"] - bData["xmin"] - string.len(text) +1 do
  66.         if k == xspot then
  67.           p.write(text)
  68.         else
  69.           p.write(" ")
  70.         end
  71.       end
  72.     else
  73.       for i = bData["xmin"], bData["xmax"] do
  74.          p.write(" ")
  75.       end
  76.     end
  77.   end
  78.   p.setBackgroundColor(colors.black)
  79. end
  80.  
  81. function screenNum()
  82.   local currColor
  83.   for name,data in pairs(button) do
  84.     currColor = colors.lime
  85.     fillNum(name, currColor, data)
  86.   end
  87. end
  88.  
  89. function checkxy(x, y)
  90.    for name, data in pairs(button) do
  91.       if y >=data["ymin"] and  y <= data["ymax"] then
  92.          if x >=data["xmin"] and x <= data["xmax"] then
  93.             data["func"]()
  94.          end
  95.       end
  96.    end
  97. end
  98.  
  99. function fill(text, color, bData)
  100.     p.setCursorPos(bData["xmin"], bData["ymin"])
  101.     p.write(text)
  102. end
  103.  
  104. function screen()
  105.    for name,data in pairs(button) do
  106.       fill(name, currColor, data)
  107.    end
  108. end
  109.  
  110. run = 1
  111.  
  112. function1 = function()
  113. if run == 1 then
  114.   line = 2
  115.   item = 89
  116.   p.clear()
  117.   for i=1, 10 do
  118.  
  119.     rednet.send(item, "update")
  120.  
  121.     id, message = rednet.receive(0.5)
  122.  
  123.     if message == nil then
  124.       return
  125.     else
  126.       length = string.len(message) + 3
  127.       setTable(message, cobble, 3, length, line, line)
  128.       mess = {}
  129.       mess = split(message, ":")
  130.       thing = tostring(mess[1])
  131.       line = line + 1
  132.       item = item + 1
  133.       screen()
  134.     end
  135.   end
  136.   sleep(10)
  137. end
  138. end
  139.  
  140. function2 = function()
  141.  
  142.   event, side, x, y = os.pullEvent("monitor_touch")
  143.   print(x.." "..y)
  144.   checkxy(x,y)
  145.  
  146. end
  147.  
  148.  
  149. while true do
  150.   parallel.waitForAny(function2,function1)
  151. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement