Advertisement
simmi

Schalttafel

Jun 24th, 2018
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.06 KB | None | 0 0
  1. --(C) by JoJa Productions
  2. --Monitor 7 breit und 3 hoch
  3. -- Monitorseite:
  4. local monSide = "back"
  5. -- bundledCable Seite:
  6. local bunSide = "back"
  7. -- Hintergrundfarbe:
  8. local bCol = colors.lightGray
  9. -- Textfarbe:
  10. local tCol = colors.white
  11. --Programmbeschreibung
  12. local prgrm_description = "Schalttafel"
  13.  
  14. m = peripheral.wrap(monSide)
  15.  
  16. local xMax,yMax = m.getSize()
  17.  
  18. local button = {}
  19. --Knopf     xP1 yP1 xP2 yP2    Name       Farbe(AUS) Farbe(AN)            Ausgang   Standardwert(false = Aus, true = an)
  20. button[1]  = { 3, 3,13, 9,   "All ON", colors.black, colors.gray,                nil,false}
  21. button[2]  = { 3,11,13,17,  "All OFF", colors.black, colors.gray,                nil,false}
  22. button[3]  = {17, 3,27, 5,    "white",   colors.red, colors.lime,       colors.white,false}
  23. button[4]  = {31, 3,41, 5,   "orange",   colors.red, colors.lime,      colors.orange,false}
  24. button[5]  = {45, 3,55, 5,  "magenta",   colors.red, colors.lime,     colors.magenta,false}
  25. button[6]  = {59, 3,69, 5,"lightBlue",   colors.red, colors.lime,   colors.lightBlue,false}
  26. button[7]  = {17, 7,27, 9,   "yellow",   colors.red, colors.lime,      colors.yellow,false}
  27. button[8]  = {31, 7,41, 9,     "lime",   colors.red, colors.lime,        colors.lime,false}
  28. button[9]  = {45, 7,55, 9,     "pink",   colors.red, colors.lime,        colors.pink,false}
  29. button[10] = {59, 7,69, 9,     "gray",   colors.red, colors.lime,        colors.gray,false}
  30. button[11] = {17,11,27,13,"lightGray",   colors.red, colors.lime,   colors.lightGray,false}
  31. button[12] = {31,11,41,13,     "cyan",   colors.red, colors.lime,        colors.cyan,false}
  32. button[13] = {45,11,55,13,   "purple",   colors.red, colors.lime,      colors.purple,false}
  33. button[14] = {59,11,69,13,     "blue",   colors.red, colors.lime,        colors.blue,false}
  34. button[15] = {17,15,27,17,    "brown",   colors.red, colors.lime,       colors.brown,false}
  35. button[16] = {31,15,41,17,    "green",   colors.red, colors.lime,       colors.green,false}
  36. button[17] = {45,15,55,17,      "red",   colors.red, colors.lime,         colors.red,false}
  37. button[18] = {59,15,69,17,    "black",   colors.red, colors.lime,       colors.black,false}
  38.  
  39. function writeCentered(txt, yP)
  40.   m.setCursorPos(xMax/2-#txt/2,yP)
  41.   m.write(txt)
  42. end
  43.  
  44. function bg(col)
  45.   m.setBackgroundColor(col)
  46.   for xP = 1,xMax do
  47.     for yP = 1,yMax do
  48.       m.setCursorPos(xP,yP)
  49.       m.write(" ")
  50.     end
  51.   end
  52. end
  53.  
  54. function JoJa()
  55.   m.setBackgroundColor(colors.gray)
  56.   for xP = 1,xMax do
  57.     m.setCursorPos(xP,1)
  58.     m.write(" ")
  59.   end
  60.   m.setCursorPos(1,1)
  61.   m.setTextColor(colors.cyan)
  62.   m.write("Jo")
  63.   m.setTextColor(colors.orange)
  64.   m.write("Ja ")
  65.   m.setTextColor(colors.lightGray)
  66.   m.write("Productions")
  67. end
  68.  
  69. function drawButton(arr)
  70.   for i = 1,#arr do
  71.     if arr[i][9] then
  72.       m.setBackgroundColor(arr[i][7])
  73.     else
  74.       m.setBackgroundColor(arr[i][6])
  75.     end
  76.     for xP = arr[i][1],arr[i][3] do
  77.       for yP = arr[i][2],arr[i][4] do
  78.         m.setCursorPos(xP,yP)
  79.         m.write(" ")
  80.       end
  81.     end
  82.     m.setCursorPos(1+arr[i][1]+(arr[i][3]-arr[i][1])/2-#arr[i][5]/2,arr[i][2]+(arr[i][4]-arr[i][2])/2)
  83.     m.write(arr[i][5])
  84.   end
  85. end
  86.  
  87. function checkButton(arr,xP,yP)
  88.   for i = 1,#arr do
  89.     if  xP >= arr[i][1] and xP <= arr[i][3]
  90.     and yP >= arr[i][2] and yP <= arr[i][4] then
  91.       if arr[i][9] then arr[i][9] = false else arr[i][9] = true end
  92.     end  
  93.   end
  94. end
  95.  
  96. bg(bCol)
  97. JoJa()
  98. m.setTextColor(tCol)
  99. if prgrm_description == nil then
  100.   prgrm_description = ""
  101. end
  102. writeCentered(prgrm_description,1)
  103. while true do
  104.   drawButton(button)
  105.   local out = 0
  106.   for i = 1,#button do
  107.     if button[i][9] then
  108.       out = out+button[i][8]
  109.     end
  110.   end
  111.   rs.setBundledOutput(bunSide,out)
  112.   sleep(.1)
  113.   local event,_,xP,yP = os.pullEvent("monitor_touch")
  114.   checkButton(button,xP,yP)
  115.   drawButton(button)
  116.   if button[1][9] then
  117.     button[1][9] = false
  118.     for i = 3,#button do
  119.       button[i][9] = true
  120.     end
  121.   elseif button[2][9] then
  122.     button[2][9] = false
  123.     for i = 3,#button do
  124.       button[i][9] = false
  125.     end
  126.   end
  127. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement