Advertisement
lewisholcombe

Reception2

Mar 29th, 2013
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.70 KB | None | 0 0
  1. -------------------------------
  2. -- ------- Variables ------- --
  3. -------------------------------
  4. local screenX, screenY = term.getSize()
  5. local admin = { username = 'admin', password = 'pass' } -- admin details to view bookings
  6. local logged = false
  7. local name, time, reason = '', '', ''
  8. local menu = 'Reception Desk'
  9. local bookingsFile = 'bookings.txt'
  10. local bookings = {}
  11. os.pullEvent = os.pullEventRaw
  12.  
  13. -- Background
  14. local bg = {[1]={[1]=2048,[2]=2048,[3]=2048,[4]=2048,[5]=2048,[6]=2048,[7]=2048,[8]=2048,[9]=2048,[10]=2048,[11]=2048,[12]=2048,[13]=2048,[14]=2048,[15]=2048,[16]=2048,[17]=2048,[18]=2048,[19]=2048,[20]=2048,[21]=2048,[22]=2048,[23]=2048,[24]=2048,[25]=2048,[26]=2048,[27]=2048,[28]=2048,[29]=2048,[30]=2048,[31]=2048,[32]=2048,[33]=2048,[34]=2048,[35]=2048,[36]=2048,[37]=2048,[38]=2048,[39]=2048,[40]=2048,[41]=2048,[42]=2048,[43]=2048,[44]=2048,[45]=2048,[46]=2048,[47]=2048,[48]=2048,[49]=2048,[50]=2048,[51]=2048,},[2]={[1]=2048,[2]=2048,[3]=2048,[4]=2048,[5]=2048,[6]=2048,[7]=2048,[8]=2048,[9]=2048,[10]=2048,[11]=2048,[12]=2048,[13]=2048,[14]=2048,[15]=2048,[16]=2048,[17]=2048,[18]=2048,[19]=2048,[20]=2048,[21]=2048,[22]=2048,[23]=2048,[24]=2048,[25]=2048,[26]=2048,[27]=2048,[28]=2048,[29]=2048,[30]=2048,[31]=2048,[32]=2048,[33]=2048,[34]=2048,[35]=2048,[36]=2048,[37]=2048,[38]=2048,[39]=2048,[40]=2048,[41]=2048,[42]=2048,[43]=2048,[44]=2048,[45]=2048,[46]=2048,[47]=2048,[48]=2048,[49]=2048,[50]=2048,[51]=2048,},[3]={[1]=2048,[2]=2048,[3]=2048,[4]=2048,[5]=2048,[6]=2048,[7]=2048,[8]=2048,[9]=2048,[10]=2048,[11]=2048,[12]=2048,[13]=2048,[14]=2048,[15]=2048,[16]=2048,[17]=2048,[18]=2048,[19]=2048,[20]=2048,[21]=2048,[22]=2048,[23]=2048,[24]=2048,[25]=2048,[26]=2048,[27]=2048,[28]=2048,[29]=2048,[30]=2048,[31]=2048,[32]=2048,[33]=2048,[34]=2048,[35]=2048,[36]=2048,[37]=2048,[38]=2048,[39]=2048,[40]=2048,[41]=2048,[42]=2048,[43]=2048,[44]=2048,[45]=2048,[46]=2048,[47]=2048,[48]=2048,[49]=2048,[50]=2048,[51]=2048,},[4]={[1]=512,[2]=512,[3]=512,[4]=512,[5]=512,[6]=512,[7]=512,[8]=512,[9]=512,[10]=512,[11]=512,[12]=512,[13]=512,[14]=512,[15]=512,[16]=512,[17]=512,[18]=512,[19]=512,[20]=512,[21]=512,[22]=512,[23]=512,[24]=512,[25]=512,[26]=512,[27]=512,[28]=512,[29]=512,[30]=512,[31]=512,[32]=512,[33]=512,[34]=512,[35]=512,[36]=512,[37]=512,[38]=512,[39]=512,[40]=512,[41]=512,[42]=512,[43]=512,[44]=512,[45]=512,[46]=512,[47]=512,[48]=512,[49]=512,[50]=512,[51]=512,},[5]={[1]=512,[2]=512,[3]=512,[4]=512,[5]=512,[6]=512,[7]=512,[8]=512,[9]=512,[10]=512,[11]=512,[12]=512,[13]=512,[14]=512,[15]=512,[16]=512,[17]=512,[18]=512,[19]=512,[20]=512,[21]=512,[22]=512,[23]=512,[24]=512,[25]=512,[26]=512,[27]=512,[28]=512,[29]=512,[30]=512,[31]=512,[32]=512,[33]=512,[34]=512,[35]=512,[36]=512,[37]=512,[38]=512,[39]=512,[40]=512,[41]=512,[42]=512,[43]=512,[44]=512,[45]=512,[46]=512,[47]=512,[48]=512,[49]=512,[50]=512,[51]=512,},[6]={[1]=512,[2]=512,[3]=512,[4]=512,[5]=512,[6]=512,[7]=512,[8]=512,[9]=512,[10]=512,[11]=512,[12]=512,[13]=512,[14]=512,[15]=512,[16]=512,[17]=512,[18]=512,[19]=512,[20]=512,[21]=512,[22]=512,[23]=512,[24]=512,[25]=512,[26]=512,[27]=512,[28]=512,[29]=512,[30]=512,[31]=512,[32]=512,[33]=512,[34]=512,[35]=512,[36]=512,[37]=512,[38]=512,[39]=512,[40]=512,[41]=512,[42]=512,[43]=512,[44]=512,[45]=512,[46]=512,[47]=512,[48]=512,[49]=512,[50]=512,[51]=512,},[7]={[1]=512,[2]=512,[3]=512,[4]=512,[5]=512,[6]=512,[7]=512,[8]=512,[9]=512,[10]=512,[11]=512,[12]=512,[13]=512,[14]=512,[15]=512,[16]=512,[17]=512,[18]=512,[19]=512,[20]=512,[21]=512,[22]=512,[23]=512,[24]=512,[25]=512,[26]=512,[27]=512,[28]=512,[29]=512,[30]=512,[31]=512,[32]=512,[33]=512,[34]=512,[35]=512,[36]=512,[37]=512,[38]=512,[39]=512,[40]=512,[41]=512,[42]=512,[43]=512,[44]=512,[45]=512,[46]=512,[47]=512,[48]=512,[49]=512,[50]=512,[51]=512,},[8]={[1]=512,[2]=512,[3]=512,[4]=512,[5]=512,[6]=512,[7]=512,[8]=512,[9]=512,[10]=512,[11]=512,[12]=512,[13]=512,[14]=512,[15]=512,[16]=512,[17]=512,[18]=512,[19]=512,[20]=512,[21]=512,[22]=512,[23]=512,[24]=512,[25]=512,[26]=512,[27]=512,[28]=512,[29]=512,[30]=512,[31]=512,[32]=512,[33]=512,[34]=512,[35]=512,[36]=512,[37]=512,[38]=512,[39]=512,[40]=512,[41]=512,[42]=512,[43]=512,[44]=512,[45]=512,[46]=512,[47]=512,[48]=512,[49]=512,[50]=512,[51]=512,},[9]={[1]=512,[2]=512,[3]=512,[4]=512,[5]=512,[6]=512,[7]=512,[8]=512,[9]=512,[10]=512,[11]=512,[12]=512,[13]=512,[14]=512,[15]=512,[16]=512,[17]=512,[18]=512,[19]=512,[20]=512,[21]=512,[22]=512,[23]=512,[24]=512,[25]=512,[26]=512,[27]=512,[28]=512,[29]=512,[30]=512,[31]=512,[32]=512,[33]=512,[34]=512,[35]=512,[36]=512,[37]=512,[38]=512,[39]=512,[40]=512,[41]=512,[42]=512,[43]=512,[44]=512,[45]=512,[46]=512,[47]=512,[48]=512,[49]=512,[50]=512,[51]=512,},[10]={[1]=512,[2]=512,[3]=512,[4]=512,[5]=512,[6]=512,[7]=512,[8]=512,[9]=512,[10]=512,[11]=512,[12]=512,[13]=512,[14]=512,[15]=512,[16]=512,[17]=512,[18]=512,[19]=512,[20]=512,[21]=512,[22]=512,[23]=512,[24]=512,[25]=512,[26]=512,[27]=512,[28]=512,[29]=512,[30]=512,[31]=512,[32]=512,[33]=512,[34]=512,[35]=512,[36]=512,[37]=512,[38]=512,[39]=512,[40]=512,[41]=512,[42]=512,[43]=512,[44]=512,[45]=512,[46]=512,[47]=512,[48]=512,[49]=512,[50]=512,[51]=512,},[11]={[1]=512,[2]=512,[3]=512,[4]=512,[5]=512,[6]=512,[7]=512,[8]=512,[9]=512,[10]=512,[11]=512,[12]=512,[13]=512,[14]=512,[15]=512,[16]=512,[17]=512,[18]=512,[19]=512,[20]=512,[21]=512,[22]=512,[23]=512,[24]=512,[25]=512,[26]=512,[27]=512,[28]=512,[29]=512,[30]=512,[31]=512,[32]=512,[33]=512,[34]=512,[35]=512,[36]=512,[37]=512,[38]=512,[39]=512,[40]=512,[41]=512,[42]=512,[43]=512,[44]=512,[45]=512,[46]=512,[47]=512,[48]=512,[49]=512,[50]=512,[51]=512,},[12]={[1]=512,[2]=512,[3]=512,[4]=512,[5]=512,[6]=512,[7]=512,[8]=512,[9]=512,[10]=512,[11]=512,[12]=512,[13]=512,[14]=512,[15]=512,[16]=512,[17]=512,[18]=512,[19]=512,[20]=512,[21]=512,[22]=512,[23]=512,[24]=512,[25]=512,[26]=512,[27]=512,[28]=512,[29]=512,[30]=512,[31]=512,[32]=512,[33]=512,[34]=512,[35]=512,[36]=512,[37]=512,[38]=512,[39]=512,[40]=512,[41]=512,[42]=512,[43]=512,[44]=512,[45]=512,[46]=512,[47]=512,[48]=512,[49]=512,[50]=512,[51]=512,},[13]={[1]=512,[2]=512,[3]=512,[4]=512,[5]=512,[6]=512,[7]=512,[8]=512,[9]=512,[10]=512,[11]=512,[12]=512,[13]=512,[14]=512,[15]=512,[16]=512,[17]=512,[18]=512,[19]=512,[20]=512,[21]=512,[22]=512,[23]=512,[24]=512,[25]=512,[26]=512,[27]=512,[28]=512,[29]=512,[30]=512,[31]=512,[32]=512,[33]=512,[34]=512,[35]=512,[36]=512,[37]=512,[38]=512,[39]=512,[40]=512,[41]=512,[42]=512,[43]=512,[44]=512,[45]=512,[46]=512,[47]=512,[48]=512,[49]=512,[50]=512,[51]=512,},[14]={[1]=512,[2]=512,[3]=512,[4]=512,[5]=512,[6]=512,[7]=512,[8]=512,[9]=512,[10]=512,[11]=512,[12]=512,[13]=512,[14]=512,[15]=512,[16]=512,[17]=512,[18]=512,[19]=512,[20]=512,[21]=512,[22]=512,[23]=512,[24]=512,[25]=512,[26]=512,[27]=512,[28]=512,[29]=512,[30]=512,[31]=512,[32]=512,[33]=512,[34]=512,[35]=512,[36]=512,[37]=512,[38]=512,[39]=512,[40]=512,[41]=512,[42]=512,[43]=512,[44]=512,[45]=512,[46]=512,[47]=512,[48]=512,[49]=512,[50]=512,[51]=512,},[15]={[1]=512,[2]=512,[3]=512,[4]=512,[5]=512,[6]=512,[7]=512,[8]=512,[9]=512,[10]=512,[11]=512,[12]=512,[13]=512,[14]=512,[15]=512,[16]=512,[17]=512,[18]=512,[19]=512,[20]=512,[21]=512,[22]=512,[23]=512,[24]=512,[25]=512,[26]=512,[27]=512,[28]=512,[29]=512,[30]=512,[31]=512,[32]=512,[33]=512,[34]=512,[35]=512,[36]=512,[37]=512,[38]=512,[39]=512,[40]=512,[41]=512,[42]=512,[43]=512,[44]=512,[45]=512,[46]=512,[47]=512,[48]=512,[49]=512,[50]=512,[51]=512,},[16]={[1]=512,[2]=512,[3]=512,[4]=512,[5]=512,[6]=512,[7]=512,[8]=512,[9]=512,[10]=512,[11]=512,[12]=512,[13]=512,[14]=512,[15]=512,[16]=512,[17]=512,[18]=512,[19]=512,[20]=512,[21]=512,[22]=512,[23]=512,[24]=512,[25]=512,[26]=512,[27]=512,[28]=512,[29]=512,[30]=512,[31]=512,[32]=512,[33]=512,[34]=512,[35]=512,[36]=512,[37]=512,[38]=512,[39]=512,[40]=512,[41]=512,[42]=512,[43]=512,[44]=512,[45]=512,[46]=512,[47]=512,[48]=512,[49]=512,[50]=512,[51]=512,},[17]={[1]=512,[2]=512,[3]=512,[4]=512,[5]=512,[6]=512,[7]=512,[8]=512,[9]=512,[10]=512,[11]=512,[12]=512,[13]=512,[14]=512,[15]=512,[16]=512,[17]=512,[18]=512,[19]=512,[20]=512,[21]=512,[22]=512,[23]=512,[24]=512,[25]=512,[26]=512,[27]=512,[28]=512,[29]=512,[30]=512,[31]=512,[32]=512,[33]=512,[34]=512,[35]=512,[36]=512,[37]=512,[38]=512,[39]=512,[40]=512,[41]=512,[42]=512,[43]=512,[44]=512,[45]=512,[46]=512,[47]=512,[48]=512,[49]=512,[50]=512,[51]=512,},[18]={[1]=512,[2]=512,[3]=512,[4]=512,[5]=512,[6]=512,[7]=512,[8]=512,[9]=512,[10]=512,[11]=512,[12]=512,[13]=512,[14]=512,[15]=512,[16]=512,[17]=512,[18]=512,[19]=512,[20]=512,[21]=512,[22]=512,[23]=512,[24]=512,[25]=512,[26]=512,[27]=512,[28]=512,[29]=512,[30]=512,[31]=512,[32]=512,[33]=512,[34]=512,[35]=512,[36]=512,[37]=512,[38]=512,[39]=512,[40]=512,[41]=512,[42]=512,[43]=512,[44]=512,[45]=512,[46]=512,[47]=512,[48]=512,[49]=512,[50]=512,[51]=512,},[19]={[1]=256,[2]=256,[3]=256,[4]=256,[5]=256,[6]=256,[7]=256,[8]=256,[9]=256,[10]=256,[11]=256,[12]=256,[13]=256,[14]=256,[15]=256,[16]=256,[17]=256,[18]=256,[19]=256,[20]=256,[21]=256,[22]=256,[23]=256,[24]=256,[25]=256,[26]=256,[27]=256,[28]=256,[29]=256,[30]=256,[31]=256,[32]=256,[33]=256,[34]=256,[35]=256,[36]=256,[37]=256,[38]=256,[39]=256,[40]=256,[41]=256,[42]=256,[43]=256,[44]=256,[45]=256,[46]=256,[47]=256,[48]=256,[49]=256,[50]=256,[51]=256,},}
  15.  
  16. -------------------------------
  17. -- ------- Functions ------- --
  18. -------------------------------
  19. local function getCenter( l, x1, x2 )
  20. return math.floor( ( ( x2 + x1 ) - ( type(l) == 'string' and #l or l ) ) / 2 ) + 1
  21. end
  22.  
  23. local function centerWrite( text, yPos, txtCol, bgCol )
  24. term.setCursorPos( ( screenX - #text ) / 2, yPos )
  25. write( text )
  26. end
  27.  
  28. local function sWrite( text, xPos, yPos, txtCol, bgCol )
  29. term.setCursorPos( xPos, yPos )
  30. write( text )
  31. end
  32.  
  33. local function format( text, l, last )
  34. return text:len() > l and text:sub( 1, l - last:len() ) .. last or text
  35. end
  36.  
  37. local function block( text, x, y, txtCol, bgCol )
  38. for i = y, y + 2 do
  39. sWrite( string.rep( ' ', text:len() + 2 ), x, i, nil, bgCol )
  40. end
  41. sWrite( text, getCenter( text, x, x + text:len() + 1 ), y + 1, txtCol, bgCol )
  42. end
  43.  
  44. local function checkArea( cx, cy, mx, my, ax, ay )
  45. return cx >= mx and cx < mx + ax and cy >= my and cy <= my + ay
  46. end
  47.  
  48. local function limitRead( properties, ... )
  49. local buttons = { ... }
  50. properties = properties or {}
  51. properties.visibleLength = properties.visibleLength or nil
  52. properties.nLimit = properties.nLimit or nil
  53. properties.replaceChar = properties.replaceChar and ( properties.replaceChar:sub( 1, 1 ) == '' and nil or properties.replaceChar:sub( 1, 1 ) ) or nil
  54. properties.temp = properties.temp or ''
  55. properties.txtCol = properties.txtCol or colours.white
  56. properties.bgCol = properties.bgCol or colours.blue
  57. properties.oldBgCol = properties.oldBgCol or colours.lightBlue
  58. local rString = properties.temp
  59. term.setCursorBlink( true )
  60.  
  61. sWrite( rString .. string.rep( ' ', properties.visibleLength - rString:len() ), properties.x, properties.y, properties.txtCol, properties.bgCol )
  62. term.setCursorPos( properties.x + ( #rString > properties.visibleLength and properties.visibleLength or #rString ), properties.y )
  63. while true do
  64. local event, p1, x, y = os.pullEvent()
  65. if event == "char" then
  66. -- Character event
  67. if #rString < properties.nLimit then
  68. rString = rString .. p1
  69. if #rString - 1 < properties.visibleLength then
  70. write( properties.replaceChar or p1 )
  71. elseif not properties.replaceChar then
  72. term.setCursorPos( properties.x, properties.y )
  73. write( rString:sub( #rString - properties.visibleLength + 1 ) )
  74. end
  75. end
  76. elseif event == "key" then
  77. if p1 == keys.backspace and #rString > 0 then
  78. -- Backspace
  79. rString = rString:sub( 1, #rString - 1 )
  80. local xPos, yPos = term.getCursorPos()
  81. term.setCursorPos(xPos-1, yPos)
  82. write(" ")
  83. term.setCursorPos(xPos-1, yPos)
  84. if #rString + 1 > properties.visibleLength then
  85. term.setCursorPos( properties.x, properties.y )
  86. write( properties.replaceChar and string.rep( properties.replaceChar, properties.visibleLength ) or rString:sub( #rString - properties.visibleLength + 1 ) )
  87. end
  88. elseif p1 == keys.enter and rString:len() > 0 then
  89. sWrite( format( rString, properties.visibleLength, ' ...' ) .. string.rep( ' ', rString:len() < properties.visibleLength and properties.visibleLength - rString:len() or 0 ), properties.x, properties.y, properties.txtCol, properties.oldBgCol )
  90. term.setCursorBlink( false )
  91. return rString
  92. end
  93. elseif event == 'mouse_click' and p1 == 1 then
  94. for i = 1, #buttons do
  95. local but = buttons[i]
  96. if checkArea( x, y, but.x, but.y, but.l - 1, but.h - 1 ) then
  97. term.setCursorBlink( false )
  98. sWrite( format( rString, properties.visibleLength, ' ...' ) .. string.rep( ' ', rString:len() < properties.visibleLength and properties.visibleLength - rString:len() or 0 ), properties.x, properties.y, properties.txtCol, properties.oldBgCol )
  99. if but.a then but.a() return nil end
  100. if but.kill then return nil
  101. elseif rString:len() > 0 then return rString end
  102. end
  103. end
  104. end
  105. end
  106. end
  107.  
  108. local function splitToTable( s )
  109. return
  110. s:len() < screenX - 7 and { s }
  111. or ( s:len() >= screenX - 7 and s:len() < ( screenX - 8 ) * 2 ) and { s:sub( 1, screenX - 8 ), s:sub( screenX - 7, ( screenX - 8 ) * 2 - 1 ) }
  112. or { s:sub( 1, screenX - 8 ), s:sub( screenX - 7, ( screenX - 8 ) * 2 - 1 ), s:sub( ( screenX - 8 ) * 2 ) }
  113. end
  114.  
  115. local function saveBooking( name, time, reason )
  116. if not fs.exists( bookingsFile ) then local f = fs.open( bookingsFile, 'w' ) f.close() end
  117.  
  118. local file = fs.open( bookingsFile, 'a' )
  119. if file then
  120. file.writeLine( name )
  121. file.writeLine( time )
  122. file.writeLine( textutils.serialize( splitToTable( reason ) ) )
  123. file.close()
  124. return 'Your booking has been recorded.', true
  125. else
  126. return 'An error has occured!', false
  127. end
  128. end
  129.  
  130. local function getBookings()
  131. local file = fs.open( bookingsFile, 'r' )
  132. if file then
  133. local a = {}
  134. local i = 1
  135. local n, t, r
  136. for line in file.readLine do
  137. if i == 1 then
  138. n = line
  139. elseif i == 2 then
  140. t = line
  141. elseif i == 3 then
  142. r = line
  143. table.insert( a, { name = n, time = t, reason = textutils.unserialize( r ) } )
  144. i = 0
  145. end
  146. i = i + 1
  147. end
  148. file.close()
  149. return a
  150. else
  151. return {}
  152. end
  153. end
  154.  
  155. local function info( msg, success )
  156. -- Clear other buttons
  157. block( ' ', getCenter( 5, 1, 26 ), 15, nil, colours.cyan )
  158. block( ' ', getCenter( 5, 26, screenX ), 15, nil, colours.cyan )
  159.  
  160. block( msg, getCenter( msg, 1, screenX ), 15, colours.white, success and colours.lime or colours.red )
  161. end
  162.  
  163. local function init( title )
  164.  
  165. centerWrite( title, 2, colours.white, colours.blue )
  166. if title == 'Reception Desk' then
  167. -- Text
  168. sWrite( 'Book an apointment', 8, 4, colours.lime, colours.cyan )
  169. sWrite( 'Name:', 4, 6, colours.blue, colours.cyan )
  170. sWrite( ' so we know who you are', 4, 7, colours.lightGrey, colours.cyan )
  171. sWrite( 'Time:', 4, 9, colours.blue, colours.cyan )
  172. sWrite( ' what time do you want to meet', 4, 10, colours.lightGrey, colours.cyan )
  173. sWrite( 'Reason:', 4, 12, colours.blue, colours.cyan )
  174. sWrite( ' why do you want to meet', 4, 13, colours.lightGrey, colours.cyan )
  175. sWrite( 'view bookings', screenX - 12, screenY, colours.grey, colours.lightGrey )
  176.  
  177. -- Text area
  178. for y = 6, 12, 3 do
  179. sWrite( string.rep( ' ', 33 ), 12, y, nil, colours.lightBlue )
  180. end
  181.  
  182. -- Buttons
  183. block( 'Apply', getCenter( 5, 1, 26 ), 15, colours.white, colours.lime )
  184. block( 'Clear', getCenter( 5, 26, screenX ), 15, colours.black, colours.red )
  185. else
  186. if logged then
  187. bookings = getBookings()
  188.  
  189. if type( bookings ) == 'table' then
  190. if #bookings > 0 then
  191. sWrite( 'There are ' .. #bookings .. ' bookings', 8, 5, colours.lime, colours.cyan )
  192. else
  193. block( ' No bookings ', getCenter( 22, 1, screenX ), 7, colours.black, colours.red )
  194. end
  195. elseif bookings == 'error' then
  196. block( 'Error opening file!', getCenter( 22, 1, screenX ), 7, colours.black, colours.red )
  197. bookings = {}
  198. end
  199. else
  200. -- Text
  201. sWrite( 'Please login', 8, 4, colours.lime, colours.cyan )
  202. sWrite( 'Username:', 4, 6, colours.blue, colours.cyan )
  203. sWrite( 'Password:', 4, 8, colours.blue, colours.cyan )
  204.  
  205. -- Text area
  206. for y = 6, 8, 2 do
  207. sWrite( string.rep( ' ', 33 ), 14, y, nil, colours.lightBlue )
  208. end
  209.  
  210. -- Buttons
  211. block( 'Login', getCenter( 5, 1, screenX ), 15, colours.white, colours.lime )
  212. --block( 'Cancel', getCenter( 6, 26, screenX ), 15, colours.black, colours.red )
  213. end
  214. -- Text
  215. sWrite( 'back', screenX - 3, screenY, colours.grey, colours.lightGrey )
  216. end
  217. -- Reset variables
  218. name, time, reason = '', '', ''
  219. end
  220.  
  221. -------------------------------
  222. -- ------- Main loop ------- --
  223. -------------------------------
  224. while true do
  225. init( menu )
  226.  
  227. while true do
  228. if menu == 'Reception Desk' then
  229. -- Get user's name
  230. name = limitRead( { visibleLength = 33, nLimit = 50, x = 12, y = 6 },
  231. { x = getCenter( 5, 1, 26 ), y = 15, h = 3, l = 7, kill = false }, { x = getCenter( 5, 26, screenX ), y = 15, h = 3, l = 7, kill = true }, { x = 39, y = screenY, h = 1, l = 12, kill = false, a = function() menu = 'Current bookings' end } )
  232. if not name then break end
  233.  
  234. -- Get time
  235. time = limitRead( { visibleLength = 33, nLimit = 50, x = 12, y = 9 },
  236. { x = getCenter( 5, 1, 26 ), y = 15, h = 3, l = 7, kill = false }, { x = getCenter( 5, 26, screenX ), y = 15, h = 3, l = 7, kill = true }, { x = 39, y = screenY, h = 1, l = 12, kill = false, a = function() menu = 'Current bookings' end } )
  237. if not time then break end
  238.  
  239. -- Get reason
  240. reason = limitRead( { visibleLength = 33, nLimit = 132, x = 12, y = 12 },
  241. { x = getCenter( 5, 1, 26 ), y = 15, h = 3, l = 7, kill = false }, { x = getCenter( 5, 26, screenX ), y = 15, h = 3, l = 7, kill = true }, { x = 39, y = screenY, h = 1, l = 12, kill = false, a = function() menu = 'Current bookings' end } )
  242. if not reason then break end
  243.  
  244. info( saveBooking( name, time, reason ) )
  245. sleep( 2 )
  246. break
  247. else
  248. if logged then
  249. if #bookings > 0 then
  250. for y = 7, 17 do
  251. end
  252. sWrite( 'Booking # /' .. #bookings, 5, 8, colours.lightBlue, colours.black )
  253. sWrite( 'Name:', 5, 10, colours.white, colours.black )
  254. sWrite( 'Time:', 5, 11, colours.white, colours.black )
  255. sWrite( 'Reason:', 5, 13, colours.white, colours.black )
  256. end
  257. local sel = 1
  258. while true do
  259. if #bookings > 0 then
  260. sWrite( sel, 14, 8, colours.yellow, colours.black )
  261. sWrite( format( bookings[sel].name, 33, ' ..' ) .. string.rep( ' ', 36 - bookings[sel].name:len() ), 11, 10, colours.red, colours.black )
  262. sWrite( format( bookings[sel].time, 33, ' ..' ) .. string.rep( ' ', 36 - bookings[sel].time:len() ), 11, 11, colours.red, colours.black )
  263. for y = 14, 16 do sWrite( string.rep( ' ', 45 ), 5, y, nil, colours.black ) end
  264. for i = 1, #bookings[sel].reason do
  265. sWrite( bookings[sel].reason[i], 5, 13 + i, colours.red, colours.black )
  266. end
  267. end
  268. local e, b, x, y = os.pullEvent()
  269. if e == 'mouse_click' and b == 1 then
  270. if x >= 47 and x <= screenX and y == screenY then
  271. -- Back
  272. menu = 'Reception Desk'
  273. logged = false
  274. break
  275. end
  276. elseif e == 'mouse_scroll' and #bookings > 0 then
  277. if b == -1 and sel > 1 then
  278. -- Up
  279. sel = sel - 1
  280. elseif b == 1 and sel < #bookings then
  281. -- Down
  282. sel = sel + 1
  283. end
  284. end
  285. end
  286. break
  287. else
  288. local username, password = '', ''
  289. -- Get username
  290. while username == '' do username = limitRead( { visibleLength = 33, nLimit = 50, x = 14, y = 6 },
  291. { x = getCenter( 5, 1, 26 ), y = 15, h = 3, l = 7, kill = false }, { x = getCenter( 5, 26, screenX ), y = 15, h = 3, l = 7, kill = true }, { x = 47, y = screenY, h = 1, l = 4, kill = false, a = function() menu = 'Reception Desk' end } ) end
  292. if not username then break end
  293.  
  294. -- Get password
  295. while password == '' do password = limitRead( { visibleLength = 33, nLimit = 50, x = 14, y = 8 },
  296. { x = getCenter( 5, 1, 26 ), y = 15, h = 3, l = 7, kill = false }, { x = getCenter( 5, 26, screenX ), y = 15, h = 3, l = 7, kill = true }, { x = 47, y = screenY, h = 1, l = 4, kill = false, a = function() menu = 'Reception Desk' end } ) end
  297. if not password then break end
  298.  
  299. if username == admin.username and password == admin.password then
  300. info( 'Logged in!', true )
  301. logged = true
  302. else
  303. info( 'Incorrect credentials!', false )
  304. end
  305. sleep( 2 )
  306. break
  307. end
  308. end
  309. end
  310. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement