JustDoesGames

beta

Sep 19th, 2019
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.91 KB | None | 0 0
  1.  
  2. -- Beta --
  3.  
  4. currentVersion = "1"
  5.  
  6. if not term.isColor() then print("Advanced Computer Required.") return end
  7. local sx,sy = term.getSize()
  8. if sx ~= 51 and sy ~= 19 then print("51 by 19 Computer Required.") return end
  9.  
  10. function clr() term.clear() end
  11. function cp(x,y) term.setCursorPos(x,y) end
  12. function setBack(col) term.setBackgroundColor(colors[col]) end
  13. function setText(col) term.setTextColor(colors[col]) end
  14.  
  15. function runMenu(menuTitleColor, menuTitleBackColor, menuData, menuDataColor, menuDataBackColor)
  16.  
  17.     if type(menuTitleColor) ~= "string" then error("runMenu: Title Color is not readable. String needed, got "..type(menuTitleColor)) end
  18.     if type(menuTitleBackColor) ~= "string" then error("runMenu: Title Background Color is not readable. String needed, got "..type(menuTitleBackColor)) end
  19.  
  20.     if type(menuData) ~= "table" then error("runMenu: Menu is not readable. Table needed, got "..type(menuData)) end
  21.     if type(menuDataColor) ~= "string" then error("runMenu: Menu Color is not readable. String needed, got "..type(menuDataColor)) end
  22.     if type(menuDataBackColor) ~= "string" then error("runMenu: Menu Background Color is not readable. String needed, got "..type(menuDataBackColor)) end
  23.  
  24.  
  25.     clr() cp(1,1) setBack(menuTitleBackColor) setText(menuTitleColor) write(menuData[1].."          ") setBack("gray") print(" ")
  26.  
  27.     cp(1,3) setText(menuDataColor)
  28.     for i=1, #menuData-1 do
  29.         if menuData[i+1] == "Save Settings" then
  30.             if saved == true then
  31.                 setBack("green")
  32.             else
  33.                 setBack("red")
  34.             end
  35.         else
  36.             setBack(menuDataBackColor)
  37.         end
  38.         write(" "..menuData[i+1].."         ")
  39.         setBack("gray")
  40.         print(" ")
  41.     end
  42.  
  43.  
  44.     local running = true
  45.     local clicked = false
  46.  
  47.     while running do
  48.         sleep(.1)
  49.         a,i,x,y = os.pullEvent("mouse_click")
  50.         if y >= 3 and y-1 <= #menuData then
  51.             if menuData[y-2] ~= nil then
  52.                 if x <= string.len(menuData[y-2])+10 then
  53.                     clicked = y-2 running = false
  54.                 end
  55.             end
  56.         end
  57.     end
  58.     setText("white") setBack("black")
  59.     return clicked
  60. end
  61.  
  62. function loadSettings()
  63.     if fs.exists("betaSettings.lua") then
  64.         local file = fs.open("betaSettings.lua", "r")
  65.         local version = file.readLine()
  66.         file.close()
  67.         local file = fs.open("betaSettings.lua", "r")
  68.         local waste = file.readLine()
  69.         local temp = {}
  70.         local cnt = 0
  71.         repeat
  72.             cnt = cnt + 1
  73.             temp[cnt] = file.readLine()
  74.         until temp[cnt] == nil
  75.         file.close()
  76.  
  77.         if #temp == #loadedSettings then if checkSaveVersion(tostring(version)) then loadedSettings = temp end end
  78.         saved = true
  79.     end
  80. end
  81.  
  82. function saveSettings()
  83.     local file = fs.open("betaSettings.lua", "w")
  84.     file.writeLine(currentVersion)
  85.     for i=1, #loadedSettings do
  86.         file.writeLine(loadedSettings[i])
  87.     end
  88.     file.close()
  89.     saved = true
  90. end
  91.  
  92. function checkSaveVersion(version)
  93.     if type(tonumber(version)) ~= "number" then return false end
  94.     if version == currentVersion then
  95.         return true
  96.     end
  97. end
  98.  
  99. function setColor()
  100.     local cols = {"white", "orange", "magenta", "lightBlue", "yellow", "lime", "pink", "gray", "lightGray", "cyan", "purple", "blue", "brown", "green", "red", "black"}
  101.     clr() cp(1,1) setBack(loadedSettings[2]) setText(loadedSettings[1]) write("Select a Color          ") setBack("gray") print(" ")
  102.  
  103.     setText("white")
  104.     for i=1, 4 do
  105.         cp(2,2+i) write(string.char(127))
  106.     end
  107.     for i=1, 4 do
  108.         cp(11,2+i) write(string.char(127))
  109.     end
  110.     for i=1, 8 do
  111.         cp(2+i,3) write(string.char(127))
  112.     end
  113.     for i=1, 8 do
  114.         cp(2+i,6) write(string.char(127))
  115.     end
  116.  
  117.     for i=1, #cols/2 do
  118.         cp(2+i,4) setBack(cols[i]) write(" ") sleep(.01)
  119.     end
  120.     for i=1, #cols/2 do
  121.         cp(2+i,5) setBack(cols[i+8]) write(" ") sleep(.01)
  122.     end
  123.  
  124.     repeat
  125.         a,i,x,y = os.pullEvent("mouse_click")
  126.     until x >= 3 and x <= 10 and y >= 4 and y <= 5
  127.  
  128.     saved = false
  129.  
  130.     if y == 4 then
  131.         return cols[x-2]
  132.     elseif y == 5 then
  133.         return cols[x+6]
  134.     end
  135. end
  136.  
  137. local mMain = {"Main Menu", "Play", "Store", "Settings", "Exit"}
  138. local mSettings = {"Settings", "Title Settings", "Menu Settings", "Advanced Settings", "Back"}
  139. local mSettings_TitleSettings = {"Title Settings", "Set Text Color", "Set Background Color", "Back"}
  140. local mSettings_MenuSettings = {"Menu Settings", "Set Text Color", "Set Background Color", "Back"}
  141. local mSettings_AdvSettings = {"Adv Settings", "Reset Settings", "Save Settings", "Load Settings", "Back"}
  142.  
  143. loadedSettings = {"yellow", "blue", "white", "blue"}
  144. saved = true
  145.  
  146. function runtime()
  147.     loadSettings()
  148.     local running = true
  149.     local currentMenu = mMain
  150.     while running do
  151.         local res = runMenu(loadedSettings[1], loadedSettings[2], currentMenu, loadedSettings[3], loadedSettings[4])
  152.         if currentMenu == mMain then
  153.             if res == 1 then
  154.                 --
  155.             elseif res == 2 then
  156.                 --
  157.             elseif res == 3 then
  158.                 currentMenu = mSettings
  159.             elseif res == 4 then
  160.                 running = false
  161.             end
  162.         elseif currentMenu == mStore then
  163.             --
  164.         elseif currentMenu == mSettings then
  165.             if res == 1 then
  166.                 currentMenu = mSettings_TitleSettings
  167.             elseif res == 2 then
  168.                 currentMenu = mSettings_MenuSettings
  169.             elseif res == 3 then
  170.                 currentMenu = mSettings_AdvSettings
  171.             elseif res == 4 then
  172.                 currentMenu = mMain
  173.             end
  174.         elseif currentMenu == mSettings_TitleSettings then
  175.             if res == 1 then
  176.                 loadedSettings[1] = setColor()
  177.             elseif res == 2 then
  178.                 loadedSettings[2] = setColor()
  179.             elseif res == 3 then
  180.                 currentMenu = mSettings
  181.             end
  182.         elseif currentMenu == mSettings_MenuSettings then
  183.             if res == 1 then
  184.                 loadedSettings[3] = setColor()
  185.             elseif res == 2 then
  186.                 loadedSettings[4] = setColor()
  187.             elseif res == 3 then
  188.                 currentMenu = mSettings
  189.             end
  190.         elseif currentMenu == mSettings_AdvSettings then
  191.             if res == 1 then
  192.                 loadedSettings = {"yellow", "blue", "white", "blue"}
  193.             elseif res == 2 then
  194.                 saveSettings()
  195.             elseif res == 3 then
  196.                 loadSettings() currentMenu = mSettings
  197.             elseif res == 4 then
  198.                 currentMenu = mSettings
  199.             end
  200.         end
  201.     end
  202. end
  203.  
  204. runtime()
Advertisement
Add Comment
Please, Sign In to add comment