Advertisement
vittoema96

CyberOsLite

Jan 26th, 2022 (edited)
985
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.90 KB | None | 0 0
  1. -------------------------------------
  2. -- This program was designed for   --
  3. -- the Minecraft mod ComputerCraft --
  4. -------------------------------------
  5.  
  6. -----------------------------------
  7. --           WARNING             --
  8. -- This program is not meant to  --
  9. -- be downloaded.                --
  10. -- To install CyberOS on your    --
  11. -- ComputerCraft device just run --
  12. -- the following line on it:     --
  13. -- pastebin get qJSSf0qg startup --
  14. -- then restart the device.      --
  15. -----------------------------------
  16.  
  17. -----------------------------------
  18. --     BASIC DEVICES API         --
  19. -- This is the superclass of all --
  20. -- "Basic" devices.              --
  21. -- It handles all the common     --
  22. -- graphical stuff.              --
  23. -----------------------------------
  24.  
  25.  
  26. class = {}
  27. class.__index = class
  28. setmetatable(class, {__index = CyberAPI.class})
  29.  
  30. themesDir = CyberAPI.mainDir.."/themes"
  31. defaultThemeDir = themesDir.."/Default"
  32.  
  33.  
  34. function class:new(shell)
  35.     local self = CyberAPI.class:new(shell)
  36.     setmetatable(self, class)
  37.    
  38.     if fs.exists(themesDir)==false then
  39.         fs.makeDir(themesDir)
  40.     end
  41.     if fs.exists(defaultThemeDir)==false then
  42.         fs.makeDir(defaultThemeDir)
  43.     end
  44.    
  45.     return self
  46. end
  47.  
  48.  
  49.  
  50. function class:themeSelection()
  51.     self:setBackground()
  52.     return self:binaryPopup("Would you like to use the Default or the Glitch theme?", "Default", "Glitch")
  53. end
  54.  
  55. function class:startupAnimation()
  56.     self:drawImageTheme("logoAnimation/bg0")
  57.     for i=1, 15 do
  58.         sleep(0.12)
  59.         local rdm = math.random(4)-1
  60.        
  61.         local imN="logoAnimation/bg"..rdm
  62.         self:drawImageTheme(imN)
  63.     end
  64.     self:drawImageTheme("logoAnimation/bg0")
  65.  
  66.     sleep(1)
  67. end
  68.  
  69. function class:binaryPopup(msg, btn1, btn2) -- returns the string of the chosen button
  70.     local x, y = term.getSize()
  71.     local actualY = y-1
  72.     x = x - 2
  73.     btn1 = "["..btn1.."]"
  74.  
  75.     local function draw(msg, btn1, btn2)
  76.         -- The message that is displayed in the top half of the screen
  77.         local formattedMsg = CyberAPI.formatString(msg, x, math.floor(actualY/2)-2)
  78.         local msgLines = #formattedMsg
  79.         for i, v in ipairs(formattedMsg) do
  80.             term.setCursorPos(2, 1+math.floor(actualY/4)-math.floor(msgLines/2)+i)
  81.             term.write(v)
  82.         end
  83.    
  84.         -- The first choiche
  85.         local formatted1 = CyberAPI.formatString(btn1, math.floor((x-7)/2), 5)
  86.         local lines1 = #formatted1
  87.         for i, v in ipairs(formatted1) do
  88.             term.setCursorPos(3, math.ceil(actualY*3/4)-math.floor(lines1/2)+i)
  89.             term.write(v)
  90.         end
  91.         -- The second choice
  92.         local formatted2 = CyberAPI.formatString(btn2, math.floor((x-7)/2), 5)
  93.         local lines2 = #formatted2
  94.         for i, v in ipairs(formatted2) do
  95.             term.setCursorPos(math.ceil(x/2)+3, math.ceil((y-1)*3/4)-math.floor(lines2/2)+i)
  96.             term.write(v)
  97.         end
  98.     end
  99.    
  100.     -- The event catcher
  101.     while true do
  102.         term.clear()
  103.         self:setBackground()
  104.         draw(msg, btn1, btn2)
  105.         local event, key= os.pullEvent("key")
  106.         if key==keys.right and btn1:find("%[") then
  107.             btn1 = btn1:sub(2, -2)
  108.             btn2 = "["..btn2.."]"
  109.         elseif key==keys.left and btn2:find("%[") then
  110.             btn1 = "["..btn1.."]"
  111.             btn2 = btn2:sub(2, -2)
  112.         elseif key==keys.enter then
  113.             if btn1:find("%[") then
  114.                 return btn1:sub(2, -2)
  115.             else
  116.                 return btn2:sub(2, -2)
  117.             end
  118.         end
  119.     end
  120. end
  121.  
  122.  
  123. function class:setBackground()
  124.     for i=1, self.x do
  125.         for k=1, self.y do
  126.             s=""
  127.             if (k==1 and i==1) or (k==self.y and i==self.x) then
  128.                 s="/"
  129.             elseif (k==1 and i==self.x) or (k==self.y and i==1) then
  130.                 s="\\"
  131.             elseif k==1 or k==self.y then
  132.                 s="-"
  133.             elseif i==1 or i==self.x then
  134.                 s="|"
  135.             end
  136.             term.setCursorPos(i, k)
  137.             term.write(s)
  138.         end
  139.     end
  140. end
  141.  
  142.  
  143.  
  144. ------------------------
  145. -- Creates a menu for --
  146. -- non-advanced PCs   --
  147. ------------------------
  148.  
  149. function drawMain(icons)
  150.    
  151.     local x, y = term.getSize()
  152.     setBackground()
  153.     local selected=1
  154.     while true do
  155.         term.clear()
  156.         drawFrame()
  157.         term.setCursorPos(math.floor((x-string.len("Main Menu"))/2), 3)
  158.         term.write("Main Menu")
  159.         for i=1, table.getn(icons) or math.floor((y-5)/2) do
  160.             local entry = icons[i]
  161.             if i==selected then
  162.                 entry = "[ "..entry.." ]"
  163.             end
  164.             term.setCursorPos( math.floor(x/2-string.len(entry)/2),3+i*2)
  165.             term.write(entry)
  166.         end
  167.         event, key = os.pullEvent("key")
  168.         if key==keys.down then
  169.             selected=(selected%table.getn(icons))+1
  170.         elseif key==keys.up then
  171.             selected=(selected+table.getn(icons)-2)%table.getn(icons)+1
  172.         elseif key==keys.enter or key==keys.right then
  173.             return icons[selected]
  174.         elseif key==keys.left or key==keys.backspace then
  175.             if string.sub("Main Menu",1, 3)~="Cyb" then
  176.                 break
  177.             end
  178.         end
  179.     end
  180. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement