Miki_Tellurium

notepad-settings

Jan 2nd, 2023 (edited)
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 15.29 KB | Gaming | 0 0
  1. -- Settings application for notepad by Miki_Tellurium
  2. -- Version: 1.0.0
  3. local buttonLibrary = require("button")
  4. local settingLibrary = require("notepadsettings")
  5. local textLibrary = require("text")
  6.  
  7. settings.load("notepad.settings")
  8. local showCredits = true
  9. --Buttons definitions
  10. local HeaderSetting = button:new()
  11. HeaderSetting:setLabel("Header text")
  12. HeaderSetting:setBackgroundColor(colors.white)
  13. HeaderSetting:setTextColor(colors.black)
  14. HeaderSetting:setLocation(1, 3)
  15.  
  16. local HeaderColorSetting = button:new()
  17. HeaderColorSetting:setLabel("Header color")
  18. HeaderColorSetting:setBackgroundColor(settings.get("HeaderColor"))
  19. HeaderColorSetting:setTextColor(colors.black)
  20. HeaderColorSetting:setLocation(15, 3)
  21.  
  22. local IngameTitleSetting1 = button:new()
  23. IngameTitleSetting1:setLabel("Ingame info")
  24. IngameTitleSetting1:setBackgroundColor(settings.get("IngameInfoTitleColor"))
  25. IngameTitleSetting1:setTextColor(colors.black)
  26. IngameTitleSetting1:setLocation(1, 6)
  27. local IngameTitleSetting2 = button:new()
  28. IngameTitleSetting2:setLabel("title color")
  29. IngameTitleSetting2:setBackgroundColor(settings.get("IngameInfoTitleColor"))
  30. IngameTitleSetting2:setTextColor(colors.black)
  31. IngameTitleSetting2:setLocation(1, 7)
  32.  
  33. local IngameInfoSetting1 = button:new()
  34. IngameInfoSetting1:setLabel("Ingame info")
  35. IngameInfoSetting1:setBackgroundColor(settings.get("IngameInfoColor"))
  36. IngameInfoSetting1:setTextColor(colors.black)
  37. IngameInfoSetting1:setLocation(15, 6)
  38. local IngameInfoSetting2 = button:new()
  39. IngameInfoSetting2:setLabel("color")
  40. IngameInfoSetting2:setBackgroundColor(settings.get("IngameInfoColor"))
  41. IngameInfoSetting2:setTextColor(colors.black)
  42. IngameInfoSetting2:setWidth(11)
  43. IngameInfoSetting2:setLocation(15, 7)
  44.  
  45. local IrlTitleSetting1 = button:new()
  46. IrlTitleSetting1:setLabel("Irl info")
  47. IrlTitleSetting1:setBackgroundColor(settings.get("IrlInfoTitleColor"))
  48. IrlTitleSetting1:setTextColor(colors.black)
  49. IrlTitleSetting1:setWidth(11)
  50. IrlTitleSetting1:setLocation(1, 10)
  51. local IrlTitleSetting2 = button:new()
  52. IrlTitleSetting2:setLabel("title color")
  53. IrlTitleSetting2:setBackgroundColor(settings.get("IrlInfoTitleColor"))
  54. IrlTitleSetting2:setTextColor(colors.black)
  55. IrlTitleSetting2:setLocation(1, 11)
  56.  
  57. local IrlInfoSetting1 = button:new()
  58. IrlInfoSetting1:setLabel("Irl info")
  59. IrlInfoSetting1:setBackgroundColor(settings.get("IrlInfoColor"))
  60. IrlInfoSetting1:setTextColor(colors.black)
  61. IrlInfoSetting1:setLocation(15, 10)
  62. local IrlInfoSetting2 = button:new()
  63. IrlInfoSetting2:setLabel("color")
  64. IrlInfoSetting2:setBackgroundColor(settings.get("IrlInfoColor"))
  65. IrlInfoSetting2:setTextColor(colors.black)
  66. IrlInfoSetting2:setWidth(8)
  67. IrlInfoSetting2:setLocation(15, 11)
  68.  
  69. local ItalyFlagSetting = button:new()
  70. ItalyFlagSetting:setLabel("Italy flag")
  71. ItalyFlagSetting:setBackgroundColor(colors.blue)
  72. ItalyFlagSetting:setTextColor(colors.black)
  73. ItalyFlagSetting:setLocation(1, 14)
  74.  
  75. local creditButton = button:new()
  76. creditButton:setLabel("Credits")
  77. creditButton:setBackgroundColor(colors.magenta)
  78. creditButton:setTextColor(colors.black)
  79. creditButton:setLocation(1, 18)
  80.  
  81. local exit = button:new()
  82. exit:setLabel("X")
  83. exit:setBackgroundColor(colors.red)
  84. exit:setTextColor(colors.black)
  85. exit:setLocation(26, 1)
  86.  
  87. -- Draw main screen
  88. local function mainScreen()
  89.     term.setBackgroundColor(colors.black)
  90.     term.clear()
  91.     term.setCursorPos(1, 1)
  92.     print("Notepad settings:")
  93.     exit:paint()
  94.     HeaderSetting:paint()
  95.     HeaderColorSetting:setBackgroundColor(settings.get("HeaderColor"))
  96.     HeaderColorSetting:paint()
  97.     IngameTitleSetting1:setBackgroundColor(settings.get("IngameInfoTitleColor"))
  98.     IngameTitleSetting1:paint()
  99.     IngameTitleSetting2:setBackgroundColor(settings.get("IngameInfoTitleColor"))
  100.     IngameTitleSetting2:paint()
  101.     IngameInfoSetting1:setBackgroundColor(settings.get("IngameInfoColor"))
  102.     IngameInfoSetting1:paint()
  103.     IngameInfoSetting2:setBackgroundColor(settings.get("IngameInfoColor"))
  104.     IngameInfoSetting2:paint()
  105.     IrlTitleSetting1:setBackgroundColor(settings.get("IrlInfoTitleColor"))
  106.     IrlTitleSetting1:paint()
  107.     IrlTitleSetting2:setBackgroundColor(settings.get("IrlInfoTitleColor"))
  108.     IrlTitleSetting2:paint()
  109.     IrlInfoSetting1:setBackgroundColor(settings.get("IrlInfoColor"))
  110.     IrlInfoSetting1:paint()
  111.     IrlInfoSetting2:setBackgroundColor(settings.get("IrlInfoColor"))
  112.     IrlInfoSetting2:paint()
  113.     ItalyFlagSetting:paint()
  114.     creditButton:paint()
  115.     if showCredits then
  116.         term.setCursorPos(1, 20)
  117.         term.clearLine()
  118.     else
  119.         text.print("Made by ", 1, 20, colors.lightBlue)
  120.         text.print("Miki Tellurium", 9, 20, colors.blue)
  121.     end
  122. end
  123. -- Change the header text
  124. local function changeHeaderText()
  125.     term.clear()
  126.     term.setCursorPos(1, 1)
  127.     print("Old header text:")
  128.     print(settings.get("HeaderText"))
  129.     print()
  130.     print("Write the new text:")
  131.     write(">")
  132.     -- Read the user input and update the header
  133.     local function readImput()
  134.         text = read()
  135.         if #text > 20 then
  136.             term.setCursorPos(1, 7)
  137.             printError("Text too long! Can't be more than 20 characters.")
  138.             sleep(2)
  139.             changeHeaderText()
  140.         else
  141.             notepadsettings.update("HeaderText", text)
  142.             term.setCursorPos(1, 8)
  143.             print("Settings updated!")
  144.             sleep(1)
  145.         end
  146.     end
  147.     -- Go back to main screen
  148.     local function exit()
  149.         local cancel = button:new()
  150.         cancel:setLabel("X")
  151.         cancel:setBackgroundColor(colors.red)
  152.         cancel:setTextColor(colors.black)
  153.         cancel:setLocation(26, 1)
  154.         cancel:paint()
  155.         while true do
  156.             local event = {os.pullEvent("mouse_click")}
  157.             if cancel:waitForClick(event) then
  158.                 return
  159.             end
  160.         end
  161.     end
  162.  
  163.     parallel.waitForAny(readImput, exit)
  164.     term.setCursorBlink(false)
  165. end
  166. -- Change color of a element
  167. local function selectColorScreen(setting)
  168.     local white = button:new()
  169.     white:setLabel("White")
  170.     white:setBackgroundColor(colors.white)
  171.     white:setTextColor(colors.black)
  172.     white:setLocation(1, 3)
  173.     local orange = button:new()
  174.     orange:setLabel("Orange")
  175.     orange:setBackgroundColor(colors.orange)
  176.     orange:setTextColor(colors.black)
  177.     orange:setLocation(9, 3)
  178.     local magenta = button:new()
  179.     magenta:setLabel("Magenta")
  180.     magenta:setBackgroundColor(colors.magenta)
  181.     magenta:setTextColor(colors.black)
  182.     magenta:setLocation(17, 3)
  183.     local lightBlue = button:new()
  184.     lightBlue:setLabel("Light Blue")
  185.     lightBlue:setBackgroundColor(colors.lightBlue)
  186.     lightBlue:setTextColor(colors.black)
  187.     lightBlue:setLocation(1, 5)
  188.     local yellow = button:new()
  189.     yellow:setLabel("Yellow")
  190.     yellow:setBackgroundColor(colors.yellow)
  191.     yellow:setTextColor(colors.black)
  192.     yellow:setLocation(13, 5)
  193.     local lime = button:new()
  194.     lime:setLabel("Lime")
  195.     lime:setBackgroundColor(colors.lime)
  196.     lime:setTextColor(colors.black)
  197.     lime:setLocation(21, 5)
  198.     local pink = button:new()
  199.     pink:setLabel("Pink")
  200.     pink:setBackgroundColor(colors.pink)
  201.     pink:setTextColor(colors.black)
  202.     pink:setLocation(1, 7)
  203.     local gray = button:new()
  204.     gray:setLabel("Gray")
  205.     gray:setBackgroundColor(colors.gray)
  206.     gray:setTextColor(colors.black)
  207.     gray:setLocation(8, 7)
  208.     local lightGray = button:new()
  209.     lightGray:setLabel("Light Gray")
  210.     lightGray:setBackgroundColor(colors.lightGray)
  211.     lightGray:setTextColor(colors.black)
  212.     lightGray:setLocation(15, 7)
  213.     local cyan = button:new()
  214.     cyan:setLabel("Cyan")
  215.     cyan:setBackgroundColor(colors.cyan)
  216.     cyan:setTextColor(colors.black)
  217.     cyan:setLocation(1, 9)
  218.     local purple = button:new()
  219.     purple:setLabel("Purple")
  220.     purple:setBackgroundColor(colors.purple)
  221.     purple:setTextColor(colors.black)
  222.     purple:setLocation(8, 9)
  223.     local blue = button:new()
  224.     blue:setLabel("Blue")
  225.     blue:setBackgroundColor(colors.blue)
  226.     blue:setTextColor(colors.black)
  227.     blue:setLocation(16, 9)
  228.     local brown = button:new()
  229.     brown:setLabel("Brown")
  230.     brown:setBackgroundColor(colors.brown)
  231.     brown:setTextColor(colors.black)
  232.     brown:setLocation(1, 11)
  233.     local green = button:new()
  234.     green:setLabel("Green")
  235.     green:setBackgroundColor(colors.green)
  236.     green:setTextColor(colors.black)
  237.     green:setLocation(9, 11)
  238.     local red = button:new()
  239.     red:setLabel("Red")
  240.     red:setBackgroundColor(colors.red)
  241.     red:setTextColor(colors.black)
  242.     red:setLocation(17, 11)
  243.  
  244.     term.clear()
  245.     term.setCursorPos(1, 1)
  246.     print("Select the new color:")
  247.     -- Get what color is clicked and change setting
  248.     local function getColorInput()
  249.         local function updateMessage()
  250.             term.setCursorPos(1, 14)
  251.             print("Settings updated!")
  252.             sleep(1)
  253.         end
  254.         white:paint()
  255.         orange:paint()
  256.         magenta:paint()
  257.         lightBlue:paint()
  258.         yellow:paint()
  259.         lime:paint()
  260.         pink:paint()
  261.         gray:paint()
  262.         lightGray:paint()
  263.         cyan:paint()
  264.         purple:paint()
  265.         blue:paint()
  266.         brown:paint()
  267.         green:paint()
  268.         red:paint()
  269.         while true do
  270.             local event = {os.pullEvent("mouse_click")}
  271.             if white:waitForClick(event) then
  272.                 notepadsettings.update(setting, colors.white)
  273.                 updateMessage()
  274.                 return
  275.             elseif orange:waitForClick(event) then
  276.                 notepadsettings.update(setting, colors.orange)
  277.                 updateMessage()
  278.                 return
  279.             elseif magenta:waitForClick(event) then
  280.                 notepadsettings.update(setting, colors.magenta)
  281.                 updateMessage()
  282.                 return
  283.             elseif lightBlue:waitForClick(event) then
  284.                 notepadsettings.update(setting, colors.lightBlue)
  285.                 updateMessage()
  286.                 return
  287.             elseif yellow:waitForClick(event) then
  288.                 notepadsettings.update(setting, colors.yellow)
  289.                 updateMessage()
  290.                 return
  291.             elseif lime:waitForClick(event) then
  292.                 notepadsettings.update(setting, colors.lime)
  293.                 updateMessage()
  294.                 return
  295.             elseif pink:waitForClick(event) then
  296.                 notepadsettings.update(setting, colors.pink)
  297.                 updateMessage()
  298.                 return
  299.             elseif gray:waitForClick(event) then
  300.                 notepadsettings.update(setting, colors.gray)
  301.                 updateMessage()
  302.                 return
  303.             elseif lightGray:waitForClick(event) then
  304.                 notepadsettings.update(setting, colors.lightGray)
  305.                 updateMessage()
  306.                 return
  307.             elseif cyan:waitForClick(event) then
  308.                 notepadsettings.update(setting, colors.cyan)
  309.                 updateMessage()
  310.                 return
  311.             elseif purple:waitForClick(event) then
  312.                 notepadsettings.update(setting, colors.purple)
  313.                 updateMessage()
  314.                 return
  315.             elseif blue:waitForClick(event) then
  316.                 notepadsettings.update(setting, colors.blue)
  317.                 updateMessage()
  318.                 return
  319.             elseif brown:waitForClick(event) then
  320.                 notepadsettings.update(setting, colors.brown)
  321.                 updateMessage()
  322.                 return
  323.             elseif green:waitForClick(event) then
  324.                 notepadsettings.update(setting, colors.green)
  325.                 updateMessage()
  326.                 return
  327.             elseif red:waitForClick(event) then
  328.                 notepadsettings.update(setting, colors.red)
  329.                 updateMessage()
  330.                 return
  331.             end
  332.         end
  333.     end
  334.     -- Go back to main screen
  335.     local function exit()
  336.         local cancel = button:new()
  337.         cancel:setLabel("X")
  338.         cancel:setBackgroundColor(colors.red)
  339.         cancel:setTextColor(colors.black)
  340.         cancel:setLocation(26, 1)
  341.         cancel:paint()
  342.         while true do
  343.             local event = {os.pullEvent("mouse_click")}
  344.             if cancel:waitForClick(event) then
  345.                 return
  346.             end
  347.         end
  348.     end
  349.  
  350.     parallel.waitForAny(getColorInput, exit)
  351. end
  352. -- Choose if show Italy flag in notepad
  353. local function enableItalyFlagScreen()
  354.     term.clear()
  355.     term.setCursorPos(1, 1)
  356.     print("Should the italy flag be displayed on main screen?")
  357.     -- Update the setting
  358.     local function yesOrNo()
  359.         local yes = button:new()
  360.         yes:setLabel("Yes")
  361.         yes:setBackgroundColor(colors.green)
  362.         yes:setTextColor(colors.black)
  363.         yes:setLocation(8, 4)
  364.         local no = button:new()
  365.         no:setLabel("No")
  366.         no:setBackgroundColor(colors.red)
  367.         no:setTextColor(colors.black)
  368.         no:setLocation(16, 4)
  369.  
  370.         yes:paint()
  371.         no:paint()
  372.         while true do
  373.             local event = {os.pullEvent("mouse_click")}
  374.             if yes:waitForClick(event) then
  375.                 notepadsettings.update("ItalyFlag", true)
  376.                 term.setCursorPos(1, 7)
  377.                 print("Settings updated!")
  378.                 sleep(1)
  379.                 return
  380.             elseif no:waitForClick(event) then
  381.                 notepadsettings.update("ItalyFlag", false)
  382.                 term.setCursorPos(1, 7)
  383.                 print("Settings updated!")
  384.                 sleep(1)
  385.                 return
  386.             end
  387.         end
  388.     end
  389.     -- Go back to main screen
  390.     local function exit()
  391.         local cancel = button:new()
  392.         cancel:setLabel("X")
  393.         cancel:setBackgroundColor(colors.red)
  394.         cancel:setTextColor(colors.black)
  395.         cancel:setLocation(26, 1)
  396.         cancel:paint()
  397.         while true do
  398.             local event = {os.pullEvent("mouse_click")}
  399.             if cancel:waitForClick(event) then
  400.                 return
  401.             end
  402.         end
  403.     end
  404.  
  405.     parallel.waitForAny(yesOrNo, exit)
  406. end
  407. -- Perform different action based on button clicked
  408. local function buttonAction()
  409.     local event = {os.pullEvent("mouse_click")}
  410.     if HeaderSetting:waitForClick(event) then
  411.         changeHeaderText()
  412.     elseif HeaderColorSetting:waitForClick(event) then
  413.         selectColorScreen("HeaderColor")
  414.     elseif IngameTitleSetting1:waitForClick(event) or IngameTitleSetting2:waitForClick(event) then
  415.         selectColorScreen("IngameInfoTitleColor")
  416.     elseif IngameInfoSetting1:waitForClick(event) or IngameInfoSetting2:waitForClick(event) then
  417.         selectColorScreen("IngameInfoColor")
  418.     elseif IrlTitleSetting1:waitForClick(event) or IrlTitleSetting2:waitForClick(event) then
  419.         selectColorScreen("IrlInfoTitleColor")
  420.     elseif IrlInfoSetting1:waitForClick(event) or IrlInfoSetting2:waitForClick(event) then
  421.         selectColorScreen("IrlInfoColor")
  422.     elseif ItalyFlagSetting:waitForClick(event) then
  423.         enableItalyFlagScreen()
  424.     elseif creditButton:waitForClick(event) then
  425.         if showCredits then
  426.             showCredits = false
  427.         else
  428.             showCredits = true
  429.         end
  430.     elseif exit:waitForClick(event) then
  431.         os.reboot()
  432.     end
  433. end
  434.  
  435. -- Run the program
  436. while true do
  437.     mainScreen()
  438.     buttonAction()
  439. end
Advertisement
Add Comment
Please, Sign In to add comment