5bitesofcookies

glass v0.0001

Jun 17th, 2013
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.86 KB | None | 0 0
  1. --If you're wanting to make an application for
  2. --CCGlass, please read the guide on the forums.
  3. --Every time a developer doesn't read the guide,
  4. --an innocent computer dies
  5. --Note: If you're making an app that deals with
  6. --addBox, wait until v0.0002 because it
  7. --will have the Pixel API, which is a lot like
  8. --paintutils but for glass.
  9.  
  10.  
  11. --DEVMODE CONFIGURATION
  12. --If you're just looking at the code, don't touch this
  13. --Application makers, this is pointless for you too
  14. devmode = true
  15. newuserdev = false
  16.  
  17.  
  18. --first we set ye color values
  19. glcolors = {}
  20.             glcolors.red = 0xff3333
  21.             glcolors.blue = 0x7dd2e4
  22.             glcolors.yellow = 0xffff4d
  23.             glcolors.green = 0x4dff4d
  24.             glcolors.gray = 0xe0e0e0
  25.             glcolors.textGray = 0x676767
  26.             glcolors.text = 0x5a5a5
  27.             glcolors.otherBlue = 0x2e679f
  28.             glcolors.black = 0x000000
  29.  
  30. --second, we ensure the user isn't wasting an advanced cpu
  31. if term.isColor() == true and devmode == false then
  32.   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)")
  33.   answer = read()
  34.   if answer == "n" then
  35.     error("User opted out")
  36.   end
  37. end
  38. function getSide()
  39.   print("Which side is the Terminal Glasses Bridge on?(top bottom left right back, caps count) ")
  40.   side = read()
  41.   sw = fs.open("glassside", "w")
  42.   sw.writeLine(side)
  43.   sw.close()
  44.   print("What is your desired username?")
  45.   username = read()
  46.   sw = fs.open("username", "w")
  47.   sw.writeLine(username)
  48.   sw.close()
  49.   print("Now, if you havn't already, take the terminal glasses you're going to use and right-click the terminal bridge.")
  50. end
  51. function load()
  52.   dir = "CCGlass/"
  53.   --note that this still runs on first time
  54.   on = true
  55.   gs = fs.open("glassside", "r")
  56.   side = gs.readLine()
  57.   gs.close()
  58.   glass = peripheral.wrap(side)
  59.   gs = fs.open("username", "r")
  60.   username = gs.readLine()
  61.   gs.close()
  62. end
  63.  
  64.  
  65. --Ye first thing where we draw stuff
  66. function firstDraw()
  67. oneText= glass.addText(10, 27.9, " ", glcolors.green)
  68. twoText= glass.addText(10, 27.9, " ", glcolors.green)
  69. threeText= glass.addText(10, 27.9, " ", glcolors.green)
  70. fourText= glass.addText(10, 27.9, " ", glcolors.green)
  71. fiveText= glass.addText(10, 27.9, " ", glcolors.green)
  72.  
  73. midText= glass.addText(29, 27.9, " ", glcolors.green)
  74. highText= glass.addText(29, 27.9, " ", glcolors.red)
  75. lowText= glass.addText(29, 27.9, " ", glcolors.otherBlue)
  76.   leftBox = glass.addBox(5, 0, 5, 60, glcolors.blue, 0.75)
  77.   bigBox = glass.addBox(10, 5, 48, 50, glcolors.gray, 0.75)
  78.   for bigWidth = 1, 20 do
  79.     bigBox.setWidth(bigWidth * 7.5)
  80.     sleep(0.01)
  81.   end
  82.   leftBox = glass.addBox(160, 0, 5, 60, glcolors.blue, 0.75)
  83.   --Putting default text
  84.  
  85. end
  86. --The way the OS prints stuffs to the screen
  87. function midPrint(text)
  88.   midText.setText(text)
  89.   midText.setScale(2)
  90.   midText.setZIndex(1)
  91.   w = bigBox.getWidth()
  92.   tw = midText.getWidth()
  93.   tw = tw*2
  94.   posx = math.floor(w-tw)/2, 2
  95.   posx = posx +10
  96.   midText.setX(posx)
  97.   posy = 20
  98.   midText.setY(posy)
  99.  
  100. end
  101.  
  102. function highPrint(text)
  103.   highText.setZIndex(1)
  104.     local w = bigBox.getWidth() --=150
  105.     highText.setText(text)
  106.     tw = highText.getWidth()
  107.   hposx = math.floor(w-tw)/2, 2
  108.   hposx = hposx+10
  109.   highText.setX(hposx)
  110.   posy = 10
  111.   highText.setY(posy)
  112.  
  113. end
  114.  
  115. function lowPrint(text)
  116.     local w = bigBox.getWidth()
  117.   lowText.setText(text)
  118.   lowText.setZIndex(1)
  119.   tw = lowText.getWidth()
  120.   posx = math.floor(w-tw)/2, 2
  121.   posx = posx +10
  122.   lowText.setX(posx)
  123.   lowText.setY(40)
  124. end
  125. --now we define print functions for books and such
  126. function tinyPrint(text, line, color)
  127.   local w = bigBox.getWidth()
  128.   if line == 1 then
  129.     oneText.setY(5)
  130.     oneText.setColor(color)
  131.     oneText.setZIndex(1)
  132.     oneText.setText(text)
  133.     elseif line == 2 then
  134.     twoText.setY(15)
  135.     twoText.setColor(color)
  136.     twoText.setZIndex(1)
  137.     twoText.setText(text)
  138.     elseif line == 3 then
  139.     threeText.setY(25)
  140.     threeText.setColor(color)
  141.     threeText.setZIndex(1)
  142.     threeText.setText(text)
  143.     elseif line == 4 then
  144.     fourText.setY(35)
  145.     fourText.setColor(color)
  146.     fourText.setZIndex(1)
  147.     fourText.setText(text)
  148.     elseif line == 5 then
  149.     fiveText.setY(45)
  150.     fiveText.setColor(color)
  151.     fiveText.setZIndex(1)
  152.     fiveText.setText(text)
  153.   end
  154. end
  155. function tinyClear()
  156. tinyPrint(" ", 1, glcolors.red)
  157. tinyPrint(" ", 2, glcolors.red)
  158. tinyPrint(" ", 3, glcolors.red)
  159. tinyPrint(" ", 4, glcolors.red)
  160. tinyPrint(" ", 5, glcolors.red)
  161. end
  162. function bigClear()
  163.   highPrint(" ")
  164.   midPrint(" ")
  165.   lowPrint(" ")
  166. end
  167. --now we launch apps based on what the user inputs
  168. function homeScreenLaunch()
  169.   tinyClear()
  170.   evt, cmd = os.pullEvent("chat_command")
  171.   if cmd == "apps" then
  172.     launchApps()
  173.   elseif cmd == "shutdown" then
  174.     on = false
  175.   elseif cmd == "help" then
  176.     shell.run('CCGlass/ccghelp')
  177.   elseif cmd == "easteregg" then
  178.     username = "You have found the easter egg that breaks glass. Congratulations on your find!"
  179.     else
  180.     reprintHome()
  181.   end
  182.   reprintHome()
  183. end
  184. --now we launch 3rd party and default apps
  185. function launchApps()
  186.   tinyClear()
  187.   highPrint("Launcher v0.001")
  188.   midPrint(" ")
  189.   lowPrint("Usage: $$appname")
  190.   evt, cmd = os.pullEvent("chat_command")
  191.   ok, error = pcall(shell.run("CCGlass/"..cmd.." "))
  192.     reprintHome()
  193. end
  194. --now we can reprint the homescreen
  195. function reprintHome()
  196.   tinyClear()
  197.   highPrint("Welcome, "..username.."!")
  198.   midPrint("V0.0001")
  199.   lowPrint("Do $$help for help.")
  200. end
  201. --firsttime?
  202. if fs.exists("glassside") == false or newuserdev == true then
  203.   getSide()
  204. end
  205.  
  206. --here comes the advanced print function
  207. function bookprint()
  208.  
  209.  
  210.  
  211.  
  212. end
  213.  
  214.  
  215. --[[begin execution]]
  216. load()
  217. firstDraw()
  218. reprintHome()
  219. while on == true do
  220.   homeScreenLaunch()
  221. end
  222. shell.run('clear')
Advertisement
Add Comment
Please, Sign In to add comment