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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#include "gfCSubSceneViewComponent.h"

#include <fsCore/fsIFile.h>
#include <fsCore/src/fsCUserSavedData.h>
#include <fsCore/src/fsCAppSettings.h>

#include <fsAppCore/src/fsCProfileManager.h>
#include <fsAppCore/src/fsILevelBasedAppCoreMain.h>
#include <fsAppCore/src/fsCAppMessageDispatcher.h>
#include <fsAppCore/src/fsCEntityFactory.h>
#include <fsAppCore/src/components/gui/elements/fsCModalGuiComponent.h>
#include <fsAppCore/src/components/gui/fsIGuiComponent.h>
#include <fsRenderer/src/components/fsCAnimatingSpriteComponent.h>
#include <fsRenderer/src/components/fsCParticleEmitterComponent.h>

#include <fsAudio/fsIAudioManager.h>

#include <gfComponents/components/gfCLevelCompleteCheckerComponent.h>
#include <gfMinigameCore/components/spotTheDiff/gfCSpotTheDiffMinigameComponent.h>
#include <gfMinigameCore/components/instantInventory/gfCInstantInventoryMiniGameLogicComponent.h>
#include <gfMinigameCore/components/joinTheDots/gfCJoinTheDotsMinigameComponent.h>
#include <gfMinigameCore/components/wordGames/wordSearch/gfCWordSearchMinigameLogicComponent.h>

#include "gfCSubSceneComponent.h"

const fsCUniqueId gfCSubSceneViewComponent::mTypeId("fsCSubSceneViewComponent");


fsBool gfCSubSceneViewComponent::FncParticleComplete::operator()(fsCEntity* const pParent)
{
	return !pParent->componentGet<fsCParticleEmitterComponent>()->activeGet();
}

fsBool gfCSubSceneViewComponent::FncAnimatingSpriteComplete::operator()(fsCEntity* const pParent)
{
	return !pParent->componentGet<fsCAnimatingSpriteComponent>()->animatingGet();
}

void gfCSubSceneViewComponent::missedEffectCreate(fsCEntity* const pEffectEntity)
{
	auto ephemeralComp = pEffectEntity->componentAdd<fsCEphemeralComponent>();

	fsStr const effectFilename = {fsCAppCoreMain::instanceGet()->settingsGet()->strGet("diffNotFoundMarker")};
	const fsStr particleExt = {".txt"};

	if (fsStr::npos != effectFilename.find(particleExt))
	{
		auto animComp = pEffectEntity->componentAdd<fsCParticleEmitterComponent>();
		animComp->particelDataLoad(fsCResourceName(effectFilename, fsCResourceName::eRES_LOCATION_ASSETS));
		ephemeralComp->init(new FncParticleComplete());
	}
	else
	{
		auto animComp = pEffectEntity->componentAdd<fsCAnimatingSpriteComponent>();
		animComp->animationDataSet(fsCResourceName(effectFilename, fsCResourceName::eRES_LOCATION_ASSETS), false);
		ephemeralComp->init(new FncAnimatingSpriteComplete());
	}
	//	ephemeralComp->init(
	//		[](fsCEntity* const pParent) -> fsBool
	//	{
	//		return !pParent->componentGet<fsCAnimatingSpriteComponent>()->animatingGet();
	//	});
}

void gfCSubSceneViewComponent::missedMarkerCreate(const fsPoint& pTapPos)
{
	fsStr const effectFilename = {fsCAppCoreMain::instanceGet()->settingsGet()->strGet("diffNotFoundMarker")};
	if (fsIFile::fileExistsGet(fsCResourceName(effectFilename, fsCResourceName::eRES_LOCATION_ASSETS)))
	{
		fsCEntity* const missedEnt = parentGet()->entityFactoryGet()->emptyEntityCreate("missedMarker");
		missedEnt->componentAdd<fsCModalGuiComponent>();

		missedEffectCreate(missedEnt);

		fsVec2d localPos = pTapPos;
		parentGet()->screenCoordConvertToLocal(pTapPos, localPos);
		missedEnt->posSet(localPos);
		parentGet()->childAdd(missedEnt);
	}
}

void gfCSubSceneViewComponent::missedTapHandle(const fsPoint& pTapPos)
{
	if (!parentGet()->childEntitiesWithComponentsOfFamilyType<gfCSpotTheDiffMinigameComponent>().empty())
	{
		missedMarkerCreate(pTapPos);
		const fsStr effectName = fsCAppCoreMain::instanceGet()->settingsGet()->strGetWithDefault(
			"sfxDiffMissedClick", "audio/sfx/find.wav");
		fsIAudioManager::instanceGet()->effectPlay(fsCResourceName(effectName, fsCResourceName::eRES_LOCATION_ASSETS));
	}
	else if (!parentGet()->childEntitiesWithComponentsOfFamilyType<gfCJoinTheDotsMinigameComponent>().empty())
	{
		const fsStr effectName = fsCAppCoreMain::instanceGet()->settingsGet()->strGetWithDefault(
			"sfxJtdIncorrectDot", "audio/sfx/find.wav");
		fsIAudioManager::instanceGet()->effectPlay(fsCResourceName(effectName, fsCResourceName::eRES_LOCATION_ASSETS));
	}
}

void gfCSubSceneViewComponent::masterCheatMenuToggle()
{
	fsCEntity* const debugMenu = fsIGuiComponent::guiCreateFromFile(fsCResourceName(
		"gui/debugWindow/debugMenuGui.txt", fsCResourceName::eRES_LOCATION_ASSETS));
	parentGet()->parentGet()->childAdd(debugMenu);
}

void gfCSubSceneViewComponent::cheatTaps()
{
	if (fsCProfileManager::instanceGet()->userSavedDataGet()->cheatModeGet(fsCUserSavedData::eCHEAT_MODE::eDEV)
		&& fsIInputManager::ePOINTER_TYPE_MOUSE != fsIInputManager::instanceGet()->pointerTypeGet())
	{
		if (!mCheatMenuTapTime)
		{
			mCheatMenuTapTime = mRunningTime;
			return;
		}

		const fsS32 doubleTapThreshold = 200;
		if (mRunningTime - mCheatMenuTapTime < doubleTapThreshold)
		{
			++mCheatMenuCount;
			if (mCheatMenuCount >= 6)
			{
				masterCheatMenuToggle();
				mCheatMenuTapTime = 0;
				mCheatMenuCount = 0;
				return;
			}
		}
		mCheatMenuTapTime = mRunningTime;
	}
}

fsBool gfCSubSceneViewComponent::acceptingInputGet() const
{
	return true;
}

void gfCSubSceneViewComponent::listenersRegisterDo()
{
	gfILensComponent::listenersRegisterDo();
	fsCAppMessageDispatcher::instanceGet()->listenerRegister(gfCSubSceneComponent::mSubSceneOpenMsg, this);
	fsCAppMessageDispatcher::instanceGet()->
		listenerRegister(gfCLevelCompleteCheckerComponent::mLevelCompleterMsg, this);
	fsCAppMessageDispatcher::instanceGet()->listenerRegister(fsILevelBasedAppCoreMain::mLevelInitialisedMsg, this);
}

void gfCSubSceneViewComponent::listenersDeregisterDo()
{
	gfILensComponent::listenersDeregisterDo();
	fsCAppMessageDispatcher::instanceGet()->listenerDeregister(gfCSubSceneComponent::mSubSceneOpenMsg, this);
	fsCAppMessageDispatcher::instanceGet()->listenerDeregister(gfCLevelCompleteCheckerComponent::mLevelCompleterMsg,
	                                                           this);
	fsCAppMessageDispatcher::instanceGet()->listenerDeregister(fsILevelBasedAppCoreMain::mLevelInitialisedMsg, this);
}

fsBool gfCSubSceneViewComponent::messageProcessDo(const fsCUniqueId& pMessageType,
                                                  const fsIMessageDispatcher::sMessageParameters& pParam)
{
	if (gfCSubSceneComponent::mSubSceneOpenMsg == pMessageType)
	{
		if (mDrag)
		{
			mDrag->clear();
		}
	}
	else if (fsILevelBasedAppCoreMain::mLevelInitialisedMsg == pMessageType)
	{
		zoomInit();
	}
	else if (parentGet()->visibleGet())
	{
		if (targetGet())
		{
			if (gfCLevelCompleteCheckerComponent::mLevelCompleterMsg == pMessageType)
			{
				zoomAndScrollReset();
			}
		}
	}
	return gfILensComponent::messageProcessDo(pMessageType, pParam);
}

void gfCSubSceneViewComponent::doOnTap(const fsPoint& pTapPos)
{
	missedTapHandle(pTapPos);

	cheatTaps();

	gfILensComponent::doOnTap(pTapPos);
}

fsIComponent* gfCSubSceneViewComponent::create(fsCEntity* pParent)
{
	return new gfCSubSceneViewComponent(pParent);
}

void gfCSubSceneViewComponent::zoomInit()
{
// 	// Desktop test code: keep zoom enabled on desktop (where it is off by default).
// 	// Must stay desktop-only - leaving zoomInit() a no-op on mobile leaves mZoom active
// 	// for scenes that should have it released, which shifts the subscene (and the 3D
// 	// with it) at start.
// #if defined(fsDesktop)
// 	return;
// #endif

	if (fsIInputManager::ePOINTER_TYPE_MOUSE != fsIInputManager::instanceGet()->pointerTypeGet())
	{
		if (
			nullptr == appSceneFirstEntityWithComponentOfFamilyType<gfIMinigameComponent>() &&
			nullptr == appSceneFirstEntityWithComponentOfFamilyType<gfCInstantInventoryMiniGameLogicComponent>() &&
			nullptr == appSceneFirstEntityWithComponentOfFamilyType<gfCWordSearchMinigameLogicComponent>())
		{
			return;
		}
	}
	mZoom.release();<--- Return value of function mZoom.release() is not used.
}

void gfCSubSceneViewComponent::init(const fsPoint& pDimensions, const fsPoint& pScrollWindow,
                                    const fsPoint& pDragEnable, const fsPoint& pLookAt)
{
	mDrag->init(pDimensions, pScrollWindow, pDragEnable, pLookAt);
}

gfCSubSceneViewComponent::gfCSubSceneViewComponent(fsCEntity* const pParent) :
	gfILensComponent(pParent, true, true, true),
	mCheatMenuCount(0),
	mCheatMenuTapTime(0)
{
}

gfCSubSceneViewComponent::~gfCSubSceneViewComponent()
{
}