Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.pullEvent = os.pullEventRaw
- -- PaymentOption's door lock.
- nScreenWidth, nScreenHeight = term.getSize()
- sUsername = "Payment"
- sPassword = "8907022"
- -- GUI Methods --
- function ClearScreen()
- term.clear()
- term.setCursorPos( 1, 1 )
- end
- -- +--------+
- -- | |
- -- +--------+
- function PrintBorder( )
- local function PrintHorizontalLine( x, y)
- term.setCursorPos( x, y )
- term.write( "+" .. string.rep( "-", nScreenWidth - 2 ) .. "+" )
- end
- PrintHorizontalLine( 1, 1 ) -- Draw the top line.
- -- Draw the center lines | |
- for nHeight = 2, nScreenHeight - 1 do
- term.setCursorPos( 1, nHeight )
- term.write( "|" )
- term.setCursorPos( nScreenWidth, nHeight )
- term.write( "|" )
- end
- --
- PrintHorizontalLine( 1, nScreenHeight ) -- Draw the bottom line.
- end
- -- xPos, yPos are the position of the upper left hand corner of the box.
- function PrintInfoBox( xPos, yPos, nBoxWidth, nBoxHeight )
- term.setCursorPos( xPos, yPos )
- local function PrintHorizontalLine( x, y )
- term.setCursorPos( x, y )
- term.write( "+" .. string.rep( "-", nBoxWidth - 2 ) .. "+" )
- end
- PrintHorizontalLine( xPos, yPos ) -- Draw the top line of the box.
- -- Draw the body of the box. | |
- for nHeight = yPos + 1, ( nBoxHeight + yPos ) - 1 do
- term.setCursorPos( xPos, nHeight )
- term.write( "|" )
- term.setCursorPos( xPos + nBoxWidth - 1, nHeight )
- term.write( "|" )
- end
- --
- PrintHorizontalLine( xPos, yPos + nBoxHeight )
- end
- -- bExactCenter determines whether or not the box should be printed in the center width and height, or on the centered width but specified height.
- function PrintCenteredInfoBox( yPos, nBoxWidth, nBoxHeight, bExactCenter )
- if not yPos and not bExactCenter then
- error( "Cannot draw a non centered box with a nil y position." )
- end
- -- If the box should be in the exact center of the screen.
- if bExactCenter then
- PrintInfoBox( nScreenWidth/2 - nBoxWidth/2, nScreenHeight/2 - nBoxHeight/2, nBoxWidth, nBoxHeight )
- -- If the box shouldn't be in the exact center of the screen, but rather on a specified y coordinate.
- else
- PrintInfoBox( nScreenWidth/2 - nBoxWidth/2, yPos, nBoxWidth, nBoxHeight )
- end
- end
- -- Draw the PaymentOption logo at the x and y
- function PrintPaymentLogo( x, y, bCentered )
- if bCentered then
- x = nScreenWidth/2 - string.len( "| __/ _` | | | | '_ ` _ \ / _ | '_ \| __|" )/2
- end
- local function Reposition( nY_Offset )
- term.setCursorPos( x, y + nY_Offset )
- end
- -- Begin the drawing.
- Reposition( 0 )
- print( "______ _ " )
- Reposition( 1 )
- print( "| ___ \\ | | " )
- Reposition( 2 )
- print( "| |_/ __ _ _ _ _ __ ___ ___ _ __ | |_ " )
- Reposition( 3 )
- print( "| __/ _' | | | | '_ ' _ \\ / _ | '_ \\| __|" )
- Reposition( 4 )
- print( "| | | (_| | |_| | | | | | | __| | | | |_ " )
- Reposition( 5 )
- print( "\\_| \\__,_|\\__, |_| |_| |_|\\___|_| |_|\\__|" )
- Reposition( 6 )
- print( " __/ | " )
- Reposition( 7 )
- print( " |___/ " )
- end
- function PrintLoginBox()
- PrintCenteredInfoBox( 10, 25, 6, false )
- local xPos_ForUsername = ( nScreenWidth/2 - 25/2 ) + 1
- local yPos_ForUsername = 12
- term.setCursorPos( xPos_ForUsername, yPos_ForUsername )
- print( "Username: " )
- term.setCursorPos( xPos_ForUsername, yPos_ForUsername + 1 )
- print( "Password: " )
- end
- function PrintWelcomeScreen()
- PrintBorder()
- cPrint( 3, "Welcome" )
- PrintPaymentLogo( nil, 4, true )
- end
- function PrintRejectionScreen()
- PrintBorder()
- cPrint( 3, "You are not" )
- PrintPaymentLogo( nil, 4, true )
- end
- -----------------
- -- Utility methods --
- function cPrint( nHeight, sString )
- term.setCursorPos( nScreenWidth/2 - string.len( sString )/2, nHeight )
- term.write( sString )
- end
- function limitRead( nLength, cReplaceChar )
- term.setCursorBlink( true )
- nLength = nLength or -1 -- -1 is unlimited
- sReturnString = ""
- xPos, yPos = term.getCursorPos()
- while true do
- event, char = os.pullEvent()
- if nLength ~= -1 and string.len( sReturnString ) >= nLength then term.setCursorBlink( false ); return sReturnString end -- Length check
- if event == "char" then sReturnString = sReturnString .. char
- elseif event == "key" and char == 28 then term.setCursorBlink( false ); return sReturnString -- Enter
- elseif event == "key" and char == 14 then -- Backspace
- term.setCursorPos( xPos, yPos )
- term.write( string.rep( " ", string.len( sReturnString ) ) )
- sReturnString = string.sub( sReturnString, 1, string.len( sReturnString )-1 )
- term.setCursorPos( xPos, yPos )
- if not cReplaceChar then term.write( sReturnString )
- else term.write( string.rep( cReplaceChar, string.len( sReturnString ) ) ) end
- end
- term.setCursorPos( xPos, yPos )
- term.write( string.rep( " ", string.len( sReturnString ) ) )
- term.setCursorPos( xPos, yPos )
- if not cReplaceChar then term.write( sReturnString )
- else term.write( string.rep( cReplaceChar, string.len( sReturnString ) ) ) end
- end
- end
- ---------------------
- -- Information grabbing methods --
- -- RETURNS:
- -- True or false depending if the given info is correct.
- function GetLoginInfo()
- local xPos_ForUsername = ( nScreenWidth/2 - 25/2 ) + string.len( "Username: " ) + 1
- local yPos_ForUsername = 12
- local sGivenUsername = ""
- local sGivenPassword = ""
- -- Checks if the given information is accurate.
- local function CheckInformation( sName, sPass )
- if sName == sUsername and sPass == sPassword then
- return true
- else
- return false
- end
- end
- -- Get the login information.
- -- Username
- term.setCursorPos( xPos_ForUsername, yPos_ForUsername )
- sGivenUsername = limitRead( 11 )
- -- Password
- term.setCursorPos( xPos_ForUsername, yPos_ForUsername + 1 )
- sGivenPassword = limitRead( 11, '*' )
- if CheckInformation( sGivenUsername, sGivenPassword ) then
- return true
- else
- return false
- end
- end
- ----------------------------------
- -- Main function --
- function RunProgram()
- ClearScreen()
- PrintBorder()
- PrintPaymentLogo( nil, 2, true )
- PrintLoginBox()
- if GetLoginInfo() then
- ClearScreen()
- PrintWelcomeScreen()
- sleep( 3 )
- ClearScreen()
- print( os.version() )
- else
- ClearScreen()
- PrintRejectionScreen()
- sleep( 3 )
- os.reboot()
- end
- end
- -------------------
- RunProgram()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement