From 7c525620f826997870a05e6c1607bc36c19f3da9 Mon Sep 17 00:00:00 2001 From: fred-boy Date: Sun, 29 Sep 2019 12:08:54 +0700 Subject: [PATCH] Remove unnecessary arguments --- .../deadsoftware/cavedroid/menu/MenuProc.java | 46 ++++++++++--------- .../cavedroid/menu/submenus/Menu.java | 8 +++- .../cavedroid/menu/submenus/MenuMain.java | 9 ++-- .../cavedroid/menu/submenus/MenuNewGame.java | 10 ++-- 4 files changed, 38 insertions(+), 35 deletions(-) diff --git a/core/src/ru/deadsoftware/cavedroid/menu/MenuProc.java b/core/src/ru/deadsoftware/cavedroid/menu/MenuProc.java index 0ab0bac..989a5d1 100644 --- a/core/src/ru/deadsoftware/cavedroid/menu/MenuProc.java +++ b/core/src/ru/deadsoftware/cavedroid/menu/MenuProc.java @@ -23,8 +23,8 @@ public class MenuProc extends Renderer { 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; } @@ -36,6 +36,27 @@ public class MenuProc extends Renderer { (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(); @@ -54,26 +75,9 @@ public class MenuProc extends Renderer { @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 f9d648a..21bf02b 100644 --- a/core/src/ru/deadsoftware/cavedroid/menu/submenus/Menu.java +++ b/core/src/ru/deadsoftware/cavedroid/menu/submenus/Menu.java @@ -17,6 +17,8 @@ import java.util.HashMap; public abstract class Menu { + private ButtonDrawer buttonDrawer; + private float width; private float height; @@ -28,10 +30,12 @@ public abstract class Menu { /** * @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(); } @@ -71,7 +75,7 @@ public abstract class Menu { * * @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 da84b26..84b73cc 100644 --- a/core/src/ru/deadsoftware/cavedroid/menu/submenus/MenuMain.java +++ b/core/src/ru/deadsoftware/cavedroid/menu/submenus/MenuMain.java @@ -3,18 +3,15 @@ package ru.deadsoftware.cavedroid.menu.submenus; 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 c0ab739..e4b719a 100644 --- a/core/src/ru/deadsoftware/cavedroid/menu/submenus/MenuNewGame.java +++ b/core/src/ru/deadsoftware/cavedroid/menu/submenus/MenuNewGame.java @@ -1,17 +1,15 @@ 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 -- 2.29.2