Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- If you're wanting to make an application for
- CCGlass, please read the guide on the forums.
- Every time a developer doesn't read the guide,
- an innocent computer crashes
- Update information:
- ===
- v0.3.0
- Version Nickname: Crystal-Clear
- *Added Okay Glass feature, which works a lot
- ^like the real Glass.
- *Removed Garbage Collectors and defined
- ^variables as local when needed instead, as
- ^suggested by TheOriginalBit
- *Added mPrint(text,line,color) which is like
- ^tinyPrint but fits 10 lines
- *Added tinyCPrint(text,line,color) which is
- ^just like the normal tinyPrint but is
- ^centered. Also done with
- ^mCPrint(text,line,color)!
- *Improved how tinyPrint works
- *Fixed the PixelAPI to display pixels at the
- ^right coords.
- *Added drawLineX(startx, endx,y,color,trans)
- ^and drawLineY(starty,endy,x,color,trans)
- ^which basicly draw lines
- *Added sleepmode, which can be turned on by
- ^doing $$sleep on the home screen.
- *Added reboot, which can be done by doing
- ^$$reboot at the home screen
- *Added options, which includes an updater :D
- *Added Books. Books go in CCGBooks/ and need
- ^no sepcial format whatsoever. Just text.
- *Removed bookPrint(an empty function)
- *Added to the versioning system more
- *Removed Herobrine
- ===
- v0.2.1: Fixes the glitch where the terminal
- would always need to be on the left side, no
- matter what
- Adds pixelClear(), which clears the pixels on
- the pixelAPI.
- Redid the versioning system to a more popular
- way of versioning applications.
- ===
- v0.2.0: Adds the Pixel API, aswell as the
- "Garbage Collectors" that set variables
- that are no longer needed at the ends of funct-
- ions to nil.
- ===
- v0.1.0
- Initial Release
- CREDITS:
- (MC IGN: Hithere__)Icanbreathecode - Making
- glass
- TheOriginalBIT for kindly making the RGB Color
- converter, and being awesome
- GravityScore for making LuaIDE, which has saved
- me a lot of time.
- The community, for helping me with figuring out
- a lot of stuff about Terminal Glasses.
- Dan200, for making computercraft
- Mikeemoo for making OpenPeripherals
- ===
- DEVMODE CONFIGURATION
- If you're just looking at the code, don't touch this
- Application makers, this is pointless for you too
- ]]
- devmode = true
- newuserdev = false
- --first we set ye color values
- glcolors = {}
- glcolors.red = 0xff3333
- glcolors.blue = 0x7dd2e4
- glcolors.yellow = 0xffff4d
- glcolors.green = 0x4dff4d
- glcolors.gray = 0xe0e0e0
- glcolors.textGray = 0x676767
- glcolors.text = 0x5a5a5
- glcolors.otherBlue = 0x2e679f
- --colors not stolen from Plastic
- --:p
- glcolors.black = 0x000000
- glcolors.purple = 0xff00ff
- glcolors.blueGreen = 0x00ffff
- glcolors.orange = 0xff6600
- glcolors.darkBlue = 0x000066
- glcolors.brown = 0x663300
- glcolors.otherGreen = 0x00ff00
- glcolors.lightOrange = 0xffcc00
- --second, we ensure the user isn't wasting an advanced cpu
- if term.isColor() == true and devmode == false then
- print("Error: You are on an advanced computer. This program will not allow other programs to be ran. Do you wish to continue anyway?(y/n, caps count)")
- local answer = read()
- if answer == "n" then
- error("User opted out")
- end
- end
- function getSide()
- tran = fs.open("glasstrans", "w")
- tran.writeLine("0.75")
- tran.close()
- print("Which side is the Terminal Glasses Bridge on?(top bottom left right back, caps count) ")
- side = read()
- sw = fs.open("glassside", "w")
- sw.writeLine(side)
- sw.close()
- print("What is your desired username?")
- username = read()
- sw = fs.open("username", "w")
- sw.writeLine(username)
- sw.close()
- print("Now, if you havn't already, take the terminal glasses you're going to use and right-click the terminal bridge.")
- end
- function loadPixelAPI()
- print("Loading PixelAPI.")
- pixelsOne = {}
- pixelsTwo = {}
- pixelsThree = {}
- pixelsFour = {}
- pixelsFive = {}
- pixelsSix = {}
- pixelsSeven = {}
- pixelsEight = {}
- pixelsNine = {}
- pixelsTen = {}
- local i
- for i = 1,30 do
- vI = i-1
- vI = vI * 5
- vI = vI + 10
- pixelsOne[i] = glass.addBox(vI, 5, 5, 5, glcolors.red, 0)
- pixelsOne[i].setZIndex(4)
- end
- for i = 1,30 do
- vI = i-1
- vI = vI * 5
- vI = vI + 10
- pixelsTwo[i] = glass.addBox(vI, 10, 5, 5, glcolors.red, 0)
- pixelsTwo[i].setZIndex(4)
- end
- for i = 1,30 do
- vI = i-1
- vI = vI * 5
- vI = vI + 10
- pixelsThree[i] = glass.addBox(vI, 15, 5, 5, glcolors.red, 0)
- pixelsThree[i].setZIndex(4)
- end
- for i = 1,30 do
- vI = i-1
- vI = vI * 5
- vI = vI + 10
- pixelsFour[i] = glass.addBox(vI, 20, 5, 5, glcolors.red, 0)
- pixelsFour[i].setZIndex(4)
- end
- for i = 1,30 do
- vI = i-1
- vI = vI * 5
- vI = vI + 10
- pixelsFive[i] = glass.addBox(vI, 25, 5, 5, glcolors.red, 0)
- pixelsFive[i].setZIndex(4)
- end
- for i = 1,30 do
- vI = i-1
- vI = vI * 5
- vI = vI + 10
- pixelsSix[i] = glass.addBox(vI, 30, 5, 5, glcolors.red, 0)
- pixelsSix[i].setZIndex(4)
- end
- for i = 1,30 do
- vI = i-1
- vI = vI * 5
- vI = vI + 10
- pixelsSeven[i] = glass.addBox(vI, 35, 5, 5, glcolors.red, 0)
- pixelsSeven[i].setZIndex(4)
- end
- for i = 1,30 do
- vI = i-1
- vI = vI * 5
- vI = vI + 10
- pixelsEight[i] = glass.addBox(vI, 40, 5, 5, glcolors.red, 0)
- pixelsEight[i].setZIndex(4)
- end
- for i = 1,30 do
- vI = i-1
- vI = vI * 5
- vI = vI + 10
- pixelsNine[i] = glass.addBox(vI, 45, 5, 5, glcolors.red, 0)
- pixelsNine[i].setZIndex(4)
- end
- for i = 1,30 do
- vI = i-1
- vI = vI * 5
- vI = vI + 10
- pixelsTen[i] = glass.addBox(vI, 50, 5, 5, glcolors.red, 0)
- pixelsTen[i].setZIndex(4)
- end
- end
- function drawPixel(x, y, color, trans)
- --example usage: 2, 4, colors.red, 1
- --this would make a red pixel appear at 2, 4.
- if y ==1 then
- pixelsOne[x].setColor(color)
- pixelsOne[x].setOpacity(trans)
- elseif y ==2 then
- pixelsTwo[x].setColor(color)
- pixelsTwo[x].setOpacity(trans)
- elseif y ==3 then
- pixelsThree[x].setColor(color)
- pixelsThree[x].setOpacity(trans)
- elseif y ==4 then
- pixelsFour[x].setColor(color)
- pixelsFour[x].setOpacity(trans)
- elseif y ==5 then
- pixelsFive[x].setColor(color)
- pixelsFive[x].setOpacity(trans)
- elseif y ==6 then
- pixelsSix[x].setColor(color)
- pixelsSix[x].setOpacity(trans)
- elseif y ==7 then
- pixelsSeven[x].setColor(color)
- pixelsSeven[x].setOpacity(trans)
- elseif y ==8 then
- pixelsEight[x].setColor(color)
- pixelsEight[x].setOpacity(trans)
- elseif y ==9 then
- pixelsNine[x].setColor(color)
- pixelsNine[x].setOpacity(trans)
- elseif y ==10 then
- pixelsTen[x].setColor(color)
- pixelsTen[x].setOpacity(trans)
- end
- end
- function pixelClear()
- for i = 1,30 do
- drawPixel(i,1,glcolors.red,0)
- end
- for i = 1,30 do
- drawPixel(i,2,glcolors.red,0)
- end
- for i = 1,30 do
- drawPixel(i,3,glcolors.red,0)
- end
- for i = 1,30 do
- drawPixel(i,4,glcolors.red,0)
- end
- for i = 1,30 do
- drawPixel(i,5,glcolors.red,0)
- end
- for i = 1,30 do
- drawPixel(i,6,glcolors.red,0)
- end
- for i = 1,30 do
- drawPixel(i,7,glcolors.red,0)
- end
- for i = 1,30 do
- drawPixel(i,8,glcolors.red,0)
- end
- for i = 1,30 do
- drawPixel(i,9,glcolors.red,0)
- end
- for i = 1,30 do
- drawPixel(i,10,glcolors.red,0)
- end
- end
- function drawLineX(startx,endx,y,colors,transpa)
- local i
- for i=startx,endx do
- drawPixel(i,y,colors,transpa)
- -- print("drew pixel at x "..i.." y "..y.." trans "..transpa.." ")
- end
- end
- function drawLineY(x,starty,endy,colory,transpar)
- local i
- for i=starty,endy do
- drawPixel(x,i,colory,transpar)
- end
- end
- function load()
- dir = "CCGlass/"
- glassVersion = "0.3"
- glassVer = 30
- --note that this still runs on first time
- on = true
- gs = fs.open("glassside", "r")
- side = gs.readLine()
- gs.close()
- glass = peripheral.wrap(side)
- gs = fs.open("username", "r")
- username = gs.readLine()
- gs.close()
- tran = fs.open("glasstrans", "r")
- transp = tran.readLine()
- tran.close()
- transp = tonumber(transp)
- shell.run('glassTheme')
- end
- --Ye first thing where we draw stuff
- --(besides the PixelAPI)
- function firstDraw()
- tinyText = {}
- local tinyY
- local i
- for i = 0,4 do
- tinyY = i *10
- tinyY = tinyY + 5
- i = i+1
- tinyText[i]= glass.addText(10, tinyY, " ", glcolors.red)
- tinyText[i].setZIndex(5)
- end
- miniPrint = {}
- for i = 0,9 do
- local yset = i * 5
- yset = yset + 5
- i = i+1
- miniPrint[i] = glass.addText(10,yset," ",glcolors.red)
- miniPrint[i].setZIndex(5)
- miniPrint[i].setScale(0.5)
- end
- midText= glass.addText(29, 27.9, " ", glcolors.green)
- highText= glass.addText(29, 27.9, " ", glcolors.red)
- lowText= glass.addText(29, 27.9, " ", glcolors.otherBlue)
- leftBox = glass.addBox(5, 0, 5, 60, sideColors, transp)
- bigBox = glass.addBox(10, 5, 150, 50, bigBoxColor, transp)
- --note that the width really is 150
- --add 10 to x cords, 5 to y cords
- for i = 1, 20 do
- bigBox.setWidth(i * 7.5)
- sleep(0.01)
- end
- leftBox = glass.addBox(160, 0, 5, 60, sideColors, transp)
- loadPixelAPI()
- end
- --The way glass prints stuffs to the screen
- function midPrint(text)
- local w
- local tw
- local posx
- local posy
- midText.setText(text)
- midText.setScale(2)
- midText.setZIndex(5)
- w = bigBox.getWidth()
- tw = midText.getWidth()
- tw = tw*2
- posx = math.floor(w-tw)/2, 2
- posx = posx +10
- midText.setX(posx)
- posy = 20
- midText.setY(posy)
- end
- function highPrint(text)
- local w
- local hposx
- local posy
- highText.setZIndex(5)
- local w = bigBox.getWidth() --=150
- highText.setText(text)
- tw = highText.getWidth()
- hposx = math.floor(w-tw)/2, 2
- hposx = hposx+10
- highText.setX(hposx)
- posy = 10
- highText.setY(posy)
- end
- function lowPrint(text)
- local w
- local tw
- local posx
- local w = bigBox.getWidth()
- lowText.setText(text)
- lowText.setZIndex(5)
- tw = lowText.getWidth()
- posx = math.floor(w-tw)/2, 2
- posx = posx +10
- lowText.setX(posx)
- lowText.setY(40)
- end
- function mPrint(text,line,color)
- if line < 11 then
- miniPrint[line].setText(text)
- miniPrint[line].setColor(color)
- miniPrint[line].setX(10)
- local correctly = true
- else
- local correctly = false
- end
- return correctly
- end
- --now we define print functions for books and such
- function tinyPrint(text,line,color)
- if line < 6 then
- tinyText[line].setText(text)
- tinyText[line].setColor(color)
- tinyText[line].setX(10)
- --^^ to counteract tinyCPrint
- local correctly = true
- else
- local correctly = false
- end
- return correctly
- end
- function tinyCPrint(text,line,color)
- if line <6 then
- local w = bigBox.getWidth()
- tinyText[line].setText(text)
- tw = tinyText[line].getWidth()
- tX = math.floor(w-tw)/2, 2
- tX = tX + 10 --take in account for the offset
- tinyText[line].setX(tX)
- tinyText[line].setColor(color)
- local correctly = true
- else
- local correctly = false
- end
- return correctly --I sure hope it does. :3
- end
- function splitUp(text)
- repeat
- endSplit = endSplit+1
- --^^increase where it splits each time,
- --done in characters
- cLeft = text:sub(endSplit+1, #text)
- --^^ set the leftover text to the rest of
- --the line
- cText = text:sub(1,endSplit)
- --^^cut off the extra text
- until glass.getStringWidth(cText) < 151
- --^^ keep trying till it gets it under 151
- return cText, cLeft
- --^^ return the variables
- end
- function getTinyPrint(line)
- if line <6 then
- return tinyText[line].getText()--, tinyText[line].getColor()
- else
- local text = "Line must be <6."
- return text
- end
- end
- function pushTinyPrint(text,color)
- local sl, sc = getTinyPrint(2)
- local tl, tc = getTinyPrint(3)
- local fl, fc = getTinyPrint(4)
- local fil, fic = getTinyPrint(5)
- tinyPrint(text,5,color)
- tinyPrint(fil,4,glcolors.red)
- tinyPrint(fl,3,glcolors.red)
- tinyPrint(tl,2,glcolors.red)
- tinyPrint(sl,1,glcolors.red)
- end
- function mCPrint(text,line,color)
- if line <11 then
- local w = bigBox.getWidth()
- miniText[line].setText(text)
- tw = miniText[line].getWidth()
- tX = math.floor(w-tw)/2, 2
- tX = tX +10 --take in account for the offset
- miniText[line].setX(tX)
- miniText[line].setColor(color)
- local correctly = true
- else
- local correctly = false
- end
- return correctly
- end
- function tinyClear()
- local i
- for i=1,5 do
- tinyPrint(" ", i, glcolors.red)
- end
- end
- function bigClear()
- highPrint(" ")
- midPrint(" ")
- lowPrint(" ")
- end
- function mClear()
- local i
- for i= 1,10 do
- mPrint(" ",i,glcolors.red)
- end
- end
- function clearAll()
- bigClear()
- tinyClear()
- mClear()
- pixelClear()
- end
- function sleepMode()
- glass.clear()
- local sleeped = true
- while sleeped == true do
- local evt, cmd = os.pullEvent("chat_command")
- cmd = string.lower(cmd)
- if cmd == "wake" then
- sleeped = false
- reboot()
- end
- end
- end
- --now we launch apps based on what the user inputs
- function homeScreenLaunch()
- mClear()
- tinyClear()
- pixelClear()
- local evt, cmd = os.pullEvent("chat_command")
- cmd = string.lower(cmd)
- if cmd == "apps" then
- launchApps()
- elseif cmd == "shutdown" then
- bigClear()
- midPrint("Goodbye.")
- sleep(1)
- on = false
- elseif cmd == "help" then
- shell.run('CCGlass/ccghelp')
- elseif cmd == "reboot" then
- bigClear()
- midPrint("Rebooting.")
- sleep(2)
- reboot()
- elseif cmd == "options" then
- shell.run('CCGlass/options')
- elseif cmd == "omg" then
- highPrint("What happened?")
- sleep(2)
- reprintHome()
- elseif cmd == "ping" then
- highPrint("Pong!")
- sleep(2)
- reprintHome()
- elseif cmd == "sleep" then
- bigClear()
- highPrint("Do $$wake to wake.")
- sleep(2)
- sleepMode()
- else
- reprintHome()
- end
- reprintHome()
- end
- --now we launch 3rd party and default apps
- function launchApps()
- tinyClear()
- tinyPrint("test :3",1,glcolors.red)
- highPrint("Launcher v1")
- midPrint(" ")
- lowPrint("Usage: $$appname")
- local evt, cmd = os.pullEvent("chat_command")
- cmd = string.lower(cmd)
- if cmd == "exit" then
- else
- shell.run("CCGlass/"..cmd.." ")
- we = fs.open("glassErrors", "w")
- we.writeLine(error)
- we.close()
- reprintHome()
- end
- end
- --now we can reprint the homescreen
- function reprintHome()
- clearAll()
- highPrint("Welcome, "..username.."!")
- midPrint("V"..glassVersion.."")
- lowPrint("Do $$help for help.")
- end
- --firsttime?
- if fs.exists("glassside") == false or newuserdev == true then
- getSide()
- end
- --this function was kindly created by TheOriginalBIT
- --who is also awesome.
- function rgbColor( _r, _g, _b )
- return bit.bor( bit.blshift( bit.bor( bit.blshift( _r, 8 ), _g ), 8 ), _b )
- end
- --[[begin execution]]
- function reboot()
- load()
- glass.clear()
- firstDraw()
- reprintHome()
- end
- reboot()
- while on == true do
- homeScreenLaunch()
- end
- glass.clear()
Advertisement
Add Comment
Please, Sign In to add comment