From c37823b90e43591c90a5d51ba553858edd63ef98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Sat, 20 Feb 2016 21:21:24 +0100 Subject: add menu/MenuCtrl --- core/src/ch/asynk/rustanddust/menu/MenuCtrl.java | 83 ++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 core/src/ch/asynk/rustanddust/menu/MenuCtrl.java diff --git a/core/src/ch/asynk/rustanddust/menu/MenuCtrl.java b/core/src/ch/asynk/rustanddust/menu/MenuCtrl.java new file mode 100644 index 0000000..8d19378 --- /dev/null +++ b/core/src/ch/asynk/rustanddust/menu/MenuCtrl.java @@ -0,0 +1,83 @@ +package ch.asynk.rustanddust.menu; + +import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import com.badlogic.gdx.utils.Disposable; + +import ch.asynk.rustanddust.RustAndDust; +import ch.asynk.rustanddust.ui.Widget; + +public class MenuCtrl implements Disposable +{ + private MainMenu mainMenu; + private PlayMenu playMenu; + private OptionsMenu optionsMenu; + private TutorialsMenu tutorialsMenu; + private Widget currentMenu; + + public boolean visible; + + public MenuCtrl(final RustAndDust game) + { + this.mainMenu = new MainMenu(game); + this.playMenu = new PlayMenu(game); + this.optionsMenu = new OptionsMenu(game); + this.tutorialsMenu = new TutorialsMenu(game); + + this.currentMenu = mainMenu; + this.currentMenu.visible = true; + this.visible = true; + } + + public boolean hit(float x, float y) + { + boolean ret = false; + + if (currentMenu.hit(x, y)) { + currentMenu.visible = false; + if (currentMenu == mainMenu) { + showNextMenu(); + } else if (currentMenu == playMenu) { + currentMenu = mainMenu; + if (playMenu.launch) + ret = true; + } else { + currentMenu = mainMenu; + } + currentMenu.visible = true; + } + + return ret; + } + + private void showNextMenu() + { + switch(mainMenu.getMenu()) { + case PLAY: currentMenu = playMenu; break; + case OPTIONS: currentMenu = optionsMenu; break; + case TUTORIALS: currentMenu = tutorialsMenu; break; + } + } + + public void draw(SpriteBatch batch) + { + if (visible) + currentMenu.draw(batch); + } + + public void setPosition() + { + mainMenu.setPosition(); + playMenu.setPosition(); + optionsMenu.setPosition(); + tutorialsMenu.setPosition(); + } + + @Override + public void dispose() + { + mainMenu.dispose(); + playMenu.dispose(); + optionsMenu.dispose(); + tutorialsMenu.dispose(); + } +} -- cgit v1.1-2-g2b99