Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- ZONA A EDITAR
- local _password_ = "5926" -- Password del sistema
- local _password_length_ = 4 -- Longitud de la password
- local _color_buttons_ = colors.black -- Color default de los botones
- local _color_active_buttons_ = colors.lime -- Color cuando haces click en el boton
- local _color_text = colors.white -- Color de texto
- local _color_background = colors.black -- Color de fondo
- local _redstone_output_ = "bottom" -- Salida de redstone signal
- local _redstone_output_time_ = 5 -- Tiempo de redstone signal
- -- FIN DE ZONA A EDITAR
- -- NO MODIFICAR
- -- TODO EL SISTEMA ESTA PARAMETRIZADO
- -- GRACIAS
- -- System Vars
- local side = nil
- for _, s in pairs(rs.getSides()) do
- if peripheral.getType(s) == "monitor" then
- side = s
- end
- end
- if not side then
- print("No se ha encontrado monitor")
- print("Porfavor, ponga uno.")
- error()
- end
- local button={}
- local tmp_password = {""}
- local password = {""}
- local x
- local y
- local mon = peripheral.wrap(side)
- -- Main Function
- function main()
- mon.setTextScale(1)
- mon.setTextColor(_color_text)
- mon.setBackgroundColor(_color_background)
- if (fs.exists("tasks") == false) then
- writeTask("_clear_")
- end
- x, y = mon.getSize()
- fillTable()
- checkTasks()
- while true do
- mon.clear()
- screen()
- local e,side,x,y = os.pullEvent("monitor_touch")
- print(x..":"..y)
- checkxy(x,y)
- sleep(.1)
- end
- end
- -- Add Button array
- function setTable(name, value, func, xmin, xmax, ymin, ymax)
- button[name] = {}
- button[name]["value"] = value
- button[name]["func"] = func
- button[name]["active"] = false
- button[name]["xmin"] = xmin
- button[name]["ymin"] = ymin
- button[name]["xmax"] = xmax
- button[name]["ymax"] = ymax
- end
- -- ClickButton handle
- function clickButton(name)
- tmp_password[#tmp_password+1] = name
- fill(name, _color_active_buttons_, button[name])
- sleep(.1)
- fill(name, _color_buttons_, button[name])
- if ((#tmp_password-1) == _password_length_) then
- checkPassword('checkPassword')
- end
- end
- -- CHECK PASSWORD
- function checkPassword(name)
- local tmp = ""
- for i = 1, y do
- if tmp_password[i] ~= nil then
- tmp = tmp .. tmp_password[i]
- end
- end
- if tmp == _password_ then
- writeTask("open_door")
- os.reboot()
- else
- os.reboot()
- end
- end
- -- WRITE TASK
- function writeTask(task)
- fs.delete("tasks")
- local file = fs.open("tasks", "w")
- file.write(task)
- file.close()
- end
- -- CHECKTASK ON STARTUP
- function checkTasks()
- local file = fs.open("tasks", "r")
- local data = file.readAll()
- if (data == "open_door") then
- redstone.setOutput(_redstone_output_, true)
- sleep(_redstone_output_time_)
- redstone.setOutput(_redstone_output_, false)
- writeTask("_clear_")
- os.reboot()
- end
- end
- -- BASIC STRUCTURE
- function fillTable()
- setTable("1", "1",clickButton, 1, 2, 1, 1)
- setTable("2", "2",clickButton, 3, 4, 1, 1)
- setTable("3", "3",clickButton, 5, 6, 1, 1)
- setTable("4", "4",clickButton, 1, 2, 3, 3)
- setTable("5", "5",clickButton, 3, 4, 3, 3)
- setTable("6", "6",clickButton, 5, 6, 3, 3)
- setTable("7", "7",clickButton, 1, 2, 5, 5)
- setTable("8", "8",clickButton, 3, 4, 5, 5)
- setTable("9", "9",clickButton, 5, 6, 5, 5)
- setTable("enviar", "enviar", checkPassword, 20, 30, 17, 19)
- end
- -- Print button
- function fill(text, color, bData)
- mon.setBackgroundColor(color)
- local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2)
- local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(text)) /2) +1
- for j = bData["ymin"], bData["ymax"] do
- mon.setCursorPos(bData["xmin"], j)
- if j == yspot then
- for k = 0, bData["xmax"] - bData["xmin"] - string.len(text) +1 do
- if k == xspot then
- mon.write(text)
- else
- mon.write(" ")
- end
- end
- else
- for i = bData["xmin"], bData["xmax"] do
- mon.write(" ")
- end
- end
- end
- mon.setBackgroundColor(colors.black)
- end
- -- Print all buttons
- function screen()
- local currColor
- for name,data in pairs(button) do
- local on = data["active"]
- fill(name, _color_buttons_, data)
- end
- end
- -- internal click function
- function checkxy(x, y)
- for name, data in pairs(button) do
- if y>=data["ymin"] and y <= data["ymax"] then
- if x>=data["xmin"] and x<= data["xmax"] then
- data["func"](name)
- data["active"] = not data["active"]
- end
- end
- end
- end
- function heading(text)
- w, h = mon.getSize()
- mon.setCursorPos((w-string.len(text))/2+1, 1)
- mon.write(text)
- end
- -- Call Main program
- main()
- -- TODOS LOS DERECHOS IFDS MaTaXeToS
Add Comment
Please, Sign In to add comment