DEADSOFTWARE

Optimize font
[cavedroid.git] / core / src / ru / deadsoftware / cavecraft / Assets.java
index 427ebc66bf2efc23ea32812d36e0bb0e6a4396b2..6a992ef067cd5eaf1f2c95e0dc13acc22bb00bb3 100644 (file)
@@ -3,6 +3,7 @@ package ru.deadsoftware.cavecraft;
 import com.badlogic.gdx.Gdx;
 import com.badlogic.gdx.graphics.Texture;
 import com.badlogic.gdx.graphics.g2d.BitmapFont;
+import com.badlogic.gdx.graphics.g2d.GlyphLayout;
 import com.badlogic.gdx.graphics.g2d.Sprite;
 import com.badlogic.gdx.graphics.g2d.TextureRegion;
 
@@ -10,11 +11,16 @@ public class Assets {
 
     public static final int BLOCK_TEXTURES = 18;
 
+    private static GlyphLayout layout;
+
     public static BitmapFont minecraftFont;
 
     public static Sprite gameLogo;
 
-    public static Texture charTexture;
+    public static Texture menuButtonTexture;
+    public static TextureRegion[] menuButton = new TextureRegion[3];
+
+    public static Texture playerTexture;
     public static Sprite[][] playerSprite = new Sprite[2][4];
 
     public static Texture pigTexture;
@@ -41,32 +47,32 @@ public class Assets {
     public static TextureRegion touchSpace;
 
     private static void loadPlayer() {
-        charTexture = new Texture(Gdx.files.internal("mobs/char.png"));
+        playerTexture = new Texture(Gdx.files.internal("mobs/char.png"));
         //LOOK TO LEFT
         //head
-        playerSprite[0][0] = new Sprite(new TextureRegion(charTexture, 0,0,12,12));
+        playerSprite[0][0] = new Sprite(new TextureRegion(playerTexture, 0,0,12,12));
         playerSprite[0][0].flip(false,true);
         //body
-        playerSprite[0][1] = new Sprite(new TextureRegion(charTexture, 0,13,12,12));
+        playerSprite[0][1] = new Sprite(new TextureRegion(playerTexture, 0,13,12,12));
         playerSprite[0][1].flip(false,true);
         //hand
-        playerSprite[0][2] = new Sprite(new TextureRegion(charTexture, 25,5,20,20));
+        playerSprite[0][2] = new Sprite(new TextureRegion(playerTexture, 25,5,20,20));
         playerSprite[0][2].flip(false,true);
         //leg
-        playerSprite[0][3] = new Sprite(new TextureRegion(charTexture, 25,27,20,20));
+        playerSprite[0][3] = new Sprite(new TextureRegion(playerTexture, 25,27,20,20));
         playerSprite[0][3].flip(false,true);
         //LOOK TO RIGHT
         //head
-        playerSprite[1][0] = new Sprite(new TextureRegion(charTexture, 13,0,12,12));
+        playerSprite[1][0] = new Sprite(new TextureRegion(playerTexture, 13,0,12,12));
         playerSprite[1][0].flip(false,true);
         //body
-        playerSprite[1][1] = new Sprite(new TextureRegion(charTexture, 13,13,12,12));
+        playerSprite[1][1] = new Sprite(new TextureRegion(playerTexture, 13,13,12,12));
         playerSprite[1][1].flip(false,true);
         //hand
-        playerSprite[1][2] = new Sprite(new TextureRegion(charTexture, 37,5,20,20));
+        playerSprite[1][2] = new Sprite(new TextureRegion(playerTexture, 37,5,20,20));
         playerSprite[1][2].flip(false,true);
         //leg
-        playerSprite[1][3] = new Sprite(new TextureRegion(charTexture, 37,27,20,20));
+        playerSprite[1][3] = new Sprite(new TextureRegion(playerTexture, 37,27,20,20));
         playerSprite[1][3].flip(false,true);
     }
 
@@ -84,9 +90,19 @@ public class Assets {
 
     public static void load() {
         minecraftFont = new BitmapFont(Gdx.files.internal("font.fnt"), true);
+        minecraftFont.getData().setScale(.375f);
+
+        layout = new GlyphLayout();
+
         gameLogo = new Sprite(new Texture(Gdx.files.internal("gamelogo.png")));
         gameLogo.flip(false, true);
 
+        menuButtonTexture = new Texture(Gdx.files.internal("buttons.png"));
+        for (int i=0; i<3; i++) {
+            menuButton[i] = new TextureRegion(menuButtonTexture, 0, 20*i, 200, 20);
+            menuButton[i].flip(false, true);
+        }
+
         loadPlayer();
         loadPig();
 
@@ -103,19 +119,21 @@ public class Assets {
         creativeScroll = new TextureRegion(creativeTexture, 3, 137, 12, 15);
         creativeScroll.flip(false, true);
 
-        touchGui = new Texture(Gdx.files.internal("touch_gui.png"));
-        for (int i=0; i<4; i++) {
-            touchArrows[i] = new TextureRegion(touchGui, i*26, 0, 26,26);
-            touchArrows[i].flip(false, true);
+        if (CaveGame.TOUCH) {
+            touchGui = new Texture(Gdx.files.internal("touch_gui.png"));
+            for (int i = 0; i < 4; i++) {
+                touchArrows[i] = new TextureRegion(touchGui, i * 26, 0, 26, 26);
+                touchArrows[i].flip(false, true);
+            }
+            touchLMB = new TextureRegion(touchGui, 0, 26, 26, 26);
+            touchLMB.flip(false, true);
+            touchRMB = new TextureRegion(touchGui, 52, 26, 26, 26);
+            touchRMB.flip(false, true);
+            touchToggleMode = new TextureRegion(touchGui, 26, 26, 26, 26);
+            touchToggleMode.flip(false, true);
+            touchSpace = new TextureRegion(touchGui, 0, 52, 104, 26);
+            touchSpace.flip(false, true);
         }
-        touchLMB = new TextureRegion(touchGui, 0, 26, 26,26);
-        touchLMB.flip(false, true);
-        touchRMB = new TextureRegion(touchGui, 52, 26, 26,26);
-        touchRMB.flip(false, true);
-        touchToggleMode = new TextureRegion(touchGui, 26, 26, 26, 26);
-        touchToggleMode.flip(false, true);
-        touchSpace = new TextureRegion(touchGui, 0, 52, 104, 26);
-        touchSpace.flip(false, true);
 
         terrain = new Texture(Gdx.files.internal("terrain.png"));
         for (int i=0; i<BLOCK_TEXTURES; i++) {
@@ -125,4 +143,14 @@ public class Assets {
         }
     }
 
+    public static int getStringWidth(String s){
+        layout.setText(minecraftFont,s);
+        return (int)layout.width;
+    }
+
+    public static int getStringHeight(String s){
+        layout.setText(minecraftFont,s);
+        return (int)layout.height;
+    }
+
 }