SHARE
TWEET

render.lua

a guest Dec 7th, 2019 87 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local setup = require("/lua/lib/setupUtils")
  2. local monUtils = require("/lua/lib/monitorUtils")
  3. local write = monUtils.write
  4. local drawBox = monUtils.drawBox
  5.  
  6. local M = {}
  7.  
  8. function renderButtons(output, buttons)
  9.     for i, button in pairs(buttons) do
  10.         drawBox(output,
  11.             2, button.y,
  12.             output.x, button.y,
  13.             true, button.color
  14.         )
  15.         write(output,
  16.             (button.text), 1, button.y, "centre",
  17.             colors.white, button.color
  18.         )
  19.     end
  20. end
  21.  
  22. M.setupWindows = function(output)
  23.     local windows = {}
  24.     local x = output.x - 36
  25.     local y = output.y
  26.     local xWindows = (x / 42)
  27.     local yWindows = (y / 14) - 1
  28.    
  29.     for i = 0, yWindows, 1 do
  30.         for ii = 0, xWindows, 1 do
  31.             local winX = (ii * 42) + 1
  32.             local winY = (i * 14) + 2
  33.            
  34.             local window = setup.setupWindow(
  35.                 output, winX, winY,
  36.                 36, 13
  37.             )
  38.             local controlWindow = setup.setupWindow(
  39.                 window, (window.x - 13), 1,
  40.                 14, window.y
  41.             )
  42.            
  43.             table.insert(windows, {
  44.                 window = window,
  45.                 controlWindow = controlWindow
  46.             })
  47.         end
  48.     end
  49.     return windows
  50. end
  51.  
  52. M.ender = function(outputsTable)
  53.  
  54.     local buttons = {
  55.         { action = "toggle",
  56.             y = 4, color = colors.blue,
  57.             text = "Toggle"
  58.         }, {action = "toggleAuto",
  59.             y = 6, color = colors.blue,
  60.             text = "Toggle Auto"
  61.         }
  62.     }
  63.    
  64.     for i, outputs in pairs(outputsTable) do
  65.         local data = outputs.data
  66.         local output = outputs.output
  67.         local controlOutput = outputs.controlOutput
  68.    
  69.         output.clear()
  70.         write(output,
  71.             "Endergenic Unit: " .. data.num,
  72.             1, 2, "left"
  73.         )
  74.         local msgs = {
  75.             on = "Active",
  76.             off = "Idle"
  77.         }
  78.         write(output,
  79.             "State: " .. msgs[data.state],
  80.             1, 4, "left"
  81.         )
  82.         write(output,
  83.             "Average RF/t: " .. data.avgRFT,
  84.             1, 7, "left"
  85.         )
  86.        
  87.         msgs = {
  88.             on = "Enabled",
  89.             off = "Disabled"
  90.         }
  91.         write(output,
  92.             "Auto: " .. msgs[data.auto],
  93.             1, (output.y - 1), "left"
  94.         )
  95.        
  96.         local bgs = {
  97.             off = colors.purple,
  98.             on = colors.cyan
  99.         }
  100.        
  101.         controlOutput.bg = bgs[data.state]
  102.         controlOutput.setBackgroundColor(controlOutput.bg)
  103.         drawBox(controlOutput,
  104.             1, 1, controlOutput.x, controlOutput.y,
  105.             true
  106.         )
  107.         drawBox(controlOutput,
  108.             1, 1, 1, controlOutput.y,
  109.             true, colors.white
  110.         )
  111.         write(controlOutput,
  112.             "Controls:",
  113.             1, 2, "centre"
  114.         )
  115.    
  116.         renderButtons(controlOutput, buttons)
  117.        
  118.     end
  119.    
  120.     return buttons
  121.    
  122. end
  123.  
  124. M.power = function()
  125.    
  126. end
  127.  
  128. return M
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top