Advertisement
faedani

Gestión de esencias Minecraft: Computercraft/Thaumcraft 2/2

May 25th, 2015
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.04 KB | None | 0 0
  1.  --programa para la tablet
  2.     rednet.open("back")
  3.     local EsenciaPCID = 2
  4.     local boton = {alto = 3, ancho = 15, fondo = colors.red, seleccionado = colors.green}
  5.     local info = { nombre = "INFO", x = 8, y = 5, seleccionado = true}
  6.     local llena = { nombre = "LLENA", x = 8, y = 11}
  7.     local botones = {info, llena}
  8.     local mensaje
  9.      
  10.     function enviaMsg(mensaje)
  11.             rednet.send(EsenciaPCID,mensaje)
  12.     end
  13.      
  14.     function info:action()
  15.       botones.info = true
  16.       info.seleccionado = true
  17.       llena.seleccionado = false
  18.       enviaMsg("info")
  19.     end
  20.      
  21.     function llena:action()
  22.       botones.info = false
  23.       info.seleccionado = false
  24.       llena.seleccionado = true
  25.       enviaMsg("llena")
  26.     end
  27.      
  28.     function enBoton(b,x,y)
  29.             local x1 = b.x + boton.ancho
  30.             local y1 = b.y + boton.alto
  31.             return x >= b.x and x <= x1 and y >= b.y and y <= y1
  32.     end
  33.      
  34.     function presionaBoton(x,y)
  35.             for _, b in ipairs(botones) do
  36.                     if enBoton(b,x,y) then
  37.                             b.action()
  38.                     end
  39.             end
  40.     end
  41.      
  42.     function dibujaBoton(b)
  43.     if b.seleccionado == true then
  44.           term.setBackgroundColor(boton.seleccionado)
  45.         else
  46.           term.setBackgroundColor(boton.fondo)
  47.         end
  48.         term.setTextColor(colors.white)
  49.         for n = 0, boton.alto - 1 do
  50.         term.setCursorPos(b.x, b.y + n)
  51.         term.write(string.rep(" ", boton.ancho - 1))
  52.       end
  53.       local y1 = b.y + (boton.alto - 1) / 2
  54.       local x1 = b.x + (boton.ancho - #b.nombre) / 2
  55.       term.setCursorPos(x1, y1)
  56.       term.write(b.nombre)
  57.       term.setBackgroundColor(colors.black)
  58.     end
  59.      
  60.     while true do
  61.             for _, b in ipairs(botones) do
  62.             dibujaBoton(b)
  63.             end
  64.      
  65.             local evento,ID,x,y = os.pullEvent()
  66.                     if evento == "mouse_click" then
  67.                             presionaBoton(x,y)
  68.                     end
  69.     end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement