-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTextBoxAsgm.java
More file actions
101 lines (99 loc) · 2.9 KB
/
TextBoxAsgm.java
File metadata and controls
101 lines (99 loc) · 2.9 KB
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
package awpsoft.gamemodule;
import java.nio.CharBuffer;
import awpsoft.gamemodule.AsgmDrawFactory.*;
import java.awt.Font;
public class TextBoxAsgm extends MovingGameObject2DAsgm
{
protected CharBuffer Text;
protected int StrLength;
public float TextLeftX, TextRightX, TextTopY, TypedLength, TypeSpeed;
public boolean BoundAlpha, BoundTrasnform, UseRelativePos, TypingMode;
public Font TextFormat;
public float ColorR, ColorG, ColorB, ColorA;
public TextBoxAsgm()
{
Text = null;
StrLength = 0;
ColorR = ColorG = ColorB = ColorA = 1.0f;
TextFormat = null;
TextLeftX = TextTopY = 0.0f;
TextRightX = 1280.0f;
TypingMode = false;
TypedLength = 0.0f;
TypeSpeed = 0.020f;
BoundAlpha = false;
BoundTrasnform = false;
UseRelativePos = true;
}
public void skipTyping()
{
TypedLength = (float)StrLength;
}
public boolean isTypingComplete()
{
if (TypedLength + 0.5 >= (float)StrLength) return true;
else return false;
}
public void setText(CharBuffer str)
{
Text = str;
if(str == null) StrLength = 0;
else StrLength = Text.length();
}
public void setText(String str)
{
if(str == null)
{
Text = null;
StrLength = 0;
}
else
{
Text = CharBuffer.wrap(str.toCharArray());
StrLength = Text.length();
}
}
@Override public void reset() {if(TypingMode) TypedLength = 0;}
@Override public boolean giveTime(int timeGived)
{
if (super.giveTime(timeGived)) return false;
if (TypedLength < (float)StrLength)
TypedLength += TypeSpeed * (float) timeGived;
if (TypedLength > (float)StrLength)
TypedLength = (float)StrLength;
return true;
}
public TextParameters getTextParameters()
{
TextParameters temp = new TextParameters();
if (!Enable) return temp;
temp.Visible = Visible;
if (!temp.Visible) return temp;
temp.ColorR = ColorR;
temp.ColorG = ColorG;
temp.ColorB = ColorB;
temp.ColorA = ColorA;
temp.TextFormat = TextFormat;
temp.StrBuffer = Text;
temp.SecondaryAlpha = BoundAlpha ? SecondaryAlpha : 1.0f;
temp.XLeft = UseRelativePos ? (TextLeftX + PosCenterX) : TextLeftX;
temp.XRight = UseRelativePos ? (TextRightX + PosCenterX) : TextRightX;
temp.YTop = UseRelativePos ? (TextTopY + PosCenterY) : TextTopY;
temp.StrLength = (!TypingMode || isTypingComplete()) ? StrLength : (Math.max(0, (int)(TypedLength + 0.5)));
return temp;
}
@Override public void draw(AsgmDrawFactory drawFactory)
{
if (!Enable || !Visible) return;
if (BoundTrasnform)
{
drawFactory.drawStep(getDrawParameters(), true);
drawFactory.drawTextStep(getTextParameters(), false);
}
else
{
drawFactory.drawStep(getDrawParameters(), false);
drawFactory.drawTextStep(getTextParameters(), true);
}
}
}