DEADSOFTWARE

Update input handling (pretty messy)
[cavedroid.git] / core / src / ru / deadsoftware / cavecraft / game / GameRenderer.java
index 84060ca2b804d6749702257f1faa5aa2cf8b8829..682984a5611adc334464374b8aad5fa46223746f 100644 (file)
@@ -19,16 +19,18 @@ public class GameRenderer {
 
     private GameProc gameProc;
 
-    public OrthographicCamera camera, fontCam;
+    public boolean showCreative = false;
+
+    public OrthographicCamera camera, fontCam, touchCam;
     ShapeRenderer shapeRenderer;
-    SpriteBatch spriteBatch, fontBatch;
+    SpriteBatch spriteBatch, fontBatch, touchBatch;
 
     public GameRenderer(GameProc gameProc) {
         Gdx.gl.glClearColor(0f,.6f,.6f,1f);
         this.gameProc = gameProc;
         camera = new OrthographicCamera();
-        camera.setToOrtho(true, 360,
-                360*((float)GameScreen.getHeight()/GameScreen.getWidth()));
+        camera.setToOrtho(true, 480,
+                480*((float)GameScreen.getHeight()/GameScreen.getWidth()));
 
         shapeRenderer = new ShapeRenderer();
         shapeRenderer.setProjectionMatrix(camera.combined);
@@ -40,6 +42,11 @@ public class GameRenderer {
         fontCam.setToOrtho(true, GameScreen.getWidth(), GameScreen.getHeight());
         fontBatch = new SpriteBatch();
         fontBatch.setProjectionMatrix(fontCam.combined);
+        touchCam = new OrthographicCamera();
+        touchCam.setToOrtho(true, 240,
+                240*((float)GameScreen.getHeight()/GameScreen.getWidth()));
+        touchBatch = new SpriteBatch();
+        touchBatch.setProjectionMatrix(touchCam.combined);
     }
 
     private void setFontColor(int r, int g, int b) {
@@ -141,6 +148,22 @@ public class GameRenderer {
         Assets.playerSkin[0][2].draw(spriteBatch);
     }
 
+    private void drawCreative() {
+        float x = camera.viewportWidth/2-Assets.creativeInv.getRegionWidth()/2;
+        float y = camera.viewportHeight/2-Assets.creativeInv.getRegionHeight()/2;
+        spriteBatch.draw(Assets.creativeInv, x, y);
+        spriteBatch.draw(Assets.creativeScroll, x+156, y+18);
+        for (int i=1; i<Items.BLOCKS.size; i++) {
+            spriteBatch.draw(Items.BLOCKS.getValueAt(i).getTexture(),x+8+(i%8)*18,
+                    y+18+(i/8)*18);
+        }
+        for (int i=0; i<9; i++) {
+            if (gameProc.player.inventory[i]>0)
+                spriteBatch.draw(Items.BLOCKS.getValueAt(gameProc.player.inventory[i]).getTexture(),
+                        x+8+i*18, y+184);
+        }
+    }
+
     private void drawGUI() {
         spriteBatch.draw(Assets.invBar, camera.viewportWidth/2 - Assets.invBar.getRegionWidth()/2, 0);
         for (int i=0; i<9; i++) {
@@ -154,20 +177,18 @@ public class GameRenderer {
                 camera.viewportWidth/2 - Assets.invBar.getRegionWidth()/2 - 1 + 20*gameProc.invSlot,
                 -1);
 
-        if (CaveGame.TOUCH) {
-            spriteBatch.draw(Assets.touchArrows[0],26,camera.viewportHeight-52);
-            spriteBatch.draw(Assets.touchArrows[1],0,camera.viewportHeight-26);
-            spriteBatch.draw(Assets.touchArrows[2],26,camera.viewportHeight-26);
-            spriteBatch.draw(Assets.touchArrows[3],52,camera.viewportHeight-26);
-            spriteBatch.draw(Assets.touchSpace, camera.viewportWidth/2-52, camera.viewportHeight-26);
-            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);
-            }
-        }
+        if (showCreative) drawCreative();
+    }
+
+    private void drawTouchGui() {
+        touchBatch.draw(Assets.touchArrows[0],26,touchCam.viewportHeight-52);
+        touchBatch.draw(Assets.touchArrows[1],0,touchCam.viewportHeight-26);
+        touchBatch.draw(Assets.touchArrows[2],26,touchCam.viewportHeight-26);
+        touchBatch.draw(Assets.touchArrows[3],52,touchCam.viewportHeight-26);
+        //touchBatch.draw(Assets.touchSpace, touchCam.viewportWidth/2-52, touchCam.viewportHeight-26);
+        touchBatch.draw(Assets.touchLMB, touchCam.viewportWidth-52, touchCam.viewportHeight-26);
+        touchBatch.draw(Assets.touchRMB, touchCam.viewportWidth-26, touchCam.viewportHeight-26);
+        touchBatch.draw(Assets.touchToggleMode, 78, touchCam.viewportHeight-26);
     }
 
     public void render() {
@@ -181,6 +202,12 @@ public class GameRenderer {
         drawGUI();
         spriteBatch.end();
 
+        if (CaveGame.TOUCH) {
+            touchBatch.begin();
+            drawTouchGui();
+            touchBatch.end();
+        }
+
         if (gameProc.ctrlMode==1) {
             shapeRenderer.begin(ShapeRenderer.ShapeType.Line);
             shapeRenderer.setColor(Color.ORANGE);