Advertisement
Guest User

hud.lua

a guest
Nov 12th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.24 KB | None | 0 0
  1. rednet.open("right")
  2. local glasses = peripheral.find("neuralInterface")
  3. local canvas = glasses.canvas()
  4.  
  5. function decToHex(dec)
  6.     return string.format("%02x", dec*255)
  7. end
  8.  
  9. function hex(r,g,b,a)
  10.     local col = "0x"..decToHex(r)..decToHex(g)..decToHex(b)..decToHex(a)
  11.     print(col)
  12.     print(tonumber(col,16))
  13.     return tonumber(col, 16)
  14. end
  15.  
  16. function fill(group, col)
  17.     return group.addRectangle(0,0,1000,1000,col)
  18. end
  19.  
  20. function clear()
  21.     canvas.clear()
  22. end
  23.  
  24. function drawBar(group,x,y,w,h,percent,col1,col2)
  25.     bar = {}
  26.     bar.rect2 = group.addRectangle(x,y,w,h,col2)
  27.     bar.rect1 = group.addRectangle(x+1,y+1,(w-2)*percent,h-2,col1)
  28.     return bar
  29. end
  30. function w()
  31.     return 512
  32. end
  33. function h()
  34.     return 256
  35. end
  36.  
  37. function loadScreen(progress,alpha,omitBar)
  38.     local screen = {}
  39.     screen.group = canvas.addGroup({0, 0})
  40.     local dg = 0.1 --darkgray
  41.     screen.bkg = fill(screen.group, hex(dg,dg,dg,alpha))
  42.     if not omitBar then
  43.         local col1 = hex(0,0,0,1)
  44.         local col2 = hex(1,1,1,1)
  45.         screen.bar = drawBar(screen.group, w()/2-50,h()/2-10,100,20,progress,col1,col2)
  46.         screen.setProgress = function(progress)
  47.             screen.bar.rect1.setSize((100-2)*progress, 20-2)
  48.         end
  49.     end
  50.     return screen
  51. end
  52.  
  53. function showRoomLoadScreen()
  54.     local screen = loadScreen(0,1)
  55.     local time = 50
  56.     for i=0,time do
  57.         screen.setProgress(i/time)
  58.         os.sleep(0.05)
  59.     end
  60.     for i=0,10 do
  61.         canvas.clear()
  62.         loadScreen(1,1-i/10,true)
  63.         os.sleep(0.05)
  64.     end
  65.     canvas.clear()
  66. end
  67.  
  68. function doorway(side)
  69.     print("doorway("..side..")")
  70.     local message = {}
  71.     message.type = "doorway"
  72.     message.data = side
  73.     message = textutils.serialise(message)
  74.     rednet.broadcast(message, "player")
  75. end
  76.  
  77. function introspector()
  78.     local introspection = peripheral.wrap("back")
  79.     local recentDoorway = 0
  80.     while true do
  81.         local blocks = introspection.scan()
  82.         for k,v in pairs(blocks) do
  83.             local block = v
  84.             if(block.x==0 and block.z==0 and block.y==-4) then
  85.                 if(block.name=="thermalfoundation:storage")then
  86.                     if(recentDoorway<1)then
  87.                         print(block.state.type)
  88.                         local type = block.state.type
  89.                         if(type=="COPPER")then
  90.                             doorway("north")
  91.                         elseif(type=="SILVER")then
  92.                             doorway("east")
  93.                         elseif(type=="LEAD")then
  94.                             doorway("south")
  95.                         elseif(type=="TIN")then
  96.                             doorway("west")
  97.                         end
  98.                         recentDoorway = 10
  99.                     end
  100.                 else
  101.                     recentDoorway = recentDoorway-1
  102.                 end
  103.             end
  104.         end
  105.         os.sleep(0.05)
  106.     end
  107. end
  108.  
  109. function listener()
  110.     while(true)do
  111.         local id,message = rednet.receive("toPlayer")
  112.         message = textutils.unserialise(message)
  113.         if(message.type=="showLoadScreen")then
  114.             showRoomLoadScreen()
  115.         end
  116.     end
  117. end
  118.  
  119. parallel.waitForAll(introspector, listener)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement