Advertisement
Frekvens1

[ComputerCraft] Screen Calibrator

Jul 16th, 2019
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.59 KB | None | 0 0
  1. -- ComputerCraft Screen Calibrator
  2. -- For whenever you need a bigger display
  3. -- but the monitors change IDs on reboots
  4.  
  5. if (not(fs.exists("monitorScreen")) or (monitorScreen == nil)) then
  6.     -- Put this in startup file: os.loadAPI("/monitorScreen")
  7.     shell.run("delete /monitorScreen")
  8.     shell.run("pastebin get SeNab0j9 /monitorScreen")
  9.     term.clear()
  10.     term.setCursorPos(1,1)
  11.     term.write('Put this in startup file:')
  12.    
  13.     term.setCursorPos(1,3)
  14.     term.write('os.loadAPI("/monitorScreen")')
  15.     term.setCursorPos(1,4)
  16.     return
  17. end
  18.  
  19. local monitors_selectedLine = {}
  20. local monitors = monitorScreen.getMonitors()
  21.  
  22. function drawMonitor(monitor_name)
  23.     local monitor = peripheral.wrap(monitor_name)
  24.     local id = monitorScreen.getMonitorID(monitor_name)
  25.    
  26.     monitor.setBackgroundColor(colors.black)
  27.     monitor.setTextColor(colors.white)
  28.     monitor.setTextScale(2)
  29.    
  30.     monitor.clear()
  31.     monitor.setCursorPos(1,1)
  32.    
  33.     monitor.write("Screen name: "..monitor_name)
  34.    
  35.     monitor.setCursorPos(1,2)
  36.     monitor.write("Current screen: "..id)
  37.    
  38.     monitor.setCursorPos(1,4)
  39.     monitor.write("Screen selection:")
  40.    
  41.     for i=1, #monitors, 1 do
  42.         monitor.setCursorPos(1,i+5)
  43.         if (id==i) then
  44.             monitor.setBackgroundColor(colors.green)
  45.             monitor.write("Active  : Screen "..i)
  46.         else
  47.             if (monitors_selectedLine[monitor_name] == nil) then
  48.                 monitor.setBackgroundColor(colors.black)
  49.                 monitor.write("Select  : Screen "..i)
  50.             else
  51.                 if monitors_selectedLine[monitor_name] == i then
  52.                     monitor.setBackgroundColor(colors.orange)
  53.                     monitor.write("Selected: Screen "..i)
  54.                 else
  55.                     monitor.setBackgroundColor(colors.black)
  56.                     monitor.write("Select  : Screen "..i)
  57.                 end
  58.             end
  59.         end
  60.     end
  61.    
  62.    
  63.     monitor.setTextColor(colors.white)
  64.    
  65.     if monitors_selectedLine[monitor_name] == nil then
  66.         monitor.setBackgroundColor(colors.green)
  67.         monitors_selectedLine[monitor_name] = id
  68.     else
  69.         if monitors_selectedLine[monitor_name] == id then
  70.             monitor.setBackgroundColor(colors.green)
  71.         else
  72.             monitor.setBackgroundColor(colors.orange)
  73.         end
  74.     end
  75.    
  76.     monitor.setCursorPos(20,2)
  77.     monitor.write("[SAVE]")
  78.    
  79.     monitor.setBackgroundColor(colors.black)
  80. end
  81.  
  82. for _, monitor_name in pairs(monitors) do
  83.     drawMonitor(monitor_name)
  84. end
  85.  
  86. while true do
  87.     local event, monitor, x, y = os.pullEvent()
  88.     if (event == "monitor_touch") then
  89.         if ((y > 5) and (y<=#monitors+5)) then
  90.             monitors_selectedLine[monitor] = y-5
  91.             drawMonitor(monitor)
  92.         end
  93.        
  94.         if (y==2) then
  95.             if ((x>=20) and (x<=25)) then
  96.                 monitorScreen.setMonitorID(monitor, monitors_selectedLine[monitor])
  97.                 drawMonitor(monitor)
  98.             end
  99.         end
  100.     end
  101. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement