Advertisement
minif

desktop

Jan 23rd, 2020
1,671
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.06 KB | None | 0 0
  1. --Minif OS
  2. --By Minif
  3.  
  4. --Functions and Variables
  5. osRunning = true
  6. osUserBGImageExists = false
  7. osUserAdmin = false
  8.  
  9. function osDrawWindow(name)
  10. paintutils.drawFilledBox(3,3,osScreenSizeX-2,osScreenSizeY-2,colors.white)
  11. paintutils.drawBox(3,3,osScreenSizeX-2,5,colors.lightGray)
  12. term.setBackgroundColor(colors.white)
  13. term.setTextColor(colors.black)
  14. term.setCursorPos(4,4)
  15. term.write(name)
  16. end
  17.  
  18. function osConfirm(name,message,detail)
  19. osDrawWindow(name)
  20. term.setCursorPos(4,7)
  21. term.write(message)
  22. term.setCursorPos(4,8)
  23. term.write(detail)
  24. paintutils.drawBox(4,11,osScreenSizeX-3,11,colors.green)
  25. term.setCursorPos(5,11)
  26. term.write("Yes")
  27. paintutils.drawBox(4,13,osScreenSizeX-3,13,colors.red)
  28. term.setCursorPos(5,13)
  29. term.write("No")
  30. local choice = false
  31. while true do
  32. osPEvent, osPB, osPX, osPY = os.pullEvent("mouse_click")
  33. if osPX >= 3 and osPX <=osScreenSizeX-2 then
  34. if osPY == 11 then
  35. choice = true
  36. return true
  37. else if osPY == 13 then
  38. return false
  39. end
  40. end
  41. end
  42. end
  43. return choice
  44. end
  45.  
  46. function osLoadPrefs()
  47. local pref = fs.open("/system/user/"..osEnteredUser.."/config", "r")
  48. local readFile = pref.readLine()
  49. if fs.exists(readFile) and not (fs.isDir(readFile)) then
  50. os_UserBGImage = paintutils.loadImage(readFile)
  51. osUserBGImageExists = true
  52. end
  53. local readLine = pref.readLine()
  54. if readLine == "true" then
  55. osUserAdmin = true
  56. end
  57. pref.close()
  58. end
  59.  
  60. --Drawing
  61. function osDrawDesktop()
  62. osFillBG(colors.cyan)
  63. if osUserBGImageExists then
  64. paintutils.drawImage(os_UserBGImage,1,2)
  65. else
  66. if osBGImageExists then
  67. paintutils.drawImage(os_BGImage,1,1)
  68. end
  69. end
  70. end
  71.  
  72. function osDrawMenu()
  73. paintutils.drawBox(1,1,osScreenSizeX,1,colors.blue)
  74. term.setBackgroundColor(colors.lightBlue)
  75. term.setTextColor(colors.black)
  76. term.setCursorPos(1,1)
  77. term.write("M >")
  78. term.setCursorPos(5,1)
  79. term.write("File >")
  80. term.setCursorPos(12,1)
  81. term.write("System >")
  82. end
  83.  
  84. function osDrawAll()
  85. term.setCursorBlink(false)
  86. osLoadPrefs()
  87. osDrawDesktop()
  88. osDrawMenu()
  89. end
  90.  
  91. function osDrawPerm(prog)
  92. paintutils.drawFilledBox(3,3,osScreenSizeX-2,osScreenSizeY-2,colors.white)
  93. paintutils.drawBox(3,3,osScreenSizeX-2,5,colors.lightGray)
  94. term.setCursorPos(4,4)
  95. term.setBackgroundColor(colors.white)
  96. term.setTextColor(colors.red)
  97. term.write("Permissions Error")
  98. term.setCursorPos(4,7)
  99. term.setTextColor(colors.black)
  100. term.write("You do not have permission")
  101. term.setCursorPos(4,8)
  102. term.write("To access the program: "..prog)
  103. term.setCursorPos(4,10)
  104. term.write("Press any key to exit.")
  105. while true do
  106. local event = os.pullEvent()
  107. if event == "mouse_click" or event == "key" then
  108. return
  109. end
  110. end
  111. end
  112.  
  113. --Menu Routines
  114. function osMenuM()
  115. term.setBackgroundColor(colors.gray)
  116. term.setTextColor(colors.white)
  117. term.setCursorPos(1,1)
  118. term.write("M v")
  119. term.setCursorPos(1,2)
  120. term.write("Info ")
  121. term.setCursorPos(1,3)
  122. term.write("Log Out ")
  123. term.setCursorPos(1,4)
  124. term.write("Shut Down")
  125. osPEvent, osPB, osPX, osPY = os.pullEvent("mouse_click")
  126. if osPEvent == "mouse_click" then
  127. if osPB == 1 and osPY == 3 and osPX<=9 then
  128. osRunning = false
  129. else if osPB == 1 and osPY == 4 and osPX<=9 then
  130. os.shutdown()
  131. else if osPB == 1 and osPY == 2 and osPX<=9 then
  132. if fs.exists("system/tools/about") then
  133. shell.run("system/tools/about")
  134. else
  135. osBSOD("Critical file missing.","/system/tools/about is missing, and is needed to run.","Please re-install this file")
  136. end
  137. end
  138. end
  139. end
  140. end
  141. end
  142.  
  143. function osMenuFile()
  144. term.setBackgroundColor(colors.gray)
  145. term.setTextColor(colors.white)
  146. term.setCursorPos(5,1)
  147. term.write("File v")
  148. term.setCursorPos(5,2)
  149. term.write("Write ")
  150. term.setCursorPos(5,3)
  151. term.write("Paint ")
  152. term.setCursorPos(5,4)
  153. term.write("Search")
  154. term.setCursorPos(5,5)
  155. term.write("build ")
  156.  
  157. osPEvent, osPB, osPX, osPY = os.pullEvent("mouse_click")
  158. if osPB == 1 and osPY == 2 and osPX >= 5 and osPX <= 10 then
  159. if fs.exists("system/tools/medit") then
  160. shell.run("system/tools/medit")
  161. else
  162. osBSOD("Critical file missing.","/system/tools/medit is missing, and is needed to run.","Please re-install this file")
  163. end
  164. else if osPB == 1 and osPY == 3 and osPX >= 5 and osPX <=10 then
  165. if fs.exists("system/tools/mpaint") then
  166. shell.run("system/tools/mpaint")
  167. else
  168. osBSOD("Critical file missing.","/system/tools/mpaint is missing, and is needed to run.","Please re-install this file")
  169. end
  170. else if osPB == 1 and osPY == 5 and osPX >= 5 and osPX <= 10 then
  171. if fs.exists("run") then
  172. shell.run("run")
  173. end
  174. else if osPB == 1 and osPY == 4 and osPX >= 5 and osPX <= 10 then
  175. if fs.exists("system/tools/look") then
  176. shell.run("system/tools/look")
  177. else
  178. osBSOD("Critical file missing.","/system/tools/look is missing, and is needed to run.","Please re-install this file")
  179. end
  180. end
  181. end
  182. end
  183. end
  184. end
  185.  
  186. function osMenuSystem()
  187. term.setBackgroundColor(colors.gray)
  188. term.setTextColor(colors.white)
  189. term.setCursorPos(12,1)
  190. term.write("System v")
  191. term.setCursorPos(12,2)
  192. term.write("Shell ")
  193. term.setCursorPos(12,3)
  194. term.write("Settings ")
  195. term.setCursorPos(12,4)
  196. term.write("Run Program")
  197.  
  198. osPEvent, osPB, osPX, osPY = os.pullEvent("mouse_click")
  199. if osPB == 1 and osPY == 2 and osPX >= 12 and osPX <= 22 then
  200. if osUserAdmin then
  201. osFillBG(colors.black)
  202. term.setBackgroundColor(colors.black)
  203. term.setTextColor(colors.white)
  204. print("Enter 'exit' to return to MinifOS")
  205. shell.run("shell")
  206. return
  207. else
  208. osDrawPerm("Shell")
  209. end
  210. else if osPB == 1 and osPY == 3 and osPX >= 12 and osPX <=22 then
  211. if fs.exists("system/tools/settings") then
  212. shell.run("system/tools/settings")
  213. return
  214. else
  215. osBSOD("Critical file missing.","/system/tools/settings is missing, and is needed to run.","Please re-install this file")
  216. end
  217. else if osPB == 1 and osPY == 4 and osPX >= 12 and osPX <= 22 then
  218. if fs.exists("system/tools/run") then
  219. shell.run("system/tools/run")
  220. else
  221. osBSOD("Critical file missing.","/system/tools/run is missing, and is needed to run.","Please re-install this file")
  222. end
  223. end
  224. end
  225. end
  226. end
  227.  
  228. --Input Events
  229. local function handleClick(button,x,y)
  230. if button == 1 and y == 1 and x <= 3 then
  231. osMenuM()
  232. osDrawAll()
  233. end
  234. if button == 1 and y == 1 and x >= 5 and x <=10 then
  235. osMenuFile()
  236. osDrawAll()
  237. end
  238. if button == 1 and y == 1 and x >= 12 and x <=19 then
  239. osMenuSystem()
  240. osDrawAll()
  241. end
  242. end
  243.  
  244. local function menuInput()
  245. osPEvent, osP1, osP2, osP3, osP4, osP5 = os.pullEvent()
  246. if osPEvent == "mouse_click" then
  247. handleClick(osP1,osP2,osP3)
  248. end
  249. end
  250.  
  251. --Execution
  252.  
  253. osLoadPrefs()
  254. osDrawAll()
  255. while osRunning do
  256. menuInput()
  257. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement