Guest User

startup

a guest
Nov 30th, 2019
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.96 KB | None | 0 0
  1. if not fs.exists('userdata/') then
  2.     fs.makeDir('userdata/')
  3. end
  4. if not fs.exists('userdata/icon') then
  5.     local icon = fs.open('userdata/icon','w')
  6.     icon.writeLine('8877788')
  7.     icon.writeLine('8777778')
  8.     icon.writeLine('8777778')
  9.     icon.writeLine('8877788')
  10.     icon.writeLine('8777778')
  11.     icon.writeLine('7777777')
  12.     icon.close()
  13. end
  14. if not fs.exists('programs/') then
  15.     fs.makeDir('programs/')
  16.     shell.run('pastebin get zgMzYTPs programs/install')
  17. end
  18. if not fs.exists('programlist') then
  19.     file = fs.open('/programlist','w')
  20.     file.writeLine('2.0')
  21.     file.writeLine('2.0')
  22.     file.writeLine('512.0')
  23.     file.writeLine('2048.0')
  24.     file.writeLine('25.0')
  25.     file.writeLine('install')
  26.     file.close()
  27. end
  28. local programstemp = {}
  29. local programs = {}
  30. local pfile = fs.open('programlist','r')
  31. local timer = 0
  32.  
  33. repeat
  34.     local line = pfile.readLine()
  35.     if line ~= nil then
  36.         table.insert(programstemp,line)
  37.     end
  38. until line == nil
  39.  
  40. for i,v in ipairs(programstemp) do
  41.     timer = timer + 1
  42.     if timer%6 == 0 then
  43.         table.insert(programs,{})
  44.     end
  45. end
  46.  
  47. local index = 1
  48. timer = 0
  49. for i,v in ipairs(programstemp) do
  50.     timer = timer + 1
  51.     local vt = v
  52.     if timer%6 ~= 0 then
  53.         vt = tonumber(v)
  54.     end
  55.     table.insert(programs[index],vt)
  56.     if timer%6 == 0 then
  57.         index = index + 1
  58.     end
  59.    
  60. end
  61.  
  62. local icon = paintutils.loadImage('userdata/icon')
  63. local monitors = {peripheral.find('monitor')}
  64. local newres = nil
  65. local monitoring = false
  66. local termog = term
  67. local ogmoresx, ogmoresy = term.getSize()
  68. if ogmoresx ~= 51 or ogmoresy ~= 19 then
  69.     monitoring = true
  70. end
  71. if #monitors ~= 0 and monitoring == true then
  72.     monitors[1].setTextScale(1)
  73.     local omwidth, omheight = monitors[1].getSize()
  74.     local omnwidth = omwidth/51
  75.     local omnheight = omheight/19
  76.     local newres = omnwidth
  77.     if omnwidth > omnheight then
  78.         newres = omnheight
  79.     end
  80.     if newres < 0.5 then
  81.         newres = 0.5
  82.         error('Monitor too small!')
  83.     elseif newres > 5 then
  84.         newres = 5
  85.     end
  86.     monitors[1].setTextScale(newres)
  87. end
  88. term.setBackgroundColor(colors.lightGray)
  89. term.clear()
  90. local owidth, oheight = term.getSize()
  91. local newterm = window.create(term.current(),math.floor(owidth/2)-24,math.floor(oheight/2)-8,51,19,true)
  92. local owidth, oheight = term.getSize()
  93. local middlex = math.ceil(owidth/2)
  94. local middley = math.ceil(oheight/2)
  95. local posx, posy = newterm.getPosition()
  96. term.redirect(newterm)
  97. term.setBackgroundColor(colors.lightBlue)
  98. term.clear()
  99. paintutils.drawImage(icon,middlex-3,6)
  100. term.setCursorPos(middlex-3,14)
  101. term.setBackgroundColor(colors.lightGray)
  102. term.setTextColor(colors.gray)
  103. write('Sign In')
  104. repeat
  105.     _, m, x, y = os.pullEvent('mouse_click')
  106. until x >= posx + 22 and x <= posx + 28 and y == posy + 13
  107. local oldpull = os.pullEvent
  108.  
  109. function newpull(event)
  110.     if event ~= 'mouse_click' then
  111.         return oldpull(event)
  112.     elseif event == 'mouse_click' then
  113.         local _, m, x, y = oldpull('mouse_click')
  114.         x = x - posx + 1
  115.         y = y - posy + 1
  116.         return _, m, x, y
  117.     end
  118. end
  119.  
  120. os.pullEvent = newpull
  121.  
  122. term.setCursorPos(middlex-3,14)
  123. term.setBackgroundColor(colors.gray)
  124. term.setTextColor(colors.lightGray)
  125. write('Sign In')
  126. sleep(0.3)
  127. while true do
  128. term.setBackgroundColor(colors.lightBlue)
  129. term.clear()
  130. paintutils.drawLine(1,19,51,19,colors.blue)
  131. for i,v in ipairs(programs) do
  132.     term.setCursorPos(v[1],v[2])
  133.     term.setBackgroundColor(v[3])
  134.     term.setTextColor(v[4])
  135.     write(string.char(v[5]))
  136. end
  137. local clicked = false
  138. local clickeditem = ''
  139. repeat
  140.     _, m, x, y = os.pullEvent('mouse_click')
  141.     for i,v in ipairs(programs) do
  142.         if v[1] == x and v[2] == y then
  143.             clicked = true
  144.             clickeditem = v[6]
  145.         end
  146.     end
  147. until clicked
  148. term.setBackgroundColor(colors.black)
  149. term.setTextColor(colors.white)
  150. shell.run('/programs/'..clickeditem)
  151. end
Advertisement
Add Comment
Please, Sign In to add comment