DEADSOFTWARE

Attempt to make more convenient controls
authorfred-boy <fred-boy@protonmail.com>
Thu, 26 Apr 2018 07:19:37 +0000 (14:19 +0700)
committerfred-boy <fred-boy@protonmail.com>
Thu, 26 Apr 2018 07:19:37 +0000 (14:19 +0700)
core/src/ru/deadsoftware/cavecraft/game/GameInput.java
core/src/ru/deadsoftware/cavecraft/game/GameProc.java
core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java
core/src/ru/deadsoftware/cavecraft/misc/InputHandlerGame.java

index 2e54ad3ee1f29f921b34331a45593ce4255f82cd..08f6e368f0fbb067a821b962f68594412be56aa5 100644 (file)
@@ -105,27 +105,9 @@ public class GameInput {
     }
 
     public void touchDown(int screenX, int screenY, int button) {
-        if (CaveGame.STATE == AppState.GAME_CREATIVE_INV &&
-                screenX>gameProc.renderer.camera.viewportWidth/2-Assets.creativeInv.getRegionWidth()/2 &&
-                screenX<gameProc.renderer.camera.viewportWidth/2+Assets.creativeInv.getRegionWidth()/2 &&
-                screenY>gameProc.renderer.camera.viewportHeight/2-Assets.creativeInv.getRegionHeight()/2 &&
-                screenY<gameProc.renderer.camera.viewportHeight/2+Assets.creativeInv.getRegionHeight()/2) {
-            int ix = (int) (screenX - (gameProc.renderer.camera.viewportWidth / 2 - Assets.creativeInv.getRegionWidth() / 2 + 8)) / 18;
-            int iy = (int) (screenY - (gameProc.renderer.camera.viewportHeight / 2 - Assets.creativeInv.getRegionHeight() / 2 + 18)) / 18;
-            int item = gameProc.creativeScroll*40+(ix + iy * 8);
-            if (item >= 0 && item < Items.BLOCKS.size) {
-                for (int i = 8; i > 0; i--) {
-                    gameProc.player.inventory[i] = gameProc.player.inventory[i - 1];
-                }
-                gameProc.player.inventory[0] = item;
-            }
-        } else if (CaveGame.STATE == AppState.GAME_CREATIVE_INV) {
-            CaveGame.STATE = AppState.GAME_PLAY;
-        } else {
-            gameProc.touchDownTime = TimeUtils.millis();
-            gameProc.isTouchDown = true;
-            gameProc.touchDownButton = button;
-        }
+        gameProc.touchDownTime = TimeUtils.millis();
+        gameProc.isTouchDown = true;
+        gameProc.touchDownButton = button;
         gameProc.touchDownX = screenX;
         gameProc.touchDownY = screenY;
     }
@@ -136,15 +118,32 @@ public class GameInput {
             gameProc.isKeyDown = false;
         }
         if (gameProc.isTouchDown) {
-            if (button == Input.Buttons.RIGHT){
+            if (CaveGame.STATE == AppState.GAME_CREATIVE_INV &&
+                    screenX>gameProc.renderer.camera.viewportWidth/2-Assets.creativeInv.getRegionWidth()/2 &&
+                    screenX<gameProc.renderer.camera.viewportWidth/2+Assets.creativeInv.getRegionWidth()/2 &&
+                    screenY>gameProc.renderer.camera.viewportHeight/2-Assets.creativeInv.getRegionHeight()/2 &&
+                    screenY<gameProc.renderer.camera.viewportHeight/2+Assets.creativeInv.getRegionHeight()/2) {
+                int ix = (int) (screenX - (gameProc.renderer.camera.viewportWidth / 2 - Assets.creativeInv.getRegionWidth() / 2 + 8)) / 18;
+                int iy = (int) (screenY - (gameProc.renderer.camera.viewportHeight / 2 - Assets.creativeInv.getRegionHeight() / 2 + 18)) / 18;
+                int item = gameProc.creativeScroll*40+(ix + iy * 8);
+                if (ix>=8 || ix<0 || iy<0 || iy>=5) item=-1;
+                if (item >= 0 && item < Items.BLOCKS.size) {
+                    for (int i = 8; i > 0; i--) {
+                        gameProc.player.inventory[i] = gameProc.player.inventory[i - 1];
+                    }
+                    gameProc.player.inventory[0] = item;
+                }
+            } else if (CaveGame.STATE == AppState.GAME_CREATIVE_INV) {
+                CaveGame.STATE = AppState.GAME_PLAY;
+            } else if (screenY<Assets.invBar.getRegionHeight() &&
+                    screenX>gameProc.renderer.camera.viewportWidth/2-Assets.invBar.getRegionWidth()/2 &&
+                    screenX<gameProc.renderer.camera.viewportWidth/2+Assets.invBar.getRegionWidth()/2) {
+                gameProc.invSlot = (int)((screenX-(gameProc.renderer.camera.viewportWidth/2-Assets.invBar.getRegionWidth()/2))/20);
+            } else if (button == Input.Buttons.RIGHT){
                 gameProc.world.placeToForeground(gameProc.cursorX, gameProc.cursorY,
                             gameProc.player.inventory[gameProc.invSlot]);
             } else if (button == Input.Buttons.LEFT) {
-                if (screenY<Assets.invBar.getRegionHeight() &&
-                        screenX>gameProc.renderer.camera.viewportWidth/2-Assets.invBar.getRegionWidth()/2 &&
-                        screenX<gameProc.renderer.camera.viewportWidth/2+Assets.invBar.getRegionWidth()/2) {
-                    gameProc.invSlot = (int)((screenX-(gameProc.renderer.camera.viewportWidth/2-Assets.invBar.getRegionWidth()/2))/20);
-                } else if (gameProc.world.getForeMap(gameProc.cursorX, gameProc.cursorY) > 0) {
+                if (gameProc.world.getForeMap(gameProc.cursorX, gameProc.cursorY) > 0) {
                     gameProc.world.placeToForeground(gameProc.cursorX, gameProc.cursorY, 0);
                 } else if (gameProc.world.getBackMap(gameProc.cursorX, gameProc.cursorY) > 0) {
                     gameProc.world.placeToBackground(gameProc.cursorX, gameProc.cursorY, 0);
@@ -157,12 +156,19 @@ public class GameInput {
 
     public void touchDragged(int screenX, int screenY) {
         if (CaveGame.STATE == AppState.GAME_CREATIVE_INV && Math.abs(screenY-gameProc.touchDownY)>16) {
-                gameProc.creativeScroll+=(screenY-gameProc.touchDownY)/16;
+            if (screenX>gameProc.renderer.camera.viewportWidth/2-Assets.creativeInv.getRegionWidth()/2 &&
+                    screenX<gameProc.renderer.camera.viewportWidth/2+Assets.creativeInv.getRegionWidth()/2 &&
+                    screenY>gameProc.renderer.camera.viewportHeight/2-Assets.creativeInv.getRegionHeight()/2 &&
+                    screenY<gameProc.renderer.camera.viewportHeight/2+Assets.creativeInv.getRegionHeight()/2) {
+                if (screenX<gameProc.renderer.camera.viewportWidth/2+Assets.creativeInv.getRegionWidth()/2-24)
+                    gameProc.creativeScroll -= (screenY - gameProc.touchDownY) / 16;
+                else gameProc.creativeScroll += (screenY - gameProc.touchDownY) / 16;
                 gameProc.touchDownX = screenX;
                 gameProc.touchDownY = screenY;
-                if (gameProc.creativeScroll<0) gameProc.creativeScroll=0;
-                if (gameProc.creativeScroll>gameProc.maxCreativeScroll)
-                    gameProc.creativeScroll=gameProc.maxCreativeScroll;
+                if (gameProc.creativeScroll < 0) gameProc.creativeScroll = 0;
+                if (gameProc.creativeScroll > gameProc.maxCreativeScroll)
+                    gameProc.creativeScroll = gameProc.maxCreativeScroll;
+            }
         }
     }
 
index 8f5dca275d9b6c3fd3c8e3402cf5212f09cbbdb8..5ba62a2e1307fc7dd16e0169dc0624960ce46217 100644 (file)
@@ -121,8 +121,7 @@ public class GameProc implements Serializable{
             if (touchDownButton== Input.Buttons.RIGHT) {
                 world.placeToBackground(cursorX, cursorY,
                         player.inventory[invSlot]);
-            } else if (touchDownButton==Input.Buttons.LEFT &&
-                    touchDownY< Assets.invBar.getRegionHeight() &&
+            } else if (touchDownY< Assets.invBar.getRegionHeight() &&
                     touchDownX>renderer.camera.viewportWidth/2-Assets.invBar.getRegionWidth()/2 &&
                     touchDownX<renderer.camera.viewportWidth/2+Assets.invBar.getRegionWidth()/2) {
                 CaveGame.STATE = AppState.GAME_CREATIVE_INV;
index 7ab146b7235c7342b0a61b56e6bd2b98e4218a9d..3ba99c3ec2c999dc7faa9866e3cb3bc5cc1d4430 100644 (file)
@@ -163,6 +163,10 @@ public class GameRenderer extends Renderer {
         spriteBatch.draw(Assets.touchLMB, camera.viewportWidth-52, camera.viewportHeight-26);
         spriteBatch.draw(Assets.touchRMB, camera.viewportWidth-26, camera.viewportHeight-26);
         spriteBatch.draw(Assets.touchToggleMode, 78, camera.viewportHeight-26);
+        if (gameProc.ctrlMode==1) {
+            Assets.shade.setPosition(83, camera.viewportHeight-21);
+            Assets.shade.draw(spriteBatch);
+        }
     }
 
     private void drawGamePlay() {
index ffc38ccea589e80007e41a40c5c4af664472ef3e..c9de4fab9d1ac38131f30bad3a966f6839c5b5d0 100644 (file)
@@ -65,7 +65,7 @@ public class InputHandlerGame implements InputProcessor {
             } else if (tx > tWidth - 26 && screenY > ty - 26) {
                 gameInput.touchDown(screenX, screenY, Input.Buttons.RIGHT);
             } else {
-                gameInput.touchDown(screenX, screenY, Input.Buttons.LEFT);
+                gameInput.touchDown(screenX, screenY, -1);
             }
         } else {
             gameInput.touchDown(screenX, screenY, button);
@@ -97,7 +97,7 @@ public class InputHandlerGame implements InputProcessor {
             } else if (tx > tWidth - 26 && screenY > ty - 26) {
                 gameInput.touchUp(screenX, screenY, Input.Buttons.RIGHT);
             } else {
-                gameInput.touchUp(screenX, screenY, Input.Buttons.LEFT);
+                gameInput.touchUp(screenX, screenY, -1);
             }
         } else {
             gameInput.touchUp(screenX, screenY, button);
@@ -109,7 +109,11 @@ public class InputHandlerGame implements InputProcessor {
     public boolean touchDragged(int screenX, int screenY, int pointer) {
         screenX *= gameProc.renderer.camera.viewportWidth/getWidth();
         screenY *= gameProc.renderer.camera.viewportHeight/getHeight();
-        gameInput.touchDragged(screenX, screenY);
+        if (gameProc.isKeyDown && (screenX>78 || screenY<gameProc.renderer.getHeight()-52)) {
+            gameInput.keyUp(gameProc.keyDownCode);
+        } else {
+            gameInput.touchDragged(screenX, screenY);
+        }
         return false;
     }