diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2016-02-20 21:21:24 +0100 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2016-02-20 21:21:24 +0100 |
commit | c37823b90e43591c90a5d51ba553858edd63ef98 (patch) | |
tree | 1d95d7be7f67bac76609ee19241dbbc43e3a4069 /core/src | |
parent | 5453479d03a9f2852a5c623ab58454dbd417ed6b (diff) | |
download | RustAndDust-c37823b90e43591c90a5d51ba553858edd63ef98.zip RustAndDust-c37823b90e43591c90a5d51ba553858edd63ef98.tar.gz |
add menu/MenuCtrl
Diffstat (limited to 'core/src')
-rw-r--r-- | core/src/ch/asynk/rustanddust/menu/MenuCtrl.java | 83 |
1 files changed, 83 insertions, 0 deletions
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(); + } +} |