1 // Copyright 2001-2018 Crytek GmbH / Crytek Group. All rights reserved.
4 #include "ParticleManager.h"
6 #include "ParticleItem.h"
7 #include "ParticleLibrary.h"
9 #include "GameEngine.h"
11 #include "Controls/PropertyItem.h"
12 #include "DataBaseDialog.h"
13 #include "ParticleDialog.h"
15 #define PARTICLES_LIBS_PATH "Libs/Particles/"
17 //////////////////////////////////////////////////////////////////////////
18 // CParticleManager implementation.
19 //////////////////////////////////////////////////////////////////////////
20 CParticleManager::CParticleManager()
22 m_bUniqNameMap
= true;
23 m_bUniqGuidMap
= false;
24 m_pLevelLibrary
= (CBaseLibrary
*)AddLibrary("Level");
25 m_pLevelLibrary
->SetLevelLibrary(true);
27 //register deprecated property editors
28 GetIEditorImpl()->RegisterDeprecatedPropertyEditor(ePropertyParticleName
, WrapMemberFunction(this, &CParticleManager::OnPickParticle
));
31 //////////////////////////////////////////////////////////////////////////
32 CParticleManager::~CParticleManager()
36 //////////////////////////////////////////////////////////////////////////
37 void CParticleManager::ClearAll()
39 CBaseLibraryManager::ClearAll();
41 m_pLevelLibrary
= (CBaseLibrary
*)AddLibrary("Level");
42 m_pLevelLibrary
->SetLevelLibrary(true);
45 //////////////////////////////////////////////////////////////////////////
46 CBaseLibraryItem
* CParticleManager::MakeNewItem()
48 return new CParticleItem
;
50 //////////////////////////////////////////////////////////////////////////
51 CBaseLibrary
* CParticleManager::MakeNewLibrary()
53 return new CParticleLibrary(this);
56 bool CParticleManager::OnPickParticle(const string
& oldValue
, string
& newValue
)
58 CString libraryName
= "";
59 CBaseLibraryItem
* pItem
= NULL
;
60 CString
particleName(oldValue
);
63 if (strcmp(particleName
, "") != 0)
66 libraryName
= particleName
.Tokenize(".", pos
);
67 CParticleManager
* particleMgr
= GetIEditorImpl()->GetParticleManager();
68 IDataBaseLibrary
* pLibrary
= particleMgr
->FindLibrary(libraryName
);
71 CString fullLibraryName
= libraryName
+ ".xml";
72 fullLibraryName
.MakeLower();
73 fullLibraryName
= CString("Libs/Particles/") + fullLibraryName
;
74 GetIEditorImpl()->GetIUndoManager()->Suspend();
75 pLibrary
= particleMgr
->LoadLibrary(fullLibraryName
);
76 GetIEditorImpl()->GetIUndoManager()->Resume();
81 particleName
.Delete(0, pos
);
82 pItem
= (CBaseLibraryItem
*)pLibrary
->FindItem(particleName
.GetString());
85 CString
leafParticleName(particleName
);
87 int lastDotPos
= particleName
.ReverseFind('.');
88 while (!pItem
&& lastDotPos
> -1)
90 particleName
.Delete(lastDotPos
, particleName
.GetLength() - lastDotPos
);
91 lastDotPos
= particleName
.ReverseFind('.');
92 pItem
= (CBaseLibraryItem
*)pLibrary
->FindItem(particleName
.GetString());
95 leafParticleName
.Replace(particleName
, "");
96 if (leafParticleName
.IsEmpty() || (leafParticleName
.GetLength() == 1 && leafParticleName
[0] == '.'))
98 if (leafParticleName
[0] == '.')
99 leafParticleName
.Delete(0);
103 GetIEditorImpl()->OpenView(DATABASE_VIEW_NAME
);
105 CDataBaseDialog
* pDataBaseDlg
= (CDataBaseDialog
*)GetIEditorImpl()->FindView("DataBase View");
106 if (pDataBaseDlg
== NULL
)
109 pDataBaseDlg
->SelectDialog(EDB_TYPE_PARTICLE
);
111 CParticleDialog
* particleDlg
= (CParticleDialog
*)pDataBaseDlg
->GetCurrent();
112 if (particleDlg
== NULL
)
115 particleDlg
->Reload();
117 if (pItem
&& strcmp(libraryName
, "") != 0)
118 particleDlg
->SelectLibrary(libraryName
.GetString());
120 particleDlg
->SelectItem(pItem
);
125 //////////////////////////////////////////////////////////////////////////
126 string
CParticleManager::GetRootNodeName()
128 return "ParticleLibs";
130 //////////////////////////////////////////////////////////////////////////
131 string
CParticleManager::GetLibsPath()
133 if (m_libsPath
.IsEmpty())
134 m_libsPath
= PARTICLES_LIBS_PATH
;
138 //////////////////////////////////////////////////////////////////////////
139 void CParticleManager::Export(XmlNodeRef
& node
)
141 XmlNodeRef libs
= node
->newChild("ParticlesLibrary");
142 for (int i
= 0; i
< GetLibraryCount(); i
++)
144 IDataBaseLibrary
* pLib
= GetLibrary(i
);
145 if (pLib
->IsLevelLibrary())
147 // Level libraries are saved in level.
148 XmlNodeRef libNode
= libs
->newChild("Library");
149 libNode
->setAttr("Name", pLib
->GetName());
153 //////////////////////////////////////////////////////////////////////////
154 void CParticleManager::PasteToParticleItem(CParticleItem
* pItem
, XmlNodeRef
& node
, bool bWithChilds
)
157 assert(node
!= NULL
);
159 CBaseLibraryItem::SerializeContext
serCtx(node
, true);
160 serCtx
.bCopyPaste
= true;
161 serCtx
.bIgnoreChilds
= !bWithChilds
;
162 pItem
->Serialize(serCtx
);
163 pItem
->GenerateIdRecursively();
166 //////////////////////////////////////////////////////////////////////////
167 void CParticleManager::DeleteItem(IDataBaseItem
* pItem
)
169 CParticleItem
* pPartItem
= ((CParticleItem
*)pItem
);
170 if (pPartItem
->GetParent())
171 pPartItem
->SetParent(NULL
);
173 CBaseLibraryManager::DeleteItem(pItem
);
177 #include <CryCore/Common_TypeInfo.h>
178 // Manually instantiate templates as needed here.
179 STRUCT_INFO_T_INSTANTIATE(Color_tpl
, <float>)