Advertisement
kurruk

code

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