| 
									
										
										
										
											2019-08-12 14:51:54 +08:00
										 |  |  |  | // Copyright (c) 2016-2018 Kiwano - Nomango
 | 
					
						
							| 
									
										
										
										
											2020-01-21 10:09:55 +08:00
										 |  |  |  | //
 | 
					
						
							| 
									
										
										
										
											2019-08-12 14:51:54 +08:00
										 |  |  |  | // Permission is hereby granted, free of charge, to any person obtaining a copy
 | 
					
						
							|  |  |  |  | // of this software and associated documentation files (the "Software"), to deal
 | 
					
						
							|  |  |  |  | // in the Software without restriction, including without limitation the rights
 | 
					
						
							|  |  |  |  | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 | 
					
						
							|  |  |  |  | // copies of the Software, and to permit persons to whom the Software is
 | 
					
						
							|  |  |  |  | // furnished to do so, subject to the following conditions:
 | 
					
						
							| 
									
										
										
										
											2020-01-21 10:09:55 +08:00
										 |  |  |  | //
 | 
					
						
							| 
									
										
										
										
											2019-08-12 14:51:54 +08:00
										 |  |  |  | // The above copyright notice and this permission notice shall be included in
 | 
					
						
							|  |  |  |  | // all copies or substantial portions of the Software.
 | 
					
						
							| 
									
										
										
										
											2020-01-21 10:09:55 +08:00
										 |  |  |  | //
 | 
					
						
							| 
									
										
										
										
											2019-08-12 14:51:54 +08:00
										 |  |  |  | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | 
					
						
							|  |  |  |  | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | 
					
						
							|  |  |  |  | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 | 
					
						
							|  |  |  |  | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 | 
					
						
							|  |  |  |  | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 | 
					
						
							|  |  |  |  | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 | 
					
						
							|  |  |  |  | // THE SOFTWARE.
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | #pragma once
 | 
					
						
							| 
									
										
										
										
											2019-12-23 18:05:08 +08:00
										 |  |  |  | #include <kiwano/2d/Actor.h>
 | 
					
						
							|  |  |  |  | #include <kiwano/2d/Stage.h>
 | 
					
						
							|  |  |  |  | #include <kiwano/2d/Transition.h>
 | 
					
						
							| 
									
										
										
										
											2020-01-21 10:09:55 +08:00
										 |  |  |  | #include <kiwano/core/Component.h>
 | 
					
						
							| 
									
										
										
										
											2019-08-12 14:51:54 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | namespace kiwano | 
					
						
							|  |  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-01-21 10:09:55 +08:00
										 |  |  |  | /**
 | 
					
						
							|  |  |  |  |  * \~chinese | 
					
						
							| 
									
										
										
										
											2020-02-10 17:32:04 +08:00
										 |  |  |  |  * @brief 导演 | 
					
						
							|  |  |  |  |  * @details 导演完成舞台的渲染、更新、事件分发以及控制舞台间跳转 | 
					
						
							| 
									
										
										
										
											2020-01-21 10:09:55 +08:00
										 |  |  |  |  * @see kiwano::Stage | 
					
						
							|  |  |  |  |  */ | 
					
						
							|  |  |  |  | class KGE_API Director | 
					
						
							|  |  |  |  |     : public Singleton<Director> | 
					
						
							|  |  |  |  |     , public UpdateComponent | 
					
						
							|  |  |  |  |     , public RenderComponent | 
					
						
							|  |  |  |  |     , public EventComponent | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  |     friend Singleton<Director>; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | public: | 
					
						
							|  |  |  |  |     /**
 | 
					
						
							|  |  |  |  |      * \~chinese | 
					
						
							| 
									
										
										
										
											2020-02-10 17:32:04 +08:00
										 |  |  |  |      * @brief 切换舞台 | 
					
						
							|  |  |  |  |      * @param[in] stage 舞台 | 
					
						
							|  |  |  |  |      * @param[in] transition 过渡动画 | 
					
						
							| 
									
										
										
										
											2020-01-21 10:09:55 +08:00
										 |  |  |  |      */ | 
					
						
							|  |  |  |  |     void EnterStage(StagePtr stage, TransitionPtr transition = nullptr); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     /**
 | 
					
						
							|  |  |  |  |      * \~chinese | 
					
						
							| 
									
										
										
										
											2020-02-10 17:32:04 +08:00
										 |  |  |  |      * @brief 切换舞台,并将当前舞台储存到栈中 | 
					
						
							|  |  |  |  |      * @param[in] stage 舞台 | 
					
						
							|  |  |  |  |      * @param[in] transition 过渡动画 | 
					
						
							| 
									
										
										
										
											2020-01-21 10:09:55 +08:00
										 |  |  |  |      */ | 
					
						
							|  |  |  |  |     void PushStage(StagePtr stage, TransitionPtr transition = nullptr); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     /**
 | 
					
						
							|  |  |  |  |      * \~chinese | 
					
						
							| 
									
										
										
										
											2020-02-10 17:32:04 +08:00
										 |  |  |  |      * @brief 退出当前舞台,并切换到上一个舞台 | 
					
						
							|  |  |  |  |      * @param[in] transition 过渡动画 | 
					
						
							| 
									
										
										
										
											2020-01-21 10:09:55 +08:00
										 |  |  |  |      */ | 
					
						
							|  |  |  |  |     void PopStage(TransitionPtr transition = nullptr); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     /**
 | 
					
						
							|  |  |  |  |      * \~chinese | 
					
						
							| 
									
										
										
										
											2020-02-10 17:32:04 +08:00
										 |  |  |  |      * @brief 获取当前舞台 | 
					
						
							|  |  |  |  |      * @return 返回当前舞台的指针 | 
					
						
							| 
									
										
										
										
											2020-01-21 10:09:55 +08:00
										 |  |  |  |      */ | 
					
						
							|  |  |  |  |     StagePtr GetCurrentStage(); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     /**
 | 
					
						
							|  |  |  |  |      * \~chinese | 
					
						
							| 
									
										
										
										
											2020-02-10 17:32:04 +08:00
										 |  |  |  |      * @brief 启用或禁用角色边界渲染功能 | 
					
						
							|  |  |  |  |      * @param enabled 是否启用 | 
					
						
							| 
									
										
										
										
											2020-01-21 10:09:55 +08:00
										 |  |  |  |      */ | 
					
						
							|  |  |  |  |     void SetRenderBorderEnabled(bool enabled); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     /**
 | 
					
						
							|  |  |  |  |      * \~chinese | 
					
						
							| 
									
										
										
										
											2020-02-10 17:32:04 +08:00
										 |  |  |  |      * @brief 显示或隐藏调试信息 | 
					
						
							|  |  |  |  |      * @param show 是否显示 | 
					
						
							| 
									
										
										
										
											2020-01-21 10:09:55 +08:00
										 |  |  |  |      */ | 
					
						
							|  |  |  |  |     void ShowDebugInfo(bool show = true); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     /**
 | 
					
						
							|  |  |  |  |      * \~chinese | 
					
						
							| 
									
										
										
										
											2020-02-10 17:32:04 +08:00
										 |  |  |  |      * @brief 退出当前舞台并清空舞台栈 | 
					
						
							| 
									
										
										
										
											2020-01-21 10:09:55 +08:00
										 |  |  |  |      */ | 
					
						
							|  |  |  |  |     void ClearStages(); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | public: | 
					
						
							|  |  |  |  |     void SetupComponent() override {} | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     void DestroyComponent() override {} | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     void OnUpdate(Duration dt) override; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     void OnRender(RenderContext& ctx) override; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     void HandleEvent(Event* evt) override; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | private: | 
					
						
							|  |  |  |  |     Director(); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     virtual ~Director(); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | private: | 
					
						
							|  |  |  |  |     bool            render_border_enabled_; | 
					
						
							|  |  |  |  |     Stack<StagePtr> stages_; | 
					
						
							|  |  |  |  |     StagePtr        current_stage_; | 
					
						
							|  |  |  |  |     StagePtr        next_stage_; | 
					
						
							|  |  |  |  |     ActorPtr        debug_actor_; | 
					
						
							|  |  |  |  |     TransitionPtr   transition_; | 
					
						
							|  |  |  |  | }; | 
					
						
							|  |  |  |  | }  // namespace kiwano
 |