1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
package tsukuba_bunko.peko.scenario.stage; |
20 |
|
|
21 |
|
import org.xml.sax.Attributes; |
22 |
|
|
23 |
|
import tsukuba_bunko.peko.Logger; |
24 |
|
|
25 |
|
import tsukuba_bunko.peko.canvas.stage.Actor; |
26 |
|
|
27 |
|
import tsukuba_bunko.peko.resource.ResourceManager; |
28 |
|
|
29 |
|
import tsukuba_bunko.peko.scenario.PSMLUtil; |
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
public class ActorHandler extends StageElementHandler { |
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
public ActorHandler() |
43 |
|
{ |
44 |
0 |
super(); |
45 |
0 |
} |
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
public void startElement( String namespaceURI, String localName, String qName, Attributes attrs ) |
52 |
|
{ |
53 |
0 |
String name = PSMLUtil.getAttributeValue( attrs, "name" ); |
54 |
0 |
if( (name == null) || (name.length() == 0) ) { |
55 |
0 |
Logger.error( MessageIDs.SCN3001E, new Object[]{getSceneContext().getCurrentPath()} ); |
56 |
0 |
return; |
57 |
|
} |
58 |
|
|
59 |
0 |
String looks = PSMLUtil.getAttributeValue( attrs, "looks" ); |
60 |
0 |
String position = PSMLUtil.getAttributeValue( attrs, "position" ); |
61 |
|
|
62 |
0 |
StageCoordinator coordinator = getStageCoordinator(); |
63 |
0 |
if( localName.equals("enter") ) { |
64 |
0 |
if( coordinator.getActor(name) != null ) { |
65 |
0 |
Logger.warn( MessageIDs.SCN3008W, new Object[]{name, getSceneContext().getCurrentPath()} ); |
66 |
|
} |
67 |
0 |
Actor actor = new Actor( name ); |
68 |
0 |
actor.setLooks( looks ); |
69 |
0 |
setPosition( actor, ((position == null)?"center":position), "center" ); |
70 |
0 |
coordinator.enter( actor ); |
71 |
0 |
} |
72 |
0 |
else if( localName.equals("action") ) { |
73 |
0 |
Actor actor = coordinator.getActor( name ); |
74 |
0 |
if( actor == null ) { |
75 |
0 |
Logger.warn( MessageIDs.SCN3002W, new Object[]{name, getSceneContext().getCurrentPath()} ); |
76 |
0 |
} |
77 |
|
else { |
78 |
0 |
if( looks != null ) { |
79 |
0 |
actor.setLooks( looks ); |
80 |
|
} |
81 |
0 |
setPosition( actor, position, null ); |
82 |
|
} |
83 |
0 |
coordinator.action( actor ); |
84 |
0 |
} |
85 |
0 |
else if( localName.equals("exit") ) { |
86 |
0 |
if( coordinator.exit(name) == null ) { |
87 |
0 |
Logger.warn( MessageIDs.SCN3002W, new Object[]{name, getSceneContext().getCurrentPath()} ); |
88 |
|
} |
89 |
|
} |
90 |
|
|
91 |
0 |
String effect = PSMLUtil.getAttributeValue( attrs, "effect" ); |
92 |
0 |
if( effect == null ) { |
93 |
0 |
ResourceManager resources = ResourceManager.getInstance(); |
94 |
0 |
effect = (String)resources.getResource( ResourceIDs.DEFAULT_EFFECT_ACTOR, true ); |
95 |
|
} |
96 |
0 |
if( !coordinator.isSlideVisible() ) { |
97 |
0 |
coordinator.updateStage( effect ); |
98 |
|
} |
99 |
0 |
} |
100 |
|
|
101 |
|
protected void setPosition( Actor actor, String position, String defaultPosition ) |
102 |
|
{ |
103 |
0 |
if( position == null ) { |
104 |
0 |
return; |
105 |
|
} |
106 |
|
|
107 |
0 |
if( "center".equals(position) ) { |
108 |
0 |
actor.setPosition( Actor.POSITION_CENTER ); |
109 |
0 |
} |
110 |
0 |
else if( "left".equals(position) ) { |
111 |
0 |
actor.setPosition( Actor.POSITION_LEFT ); |
112 |
0 |
} |
113 |
0 |
else if( "right".equals(position) ) { |
114 |
0 |
actor.setPosition( Actor.POSITION_RIGHT ); |
115 |
0 |
} |
116 |
|
else { |
117 |
|
try { |
118 |
0 |
actor.setPosition( Float.parseFloat(position) ); |
119 |
|
} |
120 |
0 |
catch( Exception e ) { |
121 |
0 |
Logger.warn( MessageIDs.SCN3005W, new Object[]{getSceneContext().getCurrentPath()}, e ); |
122 |
0 |
setPosition( actor, defaultPosition, null ); |
123 |
0 |
} |
124 |
|
} |
125 |
0 |
} |
126 |
|
} |