minif

desktop1.1

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