Advertisement
Landstryder

CC_Holodeck

Mar 1st, 2015
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.69 KB | None | 0 0
  1. --set the side the monitor is connected to
  2. m = peripheral.wrap("bottom")
  3. --set the name of the container above the IO port
  4. c = peripheral.wrap("container_chest_0")
  5. --set the side to send the redstone signal to
  6. r = "left"
  7. m.setTextScale(.5)
  8.  
  9. function MakeButton(l,n1,n2,c,c2)
  10.   if c == nil then c = colors.blue end
  11.   if c2 == nil then c2= colors.white end
  12.   local n1p = 10 - (string.len(n1)/2)
  13.   local n2p = 10 - (string.len(n2)/2)
  14.   if l>3 then p2 = 13 else p2 = 1 end
  15.   if l == 1 or l == 4 then p1 = 1
  16.   elseif l < 4 then p1 = (l-1)*19
  17.   elseif l > 4 then p1 = (l-4)*19
  18.   end
  19.   m.setBackgroundColor(c)
  20.   m.setTextColor(c2)
  21.   m.setCursorPos((p1+n1p),(p2+5))
  22.   m.write(n1)
  23.   m.setCursorPos((p1+n2p),(p2+6))
  24.   m.write(n2)
  25. end
  26.  
  27. function DrawScreen()
  28.   m.setBackgroundColor(colors.black)
  29.   m.clear()
  30.   MakeButton(1,"Eden","Program",colors.green)
  31.   MakeButton(2,"Dungeon","Program")
  32.   MakeButton(3,"Unset","Program",colors.red,colors.black)
  33.   MakeButton(4,"Unset","Program",colors.red,colors.black)
  34.   MakeButton(5,"Unset","Program",colors.red,colors.black)
  35.   MakeButton(6,"Unset","Program",colors.red,colors.black)
  36. end
  37.  
  38. function Load(p)
  39. --push cell into port
  40.   m.setBackgroundColor(colors.black)
  41.   m.setTextColor(colors.white)
  42.   m.clear()
  43.   if c.pushItem("down",p) == 0 then
  44.   m.clear()
  45.   m.setCursorPos(2,12)
  46.   m.setTextColor(colors.red)
  47.   error("An error has occurred please contact engineering")
  48.   end
  49.  
  50. --turn on redstone to activate port
  51.   redstone.setOutput(r,true)
  52.  
  53. --fancy loading thing
  54.   m.setCursorPos(23,10)
  55.   m.write("Loading...")
  56.   m.setCursorPos(18,11)
  57.   m.setBackgroundColor(colors.white)
  58.   m.write("                      ")
  59.   m.setCursorPos(18,12)
  60.   m.write(" ")
  61.   m.setCursorPos(39,12)
  62.   m.write(" ")
  63.   m.setCursorPos(18,13)
  64.   m.write("                      ")
  65.   m.setCursorPos(19,12)
  66.   m.setBackgroundColor(colors.red)
  67.   m.setTextColor(colors.red)
  68.   term.redirect(m)
  69.   textutils.slowWrite("....................",5)
  70.   term.native()
  71. --end fancy loading thing
  72.  
  73. --reset the redstone output
  74.   redstone.setOutput(r,false)
  75.  
  76. --pull cell from port
  77.   if c.pullItem("down",2) == 0 then
  78.   m.clear()
  79.   m.setCursorPos(2,12)
  80.   m.setTextColor(colors.red)
  81.   error("An error has occurred please contact engineering")
  82.   end
  83.  
  84. --draw unload button
  85.   m.setBackgroundColor(colors.black)
  86.   m.setTextColor(colors.white)
  87.   m.clear()
  88.   m.setCursorPos(18,11)
  89.   m.setBackgroundColor(colors.red)
  90.   m.write("                      ")
  91.   m.setCursorPos(18,12)
  92.   m.write(" ")
  93.   m.setCursorPos(39,12)
  94.   m.write(" ")
  95.   m.setCursorPos(18,13)
  96.   m.write("                      ")
  97.   m.setCursorPos(26,12)
  98.   m.setBackgroundColor(colors.black)
  99.   m.setTextColor(colors.red)
  100.   m.write("UNLOAD")
  101. --wait for screen click to unload
  102.   local event, side, xPos, yPos = os.pullEvent(monitor_touch)
  103.  
  104. --push cell into port
  105.   if c.pushItem("down",p) == 0 then
  106.   m.setBackgroundColor(colors.black)
  107.   m.clear()
  108.   m.setCursorPos(2,12)
  109.   m.setTextColor(colors.red)
  110.   error("An error has occurred please contact engineering")
  111.   end
  112.  
  113.  --turn on redstone to activate port
  114.   redstone.setOutput(r,true)
  115.  
  116. --fancy loading thing
  117.   m.setBackgroundColor(colors.black)
  118.   m.setTextColor(colors.white)
  119.   m.clear()
  120.   m.setCursorPos(21,10)
  121.   m.write("Unloading...")
  122.   m.setCursorPos(18,11)
  123.   m.setBackgroundColor(colors.white)
  124.   m.write("                      ")
  125.   m.setCursorPos(18,12)
  126.   m.write(" ")
  127.   m.setCursorPos(39,12)
  128.   m.write(" ")
  129.   m.setCursorPos(18,13)
  130.   m.write("                      ")
  131.   m.setCursorPos(19,12)
  132.   m.setBackgroundColor(colors.red)
  133.   m.setTextColor(colors.red)
  134.   term.redirect(m)
  135.   textutils.slowWrite("....................",10)
  136.   term.native()
  137. --end fancy loading thing
  138.  
  139. --pull cell from port
  140.  
  141.   if c.pullItem("down",2) == 0 then
  142.   m.setBackgroundColor(colors.black)
  143.   m.clear()
  144.   m.setCursorPos(2,12)
  145.   m.setTextColor(colors.red)
  146.   error("An error has occurred please contact engineering")
  147.   end
  148.  
  149. --reset redstone output
  150.   redstone.setOutput(r,false)  
  151.  
  152. --redraw the button screen
  153.   DrawScreen()
  154.  end
  155.  
  156. --initialize screen
  157. DrawScreen()
  158.  
  159. --main program loop
  160. while true do
  161. --wait for monitor touch event
  162.   local event, side, xPos, yPos = os.pullEvent(monitor_touch)
  163.   print(event,",",side,",",xPos,",",yPos)
  164.  
  165. --Determine what area of the screen was clicked
  166.   if yPos < 13 and xPos < 20 then prog = 1
  167.   elseif yPos < 13 and (xPos > 19 and xPos < 39) then prog = 2
  168.   elseif yPos < 13 and xPos > 38 then prog = 3
  169.   elseif yPos > 12 and xPos < 20 then prog = 4
  170.   elseif yPos > 12 and (xPos > 19 and xPos < 39) then prog = 5
  171.   elseif yPos > 12 and xPos > 38 then prog = 6
  172.   end
  173.   print(prog)
  174.  
  175. --send the choice to load function
  176.   Load(prog)
  177.  
  178. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement