danielcbailey

Gui Code

Jun 8th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.60 KB | None | 0 0
  1. --declaring variables
  2.  
  3. local backgroundFileName = "os/images/defaultBkImg"
  4. local _desktop = paintutils.loadImage(backgroundFileName)
  5. running = true
  6. local listFileData = {}
  7.  
  8. --declaring functions
  9.  
  10. wipeScreen = function()
  11. term.setBackgroundColor(colors.black)
  12. end
  13.  
  14. cursorPos = function()
  15. event, button, xPos, yPos = os.pullEvent("mouse_click")
  16. end
  17.  
  18. clear = function()
  19. term.clear()
  20. term.setCursorPos(1, 1)
  21. end
  22.  
  23. drawDesktop = function()
  24. term.setBackgroundColor(colors.lightGray)
  25. clear()
  26. paintutils.drawImage(_desktop, 1, 1)
  27. end
  28.  
  29. drawTaskBar = function()
  30. term.setCursorPos(1, 1)
  31. term.setBackgroundColor(colors.gray)
  32. term.clearLine()
  33. term.setCursorPos(1, 1)
  34. term.setBackgroundColor(colors.red)
  35. term.setTextColor(colors.lightGray)
  36. term.write("[^]")
  37. end
  38.  
  39. showMenu = function()
  40. term.setCursorPos(1,2)
  41. term.setBackgroundColor(colors.gray)
  42. term.setTextColor(colors.red)
  43. term.write(" [Files] ")
  44. term.setCursorPos(1,3)
  45. term.write(" [Store] ")
  46. term.setCursorPos(1,4)
  47. term.write("[Settings]")
  48. term.setCursorPos(1,5)
  49. term.write(" [Off] ")
  50. end
  51.  
  52. openSettings = function()
  53. settings = window.create(term.current(), 3, 3, 25, 15, true)
  54. drawSettings = function ()
  55. settings.setBackgroundColor(colors.gray)
  56. settings.clear()
  57. settings.setCursorPos(1,1)
  58. settings.setBackgroundColor(colors.black)
  59. settings.clearLine()
  60. settings.setCursorPos(9, 1)
  61. settings.setTextColor(colors.white)
  62. settings.write("Settings")
  63. settings.setCursorPos(25, 1)
  64. settings.setBackgroundColor(colors.red)
  65. settings.write("X")
  66. settingsShowing = true
  67. settings.setCursorPos(1, 2)
  68. settings.setBackgroundColor(colors.white)
  69. settings.setTextColor(colors.red)
  70. settings.write("Change Background Image")
  71. settings.setCursorPos(1,4)
  72. settings.write("Set a Password")
  73. settings.setCursorPos(1,6)
  74. settings.write("Launch Terminal")
  75. end
  76. drawSettings()
  77. while settingsShowing == true do
  78. cursorPos()
  79. if xPos == 27 and yPos == 3 then
  80. settingsShowing = false
  81. setup()
  82. settings.setVisible(false)
  83. end
  84. if xPos > 2 and xPos < 19 and yPos == 8 then
  85. running = false
  86. clear()
  87. settingsShowing = false
  88. settings.setVisible(false)
  89. wipeScreen()
  90. end
  91. end
  92. end
  93.  
  94. renderIcons = function(TLx, TLy, program)
  95. while running == true do
  96. os.pullEvent("mouse_click")
  97. cursorPos()
  98. sleep(0.2)
  99. if xPos > TLx - 1 and xPos < TLx +5 then
  100. if yPos < TLy + 6 and yPos > TLy - 1 then
  101. running = false
  102. os.run({}, "os/programFiles/" .. program .. "/executable")
  103. end
  104. end
  105. end
  106. end
  107.  
  108. drawIcons = function()
  109. local listFileLine = ""
  110. listFile = fs.open("os/saves/programList", "r")
  111. listFileData = {}
  112. repeat
  113. local listFileLine = listFile.readLine()
  114. table.insert(listFileData, listFileLine)
  115. until(listFileLine == nil)
  116. listFile.close()
  117. iconCount = table.getn(listFileData)
  118. i = 0
  119. while i < iconCount do
  120. iconImg = paintutils.loadImage("os/programFiles/" .. listFileData[i+1] .. "/logo")
  121. if i < 6 then
  122. paintutils.drawImage(iconImg, i * 7 + 2, 14)
  123. term.setCursorPos(i * 7 + 2, 19)
  124. term.setBackgroundColor(colors.white)
  125. term.setTextColor(colors.black)
  126. term.write(listFileData[i+1])
  127. end
  128. i = i + 1
  129. end
  130. end
  131.  
  132. --runtime code
  133.  
  134. setup = function()
  135. drawDesktop()
  136. drawTaskBar()
  137. drawIcons()
  138. term.setCursorPos(1,19)
  139. end
  140. setup()
  141. while running == true do
  142. cursorPos()
  143. if xPos < 8 and yPos == 1 then
  144. showMenu()
  145. menu = true
  146. end
  147. if menu == true then
  148. if xPos > 8 or yPos > 5 then
  149. setup()
  150. menu = false
  151. end
  152. end
  153. if menu == true and xPos < 8 and yPos == 4 then
  154. menu = false
  155. setup()
  156. openSettings()
  157. end
  158. if menu == true and xPos < 8 and yPos == 5 then
  159. running = false
  160. clear()
  161. os.shutdown()
  162. end
  163. if xPos > 2 - 1 and xPos < 2 +6 then
  164. if yPos < 14 + 6 and yPos > 14 - 1 then
  165. running = false
  166. os.run({}, "os/programFiles/" .. listFileData[1] .. "/executable")
  167. end
  168. end
  169. if xPos > 9 - 1 and xPos < 9 +6 then
  170. if yPos < 14 + 6 and yPos > 14 - 1 and iconCount > 1 then
  171. running = false
  172. os.run({}, "os/programFiles/" .. listFileData[2] .. "/executable")
  173. end
  174. end
  175. if xPos > 18 - 1 and xPos < 18 +6 then
  176. if yPos < 14 + 6 and yPos > 14 - 1 and iconCount > 2 then
  177. running = false
  178. os.run({}, "os/programFiles/" .. listFileData[3] .. "/executable")
  179. end
  180. end
  181. if xPos > 23 - 1 and xPos < 23 +6 then
  182. if yPos < 14 + 6 and yPos > 14 - 1 and iconCount > 3 then
  183. running = false
  184. os.run({}, "os/programFiles/" .. listFileData[4] .. "/executable")
  185. end
  186. end
  187. if xPos > 30 - 1 and xPos < 30 +6 then
  188. if yPos < 14 + 6 and yPos > 14 - 1 and iconCount > 4 then
  189. running = false
  190. os.run({}, "os/programFiles/" .. listFileData[5] .. "/executable")
  191. end
  192. end
  193. if xPos > 37 - 1 and xPos < 37 +6 then
  194. if yPos < 14 + 6 and yPos > 14 - 1 and iconCount > 5 then
  195. running = false
  196. os.run({}, "os/programFiles/" .. listFileData[6] .. "/executable")
  197. end
  198. end
  199. end
Advertisement
Add Comment
Please, Sign In to add comment