AquaJD

SSE Startup

Feb 2nd, 2017
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.54 KB | None | 0 0
  1. tColors = {
  2.   ["m_bg"] = colors.white,
  3.   ["m_text"] = colors.black,
  4.   ["t_bg"] = colors.blue,
  5.   ["t_text"] = colors.white,
  6.   ["b1_bg"] = colors.green,
  7.   ["b2_bg"] = colors.cyan,
  8.   ["b3_bg"] = colors.orange,
  9.   ["b_text"] = colors.white  
  10. }
  11.  
  12. tButton = {
  13.   ["b1_x"] = 4,
  14.   ["b1_y"] = 6,
  15.   ["b1_w"] = 9,
  16.   ["b1_h"] = 3,
  17.   ["b1_text"] = "Login",
  18.   ["b2_x"] = 4,
  19.   ["b2_y"] = 10,
  20.   ["b2_w"] = 12,
  21.   ["b2_h"] = 3,
  22.   ["b2_text"] = "Register",
  23.   ["b3_x"] = 4,
  24.   ["b3_y"] = 14,
  25.   ["b3_w"] = 12,
  26.   ["b3_h"] = 3,
  27.   ["b3_text"] = "Shutdown",
  28. }
  29.  
  30. function drawBox(x,y,w,h,cb,ct,text)
  31.   term.setBackgroundColor(cb)
  32.   term.setTextColor(ct)
  33.   term.setCursorPos(x,y)
  34.   for i=1,h do
  35.     for i=1,w do
  36.       write(" ")
  37.     end
  38.     term.setCursorPos(x,y+i)
  39.   end
  40.   term.setCursorPos(x+(w/2)-(#text/2),y+(h/2))
  41.   print(text)
  42. end
  43.  
  44. if not fs.exists("/sse/sse_login") or not fs.exists("/sse/sse_register") then
  45.   if not fs.exists("/sse/.users/") then
  46.     if not fs.exists("/sse") then
  47.       error("No installation of SSE found")
  48.     else
  49.       fs.makeDir("/sse/.users")
  50.     end
  51.   else
  52.     error("Installation incomplete (missing Register/Login pages)")
  53.   end
  54. end
  55.  
  56. term.setBackgroundColor(tColors["m_bg"])
  57. term.clear()
  58. term.setCursorPos(1,2)
  59. term.setBackgroundColor(tColors["t_bg"])
  60. term.clearLine()
  61. term.setCursorPos(2,2)
  62. term.setTextColor(tColors["t_text"])
  63. print("Security System Example")
  64.  
  65. drawBox(tButton["b1_x"],tButton["b1_y"],tButton["b1_w"],tButton["b1_h"],tColors["b1_bg"],tColors["b_text"],tButton["b1_text"])
  66. drawBox(tButton["b2_x"],tButton["b2_y"],tButton["b2_w"],tButton["b2_h"],tColors["b2_bg"],tColors["b_text"],tButton["b2_text"])
  67. drawBox(tButton["b3_x"],tButton["b3_y"],tButton["b3_w"],tButton["b3_h"],tColors["b3_bg"],tColors["b_text"],tButton["b3_text"])
  68.  
  69. bRunning = true
  70. while bRunning do
  71.   local event, button, X, Y = os.pullEvent()
  72.   if event == "mouse_click" then
  73.     if button == 1 then
  74.       if X >= tButton["b1_x"] and X <= (tButton["b1_x"] + tButton["b1_w"] - 1) and Y >= tButton["b1_y"] and Y <= (tButton["b1_y"] + tButton["b1_h"] - 1) then
  75.         shell.run("/sse/sse_login")
  76.         bRunning = false
  77.       elseif X >= tButton["b2_x"] and X <= (tButton["b2_x"] + tButton["b2_w"] - 1) and Y >= tButton["b2_y"] and Y <= (tButton["b2_y"] + tButton["b2_h"] - 1) then
  78.         shell.run("/sse/sse_register")
  79.         bRunning = false
  80.       elseif X >= tButton["b3_x"] and X <= (tButton["b3_x"] + tButton["b3_w"] - 1) and Y >= tButton["b3_y"] and Y <= (tButton["b3_y"] + tButton["b3_h"] - 1) then
  81.         os.shutdown()
  82.       end
  83.     end
  84.   end
  85. end
Advertisement
Add Comment
Please, Sign In to add comment