NanoBob

Computercraft storage client

Jun 21st, 2016
509
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 20.08 KB | None | 0 0
  1. local targetChannel = 666
  2.  
  3.  
  4. if fs.exists("event")==false then shell.run("pastebin get UKPy4iiE event") end
  5. if os.loadAPI("event") == false then error("Failed to load event API") end
  6.  
  7. if fs.exists("utils") == false then shell.run("pastebin get dyvydHtK utils") end
  8. if os.loadAPI("utils") == false then error("Failed to load utils API") end
  9.  
  10. if fs.exists("data") == false then shell.run("pastebin get LnvzL7ur data") end
  11. if os.loadAPI("data") == false then error("Failed to load data API") end
  12.  
  13. if fs.exists("button") == false then shell.run("pastebin get UmerzDUF button") end
  14. if os.loadAPI("button") == false then error("Failed to load button API") end
  15.  
  16.  
  17. button.setMonitor(term)
  18. --button.setTextColor(colors.green)
  19.  
  20. if data.get("channel","channel") == nil then
  21.     io.write("Channel number: ")
  22.     data.set("channel",read(),"channel")
  23. end
  24. local localChannel = tonumber(data.get("channel","channel"))
  25.  
  26. local previous = os.clock()
  27. local modem = peripheral.wrap("back")
  28. local ping
  29. local itemlist = {}
  30. local recipes = {}
  31. local cachedItems = {}
  32. local cachedRecipes = {}
  33. local searchScroll = 0
  34. local searchQuery = ""
  35. local requestCount = ""
  36. local requestItemString = ""
  37. local requestCountString = ""
  38. local craftRecipeString = ""
  39. local recipeSearchString = ""
  40. local itemCount
  41. local turtles = {}
  42. local que = {}
  43. local currentRecipe = {}
  44. modem.open(localChannel)
  45.  
  46. local screens = {
  47.     home = {},
  48.     search = {},
  49.     getCount = {},
  50.     request = {},
  51.     turtles = {},
  52.     que = {},
  53.     requestItem = {},
  54.     craft = {},
  55.     recipes = {},
  56. }
  57.  
  58. screens.update = button.addButton(1,20,26,1,"Update",false,false)
  59. screens.homeButton = button.addButton(1,2,26,1,"Home",false,false)
  60.  
  61. screens.home.search = button.addButton(2,5,11,1,"Search",false,false)
  62. screens.home.getCount = button.addButton(15,5,11,1,"Get Count",false,false)
  63. screens.home.request = button.addButton(2,7,11,1,"Request",false,false)
  64. screens.home.turtles = button.addButton(15,7,11,1,"Turtles",false,false)
  65. screens.home.que = button.addButton(2,9,11,1,"View Que",false,false)
  66. screens.home.ping = button.addButton(15,9,11,1,"Ping",false,false)
  67. screens.home.craft = button.addButton(2,11,11,1,"Craft",false,false)
  68. screens.home.addRecipe = button.addButton(15,11,11,1,"New recipes",false,false)
  69.  
  70. screens.recipes.newRecipe = button.addButton(4,18,21,1,"Add recipe",false,false)
  71.  
  72. screens.request.request = button.addButton(2,10,24,1,"request",false,false)
  73.  
  74. screens.requestItem.request = button.addButton(2,10,24,1,"request",false,false)
  75.  
  76. screens.getCount.request = button.addButton(2,10,24,1,"request",false,false)
  77.  
  78. local currentScreen = screens.home
  79.  
  80. term.setCursorPos(2,10)
  81. term.setBackgroundColor(colors.black)
  82.  
  83. function drawReadBox(title)
  84.     term.setBackgroundColor(colors.green)
  85.     term.setCursorPos(1,11)
  86.     term.write(title.."                                   ")
  87.     term.setCursorPos(1,12)
  88.     term.write(" ")
  89.     term.setBackgroundColor(colors.white)
  90.     term.write("                        ")
  91.     term.setBackgroundColor(colors.green)
  92.     term.write(" ")
  93.     term.setBackgroundColor(colors.green)
  94.     term.setCursorPos(1,13)
  95.     term.write("                           ")
  96.     term.setTextColor(colors.black)
  97.     term.setBackgroundColor(colors.white)
  98.     term.setCursorPos(2,12)
  99. end
  100.  
  101.  
  102. local buttonFunctions = {
  103.     [screens.homeButton] = function()
  104.         currentScreen = screens.home
  105.     end,
  106.    
  107.     [screens.update] = function()
  108.         error(shell.run("update"))
  109.     end,
  110.    
  111.     [screens.home.ping] = function()
  112.         previous = os.clock()
  113.         modem.transmit(targetChannel,localChannel,"ping")
  114.     end,
  115.    
  116.     [screens.home.search] = function()
  117.         currentScreen = screens.search
  118.         modem.transmit(targetChannel,localChannel,"requestItemList")
  119.         searchQuery = ""
  120.     end,
  121.    
  122.     [screens.home.request] = function()
  123.         requestItemString = ""
  124.         currentScreen = screens.request
  125.     end,
  126.    
  127.     [screens.home.getCount] = function()
  128.         requestCountString = ""
  129.         currentScreen = screens.getCount
  130.     end,
  131.    
  132.     [screens.home.turtles] = function()
  133.         currentScreen = screens.turtles
  134.         modem.transmit(targetChannel,localChannel,"requestTurtles")
  135.         local tEvent,side,channel,replyChannel,message = os.pullEvent("modem_message")
  136.         event.trigger(tEvent,side,channel,replyChannel,message)
  137.     end,
  138.    
  139.     [screens.home.que] = function()
  140.         currentScreen = screens.que
  141.         modem.transmit(targetChannel,localChannel,"requestQue")
  142.         local tEvent,side,channel,replyChannel,message = os.pullEvent("modem_message")
  143.         event.trigger(tEvent,side,channel,replyChannel,message)
  144.     end,
  145.    
  146.     [screens.home.craft] = function()
  147.         currentScreen = screens.craft
  148.         craftRecipeString=""
  149.         searchScroll = 10000
  150.         modem.transmit(targetChannel,localChannel,"requestRecipes")
  151.         local tEvent,side,channel,replyChannel,message = os.pullEvent("modem_message")
  152.         event.trigger(tEvent,side,channel,replyChannel,message)
  153.     end,
  154.    
  155.     [screens.home.addRecipe] = function()
  156.         currentScreen = screens.recipes
  157.         currentRecipe = { }
  158.     end,
  159.    
  160.     [screens.request.request] = function()
  161.         requestCount = ""
  162.         currentScreen = screens.requestItem
  163.     end,
  164.    
  165.     [screens.requestItem.request] = function()
  166.         local count = tonumber(requestCount)
  167.         if type(count)~= "number" or count == 0 then
  168.             return
  169.         end
  170.         local message = "requestItem|"..tostring(requestItemString).."|"..tostring(count)
  171.         currentScreen = screens.home
  172.         modem.transmit(targetChannel,localChannel,message)
  173.     end,
  174.    
  175.     [screens.getCount.request] = function()
  176.         local message = "getItemCount|"..tostring(requestCountString)
  177.         modem.transmit(targetChannel,localChannel,message)
  178.         local tEvent,side,channel,replyChannel,message = os.pullEvent("modem_message")
  179.         event.trigger(tEvent,side,channel,replyChannel,message)
  180.         requestCountString = ""
  181.         onChar("")
  182.     end,
  183.    
  184.     [screens.recipes.newRecipe] = function()
  185.         drawReadBox("Recipe name:")
  186.         local recipeString = read() .. "|"
  187.         for i=1,9 do
  188.             recipeString = recipeString .. ( currentRecipe[i] or "" ).. ";"
  189.         end
  190.         -- currentRecipe
  191.         currentScreen = screens.home
  192.         modem.transmit(targetChannel,localChannel,"addRecipe|"..recipeString)
  193.     end,
  194.    
  195. }
  196.  
  197. function handleClicks(buttonID)
  198.     if buttonFunctions[buttonID] == nil then return end
  199.     buttonFunctions[buttonID]()
  200. end
  201. event.addHandler("onButtonClick",handleClicks)
  202.  
  203. function onChar(letter)
  204.     if string.len(letter)>0 then
  205.         local letter = string.lower(letter)
  206.     end
  207.     if currentScreen == screens.search then
  208.         searchQuery = searchQuery..letter
  209.         term.setCursorPos(2,6)
  210.         term.setBackgroundColor(colors.white)
  211.         term.setTextColor(colors.black)
  212.         if string.len(searchQuery)>= 23 then
  213.             term.write(string.sub(searchQuery,string.len(searchQuery)-22,string.len(searchQuery)))
  214.         else
  215.             term.write(searchQuery)
  216.             for i = string.len(searchQuery),23 do
  217.                 term.write(" ")
  218.             end
  219.         end
  220.         cachedItems = {}
  221.         for name,count in pairs(itemlist) do
  222.             if string.len(searchQuery) == 0 or string.match(name,searchQuery)~= nil  then
  223.                 cachedItems[#cachedItems+1] = {name = name,count = count}
  224.             end
  225.         end
  226.         searchScroll = 0
  227.         drawSearch(true)
  228.     elseif currentScreen == screens.requestItem then
  229.         requestCount = requestCount..letter
  230.         term.setCursorPos(2,6)
  231.         term.setTextColor(colors.black)
  232.         if string.len(requestCount)>= 4 then
  233.             term.write(string.sub(requestCount,string.len(requestCount)-4,string.len(requestCount)))
  234.         else
  235.             term.write(requestCount)
  236.             for i = string.len(requestCount),4 do
  237.                 term.write(" ")
  238.             end
  239.         end
  240.     elseif currentScreen == screens.request then
  241.         requestItemString = requestItemString..letter
  242.         term.setCursorPos(2,6)
  243.         term.setTextColor(colors.black)
  244.         if string.len(requestItemString)>= 23 then
  245.             term.write(string.sub(requestItemString,string.len(requestItemString)-22,string.len(requestItemString)))
  246.         else
  247.             term.write(requestItemString)
  248.             for i = string.len(requestItemString),23 do
  249.                 term.write(" ")
  250.             end
  251.         end
  252.     elseif currentScreen == screens.getCount then
  253.         requestCountString = requestCountString..letter
  254.         term.setCursorPos(2,6)
  255.         term.setTextColor(colors.black)
  256.         if string.len(requestCountString)>= 23 then
  257.             term.write(string.sub(requestCountString,string.len(requestCountString)-22,string.len(requestCountString)))
  258.         else
  259.             term.write(requestCountString)
  260.             for i = string.len(requestCountString),23 do
  261.                 term.write(" ")
  262.             end
  263.         end
  264.     elseif currentScreen == screens.craft then
  265.         searchScroll = 0
  266.         recipeSearchString = recipeSearchString..letter
  267.         term.setCursorPos(2,6)
  268.         term.setTextColor(colors.black)
  269.         term.setBackgroundColor(colors.white)
  270.         if string.len(recipeSearchString)>= 23 then
  271.             term.write(string.sub(recipeSearchString,string.len(recipeSearchString)-22,string.len(recipeSearchString)))
  272.         else
  273.             term.write(recipeSearchString)
  274.             for i = string.len(recipeSearchString),23 do
  275.                 term.write(" ")
  276.             end
  277.         end
  278.         cachedRecipes = {}
  279.         for _,name in pairs(recipes) do
  280.             if string.len(recipeSearchString) == 0 or string.match(name,recipeSearchString)~= nil then
  281.                 cachedRecipes[#cachedRecipes+1] = name
  282.             end
  283.         end
  284.         drawCraft(true)
  285.     end
  286. end
  287. event.addHandler("char",onChar)
  288.  
  289. function onKey(key)
  290.     if currentScreen == screens.search then
  291.         if key == 14 then -- backspace
  292.             searchQuery = string.sub(searchQuery,1,string.len(searchQuery)-1)
  293.             onChar("")
  294.         elseif key == 28 then  
  295.             cachedItems = {}
  296.             for name,count in pairs(itemlist) do
  297.                 if string.len(searchQuery) == 0 or string.match(name,searchQuery)~= nil then
  298.                     cachedItems[#cachedItems+1] = {name = name,count = count}
  299.                 end
  300.             end
  301.             searchScroll = 0
  302.             drawSearch(true)
  303.         end
  304.     elseif currentScreen == screens.requestItem then
  305.         if key == 14 then -- backspace
  306.             requestCount = string.sub(requestCount,1,string.len(requestCount)-1)
  307.             onChar("")
  308.         elseif key == 28 then  
  309.             buttonFunctions[screens.requestItem.request]()
  310.             button.drawAllButtons()
  311.         end
  312.     elseif currentScreen == screens.request then
  313.         if key == 14 then -- backspace
  314.             requestItemString = string.sub(requestItemString,1,string.len(requestItemString)-1)
  315.             onChar("")
  316.         elseif key == 28 then  
  317.             buttonFunctions[screens.request.request]()
  318.             button.drawAllButtons()
  319.         end
  320.     elseif currentScreen == screens.getCount then
  321.         if key == 14 then -- backspace
  322.             requestCountString = string.sub(requestCountString,1,string.len(requestCountString)-1)
  323.             onChar("")
  324.         elseif key == 28 then  
  325.             buttonFunctions[screens.getCount.request]()
  326.             button.drawAllButtons()
  327.         end
  328.     elseif currentScreen == screens.craft then
  329.         if key == 14 then -- backspace
  330.             recipeSearchString = string.sub(recipeSearchString,1,string.len(recipeSearchString)-1)
  331.             onChar("")
  332.         elseif key == 28 then  
  333.             buttonFunctions[screens.craft.craft]()
  334.             button.drawAllButtons()
  335.         end
  336.     end
  337. end
  338. event.addHandler("key",onKey)
  339.    
  340. local drawFunctions = {
  341.     [screens.search] = function (fromChar)
  342.         term.setCursorPos(2,5)
  343.         term.setBackgroundColor(colors.black)
  344.         term.write("Search:")
  345.         term.setCursorPos(2,6)
  346.         term.setBackgroundColor(colors.white)
  347.         term.write(searchQuery)
  348.         for i=1,24 - string.len(searchQuery) do
  349.             term.write(" ")
  350.         end
  351.         --term.setBackgroundColor(colors.white)
  352.         --term.write("                        ")
  353.         term.setCursorPos(2,6)
  354.         if fromChar == nil then
  355.             --onChar("")
  356.         end
  357.         term.setTextColor(colors.yellow)
  358.         for i = 1,10 do
  359.             local id = i+searchScroll
  360.             local item = cachedItems[id]
  361.             if item == nil then
  362.                 term.setBackgroundColor(colors.black)
  363.                 term.setCursorPos(1,8+i)
  364.                 term.write("                          ")
  365.             else
  366.                 term.setCursorPos(1,8+i)
  367.                 if math.floor(i/2) == math.ceil(i/2) then
  368.                     term.setBackgroundColor(colors.gray)
  369.                 else
  370.                     term.setBackgroundColor(colors.lightGray)
  371.                 end
  372.                 local itemString = tostring(item.name).." x "..tostring(item.count)
  373.                 term.write(itemString)
  374.                 for i = string.len(itemString),25 do
  375.                     term.write(" ")
  376.                 end
  377.             end
  378.         end
  379.     end,
  380.     [screens.requestItem] = function()
  381.         term.setCursorPos(2,5)
  382.         term.setBackgroundColor(colors.black)
  383.         term.write("Count:")
  384.         term.setCursorPos(2,6)
  385.         term.setBackgroundColor(colors.white)
  386.         term.write("     ")
  387.         term.setCursorPos(2,6)
  388.         onChar("")
  389.     end,
  390.     [screens.request] = function()
  391.         term.setCursorPos(2,5)
  392.         term.setBackgroundColor(colors.black)
  393.         term.write("Name:")
  394.         term.setCursorPos(2,6)
  395.         term.setBackgroundColor(colors.white)
  396.         term.write("                        ")
  397.         term.setCursorPos(2,6)
  398.         onChar("")
  399.     end,
  400.     [screens.turtles] = function()
  401.         term.setBackgroundColor(colors.black)
  402.         term.setCursorPos(1,4)
  403.         term.write("Turtles:")
  404.         for id,turtle in pairs(turtles) do
  405.             term.setCursorPos(1,5+id*2)
  406.             if math.floor(id/2) == math.ceil(id/2) then
  407.                 term.setBackgroundColor(colors.gray)
  408.             else
  409.                 term.setBackgroundColor(colors.lightGray)
  410.             end
  411.             term.setTextColor(colors.yellow)
  412.             term.write("id: "..turtle.id.." Status: "..turtle.status)
  413.             if turtle.task~= "nil" then
  414.                 term.setCursorPos(1,5+id*2+1)
  415.                 term.write(turtle.task)
  416.             end
  417.         end
  418.     end,
  419.     [screens.que] = function()
  420.         term.setBackgroundColor(colors.black)
  421.         term.setCursorPos(1,4)
  422.         term.write("Que:")
  423.         for id,command in pairs(que) do
  424.             term.setCursorPos(1,5+id)
  425.             if math.floor(id/2) == math.ceil(id/2) then
  426.                 term.setBackgroundColor(colors.gray)
  427.             else
  428.                 term.setBackgroundColor(colors.lightGray)
  429.             end
  430.             term.setTextColor(colors.yellow)
  431.             if command~= nil then
  432.                 term.write(command)
  433.             end
  434.         end
  435.     end,
  436.     [screens.getCount] = function()
  437.         term.setCursorPos(2,5)
  438.         term.setBackgroundColor(colors.black)
  439.         term.write("Name:")
  440.         term.setCursorPos(2,8)
  441.         term.write("Result: "..tostring(itemCount))
  442.         term.setCursorPos(2,6)
  443.         term.setBackgroundColor(colors.white)
  444.         term.write("                        ")
  445.         term.setCursorPos(2,6)
  446.         onChar("")
  447.     end,
  448.     [screens.craft] = function()
  449.         term.setCursorPos(2,5)
  450.         term.setBackgroundColor(colors.black)
  451.         term.write("Search recipes:")
  452.         term.setCursorPos(2,6)
  453.         term.setBackgroundColor(colors.white)
  454.         term.write(recipeSearchString)
  455.         for i=1,24 - string.len(recipeSearchString) do
  456.             term.write(" ")
  457.         end
  458.         term.setCursorPos(2,6)
  459.         term.setTextColor(colors.yellow)
  460.         for i = 1,10 do
  461.             local id = i+searchScroll
  462.             local item = cachedRecipes[id]
  463.             if item == nil then
  464.                 term.setBackgroundColor(colors.black)
  465.                 term.setCursorPos(1,8+i)
  466.                 term.write("                          ")
  467.             else
  468.                 term.setCursorPos(1,8+i)
  469.                 if i%2==1 then
  470.                     term.setBackgroundColor(colors.gray)
  471.                 else
  472.                     term.setBackgroundColor(colors.lightGray)
  473.                 end
  474.                 local itemString = tostring(item)
  475.                 term.write(itemString)
  476.                 for i = string.len(itemString),25 do
  477.                     term.write(" ")
  478.                 end
  479.             end
  480.         end
  481.     end,
  482.     [screens.recipes] = function()
  483.         term.setCursorPos(2,4)
  484.         term.setBackgroundColor(colors.black)
  485.         term.setTextColor(colors.white)
  486.         term.write("Create recipe:")
  487.         for i = 0,8 do
  488.             if i%2==1 then
  489.                 term.setBackgroundColor(colors.lightGray)
  490.             else
  491.                 term.setBackgroundColor(colors.gray)
  492.             end
  493.             local left = 5 + (i * 6) - ( ( math.floor(i/3) * 3 ) * 6)
  494.             local top = 7 + ( math.floor(i/3) * 3)
  495.             term.setCursorPos(left,top)
  496.             term.write("      ")
  497.             term.setCursorPos(left,top+1)
  498.             term.write("      ")
  499.             term.setCursorPos(left,top+1)
  500.             if currentRecipe[i+1]~=nil then
  501.                 term.write(string.sub(currentRecipe[i+1],0,6))
  502.             end
  503.             term.setCursorPos(left,top+2)
  504.             term.write("      ")
  505.         end
  506.     end,
  507. }
  508.  
  509. function recipeClicked(button,x,y)
  510.     if currentScreen == screens.recipes and button == 1 then
  511.         local column = math.floor((x - 5) / 6 + 1 )
  512.         if column < 1 or column > 3 then return end
  513.         local row = math.floor((y - 7) / 3 + 1)
  514.         if row < 1 or row > 3 then return end
  515.         local position = math.floor(column + ( row - 1 ) * 3)
  516.        
  517.         drawReadBox("Item name (slot "..position..")        ")
  518.         local name = read()
  519.         currentRecipe[position] = name
  520.         term.setBackgroundColor(colors.green)
  521.         term.clear()
  522.         drawFunctions[currentScreen]()
  523.         drawOthers()
  524.     end
  525. end
  526. event.addHandler("mouse_click",recipeClicked)
  527.  
  528. function onClick(mouseButton,x,y)
  529.     if currentScreen == screens.search then
  530.         if y>8 and y<20 then
  531.             local item = cachedItems[y-8+searchScroll]
  532.             if item == nil then return end
  533.             requestItemString = item.name
  534.             requestCount = ""
  535.             currentScreen = screens.requestItem
  536.             button.drawAllButtons()
  537.         end
  538.     elseif currentScreen == screens.craft then
  539.         if y>8 and y<20 then
  540.             local item = cachedRecipes[y-8+searchScroll]
  541.             if item == nil then return end
  542.             drawReadBox("Procedure count: ")
  543.             local count = tonumber(read())
  544.             if count==nil then return end
  545.             local message = "requestCraft|"..item.."|"..count
  546.             currentScreen = screens.home
  547.             button.drawAllButtons()
  548.             modem.transmit(targetChannel,localChannel,message)
  549.         end
  550.     end
  551. end
  552. event.addHandler("mouse_click",onClick)
  553.  
  554. local messageHandles = {
  555.     ["ping"] = function(replyChannel,message)
  556.         return "pong"
  557.     end,
  558.     ["pong"] = drawPing,
  559.     ["returnItemList"] = function(replyChannel,message)
  560.         itemlist = {}
  561.         local items = utils.split(message,"|",2)
  562.         local i = 1
  563.         while true do
  564.             local item = utils.split(items,";",i)
  565.             if string.len(item) == 0 then
  566.                 break
  567.             end
  568.             local name = utils.split(item,",",1)
  569.             local count = tonumber(utils.split(item,",",2))
  570.             if name == nil or count == nil then
  571.                 break
  572.             end
  573.             itemlist[name] = count
  574.             i = i+1
  575.         end
  576.     end,
  577.     ["returnRecipes"] = function(replyChannel,message)
  578.         recipes = {}
  579.         local recipesString = utils.split(message,"|",2)
  580.         local i = 1
  581.         while true do
  582.             local recipe = utils.split(recipesString,";",i)
  583.             print(recipe)
  584.             if string.len(recipe) == 0 then
  585.                 break
  586.             end
  587.             recipes[#recipes+1] = recipe
  588.             i = i+1
  589.         end
  590.     end,
  591.     ["returnQue"] = function(_,message)
  592.         que = {}
  593.         local i = 1
  594.         while true do
  595.             local command = utils.split(message,"|",i+1)
  596.             if command == nil then
  597.                 break
  598.             end
  599.             que[#que+1] = command
  600.             i = i+1
  601.         end
  602.         drawFunctions[currentScreen](false)
  603.     end,
  604.     ["returnTurtles"] = function(_,message)
  605.         turtles = {}
  606.         local turtlesString = utils.split(message,"|",2)
  607.         local i = 1
  608.         while true do
  609.             local turtle = utils.split(turtlesString,";",i)
  610.             if turtle == nil or string.len(turtle) == 0 then
  611.                 break
  612.             end
  613.             local id = tostring(utils.split(turtle,",",1))
  614.             local status = tostring(utils.split(turtle,",",2))
  615.             local task = tostring(utils.split(turtle,",",3))
  616.             if id == nil or status == nil  then
  617.                 break
  618.             end
  619.             turtles[#turtles+1] = {id = id,status = status,task = task}
  620.             i = i+1
  621.         end
  622.         drawFunctions[currentScreen](false)
  623.     end,
  624.     ["returnItemCount"] = function(_,message)
  625.         itemCount = utils.split(message,"|",2)
  626.         drawFunctions[currentScreen](false)
  627.     end,
  628.    
  629. }
  630.  
  631. function handleMessages(side,channel,replyChannel,message)
  632.     if replyChannel == nil then return end
  633.     local messageType = utils.split(message,"|",1)
  634.     if messageHandles[messageType] == nil then return end
  635.     local returnMessage = messageHandles[messageType](replyChannel,message)
  636.     if returnMessage == nil then return end
  637.     wireless.transmit(replyChannel,localChannel,returnMessage)
  638. end
  639. event.addHandler("modem_message",handleMessages)
  640.  
  641. function drawSearch(...)
  642.     drawFunctions[screens.search](...)
  643. end
  644.  
  645. function drawCraft(...)
  646.     drawFunctions[screens.craft](...)
  647. end
  648.  
  649. function drawPing()
  650.     if previous~= nil then
  651.         ping = os.clock()-previous
  652.         previous = nil
  653.     end
  654.     term.setCursorPos(1,1)
  655.     term.setBackgroundColor(256)
  656.     --term.setTextColor(colors.green)
  657.     term.write(ping.."                                           ")
  658. end
  659.  
  660. function drawOthers()
  661.     for screenName,buttons in pairs(screens) do
  662.         if type(buttons)~= "number" then
  663.             for name,buttonID in pairs(buttons) do
  664.                 if buttons == currentScreen then
  665.                     button.setVisible(buttonID,true)
  666.                 else
  667.                     button.setVisible(buttonID,false)
  668.                 end
  669.             end
  670.         end
  671.     end
  672.     button.drawAllButtons(true)
  673.     drawPing()
  674.     if drawFunctions[currentScreen] == nil then return end
  675.     drawFunctions[currentScreen]()
  676. end
  677. event.addHandler("onButtonsDrawn",drawOthers)
  678. drawOthers()
  679.  
  680. function scrolled(direction)
  681.     if currentScreen == screens.search then
  682.         searchScroll = searchScroll+direction
  683.         drawSearch()
  684.     elseif currentScreen == screens.craft then
  685.         searchScroll = searchScroll+direction
  686.         drawFunctions[screens.craft]()
  687.     end
  688. end
  689. event.addHandler("mouse_scroll",scrolled)
  690.  
  691. while true do
  692.     event.handleCCEvents()
  693. end
Add Comment
Please, Sign In to add comment