2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include "fpp-game-tutorial-controller.h"
20 #include <dali/public-api/events/touch-data.h>
21 #include <dali/public-api/animation/animation.h>
22 #include <dali/public-api/actors/camera-actor.h>
23 #include <dali/public-api/render-tasks/render-task-list.h>
26 using namespace Dali::Toolkit;
28 FppGameTutorialController::FppGameTutorialController()
29 : mLeftTutorialComplete( false ),
30 mRightTutorialComplete( false )
35 FppGameTutorialController::~FppGameTutorialController()
40 void FppGameTutorialController::OnTouch( const TouchData& touchEvent )
42 Vector2 size( mStage.GetSize() );
44 bool isLandscape( size.x > size.y );
48 std::swap( size.x, size.y );
51 Vector2 sizeHalf( size * 0.5f );
53 for( size_t i = 0; i < touchEvent.GetPointCount(); ++i )
55 Vector2 pos = touchEvent.GetScreenPosition( i );
58 std::swap( pos.x, pos.y );
62 if( touchEvent.GetState( i ) == PointState::STARTED )
64 if( pos.x < sizeHalf.x && !mLeftTutorialComplete )
66 mLeftTutorialComplete = true;
67 Animation animation = Animation::New( 1.0f );
68 animation.AnimateTo( Property( mLeftLabel, Actor::Property::COLOR_ALPHA ), 0.0f );
70 // connect complete signal
71 if( mRightTutorialComplete )
73 animation.FinishedSignal().Connect( this, &FppGameTutorialController::OnTutorialComplete );
77 // right label touched
78 else if( !mRightTutorialComplete )
80 mRightTutorialComplete = true;
81 Animation animation = Animation::New( 1.0f );
82 animation.AnimateTo( Property( mRightLabel, Actor::Property::COLOR_ALPHA ), 0.0f );
83 // connect complete signal
84 if( mLeftTutorialComplete )
86 animation.FinishedSignal().Connect( this, &FppGameTutorialController::OnTutorialComplete );
94 void FppGameTutorialController::DisplayTutorial()
96 mStage = Stage::GetCurrent();
98 Vector2 stageSize( mStage.GetSize() );
99 bool isLandscape( stageSize.x > stageSize.y );
102 std::swap( stageSize.x, stageSize.y );
105 mUiRoot = Actor::New();
106 mStage.Add( mUiRoot );
108 // left tutorial text label
109 mLeftLabel = Toolkit::TextLabel::New("Touch here to walk");
110 mLeftLabel.SetParentOrigin( ParentOrigin::CENTER );
111 mLeftLabel.SetAnchorPoint( AnchorPoint::CENTER );
112 mLeftLabel.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
113 mLeftLabel.SetSize( Vector3( stageSize.x*0.5, stageSize.y, 1.0f ) );
114 mLeftLabel.SetProperty( Toolkit::Control::Property::BACKGROUND_COLOR, Vector4( 0.0, 0.0, 0.7, 0.2 ));
115 mLeftLabel.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) ); // White.
116 mLeftLabel.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
117 mLeftLabel.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
119 // right tutorial text label
120 mRightLabel = Toolkit::TextLabel::New("Touch here to look around");
121 mRightLabel.SetParentOrigin( ParentOrigin::CENTER );
122 mRightLabel.SetAnchorPoint( AnchorPoint::CENTER );
123 mRightLabel.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
124 mRightLabel.SetSize( Vector3( stageSize.x*0.5, stageSize.y, 1.0f ) );
125 mRightLabel.SetProperty( Toolkit::Control::Property::BACKGROUND_COLOR, Vector4( 0.5, 0.0, 0.0, 0.2 ));
126 mRightLabel.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) ); // White.
127 mRightLabel.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
128 mRightLabel.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
130 // create camera dedicated to be used with UI controls
131 CameraActor uiCamera = CameraActor::New();
132 mTutorialRenderTask = mStage.GetRenderTaskList().CreateTask();
133 mTutorialRenderTask.SetCameraActor( uiCamera );
134 mTutorialRenderTask.SetClearEnabled( false );
135 mTutorialRenderTask.SetSourceActor( mUiRoot );
136 mTutorialRenderTask.SetExclusive( true );
140 uiCamera.RotateBy( Degree(90.0f), Vector3( 0.0f, 0.0f, 1.0f ));
143 mLeftLabel.SetPosition( Vector3( -stageSize.x*0.25f, 0.0, 0.0 ) );
144 mRightLabel.SetPosition( Vector3( stageSize.x*0.25f, 0.0, 0.0 ) );
146 mUiRoot.Add( mLeftLabel );
147 mUiRoot.Add( mRightLabel );
148 mStage.Add( uiCamera );
150 Animation animation = Animation::New( 1.0f );
151 animation.AnimateTo( Property( mLeftLabel, Actor::Property::COLOR_ALPHA ), 1.0f, AlphaFunction::EASE_OUT );
152 animation.AnimateTo( Property( mRightLabel, Actor::Property::COLOR_ALPHA ), 1.0f, AlphaFunction::EASE_OUT );
154 animation.FinishedSignal().Connect( this, &FppGameTutorialController::OnTutorialAnimationFinished );
159 void FppGameTutorialController::OnTutorialAnimationFinished( Animation& animation )
161 // touch signal will wait for a single touch on each side of screen
162 mStage.TouchSignal().Connect( this, &FppGameTutorialController::OnTouch );
165 void FppGameTutorialController::OnTutorialComplete( Animation& animation )
167 mStage.Remove( mUiRoot );
169 mStage.GetRenderTaskList().RemoveTask( mTutorialRenderTask );