Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -------------------------------------
- -- This program was designed for --
- -- the Minecraft mod ComputerCraft --
- -------------------------------------
- -----------------------------------
- -- WARNING --
- -- This program is not meant to --
- -- be downloaded. --
- -- To install CyberOS on your --
- -- ComputerCraft device just run --
- -- the following line on it: --
- -- pastebin get qJSSf0qg startup --
- -- then restart the device. --
- -----------------------------------
- -----------------------------------
- -- ADVANCED DEVICES API --
- -- This is the superclass of all --
- -- "Advanced" devices. --
- -- It handles all the common --
- -- graphical stuff. --
- -----------------------------------
- class = {}
- class.__index = class
- setmetatable(class, {__index = CyberAPI.class})
- themesDir = CyberAPI.mainDir.."/themes"
- defaultThemeDir = themesDir.."/Default"
- defaultIconsDir = defaultThemeDir.."/Icons"
- function class:new(shell)
- local self = CyberAPI.class:new(shell)
- setmetatable(self, class)
- if fs.exists(themesDir)==false then
- fs.makeDir(themesDir)
- end
- if fs.exists(defaultThemeDir)==false then
- fs.makeDir(defaultThemeDir)
- end
- if fs.exists(defaultIconsDir)==false then
- fs.makeDir(defaultIconsDir)
- end
- getOrDownloadIcons()
- return self
- end
- function class:themeSelection()
- self:setBackground()
- return self:binaryPopup("Would you like to use the Default or the Glitch theme?", "Default", "Glitch")
- end
- function class:startupAnimation()
- self:drawImageTheme("logoAnimation/bg0")
- for i=1, 15 do
- sleep(0.12)
- local rdm = math.random(4)-1
- local imN="logoAnimation/bg"..rdm
- self:drawImageTheme(imN)
- end
- self:drawImageTheme("logoAnimation/bg0")
- sleep(1)
- end
- function class:binaryPopup(msg, btn1, btn2) -- returns the string of the chosen button
- local x, y = term.getSize()
- local actualY = y-1
- x = x - 2
- -- The message that is displayed in the top half of the screen
- local formattedMsg = CyberAPI.formatString(msg, x, math.floor(actualY/2)-2)
- local msgLines = #formattedMsg
- for i, v in ipairs(formattedMsg) do
- CyberAPI.blit(v, "0", "7", 2, 1+math.floor(actualY/4)-math.floor(msgLines/2)+i)
- end
- -- The first choiche
- local formatted1 = CyberAPI.formatString(btn1, math.floor((x-7)/2), 5)
- local lines1 = #formatted1
- for i, v in ipairs(formatted1) do
- CyberAPI.blit(v, "0", "7", 3, math.ceil(actualY*3/4)-math.floor(lines1/2)+i)
- end
- -- The second choice
- local formatted2 = CyberAPI.formatString(btn2, math.floor((x-7)/2), 5)
- local lines2 = #formatted2
- for i, v in ipairs(formatted2) do
- CyberAPI.blit(v, "0", "7", math.ceil(x/2)+3, math.ceil((y-1)*3/4)-math.floor(lines2/2)+i)
- end
- -- The event catcher
- while true do
- local event, button, xPos, yPos = os.pullEvent("mouse_click")
- if button==1 then
- if yPos>=math.ceil(actualY*3/4)-math.floor(lines1/2)+1 and yPos<=math.ceil(actualY*3/4)+math.floor(lines1/2)+1 then
- if xPos>=2 and xPos<=math.floor(x/2) then
- self:setBackground()
- return btn1
- elseif xPos>=math.ceil(x/2) and xPos<=x then
- self:setBackground()
- return btn2
- end
- end
- end
- end
- end
- function class:setBackground()
- term.clear()
- local color = self:loadElementValue("bgcolor", ".settings")
- term.setBackgroundColor(tonumber(color))
- term.setTextColor(1)
- x = self:getWidth()
- local sFill=""
- for i=1, self:getWidth()-(string.len(CyberAPI.version)+9) do
- sFill=sFill.." "
- end
- CyberAPI.blit("CyberOs v"..CyberAPI.version..sFill, "0", "5",1,1)
- end
- function getOrDownloadIcons()
- local f
- if fs.exists(defaultIconsDir.."/Add")==false then
- f = fs.open(defaultIconsDir.."/Add", "w")
- f.writeLine(" 3b")
- f.writeLine(" 333b")
- f.writeLine(" 3b")
- f.close()
- end
- if fs.exists(defaultIconsDir.."/Disk")==false then
- f = fs.open(defaultIconsDir.."/Disk", "w")
- f.writeLine("8888888")
- f.writeLine("8888888")
- f.writeLine("8ffff88")
- f.writeLine("888888d")
- f.close()
- end
- if fs.exists(defaultIconsDir.."/Game", "w") then
- f = fs.open(defaultIconsDir.."/Game", "w")
- f.writeLine("777f777")
- f.writeLine("eb77788")
- f.writeLine("5477788")
- f.writeLine("77fff77")
- f.close()
- end
- if fs.exists(defaultIconsDir.."/Lua", "w") then
- f = fs.open(defaultIconsDir.."/Lua", "w")
- f.writeLine("5555555")
- f.writeLine("5055555")
- f.writeLine("5005 5")
- f.writeLine("5555555")
- f.close()
- end
- if fs.exists(defaultIconsDir.."/Mail", "w") then
- f = fs.open(defaultIconsDir.."/Mail", "w")
- f.writeLine("e00000e")
- f.writeLine("0ee0ee0")
- f.writeLine("000e000")
- f.writeLine("0000000")
- f.close()
- end
- if fs.exists(defaultIconsDir.."/Off", "w") then
- f = fs.open(defaultIconsDir.."/Off", "w")
- f.writeLine("7755577")
- f.writeLine("7577757")
- f.writeLine("7575757")
- f.writeLine("7755577")
- f.close()
- end
- if fs.exists(defaultIconsDir.."/Paint", "w") then
- f = fs.open(defaultIconsDir.."/Paint", "w")
- f.writeLine("7777777")
- f.writeLine("747e7b7")
- f.writeLine("7a75717")
- f.writeLine("7777777")
- f.close()
- end
- if fs.exists(defaultIconsDir.."/Turtle", "w") then
- f = fs.open(defaultIconsDir.."/Turtle", "w")
- f.writeLine("8888888")
- f.writeLine("88833c8")
- f.writeLine("7777c37")
- f.writeLine("777c737")
- f.close()
- end
- if fs.exists(defaultIconsDir.."/Back", "w") then
- f = fs.open(defaultIconsDir.."/Back", "w")
- f.writeLine(" ec")
- f.writeLine("eeeeec")
- f.writeLine(" ec")
- f.close()
- end
- end
- function class:loadImagePaint(fileUrl)
- return paintutils.loadImage("paintFiles/"..fileUrl)
- end
- function class:drawImagePaint(fileUrl)
- paintutils.drawImage(loadImagePaint(fileUrl))
- end
- function class:loadImageTheme(fileUrl)
- local theme = self:loadElementValue("theme", ".settings")
- img = paintutils.loadImage(themesDir.."/"..theme.."/"..fileUrl)
- if img~=nil then
- return img
- else
- return paintutils.loadImage(defaultThemeDir.."/"..fileUrl)
- end
- end
- function class:drawImageTheme(fileUrl)
- paintutils.drawImage(self:loadImageTheme(fileUrl),1,1)
- end
RAW Paste Data
Copied