summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 3f01302)
raw | patch | inline | side by side (parent: 3f01302)
author | fred-boy <fredboy@protonmail.com> | |
Sun, 29 Sep 2019 05:08:54 +0000 (12:08 +0700) | ||
committer | fred-boy <fredboy@protonmail.com> | |
Sun, 29 Sep 2019 05:08:54 +0000 (12:08 +0700) |
diff --git a/core/src/ru/deadsoftware/cavedroid/menu/MenuProc.java b/core/src/ru/deadsoftware/cavedroid/menu/MenuProc.java
index 0ab0bac0af1bfb6f7f778c3764816c026b9f1586..989a5d1d35bdf431aa0b7354d21711a91934da4a 100644 (file)
public MenuProc(int width) {
super(width, width * GameScreen.getHeight() / GameScreen.getWidth());
- mainMenu = new MenuMain(getWidth(), getHeight());
- newGameMenu = new MenuNewGame(getWidth(), getHeight());
+ mainMenu = new MenuMain(getWidth(), getHeight(), this::drawButton);
+ newGameMenu = new MenuNewGame(getWidth(), getHeight(), this::drawButton);
currentMenu = mainMenu;
}
(button.getY() + button.getHeight() / 2) - (float) getStringHeight(button.getLabel()) / 2);
}
+ private void update() {
+ switch (CaveGame.MENU_STATE) {
+ case MAIN:
+ currentMenu = mainMenu;
+ break;
+ case NEW_GAME:
+ currentMenu = newGameMenu;
+ break;
+ case LOADING:
+ drawString("Generating World...");
+ CaveGame.APP_STATE = AppState.GAME;
+ CaveGame.GAME_STATE = GameState.PLAY;
+ break;
+ case SAVING:
+ drawString("Saving Game...");
+ CaveGame.APP_STATE = AppState.MENU;
+ CaveGame.MENU_STATE = MenuState.MAIN;
+ break;
+ }
+ }
+
@Override
public boolean touchUp(int screenX, int screenY, int pointer, int mb) {
screenX *= getWidth() / GameScreen.getWidth();
@Override
public void render() {
+ update();
spriter.begin();
- switch (CaveGame.MENU_STATE) {
- case MAIN:
- currentMenu = mainMenu;
- break;
- case NEW_GAME:
- currentMenu = newGameMenu;
- break;
- case LOADING:
- drawString("Generating World...");
- CaveGame.APP_STATE = AppState.GAME;
- CaveGame.GAME_STATE = GameState.PLAY;
- break;
- case SAVING:
- drawString("Saving Game...");
- CaveGame.APP_STATE = AppState.MENU;
- CaveGame.MENU_STATE = MenuState.MAIN;
- break;
- }
- currentMenu.draw(spriter, this::drawButton, getWidth(), getHeight());
+ currentMenu.draw(spriter);
drawString("CaveDroid " + CaveGame.VERSION, 0,
getHeight() - getStringHeight("CaveDroid " + CaveGame.VERSION) * 1.5f);
spriter.end();
diff --git a/core/src/ru/deadsoftware/cavedroid/menu/submenus/Menu.java b/core/src/ru/deadsoftware/cavedroid/menu/submenus/Menu.java
index f9d648a37c6996fbc295d8026baf268ebd020f19..21bf02b083050bb90be78135fb078a0fc1aadcb3 100644 (file)
public abstract class Menu {
+ private ButtonDrawer buttonDrawer;
+
private float width;
private float height;
/**
* @param width Viewport width
* @param height Viewport height
+ * @param buttonDrawer {@link ButtonDrawer} that will draw the buttons of this menu
*/
- Menu(float width, float height) {
+ Menu(float width, float height, ButtonDrawer buttonDrawer) {
this.width = width;
this.height = height;
+ this.buttonDrawer = buttonDrawer;
initButtons();
}
*
* @param spriter {@link SpriteBatch} that will draw it. Should be already started.
*/
- public void draw(SpriteBatch spriter, ButtonDrawer buttonDrawer, float width, float height) {
+ public void draw(SpriteBatch spriter) {
TextureRegion background = Assets.textureRegions.get("background");
TextureRegion gamelogo = Assets.textureRegions.get("gamelogo");
diff --git a/core/src/ru/deadsoftware/cavedroid/menu/submenus/MenuMain.java b/core/src/ru/deadsoftware/cavedroid/menu/submenus/MenuMain.java
index da84b266d9607b90ea2df2e1d11b0a598effa81c..84b73ccd76805c7184989db4b106bf12bf6cd5db 100644 (file)
import com.badlogic.gdx.Gdx;
import ru.deadsoftware.cavedroid.game.GameSaver;
import ru.deadsoftware.cavedroid.menu.objects.Button;
+import ru.deadsoftware.cavedroid.menu.objects.ButtonDrawer;
import ru.deadsoftware.cavedroid.menu.objects.ButtonEventListener;
import java.util.HashMap;
public class MenuMain extends Menu {
- /**
- * @param width Viewport width
- * @param height Viewport height
- */
- public MenuMain(float width, float height) {
- super(width, height);
+ public MenuMain(float width, float height, ButtonDrawer buttonDrawer) {
+ super(width, height, buttonDrawer);
}
@Override
diff --git a/core/src/ru/deadsoftware/cavedroid/menu/submenus/MenuNewGame.java b/core/src/ru/deadsoftware/cavedroid/menu/submenus/MenuNewGame.java
index c0ab73940f70b2e05bd0032b1eb3954c4652682d..e4b719ac23291f8c3a6a39ec56c8ff7bc9e63e7b 100644 (file)
package ru.deadsoftware.cavedroid.menu.submenus;
import com.badlogic.gdx.Gdx;
+import ru.deadsoftware.cavedroid.menu.objects.ButtonDrawer;
import ru.deadsoftware.cavedroid.menu.objects.ButtonEventListener;
import java.util.HashMap;
public class MenuNewGame extends Menu {
- /**
- * @param width Viewport width
- * @param height Viewport height
- */
- public MenuNewGame(float width, float height) {
- super(width, height);
+
+ public MenuNewGame(float width, float height, ButtonDrawer buttonDrawer) {
+ super(width, height, buttonDrawer);
}
@Override