koki2000

gomb

Jun 20th, 2016
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.44 KB | None | 0 0
  1. rednet.open("back")
  2. signal = 0
  3. local gomb = {}
  4. term.clear()
  5. gomb[1] = {x = 1, y = 1, x2 = 3, y2 = 1, color = colors.red, dcolor = colors.red, szoveg = "a", value = 1}
  6. gomb[2] = {x = 5, y = 1, x2 = 7, y2 = 1, color = colors.yellow, dcolor = colors.yellow, szoveg = "b", value = 0}
  7. gomb[3] = {x = 9, y = 1, x2 = 11, y2 = 1, color = colors.green, dcolor = colors.green, szoveg = "c", value = 0}
  8. gomb[4] = {x = 1, y = 3, x2 = 3, y2 = 3, color = colors.orange, dcolor = colors.orange, szoveg = "d", value = 0}
  9. gomb[5] = {x = 5, y = 3, x2 = 7, y2 = 3, color = colors.magenta, dcolor = colors.magenta, szoveg = "e", value = 0}
  10. gomb[6] = {x = 9, y = 3, x2 = 11, y2 = 3, color = colors.cyan, dcolor = colors.cyan, szoveg = "f", value = 0}
  11. gomb[7] = {x = 41, y = 1, x2 = 43, y2 = 1, color = 2, dcolor = 2, szoveg = "1", value = 0}
  12. gomb[8] = {x = 45, y = 1, x2 = 47, y2 = 1, color = 4, dcolor = 4, szoveg = "2", value = 0}
  13. gomb[9] = {x = 49, y = 1, x2 = 51, y2 = 1, color = 8, dcolor = 8, szoveg = "3", value = 0}
  14. gomb[10] = {x = 41, y = 3, x2 = 43, y2 = 3, color = 16, dcolor = 16, szoveg = "4", value = 0}
  15.  
  16.  
  17. function tclr()
  18.  term.clear()
  19.  term.setCursorPos(1,1)
  20. end
  21.  
  22. function kirajzol()
  23.  term.clear()
  24.  for i = 1, #gomb do
  25.   if gomb[i].value == 1 then
  26.    for j = 0 + gomb[i].y, gomb[i].y2 do
  27.     for k = 0 + gomb[i].x, gomb[i].x2 do
  28.      term.setCursorPos(k, j)
  29.      term.setBackgroundColor(gomb[i].color)
  30.      print(" ")
  31.     end
  32.    end
  33.    term.setCursorPos(gomb[i].x+1, gomb[i].y)
  34.    print(gomb[i].szoveg)
  35.   end
  36.   term.setBackgroundColor(colors.black)
  37.  end
  38. end
  39.  
  40. function paint()
  41.  term.clear()
  42.  for i = 1, #gomb do
  43.   if gomb[i].value == 1 then
  44.    paintutils.drawFilledBox(gomb[i].x, gomb[i].y, gomb[i].x2, gomb[i].y2, gomb[i].color)
  45.    term.setCursorPos(gomb[i].x+1, gomb[i].y)
  46.    print(gomb[i].szoveg)
  47.   end
  48.  end
  49.   term.setBackgroundColor(colors.black)
  50. end
  51.  
  52. function click(xpos, ypos, xs, ys, xe, ye)
  53.  if xpos < xs or xpos > xe or ypos < ys or ypos > ye then
  54.   return false
  55.  else
  56.   return true
  57.  end
  58. end
  59.  
  60. function setter(ertek, xpos, ypos, i, xs, ys, xe, ye)
  61.  if ertek then
  62.   if gomb[i].color == gomb[i].dcolor then
  63.    esemeny(i)
  64.    gomb[i].color = colors.lime
  65.   else
  66.    esemeny(i)
  67.    gomb[i].color = gomb[i].dcolor
  68.   end
  69.  else
  70.   term.setCursorPos(xpos, ypos)
  71.   print("x")
  72.  end
  73. end
  74.  
  75. function esemeny(i)
  76.  if gomb[i].color == gomb[i].dcolor then
  77.    if i == 1 then
  78.     for i = 1, #gomb do
  79.      gomb[i].value = 1
  80.     end
  81.     rs.setOutput("left", true)
  82.    elseif i == 2 then
  83.     rs.setOutput("right", true)
  84.    elseif i == 3 then
  85.     rednet.broadcast("open")
  86.    elseif i == 4 then
  87.     redstone.setAnalogOutput("left", signal)
  88.    elseif i == 9 then
  89.     signal = 3
  90.    end
  91.  else
  92.    if i == 1 then
  93.     for i = 1, #gomb do
  94.      gomb[i].value = 0
  95.     end
  96.     gomb[1].value = 1
  97.     rs.setOutput("left", false)
  98.    elseif i == 2 then
  99.     rs.setOutput("right", false)
  100.    elseif i == 3 then
  101.     rednet.broadcast("close")
  102.    elseif i == 4 then
  103.     redstone.setAnalogOutput("left", 0)
  104.    elseif i == 9 then
  105.     signal = 0
  106.    end
  107.  end
  108. end
  109.  
  110. while true do
  111. kirajzol()
  112. local event, button, xpos, ypos = os.pullEvent("mouse_click")
  113.  for i=1, #gomb do
  114.   if gomb[i].value == 1 then
  115.    if click(xpos, ypos, gomb[i].x, gomb[i].y, gomb[i].x2, gomb[i].y2) then
  116.     setter(true, xpos, ypos, i, gomb[i].x, gomb[i].y, gomb[i].x2, gomb[i].y2)
  117.    else
  118.     setter(false, xpos, ypos, i, gomb[i].x, gomb[i].y, gomb[i].x2, gomb[i].y2)
  119.    end
  120.   end
  121.  end
  122. end
Add Comment
Please, Sign In to add comment