88import java .awt .Graphics ;
99import java .awt .Graphics2D ;
1010import java .awt .Image ;
11+ import java .awt .Rectangle ;
1112import java .awt .geom .AffineTransform ;
1213import java .awt .geom .Line2D ;
1314import java .awt .image .AffineTransformOp ;
3839import de .neuwirthinformatik .Alexander .TU .Basic .Deck ;
3940import de .neuwirthinformatik .Alexander .TU .Basic .GlobalData ;
4041import de .neuwirthinformatik .Alexander .TU .Basic .SkillSpec ;
42+ import de .neuwirthinformatik .Alexander .TU .TUO .TUO .Result ;
4143import de .neuwirthinformatik .Alexander .TU .util .StringUtil ;
4244import de .neuwirthinformatik .Alexander .TU .util .Wget ;
4345
@@ -52,6 +54,57 @@ public Render() throws FontFormatException, IOException {
5254 optimus = Font .createFont (Font .TRUETYPE_FONT , TU .class .getResourceAsStream ("/Optimus.otf" ));
5355 arial = Font .createFont (Font .TRUETYPE_FONT , TU .class .getResourceAsStream ("/arialbold.ttf" ));
5456 }
57+
58+ public BufferedImage renderScore (Result r , CardInstance y_com ,CardInstance y_dom ,CardInstance y_ass , CardInstance e_com ,CardInstance e_dom ,CardInstance e_ass ,File y_s ,File e_s ) {
59+
60+ // int offset_y = 10;
61+ int width = CARD_WIDTH * 2 ;
62+ int height = CARD_HEIGHT * 2 ;
63+ BufferedImage img = new BufferedImage (width , height , BufferedImage .TYPE_INT_ARGB );
64+ Graphics g = img .getGraphics ();
65+ g .setColor (Color .white );
66+ g .fillRect (0 , 0 , width , height );
67+
68+ g .drawImage (render (y_ass , new String [] { "" , "" , "" }, y_s , y_ass .getCardType ()), 0 , 0 , null );
69+ g .drawImage (render (e_ass , new String [] { "" , "" , "" }, e_s , e_ass .getCardType ()), 0 , CARD_HEIGHT , null );
70+
71+ if (r .WINS > r .LOSSES ) {
72+ g .setColor (Color .GREEN );
73+ }
74+ else if (r .LOSSES > r .WINS ){
75+ g .setColor (Color .RED );
76+ }
77+ else {
78+ g .setColor (Color .BLACK );
79+ }
80+ drawCenteredString (g ,"" +(int ) Math .round (r .WINS ) + "%" , new Rectangle (CARD_WIDTH ,0 ,CARD_WIDTH ,CARD_HEIGHT ),new Font ("Serif" , Font .BOLD , 50 ));
81+
82+ if (r .WINS > r .LOSSES ) {
83+ g .setColor (Color .RED );
84+ }
85+ else if (r .LOSSES > r .WINS ){
86+ g .setColor (Color .GREEN );
87+ }
88+ else {
89+ g .setColor (Color .BLACK );
90+ }
91+ drawCenteredString (g ,"" +(int ) Math .round (r .LOSSES ) + "%" ,new Rectangle (CARD_WIDTH ,CARD_HEIGHT ,CARD_WIDTH ,CARD_HEIGHT ),new Font ("Serif" , Font .BOLD , 50 ));
92+
93+ return img ;
94+
95+ }
96+ public void drawCenteredString (Graphics g , String text , Rectangle rect , Font font ) {
97+ // Get the FontMetrics
98+ FontMetrics metrics = g .getFontMetrics (font );
99+ // Determine the X coordinate for the text
100+ int x = rect .x + (rect .width - metrics .stringWidth (text )) / 2 ;
101+ // Determine the Y coordinate for the text (note we add the ascent, as in java 2d 0 is top of the screen)
102+ int y = rect .y + ((rect .height - metrics .getHeight ()) / 2 ) + metrics .getAscent ();
103+ // Set the font
104+ g .setFont (font );
105+ // Draw the String
106+ g .drawString (text , x , y );
107+ }
55108
56109 public BufferedImage renderDeck (CardInstance com , CardInstance dom , CardInstance ass , File s ) {
57110 // int offset_y = 10;
@@ -68,8 +121,7 @@ public BufferedImage renderDeck(CardInstance com, CardInstance dom, CardInstance
68121 BufferedImage cimg = render (ass , new String [] { "" , "" , "" }, s , ass .getCardType ());
69122 for (int iid = 0 ; iid < 12 ; iid ++) {
70123 if (i > 1 )
71- g .drawImage (cimg ,
72- CARD_WIDTH * (1 + (i - 2 ) % 5 ), ((i - 2 ) / 5 ) * CARD_HEIGHT , null );
124+ g .drawImage (cimg , CARD_WIDTH * (1 + (i - 2 ) % 5 ), ((i - 2 ) / 5 ) * CARD_HEIGHT , null );
73125 i ++;
74126 }
75127
@@ -98,7 +150,10 @@ public BufferedImage renderDeck(CardInstance[] deck, File s) {
98150 return img ;
99151 }
100152
153+ @ Deprecated
101154 public BufferedImage renderDeck (CardInstance [] deck , String s ) {
155+ return renderDeck (deck ,new File (s ));
156+ /*
102157 // int offset_y = 10;
103158 int width = CARD_WIDTH * 6;
104159 int height = CARD_HEIGHT * 2;
@@ -118,6 +173,7 @@ public BufferedImage renderDeck(CardInstance[] deck, String s) {
118173 }
119174
120175 return img;
176+ */
121177 }
122178
123179 public BufferedImage renderDeck (Deck d ) {
@@ -257,28 +313,25 @@ public BufferedImage render(CardInstance c) {
257313 }
258314
259315 public BufferedImage render (CardInstance c , String [] txts , String file , CardType type ) {
316+ if (file == null || "" .equals (file )) {
317+ return render (c , txts , (File )null , type );
318+ }
319+ else {
320+ return render (c , txts ,new File (file ) , type );
321+ }
322+ }
323+
324+ public BufferedImage render (CardInstance c , String [] txts , File file , CardType type ) {
260325 Image bi = null ;
261326 try {
262-
263- if (file == null || "" .equals (file )) {
327+ if (file == null ) {
264328 bi = getCardImage (c .getCard ().getAssetBundle (), c .getCard ().getPicture ());
265329 } else {
266- bi = ImageIO .read (new File ( file ) );
330+ bi = ImageIO .read (file );
267331 bi = bi .getScaledInstance (150 , 125 , Image .SCALE_SMOOTH );
268332 }
269333 } catch (Exception e ) {
270334 e .printStackTrace ();
271- } // TODO FINALLY RM FOLDER
272- return render (c , txts , bi , type );
273- }
274-
275- public BufferedImage render (CardInstance c , String [] txts , File file , CardType type ) {
276- Image bi = null ;
277- try {
278- bi = ImageIO .read (file );
279- bi = bi .getScaledInstance (150 , 125 , Image .SCALE_SMOOTH );
280- } catch (Exception e ) {
281- e .printStackTrace ();
282335 }
283336 return render (c , txts , bi , type );
284337 }
0 commit comments