-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMessageAnimator.java
119 lines (101 loc) · 3.24 KB
/
MessageAnimator.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import java.awt.*;
import java.awt.geom.*;
class MessageAnimator implements Runnable
{
static String win="You won!😎";
static String lose="You lost🙄🙄";
static String draw="Game draw😶";
static String starts="Game starts😄";
static String discn="Disconnected !🤡";
String instr;
static String greet=win;
static Font font=new Font("LEPIFONT",Font.PLAIN,0);
final static int maxWidth=gui.scalefactor*8;
boolean vanish=true;
public MessageAnimator(String s,boolean fade)
{
greet=s;
instr=s;
vanish=fade;
}
/*
* squareX,squareY,squareWidth,squareHeight,fontSize,Opacity
*/
static float squareX,squareY,squareWidth,squareHeight,fontSize,opacity;
public void run()//see dimensions of messages dont exceed space in drawing panel
{
/**
* start from top-center of the game area
* enlarge till width is equal to game area's width
*/
squareX=maxWidth/2;
squareY=0;
squareWidth=0;
squareHeight=0;
fontSize=0;
opacity=0;
float k=0;
while(k<1)//while squares touches left boundary of chessboard
{
//squareX=(int)(maxWidth/2+(0-maxWidth/2)*k);//square moves in X direction from 320 to 0
squareY=(int)(0+(320-fontSize)*k);//square moves in X direction from 320 to 0
squareHeight=2*fontSize;
opacity=(int)(0+(220)*k);//opacity increases
font=new Font("LEPIFONT",Font.PLAIN,(int)fontSize);
FontMetrics fm=game.getChessBoard().pan.getFontMetrics(font);
int width=fm.stringWidth(greet);
squareWidth=width;
squareX=(maxWidth-width)/2;
if(width<maxWidth-20)
fontSize+=1;
//printData();
k+=0.01;
game.getChessBoard().refresh();
try
{
Thread.sleep(3);
}
catch (InterruptedException ie)
{
ie.printStackTrace();
}
}
if(!vanish)
return;
k=0;
while(k<1)
{
opacity=220*(1-k);
k+=0.01;
game.getChessBoard().refresh();
try
{
Thread.sleep(3);
}
catch (InterruptedException ie)
{
ie.printStackTrace();
}
}
}
public static void drawContent(Graphics2D g)
{
Color bgc,tc;
//maybe transition these colors
if(Environment.isDarkMode())
{
bgc=new Color(32, 51, 51,(int)opacity);
tc=new Color(250,250,250,(int)opacity);
}
else
{
bgc=new Color(255, 232, 224,(int)opacity);
tc=new Color(0,0,0,(int)opacity);
}
g.setColor(bgc);
g.fill(new RoundRectangle2D.Double(squareX,squareY,squareWidth,squareHeight,50,50));
g.setColor(tc);
g.setFont(font);
g.drawString(greet,(int)squareX,(int)(squareY+(squareHeight+fontSize)/2));
}
}