DEADSOFTWARE

Remove unnecessary arguments
authorfred-boy <fredboy@protonmail.com>
Sun, 29 Sep 2019 05:08:54 +0000 (12:08 +0700)
committerfred-boy <fredboy@protonmail.com>
Sun, 29 Sep 2019 05:08:54 +0000 (12:08 +0700)
core/src/ru/deadsoftware/cavedroid/menu/MenuProc.java
core/src/ru/deadsoftware/cavedroid/menu/submenus/Menu.java
core/src/ru/deadsoftware/cavedroid/menu/submenus/MenuMain.java
core/src/ru/deadsoftware/cavedroid/menu/submenus/MenuNewGame.java

index 0ab0bac0af1bfb6f7f778c3764816c026b9f1586..989a5d1d35bdf431aa0b7354d21711a91934da4a 100644 (file)
@@ -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();
index f9d648a37c6996fbc295d8026baf268ebd020f19..21bf02b083050bb90be78135fb078a0fc1aadcb3 100644 (file)
@@ -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");
 
index da84b266d9607b90ea2df2e1d11b0a598effa81c..84b73ccd76805c7184989db4b106bf12bf6cd5db 100644 (file)
@@ -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
index c0ab73940f70b2e05bd0032b1eb3954c4652682d..e4b719ac23291f8c3a6a39ec56c8ff7bc9e63e7b 100644 (file)
@@ -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