2 * Copyright (c) 2020 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-event.h>
21 #include <dali/public-api/animation/animation.h>
22 #include <dali/public-api/actors/camera-actor.h>
23 #include <dali/public-api/object/property-map.h>
24 #include <dali/public-api/render-tasks/render-task-list.h>
25 #include <dali-toolkit/public-api/visuals/visual-properties.h>
26 #include <dali-toolkit/public-api/visuals/color-visual-properties.h>
29 using namespace Dali::Toolkit;
31 FppGameTutorialController::FppGameTutorialController()
32 : mLeftTutorialComplete( false ),
33 mRightTutorialComplete( false )
38 FppGameTutorialController::~FppGameTutorialController()
43 void FppGameTutorialController::OnTouch( const TouchEvent& touchEvent )
45 Vector2 size( mWindow.GetSize() );
47 bool isLandscape( size.x > size.y );
51 std::swap( size.x, size.y );
54 Vector2 sizeHalf( size * 0.5f );
56 for( size_t i = 0; i < touchEvent.GetPointCount(); ++i )
58 Vector2 pos = touchEvent.GetScreenPosition( i );
61 std::swap( pos.x, pos.y );
65 if( touchEvent.GetState( i ) == PointState::STARTED )
67 if( pos.x < sizeHalf.x && !mLeftTutorialComplete )
69 mLeftTutorialComplete = true;
70 Animation animation = Animation::New( 1.0f );
71 animation.AnimateTo( Property( mLeftLabel, Actor::Property::COLOR_ALPHA ), 0.0f );
73 // connect complete signal
74 if( mRightTutorialComplete )
76 animation.FinishedSignal().Connect( this, &FppGameTutorialController::OnTutorialComplete );
80 // right label touched
81 else if( !mRightTutorialComplete )
83 mRightTutorialComplete = true;
84 Animation animation = Animation::New( 1.0f );
85 animation.AnimateTo( Property( mRightLabel, Actor::Property::COLOR_ALPHA ), 0.0f );
86 // connect complete signal
87 if( mLeftTutorialComplete )
89 animation.FinishedSignal().Connect( this, &FppGameTutorialController::OnTutorialComplete );
97 void FppGameTutorialController::DisplayTutorial( Dali::Window window )
101 Vector2 windowSize( mWindow.GetSize() );
102 bool isLandscape( windowSize.x > windowSize.y );
105 std::swap( windowSize.x, windowSize.y );
108 mUiRoot = Actor::New();
109 mWindow.Add( mUiRoot );
111 // left tutorial text label
112 mLeftLabel = Toolkit::TextLabel::New("Touch here to walk");
113 mLeftLabel.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
114 mLeftLabel.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
115 mLeftLabel.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
116 mLeftLabel.SetProperty( Actor::Property::SIZE, Vector3( windowSize.x*0.5, windowSize.y, 1.0f ) );
117 mLeftLabel.SetProperty( Toolkit::Control::Property::BACKGROUND,
118 Property::Map().Add( Toolkit::Visual::Property::TYPE, Visual::COLOR )
119 .Add( ColorVisual::Property::MIX_COLOR, Vector4( 0.0, 0.0, 0.7, 0.2 ) ) );
120 mLeftLabel.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) ); // White.
121 mLeftLabel.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
122 mLeftLabel.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
124 // right tutorial text label
125 mRightLabel = Toolkit::TextLabel::New("Touch here to look around");
126 mRightLabel.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
127 mRightLabel.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
128 mRightLabel.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
129 mRightLabel.SetProperty( Actor::Property::SIZE, Vector3( windowSize.x*0.5, windowSize.y, 1.0f ) );
130 mRightLabel.SetProperty( Toolkit::Control::Property::BACKGROUND,
131 Property::Map().Add( Toolkit::Visual::Property::TYPE, Visual::COLOR )
132 .Add( ColorVisual::Property::MIX_COLOR, Vector4( 0.5, 0.0, 0.0, 0.2 ) ) );
133 mRightLabel.SetProperty( Toolkit::TextLabel::Property::TEXT_COLOR, Vector4( 1.0f, 1.0f, 1.0f, 1.0f ) ); // White.
134 mRightLabel.SetProperty( Toolkit::TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
135 mRightLabel.SetProperty( Toolkit::TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
137 // create camera dedicated to be used with UI controls
138 CameraActor uiCamera = CameraActor::New();
139 mTutorialRenderTask = mWindow.GetRenderTaskList().CreateTask();
140 mTutorialRenderTask.SetCameraActor( uiCamera );
141 mTutorialRenderTask.SetClearEnabled( false );
142 mTutorialRenderTask.SetSourceActor( mUiRoot );
143 mTutorialRenderTask.SetExclusive( true );
147 uiCamera.RotateBy( Degree(90.0f), Vector3( 0.0f, 0.0f, 1.0f ));
150 mLeftLabel.SetProperty( Actor::Property::POSITION, Vector3( -windowSize.x*0.25f, 0.0, 0.0 ) );
151 mRightLabel.SetProperty( Actor::Property::POSITION, Vector3( windowSize.x*0.25f, 0.0, 0.0 ) );
153 mUiRoot.Add( mLeftLabel );
154 mUiRoot.Add( mRightLabel );
155 mWindow.Add( uiCamera );
157 Animation animation = Animation::New( 1.0f );
158 animation.AnimateTo( Property( mLeftLabel, Actor::Property::COLOR_ALPHA ), 1.0f, AlphaFunction::EASE_OUT );
159 animation.AnimateTo( Property( mRightLabel, Actor::Property::COLOR_ALPHA ), 1.0f, AlphaFunction::EASE_OUT );
161 animation.FinishedSignal().Connect( this, &FppGameTutorialController::OnTutorialAnimationFinished );
166 void FppGameTutorialController::OnTutorialAnimationFinished( Animation& animation )
168 // touch signal will wait for a single touch on each side of screen
169 mWindow.TouchSignal().Connect( this, &FppGameTutorialController::OnTouch );
172 void FppGameTutorialController::OnTutorialComplete( Animation& animation )
174 mWindow.Remove( mUiRoot );
176 mWindow.GetRenderTaskList().RemoveTask( mTutorialRenderTask );