Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --First time setup/load settings
- if not fs.exists("settings") then
- if not fs.exists("button") then
- shell.run("pastebin", "get", "Kd7gQKLe", "button")
- shell.run("pastebin", "get", "KrfYp2Jf", "splash")
- end
- data = {first = true, pin = " ", name = " "}
- save = function()
- file = fs.open("settings", "w")
- file.write(textutils.serialise(data))
- file.close()
- end
- save()
- else
- save = function()
- file = fs.open("settings", "w")
- file.write(textutils.serialise(data))
- file.close()
- end
- file = fs.open("settings", "r")
- data = textutils.unserialise(file.readAll())
- file.close()
- end
- --Variable declaraction
- rednet.open("top")
- splash = paintutils.loadImage("splash")
- shell.run("button")
- size = {x = 26, y = 20}
- loggedIn = false
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- --Changes table button states
- function tState(_t, _s)
- for _, button in pairs(_t) do
- button:set("enabled", _s)
- end
- end
- --Create number pad buttons
- pinButtons = {}
- local i = 0
- for _yy = 1, 3 do
- for _xx = 0, 2 do
- i = i + 1
- pinButtons[i] = newButton((9 + (_xx * 3)), (11 + (_yy * 2)), 1, 1, tostring(i), "f", "0", tostring(i))
- end
- end
- pinButtons[11] = newButton(12, 19, 1, 1, "0", "f", "0", 0)
- pinButtons[10] = newButton (9, 19, 1, 1, " ", "0", "d", "enter")
- pinButtons[12] = newButton (15, 19, 1, 1, " ", "0", "e", "back")
- tState(pinButtons, false)
- --Create main menu buttons
- menuButtons = {}
- menuButtons[1] = newButton(3, 13, 12, 7, " $$ Send $$ ", colors.white, colors.blue, "send")
- menuButtons[2] = newButton(18, 13, 6, 3, "Update", colors.white, colors.green, "update")
- menuButtons[3] = newButton(18, 17, 6, 3, "Exit", colors.white, colors.red, "exit")
- tState(menuButtons, false)
- --Create Confirm Buttons
- confirmButtons = {}
- confirmButtons[1] = newButton(3, 10, 9, 5, "Confirm", colors.white, colors.green, "confirm")
- confirmButtons[2] = newButton(14, 10, 9 , 5, "Cancel", colors.white, colors.red, "deny")
- tState(confirmButtons, false)
- --Number pad gets numbers intill enter is pressed
- function pad(header)
- local order = ""
- local cTest = true
- tState(pinButtons, true)
- while cTest do
- term.clear()
- term.setCursorPos(math.floor((size.x / 2) - (#header / 2)), 4)
- term.write(header)
- term.setCursorPos(math.floor((size.x / 2) - (#order / 2)), 6)
- term.write(order)
- drawDummyButtons("t")
- local _e, _m, mx, my = os.pullEvent("mouse_click")
- local _a = checkDummy(mx, my)
- if _a then
- if _a == "enter" then
- cTest = false
- tState(pinButtons, false)
- return order
- elseif _a == "back" then
- order = string.sub(order, 1, #order - 1)
- else
- order = order .. _a
- end
- end
- end
- tState(pinButtons, false)
- end
- --Gets alphanumerical/enter/backspace
- function getKey()
- while true do
- local _e, character = os.pullEvent()
- if _e == "char" then
- return character
- elseif _e == "key" then
- if character == 28 then
- return "enter"
- elseif character == 14 then
- return "back"
- end
- end
- end
- end
- --Opens text input field with header
- function getName(_t)
- local _check = true
- local name = ""
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- while _check do
- term.clear()
- term.setCursorPos((13 - math.floor(#_t / 2)), 5)
- term.write(_t)
- term.setCursorPos(math.floor((size.x / 2) - (#name / 2)), 7)
- term.write(name)
- local char = getKey()
- if char == "enter" then
- _check = false
- return name
- elseif char == "back" then
- if #name > 0 then
- name = string.sub(name, 1, #name - 1)
- end
- else
- name = name .. char
- end
- end
- end
- --Gets balance
- function getBal()
- local balMsg = {
- command = "get balance",
- }
- rednet.broadcast(balMsg, "VCOB")
- local _ID, bal = rednet.receive("VCOBR")
- return bal
- end
- --Main Loop
- while true do
- --First time account creation
- if data.first then
- --Name input
- data.name = getName("Enter your name:")
- --Pin creation
- term.clear()
- local newPin = pad("Create a pin:")
- data.pin = newPin
- local newAccMsg = {
- pin = data.pin,
- name = data.name,
- command = "create"
- }
- rednet.broadcast(newAccMsg, "VCOB")
- id, NAC = rednet.receive("NAC")
- if NAC == "success" then
- data.first = false
- save()
- loggedIn = true
- os.setComputerLabel(data.name .. "'s bank card")
- end
- else
- if loggedIn then
- --Main screen
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- term.clear()
- data.balance = getBal()
- tState(menuButtons, true)
- drawButtons("t")
- paintutils.drawFilledBox(3, 9, 23, 11, colors.lightGray)
- term.setTextColor(colors.black)
- term.setCursorPos(4,10)
- term.setBackgroundColor(colors.lightGray)
- term.write("Balance:")
- term.setCursorPos((22 - #tostring(data.balance)), 10)
- term.write(tostring("$" .. data.balance))
- term.setBackgroundColor(colors.white)
- paintutils.drawBox(3, 3, 23, 6, colors.lightBlue)
- paintutils.drawImage(splash, 3, 3)
- paintutils.drawFilledBox(1,1,26,1, colors.black)
- term.setTextColor(colors.white)
- term.setCursorPos(((size.x / 2) - (#data.name / 2)),1)
- term.write(data.name)
- local _e, _m, mx, my = os.pullEvent("mouse_click")
- local _m = checkButtons(mx, my)
- if _m then
- if _m == "update" then
- --:-)
- elseif _m == "exit" then
- --Reboot device
- term.setCursorPos(1,1)
- term.setTextColor(colors.white)
- shell.run("reboot")
- elseif _m == "send" then
- --Send money
- tState(menuButtons, false)
- local reciever = getName("Send to:")
- term.clear()
- local amount = tonumber(pad("Amount:"))
- if amount > 0 then
- term.clear()
- tState(menuButtons, false)
- tState(pinButtons, false)
- tState(confirmButtons, true)
- drawButtons("t")
- local confMess = "Send $" .. tostring(amount) .. " too " .. reciever .. "?"
- term.setCursorPos(math.floor((size.x / 2) - (#confMess / 2)), 5)
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- term.write(confMess)
- local _x, _y, mx, my = os.pullEvent("mouse_click")
- local _m = checkButtons(mx, my)
- if _m == "confirm" then
- local sendMsg = {
- command = "send",
- recName = reciever,
- sum = amount,
- pin = data.pin
- }
- rednet.broadcast(sendMsg, "VCOB")
- end
- tState(confirmButtons, false)
- end
- tState(menuButtons, true)
- end
- end
- else
- --Log in
- local answer = pad(" ")
- if answer == data.pin then
- loggedIn = true
- else
- term.setCursorPos(9, 9)
- term.setTextColor(colors.red)
- term.write("Incorrect")
- term.setTextColor(colors.black)
- sleep(2)
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement