1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214 | #include "gfCTappableCollectableComponent.h"
#include <fsRenderer/src/components/fsCSpriteComponent.h>
#include <fsAppCore/src/components/fsISubSceneComponent.h>
#include <fsAppCore/fsIInputManager.h>
#include "gfCGhostSpriteComponent.h"
const fsCUniqueId gfCTappableCollectableComponent::mTypeId("fsCTappableCollectableComponent");
void gfCTappableCollectableComponent::inputStealDo()
{
mTakingInput = false;
fsIInputManager::instanceGet()->priorityListenerDeregister(this);
fsIInputManager::sPointerMsgParam message;
message.mPos = fsPoint(0, 0);
message.mIdx = 0;
message.mDown = true;
fsIInputManager::instanceGet()->messageDispatch(fsIInputManager::mPointerDownStealMsg, message);
}
void gfCTappableCollectableComponent::deserialiseDo()
{
gfICollectableComponent::deserialiseDo();
if (eCOLLECTION_STATE::eCOLLECTIBLE == stateGet() && mGhostSpriteComp)
{
mGhostSpriteComp->parentEntityInteractiveSet(true);
}
}
void gfCTappableCollectableComponent::deactivateDo()
{
if (mGhostSpriteComp)
{
mGhostSpriteComp->parentEntityInteractiveSet(false);
}
}
void gfCTappableCollectableComponent::activateDo()
{
if (mGhostSpriteComp)
{
mGhostSpriteComp->parentEntityInteractiveSet(true);
}
}
void gfCTappableCollectableComponent::listenersDeregisterDo()
{
gfICollectableComponent::listenersDeregisterDo();
fsIInputManager::instanceGet()->listenerDeregister(fsIInputManager::mPointerDownMsg, this);
fsIInputManager::instanceGet()->listenerDeregister(fsIInputManager::mPointerMoveMsg, this);
fsIInputManager::instanceGet()->listenerDeregister(fsIInputManager::mPointerUpMsg, this);
}
void gfCTappableCollectableComponent::listenersRegisterDo()
{
gfICollectableComponent::listenersRegisterDo();
fsIInputManager::instanceGet()->listenerRegister(fsIInputManager::mPointerDownMsg, this);
fsIInputManager::instanceGet()->listenerRegister(fsIInputManager::mPointerMoveMsg, this);
fsIInputManager::instanceGet()->listenerRegister(fsIInputManager::mPointerUpMsg, this);
}
fsBool gfCTappableCollectableComponent::mouseNoLongerOver(const fsIMessageDispatcher::sMessageParameters& pParam)
{
const auto& mousePos = static_cast<const fsIInputManager::sPointerMsgParam&>(pParam).mPos;
if (mTakingInput && !hitTest(mousePos))
{
static_cast<const fsIInputManager::sPointerMsgParam&>(pParam).mStealableFrom = this;
mTakingInput = false;
return true;
}
return false;
}
fsBool gfCTappableCollectableComponent::messageProcessDo(const fsCUniqueId& pMessageType,
const fsIMessageDispatcher::sMessageParameters& pParam)
{
if (eCOLLECTION_STATE::eCOLLECTIBLE == stateGet())
{
if (fsIInputManager::mPointerDownMsg == pMessageType)
{
return pointerDownHandle(pParam);
}
if (fsIInputManager::mPointerMoveMsg == pMessageType)
{
if (mouseNoLongerOver(pParam))
{
return false;
}
return mTakingInput;
}
if (fsIInputManager::mPointerUpMsg == pMessageType && mTakingInput)
{
pointerUpHandle(static_cast<const fsIInputManager::sPointerMsgParam&>(pParam).mPos);
return true;
}
}
else if (eCOLLECTION_STATE::eCOLLECTED_EFFECT_PLAYING == stateGet())
{
if (fsIInputManager::mPointerDownMsg == pMessageType)
{
gfICollectableComponent::messageProcessDo(pMessageType, pParam);
auto& mousePos = static_cast<const fsIInputManager::sPointerMsgParam&>(pParam).mPos;<--- Variable 'mousePos' can be declared as reference to const
if (hitTest(mousePos))
{
return true;
}
return false;
}
}
return gfICollectableComponent::messageProcessDo(pMessageType, pParam);
}
fsBool gfCTappableCollectableComponent::pointerDownHandle(const fsIMessageDispatcher::sMessageParameters& pParam)
{
auto messageParams = static_cast<const fsIInputManager::sPointerMsgParam&>(pParam);
if (0 == messageParams.mIdx)
{
if (hitTest(messageParams.mPos))
{
if (!mTakingInput)
{
mTakingInput = true;
fsIInputManager::instanceGet()->priorityListenerRegister(this);
return true;
}
}
}
else
{
if (hitTest(messageParams.mPos))
{
// just absorb multiple input
return true;
}
if (mTakingInput)
{
static_cast<const fsIInputManager::sPointerMsgParam&>(pParam).mStealableFrom = this;
}
}
return false;
}
void gfCTappableCollectableComponent::pointerUpHandle(const fsPoint& pPointerPos)
{
mTakingInput = false;
fsIInputManager::instanceGet()->priorityListenerDeregister(this);
if (collectable() && hitTestAndCollect(pPointerPos))
{
collectionProcessTrigger();
}
}
fsBool gfCTappableCollectableComponent::hitTestAndCollect(const fsPoint& pPointerPos)
{
return hitTest(pPointerPos);
}
fsBool gfCTappableCollectableComponent::hitTest(const fsPoint& pPointerPos)
{
if (fsISpriteComponent* const sprComp = parentGet()->spriteComponentGet())
{
if (mTouchHitSprite)
{
fsVec2d localPos;
if (parentGet()->screenCoordConvertToLocal(pPointerPos, localPos))
{
mTouchHitSprite->parentGet()->posSet(localPos + parentGet()->posGet());
mTouchHitSprite->parentGet()->matrixUpdate();
return (sprComp->hitTest(mTouchHitSprite, true));
}
}
return sprComp->hitTest(pPointerPos, true);
}
return false;
}
void gfCTappableCollectableComponent::touchHitSpriteStore()
{
fsCEntity* subSceneEnt = dynamic_cast<fsCEntity*>(parentGet()->parentGet());
auto* subSceneComp = subSceneEnt->firstComponentOfFamilyType<fsISubSceneComponent>();
if (!subSceneComp)
{
// parented to new parallax entity - might move touch hit sprite up to hog level
subSceneEnt = dynamic_cast<fsCEntity*>(parentGet()->parentGet()->parentGet());
subSceneComp = subSceneEnt->firstComponentOfFamilyType<fsISubSceneComponent>();
}
fsAssert(subSceneComp != nullptr, "Expected parent to have a SubSceneComponent.\n");
mTouchHitSprite = subSceneComp->touchHitSpriteCompGet();
}
fsIComponent* gfCTappableCollectableComponent::create(fsCEntity* pParent)
{
auto* const tapComp = new gfCTappableCollectableComponent(pParent);
auto* const ghostSprComp = pParent->componentAdd<gfCGhostSpriteComponent>();
tapComp->mGhostSpriteComp = ghostSprComp;
return tapComp;
}
gfCTappableCollectableComponent::gfCTappableCollectableComponent(fsCEntity* const pParent) :
gfICollectableComponent(pParent),
mTakingInput(false),
mTouchHitSprite(nullptr),
mGhostSpriteComp(nullptr)
{
}
gfCTappableCollectableComponent::~gfCTappableCollectableComponent()
{
}
|