Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Beta --
- currentVersion = "1"
- if not term.isColor() then print("Advanced Computer Required.") return end
- local sx,sy = term.getSize()
- if sx ~= 51 and sy ~= 19 then print("51 by 19 Computer Required.") return end
- function clr() term.clear() end
- function cp(x,y) term.setCursorPos(x,y) end
- function setBack(col) term.setBackgroundColor(colors[col]) end
- function setText(col) term.setTextColor(colors[col]) end
- function runMenu(menuTitleColor, menuTitleBackColor, menuData, menuDataColor, menuDataBackColor)
- if type(menuTitleColor) ~= "string" then error("runMenu: Title Color is not readable. String needed, got "..type(menuTitleColor)) end
- if type(menuTitleBackColor) ~= "string" then error("runMenu: Title Background Color is not readable. String needed, got "..type(menuTitleBackColor)) end
- if type(menuData) ~= "table" then error("runMenu: Menu is not readable. Table needed, got "..type(menuData)) end
- if type(menuDataColor) ~= "string" then error("runMenu: Menu Color is not readable. String needed, got "..type(menuDataColor)) end
- if type(menuDataBackColor) ~= "string" then error("runMenu: Menu Background Color is not readable. String needed, got "..type(menuDataBackColor)) end
- clr() cp(1,1) setBack(menuTitleBackColor) setText(menuTitleColor) write(menuData[1].." ") setBack("gray") print(" ")
- cp(1,3) setText(menuDataColor)
- for i=1, #menuData-1 do
- if menuData[i+1] == "Save Settings" then
- if saved == true then
- setBack("green")
- else
- setBack("red")
- end
- else
- setBack(menuDataBackColor)
- end
- write(" "..menuData[i+1].." ")
- setBack("gray")
- print(" ")
- end
- local running = true
- local clicked = false
- while running do
- sleep(.1)
- a,i,x,y = os.pullEvent("mouse_click")
- if y >= 3 and y-1 <= #menuData then
- if menuData[y-2] ~= nil then
- if x <= string.len(menuData[y-2])+10 then
- clicked = y-2 running = false
- end
- end
- end
- end
- setText("white") setBack("black")
- return clicked
- end
- function loadSettings()
- if fs.exists("betaSettings.lua") then
- local file = fs.open("betaSettings.lua", "r")
- local version = file.readLine()
- file.close()
- local file = fs.open("betaSettings.lua", "r")
- local waste = file.readLine()
- local temp = {}
- local cnt = 0
- repeat
- cnt = cnt + 1
- temp[cnt] = file.readLine()
- until temp[cnt] == nil
- file.close()
- if #temp == #loadedSettings then if checkSaveVersion(tostring(version)) then loadedSettings = temp end end
- saved = true
- end
- end
- function saveSettings()
- local file = fs.open("betaSettings.lua", "w")
- file.writeLine(currentVersion)
- for i=1, #loadedSettings do
- file.writeLine(loadedSettings[i])
- end
- file.close()
- saved = true
- end
- function checkSaveVersion(version)
- if type(tonumber(version)) ~= "number" then return false end
- if version == currentVersion then
- return true
- end
- end
- function setColor()
- local cols = {"white", "orange", "magenta", "lightBlue", "yellow", "lime", "pink", "gray", "lightGray", "cyan", "purple", "blue", "brown", "green", "red", "black"}
- clr() cp(1,1) setBack(loadedSettings[2]) setText(loadedSettings[1]) write("Select a Color ") setBack("gray") print(" ")
- setText("white")
- for i=1, 4 do
- cp(2,2+i) write(string.char(127))
- end
- for i=1, 4 do
- cp(11,2+i) write(string.char(127))
- end
- for i=1, 8 do
- cp(2+i,3) write(string.char(127))
- end
- for i=1, 8 do
- cp(2+i,6) write(string.char(127))
- end
- for i=1, #cols/2 do
- cp(2+i,4) setBack(cols[i]) write(" ") sleep(.01)
- end
- for i=1, #cols/2 do
- cp(2+i,5) setBack(cols[i+8]) write(" ") sleep(.01)
- end
- repeat
- a,i,x,y = os.pullEvent("mouse_click")
- until x >= 3 and x <= 10 and y >= 4 and y <= 5
- saved = false
- if y == 4 then
- return cols[x-2]
- elseif y == 5 then
- return cols[x+6]
- end
- end
- local mMain = {"Main Menu", "Play", "Store", "Settings", "Exit"}
- local mSettings = {"Settings", "Title Settings", "Menu Settings", "Advanced Settings", "Back"}
- local mSettings_TitleSettings = {"Title Settings", "Set Text Color", "Set Background Color", "Back"}
- local mSettings_MenuSettings = {"Menu Settings", "Set Text Color", "Set Background Color", "Back"}
- local mSettings_AdvSettings = {"Adv Settings", "Reset Settings", "Save Settings", "Load Settings", "Back"}
- loadedSettings = {"yellow", "blue", "white", "blue"}
- saved = true
- function runtime()
- loadSettings()
- local running = true
- local currentMenu = mMain
- while running do
- local res = runMenu(loadedSettings[1], loadedSettings[2], currentMenu, loadedSettings[3], loadedSettings[4])
- if currentMenu == mMain then
- if res == 1 then
- --
- elseif res == 2 then
- --
- elseif res == 3 then
- currentMenu = mSettings
- elseif res == 4 then
- running = false
- end
- elseif currentMenu == mStore then
- --
- elseif currentMenu == mSettings then
- if res == 1 then
- currentMenu = mSettings_TitleSettings
- elseif res == 2 then
- currentMenu = mSettings_MenuSettings
- elseif res == 3 then
- currentMenu = mSettings_AdvSettings
- elseif res == 4 then
- currentMenu = mMain
- end
- elseif currentMenu == mSettings_TitleSettings then
- if res == 1 then
- loadedSettings[1] = setColor()
- elseif res == 2 then
- loadedSettings[2] = setColor()
- elseif res == 3 then
- currentMenu = mSettings
- end
- elseif currentMenu == mSettings_MenuSettings then
- if res == 1 then
- loadedSettings[3] = setColor()
- elseif res == 2 then
- loadedSettings[4] = setColor()
- elseif res == 3 then
- currentMenu = mSettings
- end
- elseif currentMenu == mSettings_AdvSettings then
- if res == 1 then
- loadedSettings = {"yellow", "blue", "white", "blue"}
- elseif res == 2 then
- saveSettings()
- elseif res == 3 then
- loadSettings() currentMenu = mSettings
- elseif res == 4 then
- currentMenu = mSettings
- end
- end
- end
- end
- runtime()
Advertisement
Add Comment
Please, Sign In to add comment