View Javadoc

1   /*
2    * All Rights Reserved.
3    * Copyright (C) 1999-2005 Tsukuba Bunko.
4    *
5    * Licensed under the BSD License ("the License"); you may not use
6    * this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    *
9    *       http://www.tsukuba-bunko.org/licenses/LICENSE.txt
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   *
17   * $Id: StageCoordinator.java,v 1.3 2005/08/19 03:18:11 ppoi Exp $
18   */
19  package tsukuba_bunko.peko.scenario.stage;
20  
21  import	tsukuba_bunko.peko.ActionControler;
22  import tsukuba_bunko.peko.Logger;
23  
24  import	tsukuba_bunko.peko.canvas.stage.Actor;
25  import	tsukuba_bunko.peko.canvas.stage.Stage;
26  
27  import tsukuba_bunko.peko.scenario.Coordinator;
28  import	tsukuba_bunko.peko.scenario.SceneContext;
29  
30  
31  /***
32   * StageCanvas への操作を取り持つコーディネータモジュールです。
33   * @author	$Author: ppoi $
34   * @version	$Revision: 1.3 $ $Date: 2005/08/19 03:18:11 $
35   */
36  public class StageCoordinator	extends Coordinator	{
37  
38  	/***
39  	 * 立ち位置:中央
40  	 */
41  	public static final int	POSITION_CENTER = 0;
42  
43  	/***
44  	 * 立ち位置:左
45  	 */
46  	public static final int	POSITION_LEFT = 1;
47  
48  	/***
49  	 * 立ち位置:右
50  	 */
51  	public static final int	POSITION_RIGHT = 2;
52  
53  
54  	/***
55  	 * ネストレベル
56  	 */
57  	protected int	_level = 0;
58  
59  
60  	/***
61  	 * <code>StageCoordinator</code> のインスタンスを生成します。
62  	 */
63  	public StageCoordinator()
64  	{
65  		super();
66  	}
67  
68  
69  	/***
70  	 * <code>name</code> で識別される役者の情報を取得します。
71  	 * @param	name	役者名
72  	 * @return	Actor オブジェクト。該当する役者がいない場合 <code>null</code>
73  	 */
74  	public Actor getActor( String name )
75  	{
76  		Actor	actor = getStage().getActor( name );
77  		if( actor == null )	{
78  			return null;
79  		}
80  		else	{
81  			Actor	copy = new Actor( actor.getName() );
82  			actor.copyTo( copy );
83  			return copy;
84  		}
85  	}
86  
87  
88  	/***
89  	 * 役者を舞台に登場させます。
90  	 * @param	actor	登場する役者
91  	 */
92  	public void enter( Actor actor )
93  	{
94  		if( isActiveThread() )	{
95  			getStage().enter( actor );
96  		}
97  	}
98  
99  	/***
100 	 * 役者を動かします。
101 	 * @param	actor	動かす役者
102 	 */
103 	public void action( Actor actor )
104 	{
105 		if( isActiveThread() )	{
106 			Stage	stage = getStage();
107 			Actor	current = stage.getActor( actor.getName() );
108 			if( current != null )	{
109 				if( current.getLooksImage() != actor.getLooksImage() )	{
110 					stage.exit( actor.getName() );
111 					stage.enter( actor );
112 				}
113 				else	{
114 					stage.enter( actor );
115 				}
116 			}
117 		}
118 	}
119 
120 	/***
121 	 * 役者を退場させます。
122 	 * @param	name	退場させる役者名
123 	 * @return	退場した役者
124 	 */
125 	public Actor exit( String name )
126 	{
127 		if( isActiveThread() )	{
128 			return getStage().exit( name );
129 		}
130 		else	{
131 			return null;
132 		}
133 	}
134 
135 	/***
136 	 * 背景を指定した色に設定します。
137 	 * @param	color	色名
138 	 */
139 	public void setBackgroundColor( String color )
140 	{
141 		if( isActiveThread() )	{
142 			getStage().setBackgroundColor( color );
143 		}
144 	}
145 
146 	/***
147 	 * 背景を指定された画像に設定します。
148 	 * @param	image	画像名
149 	 */
150 	public void setBackgroundImage( String image )
151 	{
152 		if( isActiveThread() )	{
153 			getStage().setBackgroundImage( image );
154 		}
155 	}
156 
157 	/***
158 	 * スライドを表示します。
159 	 * @param	slide	スライド名
160 	 */
161 	public void showSlide( String slide )
162 	{
163 		if( isActiveThread() )	{
164 			getStage().showSlide( slide );
165 		}
166 	}
167 
168 	/***
169 	 * スライドを隠します。
170 	 */
171 	public void hideSlide()
172 	{
173 		if( isActiveThread() )	{
174 			getStage().hideSlide();
175 		}
176 	}
177 
178 	/***
179 	 * BGM を再生します。
180 	 * @param	id	BGM ID
181 	 * @param	clipName	クリップ名
182 	 * @param	loop	ループする場合 <code>true</code>、それ以外の場合 <code>false</code>
183 	 */
184 	public void playBGM( String id, String clipName, boolean loop )
185 	{
186 		if( isActiveThread() )	{
187 			getStage().playBGM( id, clipName, loop );
188 		}
189 	}
190 
191 	/***
192 	 * BGM を停止します。
193 	 * @param	id	BGM ID
194 	 */
195 	public void stopBGM( String id, int mode )
196 	{
197 		if( isActiveThread() )	{
198 			getStage().stopBGM( id, mode );
199 		}
200 	}
201 
202 	/***
203 	 * SE を再生します。
204 	 * @param	id	SE ID
205 	 * @param	clipName	クリップ名
206 	 * @param	loop	ループする場合 <code>true</code>、それ以外の場合 <code>false</code>
207 	 */
208 	public void playSE( String id, String clipName, boolean loop )
209 	{
210 		if( isActiveThread() )	{
211 			getStage().playSE( id, clipName, loop );
212 		}
213 	}
214 
215 	/***
216 	 * SE を停止します。
217 	 * @param	id	SE ID
218 	 */
219 	public void stopSE( String id, int mode )
220 	{
221 		if( isActiveThread() )	{
222 			getStage().stopSE( id, mode );
223 		}
224 	}
225 
226 	/***
227 	 * ステージを指定されたエフェクトを使用して更新します。
228 	 * @param	effect	エフェクト名
229 	 */
230 	public void updateStage( String effect )
231 	{
232 		Logger.debug( "[scenario.stage] update stage. effect=" + effect );
233 		if( _level > 1 )	{
234 			return;
235 		}
236 
237 		Stage	stage = getStage();
238 		stage.updateCanvas( effect );
239 	}
240 
241 	/***
242 	 * エフェクトを使用せずにステージを更新します。
243 	 */
244 	public void updateStage()
245 	{
246 		if( isActiveThread() )	{
247 			updateStage( null );
248 		}
249 	}
250 
251 	/***
252 	 * テキストキャンバスを隠します。
253 	 */
254 	public void hideTextCanvas()
255 	{
256 		if( isActiveThread() )	{
257 			getCanvasManager().hideTextCanvas();
258 		}
259 	}
260 
261 	/***
262 	 * ステージを取得します。
263 	 * @return	ステージ
264 	 */
265 	protected Stage getStage()
266 	{
267 		return getCanvasManager().getStage();
268 	}
269 
270 	/***
271 	 * スライドが表示中かどうかを判定します。
272 	 * @return	スライドが表示中の場合 <code>true</code>,非表示中の場合 <code>false</code>
273 	 */
274 	public boolean isSlideVisible()
275 	{
276 		return (getStage().getSlideImage() != null);
277 	}
278 
279 
280 //
281 //	Coordinator の実装
282 //
283 	public void prepare( SceneContext context, Thread activeThread )
284 	{
285 		super.prepare( context, activeThread );
286 		_level = 0;
287 	}
288 
289 	/***
290 	 * StageCanvas に対する操作を開始します。
291 	 */
292 	public void begin()
293 	{
294 		if( isActiveThread() )	{
295 			_level++;
296 			getCanvasManager().hideTextCanvas();
297 			getActionControler().setActive( false );
298 			getActionControler().setSaveEnabled( true );
299 		}
300 	}
301 
302 	/***
303 	 * StageCanvas に対する操作を終了し、キャンバスの状態を確定します。
304 	 */
305 	public void commit()
306 	{
307 		if( isActiveThread() )	{
308 			_level--;
309 			if( _level == 0 )	{
310 				ActionControler	controler = getActionControler();
311 				controler.setActive( true );
312 				controler.setSaveEnabled( false );
313 				Stage	stage = getStage();
314 				stage.commit();
315 			}
316 		}
317 	}
318 }