Advertisement
pepeknamornik

Robot App

Feb 9th, 2020
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.35 KB | None | 0 0
  1. local w, h = term.getSize()
  2. local nastaveni={barva=colors.blue}
  3. local f=fs.open("/C/system/.core/colors","r")
  4. local cnt=f.readAll()
  5. f.close()
  6. local nastaveni=textutils.unserialize(cnt)    
  7. local f=fs.open("/C/system/.core/textcol","r")
  8. local tnt=f.readAll()
  9. f.close()
  10. local text=textutils.unserialize(tnt)
  11. local function prc(text, y)
  12.   local w = term.getSize()
  13.   local _, cy = term.getCursorPos()
  14.   term.setCursorPos(math.ceil((w-#text)/2), y or cy)
  15.   write(text)
  16. end
  17. local f=fs.open("/C/system/RAM/user","r")
  18. user=f.readLine()
  19. f.close()
  20.  
  21. local idTurtle = ""
  22. local connected = false
  23. local modem = peripheral.wrap('back')
  24. idPC = os.getComputerID()
  25. -- zamenit XXX
  26.    
  27. function minimalizace ()
  28.  
  29.     if not fs.exists ("/C/system/.core/setting/mineditor") then
  30.     shell.run ("pastebin get EiKMubhV /C/system/.core/setting/mineditor")
  31.     minimalizace()
  32.     end
  33.    
  34.     if fs.exists ("/C/system/RAM/"..user.."/RobotCon") then
  35.     fs.delete ("/C/system/RAM/"..user.."/RobotCon")
  36.     end
  37.    
  38.     local data = fs.open ("/C/system/RAM/"..user.."/RobotCon", "w")
  39.     data.writeLine(funkce)
  40.     data.close ()
  41.     local data = fs.open ("/C/system/RAM/"..user.."/prlists", "w")
  42.         data.writeLine ("RobotCon")
  43.         data.close ()
  44.     shell.run ("/C/system/.core/setting/mineditor")
  45. end
  46.  
  47. function ukonceni ()
  48.     fs.delete ("/C/system/RAM/RobotCon")
  49.     shell.run("/C/system/api/closeApp")
  50. end
  51.  
  52. function resus ()
  53.     if fs.exists ("/C/system/RAM/RobotCon") then
  54.     local data = fs.open ("/C/system/RAM/RobotCon", "r")
  55.             local funkce = data.readLine ()
  56.             data.close ()
  57.            
  58.         local myFuncs = {
  59.             ["setting"] = function()
  60.             setting ()
  61.             end,
  62.            
  63.  
  64.         }
  65.  
  66.         myFuncs[funkce]()
  67.         menu ()
  68.     end
  69. end
  70.  
  71.  
  72. function start ()
  73.     resus ()
  74.     modem.open(idPC)
  75.     term.setBackgroundColor(colors.white)
  76.     term.setTextColor(colors.black)
  77.     term.clear ()
  78.         if not fs.exists ("/C/Programs/PepekSoft/RobotCon.nft") then
  79.         shell.run("pastebin get a4pju742 /C/Programs/PepekSoft/RobotCon.nft")
  80.         end
  81.     local image = paintutils.loadImage("/C/Programs/PepekSoft/RobotCon.nft")
  82.     paintutils.drawImage(image, w/2-7, 4)
  83.     prc ("Robot Control", 16)
  84.     sleep (1)
  85.     menu ()
  86. end
  87.  
  88. function prijem()
  89. term.setBackgroundColor(colors.white)
  90. term.setTextColor(colors.black)
  91.  
  92. timerRX = os.startTimer(2)
  93.     while true do
  94.     local event,p1,p2,p3,p4 = os.pullEvent()
  95.       if event == ("modem_message") then
  96.           if (p3 == 1) then
  97.           term.setCursorPos(1,1)
  98.           term.write(p4)
  99.                 if (p4 == "ok") then
  100.                 connected = true
  101.                 else
  102.                 connected = false
  103.                 end
  104.                 return
  105.             end
  106.       elseif event == "timer" then
  107.         if p1 >= timerRX then
  108.         term.setCursorPos(5,12)
  109.         write"error - timer out"
  110.         connected = true
  111.         sleep(1)
  112.         return
  113.         end
  114.       end
  115.     end
  116. end
  117.  
  118.  
  119. function menu()
  120. term.setBackgroundColor(colors.white)
  121. term.clear ()
  122. if connected then
  123.     term.setTextColor(colors.green)
  124.     term.setCursorPos(13,4)
  125.     write"Connected  "
  126.     else
  127.     term.setTextColor(colors.red)
  128.     term.setCursorPos(13,4)
  129.     write"Disconected"
  130. end
  131. term.setTextColor(colors.black)
  132. term.setCursorPos(2,2)
  133. write"Turtle ID: "
  134. term.setCursorPos(2,4)
  135. write "Status: "
  136.  
  137. term.setBackgroundColor(colors.lightGray)
  138. term.setCursorPos(13,2)
  139. write "     "
  140. term.setCursorPos(13,2)
  141. write (idTurtle)
  142. term.setBackgroundColor(colors.gray)
  143. term.setTextColor(colors.white)
  144. term.setCursorPos(19,2)
  145. write " Connect "
  146. term.setCursorPos(2,18)
  147. write" Setting "
  148.  
  149. term.setBackgroundColor(colors.white)
  150. term.setTextColor(colors.blue)
  151. term.setCursorPos(w/2-5,h-1)
  152. write "  Pepek"
  153. term.setCursorPos(w/2+3,h-1)
  154. write "Soft  "
  155. term.setCursorPos(w/2+2,h-1)
  156. term.setTextColor(colors.lime)
  157. write "@"
  158.  
  159. term.setBackgroundColor(colors.black)
  160. term.setTextColor(colors.white)
  161. term.setCursorPos(10,8)
  162. write"<"
  163. term.setCursorPos(16,8)
  164. write">"
  165. term.setCursorPos(13,6)
  166. write"^"
  167. term.setCursorPos(13,10)
  168. write"V"
  169.  
  170.  
  171.      while true do
  172.     local event, button, x, y = os.pullEvent("mouse_click")
  173.     xy = x..","..y
  174.      
  175.             if x >= 2 and x <= 12 and y == 18 and button == 1 then
  176.             setting()
  177.             elseif x == 13 and y == 6 and button == 1 then
  178.             modem.transmit(tonumber(idTurtle),2,"forward")
  179.             elseif x == 13 and y == 10 and button == 1 then
  180.             modem.transmit(tonumber(idTurtle),2,"back")
  181.             elseif x == 16 and y == 8 and button == 1 then
  182.             modem.transmit(tonumber(idTurtle),2,"right")
  183.             elseif x == 10 and y == 8 and button == 1 then
  184.             modem.transmit(tonumber(idTurtle),2,"left")
  185.             elseif x >= 13 and x <= 17 and y == 2 and button == 1 then
  186.             term.setBackgroundColor(colors.gray)
  187.             term.setTextColor(colors.white)
  188.             term.setCursorPos(13,2)
  189.             write "     "
  190.             term.setCursorPos(13,2)
  191.             idTurtle = read()
  192.             menu()
  193.             elseif x >= 19 and x <= 27 and y == 2 and button == 1 then
  194.             modem.transmit(tonumber(idTurtle),1,idPC)
  195.             prijem()
  196.             menu()
  197.             elseif x >= 5 and x <= 14 and y == 13 and button == 1 then
  198.  
  199.  
  200.             elseif x >= 5 and x <= 14 and y == 15 and button == 1 then
  201.            
  202.            
  203.             elseif x >= 5 and x <= 14 and y == 17 and button == 1 then
  204.            
  205.            
  206.             else
  207.             paintutils.drawLine(1, 1, w, 1, colors.black)
  208.             paintutils.drawPixel (w,1, colors.red)
  209.             term.setCursorPos (w,1)
  210.                 term.setTextColor(text.barva)
  211.             print "*"
  212.                     while true do
  213.                         local event, button, x, y = os.pullEvent("mouse_click")
  214.                         xy = x..","..y
  215.                
  216.                         if x == w and y == 1 then
  217.                         ukonceni ()
  218.                         else
  219.                         menu()
  220.                         end
  221.                     end
  222.             break
  223.         end
  224.     end
  225. end
  226.  
  227. function editmenu()
  228.  term.setBackgroundColor(colors.white)
  229. term.setTextColor(colors.blue)
  230. term.setCursorPos(20,19)
  231. write"  Pepek"
  232. term.setCursorPos(28,19)
  233. write"Soft  "
  234. term.setCursorPos(27,19)
  235. term.setTextColor(colors.lime)
  236. write"@"
  237.      while true do
  238.     local event, button, x, y = os.pullEvent("mouse_click")
  239.     xy = x..","..y
  240.      
  241.     if x >= 5 and x <= 28 and y == 7 and button == 1 then
  242.     instalace = 1
  243.     else
  244.     paintutils.drawLine(1, 1, w, 1, colors.black)
  245.     paintutils.drawPixel (w,1, colors.red)
  246.     term.setTextColor(colors.white)
  247.     term.setCursorPos (w,1)
  248.     print "*"
  249.     paintutils.drawPixel (w-1,1, colors.lightGray)
  250.     term.setCursorPos (w-1,1)
  251.     print "<"
  252.     paintutils.drawPixel (49,1, colors.lightGray)
  253.     term.setCursorPos (49,1)
  254.     print "_"
  255.              while true do
  256.         local event, button, x, y = os.pullEvent("mouse_click")
  257.         xy = x..","..y
  258.        
  259.         if x == w and y == 1 then
  260.             ukonceni ()
  261.         elseif x == w-1 and y == 1 then
  262.             menud ()
  263.         elseif x == 49 and y == 1 then
  264.             minimalizace ()
  265.         else
  266.         editmenu()
  267.             end
  268.             end
  269.     break
  270.     end
  271.     end
  272. end
  273.  
  274. function setting()
  275.     funkce = "setting"
  276.     term.setBackgroundColor(colors.white)
  277.     term.setTextColor(colors.black)
  278.     term.clear ()
  279.    
  280.     term.setBackgroundColor(colors.lightGray)
  281.     term.setTextColor(colors.black)
  282.     term.setCursorPos(5,7)
  283.     write "Stranka 2"
  284.    
  285.     while true do
  286.        
  287.         local event, button, x, y = os.pullEvent("mouse_click")
  288.         xy = x..","..y
  289.    
  290.             if x >= 5 and x <= 45 and y == 10 and button == 1 then
  291.  
  292.  
  293.             elseif x >= 41 and x <= w and y == 18 and button == 1 then
  294.            
  295.            
  296.             else
  297.             paintutils.drawLine(1, 1, w, 1, colors.black)
  298.             paintutils.drawPixel (w,1, colors.red)
  299.             term.setTextColor(colors.white)
  300.             term.setCursorPos (w,1)
  301.             print "*"
  302.             paintutils.drawPixel (w-1,1, colors.lightGray)
  303.             term.setCursorPos (w-1,1)
  304.             print "<"
  305.             paintutils.drawPixel (49,1, colors.lightGray)
  306.             term.setCursorPos (49,1)
  307.             print "_"
  308.            
  309.                 while true do
  310.                     local event, button, x, y = os.pullEvent("mouse_click")
  311.                     xy = x..","..y
  312.                    
  313.                         if x == w and y == 1 then
  314.                                 ukonceni ()
  315.                             elseif x == w-1 and y == 1 then
  316.                                 menu ()    -- predchozi stranka
  317.                             elseif x == 49 and y == 1 then
  318.                                 minimalizace ()
  319.                             else
  320.                                 setting()
  321.                         end
  322.                 end
  323.             end
  324.     end
  325. end
  326.  
  327. start ()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement