Advertisement
Guest User

button

a guest
Nov 25th, 2015
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.19 KB | None | 0 0
  1. local mon = peripheral.wrap("top")
  2. mon.setTextScale(2)
  3. mon.setTextColor(colors.white)
  4. local button={}
  5. mon.setBackgroundColor(colors.black)
  6. local cb = peripheral.wrap("right")
  7.    
  8. function setTable(warp, name, xmin, xmax, ymin, ymax)
  9.    button[warp] = {}
  10.    button[warp]["warp"] = warp
  11.    button[warp]["name"] = name
  12.    button[warp]["active"] = false
  13.    button[warp]["xmin"] = xmin
  14.    button[warp]["ymin"] = ymin
  15.    button[warp]["xmax"] = xmax
  16.    button[warp]["ymax"] = ymax
  17. end
  18.  
  19. function fill(color, bData)
  20.    mon.setBackgroundColor(color)
  21.    local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2)
  22.    local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(bData["name"])) /2) +1
  23.    local xspot2 = math.floor((bData["xmax"] - bData["xmin"] - string.len(bData["warp"])) /2) +1
  24.    for j = bData["ymin"], bData["ymax"] do
  25.       mon.setCursorPos(bData["xmin"], j)
  26.       if j == yspot then
  27.          for k = 0, bData["xmax"] - bData["xmin"] - string.len(bData["name"]) +1 do
  28.             if k == xspot then
  29.                mon.write(bData["name"])
  30.             else
  31.                mon.write(" ")
  32.             end
  33.          end
  34.       elseif j == bData["ymax"] then
  35.          for k = 0, bData["xmax"] - bData["xmin"] - string.len(bData["warp"]) + 1 do
  36.             if k == xspot2 then
  37.                mon.write(bData["warp"])
  38.             else
  39.                mon.write(" ")
  40.             end
  41.          end
  42.       else
  43.          for i = bData["xmin"], bData["xmax"] do
  44.             mon.write(" ")
  45.          end
  46.       end
  47.    end
  48.    mon.setBackgroundColor(colors.black)
  49. end
  50.      
  51. function screen()
  52.    local currColor
  53.    for z,data in pairs(button) do
  54.       if data["name"] == "vide" then
  55.         currColor = colors.red
  56.       else
  57.         currColor = colors.lime
  58.       end
  59.       fill(currColor, data)
  60.    end
  61. end
  62.                                              
  63. function checkxy(x, y)
  64.    for name, data in pairs(button) do
  65.       if y>=data["ymin"] and  y <= data["ymax"] then
  66.          if x>=data["xmin"] and x<= data["xmax"] then
  67.             cb.setCommand("warps " .. data["warp"] .. " @p[c=1]")
  68.             cb.runCommand()
  69.             return true
  70.          end
  71.       end
  72.    end
  73.    return false
  74. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement