Advertisement
Guest User

Untitled

a guest
Jan 31st, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.76 KB | None | 0 0
  1. if not term.isColor() then
  2. error("Invalid display")
  3. end
  4.  
  5. local w,h = term.getSize()
  6.  
  7.  
  8. defaultConfig = {
  9. desktop = {
  10. background = 2,
  11. },
  12. user = {
  13. name = nil,
  14. password = nil,
  15. }
  16. }
  17.  
  18. params = {}
  19.  
  20. --display functions
  21. function nicePrint(text, x, y, bcolor, fcolor)
  22. if bcolor ~= nil then
  23. term.setBackgroundColor(bcolor)
  24. end
  25. term.setTextColor(fcolor)
  26. term.setCursorPos(x, y)
  27. term.write(text)
  28. end
  29.  
  30. function centerPrint(text, y, bcolor, fcolor)
  31. nicePrint(text, w / 2 - #text / 2, y, bcolor, fcolor)
  32. end
  33.  
  34. function rectangle(x, y, w, h, color)
  35. paintutils.drawFilledBox(x + 1, y + 1, x + 1 + w, y + 1 + h, color)
  36. end
  37.  
  38. --main functions
  39. function setup()
  40. local step = 0
  41. local username = "Username: "
  42. local password = "Password: "
  43. local confirmPassword = "Confirm password: "
  44. local bgColor = "Desktop color: "
  45. while true do
  46. rectangle(0, 0, w, h, 1)
  47. rectangle(0, 0, w, 2, 128)
  48. nicePrint("Welcome to BeraudOS !", 2, 2, nil, 1)
  49. nicePrint("Let's configure your desktop !", 2, 5, 1, 32768)
  50. nicePrint("> Fill in the informations bellow", 2, 6, 1, 2048)
  51. nicePrint(username, 4, 8, 1, 256)
  52. nicePrint(password, 4, 9, 1, 256)
  53.  
  54. if step > 3 then
  55. nicePrint(confirmPassword, 4, 10, 1, 8192)
  56. else
  57. nicePrint(confirmPassword, 4, 10, 1, 256)
  58. end
  59.  
  60. nicePrint(bgColor, 4, 11, 1, 256)
  61.  
  62. if step < 4 then
  63. nicePrint(">", 2, 8 + step, 1, 2048)
  64. if step == 0 then
  65. term.setCursorPos(14, 8)
  66. defaultConfig.user.name = io.read()
  67. username = username .. defaultConfig.user.name
  68. elseif step == 1 then
  69. term.setCursorPos(14, 9)
  70. defaultConfig.user.password = read("*")
  71. password = password .. "Hidden"
  72. elseif step == 2 then
  73. local p = nil
  74. while p ~= defaultConfig.user.password do
  75. rectangle(22, 10, 30, 1, 1)
  76. term.setCursorPos(22, 10)
  77. p = read("*")
  78. end
  79. confirmPassword = confirmPassword .. "Hidden"
  80. elseif step == 3 then
  81. local c = 2
  82. local r = true
  83. while r do
  84. nicePrint("<Next>", 20, 11, 2^c, 1)
  85. nicePrint(" OK ", 26, 11, 2048, 1)
  86. e = {os.pullEvent()}
  87. if e[1] == "mouse_click" then
  88. if e[4] == 11 then
  89. if e[3] >= 20 and e[3] <= 25 then
  90. if c + 1 < 14 then
  91. c = c + 1
  92. else
  93. c = 2
  94. end
  95. elseif e[3] >= 26 and e[3] <= 30 then
  96. defaultConfig.desktop.background = c
  97. bgColor = bgColor .. "Chosen"
  98. r = false
  99. end
  100. end
  101. end
  102. end
  103. end
  104. step = step + 1
  105. elseif step == 4 then
  106. nicePrint(" Done ", w - 9, h - 2, 2048, 1)
  107. e = {os.pullEvent()}
  108. if e[1] == "mouse_click" and e[3] >= w - 9 and e[3] <= w - 1 and e[4] == h - 2 then
  109. local f = fs.open("/os/config.cfg", "w")
  110. f.write("return " .. textutils.serialize(defaultConfig))
  111. step = 5
  112. end
  113. elseif step == 5 then
  114. nicePrint(" Rebooting ", w - 11, h - 2, 512, 1)
  115. sleep(2)
  116. os.reboot()
  117. end
  118. end
  119. end
  120.  
  121. function desktop()
  122. local i = 0
  123. while true do
  124. rectangle(0, 0, w, h, 1)
  125. centerPrint("BeraudOS is loading (" .. i .. " %) ...", h / 2, 1, 32768)
  126. sleep(2)
  127. if i + 1 == 100 then
  128. i = 0
  129. else
  130. i = i + 1
  131. end
  132. end
  133. end
  134.  
  135. function init()
  136. rectangle(0, 0, w, h, 128)
  137. sleep(0.1)
  138. rectangle(0, 0, w, h, 256)
  139. sleep(0.1)
  140. rectangle(0, 0, w, h, 1)
  141. local boot = true
  142. local timer = os.startTimer(2)
  143. while boot do
  144. e = {os.pullEvent()}
  145. if e[1] == "timer" then
  146. boot = false
  147. desktop()
  148. elseif e[1] == "key" and e[2] == keys.c then
  149. boot = false
  150. os.cancelTimer(timer)
  151. term.setBackgroundColor(32768)
  152. term.clear()
  153. term.setTextColor(1)
  154. term.setCursorPos(1, 1)
  155. shell.run("shell")
  156. end
  157. end
  158. end
  159.  
  160. if fs.exists("/os/config.cfg") then
  161. params = dofile("/os/config.cfg")
  162. init()
  163. else
  164. setup()
  165. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement