Advertisement
mrkarp

rc2mf

Feb 20th, 2021
932
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.30 KB | None | 0 0
  1. local monitor
  2. local hasMonitor = false
  3. local ProgressBar = {}
  4. local FillColor = colors.orange
  5. local EmptyColor = colors.blue
  6. local TextColor = colors.white
  7.  
  8. function SetPeripheral(side)
  9.   if (peripheral.isPresent(side)) then
  10.     monitor = peripheral.wrap(side)
  11.     hasMonitor = true
  12.   end
  13. end
  14.  
  15. function SetTable(name, maxVal, curVal, xmin, xmax, y)
  16.   ProgressBar[name] = {}
  17.   ProgressBar[name]["Max"] = maxVal
  18.   ProgressBar[name]["Current"] = curVal
  19.   ProgressBar[name]["XMin"] = xmin
  20.   ProgressBar[name]["XMax"] = xmax
  21.   ProgressBar[name]["YVal"] = y
  22. end
  23.  
  24. function ClearTable()
  25.   if (hasMonitor) then
  26.     ProgressBar = {}
  27.   end
  28. end
  29.  
  30. function SetFillColor(color)
  31.   if (colors.combine(color,color)) then  
  32.     FillColor = color
  33.   end
  34. end
  35.  
  36. function SetEmptyColor(color)
  37.   if (colors.combine(color,color)) then
  38.     EmptyColor = color
  39.   end
  40. end
  41.  
  42. function SetTextColor(color)
  43.   if (colors.combine(color,color)) then
  44.     TextColor = color
  45.   end
  46. end
  47.  
  48. function SetMaxValue(name, intVal)
  49.   if (ProgressBar[name]) then
  50.     ProgressBar[name]["Max"] = intVal
  51.   end
  52. end
  53.  
  54. function SetCurValue(name, intVal)
  55.   if (ProgressBar[name]) then
  56.     ProgressBar[name]["Current"] = intVal
  57.   end
  58. end
  59.  
  60. function DrawToPeripheral()
  61.   if (hasMonitor) then
  62.     for name, data in pairs(ProgressBar) do
  63.       DrawBar(name, data)
  64.     end
  65.   end
  66. end
  67.  
  68. function DrawBar(name, arr)
  69.   local y = arr["YVal"]
  70.   local fill = math.floor((arr["XMax"] - arr["XMin"]) * (arr["Current"] / arr["Max"]))
  71.  
  72.   --monitor.setBackgroundColor(FillColor)
  73.   if fill then
  74.       if (fill <= 25) then
  75.         monitor.setBackgroundColor(colors.red)
  76.     end
  77.       if (fill <= 50) then
  78.         monitor.setBackgroundColor(colors.orange)
  79.         end
  80.       if (fill <= 75) then
  81.         monitor.setBackgroundColor(colors.yellow)
  82.         end
  83.       if (fill <= 99) then
  84.         monitor.setBackgroundColor(colors.green)
  85.       end
  86.   end
  87.  
  88.   monitor.setTextColor(TextColor)
  89.  
  90.   for x = arr["XMin"], arr["XMax"] do
  91.     local num = math.floor(x - arr["XMin"])
  92.     monitor.setCursorPos(x,y)
  93.  
  94.     if (num > fill) then
  95.       monitor.setBackgroundColor(EmptyColor)
  96.     end
  97.  
  98.     if (num == 0) then
  99.       monitor.write("[")
  100.     end
  101.     if (x == arr["XMax"]) then
  102.       monitor.write("]")
  103.     else
  104.       monitor.write(" ")
  105.     end
  106.   end
  107.  
  108.   monitor.setBackgroundColor(colors.black)
  109. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement