Advertisement
CaptainSpaceCat

settings

May 17th, 2015
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.96 KB | None | 0 0
  1. w, h = term.getSize()
  2. os.loadAPI("iosvars")
  3. function initialize()
  4.   term.setBackgroundColor(colors.lightGray)
  5.   term.clear()
  6.   iosutils.centerAlign("System Settings", 1, colors.gray, colors.lightGray)
  7.   iosutils.leftAlign("Background Color", 3)
  8.   iosutils.leftAlign("Wi-Fi", 6)
  9.   iosutils.leftAlign("Computer Label", 9)
  10.   iosutils.leftAlign("Run IOS on Startup", 12)
  11.  
  12.   for i = 1, 16 do
  13.     term.setCursorPos(i, 4)
  14.     term.setBackgroundColor(iosutils.colors[i])
  15.     term.write(" ")
  16.   end
  17.  
  18.   iosutils.leftAlign(">", 10, colors.gray, colors.lightGray)
  19.  
  20.   function clickDetect(x, y, x2, y2)
  21.     if select[3] >= x and select[3] <= x2 and select[4] >= y and select[4] <= y2 then
  22.       return true
  23.     else
  24.       return false
  25.     end
  26.   end  
  27. end
  28.  
  29. function changeVars(changeBK, changeWF, changeST)
  30.   oTemp = fs.open("temp", "w")
  31.   for line in io.lines("iosvars") do
  32.     --print(string.sub(line, 0, 16))
  33.     --print(string.sub(line, 0, 5))
  34.     if changeBK and string.sub(line, 0, 15) == "backgroundColor" then
  35.       oTemp.writeLine("backgroundColor = iosutils.colors[" .. tostring(select[3]) .. "]")
  36.     elseif changeWF and string.sub(line, 0, 4) == "wifi" then
  37.       if changeWF == 1 then
  38.         oTemp.writeLine("wifi = true")
  39.       else
  40.         oTemp.writeLine("wifi = false")
  41.       end
  42.     elseif changeST and string.sub(line, 0, 7) == "startup" then
  43.       oTempStartup = fs.open("startuptemp", "w")
  44.       if fs.exists("startup") then
  45.         for ln in io.lines("startup") do
  46.           if string.sub(ln, 0, 16) ~= "shell.run(\"ios\")" then
  47.             oTempStartup.writeLine(ln)
  48.           end
  49.         end
  50.       end
  51.       if changeST == 1 then
  52.         oTemp.writeLine("startup = true")
  53.         oTempStartup.writeLine("shell.run(\"ios\")")
  54.       else
  55.         oTemp.writeLine("startup = false")
  56.       end
  57.       oTempStartup.flush()
  58.       oTempStartup.close()
  59.       if fs.exists("startup") then
  60.         shell.run("delete startup")
  61.       end
  62.       shell.run("copy startuptemp startup")
  63.       shell.run("delete startuptemp")
  64.     else
  65.       oTemp.writeLine(line)
  66.     end
  67.   end
  68.   oTemp.flush()
  69.   oTemp.close()
  70.   shell.run("delete iosvars")
  71.   shell.run("copy temp iosvars")
  72.   shell.run("delete temp")
  73. end
  74.  
  75. select = {}
  76. select[1] = "mouse_click"
  77. select[2] = 1
  78. select[3] = 1
  79. select[4] = 1
  80. initialize()
  81. while true do
  82.   --detect clicks and change vars--
  83.   if clickDetect(1, 4, 16, 4) then
  84.     changeVars(true, false, false)
  85.   end
  86.   if clickDetect(1, 7, 2, 7) then
  87.     --open iosvars and write true
  88.     changeVars(false, 1, false)
  89.   end
  90.   if clickDetect(5, 7, 7, 7) then
  91.     changeVars(false, 0, false)
  92.   end
  93.   if clickDetect(1, 10, 10, 10) then
  94.     term.setCursorPos(2, 10)
  95.     term.setBackgroundColor(colors.lightGray)
  96.     term.setTextColor(colors.gray)
  97.     local label = read()
  98.     --label = string.gsub(label, "\"", "\\\"")
  99.     label = "\"" .. label .. "\""
  100.     shell.run("label set " .. tostring(label))
  101.     initialize()
  102.   end
  103.   if clickDetect(1, 13, 3, 13) then
  104.     changeVars(false, false, 1)
  105.   end
  106.   if clickDetect(6, 13, 7, 13) then
  107.     changeVars(false, false, 0)
  108.   end
  109.   --write page based on vars--
  110.   os.loadAPI("iosvars")
  111.   if iosvars.wifi then
  112.     iosutils.leftAlign("    Off", 7, colors.red, colors.lightGray)
  113.     iosutils.leftAlign("On", 7, colors.green, colors.white)
  114.     rednet.open("back")
  115.   else
  116.     iosutils.leftAlign("    Off", 7, colors.red, colors.white)
  117.     iosutils.leftAlign("On  ", 7, colors.green, colors.lightGray)
  118.     rednet.close("back")
  119.   end
  120.   if iosvars.startup then
  121.     iosutils.leftAlign("     No", 13, colors.red, colors.lightGray)
  122.     iosutils.leftAlign("Yes", 13, colors.green, colors.white)
  123.   else
  124.     iosutils.leftAlign("     No", 13, colors.red, colors.white)
  125.     iosutils.leftAlign("Yes  ", 13, colors.green, colors.lightGray)
  126.   end
  127.   term.setCursorPos(1, 5)
  128.   term.setBackgroundColor(iosvars.backgroundColor)
  129.   for i = 1, 16 do
  130.     term.write(" ")
  131.   end
  132.   select = {os.pullEvent("mouse_click")}
  133. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement