Advertisement
Ceziy

main_menu.lua

Nov 27th, 2023 (edited)
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.62 KB | None | 0 0
  1. os.loadAPI("ATMApi.lua")
  2.  
  3. os.pullEvent = os.pullEventRaw
  4. local w,h = term.getSize()
  5.  
  6. local title = "Choose option"
  7. local ch_1 = "Card's info"
  8. local ch_2 = "Deposite"
  9. local ch_3 = "Withdraw"
  10. local ch_4 = "Pay"
  11. local ch_5 = "Log out"
  12. local nOption = 1
  13.  
  14.  
  15. function update()
  16.     term.clear()
  17.     local t1 = ch_1
  18.     local t2 = ch_2
  19.     local t3 = ch_3
  20.     local t4 = ch_4
  21.     local t5 = ch_5
  22.     if nOption == 6 then nOption = 5 end
  23.     if nOption == 0 then nOption = 1 end
  24.     if nOption == 1 then t1 = "[ " .. t1 .. " ]"
  25.     elseif nOption == 2 then t2 = "[ " .. t2 .. " ]"
  26.     elseif nOption == 3 then t3 = "[ " .. t3 .. " ]"
  27.     elseif nOption == 4 then t4 = "[ " .. t4 .. " ]"
  28.     elseif nOption == 5 then t5 = "[ " .. t5 .. " ]"
  29.     end
  30.     ATMApi.printCent(math.floor(h/2) - 3, title)
  31.     ATMApi.printCent(math.floor(h/2) - 1, t1)
  32.     ATMApi.printCent(math.floor(h/2), t2)
  33.     ATMApi.printCent(math.floor(h/2) + 1, t3)
  34.     ATMApi.printCent(math.floor(h/2) + 2, t4)
  35.     ATMApi.printCent(math.floor(h/2) + 3, t5)
  36. end
  37.  
  38. update()
  39.  
  40. while true do
  41.     local event, key = os.pullEvent("key")
  42.    
  43.     if key == keys.enter then
  44.         if ATMApi.cardIn() == true then
  45.             if nOption == 1 then shell.run("card_info") end
  46.         else shell.run("main")
  47.         end
  48.         if nOption == 5 then shell.run("main") end
  49.     elseif key == keys.down then
  50.         nOption = nOption + 1
  51.     elseif key == keys.up then
  52.         nOption = nOption - 1
  53.     end
  54.     update()
  55. end
  56.  
  57. --shell.run("main_menu")
  58. --rednet.open("top")
  59. --rednet.send(0, "client 948211")
  60. --id, message = rednet.receive()
  61. --print(message.pass)
  62.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement