Menu.java 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. package pathgame.gameplay.menu;
  2. import pathgame.gameplay.Gamestate;
  3. import pathgame.gameplay.Gamestates;
  4. import pathgame.gameplay.Keys;
  5. import pathgame.gameplay.Level;
  6. public class Menu
  7. {
  8. private final static int MAIN_ID;
  9. private final static int ESCAPE_ID;
  10. private final static int OPTION_ID;
  11. private final static int CHARACTER_ID;
  12. private final static int AFTER_SCORE_ID;
  13. static
  14. {
  15. int id = 0;
  16. MAIN_ID = id++;
  17. ESCAPE_ID = id++;
  18. OPTION_ID = id++;
  19. CHARACTER_ID = id++;
  20. AFTER_SCORE_ID = id++;
  21. }
  22. private final BaseMenu[] menus = new BaseMenu[]
  23. {
  24. new MainMenu(MAIN_ID, OPTION_ID, CHARACTER_ID),
  25. new EscMenu(ESCAPE_ID, MAIN_ID),
  26. new OptionMenu(OPTION_ID, MAIN_ID),
  27. new CharacterMenu(CHARACTER_ID, MAIN_ID),
  28. new AfterScoreMenu(AFTER_SCORE_ID, MAIN_ID)
  29. };
  30. private int currentIndex = 0;
  31. public void tick(Gamestate gamestate, Level level)
  32. {
  33. if(gamestate.getState() == Gamestates.MENU)
  34. {
  35. currentIndex = menus[currentIndex].tick(gamestate, level);
  36. if(currentIndex == ESCAPE_ID && Keys.ESCAPE_KEY.getTime() == 1)
  37. {
  38. gamestate.setState(Gamestates.GAMEPLAY);
  39. }
  40. else if((currentIndex == OPTION_ID || currentIndex == CHARACTER_ID)
  41. && Keys.ESCAPE_KEY.getTime() == 1)
  42. {
  43. currentIndex = MAIN_ID;
  44. }
  45. }
  46. else if(gamestate.getState() == Gamestates.GAMEPLAY && Keys.ESCAPE_KEY.getTime() == 1)
  47. {
  48. currentIndex = ESCAPE_ID;
  49. gamestate.setState(Gamestates.MENU);
  50. menus[currentIndex].resetIndex();
  51. }
  52. else if(level.getShowAfterScore())
  53. {
  54. currentIndex = AFTER_SCORE_ID;
  55. gamestate.setState(Gamestates.MENU);
  56. menus[currentIndex].resetIndex();
  57. }
  58. }
  59. public MenuButton[] getOptions()
  60. {
  61. return menus[currentIndex].getOptions();
  62. }
  63. public int getActiveIndex()
  64. {
  65. return menus[currentIndex].getActiveIndex();
  66. }
  67. public boolean isOptionMenu()
  68. {
  69. return menus[currentIndex].isOptionMenu();
  70. }
  71. public void showEscapeMenu()
  72. {
  73. currentIndex = ESCAPE_ID;
  74. }
  75. }