patch text + cout mana

This commit is contained in:
marc barbier
2021-01-04 12:14:45 +01:00
parent db523a9d13
commit 47be04c450
4 changed files with 110 additions and 23 deletions
@@ -3,6 +3,7 @@ package com.iutlaval.myapplication.Game;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.util.Log;
import android.view.MotionEvent;
import android.widget.Toast;
@@ -96,8 +97,8 @@ public class GameLogicThread extends Thread{
//Rectangle pos = new Rectangle(0F,0F,100F,100F);
ready=true;
final String host = "2.tcp.ngrok.io";//192.168.43.251tcp://2.tcp.ngrok.io:
final int port = 13450;
final String host = "4.tcp.ngrok.io";//192.168.43.251tcp://2.tcp.ngrok.io:
final int port = 16784;
try {
Socket client = new Socket(host, port);
@@ -183,9 +184,9 @@ public class GameLogicThread extends Thread{
break;
case Command.SETMANA:
renderer.removeToDraw("mana");
renderer.removeToDrawWithoutUpdate("mana");
mana = coms.recieveInt();
renderer.addToDraw(new DrawableText("Mana : "+mana,90F,90F,"mana",10F,10F,100,800,200));
renderer.addToDraw(new DrawableText("Mana : "+mana,85F,60F,"mana",100,12, Color.WHITE));
break;
case Command.ENEMYTURN:
@@ -263,6 +264,7 @@ public class GameLogicThread extends Thread{
//detruit la carte sur le terrain du joueur
int zoneOfTheDestroyedCard = coms.recieveInt();
Card cardToDestroy = board.removeCardOnPlayerBoard(zoneOfTheDestroyedCard);
Log.e("destroying",""+cardToDestroy);
renderer.removeToDraw(cardToDestroy);
break;
@@ -97,6 +97,7 @@ public class DrawableCard extends Drawable{
private Drawable cardTitle;
private Drawable cardHpDrawable;
private Drawable cardAtkDrawable;
private Drawable cardCostDrawable;
//DEPENDANCE CIRCULAIRE NE PAS CHANGER DE GC NON Tracing
//https://www.baeldung.com/java-gc-cyclic-references
@@ -157,8 +158,19 @@ public class DrawableCard extends Drawable{
frameDrawable = new DrawableBitmap(c.getFrameBitmap(context),0,0,name+"frame",CARD_WITH*ratio,CARD_HEIGHT*ratio);
//to string retourne le hash code de l'objet qui est donc unique ce qui fait de lui un id parfait
if(c.getDescription() != null)
cardDescription = new DrawableText(c.getDescription(),0,0,toString()+"description",DESCRIPTION_WIDTH*ratio,DESCRIPTION_HEIGHT*ratio,DESCRIPTION_FONT_SIZE,DESCRIPTION_TEXT_X_RES,DESCRIPTION_TEXT_Y_RES);
cardTitle = new DrawableText(c.getName(),0,0,toString()+"name",TITLE_WIDTH*ratio,TITLE_HEIGHT*ratio,TITLE_FONT_SIZE,TEXT_TITLE_X_RES,TEXT_TITLE_Y_RES);
cardDescription = new DrawableText(c.getDescription(),0,0,toString()+"description",DESCRIPTION_WIDTH*ratio,DESCRIPTION_HEIGHT*ratio,DESCRIPTION_FONT_SIZE,DESCRIPTION_TEXT_X_RES,DESCRIPTION_TEXT_Y_RES,Color.BLACK);
if(c.getName().length() < 16)
{
//cardTitle = new DrawableText(c.getName(),0,0,toString()+"name",TITLE_WIDTH*ratio,TITLE_HEIGHT*ratio,TITLE_FONT_SIZE,TEXT_TITLE_X_RES,TEXT_TITLE_Y_RES,Color.BLACK,16);
cardTitle = new DrawableText(c.getName(),0,0,toString()+"name",TITLE_FONT_SIZE,TITLE_WIDTH,Color.BLACK,16);
}else{
cardTitle = new DrawableText(c.getName(),0,0,toString()+"name",TITLE_WIDTH*ratio,TITLE_HEIGHT*ratio,TITLE_FONT_SIZE*0.75F,TEXT_TITLE_X_RES,TEXT_TITLE_Y_RES,Color.BLACK,30);
//cardTitle = new DrawableText(c.getName(),0,0,toString()+"name",TITLE_FONT_SIZE,TITLE_WIDTH,Color.BLACK,40);
}
cardCostDrawable = new DrawableText(c.getCost() + "", 0, 0, toString() + "cost", OFFBOARD_ATK_HP_WIDTH*ratio, OFFBOARD_ATK_HP_HEIGHT*ratio, HP_ATK_FONT_SIZE, TEXT_ATK_HP_X_RES, TEXT_ATK_HP_Y_RES,Color.BLACK);
Rectangle opacityRect = new Rectangle(x,y,OPACITY_RECT_WIDTH*ratio+x,OPACITY_RECT_HEIGHT*ratio+x);
Bitmap pictureBitmap = BitmapFactory.decodeResource(context.getResources(),c.getCardPicture());
@@ -226,14 +238,14 @@ public class DrawableCard extends Drawable{
{
if(onBoard) {
if (atk != null)
cardAtkDrawable = new DrawableText(atk+"", 0, 0, toString() + "atk", ONBOARD_ATK_HP_WIDTH*ratio, ONBOARD_ATK_HP_HEIGHT*ratio, HP_ATK_FONT_SIZE,TEXT_ATK_HP_X_RES,TEXT_ATK_HP_Y_RES);
cardAtkDrawable = new DrawableText(atk+"", 0, 0, toString() + "atk", ONBOARD_ATK_HP_WIDTH*ratio, ONBOARD_ATK_HP_HEIGHT*ratio, HP_ATK_FONT_SIZE,TEXT_ATK_HP_X_RES,TEXT_ATK_HP_Y_RES,Color.BLACK);
if (hp != null)
cardHpDrawable = new DrawableText(hp+"", 0, 0, toString() + "hp", ONBOARD_ATK_HP_WIDTH*ratio, ONBOARD_ATK_HP_HEIGHT*ratio, HP_ATK_FONT_SIZE,TEXT_ATK_HP_X_RES,TEXT_ATK_HP_Y_RES);
cardHpDrawable = new DrawableText(hp+"", 0, 0, toString() + "hp", ONBOARD_ATK_HP_WIDTH*ratio, ONBOARD_ATK_HP_HEIGHT*ratio, HP_ATK_FONT_SIZE,TEXT_ATK_HP_X_RES,TEXT_ATK_HP_Y_RES,Color.BLACK);
}else{
if (atk != null)
cardAtkDrawable = new DrawableText(atk + "", 0, 0, toString() + "atk", OFFBOARD_ATK_HP_WIDTH*ratio, OFFBOARD_ATK_HP_HEIGHT*ratio, HP_ATK_FONT_SIZE, TEXT_ATK_HP_X_RES, TEXT_ATK_HP_Y_RES);
cardAtkDrawable = new DrawableText(atk + "", 0, 0, toString() + "atk", OFFBOARD_ATK_HP_WIDTH*ratio, OFFBOARD_ATK_HP_HEIGHT*ratio, HP_ATK_FONT_SIZE, TEXT_ATK_HP_X_RES, TEXT_ATK_HP_Y_RES,Color.BLACK);
if (hp != null)
cardHpDrawable = new DrawableText(hp + "", 0, 0, toString() + "hp", OFFBOARD_ATK_HP_WIDTH*ratio, OFFBOARD_ATK_HP_HEIGHT*ratio, HP_ATK_FONT_SIZE, TEXT_ATK_HP_X_RES, TEXT_ATK_HP_Y_RES);
cardHpDrawable = new DrawableText(hp + "", 0, 0, toString() + "hp", OFFBOARD_ATK_HP_WIDTH*ratio, OFFBOARD_ATK_HP_HEIGHT*ratio, HP_ATK_FONT_SIZE, TEXT_ATK_HP_X_RES, TEXT_ATK_HP_Y_RES,Color.BLACK);
}
setCoordinates(getX(), getY());
}
@@ -282,6 +294,7 @@ public class DrawableCard extends Drawable{
if(cardDescription != null)cardDescription.drawOn(c,p);
cardHpDrawable.drawOn(c,p);
cardAtkDrawable.drawOn(c,p);
cardCostDrawable.drawOn(c,p);
}
}
@@ -311,6 +324,8 @@ public class DrawableCard extends Drawable{
cardAtkDrawable.setCoordinates(x + OFFBOARD_ATK_X*ratio,y + OFFBOARD_ATK_HP_Y*ratio);
cardHpDrawable.setCoordinates(x + OFFBOARD_HP_X*ratio,y +OFFBOARD_ATK_HP_Y*ratio);
cardTitle.setCoordinates(x+OFFBOARD_TITLE_X*ratio,y - OFFBOARD_TITLE_Y*ratio);
cardCostDrawable.setCoordinates(x+CARD_WITH/2*ratio,y + OFFBOARD_ATK_HP_Y *ratio);
}
}
@@ -3,6 +3,7 @@ package com.iutlaval.myapplication.Video.Drawables;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.text.TextPaint;
import android.util.Log;
import com.iutlaval.myapplication.GameActivity;
@@ -15,6 +16,58 @@ import java.util.List;
* tout modification de ce code doit passer par marc car seul moi sait a quel point il est complex
*/
public class DrawableText extends Drawable{
public DrawableText(String text,float x_pos,float y_pos,String name,float textSize , float x_size,int color)
{
this(text,x_pos,y_pos,name,textSize,x_size,color,20);
}
/**
* ce constructeur permet de créer un text un une ligne avec moin d'argument
* @param text
* @param x_pos
* @param y_pos
* @param name
* @param textSize
*/
public DrawableText(String text,float x_pos,float y_pos,String name,float textSize , float x_size,int color,int nbcharPerlines)
{
super(x_pos,y_pos,name);
TextPaint p = new TextPaint();
p.setAntiAlias(true);
p.setTextSize(textSize);
p.setColor(color);
int canvas_width = (int) p.measureText(text);
int canvas_height = (int) textSize;
Bitmap bitmap = Bitmap.createBitmap(canvas_width, canvas_height, Bitmap.Config.ARGB_8888);
setBitmap(bitmap);
Canvas c = new Canvas(bitmap);
//si on a une description
int index = 1;
List<String> linesOfText = cutText(nbcharPerlines,text);
for(String line : linesOfText)
{
//y_canvasRatio/linesOfText.size()
c.drawText(line ,0,index*textSize,p);
index++;
}
int scalled_x_size = (int) (GameActivity.screenWidth*x_size/100);
int y_size = (int) (x_size/(canvas_width * 1.0) * 200 * linesOfText.size());
int scalled_y_size = GameActivity.screenHeight*y_size/100;
setBitmap(Bitmap.createScaledBitmap(bitmap,scalled_x_size,scalled_y_size,GameActivity.bilinearFiltering));
}
/**
* ce constructeur permet de rendre du texte
* @param text le texte a rendre
@@ -26,12 +79,28 @@ public class DrawableText extends Drawable{
* @param y_canvasRatio taille du canevas en pixel sur le quel le texte va être dessiné /!\ doit être proportionnel a la police
* @param x_canvasRatio voire y_canvasRatio
*/
public DrawableText(String text,float x_pos,float y_pos,String name, float x_size,float y_size,float textSize , int x_canvasRatio, int y_canvasRatio)
public DrawableText(String text,float x_pos,float y_pos,String name, float x_size,float y_size,float textSize , int x_canvasRatio, int y_canvasRatio,int color)
{
this(text,x_pos,y_pos,name,x_size,y_size,textSize,x_canvasRatio,y_canvasRatio,color,20);
}
/**
* ce constructeur permet de rendre du texte
* @param text le texte a rendre
* @param x_pos position en x du texte
* @param y_pos position en y du texte
* @param name nom du Drawable
* @param x_size taille du drawable entre 0 et 100
* @param y_size taille du drawable entre 0 et 100
* @param y_canvasRatio taille du canevas en pixel sur le quel le texte va être dessiné /!\ doit être proportionnel a la police
* @param x_canvasRatio voire y_canvasRatio
*/
public DrawableText(String text,float x_pos,float y_pos,String name, float x_size,float y_size,float textSize , int x_canvasRatio, int y_canvasRatio,int color,int nbcharPerlines)
{
super(x_pos,y_pos,name);
checkPaint();
p.setColor(Color.BLACK);
p.setColor(color);
p.setAntiAlias(true);
p.setTextSize(textSize);
@@ -40,16 +109,13 @@ public class DrawableText extends Drawable{
Canvas c = new Canvas(bitmap);
//si on a une description
if(text != null)
int index = 1;
List<String> linesOfText = cutText(nbcharPerlines,text);
for(String line : linesOfText)
{
int index = 1;
List<String> linesOfText = cutText(20,text);
for(String line : linesOfText)
{
//y_canvasRatio/linesOfText.size()
c.drawText(line ,0,index*textSize,p);
index++;
}
//y_canvasRatio/linesOfText.size()
c.drawText(line ,0,index*textSize,p);
index++;
}
@@ -65,7 +131,7 @@ public class DrawableText extends Drawable{
* @param text texte a afficher
* @return liste de lignes de texte
*/
private List<String> cutText(int charPerLines,String text)
private static List<String> cutText(int charPerLines,String text)
{
List<String> output = new ArrayList<>();
@@ -81,9 +147,13 @@ public class DrawableText extends Drawable{
//fillWithSpace(nextLine,charPerLines);
output.add(nextLine.toString());
nextLine.delete(0,charPerLines-1);
nextLine.append(" " + word);
}
}else{
Log.e("TextRender","ERROR WORD TOO LONG :" + word);
if(!nextLine.toString().isEmpty())output.add(nextLine.toString());
nextLine.delete(0,charPerLines-1);
output.add(word);
}
}
if(!nextLine.toString().equals(""))