text card

This commit is contained in:
mmarc471@gmail.com
2020-09-09 15:24:50 +02:00
parent 10a0461b3b
commit 75df96126f
5 changed files with 92 additions and 5 deletions
@@ -65,5 +65,7 @@ public abstract class Card {
{
return "#00000000";
}
public abstract String getDescription();
//TODO
}
@@ -17,4 +17,9 @@ public class DemoCard extends Card{
public String getColor() {
return "#70000000";
}
@Override
public String getDescription() {
return "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec volutpat metus eu augue aliquet, nec accumsan tellus aliquam. Nullam eu consectetur quam.";
}
}
@@ -98,7 +98,8 @@ public class GameActivity extends Activity {
if(i==0)increm=-increm;
//TODO get x,y coordinate form name
view.moveToDraw(i,i,"card2");
//view.moveToDraw(i,i,"card2");
//view.moveToDraw(1,1,"card2");
FpsTime.waitFrameTime();
}
}
@@ -10,6 +10,9 @@ import androidx.annotation.NonNull;
import com.iutlaval.myapplication.GameActivity;
import com.iutlaval.myapplication.InvalidDataException;
import java.util.ArrayList;
import java.util.List;
public class Drawable {
private float x,y;
@@ -64,15 +67,52 @@ public class Drawable {
System.out.println(x_scaled_size + " y: " + y_scaled_size);
System.out.println(y_size);
if(x_scaled_size <=0 || y_scaled_size <=0)
{
throw new InvalidDataException(name,x_scaled_size,y_scaled_size);
}
this.bitmap = Bitmap.createScaledBitmap(bitmap, (int)x_scaled_size, (int)y_scaled_size, GameActivity.bilinearFiltering);
Log.i("loul",""+this.bitmap.getWidth());
}
/**TODO : limiter la longeur des lignes et implementer le retour a la ligne
* 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
*/
public Drawable(String text,float x_pos,float y_pos,String name, float x_size,float y_size,float textSize)
{
this(x_pos,y_pos,name);
//this ratio is used to dial the quality of the text;
List<String> linesOfText = cutText(20,text);
bitmap = Bitmap.createBitmap((int)(text.length()*textSize / linesOfText.size()), (int) 40*linesOfText.size(), Bitmap.Config.ARGB_8888);
checkPaint();
p.setTextSize(textSize*2);
Canvas c = new Canvas(bitmap);
int index = 1;
for(String line : linesOfText)
{
c.drawText(line ,0,textSize*2*index,p);
index++;
}
float x_scaled_size = x_size* GameActivity.screenWidth/100;
float y_scaled_size = y_size* GameActivity.screenHeight/100;
bitmap = Bitmap.createScaledBitmap(bitmap, (int)x_scaled_size, (int)y_scaled_size, GameActivity.bilinearFiltering);
}
/**
* ce constructeur n'est pas rapide essayer de l'utiliser le moin possible
* TODO : optimize it and remove the deprecated flag
@@ -149,8 +189,38 @@ public class Drawable {
this.y=y;
}
/**
* cette fonction permet d'initialiser le pinceau
*/
private void checkPaint() {
if(p==null)
p = new Paint();
}
/**
* cette fonction est appeler quand le drawable est retirer de la liste toDraw
*/
public void onDeletion(Renderer r){}
private List<String> cutText(int charPerLines,String text)
{
List<String> output = new ArrayList<>();
//TODO cut text in lines
String nextLine = "";
for (String word : text.split(" ")) {
if(word.length() < charPerLines)
{
if(word.length() + nextLine.length() +1 < charPerLines)
{
nextLine += " " + word;
}else{
output.add(nextLine);
nextLine="";
}
}else{
Log.e("TextRender","ERROR WORD TOO LONG :" + word);
}
}
return output;
}
}
@@ -23,10 +23,14 @@ public class DrawableCard extends Drawable{
private Boolean onBoard;
private Drawable cardOnBardDrawable;
private Drawable cardDescription;
public DrawableCard(Card c, float x, float y, String name, Context context) throws InvalidDataException {
super(c.getFrameBitmap(context),x,y,name,CARD_WITH,CARD_HEIGHT);
cardDescription = new Drawable(c.getDescription(),x+CARD_WITH*0.1F,y+CARD_HEIGHT/2,name,CARD_WITH,CARD_HEIGHT/2,10F);
color = c.getColor();//CARD_WITH+x
Rectangle cardRect = new Rectangle(x,y,(float)(CARD_WITH+x),(float)(CARD_HEIGHT+x));
OpacityRectangleDrawable = new Drawable(cardRect,toString()+"Opacity", Color.parseColor(c.getColor()));
@@ -56,13 +60,14 @@ public class DrawableCard extends Drawable{
cardOnBoardHp.bitmapRectangleBuilder(cardOnBoardBitmap,Color.parseColor("#FF00FF00"),p);
cardOnBoardAtk.bitmapRectangleBuilder(cardOnBoardBitmap,Color.parseColor("#FFFF0000"),p);
cardOnBardDrawable = new Drawable(cardOnBoardBitmap,x+1,y+2,toString()+"BOARD",CARD_WITH,CARD_HEIGHT*2/3);
cardOnBardDrawable = new Drawable(cardOnBoardBitmap,x,y,toString()+"BOARD",CARD_WITH,CARD_HEIGHT*2/3);
onBoard=true;
onBoard=false;
}
private String removeAlpha(String color) {
char[] colorArray = color.toCharArray();;
char[] colorArray = color.toCharArray();
if(colorArray[1]=='0' && colorArray[2]=='0')return "#FFFFFFFF";
colorArray[1]='F';
colorArray[2]='F';
System.out.println(String.valueOf(colorArray));
@@ -81,6 +86,9 @@ public class DrawableCard extends Drawable{
super.drawOn(c, p);
OpacityRectangleDrawable.drawOn(c,p);
PictureDrawable.drawOn(c,p);
cardDescription.drawOn(c,p);
//draw text in the card
}
}
@@ -94,6 +102,7 @@ public class DrawableCard extends Drawable{
super.setCoordinates(x, y);
OpacityRectangleDrawable.setCoordinates(x, y);
PictureDrawable.setCoordinates(x + 1.1F, y + 2.5F);
cardDescription.setCoordinates(x,y);
}
}