Advertisement
TiagoCC

OS/.desktop

Apr 1st, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.63 KB | None | 0 0
  1. -- Loading some variables.
  2. local ChoiceA = 0
  3. h = fs.open("Storage/user","r")
  4. local user = h.readAll()
  5. h.close()
  6. local what = false
  7.  
  8.  
  9. -- Functions
  10. function readd1(num,secret)
  11.  word = nil
  12.  what = true
  13.  term.setCursorBlink(true)
  14.  local times = tonumber(num)
  15.  while true do
  16.    local x, y = term.getCursorPos()
  17.    local event1, param1, param2, param3 = os.pullEvent()
  18.    if event1 == "char" then
  19.     if word == nil then
  20.       word = param1
  21.     else
  22.       word = (word..param1)
  23.     end
  24.      if secret == nil then
  25.        term.write(param1)
  26.      else
  27.        term.write(secret)
  28.      end
  29.      term.setCursorPos(x + 1,y)
  30.      times = times - 1
  31.    elseif event1 == "key" then
  32.     if param1 == 28 then
  33.      break
  34.     end
  35.     if (param1 == 14) and (string.len(word) > 0) then
  36.       word = string.sub(word,1,-2)
  37.       term.setCursorPos(x - 1,y)
  38.       term.write(" ")
  39.       term.setCursorPos(x - 1,y)
  40.       times = times + 1
  41.     end
  42.    elseif event1 == "mouse_click" then
  43.     if param1 == 1 then
  44.      if (param2 == 51) and (param3 == 1) then
  45.       MenuB = 0
  46.       term.setCursorBlink(false)
  47.       shell.run("OS/.desktop")
  48.      elseif not ((param2 > 12 and param2 < 23) and (param3 == 3)) then
  49.        break
  50.      end
  51.     end
  52.    end
  53.    if times == 0 then
  54.      break
  55.    end      
  56.  end
  57.  term.setCursorBlink(false)
  58.  return word,succes
  59. end
  60.  
  61.  
  62. function readd2(num,secret)
  63.  what = false
  64.  term.setCursorBlink(true)
  65.  local times = tonumber(num)
  66.  while true do
  67.    local x, y = term.getCursorPos()
  68.    local event1, param1, param2, param3 = os.pullEvent()
  69.    if event1 == "char" then
  70.     if word == nil then
  71.       word = param1
  72.     else
  73.       word = (word..param1)
  74.     end
  75.      if secret == nil then
  76.        term.write(param1)
  77.      else
  78.        term.write(secret)
  79.      end
  80.      term.setCursorPos(x + 1,y)
  81.      times = times - 1
  82.    elseif event1 == "key" then
  83.     if param1 == 28 then
  84.      break
  85.     end
  86.     if (param1 == 14) and (string.len(word) > 0) then
  87.       word = string.sub(word,1,-2)
  88.       term.setCursorPos(x - 1,y)
  89.       term.write(" ")
  90.       term.setCursorPos(x - 1,y)
  91.       times = times + 1
  92.     end
  93.    elseif event1 == "mouse_click" then
  94.     if param1 == 1 then
  95.      if (param2 == 51) and (param3 == 1) then
  96.       MenuB = 0
  97.       term.setCursorBlink(false)
  98.       shell.run("OS/.desktop")
  99.      elseif (param2 > 12 and param2 < 23) and (param3 == 3) then
  100.        term.setCursorPos(13,4)
  101.        term.write("          ")
  102.        term.setCursorPos(13,3)
  103.        what = false
  104.        word,what = readd1(10)
  105.        break
  106.      end
  107.     end
  108.    end
  109.    if times == 0 then
  110.      break
  111.    end      
  112.   end
  113.  term.setCursorBlink(false)
  114.  return word,what
  115. end
  116.  
  117.  
  118. function drawinterface1()
  119. term.setBackgroundColor(colors.lightBlue)
  120. term.clear()
  121. term.setCursorPos(1,1)
  122. if fs.exists("Storage/Accounts/"..user.."/.paint/.editBG") then
  123.   EditBG = paintutils.loadImage("Storage/Accounts/" ..user.."/.paint/.editBG")
  124.   paintutils.drawImage(EditBG, 1, 1)
  125. else
  126.   BaseBG = paintutils.loadImage("Storage/.paint/.baseBG")
  127.   paintutils.drawImage(BaseBG, 1, 1)
  128. end
  129. term.setCursorPos(47,1)
  130. term.setBackgroundColor(colors.red)
  131. term.setTextColor(colors.white)
  132.  
  133. term.write(" Edit")
  134. term.setCursorPos(1,19)
  135. term.setBackgroundColor(colors.yellow)
  136. term.clearLine()
  137. term.setBackgroundColor(colors.red)
  138. term.setTextColor(colors.white)
  139. term.write("Menu")
  140. term.setCursorPos(1,1)
  141. end
  142.  
  143.  
  144. function drawmenu1()
  145.   term.setBackgroundColor(colors.lightGray)
  146.  
  147.   term.setCursorPos(1,15)
  148.   term.setTextColor(colors.gray)
  149.   term.write("Settings")
  150.  
  151.   term.setCursorPos(1,16)
  152.   term.setTextColor(colors.gray)
  153.   term.write("Programs")
  154.  
  155.   term.setCursorPos(1,17)
  156.   term.setTextColor(colors.gray)
  157.   term.write("Reboot  ")
  158.  
  159.   term.setCursorPos(1,18)
  160.   term.setTextColor(colors.gray)
  161.   term.write("Close   ")
  162. end
  163.  
  164.  
  165. function drawSettings1()
  166. term.setBackgroundColor(colors.lightBlue)
  167. term.clear()
  168. paintutils.drawBox(1, 1, 51, 19, colors.yellow)
  169. term.setBackgroundColor(colors.yellow)
  170. term.setTextColor(colors.green)
  171. term.setCursorPos(1,1)
  172. term.write("Settings")
  173. term.setBackgroundColor(colors.red)
  174. term.setTextColor(colors.white)
  175. term.setCursorPos(51,1)
  176. term.write("X")
  177. term.setBackgroundColor(colors.lightBlue)
  178. term.setTextColor(colors.cyan)
  179. term.setCursorPos(3,3)
  180. term.write("Username:")
  181. term.setCursorPos(13,3)
  182. term.setBackgroundColor(colors.white)
  183. term.write("          ")
  184. term.setBackgroundColor(colors.lightBlue)
  185. term.setCursorPos(3,4)
  186. term.write("Password:")
  187. term.setBackgroundColor(colors.white)
  188. term.setCursorPos(13,4)
  189. term.write("          ")
  190. end
  191.  
  192.  
  193. -- Creating the interface.
  194. drawinterface1()  
  195. if MenuB == 1 then
  196.   drawmenu1()
  197. end
  198.  
  199. local function checkevents()
  200. -- Handling the events.
  201. while true do
  202. local event, button, x, y = os.pullEvent("mouse_click")
  203. if button == 1 then
  204.   if (x == 1 or x == 2 or x == 3 or x == 4) and (y == 19) then
  205.     MenuB = 1
  206.     drawmenu1()
  207.   end
  208.   if (x > 0 and x < 9) and (MenuB == 1) and (y < 19 and y > 14) then
  209.     if (y == 18) and (x < 9) then
  210.       ChoiceA = 2
  211.       break
  212.     elseif (y == 17) and (x < 9) then
  213.       ChoiceA = 3
  214.       break
  215.     elseif (y == 16) and (x < 9) then
  216.       ChoiceA = 4
  217.       break
  218.     elseif (y == 15) and (x < 9) then
  219.       ChoiceA = 5
  220.       drawSettings1()
  221.       break
  222.     end
  223.   end
  224.   if (ChoiceA ~= 5) and (x == 47 or x == 48 or x == 49 or x == 50 or x == 51) and (y == 1) then
  225.     ChoiceA = 1
  226.     break
  227.   end
  228. end
  229. end
  230.  
  231.  
  232. -- Outcome for the events.
  233. if ChoiceA == 1 then
  234.   MenuB = 0
  235.   shell.run("paint","Storage/Accounts/"..user.. "/.paint/.editBG")
  236.   shell.run("OS/.desktop")
  237.  
  238. elseif ChoiceA == 2 then
  239.   MenuB = 0
  240.   shell.run("OS/.desktop")
  241.   term.clear()
  242.   sleep(3)
  243.  
  244. elseif ChoiceA == 3 then
  245.   MenuB = 0
  246.   os.reboot()
  247.  
  248. elseif ChoiceA == 4 then
  249.   MenuB = 0
  250.   shell.run("OS/.programmefinder")
  251.   shell.run("OS/.desktop")
  252. elseif ChoiceA == 5 then
  253.   drawSettings1()
  254.  while true do
  255.    drawSettings1()
  256.    local event, button, x, y = os.pullEvent("mouse_click")
  257.   if button == 1 then
  258.    if (x > 12 and x < 23) and (y == 3) then
  259.      term.setBackgroundColor(colors.pink)
  260.      term.setCursorPos(13,3)
  261.      local newUsername,succes = readd1(10)
  262.     if newUsername ~= nil then
  263.      if succes == true then
  264.        shell.run("rename","Storage/Accounts/"..user,"Storage/Accounts/"..newUsername)
  265.        local h = fs.open("Storage/user","w")
  266.        h.write(newUsername)
  267.        h.close()
  268.      end
  269.     end
  270.      term.setCursorPos(3,2)
  271.      term.setBackgroundColor(colors.white)
  272.      term.setTextColor(colors.lime)
  273.     if succes == true then
  274.       term.write("Succesfully changed to: "..newUsername)
  275.     end
  276.      sleep(1)
  277.      drawSettings1()
  278.    elseif (x > 12 and x < 23) and (y == 4) then                
  279.      term.setBackgroundColor(colors.pink)
  280.      term.setCursorPos(13,4)
  281.      local newPassword,what = readd2(10,"*")
  282.     if what == true then
  283.       shell.run("rename","Storage/Accounts/"..user,"Storage/Accounts/"..newPassword)
  284.       local h = fs.open("Storage/user","w")
  285.       h.write(newPassword)
  286.       h.close()
  287.     end
  288.     if what == false then
  289.       local h =
  290.      fs.open("Storage/Accounts/"..user.."/password","w")
  291.      h.write(newPassword)
  292.      h.close()
  293.     end
  294.      term.setCursorPos(3,2)
  295.      term.setBackgroundColor(colors.white)
  296.      term.setTextColor(colors.lime)
  297.      if what == false then
  298.        term.write("Succesfully changed password!")
  299.      end
  300.      if what == true then
  301.        term.write("Succesfully changed to: " .. (newPassword))
  302.      end
  303.      sleep(1)
  304.      drawSettings1()
  305.    elseif (x == 51) and (y == 1) then
  306.      MenuB = 0
  307.      shell.run("OS/.desktop")
  308.    end
  309.   end
  310.  end
  311. end
  312. end
  313.  
  314. checkevents()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement