Advertisement
Redxone

ComputerCraft - StoneLock [Installer]

Jan 8th, 2017
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.27 KB | None | 0 0
  1. local w,h = term.getSize()
  2. local rw = w/2
  3. local rh = h/2
  4. local scp = term.setCursorPos
  5. local sbc = term.setBackgroundColor
  6. local stc = term.setTextColor
  7.  
  8. function defwindow()
  9.     return colors.white,colors.blue,colors.black,colors.lightGray --term.getBackgroundColor()
  10. end
  11.  
  12.  
  13. function window_write(ww,wh,txt)
  14.     local x, y = term.getCursorPos()
  15.     scp(((rw+1) - ww/2)+x,((rh+2) - wh/2)+y)
  16.     write(txt)
  17. end
  18.  
  19. function window(dowait,title,text,ww,wh,bgcolor,topcolor,sdwcolor,ccol)
  20.     if(dowait == nil)then dowait = true end
  21.     paintutils.drawFilledBox(
  22.         (rw+1) - ww/2,
  23.         (rh+2) - wh/2,
  24.         (rw+1) + ww/2,
  25.         (rh+2) + wh/2,
  26.         sdwcolor
  27.     )
  28.     paintutils.drawFilledBox(
  29.         rw - ww/2,
  30.         (rh+1) - wh/2,
  31.         rw + ww/2,
  32.         (rh+1) + wh/2,
  33.         bgcolor
  34.     )
  35.     paintutils.drawLine(
  36.         rw - ww/2,
  37.         (rh+1) - wh/2,
  38.         rw + ww/2,
  39.         (rh+1) - wh/2,
  40.         topcolor
  41.     )
  42.     sbc(topcolor)
  43.     stc(2^ ( 15 - (math.log(sdwcolor) / math.log(2) ) ))
  44.     scp((rw-ww/2),(rh+1) - wh/2)
  45.     write(title)
  46.     sbc(bgcolor)
  47.     stc(sdwcolor)
  48.     local strlin = ( ( rh + 2 ) - wh/2) +1
  49.     scp((rw-ww/2), strlin)
  50.     local xx = 0
  51.     local online = 1
  52.     local ind = 0
  53.     for i = 1, #text do
  54.         xx = xx + 1
  55.         if(text:sub(ind,ind+1) == "/n")then
  56.             online = online + 1
  57.             xx = 1
  58.             ind = ind + 1
  59.         else
  60.             scp((rw-ww/2)+xx,strlin+online)
  61.             write(text:sub(ind,ind))
  62.         end
  63.         ind = ind + 1
  64.     end
  65.     if(dowait)then
  66.         os.pullEvent("key")
  67.         paintutils.drawFilledBox(
  68.             (rw) - ww/2,
  69.             (rh) - wh/2,
  70.             (rw+1) + ww/2,
  71.             (rh+2) + wh/2,
  72.             ccol
  73.         )
  74.     end
  75. end
  76.  
  77. function askyn()
  78.     local inyn = true
  79.     local isy = false
  80.     while(inyn)do
  81.         local e, k = os.pullEvent("key")
  82.         if(k == keys.y)then
  83.             isy = true
  84.             inyn = false
  85.             break
  86.         elseif(k == keys.n)then
  87.             inyn = false
  88.             break
  89.         end
  90.     end
  91.     return isy
  92. end
  93.  
  94. paintutils.drawFilledBox(1,1,w,h,colors.lightGray)
  95. window(1,"StoneLock Installer","  Welcome to StoneLock. /n/n A lock designed for all /n StoneFruit staff members.",28,8,defwindow())
  96. window(false,"StoneLock Installer","    Install StoneLock? ",28,8,defwindow())
  97. sbc(colors.gray)
  98. scp(4,8)
  99. window_write(38,10,string.rep(" ",29))
  100. scp(16,8)
  101. stc(colors.white)
  102. window_write(38,10,"Y/n?")
  103. if(askyn())then
  104.     paintutils.drawFilledBox(1,1,w,h,colors.lightGray)
  105.     window(false,"StoneLock Installer","Download to:",38,8,defwindow())
  106.     scp(1,4)
  107.     sbc(colors.gray)
  108.     window_write(38,8,string.rep(" ",35))
  109.     scp(rw - 17, 11)
  110.     stc(colors.white)
  111.     local to = read()
  112.         local file = http.get("http://pastebin.com/raw.php?i=Mgs8dTx2")
  113.         if file then
  114.             local f = fs.open(to,"w")
  115.             f.write(file.readAll())
  116.             f.close()
  117.             window(1,"StoneLock Installer","Downloaded file: " .. to .. ". /n Successfully.",38,8,defwindow())
  118.             paintutils.drawFilledBox(1,1,w,h,colors.lightGray)
  119.             window(1,"StoneLock Installer","Setup completed! /n Press any key.",38,8,defwindow())
  120.             sbc(colors.black)
  121.             stc(colors.white)
  122.             scp(1,1)
  123.             term.clear()
  124.         else
  125.             window(false,"StoneLock Installer","/n/n download failed.",38,8,defwindow())
  126.             stc(colors.red)
  127.             scp(1,1)
  128.             window_write(38,8,"FATAL ERROR")
  129.             os.pullEvent("key")
  130.             window(1,"Fatal Error","download failed /n press any key to exit.",38,8,defwindow())
  131.             sbc(colors.black)
  132.             stc(colors.white)
  133.             scp(1,1)
  134.             term.clear()
  135.         end
  136. else
  137.     sbc(colors.black)
  138.     stc(colors.white)
  139.     scp(1,1)
  140.     term.clear()
  141. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement