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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
|
package NET.worlds.scape;
import NET.worlds.console.Console;
import NET.worlds.network.URL;
import java.awt.Color;
class MaterialTexture extends SuperRoot implements NonPersister {
private URL fileName;
private StringTexture stexture;
private String text = "";
private String font = Console.message("MaterialFont");
private int size = 48;
private Color foregroundColor = Color.white;
private Color backgroundColor = Color.black;
MaterialTexture(URL textureName) {
this.fileName = textureName;
}
MaterialTexture(StringTexture texture) {
this.stexture = texture;
this.text = this.stexture.getText();
this.font = this.stexture.getFont();
this.size = this.stexture.getSize();
this.foregroundColor = this.stexture.getForegroundColor();
this.backgroundColor = this.stexture.getBackgroundColor();
}
private void setFile(URL name, boolean force) {
this.fileName = name;
if (this.stexture == null || force) {
this.stexture = null;
((Material)this.getOwner()).loadTexture(name);
}
}
private void makeString() {
Material owner = (Material)this.getOwner();
this.stexture = new StringTexture(this.text, this.font, this.size, this.foregroundColor, this.backgroundColor);
owner.setTexture(this.stexture);
}
private String getText() {
return this.text;
}
private void setText(String text) {
this.text = text;
if (this.stexture != null) {
this.makeString();
}
}
private void setFont(String font) {
this.font = font;
if (this.stexture != null) {
this.makeString();
}
}
private void setSize(int size) {
if (size >= 1 && size <= 720) {
this.size = size;
if (this.stexture != null) {
this.makeString();
}
} else {
Console.println(Console.message("Font-sizes"));
}
}
private void setForegroundColor(Color color) {
this.foregroundColor = color;
if (this.stexture != null) {
this.makeString();
}
}
private void setBackgroundColor(Color color) {
this.backgroundColor = color;
if (this.stexture != null) {
this.makeString();
}
}
@Override
public Object properties(int index, int offset, int mode, Object value) throws NoSuchPropertyException {
Object ret = null;
switch (index - offset) {
case 0:
if (mode == 0) {
ret = BooleanPropertyEditor.make(
new Property(this, index, "Texture Type (Text String)"), "Texture loaded from an image file.", "Texture created from a text string."
);
} else if (mode == 1) {
ret = new Boolean(this.stexture != null);
} else if (mode == 2) {
boolean stringTexture = (Boolean)value;
if (stringTexture && this.stexture == null) {
this.makeString();
} else if (!stringTexture && this.stexture != null) {
this.setFile(this.fileName, true);
}
}
break;
case 1:
if (mode == 0) {
ret = new Property(this, index, "File");
if (this.stexture == null) {
ret = URLPropertyEditor.make((Property)ret, TextureDecoder.getAllExts());
}
} else if (mode == 1) {
ret = this.fileName;
} else if (mode == 2) {
this.setFile((URL)value, false);
}
break;
case 2:
if (mode == 0) {
ret = new Property(this, index, "Text");
if (this.stexture != null) {
ret = StringPropertyEditor.make((Property)ret);
}
} else if (mode == 1) {
ret = this.getText();
} else if (mode == 2) {
this.setText((String)value);
}
break;
case 3:
if (mode == 0) {
ret = new Property(this, index, "Font");
if (this.stexture != null) {
ret = StringPropertyEditor.make((Property)ret);
}
} else if (mode == 1) {
ret = this.font;
} else if (mode == 2) {
this.setFont((String)value);
}
System.out.println("Setting font " + (String)value + " in Material.java");
break;
case 4:
if (mode == 0) {
ret = new Property(this, index, "Size");
if (this.stexture != null) {
ret = IntegerPropertyEditor.make((Property)ret);
}
} else if (mode == 1) {
ret = new Integer(this.size);
} else if (mode == 2) {
this.setSize((Integer)value);
}
break;
case 5:
if (mode == 0) {
ret = new Property(this, index, "Foreground Color");
if (this.stexture != null) {
ret = ColorPropertyEditor.make((Property)ret);
}
} else if (mode == 1) {
ret = this.foregroundColor;
} else if (mode == 2) {
this.setForegroundColor((Color)value);
}
break;
case 6:
if (mode == 0) {
ret = new Property(this, index, "Background Color");
if (this.stexture != null) {
ret = ColorPropertyEditor.make((Property)ret);
}
} else if (mode == 1) {
ret = this.backgroundColor;
} else if (mode == 2) {
this.setBackgroundColor((Color)value);
}
break;
default:
ret = super.properties(index, offset + 7, mode, value);
}
return ret;
}
@Override
public String toString() {
if (this.stexture != null) {
return "" + this.stexture;
} else {
Material owner = (Material)this.getOwner();
URL name = null;
if (owner != null) {
name = owner.textureName;
}
return name == null ? "File " : "File " + name;
}
}
}
|