Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Settings application for notepad by Miki_Tellurium
- -- Version: 1.0.0
- local buttonLibrary = require("button")
- local settingLibrary = require("notepadsettings")
- local textLibrary = require("text")
- settings.load("notepad.settings")
- local showCredits = true
- --Buttons definitions
- local HeaderSetting = button:new()
- HeaderSetting:setLabel("Header text")
- HeaderSetting:setBackgroundColor(colors.white)
- HeaderSetting:setTextColor(colors.black)
- HeaderSetting:setLocation(1, 3)
- local HeaderColorSetting = button:new()
- HeaderColorSetting:setLabel("Header color")
- HeaderColorSetting:setBackgroundColor(settings.get("HeaderColor"))
- HeaderColorSetting:setTextColor(colors.black)
- HeaderColorSetting:setLocation(15, 3)
- local IngameTitleSetting1 = button:new()
- IngameTitleSetting1:setLabel("Ingame info")
- IngameTitleSetting1:setBackgroundColor(settings.get("IngameInfoTitleColor"))
- IngameTitleSetting1:setTextColor(colors.black)
- IngameTitleSetting1:setLocation(1, 6)
- local IngameTitleSetting2 = button:new()
- IngameTitleSetting2:setLabel("title color")
- IngameTitleSetting2:setBackgroundColor(settings.get("IngameInfoTitleColor"))
- IngameTitleSetting2:setTextColor(colors.black)
- IngameTitleSetting2:setLocation(1, 7)
- local IngameInfoSetting1 = button:new()
- IngameInfoSetting1:setLabel("Ingame info")
- IngameInfoSetting1:setBackgroundColor(settings.get("IngameInfoColor"))
- IngameInfoSetting1:setTextColor(colors.black)
- IngameInfoSetting1:setLocation(15, 6)
- local IngameInfoSetting2 = button:new()
- IngameInfoSetting2:setLabel("color")
- IngameInfoSetting2:setBackgroundColor(settings.get("IngameInfoColor"))
- IngameInfoSetting2:setTextColor(colors.black)
- IngameInfoSetting2:setWidth(11)
- IngameInfoSetting2:setLocation(15, 7)
- local IrlTitleSetting1 = button:new()
- IrlTitleSetting1:setLabel("Irl info")
- IrlTitleSetting1:setBackgroundColor(settings.get("IrlInfoTitleColor"))
- IrlTitleSetting1:setTextColor(colors.black)
- IrlTitleSetting1:setWidth(11)
- IrlTitleSetting1:setLocation(1, 10)
- local IrlTitleSetting2 = button:new()
- IrlTitleSetting2:setLabel("title color")
- IrlTitleSetting2:setBackgroundColor(settings.get("IrlInfoTitleColor"))
- IrlTitleSetting2:setTextColor(colors.black)
- IrlTitleSetting2:setLocation(1, 11)
- local IrlInfoSetting1 = button:new()
- IrlInfoSetting1:setLabel("Irl info")
- IrlInfoSetting1:setBackgroundColor(settings.get("IrlInfoColor"))
- IrlInfoSetting1:setTextColor(colors.black)
- IrlInfoSetting1:setLocation(15, 10)
- local IrlInfoSetting2 = button:new()
- IrlInfoSetting2:setLabel("color")
- IrlInfoSetting2:setBackgroundColor(settings.get("IrlInfoColor"))
- IrlInfoSetting2:setTextColor(colors.black)
- IrlInfoSetting2:setWidth(8)
- IrlInfoSetting2:setLocation(15, 11)
- local ItalyFlagSetting = button:new()
- ItalyFlagSetting:setLabel("Italy flag")
- ItalyFlagSetting:setBackgroundColor(colors.blue)
- ItalyFlagSetting:setTextColor(colors.black)
- ItalyFlagSetting:setLocation(1, 14)
- local creditButton = button:new()
- creditButton:setLabel("Credits")
- creditButton:setBackgroundColor(colors.magenta)
- creditButton:setTextColor(colors.black)
- creditButton:setLocation(1, 18)
- local exit = button:new()
- exit:setLabel("X")
- exit:setBackgroundColor(colors.red)
- exit:setTextColor(colors.black)
- exit:setLocation(26, 1)
- -- Draw main screen
- local function mainScreen()
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setCursorPos(1, 1)
- print("Notepad settings:")
- exit:paint()
- HeaderSetting:paint()
- HeaderColorSetting:setBackgroundColor(settings.get("HeaderColor"))
- HeaderColorSetting:paint()
- IngameTitleSetting1:setBackgroundColor(settings.get("IngameInfoTitleColor"))
- IngameTitleSetting1:paint()
- IngameTitleSetting2:setBackgroundColor(settings.get("IngameInfoTitleColor"))
- IngameTitleSetting2:paint()
- IngameInfoSetting1:setBackgroundColor(settings.get("IngameInfoColor"))
- IngameInfoSetting1:paint()
- IngameInfoSetting2:setBackgroundColor(settings.get("IngameInfoColor"))
- IngameInfoSetting2:paint()
- IrlTitleSetting1:setBackgroundColor(settings.get("IrlInfoTitleColor"))
- IrlTitleSetting1:paint()
- IrlTitleSetting2:setBackgroundColor(settings.get("IrlInfoTitleColor"))
- IrlTitleSetting2:paint()
- IrlInfoSetting1:setBackgroundColor(settings.get("IrlInfoColor"))
- IrlInfoSetting1:paint()
- IrlInfoSetting2:setBackgroundColor(settings.get("IrlInfoColor"))
- IrlInfoSetting2:paint()
- ItalyFlagSetting:paint()
- creditButton:paint()
- if showCredits then
- term.setCursorPos(1, 20)
- term.clearLine()
- else
- text.print("Made by ", 1, 20, colors.lightBlue)
- text.print("Miki Tellurium", 9, 20, colors.blue)
- end
- end
- -- Change the header text
- local function changeHeaderText()
- term.clear()
- term.setCursorPos(1, 1)
- print("Old header text:")
- print(settings.get("HeaderText"))
- print()
- print("Write the new text:")
- write(">")
- -- Read the user input and update the header
- local function readImput()
- text = read()
- if #text > 20 then
- term.setCursorPos(1, 7)
- printError("Text too long! Can't be more than 20 characters.")
- sleep(2)
- changeHeaderText()
- else
- notepadsettings.update("HeaderText", text)
- term.setCursorPos(1, 8)
- print("Settings updated!")
- sleep(1)
- end
- end
- -- Go back to main screen
- local function exit()
- local cancel = button:new()
- cancel:setLabel("X")
- cancel:setBackgroundColor(colors.red)
- cancel:setTextColor(colors.black)
- cancel:setLocation(26, 1)
- cancel:paint()
- while true do
- local event = {os.pullEvent("mouse_click")}
- if cancel:waitForClick(event) then
- return
- end
- end
- end
- parallel.waitForAny(readImput, exit)
- term.setCursorBlink(false)
- end
- -- Change color of a element
- local function selectColorScreen(setting)
- local white = button:new()
- white:setLabel("White")
- white:setBackgroundColor(colors.white)
- white:setTextColor(colors.black)
- white:setLocation(1, 3)
- local orange = button:new()
- orange:setLabel("Orange")
- orange:setBackgroundColor(colors.orange)
- orange:setTextColor(colors.black)
- orange:setLocation(9, 3)
- local magenta = button:new()
- magenta:setLabel("Magenta")
- magenta:setBackgroundColor(colors.magenta)
- magenta:setTextColor(colors.black)
- magenta:setLocation(17, 3)
- local lightBlue = button:new()
- lightBlue:setLabel("Light Blue")
- lightBlue:setBackgroundColor(colors.lightBlue)
- lightBlue:setTextColor(colors.black)
- lightBlue:setLocation(1, 5)
- local yellow = button:new()
- yellow:setLabel("Yellow")
- yellow:setBackgroundColor(colors.yellow)
- yellow:setTextColor(colors.black)
- yellow:setLocation(13, 5)
- local lime = button:new()
- lime:setLabel("Lime")
- lime:setBackgroundColor(colors.lime)
- lime:setTextColor(colors.black)
- lime:setLocation(21, 5)
- local pink = button:new()
- pink:setLabel("Pink")
- pink:setBackgroundColor(colors.pink)
- pink:setTextColor(colors.black)
- pink:setLocation(1, 7)
- local gray = button:new()
- gray:setLabel("Gray")
- gray:setBackgroundColor(colors.gray)
- gray:setTextColor(colors.black)
- gray:setLocation(8, 7)
- local lightGray = button:new()
- lightGray:setLabel("Light Gray")
- lightGray:setBackgroundColor(colors.lightGray)
- lightGray:setTextColor(colors.black)
- lightGray:setLocation(15, 7)
- local cyan = button:new()
- cyan:setLabel("Cyan")
- cyan:setBackgroundColor(colors.cyan)
- cyan:setTextColor(colors.black)
- cyan:setLocation(1, 9)
- local purple = button:new()
- purple:setLabel("Purple")
- purple:setBackgroundColor(colors.purple)
- purple:setTextColor(colors.black)
- purple:setLocation(8, 9)
- local blue = button:new()
- blue:setLabel("Blue")
- blue:setBackgroundColor(colors.blue)
- blue:setTextColor(colors.black)
- blue:setLocation(16, 9)
- local brown = button:new()
- brown:setLabel("Brown")
- brown:setBackgroundColor(colors.brown)
- brown:setTextColor(colors.black)
- brown:setLocation(1, 11)
- local green = button:new()
- green:setLabel("Green")
- green:setBackgroundColor(colors.green)
- green:setTextColor(colors.black)
- green:setLocation(9, 11)
- local red = button:new()
- red:setLabel("Red")
- red:setBackgroundColor(colors.red)
- red:setTextColor(colors.black)
- red:setLocation(17, 11)
- term.clear()
- term.setCursorPos(1, 1)
- print("Select the new color:")
- -- Get what color is clicked and change setting
- local function getColorInput()
- local function updateMessage()
- term.setCursorPos(1, 14)
- print("Settings updated!")
- sleep(1)
- end
- white:paint()
- orange:paint()
- magenta:paint()
- lightBlue:paint()
- yellow:paint()
- lime:paint()
- pink:paint()
- gray:paint()
- lightGray:paint()
- cyan:paint()
- purple:paint()
- blue:paint()
- brown:paint()
- green:paint()
- red:paint()
- while true do
- local event = {os.pullEvent("mouse_click")}
- if white:waitForClick(event) then
- notepadsettings.update(setting, colors.white)
- updateMessage()
- return
- elseif orange:waitForClick(event) then
- notepadsettings.update(setting, colors.orange)
- updateMessage()
- return
- elseif magenta:waitForClick(event) then
- notepadsettings.update(setting, colors.magenta)
- updateMessage()
- return
- elseif lightBlue:waitForClick(event) then
- notepadsettings.update(setting, colors.lightBlue)
- updateMessage()
- return
- elseif yellow:waitForClick(event) then
- notepadsettings.update(setting, colors.yellow)
- updateMessage()
- return
- elseif lime:waitForClick(event) then
- notepadsettings.update(setting, colors.lime)
- updateMessage()
- return
- elseif pink:waitForClick(event) then
- notepadsettings.update(setting, colors.pink)
- updateMessage()
- return
- elseif gray:waitForClick(event) then
- notepadsettings.update(setting, colors.gray)
- updateMessage()
- return
- elseif lightGray:waitForClick(event) then
- notepadsettings.update(setting, colors.lightGray)
- updateMessage()
- return
- elseif cyan:waitForClick(event) then
- notepadsettings.update(setting, colors.cyan)
- updateMessage()
- return
- elseif purple:waitForClick(event) then
- notepadsettings.update(setting, colors.purple)
- updateMessage()
- return
- elseif blue:waitForClick(event) then
- notepadsettings.update(setting, colors.blue)
- updateMessage()
- return
- elseif brown:waitForClick(event) then
- notepadsettings.update(setting, colors.brown)
- updateMessage()
- return
- elseif green:waitForClick(event) then
- notepadsettings.update(setting, colors.green)
- updateMessage()
- return
- elseif red:waitForClick(event) then
- notepadsettings.update(setting, colors.red)
- updateMessage()
- return
- end
- end
- end
- -- Go back to main screen
- local function exit()
- local cancel = button:new()
- cancel:setLabel("X")
- cancel:setBackgroundColor(colors.red)
- cancel:setTextColor(colors.black)
- cancel:setLocation(26, 1)
- cancel:paint()
- while true do
- local event = {os.pullEvent("mouse_click")}
- if cancel:waitForClick(event) then
- return
- end
- end
- end
- parallel.waitForAny(getColorInput, exit)
- end
- -- Choose if show Italy flag in notepad
- local function enableItalyFlagScreen()
- term.clear()
- term.setCursorPos(1, 1)
- print("Should the italy flag be displayed on main screen?")
- -- Update the setting
- local function yesOrNo()
- local yes = button:new()
- yes:setLabel("Yes")
- yes:setBackgroundColor(colors.green)
- yes:setTextColor(colors.black)
- yes:setLocation(8, 4)
- local no = button:new()
- no:setLabel("No")
- no:setBackgroundColor(colors.red)
- no:setTextColor(colors.black)
- no:setLocation(16, 4)
- yes:paint()
- no:paint()
- while true do
- local event = {os.pullEvent("mouse_click")}
- if yes:waitForClick(event) then
- notepadsettings.update("ItalyFlag", true)
- term.setCursorPos(1, 7)
- print("Settings updated!")
- sleep(1)
- return
- elseif no:waitForClick(event) then
- notepadsettings.update("ItalyFlag", false)
- term.setCursorPos(1, 7)
- print("Settings updated!")
- sleep(1)
- return
- end
- end
- end
- -- Go back to main screen
- local function exit()
- local cancel = button:new()
- cancel:setLabel("X")
- cancel:setBackgroundColor(colors.red)
- cancel:setTextColor(colors.black)
- cancel:setLocation(26, 1)
- cancel:paint()
- while true do
- local event = {os.pullEvent("mouse_click")}
- if cancel:waitForClick(event) then
- return
- end
- end
- end
- parallel.waitForAny(yesOrNo, exit)
- end
- -- Perform different action based on button clicked
- local function buttonAction()
- local event = {os.pullEvent("mouse_click")}
- if HeaderSetting:waitForClick(event) then
- changeHeaderText()
- elseif HeaderColorSetting:waitForClick(event) then
- selectColorScreen("HeaderColor")
- elseif IngameTitleSetting1:waitForClick(event) or IngameTitleSetting2:waitForClick(event) then
- selectColorScreen("IngameInfoTitleColor")
- elseif IngameInfoSetting1:waitForClick(event) or IngameInfoSetting2:waitForClick(event) then
- selectColorScreen("IngameInfoColor")
- elseif IrlTitleSetting1:waitForClick(event) or IrlTitleSetting2:waitForClick(event) then
- selectColorScreen("IrlInfoTitleColor")
- elseif IrlInfoSetting1:waitForClick(event) or IrlInfoSetting2:waitForClick(event) then
- selectColorScreen("IrlInfoColor")
- elseif ItalyFlagSetting:waitForClick(event) then
- enableItalyFlagScreen()
- elseif creditButton:waitForClick(event) then
- if showCredits then
- showCredits = false
- else
- showCredits = true
- end
- elseif exit:waitForClick(event) then
- os.reboot()
- end
- end
- -- Run the program
- while true do
- mainScreen()
- buttonAction()
- end
Advertisement
Add Comment
Please, Sign In to add comment