Advertisement
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. --
- -----------------------------------
- -----------------------------------
- -- BASIC DEVICES API --
- -- This is the superclass of all --
- -- "Basic" devices. --
- -- It handles all the common --
- -- graphical stuff. --
- -----------------------------------
- class = {}
- class.__index = class
- setmetatable(class, {__index = CyberAPI.class})
- themesDir = CyberAPI.mainDir.."/themes"
- defaultThemeDir = themesDir.."/Default"
- 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
- 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
- btn1 = "["..btn1.."]"
- local function draw(msg, btn1, btn2)
- -- 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
- term.setCursorPos(2, 1+math.floor(actualY/4)-math.floor(msgLines/2)+i)
- term.write(v)
- 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
- term.setCursorPos(3, math.ceil(actualY*3/4)-math.floor(lines1/2)+i)
- term.write(v)
- 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
- term.setCursorPos(math.ceil(x/2)+3, math.ceil((y-1)*3/4)-math.floor(lines2/2)+i)
- term.write(v)
- end
- end
- -- The event catcher
- while true do
- term.clear()
- self:setBackground()
- draw(msg, btn1, btn2)
- local event, key= os.pullEvent("key")
- if key==keys.right and btn1:find("%[") then
- btn1 = btn1:sub(2, -2)
- btn2 = "["..btn2.."]"
- elseif key==keys.left and btn2:find("%[") then
- btn1 = "["..btn1.."]"
- btn2 = btn2:sub(2, -2)
- elseif key==keys.enter then
- if btn1:find("%[") then
- return btn1:sub(2, -2)
- else
- return btn2:sub(2, -2)
- end
- end
- end
- end
- function class:setBackground()
- for i=1, self.x do
- for k=1, self.y do
- s=""
- if (k==1 and i==1) or (k==self.y and i==self.x) then
- s="/"
- elseif (k==1 and i==self.x) or (k==self.y and i==1) then
- s="\\"
- elseif k==1 or k==self.y then
- s="-"
- elseif i==1 or i==self.x then
- s="|"
- end
- term.setCursorPos(i, k)
- term.write(s)
- end
- end
- end
- ------------------------
- -- Creates a menu for --
- -- non-advanced PCs --
- ------------------------
- function drawMain(icons)
- local x, y = term.getSize()
- setBackground()
- local selected=1
- while true do
- term.clear()
- drawFrame()
- term.setCursorPos(math.floor((x-string.len("Main Menu"))/2), 3)
- term.write("Main Menu")
- for i=1, table.getn(icons) or math.floor((y-5)/2) do
- local entry = icons[i]
- if i==selected then
- entry = "[ "..entry.." ]"
- end
- term.setCursorPos( math.floor(x/2-string.len(entry)/2),3+i*2)
- term.write(entry)
- end
- event, key = os.pullEvent("key")
- if key==keys.down then
- selected=(selected%table.getn(icons))+1
- elseif key==keys.up then
- selected=(selected+table.getn(icons)-2)%table.getn(icons)+1
- elseif key==keys.enter or key==keys.right then
- return icons[selected]
- elseif key==keys.left or key==keys.backspace then
- if string.sub("Main Menu",1, 3)~="Cyb" then
- break
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement