monster010

CC - Label API

Apr 20th, 2016
3,098
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.40 KB | None | 0 0
  1. -- Label API - (c) monster010 -- v1.1
  2. local labels = {}
  3. local monitor
  4.  
  5. function construct(moni)
  6.     monitor = moni
  7. end
  8.  
  9. function getLabels()
  10.     return labels
  11. end
  12.  
  13. function clear()
  14.     labels = {}
  15. end
  16.  
  17. function add(name, label, x, y, slabel, cltext, clstext, clfill, clsfill)
  18.     if not slabel then slabel = false end
  19.     if not cltext then cltext = colors.white end
  20.     if not clstext then clstext = colors.white end
  21.     if not clfill then clfill = colors.black end
  22.     if not clsfill then clsfill = colors.black end
  23.  
  24.     labels[name] = {}
  25.     labels[name]["txt"] = label
  26.     labels[name]["x"] = x
  27.     labels[name]["y"] = y
  28.     labels[name]["stxt"] = slabel
  29.     labels[name]["cl"] = cltext
  30.     labels[name]["cls"] = clstext
  31.     labels[name]["bfill"] = clfill
  32.     labels[name]["bsfill"] = clsfill
  33. end
  34.  
  35. function set(name, key, val)
  36.     labels[name][key] = val
  37. end
  38.  
  39. function screen()
  40.     for name, lData in pairs(labels) do
  41.         fill(name, lData)
  42.     end
  43. end
  44.  
  45. function fill(name, data)
  46.     monitor.setBackgroundColor(data["bfill"])
  47.     monitor.setTextColor(data["cl"])
  48.     monitor.setCursorPos(data["x"], data["y"])
  49.  
  50.     monitor.write(data["txt"])
  51.  
  52.     if data["stxt"] then
  53.         monitor.setBackgroundColor(data["bsfill"])
  54.         monitor.setTextColor(data["cls"])
  55.         monitor.setCursorPos(data["x"] + 1 + string.len(data["txt"]), data["y"])
  56.  
  57.         monitor.write(data["stxt"])
  58.     end
  59.  
  60.     monitor.setBackgroundColor(colors.black)
  61.     monitor.setTextColor(colors.white)
  62. end
Advertisement
Add Comment
Please, Sign In to add comment