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