3
0

UiAnimationSystem.cpp 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include "UiAnimationSystem.h"
  9. #include "AnimSplineTrack.h"
  10. #include "AnimSequence.h"
  11. #include "AzEntityNode.h"
  12. #include "UiAnimSerialize.h"
  13. #include <AzCore/Component/ComponentApplicationBus.h>
  14. #include <AzCore/std/containers/map.h>
  15. #include <AzCore/std/containers/unordered_map.h>
  16. #include <ISystem.h>
  17. #include <ILog.h>
  18. #include <IConsole.h>
  19. //////////////////////////////////////////////////////////////////////////
  20. // Serialization for anim nodes & param types
  21. #define REGISTER_NODE_TYPE(name) assert(!m_animNodeEnumToStringMap.contains(eUiAnimNodeType_ ## name)); \
  22. m_animNodeEnumToStringMap[eUiAnimNodeType_ ## name] = AZ_STRINGIZE(name); \
  23. m_animNodeStringToEnumMap[UiAnimParamSystemString(AZ_STRINGIZE(name))] = eUiAnimNodeType_ ## name;
  24. #define REGISTER_PARAM_TYPE(name) assert(!m_animParamEnumToStringMap.contains(eUiAnimParamType_ ## name)); \
  25. m_animParamEnumToStringMap[eUiAnimParamType_ ## name] = AZ_STRINGIZE(name); \
  26. m_animParamStringToEnumMap[UiAnimParamSystemString(AZ_STRINGIZE(name))] = eUiAnimParamType_ ## name;
  27. // If you get an assert in this function, it means two node types have the same enum value.
  28. void UiAnimationSystem::RegisterNodeTypes()
  29. {
  30. REGISTER_NODE_TYPE(Entity)
  31. REGISTER_NODE_TYPE(Director)
  32. REGISTER_NODE_TYPE(Camera)
  33. REGISTER_NODE_TYPE(CVar)
  34. REGISTER_NODE_TYPE(ScriptVar)
  35. REGISTER_NODE_TYPE(Material)
  36. REGISTER_NODE_TYPE(Event)
  37. REGISTER_NODE_TYPE(Group)
  38. REGISTER_NODE_TYPE(Layer)
  39. REGISTER_NODE_TYPE(Comment)
  40. REGISTER_NODE_TYPE(RadialBlur)
  41. REGISTER_NODE_TYPE(ColorCorrection)
  42. REGISTER_NODE_TYPE(DepthOfField)
  43. REGISTER_NODE_TYPE(ScreenFader)
  44. REGISTER_NODE_TYPE(Light)
  45. REGISTER_NODE_TYPE(HDRSetup)
  46. REGISTER_NODE_TYPE(ShadowSetup)
  47. REGISTER_NODE_TYPE(Alembic)
  48. REGISTER_NODE_TYPE(GeomCache)
  49. REGISTER_NODE_TYPE(Environment)
  50. REGISTER_NODE_TYPE(ScreenDropsSetup)
  51. REGISTER_NODE_TYPE(AzEntity)
  52. }
  53. // If you get an assert in this function, it means two param types have the same enum value.
  54. void UiAnimationSystem::RegisterParamTypes()
  55. {
  56. REGISTER_PARAM_TYPE(Event)
  57. REGISTER_PARAM_TYPE(Float)
  58. REGISTER_PARAM_TYPE(TrackEvent)
  59. REGISTER_PARAM_TYPE(AzComponentField)
  60. }
  61. //////////////////////////////////////////////////////////////////////////
  62. UiAnimationSystem::UiAnimationSystem()
  63. {
  64. m_pSystem = (gEnv) ? gEnv->pSystem : nullptr;
  65. m_bRecording = false;
  66. m_pCallback = NULL;
  67. m_bPaused = false;
  68. m_sequenceStopBehavior = eSSB_GotoEndTime;
  69. m_lastUpdateTime = AZ::Time::ZeroTimeUs;
  70. m_nextSequenceId = 1;
  71. RegisterNodeTypes();
  72. RegisterParamTypes();
  73. }
  74. //////////////////////////////////////////////////////////////////////////
  75. bool UiAnimationSystem::Load(const char* pszFile, const char* pszMission)
  76. {
  77. INDENT_LOG_DURING_SCOPE (true, "UI Animation system is loading the file '%s' (mission='%s')", pszFile, pszMission);
  78. XmlNodeRef rootNode = m_pSystem->LoadXmlFromFile(pszFile);
  79. if (!rootNode)
  80. {
  81. return false;
  82. }
  83. XmlNodeRef Node = NULL;
  84. for (int i = 0; i < rootNode->getChildCount(); i++)
  85. {
  86. XmlNodeRef missionNode = rootNode->getChild(i);
  87. XmlString sName;
  88. if (!(sName = missionNode->getAttr("Name")))
  89. {
  90. continue;
  91. }
  92. if (_stricmp(sName.c_str(), pszMission))
  93. {
  94. continue;
  95. }
  96. Node = missionNode;
  97. break;
  98. }
  99. if (!Node)
  100. {
  101. return false;
  102. }
  103. Serialize(Node, true, true, false);
  104. return true;
  105. }
  106. //////////////////////////////////////////////////////////////////////////
  107. IUiAnimTrack* UiAnimationSystem::CreateTrack([[maybe_unused]] EUiAnimCurveType type)
  108. {
  109. #if 0
  110. switch (type)
  111. {
  112. case eUiAnimCurveType_TCBFloat:
  113. return new CTcbFloatTrack;
  114. case eUiAnimCurveType_TCBVector:
  115. return new CTcbVectorTrack;
  116. case eUiAnimCurveType_TCBQuat:
  117. return new CTcbQuatTrack;
  118. }
  119. ;
  120. #endif
  121. assert(0);
  122. return 0;
  123. }
  124. //////////////////////////////////////////////////////////////////////////
  125. IUiAnimSequence* UiAnimationSystem::CreateSequence(const char* pSequenceName, bool bLoad, uint32 id)
  126. {
  127. if (!bLoad)
  128. {
  129. id = m_nextSequenceId++;
  130. }
  131. IUiAnimSequence* pSequence = aznew CUiAnimSequence(this, id);
  132. pSequence->SetName(pSequenceName);
  133. m_sequences.push_back(pSequence);
  134. return pSequence;
  135. }
  136. //////////////////////////////////////////////////////////////////////////
  137. IUiAnimSequence* UiAnimationSystem::LoadSequence(const char* pszFilePath)
  138. {
  139. XmlNodeRef sequenceNode = m_pSystem->LoadXmlFromFile(pszFilePath);
  140. if (sequenceNode)
  141. {
  142. return LoadSequence(sequenceNode);
  143. }
  144. return NULL;
  145. }
  146. //////////////////////////////////////////////////////////////////////////
  147. IUiAnimSequence* UiAnimationSystem::LoadSequence(XmlNodeRef& xmlNode, bool bLoadEmpty)
  148. {
  149. IUiAnimSequence* pSequence = aznew CUiAnimSequence(this, 0);
  150. pSequence->Serialize(xmlNode, true, bLoadEmpty);
  151. // Delete previous sequence with the same name.
  152. const char* pFullName = pSequence->GetName();
  153. IUiAnimSequence* pPrevSeq = FindSequence(pFullName);
  154. if (pPrevSeq)
  155. {
  156. RemoveSequence(pPrevSeq);
  157. }
  158. m_sequences.push_back(pSequence);
  159. return pSequence;
  160. }
  161. //////////////////////////////////////////////////////////////////////////
  162. IUiAnimSequence* UiAnimationSystem::FindSequence(const char* pSequenceName) const
  163. {
  164. assert(pSequenceName);
  165. if (!pSequenceName)
  166. {
  167. return NULL;
  168. }
  169. for (Sequences::const_iterator it = m_sequences.begin(); it != m_sequences.end(); ++it)
  170. {
  171. IUiAnimSequence* pCurrentSequence = it->get();
  172. const char* fullname = pCurrentSequence->GetName();
  173. if (_stricmp(fullname, pSequenceName) == 0)
  174. {
  175. return pCurrentSequence;
  176. }
  177. }
  178. return NULL;
  179. }
  180. //////////////////////////////////////////////////////////////////////////
  181. IUiAnimSequence* UiAnimationSystem::FindSequenceById(uint32 id) const
  182. {
  183. if (id == 0 || id >= m_nextSequenceId)
  184. {
  185. return NULL;
  186. }
  187. for (Sequences::const_iterator it = m_sequences.begin(); it != m_sequences.end(); ++it)
  188. {
  189. IUiAnimSequence* pCurrentSequence = it->get();
  190. if (id == pCurrentSequence->GetId())
  191. {
  192. return pCurrentSequence;
  193. }
  194. }
  195. return NULL;
  196. }
  197. //////////////////////////////////////////////////////////////////////////
  198. bool UiAnimationSystem::FindSequence(IUiAnimSequence* pSequence, PlayingSequences::const_iterator& sequenceIteratorOut) const
  199. {
  200. PlayingSequences::const_iterator itend = m_playingSequences.end();
  201. for (sequenceIteratorOut = m_playingSequences.begin(); sequenceIteratorOut != itend; ++sequenceIteratorOut)
  202. {
  203. if (sequenceIteratorOut->sequence == pSequence)
  204. {
  205. return true;
  206. }
  207. }
  208. return false;
  209. }
  210. //////////////////////////////////////////////////////////////////////////
  211. bool UiAnimationSystem::FindSequence(IUiAnimSequence* pSequence, PlayingSequences::iterator& sequenceIteratorOut)
  212. {
  213. PlayingSequences::const_iterator itend = m_playingSequences.end();
  214. for (sequenceIteratorOut = m_playingSequences.begin(); sequenceIteratorOut != itend; ++sequenceIteratorOut)
  215. {
  216. if (sequenceIteratorOut->sequence == pSequence)
  217. {
  218. return true;
  219. }
  220. }
  221. return false;
  222. }
  223. //////////////////////////////////////////////////////////////////////////
  224. IUiAnimSequence* UiAnimationSystem::GetSequence(int i) const
  225. {
  226. assert(i >= 0 && i < GetNumSequences());
  227. if (i < 0 || i >= GetNumSequences())
  228. {
  229. return NULL;
  230. }
  231. return m_sequences[i].get();
  232. }
  233. //////////////////////////////////////////////////////////////////////////
  234. int UiAnimationSystem::GetNumSequences() const
  235. {
  236. return static_cast<int>(m_sequences.size());
  237. }
  238. //////////////////////////////////////////////////////////////////////////
  239. IUiAnimSequence* UiAnimationSystem::GetPlayingSequence(int i) const
  240. {
  241. assert(i >= 0 && i < GetNumPlayingSequences());
  242. if (i < 0 || i >= GetNumPlayingSequences())
  243. {
  244. return NULL;
  245. }
  246. return m_playingSequences[i].sequence.get();
  247. }
  248. //////////////////////////////////////////////////////////////////////////
  249. int UiAnimationSystem::GetNumPlayingSequences() const
  250. {
  251. return static_cast<int>(m_playingSequences.size());
  252. }
  253. //////////////////////////////////////////////////////////////////////////
  254. void UiAnimationSystem::AddSequence(IUiAnimSequence* pSequence)
  255. {
  256. m_sequences.push_back(pSequence);
  257. }
  258. //////////////////////////////////////////////////////////////////////////
  259. bool UiAnimationSystem::IsCutScenePlaying() const
  260. {
  261. const uint numPlayingSequences = static_cast<uint>(m_playingSequences.size());
  262. for (uint i = 0; i < numPlayingSequences; ++i)
  263. {
  264. const IUiAnimSequence* pAnimSequence = m_playingSequences[i].sequence.get();
  265. if (pAnimSequence && (pAnimSequence->GetFlags() & IUiAnimSequence::eSeqFlags_CutScene) != 0)
  266. {
  267. return true;
  268. }
  269. }
  270. return false;
  271. }
  272. //////////////////////////////////////////////////////////////////////////
  273. void UiAnimationSystem::RemoveSequence(IUiAnimSequence* pSequence)
  274. {
  275. assert(pSequence != 0);
  276. if (pSequence)
  277. {
  278. IUiAnimationCallback* pCallback = GetCallback();
  279. SetCallback(NULL);
  280. StopSequence(pSequence);
  281. for (Sequences::iterator it = m_sequences.begin(); it != m_sequences.end(); ++it)
  282. {
  283. if (pSequence == *it)
  284. {
  285. m_animationListenerMap.erase(pSequence);
  286. m_sequences.erase(it);
  287. break;
  288. }
  289. }
  290. SetCallback(pCallback);
  291. }
  292. }
  293. //////////////////////////////////////////////////////////////////////////
  294. int UiAnimationSystem::OnSequenceRenamed(const char* before, const char* after)
  295. {
  296. assert(before && after);
  297. if (before == NULL || after == NULL)
  298. {
  299. return 0;
  300. }
  301. if (_stricmp(before, after) == 0)
  302. {
  303. return 0;
  304. }
  305. int count = 0;
  306. // UI_ANIMATION_REVISIT : this only did anything for director nodes
  307. return count;
  308. }
  309. //////////////////////////////////////////////////////////////////////////
  310. int UiAnimationSystem::OnCameraRenamed([[maybe_unused]] const char* before, [[maybe_unused]] const char* after)
  311. {
  312. // UI_ANIMATION_REVISIT - not used
  313. return 0;
  314. }
  315. //////////////////////////////////////////////////////////////////////////
  316. void UiAnimationSystem::RemoveAllSequences()
  317. {
  318. IUiAnimationCallback* pCallback = GetCallback();
  319. SetCallback(NULL);
  320. InternalStopAllSequences(true, false);
  321. stl::free_container(m_sequences);
  322. for (TUiAnimationListenerMap::iterator it = m_animationListenerMap.begin(); it != m_animationListenerMap.end(); )
  323. {
  324. if (it->first)
  325. {
  326. m_animationListenerMap.erase(it++);
  327. }
  328. else
  329. {
  330. ++it;
  331. }
  332. }
  333. SetCallback(pCallback);
  334. }
  335. //////////////////////////////////////////////////////////////////////////
  336. void UiAnimationSystem::PlaySequence(const char* pSequenceName, IUiAnimSequence* pParentSeq, bool bResetFx, bool bTrackedSequence, float startTime, float endTime)
  337. {
  338. IUiAnimSequence* pSequence = FindSequence(pSequenceName);
  339. if (pSequence)
  340. {
  341. PlaySequence(pSequence, pParentSeq, bResetFx, bTrackedSequence, startTime, endTime);
  342. }
  343. else
  344. {
  345. gEnv->pLog->Log ("UiAnimationSystem::PlaySequence: Error: Sequence \"%s\" not found", pSequenceName);
  346. }
  347. }
  348. //////////////////////////////////////////////////////////////////////////
  349. void UiAnimationSystem::PlaySequence(IUiAnimSequence* pSequence, IUiAnimSequence* parentSeq,
  350. [[maybe_unused]] bool bResetFx, bool bTrackedSequence, float startTime, float endTime)
  351. {
  352. assert(pSequence != 0);
  353. if (!pSequence || IsPlaying(pSequence))
  354. {
  355. return;
  356. }
  357. // If this sequence is cut scene disable player.
  358. if (pSequence->GetFlags() & IUiAnimSequence::eSeqFlags_CutScene)
  359. {
  360. OnCameraCut();
  361. pSequence->SetParentSequence(parentSeq);
  362. }
  363. pSequence->Activate();
  364. pSequence->Resume();
  365. static_cast<CUiAnimSequence*>(pSequence)->OnStart();
  366. PlayingUIAnimSequence ps;
  367. ps.sequence = pSequence;
  368. ps.startTime = startTime == -FLT_MAX ? pSequence->GetTimeRange().start : startTime;
  369. ps.endTime = endTime == -FLT_MAX ? pSequence->GetTimeRange().end : endTime;
  370. ps.currentTime = startTime == -FLT_MAX ? pSequence->GetTimeRange().start : startTime;
  371. ps.currentSpeed = 1.0f;
  372. ps.trackedSequence = bTrackedSequence;
  373. ps.bSingleFrame = false;
  374. // Make sure all members are initialized before pushing.
  375. m_playingSequences.push_back(ps);
  376. // tell all interested listeners
  377. NotifyListeners(pSequence, IUiAnimationListener::eUiAnimationEvent_Started);
  378. }
  379. //////////////////////////////////////////////////////////////////////////
  380. void UiAnimationSystem::NotifyListeners(IUiAnimSequence* pSequence, IUiAnimationListener::EUiAnimationEvent event)
  381. {
  382. TUiAnimationListenerMap::iterator found (m_animationListenerMap.find(pSequence));
  383. if (found != m_animationListenerMap.end())
  384. {
  385. TUiAnimationListenerVec listForSeq = (*found).second;
  386. TUiAnimationListenerVec::iterator iter (listForSeq.begin());
  387. while (iter != listForSeq.end())
  388. {
  389. (*iter)->OnUiAnimationEvent(event, pSequence);
  390. ++iter;
  391. }
  392. }
  393. // 'NULL' ones are listeners interested in every sequence. Do not send "update" here
  394. if (event != IUiAnimationListener::eUiAnimationEvent_Updated)
  395. {
  396. TUiAnimationListenerMap::iterator found2 (m_animationListenerMap.find((IUiAnimSequence*)0));
  397. if (found2 != m_animationListenerMap.end())
  398. {
  399. TUiAnimationListenerVec listForSeq = (*found2).second;
  400. TUiAnimationListenerVec::iterator iter (listForSeq.begin());
  401. while (iter != listForSeq.end())
  402. {
  403. (*iter)->OnUiAnimationEvent(event, pSequence);
  404. ++iter;
  405. }
  406. }
  407. }
  408. }
  409. //////////////////////////////////////////////////////////////////////////
  410. void UiAnimationSystem::NotifyTrackEventListeners(const char* eventName, const char* valueName, IUiAnimSequence* pSequence)
  411. {
  412. TUiAnimationListenerMap::iterator found(m_animationListenerMap.find(pSequence));
  413. if (found != m_animationListenerMap.end())
  414. {
  415. TUiAnimationListenerVec listForSeq = (*found).second;
  416. TUiAnimationListenerVec::iterator iter(listForSeq.begin());
  417. while (iter != listForSeq.end())
  418. {
  419. (*iter)->OnUiTrackEvent(AZStd::string(eventName), AZStd::string(valueName), pSequence);
  420. ++iter;
  421. }
  422. }
  423. // 'NULL' ones are listeners interested in every sequence.
  424. TUiAnimationListenerMap::iterator found2(m_animationListenerMap.find(static_cast<IUiAnimSequence*>(nullptr)));
  425. if (found2 != m_animationListenerMap.end())
  426. {
  427. TUiAnimationListenerVec listForSeq = (*found2).second;
  428. TUiAnimationListenerVec::iterator iter(listForSeq.begin());
  429. while (iter != listForSeq.end())
  430. {
  431. (*iter)->OnUiTrackEvent(AZStd::string(eventName), AZStd::string(valueName), pSequence);
  432. ++iter;
  433. }
  434. }
  435. }
  436. //////////////////////////////////////////////////////////////////////////
  437. bool UiAnimationSystem::StopSequence(const char* pSequenceName)
  438. {
  439. IUiAnimSequence* pSequence = FindSequence(pSequenceName);
  440. if (pSequence)
  441. {
  442. return StopSequence(pSequence);
  443. }
  444. return false;
  445. }
  446. //////////////////////////////////////////////////////////////////////////
  447. bool UiAnimationSystem::StopSequence(IUiAnimSequence* pSequence)
  448. {
  449. return InternalStopSequence(pSequence, false, true);
  450. }
  451. //////////////////////////////////////////////////////////////////////////
  452. void UiAnimationSystem::InternalStopAllSequences(bool bAbort, bool bAnimate)
  453. {
  454. while (!m_playingSequences.empty())
  455. {
  456. InternalStopSequence(m_playingSequences.begin()->sequence.get(), bAbort, bAnimate);
  457. }
  458. stl::free_container(m_playingSequences);
  459. }
  460. //////////////////////////////////////////////////////////////////////////
  461. bool UiAnimationSystem::InternalStopSequence(IUiAnimSequence* pSequence, bool bAbort, bool bAnimate)
  462. {
  463. assert(pSequence != 0);
  464. bool bRet = false;
  465. PlayingSequences::iterator it;
  466. if (FindSequence(pSequence, it))
  467. {
  468. if (bAnimate)
  469. {
  470. if (m_sequenceStopBehavior == eSSB_GotoEndTime)
  471. {
  472. SUiAnimContext ac;
  473. ac.bSingleFrame = true;
  474. ac.time = pSequence->GetTimeRange().end;
  475. pSequence->Animate(ac);
  476. }
  477. else if (m_sequenceStopBehavior == eSSB_GotoStartTime)
  478. {
  479. SUiAnimContext ac;
  480. ac.bSingleFrame = true;
  481. ac.time = pSequence->GetTimeRange().start;
  482. pSequence->Animate(ac);
  483. }
  484. pSequence->Deactivate();
  485. }
  486. // tell all interested listeners
  487. NotifyListeners(pSequence, bAbort ? IUiAnimationListener::eUiAnimationEvent_Aborted : IUiAnimationListener::eUiAnimationEvent_Stopped);
  488. // erase the sequence after notifying listeners so if they choose to they can get the ending time of this sequence
  489. if (FindSequence(pSequence, it))
  490. {
  491. m_playingSequences.erase(it);
  492. }
  493. pSequence->Resume();
  494. static_cast<CUiAnimSequence*>(pSequence)->OnStop();
  495. bRet = true;
  496. }
  497. return bRet;
  498. }
  499. //////////////////////////////////////////////////////////////////////////
  500. bool UiAnimationSystem::AbortSequence(IUiAnimSequence* pSequence, bool bLeaveTime)
  501. {
  502. return InternalStopSequence(pSequence, true, !bLeaveTime);
  503. }
  504. //////////////////////////////////////////////////////////////////////////
  505. void UiAnimationSystem::StopAllSequences()
  506. {
  507. InternalStopAllSequences(false, true);
  508. }
  509. //////////////////////////////////////////////////////////////////////////
  510. void UiAnimationSystem::StopAllCutScenes()
  511. {
  512. bool bAnyStoped;
  513. PlayingSequences::iterator next;
  514. do
  515. {
  516. bAnyStoped = false;
  517. for (PlayingSequences::iterator it = m_playingSequences.begin(); it != m_playingSequences.end(); it = next)
  518. {
  519. next = it;
  520. ++next;
  521. IUiAnimSequence* pCurrentSequence = it->sequence.get();
  522. if (pCurrentSequence->GetFlags() & IUiAnimSequence::eSeqFlags_CutScene)
  523. {
  524. bAnyStoped = true;
  525. StopSequence(pCurrentSequence);
  526. break;
  527. }
  528. }
  529. } while (bAnyStoped);
  530. if (m_playingSequences.empty())
  531. {
  532. stl::free_container(m_playingSequences);
  533. }
  534. }
  535. //////////////////////////////////////////////////////////////////////////
  536. bool UiAnimationSystem::IsPlaying(IUiAnimSequence* pSequence) const
  537. {
  538. for (PlayingSequences::const_iterator it = m_playingSequences.begin(); it != m_playingSequences.end(); ++it)
  539. {
  540. if (it->sequence == pSequence)
  541. {
  542. return true;
  543. }
  544. }
  545. return false;
  546. }
  547. //////////////////////////////////////////////////////////////////////////
  548. void UiAnimationSystem::Reset(bool bPlayOnReset, bool bSeekToStart)
  549. {
  550. InternalStopAllSequences(true, false);
  551. // Reset all sequences.
  552. for (Sequences::iterator iter = m_sequences.begin(); iter != m_sequences.end(); ++iter)
  553. {
  554. IUiAnimSequence* pCurrentSequence = iter->get();
  555. NotifyListeners(pCurrentSequence, IUiAnimationListener::eUiAnimationEvent_Started);
  556. pCurrentSequence->Reset(bSeekToStart);
  557. NotifyListeners(pCurrentSequence, IUiAnimationListener::eUiAnimationEvent_Stopped);
  558. }
  559. if (bPlayOnReset)
  560. {
  561. for (Sequences::iterator iter = m_sequences.begin(); iter != m_sequences.end(); ++iter)
  562. {
  563. IUiAnimSequence* pCurrentSequence = iter->get();
  564. if (pCurrentSequence->GetFlags() & IUiAnimSequence::eSeqFlags_PlayOnReset)
  565. {
  566. PlaySequence(pCurrentSequence);
  567. }
  568. }
  569. }
  570. // un-pause the UI animation system
  571. m_bPaused = false;
  572. }
  573. //////////////////////////////////////////////////////////////////////////
  574. void UiAnimationSystem::PlayOnLoadSequences()
  575. {
  576. for (Sequences::iterator sit = m_sequences.begin(); sit != m_sequences.end(); ++sit)
  577. {
  578. IUiAnimSequence* pSequence = sit->get();
  579. if (pSequence->GetFlags() & IUiAnimSequence::eSeqFlags_PlayOnReset)
  580. {
  581. PlaySequence(pSequence);
  582. }
  583. }
  584. }
  585. //////////////////////////////////////////////////////////////////////////
  586. void UiAnimationSystem::StillUpdate()
  587. {
  588. if (!gEnv->IsEditor())
  589. {
  590. return;
  591. }
  592. for (PlayingSequences::iterator it = m_playingSequences.begin(); it != m_playingSequences.end(); ++it)
  593. {
  594. PlayingUIAnimSequence& playingSequence = *it;
  595. playingSequence.sequence->StillUpdate();
  596. }
  597. }
  598. //////////////////////////////////////////////////////////////////////////
  599. void UiAnimationSystem::ShowPlayedSequencesDebug()
  600. {
  601. constexpr f32 green[4] = {0, 1, 0, 1};
  602. constexpr f32 purple[4] = {1, 0, 1, 1};
  603. constexpr f32 white[4] = {1, 1, 1, 1};
  604. float y = 10.0f;
  605. AZStd::vector<AZStd::string> names;
  606. //TODO: needs an implementation
  607. auto Draw2dLabel = [](float /*x*/,float /*y*/,float /*depth*/,const f32* /*color*/,bool /*center*/, const char* /*fmt*/, ...) {};
  608. for (PlayingSequences::iterator it = m_playingSequences.begin(); it != m_playingSequences.end(); ++it)
  609. {
  610. PlayingUIAnimSequence& playingSequence = *it;
  611. if (playingSequence.sequence == nullptr)
  612. {
  613. continue;
  614. }
  615. AZ_Assert(false,"gEnv->pRenderer is always null so it can't be used here");
  616. const char* fullname = playingSequence.sequence->GetName();
  617. Draw2dLabel(1.0f, y, 1.3f, green, false, "Sequence %s : %f (x %f)", fullname, playingSequence.currentTime, playingSequence.currentSpeed);
  618. y += 16.0f;
  619. for (int i = 0; i < playingSequence.sequence->GetNodeCount(); ++i)
  620. {
  621. // Checks nodes which happen to be in several sequences.
  622. // Those can be a bug, since several sequences may try to control the same entity.
  623. AZStd::string name = playingSequence.sequence->GetNode(i)->GetName();
  624. bool alreadyThere = false;
  625. if (AZStd::find(names.begin(), names.end(), name) != names.end())
  626. {
  627. alreadyThere = true;
  628. }
  629. else
  630. {
  631. names.push_back(name);
  632. }
  633. Draw2dLabel((21.0f + 100.0f * i), ((i % 2) ? (y + 8.0f) : y), 1.0f, alreadyThere ? white : purple, false, "%s", name.c_str());
  634. }
  635. y += 32.0f;
  636. }
  637. }
  638. //////////////////////////////////////////////////////////////////////////
  639. void UiAnimationSystem::PreUpdate(float deltaTime)
  640. {
  641. UpdateInternal(deltaTime, true);
  642. }
  643. //////////////////////////////////////////////////////////////////////////
  644. void UiAnimationSystem::PostUpdate(float deltaTime)
  645. {
  646. UpdateInternal(deltaTime, false);
  647. }
  648. //////////////////////////////////////////////////////////////////////////
  649. void UiAnimationSystem::UpdateInternal(const float deltaTime, const bool bPreUpdate)
  650. {
  651. SUiAnimContext animContext;
  652. if (m_bPaused)
  653. {
  654. return;
  655. }
  656. // don't update more than once if dt==0.0
  657. const AZ::TimeUs curTime = AZ::GetElapsedTimeUs();
  658. if (deltaTime == 0.0f && curTime == m_lastUpdateTime && !gEnv->IsEditor())
  659. {
  660. return;
  661. }
  662. m_lastUpdateTime = curTime;
  663. float fps = 60.0f;
  664. std::vector<IUiAnimSequence*> stopSequences;
  665. const size_t numPlayingSequences = m_playingSequences.size();
  666. for (size_t i = 0; i < numPlayingSequences; ++i)
  667. {
  668. PlayingUIAnimSequence& playingSequence = m_playingSequences[i];
  669. if (playingSequence.sequence->IsPaused())
  670. {
  671. continue;
  672. }
  673. const float scaledTimeDelta = deltaTime * playingSequence.currentSpeed;
  674. // Increase play time in pre-update
  675. if (bPreUpdate)
  676. {
  677. playingSequence.currentTime += scaledTimeDelta;
  678. }
  679. // Skip sequence if current update does not apply
  680. const bool bSequenceEarlyUpdate = (playingSequence.sequence->GetFlags() & IUiAnimSequence::eSeqFlags_EarlyAnimationUpdate) != 0;
  681. if (bPreUpdate && !bSequenceEarlyUpdate || !bPreUpdate && bSequenceEarlyUpdate)
  682. {
  683. continue;
  684. }
  685. animContext.time = playingSequence.currentTime;
  686. animContext.pSequence = playingSequence.sequence.get();
  687. animContext.dt = scaledTimeDelta;
  688. animContext.fps = fps;
  689. animContext.startTime = playingSequence.startTime;
  690. // Check time out of range, setting up playingSequence for the next Update
  691. bool wasLooped = false;
  692. if (playingSequence.currentTime > playingSequence.endTime)
  693. {
  694. int seqFlags = playingSequence.sequence->GetFlags();
  695. if (seqFlags & IUiAnimSequence::eSeqFlags_OutOfRangeLoop)
  696. {
  697. // Time wrap's back to the start of the time range.
  698. playingSequence.currentTime = playingSequence.startTime; // should there be a fmodf here?
  699. wasLooped = true;
  700. }
  701. else if (seqFlags & IUiAnimSequence::eSeqFlags_OutOfRangeConstant)
  702. {
  703. // Time just continues normally past the end of time range.
  704. }
  705. else
  706. {
  707. // If no out-of-range type specified sequence stopped when time reaches end of range.
  708. // Que sequence for stopping.
  709. if (playingSequence.trackedSequence == false)
  710. {
  711. stopSequences.push_back(playingSequence.sequence.get());
  712. }
  713. continue;
  714. }
  715. }
  716. else
  717. {
  718. NotifyListeners(playingSequence.sequence.get(), IUiAnimationListener::eUiAnimationEvent_Updated);
  719. }
  720. animContext.bSingleFrame = playingSequence.bSingleFrame;
  721. playingSequence.bSingleFrame = false;
  722. // Animate sequence. (Can invalidate iterator)
  723. playingSequence.sequence->Animate(animContext);
  724. // we call OnLoop() *after* Animate() to reset sounds (for CUiAnimSceneNodes), for the next update (the looped update)
  725. if (wasLooped)
  726. {
  727. playingSequence.sequence->OnLoop();
  728. }
  729. }
  730. // Stop queued sequences.
  731. for (int i = 0; i < (int)stopSequences.size(); i++)
  732. {
  733. StopSequence(stopSequences[i]);
  734. }
  735. }
  736. //////////////////////////////////////////////////////////////////////////
  737. void UiAnimationSystem::Render()
  738. {
  739. for (PlayingSequences::iterator it = m_playingSequences.begin(); it != m_playingSequences.end(); ++it)
  740. {
  741. PlayingUIAnimSequence& playingSequence = *it;
  742. playingSequence.sequence->Render();
  743. }
  744. }
  745. //////////////////////////////////////////////////////////////////////////
  746. void UiAnimationSystem::Callback(IUiAnimationCallback::ECallbackReason reason, IUiAnimNode* pNode)
  747. {
  748. if (m_pCallback)
  749. {
  750. m_pCallback->OnUiAnimationCallback(reason, pNode);
  751. }
  752. }
  753. //////////////////////////////////////////////////////////////////////////
  754. void UiAnimationSystem::Serialize(XmlNodeRef& xmlNode, bool bLoading, [[maybe_unused]] bool bRemoveOldNodes, bool bLoadEmpty)
  755. {
  756. if (bLoading)
  757. {
  758. //////////////////////////////////////////////////////////////////////////
  759. // Load sequences from XML.
  760. //////////////////////////////////////////////////////////////////////////
  761. XmlNodeRef seqNode = xmlNode->findChild("SequenceData");
  762. if (seqNode)
  763. {
  764. RemoveAllSequences();
  765. INDENT_LOG_DURING_SCOPE(true, "SequenceData tag contains %u sequences", seqNode->getChildCount());
  766. for (int i = 0; i < seqNode->getChildCount(); i++)
  767. {
  768. XmlNodeRef childNode = seqNode->getChild(i);
  769. if (!LoadSequence(childNode, bLoadEmpty))
  770. {
  771. return;
  772. }
  773. }
  774. }
  775. }
  776. else
  777. {
  778. XmlNodeRef sequencesNode = xmlNode->newChild("SequenceData");
  779. for (int i = 0; i < GetNumSequences(); ++i)
  780. {
  781. IUiAnimSequence* pSequence = GetSequence(i);
  782. XmlNodeRef sequenceNode = sequencesNode->newChild("Sequence");
  783. pSequence->Serialize(sequenceNode, false);
  784. }
  785. }
  786. }
  787. //////////////////////////////////////////////////////////////////////////
  788. void UiAnimationSystem::InitPostLoad(bool remapIds, LyShine::EntityIdMap* entityIdMap)
  789. {
  790. for (int i = 0; i < GetNumSequences(); ++i)
  791. {
  792. IUiAnimSequence* pSequence = GetSequence(i);
  793. pSequence->InitPostLoad(this, remapIds, entityIdMap);
  794. }
  795. }
  796. //////////////////////////////////////////////////////////////////////////
  797. void UiAnimationSystem::Pause()
  798. {
  799. m_bPaused = true;
  800. }
  801. //////////////////////////////////////////////////////////////////////////
  802. void UiAnimationSystem::Resume()
  803. {
  804. m_bPaused = false;
  805. }
  806. //////////////////////////////////////////////////////////////////////////
  807. float UiAnimationSystem::GetPlayingTime(IUiAnimSequence* pSequence)
  808. {
  809. if (!pSequence || !IsPlaying(pSequence))
  810. {
  811. return -1.0;
  812. }
  813. PlayingSequences::const_iterator it;
  814. if (FindSequence(pSequence, it))
  815. {
  816. return it->currentTime;
  817. }
  818. return -1.0f;
  819. }
  820. float UiAnimationSystem::GetPlayingSpeed(IUiAnimSequence* pSequence)
  821. {
  822. if (!pSequence || !IsPlaying(pSequence))
  823. {
  824. return -1.0f;
  825. }
  826. PlayingSequences::const_iterator it;
  827. if (FindSequence(pSequence, it))
  828. {
  829. return it->currentSpeed;
  830. }
  831. return -1.0f;
  832. }
  833. bool UiAnimationSystem::SetPlayingTime(IUiAnimSequence* pSequence, float fTime)
  834. {
  835. if (!pSequence || !IsPlaying(pSequence))
  836. {
  837. return false;
  838. }
  839. PlayingSequences::iterator it;
  840. if (FindSequence(pSequence, it) && !(pSequence->GetFlags() & IUiAnimSequence::eSeqFlags_NoSeek))
  841. {
  842. it->currentTime = fTime;
  843. it->bSingleFrame = true;
  844. NotifyListeners(pSequence, IUiAnimationListener::eUiAnimationEvent_Updated);
  845. return true;
  846. }
  847. return false;
  848. }
  849. bool UiAnimationSystem::SetPlayingSpeed(IUiAnimSequence* pSequence, float fSpeed)
  850. {
  851. if (!pSequence)
  852. {
  853. return false;
  854. }
  855. PlayingSequences::iterator it;
  856. if (FindSequence(pSequence, it) && !(pSequence->GetFlags() & IUiAnimSequence::eSeqFlags_NoSpeed))
  857. {
  858. NotifyListeners(pSequence, IUiAnimationListener::eUiAnimationEvent_Updated);
  859. it->currentSpeed = fSpeed;
  860. return true;
  861. }
  862. return false;
  863. }
  864. bool UiAnimationSystem::GetStartEndTime(IUiAnimSequence* pSequence, float& fStartTime, float& fEndTime)
  865. {
  866. fStartTime = 0.0f;
  867. fEndTime = 0.0f;
  868. if (!pSequence || !IsPlaying(pSequence))
  869. {
  870. return false;
  871. }
  872. PlayingSequences::const_iterator it;
  873. if (FindSequence(pSequence, it))
  874. {
  875. fStartTime = it->startTime;
  876. fEndTime = it->endTime;
  877. return true;
  878. }
  879. return false;
  880. }
  881. bool UiAnimationSystem::SetStartEndTime(IUiAnimSequence* pSeq, const float fStartTime, const float fEndTime)
  882. {
  883. if (!pSeq || !IsPlaying(pSeq))
  884. {
  885. return false;
  886. }
  887. PlayingSequences::iterator it;
  888. if (FindSequence(pSeq, it))
  889. {
  890. it->startTime = fStartTime;
  891. it->endTime = fEndTime;
  892. return true;
  893. }
  894. return false;
  895. }
  896. void UiAnimationSystem::SetSequenceStopBehavior(ESequenceStopBehavior behavior)
  897. {
  898. m_sequenceStopBehavior = behavior;
  899. }
  900. IUiAnimationSystem::ESequenceStopBehavior UiAnimationSystem::GetSequenceStopBehavior()
  901. {
  902. return m_sequenceStopBehavior;
  903. }
  904. bool UiAnimationSystem::AddUiAnimationListener(IUiAnimSequence* pSequence, IUiAnimationListener* pListener)
  905. {
  906. assert (pListener != 0);
  907. if (pSequence != NULL && std::find(m_sequences.begin(), m_sequences.end(), pSequence) == m_sequences.end())
  908. {
  909. gEnv->pLog->Log ("UiAnimationSystem::AddUiAnimationListener: Sequence %p unknown to UiAnimationSystem", pSequence);
  910. return false;
  911. }
  912. return stl::push_back_unique(m_animationListenerMap[pSequence], pListener);
  913. }
  914. bool UiAnimationSystem::RemoveUiAnimationListener(IUiAnimSequence* pSequence, IUiAnimationListener* pListener)
  915. {
  916. assert (pListener != 0);
  917. if (pSequence != NULL
  918. && std::find(m_sequences.begin(), m_sequences.end(), pSequence) == m_sequences.end())
  919. {
  920. gEnv->pLog->Log ("UiAnimationSystem::AddUiAnimationListener: Sequence %p unknown to UiAnimationSystem", pSequence);
  921. return false;
  922. }
  923. return stl::find_and_erase(m_animationListenerMap[pSequence], pListener);
  924. }
  925. void UiAnimationSystem::GoToFrame(const char* seqName, float targetFrame)
  926. {
  927. assert(seqName != NULL);
  928. for (PlayingSequences::iterator it = m_playingSequences.begin();
  929. it != m_playingSequences.end(); ++it)
  930. {
  931. PlayingUIAnimSequence& ps = *it;
  932. const char* fullname = ps.sequence->GetName();
  933. if (strcmp(fullname, seqName) == 0)
  934. {
  935. assert(ps.sequence->GetTimeRange().start <= targetFrame && targetFrame <= ps.sequence->GetTimeRange().end);
  936. ps.currentTime = targetFrame;
  937. ps.bSingleFrame = true;
  938. break;
  939. }
  940. }
  941. }
  942. //////////////////////////////////////////////////////////////////////////
  943. void UiAnimationSystem::SerializeNodeType(EUiAnimNodeType& animNodeType, XmlNodeRef& xmlNode, bool bLoading, const uint version, int flags)
  944. {
  945. static const char* kType = "Type";
  946. if (bLoading)
  947. {
  948. // Old serialization values that are no longer
  949. // defined in IUiAnimationSystem.h, but needed for conversion:
  950. static const int kOldParticleNodeType = 0x18;
  951. animNodeType = eUiAnimNodeType_Invalid;
  952. // In old versions there was special code for particles
  953. // that is now handles by generic entity node code
  954. if (version == 0 && animNodeType == kOldParticleNodeType)
  955. {
  956. animNodeType = eUiAnimNodeType_Entity;
  957. return;
  958. }
  959. // Convert light nodes that are not part of a light
  960. // animation set to common entity nodes
  961. if (version <= 1 && animNodeType == eUiAnimNodeType_Light && !(flags & IUiAnimSequence::eSeqFlags_LightAnimationSet))
  962. {
  963. animNodeType = eUiAnimNodeType_Entity;
  964. return;
  965. }
  966. if (version <= 2)
  967. {
  968. int type;
  969. if (xmlNode->getAttr(kType, type))
  970. {
  971. animNodeType = (EUiAnimNodeType)type;
  972. }
  973. return;
  974. }
  975. else
  976. {
  977. XmlString nodeTypeString;
  978. if (xmlNode->getAttr(kType, nodeTypeString))
  979. {
  980. assert(m_animNodeStringToEnumMap.contains(nodeTypeString.c_str()));
  981. animNodeType = stl::find_in_map(m_animNodeStringToEnumMap, nodeTypeString.c_str(), eUiAnimNodeType_Invalid);
  982. }
  983. }
  984. }
  985. else
  986. {
  987. const char* pTypeString = "Invalid";
  988. assert(m_animNodeEnumToStringMap.find(animNodeType) != m_animNodeEnumToStringMap.end());
  989. pTypeString = m_animNodeEnumToStringMap[animNodeType].c_str();
  990. xmlNode->setAttr(kType, pTypeString);
  991. }
  992. }
  993. //////////////////////////////////////////////////////////////////////////
  994. void UiAnimationSystem::SerializeParamType(CUiAnimParamType& animParamType, XmlNodeRef& xmlNode, bool bLoading, const uint version)
  995. {
  996. static const char* kByNameAttrName = "paramIdIsName";
  997. static const char* kParamUserValue = "paramUserValue";
  998. if (bLoading)
  999. {
  1000. animParamType.m_type = eUiAnimParamType_Invalid;
  1001. if (version <= 6)
  1002. {
  1003. static const char* kParamId = "paramId";
  1004. if (xmlNode->haveAttr(kByNameAttrName))
  1005. {
  1006. XmlString name;
  1007. if (xmlNode->getAttr(kParamId, name))
  1008. {
  1009. animParamType.m_type = eUiAnimParamType_ByString;
  1010. animParamType.m_name = name.c_str();
  1011. }
  1012. }
  1013. else
  1014. {
  1015. int type;
  1016. xmlNode->getAttr(kParamId, type);
  1017. animParamType.m_type = (EUiAnimParamType)type;
  1018. }
  1019. }
  1020. else
  1021. {
  1022. static const char* kParamType = "paramType";
  1023. XmlString paramTypeString;
  1024. if (xmlNode->getAttr(kParamType, paramTypeString))
  1025. {
  1026. if (paramTypeString == "ByString")
  1027. {
  1028. animParamType.m_type = eUiAnimParamType_ByString;
  1029. XmlString userValue;
  1030. xmlNode->getAttr(kParamUserValue, userValue);
  1031. animParamType.m_name = userValue;
  1032. }
  1033. else if (paramTypeString == "User")
  1034. {
  1035. animParamType.m_type = eUiAnimParamType_User;
  1036. int type;
  1037. xmlNode->getAttr(kParamUserValue, type);
  1038. animParamType.m_type = (EUiAnimParamType)type;
  1039. }
  1040. else
  1041. {
  1042. assert(m_animParamStringToEnumMap.contains(paramTypeString.c_str()));
  1043. animParamType.m_type = stl::find_in_map(m_animParamStringToEnumMap, paramTypeString.c_str(), eUiAnimParamType_Invalid);
  1044. }
  1045. }
  1046. }
  1047. }
  1048. else
  1049. {
  1050. static const char* kParamType = "paramType";
  1051. const char* pTypeString = "Invalid";
  1052. if (animParamType.m_type == eUiAnimParamType_ByString)
  1053. {
  1054. pTypeString = "ByString";
  1055. xmlNode->setAttr(kParamUserValue, animParamType.m_name.c_str());
  1056. }
  1057. else if (animParamType.m_type >= eUiAnimParamType_User)
  1058. {
  1059. pTypeString = "User";
  1060. xmlNode->setAttr(kParamUserValue, (int)animParamType.m_type);
  1061. }
  1062. else
  1063. {
  1064. assert(m_animParamEnumToStringMap.find(animParamType.m_type) != m_animParamEnumToStringMap.end());
  1065. pTypeString = m_animParamEnumToStringMap[animParamType.m_type].c_str();
  1066. }
  1067. xmlNode->setAttr(kParamType, pTypeString);
  1068. }
  1069. }
  1070. //////////////////////////////////////////////////////////////////////////
  1071. void UiAnimationSystem::SerializeParamData(UiAnimParamData& animParamData, XmlNodeRef& xmlNode, bool bLoading)
  1072. {
  1073. static const char* kLabelComponentIdHi = "ParamComponentIdHi";
  1074. static const char* kLabelComponentIdLo = "ParamComponentIdLo";
  1075. static const char* kLabelTypeId = "ParamTypeId";
  1076. static const char* kLabelName = "ParamName";
  1077. static const char* kLabelOffset = "ParamOffset";
  1078. if (bLoading)
  1079. {
  1080. unsigned long idHi = 0;
  1081. unsigned long idLo = 0;
  1082. XmlString uuidStr;
  1083. XmlString nameStr;
  1084. size_t offset = 0;
  1085. xmlNode->getAttr(kLabelComponentIdHi, idHi);
  1086. xmlNode->getAttr(kLabelComponentIdLo, idLo);
  1087. xmlNode->getAttr(kLabelTypeId, uuidStr);
  1088. xmlNode->getAttr(kLabelName, nameStr);
  1089. xmlNode->getAttr(kLabelOffset, offset);
  1090. AZ::u64 id64 = ((AZ::u64)idHi) << 32 | idLo;
  1091. AZ::Uuid uuid(uuidStr.c_str(), uuidStr.length());
  1092. animParamData = UiAnimParamData(id64, nameStr.c_str(), uuid, offset);
  1093. }
  1094. else
  1095. {
  1096. AZ::u64 id64 = animParamData.GetComponentId();
  1097. unsigned long idHi = id64 >> 32;
  1098. unsigned long idLo = id64 & 0xFFFFFFFF;
  1099. XmlString uuidStr;
  1100. uuidStr += animParamData.GetTypeId().ToString<AZStd::string>();
  1101. XmlString nameStr(animParamData.GetName());
  1102. size_t offset = animParamData.GetOffset();
  1103. xmlNode->setAttr(kLabelComponentIdHi, idHi);
  1104. xmlNode->setAttr(kLabelComponentIdLo, idLo);
  1105. xmlNode->setAttr(kLabelTypeId, uuidStr);
  1106. xmlNode->setAttr(kLabelName, nameStr);
  1107. xmlNode->setAttr(kLabelOffset, offset);
  1108. }
  1109. }
  1110. //////////////////////////////////////////////////////////////////////////
  1111. const char* UiAnimationSystem::GetParamTypeName(const CUiAnimParamType& animParamType)
  1112. {
  1113. if (animParamType.m_type == eUiAnimParamType_ByString)
  1114. {
  1115. return animParamType.GetName();
  1116. }
  1117. else if (animParamType.m_type >= eUiAnimParamType_User)
  1118. {
  1119. return "User";
  1120. }
  1121. else
  1122. {
  1123. if (m_animParamEnumToStringMap.find(animParamType.m_type) != m_animParamEnumToStringMap.end())
  1124. {
  1125. return m_animParamEnumToStringMap[animParamType.m_type].c_str();
  1126. }
  1127. }
  1128. return "Invalid";
  1129. }
  1130. //////////////////////////////////////////////////////////////////////////
  1131. void UiAnimationSystem::OnCameraCut()
  1132. {
  1133. }
  1134. //////////////////////////////////////////////////////////////////////////
  1135. void UiAnimationSystem::Reflect(AZ::SerializeContext* serializeContext)
  1136. {
  1137. serializeContext->Class<UiAnimationSystem>()
  1138. ->Version(1)
  1139. ->Field("Sequences", &UiAnimationSystem::m_sequences);
  1140. UiAnimSerialize::ReflectUiAnimTypes(serializeContext);
  1141. // These rely on these classes having a friend declaration for this class
  1142. serializeContext->Class<CUiAnimParamType>()
  1143. ->Version(1)
  1144. ->Field("Type", &CUiAnimParamType::m_type);
  1145. serializeContext->Class<UiAnimParamData>()
  1146. ->Version(1)
  1147. ->Field("ComponentId", &UiAnimParamData::m_componentId)
  1148. ->Field("TypeId", &UiAnimParamData::m_typeId)
  1149. ->Field("Name", &UiAnimParamData::m_name);
  1150. }
  1151. #ifdef UI_ANIMATION_SYSTEM_SUPPORT_EDITING
  1152. //////////////////////////////////////////////////////////////////////////
  1153. EUiAnimNodeType UiAnimationSystem::GetNodeTypeFromString(const char* pString) const
  1154. {
  1155. return stl::find_in_map(m_animNodeStringToEnumMap, pString, eUiAnimNodeType_Invalid);
  1156. }
  1157. //////////////////////////////////////////////////////////////////////////
  1158. CUiAnimParamType UiAnimationSystem::GetParamTypeFromString(const char* pString) const
  1159. {
  1160. const EUiAnimParamType paramType = stl::find_in_map(m_animParamStringToEnumMap, pString, eUiAnimParamType_Invalid);
  1161. if (paramType != eUiAnimParamType_Invalid)
  1162. {
  1163. return CUiAnimParamType(paramType);
  1164. }
  1165. return CUiAnimParamType(pString);
  1166. }
  1167. #endif