5bitesofcookies

Glass 3.0(BETA 1)

Oct 17th, 2013
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.12 KB | None | 0 0
  1. --[[
  2. If you're wanting to make an application for
  3. CCGlass, please read the guide on the forums.
  4. Every time a developer doesn't read the guide,
  5. an innocent computer crashes
  6.  
  7. Update information:
  8. ===
  9. v0.3.0
  10. Version Nickname: Crystal-Clear
  11. *Added Okay Glass feature, which works a lot
  12. ^like the real Glass.
  13. *Removed Garbage Collectors and defined
  14. ^variables as local when needed instead, as
  15. ^suggested by TheOriginalBit
  16. *Added mPrint(text,line,color) which is like
  17. ^tinyPrint but fits 10 lines
  18. *Added tinyCPrint(text,line,color) which is
  19. ^just like the normal tinyPrint but is
  20. ^centered. Also done with
  21. ^mCPrint(text,line,color)!
  22. *Improved how tinyPrint works
  23. *Fixed the PixelAPI to display pixels at the
  24. ^right coords.
  25. *Added drawLineX(startx, endx,y,color,trans)
  26. ^and drawLineY(starty,endy,x,color,trans)
  27. ^which basicly draw lines
  28. *Added sleepmode, which can be turned on by
  29. ^doing $$sleep on the home screen.
  30. *Added reboot, which can be done by doing
  31. ^$$reboot at the home screen
  32. *Added options, which includes an updater :D
  33. *Added Books. Books go in CCGBooks/ and need
  34. ^no sepcial format whatsoever. Just text.
  35. *Removed bookPrint(an empty function)
  36. *Added to the versioning system more
  37. *Removed Herobrine
  38.  
  39. ===
  40. v0.2.1: Fixes the glitch where the terminal
  41. would always need to be on the left side, no
  42. matter what
  43. Adds pixelClear(), which clears the pixels on
  44. the pixelAPI.
  45. Redid the versioning system to a more popular
  46. way of versioning applications.
  47. ===
  48. v0.2.0: Adds the Pixel API, aswell as the
  49. "Garbage Collectors" that set variables
  50. that are no longer needed at the ends of funct-
  51. ions to nil.
  52. ===
  53. v0.1.0
  54. Initial Release
  55.  
  56.  
  57.  
  58.  
  59. CREDITS:
  60. (MC IGN: Hithere__)Icanbreathecode - Making
  61. glass
  62. TheOriginalBIT for kindly making the RGB Color
  63. converter, and being awesome
  64. GravityScore for making LuaIDE, which has saved
  65. me a lot of time.
  66. The community, for helping me with figuring out
  67. a lot of stuff about Terminal Glasses.
  68. Dan200, for making computercraft
  69. Mikeemoo for making OpenPeripherals
  70. ===
  71. DEVMODE CONFIGURATION
  72. If you're just looking at the code, don't touch this
  73. Application makers, this is pointless for you too
  74. ]]
  75. devmode = true
  76. newuserdev = false
  77. --first we set ye color values
  78. glcolors = {}
  79. glcolors.red = 0xff3333
  80. glcolors.blue = 0x7dd2e4
  81. glcolors.yellow = 0xffff4d
  82. glcolors.green = 0x4dff4d
  83. glcolors.gray = 0xe0e0e0
  84. glcolors.textGray = 0x676767
  85. glcolors.text = 0x5a5a5
  86. glcolors.otherBlue = 0x2e679f
  87. --colors not stolen from Plastic
  88. --:p
  89. glcolors.black = 0x000000
  90. glcolors.purple = 0xff00ff
  91. glcolors.blueGreen = 0x00ffff
  92. glcolors.orange = 0xff6600
  93. glcolors.darkBlue = 0x000066
  94. glcolors.brown = 0x663300
  95. glcolors.otherGreen = 0x00ff00
  96. glcolors.lightOrange = 0xffcc00
  97. --second, we ensure the user isn't wasting an advanced cpu
  98. if term.isColor() == true and devmode == false then
  99. 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)")
  100. local answer = read()
  101. if answer == "n" then
  102. error("User opted out")
  103. end
  104. end
  105. function getSide()
  106. tran = fs.open("glasstrans", "w")
  107. tran.writeLine("0.75")
  108. tran.close()
  109. print("Which side is the Terminal Glasses Bridge on?(top bottom left right back, caps count) ")
  110. side = read()
  111. sw = fs.open("glassside", "w")
  112. sw.writeLine(side)
  113. sw.close()
  114. print("What is your desired username?")
  115. username = read()
  116. sw = fs.open("username", "w")
  117. sw.writeLine(username)
  118. sw.close()
  119. print("Now, if you havn't already, take the terminal glasses you're going to use and right-click the terminal bridge.")
  120. end
  121. function loadPixelAPI()
  122. print("Loading PixelAPI.")
  123. pixelsOne = {}
  124. pixelsTwo = {}
  125. pixelsThree = {}
  126. pixelsFour = {}
  127. pixelsFive = {}
  128. pixelsSix = {}
  129. pixelsSeven = {}
  130. pixelsEight = {}
  131. pixelsNine = {}
  132. pixelsTen = {}
  133. local i
  134. for i = 1,30 do
  135. vI = i-1
  136. vI = vI * 5
  137. vI = vI + 10
  138. pixelsOne[i] = glass.addBox(vI, 5, 5, 5, glcolors.red, 0)
  139. pixelsOne[i].setZIndex(4)
  140. end
  141. for i = 1,30 do
  142. vI = i-1
  143. vI = vI * 5
  144. vI = vI + 10
  145. pixelsTwo[i] = glass.addBox(vI, 10, 5, 5, glcolors.red, 0)
  146. pixelsTwo[i].setZIndex(4)
  147. end
  148. for i = 1,30 do
  149. vI = i-1
  150. vI = vI * 5
  151. vI = vI + 10
  152. pixelsThree[i] = glass.addBox(vI, 15, 5, 5, glcolors.red, 0)
  153. pixelsThree[i].setZIndex(4)
  154. end
  155. for i = 1,30 do
  156. vI = i-1
  157. vI = vI * 5
  158. vI = vI + 10
  159. pixelsFour[i] = glass.addBox(vI, 20, 5, 5, glcolors.red, 0)
  160. pixelsFour[i].setZIndex(4)
  161. end
  162. for i = 1,30 do
  163. vI = i-1
  164. vI = vI * 5
  165. vI = vI + 10
  166. pixelsFive[i] = glass.addBox(vI, 25, 5, 5, glcolors.red, 0)
  167. pixelsFive[i].setZIndex(4)
  168. end
  169. for i = 1,30 do
  170. vI = i-1
  171. vI = vI * 5
  172. vI = vI + 10
  173. pixelsSix[i] = glass.addBox(vI, 30, 5, 5, glcolors.red, 0)
  174. pixelsSix[i].setZIndex(4)
  175. end
  176. for i = 1,30 do
  177. vI = i-1
  178. vI = vI * 5
  179. vI = vI + 10
  180. pixelsSeven[i] = glass.addBox(vI, 35, 5, 5, glcolors.red, 0)
  181. pixelsSeven[i].setZIndex(4)
  182. end
  183. for i = 1,30 do
  184. vI = i-1
  185. vI = vI * 5
  186. vI = vI + 10
  187. pixelsEight[i] = glass.addBox(vI, 40, 5, 5, glcolors.red, 0)
  188. pixelsEight[i].setZIndex(4)
  189. end
  190. for i = 1,30 do
  191. vI = i-1
  192. vI = vI * 5
  193. vI = vI + 10
  194. pixelsNine[i] = glass.addBox(vI, 45, 5, 5, glcolors.red, 0)
  195. pixelsNine[i].setZIndex(4)
  196. end
  197. for i = 1,30 do
  198. vI = i-1
  199. vI = vI * 5
  200. vI = vI + 10
  201. pixelsTen[i] = glass.addBox(vI, 50, 5, 5, glcolors.red, 0)
  202. pixelsTen[i].setZIndex(4)
  203. end
  204. end
  205. function drawPixel(x, y, color, trans)
  206. --example usage: 2, 4, colors.red, 1
  207. --this would make a red pixel appear at 2, 4.
  208. if y ==1 then
  209. pixelsOne[x].setColor(color)
  210. pixelsOne[x].setOpacity(trans)
  211. elseif y ==2 then
  212. pixelsTwo[x].setColor(color)
  213. pixelsTwo[x].setOpacity(trans)
  214. elseif y ==3 then
  215. pixelsThree[x].setColor(color)
  216. pixelsThree[x].setOpacity(trans)
  217. elseif y ==4 then
  218. pixelsFour[x].setColor(color)
  219. pixelsFour[x].setOpacity(trans)
  220. elseif y ==5 then
  221. pixelsFive[x].setColor(color)
  222. pixelsFive[x].setOpacity(trans)
  223. elseif y ==6 then
  224. pixelsSix[x].setColor(color)
  225. pixelsSix[x].setOpacity(trans)
  226. elseif y ==7 then
  227. pixelsSeven[x].setColor(color)
  228. pixelsSeven[x].setOpacity(trans)
  229. elseif y ==8 then
  230. pixelsEight[x].setColor(color)
  231. pixelsEight[x].setOpacity(trans)
  232. elseif y ==9 then
  233. pixelsNine[x].setColor(color)
  234. pixelsNine[x].setOpacity(trans)
  235. elseif y ==10 then
  236. pixelsTen[x].setColor(color)
  237. pixelsTen[x].setOpacity(trans)
  238. end
  239. end
  240. function pixelClear()
  241. for i = 1,30 do
  242. drawPixel(i,1,glcolors.red,0)
  243. end
  244. for i = 1,30 do
  245. drawPixel(i,2,glcolors.red,0)
  246. end
  247. for i = 1,30 do
  248. drawPixel(i,3,glcolors.red,0)
  249. end
  250. for i = 1,30 do
  251. drawPixel(i,4,glcolors.red,0)
  252. end
  253. for i = 1,30 do
  254. drawPixel(i,5,glcolors.red,0)
  255. end
  256. for i = 1,30 do
  257. drawPixel(i,6,glcolors.red,0)
  258. end
  259. for i = 1,30 do
  260. drawPixel(i,7,glcolors.red,0)
  261. end
  262. for i = 1,30 do
  263. drawPixel(i,8,glcolors.red,0)
  264. end
  265. for i = 1,30 do
  266. drawPixel(i,9,glcolors.red,0)
  267. end
  268. for i = 1,30 do
  269. drawPixel(i,10,glcolors.red,0)
  270. end
  271. end
  272. function drawLineX(startx,endx,y,colors,transpa)
  273. local i
  274. for i=startx,endx do
  275. drawPixel(i,y,colors,transpa)
  276. -- print("drew pixel at x "..i.." y "..y.." trans "..transpa.." ")
  277. end
  278. end
  279. function drawLineY(x,starty,endy,colory,transpar)
  280. local i
  281. for i=starty,endy do
  282. drawPixel(x,i,colory,transpar)
  283. end
  284. end
  285. function load()
  286. dir = "CCGlass/"
  287. glassVersion = "0.3"
  288. glassVer = 30
  289. --note that this still runs on first time
  290. on = true
  291. gs = fs.open("glassside", "r")
  292. side = gs.readLine()
  293. gs.close()
  294. glass = peripheral.wrap(side)
  295. gs = fs.open("username", "r")
  296. username = gs.readLine()
  297. gs.close()
  298. tran = fs.open("glasstrans", "r")
  299. transp = tran.readLine()
  300. tran.close()
  301. transp = tonumber(transp)
  302. shell.run('glassTheme')
  303. end
  304. --Ye first thing where we draw stuff
  305. --(besides the PixelAPI)
  306. function firstDraw()
  307. tinyText = {}
  308. local tinyY
  309. local i
  310. for i = 0,4 do
  311. tinyY = i *10
  312. tinyY = tinyY + 5
  313. i = i+1
  314. tinyText[i]= glass.addText(10, tinyY, " ", glcolors.red)
  315. tinyText[i].setZIndex(5)
  316. end
  317. miniPrint = {}
  318. for i = 0,9 do
  319. local yset = i * 5
  320. yset = yset + 5
  321. i = i+1
  322. miniPrint[i] = glass.addText(10,yset," ",glcolors.red)
  323. miniPrint[i].setZIndex(5)
  324. miniPrint[i].setScale(0.5)
  325. end
  326. midText= glass.addText(29, 27.9, " ", glcolors.green)
  327. highText= glass.addText(29, 27.9, " ", glcolors.red)
  328. lowText= glass.addText(29, 27.9, " ", glcolors.otherBlue)
  329. leftBox = glass.addBox(5, 0, 5, 60, sideColors, transp)
  330. bigBox = glass.addBox(10, 5, 150, 50, bigBoxColor, transp)
  331. --note that the width really is 150
  332. --add 10 to x cords, 5 to y cords
  333. for i = 1, 20 do
  334. bigBox.setWidth(i * 7.5)
  335. sleep(0.01)
  336. end
  337. leftBox = glass.addBox(160, 0, 5, 60, sideColors, transp)
  338. loadPixelAPI()
  339. end
  340. --The way glass prints stuffs to the screen
  341. function midPrint(text)
  342. local w
  343. local tw
  344. local posx
  345. local posy
  346. midText.setText(text)
  347. midText.setScale(2)
  348. midText.setZIndex(5)
  349. w = bigBox.getWidth()
  350. tw = midText.getWidth()
  351. tw = tw*2
  352. posx = math.floor(w-tw)/2, 2
  353. posx = posx +10
  354. midText.setX(posx)
  355. posy = 20
  356. midText.setY(posy)
  357. end
  358. function highPrint(text)
  359. local w
  360. local hposx
  361. local posy
  362. highText.setZIndex(5)
  363. local w = bigBox.getWidth() --=150
  364. highText.setText(text)
  365. tw = highText.getWidth()
  366. hposx = math.floor(w-tw)/2, 2
  367. hposx = hposx+10
  368. highText.setX(hposx)
  369. posy = 10
  370. highText.setY(posy)
  371. end
  372. function lowPrint(text)
  373. local w
  374. local tw
  375. local posx
  376. local w = bigBox.getWidth()
  377. lowText.setText(text)
  378. lowText.setZIndex(5)
  379. tw = lowText.getWidth()
  380. posx = math.floor(w-tw)/2, 2
  381. posx = posx +10
  382. lowText.setX(posx)
  383. lowText.setY(40)
  384. end
  385. function mPrint(text,line,color)
  386. if line < 11 then
  387. miniPrint[line].setText(text)
  388. miniPrint[line].setColor(color)
  389. miniPrint[line].setX(10)
  390. local correctly = true
  391. else
  392. local correctly = false
  393. end
  394. return correctly
  395. end
  396. --now we define print functions for books and such
  397. function tinyPrint(text,line,color)
  398. if line < 6 then
  399. tinyText[line].setText(text)
  400. tinyText[line].setColor(color)
  401. tinyText[line].setX(10)
  402. --^^ to counteract tinyCPrint
  403. local correctly = true
  404. else
  405. local correctly = false
  406. end
  407. return correctly
  408. end
  409. function tinyCPrint(text,line,color)
  410. if line <6 then
  411. local w = bigBox.getWidth()
  412. tinyText[line].setText(text)
  413. tw = tinyText[line].getWidth()
  414. tX = math.floor(w-tw)/2, 2
  415. tX = tX + 10 --take in account for the offset
  416. tinyText[line].setX(tX)
  417. tinyText[line].setColor(color)
  418. local correctly = true
  419. else
  420. local correctly = false
  421. end
  422. return correctly --I sure hope it does. :3
  423. end
  424. function splitUp(text)
  425. repeat
  426. endSplit = endSplit+1
  427. --^^increase where it splits each time,
  428. --done in characters
  429. cLeft = text:sub(endSplit+1, #text)
  430. --^^ set the leftover text to the rest of
  431. --the line
  432. cText = text:sub(1,endSplit)
  433. --^^cut off the extra text
  434. until glass.getStringWidth(cText) < 151
  435. --^^ keep trying till it gets it under 151
  436. return cText, cLeft
  437. --^^ return the variables
  438. end
  439. function getTinyPrint(line)
  440. if line <6 then
  441. return tinyText[line].getText()--, tinyText[line].getColor()
  442. else
  443. local text = "Line must be <6."
  444. return text
  445. end
  446. end
  447.  
  448. function pushTinyPrint(text,color)
  449. local sl, sc = getTinyPrint(2)
  450. local tl, tc = getTinyPrint(3)
  451. local fl, fc = getTinyPrint(4)
  452. local fil, fic = getTinyPrint(5)
  453. tinyPrint(text,5,color)
  454. tinyPrint(fil,4,glcolors.red)
  455. tinyPrint(fl,3,glcolors.red)
  456. tinyPrint(tl,2,glcolors.red)
  457. tinyPrint(sl,1,glcolors.red)
  458. end
  459.  
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466.  
  467.  
  468. function mCPrint(text,line,color)
  469. if line <11 then
  470. local w = bigBox.getWidth()
  471. miniText[line].setText(text)
  472. tw = miniText[line].getWidth()
  473. tX = math.floor(w-tw)/2, 2
  474. tX = tX +10 --take in account for the offset
  475. miniText[line].setX(tX)
  476. miniText[line].setColor(color)
  477. local correctly = true
  478. else
  479. local correctly = false
  480. end
  481. return correctly
  482. end
  483.  
  484. function tinyClear()
  485. local i
  486. for i=1,5 do
  487. tinyPrint(" ", i, glcolors.red)
  488. end
  489. end
  490. function bigClear()
  491. highPrint(" ")
  492. midPrint(" ")
  493. lowPrint(" ")
  494. end
  495. function mClear()
  496. local i
  497. for i= 1,10 do
  498. mPrint(" ",i,glcolors.red)
  499. end
  500. end
  501. function clearAll()
  502. bigClear()
  503. tinyClear()
  504. mClear()
  505. pixelClear()
  506. end
  507. function sleepMode()
  508. glass.clear()
  509. local sleeped = true
  510. while sleeped == true do
  511. local evt, cmd = os.pullEvent("chat_command")
  512. cmd = string.lower(cmd)
  513. if cmd == "wake" then
  514. sleeped = false
  515. reboot()
  516. end
  517. end
  518. end
  519. --now we launch apps based on what the user inputs
  520. function homeScreenLaunch()
  521. mClear()
  522. tinyClear()
  523. pixelClear()
  524. local evt, cmd = os.pullEvent("chat_command")
  525. cmd = string.lower(cmd)
  526. if cmd == "apps" then
  527. launchApps()
  528. elseif cmd == "shutdown" then
  529. bigClear()
  530. midPrint("Goodbye.")
  531. sleep(1)
  532. on = false
  533. elseif cmd == "help" then
  534. shell.run('CCGlass/ccghelp')
  535. elseif cmd == "reboot" then
  536. bigClear()
  537. midPrint("Rebooting.")
  538. sleep(2)
  539. reboot()
  540. elseif cmd == "options" then
  541. shell.run('CCGlass/options')
  542. elseif cmd == "omg" then
  543. highPrint("What happened?")
  544. sleep(2)
  545. reprintHome()
  546. elseif cmd == "ping" then
  547. highPrint("Pong!")
  548. sleep(2)
  549. reprintHome()
  550. elseif cmd == "sleep" then
  551. bigClear()
  552. highPrint("Do $$wake to wake.")
  553. sleep(2)
  554. sleepMode()
  555. else
  556. reprintHome()
  557. end
  558. reprintHome()
  559. end
  560. --now we launch 3rd party and default apps
  561. function launchApps()
  562. tinyClear()
  563. tinyPrint("test :3",1,glcolors.red)
  564. highPrint("Launcher v1")
  565. midPrint(" ")
  566. lowPrint("Usage: $$appname")
  567. local evt, cmd = os.pullEvent("chat_command")
  568. cmd = string.lower(cmd)
  569. if cmd == "exit" then
  570. else
  571. shell.run("CCGlass/"..cmd.." ")
  572. we = fs.open("glassErrors", "w")
  573. we.writeLine(error)
  574. we.close()
  575. reprintHome()
  576. end
  577. end
  578. --now we can reprint the homescreen
  579. function reprintHome()
  580. clearAll()
  581. highPrint("Welcome, "..username.."!")
  582. midPrint("V"..glassVersion.."")
  583. lowPrint("Do $$help for help.")
  584. end
  585. --firsttime?
  586. if fs.exists("glassside") == false or newuserdev == true then
  587. getSide()
  588. end
  589. --this function was kindly created by TheOriginalBIT
  590. --who is also awesome.
  591. function rgbColor( _r, _g, _b )
  592. return bit.bor( bit.blshift( bit.bor( bit.blshift( _r, 8 ), _g ), 8 ), _b )
  593. end
  594. --[[begin execution]]
  595. function reboot()
  596. load()
  597. glass.clear()
  598. firstDraw()
  599. reprintHome()
  600. end
  601. reboot()
  602. while on == true do
  603. homeScreenLaunch()
  604. end
  605. glass.clear()
Advertisement
Add Comment
Please, Sign In to add comment