!XT (BREAK-16) (Sandbox) Remove double-newlines at the end of files.
[CRYENGINE.git] / Code / Sandbox / Plugins / EditorCommon / QPropertyTree / CharacterAnimationSelector.cpp
blob5060ea02e3c870d9586e173443aaf8256068b894
1 // Copyright 2001-2018 Crytek GmbH / Crytek Group. All rights reserved.
3 #pragma once
5 #include "StdAfx.h"
7 #include <Models/CharacterAnimationsModel.h>
8 #include <Dialogs/TreeViewDialog.h>
9 #include "IResourceSelectorHost.h"
11 #include <CryAnimation/ICryAnimation.h>
13 dll_string CharacterAnimationSelector(const SResourceSelectorContext& x, const char* previousValue, IEntity* pEntity)
15 if (!pEntity || !pEntity->GetCharacter(0) || !pEntity->GetCharacter(0)->GetIAnimationSet())
16 return previousValue;
18 IAnimationSet* pAnimSet = pEntity->GetCharacter(0)->GetIAnimationSet();
19 CCharacterAnimationsModel* pModel = new CCharacterAnimationsModel(*pAnimSet);
20 CTreeViewDialog dialog(x.parentWidget);
21 QString selectedValue(previousValue);
23 dialog.Initialize(pModel, 0);
25 for (int32 row = pModel->rowCount(); row--; )
27 const QModelIndex index = pModel->index(row, 0);
28 if (pModel->data(index, Qt::DisplayRole).value<QString>() == selectedValue)
30 dialog.SetSelectedValue(index, false);
34 if (dialog.exec())
36 QModelIndex index = dialog.GetSelected();
37 if (index.isValid())
39 return index.data().value<QString>().toLocal8Bit().data();
43 return previousValue;
46 dll_string ValidateCharacterAnimation(const SResourceSelectorContext& x, const char* newValue, const char* previousValue, IEntity* pEntity)
48 if (!newValue || !*newValue)
49 return dll_string();
51 if (!pEntity || !pEntity->GetCharacter(0) || !pEntity->GetCharacter(0)->GetIAnimationSet())
52 return previousValue;
54 IAnimationSet* pAnimSet = pEntity->GetCharacter(0)->GetIAnimationSet();
55 CCharacterAnimationsModel* pModel = new CCharacterAnimationsModel(*pAnimSet);
56 int itemCount = pModel->rowCount();
57 for (int i = 0; i < itemCount; ++i)
59 QModelIndex index = pModel->index(i, 0);
60 if (pModel->data(index, Qt::DisplayRole).value<QString>() == newValue)
61 return newValue;
64 return previousValue;
67 dll_string ValidateTrackCharacterAnimation(const SResourceSelectorContext& x, const char* newValue, const char* previousValue, IEntity* pEntity)
69 return newValue;
72 REGISTER_RESOURCE_VALIDATING_SELECTOR("TrackCharacterAnimation", CharacterAnimationSelector, ValidateTrackCharacterAnimation, "")
73 REGISTER_RESOURCE_VALIDATING_SELECTOR("CharacterAnimation", CharacterAnimationSelector, ValidateCharacterAnimation, "")