1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
package tsukuba_bunko.peko.canvas.stage; |
20 |
|
|
21 |
|
import java.awt.Color; |
22 |
|
import java.awt.Image; |
23 |
|
|
24 |
|
import java.io.Serializable; |
25 |
|
|
26 |
|
import java.util.HashMap; |
27 |
|
import java.util.Iterator; |
28 |
|
import java.util.Map; |
29 |
|
|
30 |
|
import tsukuba_bunko.peko.Logger; |
31 |
|
|
32 |
|
import tsukuba_bunko.peko.resource.ColorManager; |
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
public class Stage implements Serializable { |
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
private static final long serialVersionUID = -5885153839184445498L; |
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
0 |
transient private StageCanvas _canvas = null; |
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
0 |
private AudioPlayer _audioPlayer = new AudioPlayer(); |
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
|
61 |
0 |
transient private Map _actors = new HashMap(); |
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
|
66 |
0 |
private HashMap _committedActors = new HashMap(); |
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
|
71 |
0 |
transient private String _background = null; |
72 |
|
|
73 |
|
|
74 |
|
|
75 |
|
|
76 |
0 |
private String _committedBackground = null; |
77 |
|
|
78 |
|
|
79 |
|
|
80 |
|
|
81 |
0 |
transient private Image _backgroundImage = null; |
82 |
|
|
83 |
|
|
84 |
|
|
85 |
|
|
86 |
0 |
transient private Color _backgroundColor = null; |
87 |
|
|
88 |
|
|
89 |
|
|
90 |
|
|
91 |
0 |
private Color _committedBackgroundColor = null; |
92 |
|
|
93 |
|
|
94 |
|
|
95 |
|
|
96 |
0 |
transient private String _slide = null; |
97 |
|
|
98 |
|
|
99 |
|
|
100 |
|
|
101 |
0 |
private String _committedSlide = null; |
102 |
|
|
103 |
|
|
104 |
|
|
105 |
|
|
106 |
0 |
transient private Image _slideImage = null; |
107 |
|
|
108 |
|
|
109 |
|
|
110 |
|
|
111 |
|
|
112 |
|
public Stage() |
113 |
|
{ |
114 |
0 |
super(); |
115 |
0 |
} |
116 |
|
|
117 |
|
|
118 |
|
|
119 |
|
|
120 |
|
|
121 |
|
|
122 |
|
public void enter( Actor actor ) |
123 |
|
{ |
124 |
0 |
_actors.put( actor.getName(), actor ); |
125 |
0 |
} |
126 |
|
|
127 |
|
|
128 |
|
|
129 |
|
|
130 |
|
public Actor getName( String name ) |
131 |
|
{ |
132 |
0 |
return (Actor)_actors.get( name ); |
133 |
|
} |
134 |
|
|
135 |
|
|
136 |
|
|
137 |
|
|
138 |
|
public Actor exit( String name ) |
139 |
|
{ |
140 |
0 |
Actor actor = (Actor)_actors.remove( name ); |
141 |
0 |
if( actor != null ) { |
142 |
0 |
actor.disposeLooks(); |
143 |
|
} |
144 |
0 |
return actor; |
145 |
|
} |
146 |
|
|
147 |
|
|
148 |
|
|
149 |
|
|
150 |
|
public void exitAll() |
151 |
|
{ |
152 |
0 |
String[] names = (String[])_actors.keySet().toArray( new String[_actors.size()] ); |
153 |
0 |
for( int i = 0; i < names.length; ++i ) { |
154 |
0 |
exit( names[i] ); |
155 |
|
} |
156 |
0 |
} |
157 |
|
|
158 |
|
|
159 |
|
|
160 |
|
|
161 |
|
public Actor getActor( String name ) |
162 |
|
{ |
163 |
0 |
return (Actor)_actors.get( name ); |
164 |
|
} |
165 |
|
|
166 |
|
|
167 |
|
|
168 |
|
|
169 |
|
public Map getActors() |
170 |
|
{ |
171 |
0 |
return _actors; |
172 |
|
} |
173 |
|
|
174 |
|
|
175 |
|
|
176 |
|
|
177 |
|
|
178 |
|
public void setBackgroundImage( String image ) |
179 |
|
{ |
180 |
0 |
ImageManager images = ImageManager.getInstance(); |
181 |
0 |
if( (_backgroundImage != null) && !_background.equals(image) ) { |
182 |
0 |
images.putImage( _background, _backgroundImage ); |
183 |
0 |
_backgroundImage = null; |
184 |
|
} |
185 |
|
|
186 |
0 |
Image background = images.getImage( image ); |
187 |
0 |
if( background != null ) { |
188 |
0 |
_backgroundImage = background; |
189 |
0 |
_background = image; |
190 |
0 |
_backgroundColor = null; |
191 |
0 |
} |
192 |
0 |
else if( background == null ) { |
193 |
0 |
Logger.error( "[canvas.stage] invalid background-image :" + image ); |
194 |
0 |
_backgroundColor = Color.black; |
195 |
0 |
_background = "black"; |
196 |
|
} |
197 |
0 |
} |
198 |
|
|
199 |
|
|
200 |
|
|
201 |
|
|
202 |
|
|
203 |
|
public Image getBackgroundImage() |
204 |
|
{ |
205 |
0 |
return _backgroundImage; |
206 |
|
} |
207 |
|
|
208 |
|
|
209 |
|
|
210 |
|
|
211 |
|
|
212 |
|
public void setBackgroundColor( String color ) |
213 |
|
{ |
214 |
0 |
if( _backgroundImage != null ) { |
215 |
0 |
ImageManager images = ImageManager.getInstance(); |
216 |
0 |
images.putImage( _background, _backgroundImage ); |
217 |
0 |
_backgroundImage = null; |
218 |
|
} |
219 |
0 |
ColorManager colors = ColorManager.getInstance(); |
220 |
0 |
_backgroundColor = colors.getColor( color ); |
221 |
0 |
_background = color; |
222 |
0 |
} |
223 |
|
|
224 |
|
|
225 |
|
|
226 |
|
|
227 |
|
|
228 |
|
public Color getBackgroundColor() |
229 |
|
{ |
230 |
0 |
return _backgroundColor; |
231 |
|
} |
232 |
|
|
233 |
|
|
234 |
|
|
235 |
|
|
236 |
|
|
237 |
|
public void showSlide( String slide ) |
238 |
|
{ |
239 |
0 |
ImageManager images = ImageManager.getInstance(); |
240 |
0 |
if( (_slide != null) && !_slide.equals(slide) ) { |
241 |
0 |
images.putImage( _slide, _slideImage ); |
242 |
|
} |
243 |
0 |
_slideImage = images.getImage( slide ); |
244 |
0 |
_slide = slide; |
245 |
0 |
} |
246 |
|
|
247 |
|
|
248 |
|
|
249 |
|
|
250 |
|
public void hideSlide() |
251 |
|
{ |
252 |
0 |
if( _slideImage != null ) { |
253 |
0 |
ImageManager images = ImageManager.getInstance(); |
254 |
0 |
images.putImage( _slide, _slideImage ); |
255 |
|
} |
256 |
0 |
_slide = null; |
257 |
0 |
_slideImage = null; |
258 |
0 |
} |
259 |
|
|
260 |
|
|
261 |
|
|
262 |
|
|
263 |
|
|
264 |
|
public String getSlide() |
265 |
|
{ |
266 |
0 |
return _slide; |
267 |
|
} |
268 |
|
|
269 |
|
|
270 |
|
|
271 |
|
|
272 |
|
|
273 |
|
public Image getSlideImage() |
274 |
|
{ |
275 |
0 |
return _slideImage; |
276 |
|
} |
277 |
|
|
278 |
|
|
279 |
|
|
280 |
|
|
281 |
|
|
282 |
|
|
283 |
|
|
284 |
|
public void playBGM( String id, String clipName, boolean loop ) |
285 |
|
{ |
286 |
0 |
_audioPlayer.playBGM( id, clipName, loop ); |
287 |
0 |
} |
288 |
|
|
289 |
|
|
290 |
|
|
291 |
|
|
292 |
|
|
293 |
|
|
294 |
|
public void stopBGM( String id, int mode ) |
295 |
|
{ |
296 |
0 |
_audioPlayer.stop( id, mode ); |
297 |
0 |
} |
298 |
|
|
299 |
|
|
300 |
|
|
301 |
|
|
302 |
|
|
303 |
|
public void stopSE( String id, int mode ) |
304 |
|
{ |
305 |
0 |
_audioPlayer.stop( id, mode ); |
306 |
0 |
} |
307 |
|
|
308 |
|
|
309 |
|
|
310 |
|
|
311 |
|
|
312 |
|
|
313 |
|
|
314 |
|
public void playSE( String id, String clipName, boolean loop ) |
315 |
|
{ |
316 |
0 |
_audioPlayer.playSE( id, clipName, loop ); |
317 |
0 |
} |
318 |
|
|
319 |
|
|
320 |
|
|
321 |
|
|
322 |
|
|
323 |
|
public void setAudioPlayer( AudioPlayer audioPlayer ) |
324 |
|
{ |
325 |
0 |
_audioPlayer = audioPlayer; |
326 |
0 |
} |
327 |
|
|
328 |
|
|
329 |
|
|
330 |
|
|
331 |
|
|
332 |
|
public AudioPlayer getAudioPlayer() |
333 |
|
{ |
334 |
0 |
return _audioPlayer; |
335 |
|
} |
336 |
|
|
337 |
|
|
338 |
|
|
339 |
|
|
340 |
|
|
341 |
|
void setStageCanvas( StageCanvas canvas ) |
342 |
|
{ |
343 |
0 |
_canvas = canvas; |
344 |
0 |
} |
345 |
|
|
346 |
|
|
347 |
|
|
348 |
|
|
349 |
|
|
350 |
|
public StageCanvas getStageCanvas() |
351 |
|
{ |
352 |
0 |
return _canvas; |
353 |
|
} |
354 |
|
|
355 |
|
|
356 |
|
|
357 |
|
|
358 |
|
public void updateCanvas() |
359 |
|
{ |
360 |
0 |
_canvas.updateCanvas( null ); |
361 |
0 |
} |
362 |
|
|
363 |
|
|
364 |
|
|
365 |
|
|
366 |
|
public void updateCanvas( String effect ) |
367 |
|
{ |
368 |
0 |
if( _canvas != null ) { |
369 |
0 |
Logger.debug( "[canvas.stage] effect :" + effect ); |
370 |
0 |
_canvas.updateCanvas( effect ); |
371 |
|
} |
372 |
0 |
} |
373 |
|
|
374 |
|
|
375 |
|
public void commit() |
376 |
|
{ |
377 |
0 |
_committedActors.clear(); |
378 |
0 |
_committedActors.putAll( _actors ); |
379 |
0 |
_committedBackground = _background; |
380 |
0 |
_committedBackgroundColor = _backgroundColor; |
381 |
0 |
_committedSlide = _slide; |
382 |
0 |
} |
383 |
|
|
384 |
|
|
385 |
|
|
386 |
|
|
387 |
|
void dispose() |
388 |
|
{ |
389 |
0 |
Iterator itr = _actors.values().iterator(); |
390 |
0 |
while( itr.hasNext() ) { |
391 |
0 |
((Actor)itr.next()).disposeLooks(); |
392 |
0 |
} |
393 |
|
|
394 |
0 |
if( _backgroundImage != null ) { |
395 |
0 |
ImageManager images = ImageManager.getInstance(); |
396 |
0 |
images.putImage( _background, _backgroundImage ); |
397 |
|
} |
398 |
|
|
399 |
0 |
_audioPlayer.stopAll(); |
400 |
0 |
} |
401 |
|
|
402 |
|
|
403 |
|
|
404 |
|
|
405 |
|
public void prepare() |
406 |
|
{ |
407 |
0 |
if( _actors == null ) { |
408 |
0 |
_actors = (Map)_committedActors.clone(); |
409 |
|
} |
410 |
|
|
411 |
0 |
Iterator itr = _actors.values().iterator(); |
412 |
0 |
while( itr.hasNext() ) { |
413 |
0 |
((Actor)itr.next()).prepare(); |
414 |
0 |
} |
415 |
|
|
416 |
0 |
if( _committedBackgroundColor == null ) { |
417 |
0 |
setBackgroundImage( _committedBackground ); |
418 |
0 |
} |
419 |
|
else { |
420 |
0 |
_background = _committedBackground; |
421 |
0 |
_backgroundColor = _committedBackgroundColor; |
422 |
|
} |
423 |
|
|
424 |
0 |
if( _committedSlide != null ) { |
425 |
0 |
showSlide( _committedSlide ); |
426 |
|
} |
427 |
|
|
428 |
0 |
updateCanvas(); |
429 |
0 |
} |
430 |
|
} |