12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- package pathgame.gameplay.menu;
- import pathgame.gameplay.Gamestate;
- import pathgame.gameplay.Gamestates;
- import pathgame.gameplay.Keys;
- import pathgame.gameplay.Level;
- 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;
- private int currentIndex = 0;
- public Menu(Keys keys) {
- menus = new BaseMenu[]{
- new MainMenu(MAIN_ID, OPTION_ID, CHARACTER_ID),
- new EscMenu(ESCAPE_ID, MAIN_ID),
- new OptionMenu(OPTION_ID, MAIN_ID, keys),
- new CharacterMenu(CHARACTER_ID, MAIN_ID),
- new AfterScoreMenu(AFTER_SCORE_ID, MAIN_ID)
- };
- }
- public void tick(Gamestate gamestate, Level level, Keys keys) {
- if(gamestate.is(Gamestates.MENU)) {
- currentIndex = menus[currentIndex].tick(gamestate, level, keys);
- if(currentIndex == ESCAPE_ID && keys.escape.getTime() == 1) {
- gamestate.setState(Gamestates.GAMEPLAY);
- } else if((currentIndex == OPTION_ID || currentIndex == CHARACTER_ID)
- && keys.escape.getTime() == 1) {
- currentIndex = MAIN_ID;
- }
- } else if(gamestate.is(Gamestates.GAMEPLAY) && keys.escape.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();
- }
- }
- public MenuButton[] getOptions() {
- return menus[currentIndex].getOptions();
- }
- public int getActiveIndex() {
- return menus[currentIndex].getActiveIndex();
- }
- public boolean isOptionMenu() {
- return menus[currentIndex].isOptionMenu();
- }
- public void showEscapeMenu() {
- currentIndex = ESCAPE_ID;
- }
- }
|