Advertisement
paramus

SmartPhone

Jan 22nd, 2025 (edited)
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.47 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.         {"Market", "U3vd1Qb5"},
  44.         {"Options", "J9hVM3gx"}
  45.     }
  46.    
  47.     for a=1,#LSApps,1 do
  48.         if (fs.exists("Apps/" .. LSApps[a][1]) == false) then
  49.             fs.delete("Apps/" .. LSApps[a][1])
  50.             shell.execute("pastebin", "get", LSApps[a][2], "Apps/" .. LSApps[a][1] .. "/" .. LSApps[a][1] .. ".lua")
  51.             local fUID = fs.open("Apps/" .. LSApps[a][1] .. "/UID.txt", "w")
  52.             fUID.write(LSApps[a][2])
  53.             fUID.close()
  54.         end
  55.     end
  56. end
  57.  
  58. function Gui()
  59.     term.setBackgroundColor(backColor)
  60.     term.setTextColor(textColor)
  61.     term.clear()
  62.  
  63.     Ventana = window.create(term.current(), 1,1,26,20)
  64.     Ventana.setBackgroundColor(backColor)
  65.     Ventana.clear()
  66.  
  67.     --Info bar
  68.     local IBar = window.create(term.current(),1,1,26,1)
  69.     IBar.setBackgroundColor(colors.green)
  70.     IBar.clear()
  71.     IBar.setCursorPos(1,1)
  72.     IBar.setTextColor(textColor)
  73.     IBar.write(textutils.formatTime(os.time(), false))
  74.     IBar.setCursorPos(17,1)
  75.     IBar.write("BlockDroid")
  76.    
  77.     --Crear botones
  78.     LSBotones = {}
  79.     LSApps = fs.list("Apps")
  80.     local nApps = table.getn(LSApps)
  81.     local height = 4
  82.     for i=(6*(Page-1))+1,nApps,1
  83.     do
  84.         if (i > (6*Page)) then
  85.             height = 4
  86.             break
  87.         end
  88.        
  89.         local path = "Apps/" .. LSApps[i] .. "/" .. LSApps[i] .. ".lua"
  90.         if (i==(6*(Page-1))+1) then
  91.             CreateButton(5, height, 11, height+2, appColor, LSApps[i], path)
  92.         elseif (i%2==0) then
  93.             CreateButton(5 + 11, height, 11 + 11, height+2, appColor, LSApps[i], path)
  94.         else
  95.             height = height+5
  96.             CreateButton(5, height, 11, height+2, appColor, LSApps[i], path)
  97.         end
  98.     end
  99.    
  100.     --Page Navigation
  101.     if (Page>1) then
  102.         paintutils.drawFilledBox(1,19,7,20, appColor)
  103.         term.setBackgroundColor(colors.yellow)
  104.         term.setCursorPos(3,20)
  105.         term.write("<---")
  106.     end
  107.     if (nApps > Page * 6) then
  108.         paintutils.drawFilledBox(20,19,26,20, appColor)
  109.         term.setBackgroundColor(colors.yellow)
  110.         term.setCursorPos(21,20)
  111.         term.write("--->")
  112.     end
  113.  
  114.     --Page number
  115.     term.setBackgroundColor(backColor)
  116.     IBar.setTextColor(textColor)
  117.     term.setCursorPos(13,20)
  118.     term.write(Page)
  119. end
  120.  
  121. function Events()
  122.     while(true) do
  123.         parallel.waitForAny(
  124.             function()
  125.                 local e, button, x, y = os.pullEvent("mouse_click");
  126.                 Gui()
  127.                 if button == 1 then
  128.                     OpenApp(x, y)
  129.                     ChangePage(x, y)
  130.                 end
  131.             end,
  132.             function()
  133.                 sleep(.5)
  134.                 Gui()
  135.             end,
  136.             function()
  137.                 local ID,MSg = rednet.receive(1)
  138.                 if (Msg=="trkr") then
  139.                     rednet.send(ID, "Test")
  140.                 end
  141.             end
  142.         )
  143.     end
  144. end
  145.  
  146. function OpenApp(x, y)
  147.     for o = 1,#LSBotones,1 do
  148.         if (o > 6) then break end
  149.        
  150.         if x >= LSBotones[o][1] and y >= LSBotones[o][2] and x <= LSBotones[o][3] and y <= LSBotones[o][4]
  151.         then
  152.             multishell.setTitle(1, "Home")
  153.             local pro = shell.openTab(LSBotones[o][6])
  154.             multishell.setFocus(pro)
  155.             multishell.setTitle(pro, LSBotones[o][5])
  156.         end
  157.     end
  158. end
  159.  
  160. function ChangePage(x, y)
  161.     if (x >= 1 and y >= 19 and x <= 7 and Page > 1) then -- Previous Page
  162.         Page = Page-1
  163.         Gui()
  164.     elseif (x>= 20 and y >= 19 and x <= 26) then -- Next Page
  165.         if (#LSApps > Page*6) then
  166.             Page = Page+1
  167.             Gui()
  168.         end
  169.     end
  170. end
  171.  
  172. function CreateButton(x1, y1, x2, y2, color, name, program)
  173.     local Button = window.create(term.current(), x1, y1, x2-x1+1, y2-y1+1)
  174.     Button.setBackgroundColor(color)
  175.     Button.clear()
  176.     paintutils.drawPixel(x1,y1)
  177.     paintutils.drawPixel(x2,y1)
  178.     paintutils.drawPixel(x1,y2)
  179.     paintutils.drawPixel(x2,y2)
  180.     term.setCursorPos(x1, y2+1)
  181.     term.setTextColor(textColor)
  182.     term.write(name)
  183.    
  184.     local i = table.getn(LSBotones) + 1
  185.     LSBotones[i] = {x1, y1, x2, y2, name, program}
  186. end
  187.  
  188. -- MAIN --
  189. SystemData()
  190. Gui()
  191. Events()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement