From 2a4656ccb08e38ddc7f3539e6d5ced25161fb270 Mon Sep 17 00:00:00 2001 From: Igor Timofeev Date: Tue, 6 Oct 2015 18:49:02 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=B1=D0=B5=D1=82=D1=83=20CodeDoor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Applications/CodeDoor/CodeDoor.lua | 177 +++++++++++++++++++++++++++++ Applications/CodeDoor/Icon.pic | Bin 0 -> 265 bytes MineOS/OS.lua | 3 +- lib/ECSAPI.lua | 9 ++ 4 files changed, 188 insertions(+), 1 deletion(-) create mode 100644 Applications/CodeDoor/CodeDoor.lua create mode 100644 Applications/CodeDoor/Icon.pic diff --git a/Applications/CodeDoor/CodeDoor.lua b/Applications/CodeDoor/CodeDoor.lua new file mode 100644 index 00000000..db4eb6a1 --- /dev/null +++ b/Applications/CodeDoor/CodeDoor.lua @@ -0,0 +1,177 @@ +local rs +local sides = require("sides") +local event = require("event") + +-- if not component.isAvailable("redstone") then +-- ecs.error("This program requires Redstone I/O block or Redstone Card to work.") +-- return +-- else +-- rs = require("redstone") +-- end + +------------------------------------------------------------------------------------------------------------ + +local colors = { + background = 0x202020, + borders = 0xFFDD00, +} + +------------------------------------------------------------------------------------------------------------ + +local keyPad = { + {"1", "2", "3"}, + {"4", "5", "6"}, + {"7", "8", "9"}, + {"*", "0", "#"}, +} + +local xSize, ySize +local buttons = {} +local biometry = {} +local input +local password = "12345" +local nicknames = { + "IgorTimofeev", + "IT2", +} + +local function drawKeyPad(x, y) + local xPos, yPos = x, y + buttons = {} + for j = 1, #keyPad do + xPos = x + for i = 1, #keyPad[j] do + ecs.drawFramedButton(xPos, yPos, 5, 3, keyPad[j][i], colors.borders) + buttons[keyPad[j][i]] = {xPos, yPos, xPos + 4, yPos + 2} + xPos = xPos + 6 + end + yPos = yPos + 3 + end +end + +local function visualScan(x, y, timing) + local yPos = y + + gpu.set(x, yPos, "╞══════════╡") + yPos = yPos - 1 + os.sleep(timing) + + for i = 1, 3 do + gpu.set(x, yPos, "╞══════════╡") + gpu.set(x, yPos + 1, "│ │") + yPos = yPos - 1 + os.sleep(timing) + end + + yPos = yPos + 2 + + for i = 1, 3 do + gpu.set(x, yPos, "╞══════════╡") + gpu.set(x, yPos - 1, "│ │") + yPos = yPos + 1 + os.sleep(timing) + end + gpu.set(x, yPos - 1, "│ │") +end + +local function infoPanel(info, background, foreground) + ecs.square(1, 1, xSize, 3, background) + ecs.colorText(math.ceil(xSize / 2 - unicode.len(info) / 2), 2, foreground, info) +end + +local function drawAll() + local xPos, yPos = 3, 5 + + --Как прописывать знаки типа © § ® ™ + + infoPanel(input or "CodeDoor Protection Enabled", colors.borders, colors.background) + + --кейпад + gpu.setBackground(colors.background) + drawKeyPad(xPos, yPos) + + --Био + xPos = xPos + 18 + ecs.border(xPos, yPos, 12, 6, colors.background, colors.borders) + ecs.square(xPos + 5, yPos + 2, 2, 2, colors.borders) + gpu.setBackground(colors.background) + biometry = {xPos, yPos, xPos + 11, yPos + 5} + + --Био текст + yPos = yPos + 7 + xPos = xPos + 1 + gpu.set(xPos + 3, yPos, "ECS®") + gpu.set(xPos + 1, yPos + 1, "Security") + gpu.set(xPos + 1, yPos + 2, "Systems™") + +end + +local function checkNickname(name) + for i = 1, #nicknames do + if name == nicknames[i] then + return true + end + end + return false +end + +------------------------------------------------------------------------------------------------------------ + +xSize, ySize = gpu.getResolution() + +ecs.prepareToExit(colors.background) + +drawAll() + +while true do + local e = {event.pull()} + if e[1] == "touch" then + for key in pairs(buttons) do + if ecs.clickedAtArea(e[3], e[4], buttons[key][1], buttons[key][2], buttons[key][3], buttons[key][4]) then + ecs.square(buttons[key][1], buttons[key][2], 5, 3, colors.borders) + gpu.setForeground(colors.background) + gpu.set(buttons[key][1] + 2, buttons[key][2] + 1, key) + os.sleep(0.2) + + if key == "*" then + input = nil + drawAll() + elseif key == "#" then + drawAll() + if input == password then + infoPanel("Access granted!", ecs.colors.green, 0xFFFFFF) + else + infoPanel("Access denied!", ecs.colors.red, 0xFFFFFF) + end + input = nil + os.sleep(1) + drawAll() + else + input = (input or "") .. key + drawAll() + end + + break + end + end + + if ecs.clickedAtArea(e[3], e[4], biometry[1], biometry[2], biometry[3], biometry[4]) then + visualScan(biometry[1], biometry[2] + 4, 0.08) + if checkNickname(e[6]) then + infoPanel("Welcome, " .. e[6], ecs.colors.green, 0xFFFFFF) + else + infoPanel("Access denied!", ecs.colors.red, 0xFFFFFF) + end + os.sleep(1) + drawAll() + end + end +end + + + + + + + + diff --git a/Applications/CodeDoor/Icon.pic b/Applications/CodeDoor/Icon.pic new file mode 100644 index 0000000000000000000000000000000000000000..f4b03062f598aceb0ee0dee4d8dedd03fe30bb9a GIT binary patch literal 265 zcmeCoPtHt};^JUo0E7Pu|L=ksFj^PN$3-i^^ucI3IXRFPLny5PrH#<|#xOoiAB={I go519uv?&_j4917)gV9iNbC^7owm{=s!uT+K0JxDtH~;_u literal 0 HcmV?d00001 diff --git a/MineOS/OS.lua b/MineOS/OS.lua index 52995843..a2957d13 100644 --- a/MineOS/OS.lua +++ b/MineOS/OS.lua @@ -349,7 +349,8 @@ local function createDesktopShortCuts() "Robot.app", "Shooting.app", "Shop.app", - "TetrisAlpha.app" + "TetrisAlpha.app", + "CodeDoor.app", } local dockApps = { diff --git a/lib/ECSAPI.lua b/lib/ECSAPI.lua index a0097bd7..6d241462 100644 --- a/lib/ECSAPI.lua +++ b/lib/ECSAPI.lua @@ -490,6 +490,15 @@ function ECSAPI.border(x, y, width, height, back, fore) end end +--Кнопка в виде текста в рамке +function ECSAPI.drawFramedButton(x, y, width, height, text, color) + ECSAPI.border(x, y, width, height, gpu.getBackground(), color) + gpu.fill(x + 1, y + 1, width - 2, height - 2, " ") + x = x + math.floor(width / 2 - unicode.len(text) / 2) + y = y + math.floor(width / 2 - 1) + gpu.set(x, y, text) +end + --Юникодовский разделитель function ECSAPI.separator(x, y, width, back, fore) ECSAPI.colorTextWithBack(x, y, fore, back, string.rep("─", width))