Advertisement
paramus

SmartPhone

Jan 22nd, 2025 (edited)
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.30 KB | Gaming | 0 0
  1. local Ventana
  2. local LSBotones = {}
  3. local backColor = colors.white
  4. local LSApps
  5.  
  6. function SystemData()
  7.     --File system
  8.     if (fs.exists("Apps") == false) then
  9.         fs.makeDir("Apps")
  10.     end
  11.     if (fs.exists("SysData") == false) then
  12.         fs.makeDir("SysData")
  13.         if(fs.exists("SysData/os.json")) then
  14.             fs.delete("SysData/os.json")
  15.         end
  16.     end
  17.     local file = fs.open("SysData/os.json", "w")
  18.     file.writeLine("1.0") --os Version
  19.     file.close()
  20.    
  21.     --Obligatory apps
  22.     if (fs.exists("Apps/Market") == false) then
  23.         fs.delete("Apps/Market")
  24.         shell.execute("pastebin", "get", "U3vd1Qb5", "Apps/Market/Market.lua")
  25.     end
  26.     if (fs.exists("Apps/Tardis") == false) then
  27.         fs.delete("Apps/Tardis")
  28.         shell.execute("pastebin", "get", "yeXzddW4", "Apps/Tardis/Tardis.lua")
  29.     end
  30.    
  31.     --Check for updates (rednet from server)
  32.     local CurrentVersion = fs.open("SysData/os.json", "r").readLine() --os Version
  33.    
  34.     rednet.open("back")
  35.     local ID,NewVersion = rednet.receive("Version", 1)
  36.     rednet.close("back")
  37.     if (NewVersion ~= nil) then
  38.         if(NewVersion ~= CurrentVersion) then
  39.             shell.execute("AutoUpdate.lua")
  40.         end
  41.     end
  42. end
  43.  
  44. function Gui()
  45.     term.clear()
  46.  
  47.     Ventana = window.create(term.current(), 1,1,26,20)
  48.     Ventana.setBackgroundColor(backColor)
  49.     Ventana.clear()
  50.  
  51.     --Info bar
  52.     local IBar = window.create(term.current(),1,1,26,2)
  53.     IBar.setBackgroundColor(colors.green)
  54.     IBar.clear()
  55.     IBar.write(textutils.formatTime(os.time(), false) .. "        BlockDroid")
  56.  
  57.     --Crear botones
  58.     LSBotones = {}
  59.     LSApps = fs.list("Apps")
  60.     local nApps = table.getn(LSApps)
  61.     local height = 5
  62.     for i=1,nApps,1
  63.     do
  64.         local path = "Apps/" .. LSApps[i] .. "/" .. LSApps[i] .. ".lua"
  65.         if (i==1) then
  66.             CrearBoton(5, height, 11, height+2, colors.yellow, LSApps[i], path)
  67.         elseif (i%2==0) then
  68.             CrearBoton(5 + 11, height, 11 + 11, height+2, colors.yellow, LSApps[i], path)
  69.         else
  70.             height = height+5
  71.             CrearBoton(5, height, 11, height+2, colors.yellow, LSApps[i], path)
  72.         end
  73.     end
  74. end
  75.  
  76. function Events()
  77.     while(true) do
  78.         parallel.waitForAny(
  79.             function()
  80.                 local e, button, x, y = os.pullEvent("mouse_click");
  81.                 Gui()
  82.                 if button == 1 then
  83.                     AbrirApp(x, y)
  84.                 end
  85.             end,
  86.             function()
  87.                 sleep(2)
  88.                 Gui()
  89.             end
  90.         )
  91.     end
  92. end
  93.  
  94. function AbrirApp(x, y)
  95.     for o = 1,#LSBotones,1 do
  96.         if x >= LSBotones[o][1] and y >= LSBotones[o][2] and x <= LSBotones[o][3] and y <= LSBotones[o][4]
  97.         then
  98.             local pro = multishell.launch({}, LSBotones[o][6])
  99.             multishell.setFocus(pro)
  100.             multishell.setTitle(pro, LSBotones[o][5])
  101.         end
  102.     end
  103. end
  104.  
  105. function CrearBoton(x1, y1, x2, y2, color, name, program)
  106.     local Button = window.create(term.current(), x1, y1, x2-x1+1, y2-y1+1)
  107.     Button.setBackgroundColor(color)
  108.     Button.clear()
  109.     Button.write(name)
  110.    
  111.     local i = table.getn(LSBotones) + 1
  112.     LSBotones[i] = {x1, y1, x2, y2, name, program}
  113. end
  114.  
  115. -- MAIN --
  116. SystemData()
  117. Gui()
  118. Events()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement