123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- package pathgame.gameplay.menu;
- import pathgame.gameplay.Gamestate;
- import pathgame.gameplay.Gamestates;
- import pathgame.gameplay.Keys;
- import pathgame.gameplay.Level;
- /**
- * A container for holding and manages all kinds of menus
- *
- * @author julia
- */
- public class Menu
- {
- private final static int MAIN_ID;
- private final static int ESCAPE_ID;
- private final static int OPTION_ID;
- private final static int CHARACTER_ID;
- private final static int AFTER_SCORE_ID;
- static
- {
- int id = 0;
- MAIN_ID = id++;
- ESCAPE_ID = id++;
- OPTION_ID = id++;
- CHARACTER_ID = id++;
- AFTER_SCORE_ID = id++;
- }
- private final BaseMenu[] menus = new BaseMenu[]
- {
- new MainMenu(MAIN_ID, OPTION_ID, CHARACTER_ID),
- new EscMenu(ESCAPE_ID, MAIN_ID),
- new OptionMenu(OPTION_ID, MAIN_ID),
- new CharacterMenu(CHARACTER_ID, MAIN_ID),
- new AfterScoreMenu(AFTER_SCORE_ID, MAIN_ID)
- };
- private int currentIndex = 0;
- /**
- * Updates the menu state every gametick based on user input
- *
- * @param gamestate the gamestate
- * @param level a level containing the current map and the current player
- */
- public void tick(Gamestate gamestate, Level level)
- {
- if(gamestate.getState() == Gamestates.MENU)
- {
- currentIndex = menus[currentIndex].tick(gamestate, level);
- if(currentIndex == ESCAPE_ID && Keys.ESCAPE_KEY.getTime() == 1)
- {
- gamestate.setState(Gamestates.GAMEPLAY);
- }
- else if((currentIndex == OPTION_ID || currentIndex == CHARACTER_ID)
- && Keys.ESCAPE_KEY.getTime() == 1)
- {
- currentIndex = MAIN_ID;
- }
- }
- else if(gamestate.getState() == Gamestates.GAMEPLAY && Keys.ESCAPE_KEY.getTime() == 1)
- {
- currentIndex = ESCAPE_ID;
- gamestate.setState(Gamestates.MENU);
- menus[currentIndex].resetIndex();
- }
- else if(level.isShowingAfterScore())
- {
- currentIndex = AFTER_SCORE_ID;
- gamestate.setState(Gamestates.MENU);
- menus[currentIndex].resetIndex();
- }
- }
- /**
- * Returns the array of menu buttons of the menu
- *
- * @return the array of menu buttons of the menu
- */
- public MenuButton[] getOptions()
- {
- return menus[currentIndex].getOptions();
- }
- /**
- * Returns the index of the active menu button
- *
- * @return the index of the active menu button
- */
- public int getActiveIndex()
- {
- return menus[currentIndex].getActiveIndex();
- }
- /**
- * Returns if this is the OptionMenu
- *
- * @return if this is the OptionMenu
- */
- public boolean isOptionMenu()
- {
- return menus[currentIndex].isOptionMenu();
- }
- /**
- * Opens the escape menu
- *
- */
- public void showEscapeMenu()
- {
- currentIndex = ESCAPE_ID;
- }
- }
|