LolzPB

settings

Jun 11th, 2020
1,357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.82 KB | None | 0 0
  1. settings = {}
  2.  
  3. colortab = {2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768}
  4.  
  5. function loadSettings()
  6.   file = fs.open("/.settings", "r")
  7.   settings = textutils.unserialize(file.readAll())
  8.   file.close()
  9. end
  10.  
  11. function pickColor()
  12.   w, h = term.getSize()
  13.   colreg = {}
  14.   term.setBackgroundColor(colors.white)
  15.   term.clear()
  16.   term.setCursorPos(1, 1)
  17.   term.setTextColor(colors.black)
  18.   term.write("<")
  19.   term.setCursorPos(2, 2)
  20.   term.write("Scegli un colore: ")
  21.   term.setCursorPos((w/2)-((#colortab*3)/2), 4)
  22.   for i, k in pairs(colortab) do
  23.     term.setBackgroundColor(k)
  24.     x, y = term.getCursorPos()
  25.     colreg[tostring(x).." "..tostring(y)] = k
  26.     colreg[tostring(x+1).." "..tostring(y)] = k
  27.     colreg[tostring(x+2).." "..tostring(y)] = k
  28.     if k ~= colors.white then
  29.       term.write("   ")
  30.     else
  31.       term.setTextColor(colors.gray)
  32.       term.write("BIA")
  33.     end
  34.   end
  35.   while true do
  36.     _, bt, x, y = os.pullEvent("mouse_click")
  37.     if bt == 1 and x == 1 and y == 1 then
  38.       return nil
  39.     elseif bt == 1 and colreg[tostring(x).." "..tostring(y)] ~= nil then
  40.       return colreg[tostring(x).." "..tostring(y)]
  41.     end
  42.   end
  43. end
  44.  
  45.  
  46. function drawSettings()
  47.   w, h = term.getSize()
  48.   term.setBackgroundColor(colors.white)
  49.   term.clear()
  50.   term.setCursorPos(51, 1)
  51.   term.setBackgroundColor(colors.red)
  52.   term.setTextColor(colors.black)
  53.   term.write("X")
  54.   term.setBackgroundColor(colors.white)
  55.   term.setCursorPos((w/2)-(#"Impostazioni"/2), 1)
  56.   term.write("Impostazioni")
  57.   term.setCursorPos(2, 3)
  58.   term.write("Colore di sfondo: ")
  59.   term.setBackgroundColor(settings["background"])
  60.   term.write("  ")
  61.   term.setBackgroundColor(colors.white)
  62.   term.setCursorPos(2, 5)
  63.   term.write("Cancellare i file a sessione terminata: ")
  64.   if settings["live"] then
  65.     term.setBackgroundColor(colors.lime)
  66.     term.write(" ")
  67.     term.setBackgroundColor(colors.lightGray)
  68.     term.write(" ")
  69.   else
  70.     term.setBackgroundColor(colors.lightGray)
  71.     term.write(" ")
  72.     term.setBackgroundColor(colors.red)
  73.     term.write(" ")
  74.   end
  75. end
  76.  
  77. loadSettings()
  78.  
  79. while true do
  80.   drawSettings()
  81.   _, bt, x, y = os.pullEvent("mouse_click")
  82.   if bt == 1 and x == 51 and y == 1 then
  83.     term.setBackgroundColor(colors.black)
  84.     term.clear()
  85.     term.setCursorPos(1, 1)
  86.     break
  87.   elseif bt == 1 and x >= 20 and x <= 21 and y == 3 then
  88.     color = pickColor()
  89.     if color ~= nil then
  90.       settings["background"] = color
  91.       file = fs.open("/.settings", "w")
  92.       file.write(textutils.serialize(settings))
  93.       file.close()
  94.     end    
  95.   elseif bt == 1 and x >= 42 and x <= 43 and y == 5 then
  96.     settings["live"] = not settings["live"]
  97.     file = fs.open("/.settings", "w")
  98.     file.write(textutils.serialize(settings))
  99.     file.close()
  100.   end
  101. end
  102.  
  103. return
Advertisement
Add Comment
Please, Sign In to add comment