Advertisement
paramus

Options

Jan 25th, 2025 (edited)
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.21 KB | Gaming | 0 0
  1. local lsColors = {colors.white, colors.orange, colors.magenta, colors.lightBlue, colors.yellow, colors.lime, colors.pink, colors.gray, colors.lightGray, colors.cyan, colors.purple, colors.blue, colors.brown, colors.green, colors.red, colors.black}
  2.  
  3. local backColor, appColor, textColor
  4. local iBackColor, iAppColor, iTextColor
  5.  
  6. function GetData()
  7.     if (fs.exists("SysData/options.txt")) then
  8.         file = fs.open("SysData/options.txt", "r")
  9.         backColor = tonumber(file.readLine()) --Background color
  10.         appColor = tonumber(file.readLine()) --App color
  11.         textColor = tonumber(file.readLine()) --Text color
  12.         file.close()
  13.     else
  14.         backColor = colors.cyan --Background color
  15.         appColor = colors.yellow --App color
  16.         textColor = colors.white --Text color
  17.     end
  18.    
  19.     for i=1,#lsColors,1 do
  20.         if (backColor==lsColors[i]) then iBackColor = i+1 end
  21.         if (appColor==lsColors[i]) then iAppColor = i+1 end
  22.         if (textColor==lsColors[i]) then iTextColor = i+1 end
  23.     end
  24. end
  25.  
  26. function SaveData()
  27.     file = fs.open("SysData/options.txt", "w")
  28.     file.writeLine(backColor) --Background color
  29.     file.writeLine(appColor) --App color
  30.     file.writeLine(textColor) --Text color
  31.     file.close()
  32. end
  33.  
  34. function Gui()
  35.     term.setBackgroundColor(backColor)
  36.     term.clear()
  37.     local win = window.create(term.current(),1,1,26,20)
  38.     win.setBackgroundColor(backColor)
  39.     win.clear()
  40.  
  41.     --Title
  42.     paintutils.drawPixel(4,2,backColor)
  43.     term.setCursorPos(4,2)
  44.     term.setTextColor(textColor)
  45.     term.write("-Design Options-")
  46.    
  47.     --Return button
  48.     paintutils.drawPixel(2,2,colors.red)
  49.     term.setCursorPos(2,2)
  50.     term.setTextColor(textColor)
  51.     term.write("x")
  52.    
  53.     --Color pickers
  54.     for i=1,#lsColors,1 do
  55.         paintutils.drawPixel(i+1,5,lsColors[i])
  56.         paintutils.drawPixel(i+1,9,lsColors[i])
  57.         paintutils.drawPixel(i+1,13,lsColors[i])
  58.     end
  59.    
  60.     --Background color Picker
  61.     paintutils.drawPixel(2,4,backColor)
  62.     term.setCursorPos(2,4)
  63.     term.setTextColor(textColor)
  64.     term.write("Background color")
  65.     paintutils.drawPixel(iBackColor,6,backColor)
  66.     term.setCursorPos(iBackColor,6)
  67.     term.setTextColor(textColor)
  68.     term.write("*")
  69.    
  70.     --App color Picker
  71.     paintutils.drawPixel(2,8,backColor)
  72.     term.setCursorPos(2,8)
  73.     term.setTextColor(textColor)
  74.     term.write("App color")
  75.     paintutils.drawPixel(iAppColor,10,backColor)
  76.     term.setCursorPos(iAppColor,10)
  77.     term.setTextColor(textColor)
  78.     term.write("*")
  79.    
  80.     --Text color Picker
  81.     paintutils.drawPixel(2,12,backColor)
  82.     term.setCursorPos(2,12)
  83.     term.setTextColor(textColor)
  84.     term.write("Text color")
  85.     paintutils.drawPixel(iTextColor,14,backColor)
  86.     term.setCursorPos(iTextColor,14)
  87.     term.setTextColor(textColor)
  88.     term.write("*")
  89.    
  90.     --Change peripheral Button
  91.     paintutils.drawPixel(2,17,colors.yellow)
  92.     term.setCursorPos(2,17)
  93.     term.setTextColor(textColor)
  94.     term.write("Change    ")
  95.     term.setCursorPos(2,18)
  96.     term.write("Peripheral")
  97.    
  98.     --Change peripheral Button
  99.     paintutils.drawPixel(13,17,colors.red)
  100.     term.setCursorPos(13,17)
  101.     term.setTextColor(textColor)
  102.     term.write("Unequip   ")
  103.     term.setCursorPos(13,18)
  104.     term.write("Peripheral")
  105. end
  106.  
  107. function Buttons(x,y)
  108.     local i = x-1
  109.    
  110.     if (x == 2 and y == 2) then
  111.         SaveData()
  112.         error("",0)
  113.     elseif (y==5) then
  114.         backColor = lsColors[i]
  115.         iBackColor = x
  116.     elseif (y==9) then
  117.         appColor = lsColors[i]
  118.         iAppColor = x
  119.     elseif (y==13) then
  120.         textColor = lsColors[i]
  121.         iTextColor = x
  122.     elseif (y>=17 and y<=18 and x>=2 and x<=11) then
  123.         pocket.equipBack()
  124.     elseif (y>=17 and y<=18 and x>=13 and x<=22) then
  125.         pocket.unequipBack()
  126.     end
  127. end
  128.  
  129. -- Main --
  130. local click=false
  131. GetData()
  132. while(true) do
  133.     local e,b,x,y
  134.     parallel.waitForAny(
  135.         function()
  136.             Gui()
  137.             sleep(2)
  138.         end,
  139.         function()
  140.             e,b,x,y = os.pullEvent("mouse_click")
  141.             click = true
  142.         end)
  143.    
  144.     if (click == true) then
  145.         click = false
  146.         Buttons(x,y)
  147.     end
  148. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement