paramus

SmartPhone

Jan 22nd, 2025 (edited)
408
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.38 KB | Gaming | 0 0
  1. peripheral.find("modem", rednet.open)
  2. local Ventana, LSApps
  3. local LSBotones = {}
  4. local backColor,appColor,textColor
  5. local Page = 1
  6.  
  7. function SystemData()
  8.     --File system
  9.     if (fs.exists("Apps") == false) then
  10.         fs.makeDir("Apps")
  11.     end
  12.     if (fs.exists("SysData") == false) then
  13.         fs.makeDir("SysData")
  14.         if(fs.exists("SysData/os.json")) then
  15.             fs.delete("SysData/os.json")
  16.         end
  17.     end
  18.     local file = fs.open("SysData/os.json", "w")
  19.     file.writeLine("1.0") --os Version
  20.     file.close()
  21.    
  22.     --Auto install
  23.     if (fs.exists("startup.lua") == false) then
  24.         shell.execute("pastebin", "get", "Yir91aUq", "startup.lua")
  25.     end
  26.    
  27.     --Options
  28.     if (fs.exists("SysData/options.txt") == false) then
  29.         file = fs.open("SysData/options.txt", "w")
  30.         file.writeLine(colors.cyan) --Background color
  31.         file.writeLine(colors.yellow) --App color
  32.         file.writeLine(colors.white) --Text color
  33.         file.close()
  34.     end
  35.     file = fs.open("SysData/options.txt", "r")
  36.     backColor = tonumber(file.readLine()) --Background color
  37.     appColor = tonumber(file.readLine()) --App color
  38.     textColor = tonumber(file.readLine()) --Text color
  39.     file.close()
  40.    
  41.     --Obligatory apps
  42.     local LSApps ={
  43.         {"Apps", "U3vd1Qb5"},
  44.         {"Optns", "J9hVM3gx"},
  45.         {"Birb", "PEu7TMTy"},
  46.         {"Calc", "jWWUdLHg"}
  47.     }
  48.    
  49.     for a=1,#LSApps,1 do
  50.         if (fs.exists("Apps/" .. LSApps[a][1]) == false) then
  51.             fs.delete("Apps/" .. LSApps[a][1])
  52.             shell.execute("pastebin", "get", LSApps[a][2], "Apps/" .. LSApps[a][1] .. "/" .. LSApps[a][1] .. ".lua")
  53.             local fUID = fs.open("Apps/" .. LSApps[a][1] .. "/UID.txt", "w")
  54.             fUID.write(LSApps[a][2])
  55.             fUID.close()
  56.         end
  57.     end
  58. end
  59.  
  60. function Gui()
  61.     term.setBackgroundColor(backColor)
  62.     term.setTextColor(textColor)
  63.     term.clear()
  64.  
  65.     Ventana = window.create(term.current(), 1,1,26,20)
  66.     Ventana.setBackgroundColor(backColor)
  67.     Ventana.clear()
  68.  
  69.     --Info bar
  70.     local IBar = window.create(term.current(),1,1,26,1)
  71.     IBar.setBackgroundColor(colors.green)
  72.     IBar.clear()
  73.     IBar.setCursorPos(1,1)
  74.     IBar.setTextColor(textColor)
  75.     IBar.write(textutils.formatTime(os.time(), false))
  76.     IBar.setCursorPos(17,1)
  77.     IBar.write("BlockDroid")
  78.    
  79.     --Crear botones
  80.     LSBotones = {}
  81.     LSApps = fs.list("Apps")
  82.     local nApps = table.getn(LSApps)
  83.     local height = 4
  84.     for i=(6*(Page-1))+1,nApps,1
  85.     do
  86.         if (i > (6*Page)) then
  87.             height = 4
  88.             break
  89.         end
  90.        
  91.         local path = "Apps/" .. LSApps[i] .. "/" .. LSApps[i] .. ".lua"
  92.         if (i==(6*(Page-1))+1) then
  93.             CreateButton(5, height, 11, height+2, appColor, LSApps[i], path)
  94.         elseif (i%2==0) then
  95.             CreateButton(5 + 11, height, 11 + 11, height+2, appColor, LSApps[i], path)
  96.         else
  97.             height = height+5
  98.             CreateButton(5, height, 11, height+2, appColor, LSApps[i], path)
  99.         end
  100.     end
  101.    
  102.     --Page Navigation
  103.     if (Page>1) then
  104.         paintutils.drawFilledBox(1,19,7,20, appColor)
  105.         term.setBackgroundColor(colors.yellow)
  106.         term.setCursorPos(3,20)
  107.         term.write("<---")
  108.     end
  109.     if (nApps > Page * 6) then
  110.         paintutils.drawFilledBox(20,19,26,20, appColor)
  111.         term.setBackgroundColor(colors.yellow)
  112.         term.setCursorPos(21,20)
  113.         term.write("--->")
  114.     end
  115.  
  116.     --Page number
  117.     term.setBackgroundColor(backColor)
  118.     IBar.setTextColor(textColor)
  119.     term.setCursorPos(13,20)
  120.     term.write(Page)
  121. end
  122.  
  123. function Events()
  124.     while(true) do
  125.         parallel.waitForAny(
  126.             function()
  127.                 local e, button, x, y = os.pullEvent("mouse_click");
  128.                 Gui()
  129.                 if button == 1 then
  130.                     OpenApp(x, y)
  131.                     ChangePage(x, y)
  132.                 end
  133.             end,
  134.             function()
  135.                 sleep(.5)
  136.                 Gui()
  137.             end
  138.         )
  139.     end
  140. end
  141.  
  142. function OpenApp(x, y)
  143.     for o = 1,#LSBotones,1 do
  144.         if (o > 6) then break end
  145.        
  146.         if x >= LSBotones[o][1] and y >= LSBotones[o][2] and x <= LSBotones[o][3] and y <= LSBotones[o][4]
  147.         then
  148.             multishell.setTitle(1, "Home")
  149.             local pro = shell.openTab(LSBotones[o][6])
  150.             multishell.setFocus(pro)
  151.             multishell.setTitle(pro, LSBotones[o][5])
  152.         end
  153.     end
  154. end
  155.  
  156. function ChangePage(x, y)
  157.     if (x >= 1 and y >= 19 and x <= 7 and Page > 1) then -- Previous Page
  158.         Page = Page-1
  159.         Gui()
  160.     elseif (x>= 20 and y >= 19 and x <= 26) then -- Next Page
  161.         if (#LSApps > Page*6) then
  162.             Page = Page+1
  163.             Gui()
  164.         end
  165.     end
  166. end
  167.  
  168. function CreateButton(x1, y1, x2, y2, color, name, program)
  169.     local Button = window.create(term.current(), x1, y1, x2-x1+1, y2-y1+1)
  170.     Button.setBackgroundColor(color)
  171.     Button.clear()
  172.     paintutils.drawPixel(x1,y1)
  173.     paintutils.drawPixel(x2,y1)
  174.     paintutils.drawPixel(x1,y2)
  175.     paintutils.drawPixel(x2,y2)
  176.    
  177.     -- Name
  178.     term.setCursorPos(x1+3-math.floor(string.len(name)/2), y2+1)
  179.     term.setTextColor(textColor)
  180.     term.write(name)
  181.    
  182.     local i = table.getn(LSBotones) + 1
  183.     LSBotones[i] = {x1, y1, x2, y2, name, program}
  184. end
  185.  
  186. -- MAIN --
  187. SystemData()
  188. Gui()
  189. Events()
Advertisement
Add Comment
Please, Sign In to add comment