minecraft_tyler

Main Code

Apr 10th, 2016
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.16 KB | None | 0 0
  1. --Variable
  2. os.loadAPI("Ds_Data/kernal")
  3. os.loadAPI("Ds_Data/errorC")
  4.  
  5. local w,h = term.getSize()
  6. local tArgs = {...}
  7. local config = "/DS_Data/.conf"
  8. local bg = string.sub(kernal.getLine(config, 7), string.find(kernal.getLine(config, 7), ":")+2)
  9. local bg_col = tonumber(string.sub(kernal.getLine(config, 7), string.find(kernal.getLine(config, 7), ":")+2))
  10. local osVer = string.sub(kernal.getLine(config, 6), string.find(kernal.getLine(config, 6), ":")+2)
  11. local brunning = true
  12. local slc = 0
  13. local _mtext = tonumber(string.sub(kernal.getLine(config, 9), string.find(kernal.getLine(config, 9), ":")+2))
  14. local _mback = tonumber(string.sub(kernal.getLine(config, 10), string.find(kernal.getLine(config, 10), ":")+2))
  15. local images = "Documents/Images/"
  16.  
  17.  
  18. --Tables
  19. local menu = {
  20.         [1] = {txt = ""; tcol = _mtext; bcol = _mback; x = 1; xx = 7; y = 1; cmd = function() slc = 1 end};
  21.         [2] = {txt = "            "; tcol = _mtext; bcol = _mback; x = 1; xx = 12; y = 2; cmd = function() end};
  22.         [3] = {txt = " Programs > "; tcol = _mtext; bcol = _mback; x = 1; xx = 12; y = 3; cmd = function() end};
  23.         [4] = {txt = " Settings > "; tcol = _mtext; bcol = _mback; x = 1; xx = 12; y = 4; cmd = function() end};
  24.         [5] = {txt = " Lua Prompt "; tcol = _mtext; bcol = _mback; x = 1; xx = 12; y = 5; cmd = function() term.setBackgroundColor(colors.black) term.setTextColor(1) shell.run("lua") end};
  25.         [6] = {txt = " Quit       "; tcol = _mtext; bcol = _mback; x = 1; xx = 12; y = 6; cmd = function() term.setBackgroundColor(colors.black) term.setCursorPos(1,1) term.clear() brunning = false end};
  26.         [7] = {txt = " Shutdown   "; tcol = _mtext; bcol = _mback; x = 1; xx = 12; y = 7; cmd = function() os.shutdown() end};
  27.         [8] = {txt = " Logoff     "; tcol = _mtext; bcol = _mback; x = 1; xx = 12; y = 8; cmd = function() end};
  28.         [9] = {txt = " Reboot     "; tcol = _mtext; bcol = _mback; x = 1; xx = 12; y = 9; cmd = function() os.reboot() end};
  29.         [10] = {txt = "            "; tcol = _mtext; bcol = _mback; x = 1; xx = 12; y = 10; cmd = function() error("Test Error") end};
  30. }
  31. --Functions
  32. local function tb_Draw()
  33.         term.setCursorPos(1,1)
  34.         term.setBackgroundColor(8)
  35.         term.setTextColor(1)
  36.         term.clearLine()
  37.         print("[Begin]")
  38.         term.setCursorPos(math.floor(w)-#osVer, 1)
  39.         print(osVer)
  40. end
  41.  
  42. local function clear(bcol)
  43.         term.setBackgroundColor(bcol)
  44.         term.clear()
  45. end
  46.  
  47. local function drawMenu()
  48.         for k,v in pairs(menu) do
  49.                 term.setBackgroundColor(v.bcol)
  50.                 term.setTextColor(v.tcol)
  51.                 term.setCursorPos(v.x, v.y)
  52.                 print(v.txt)
  53.         end
  54. end
  55.  
  56. local function drawScreen(bcol, bimage)
  57.         clear(bcol)
  58.         if bimage == "None" then bimage = images.."bg.npg" end
  59.         paintutils.drawImage(paintutils.loadImage(images.."bg.npg"), 1, 1)
  60.         tb_Draw()
  61. end
  62.  
  63. local function menuClick()
  64.         for k,v in pairs(menu) do
  65.                 if      e[1] == "mouse_click" then
  66.                         if e[2] == 1 then
  67.                                 if e[3] >= v.x and e[3] <= v.xx and e[4] == v.y then
  68.                                         v.cmd()
  69.                                         else slc = 0 drawScreen(bg_col, bg)
  70.                                 end
  71.                         end
  72.                 end
  73.         end
  74. end
  75.  
  76. local function getFile(url, path)
  77.     download = http.get(url)
  78.     kernal.fwrite(path, download.readAll())
  79. end
  80.  
  81.  
  82. --Main code
  83. local function main()
  84. drawScreen(bg_col, bg)
  85. while brunning do
  86. e = {os.pullEvent()}
  87.         if slc == 0 then
  88.                 drawScreen(bg_col, bg)
  89.                 if e[1] == "mouse_click" then
  90.                         if e[2] == 1 then
  91.                                 if e[3] >= 1 and e[3] <= 7 and e[4] == 1 then
  92.                                         slc = 1
  93.                                         drawMenu()
  94.                                 end
  95.                         end
  96.                 end
  97.         elseif slc == 1 then
  98.                 drawMenu()
  99.                 menuClick()
  100.         end
  101. end
  102. end
  103.  
  104. errorC.A_crash(main, "center", colors.blue, 1)
Advertisement
Add Comment
Please, Sign In to add comment