7
#include "Precompiled.h"
8
#include "AnimationViewControl.h"
9
#include "FactoryManager.h"
10
#include "DataSelectorManager.h"
11
#include "DataManager.h"
12
#include "DataUtility.h"
17
FACTORY_ITEM_ATTRIBUTE(AnimationViewControl)
19
AnimationViewControl::AnimationViewControl() :
24
mButtonRight(nullptr),
32
AnimationViewControl::~AnimationViewControl()
36
void AnimationViewControl::OnInitialise(Control* _parent, MyGUI::Widget* _place, const std::string& _layoutName)
38
Control::OnInitialise(_parent, _place, _layoutName);
40
InitialiseByAttributes(this);
42
std::string parentType = "Index";
43
DataSelectorManager::getInstance().getEvent(parentType)->connect(this, &AnimationViewControl::notifyChangeDataSelector);
44
mParentData = DataUtility::getSelectedDataByType(parentType);
45
notifyChangeDataSelector(mParentData, false);
47
mImage->getParent()->eventChangeCoord += MyGUI::newDelegate(this, &AnimationViewControl::notifyChangeCoord);
50
MyGUI::Gui::getInstance().eventFrameStart += MyGUI::newDelegate(this, &AnimationViewControl::notifyFrameStart);
52
mButtonPlay->eventMouseButtonClick += MyGUI::newDelegate(this, &AnimationViewControl::notifyMouseButtonClick);
53
mButtonLeft->eventMouseButtonClick += MyGUI::newDelegate(this, &AnimationViewControl::notifyMouseButtonClick);
54
mButtonRight->eventMouseButtonClick += MyGUI::newDelegate(this, &AnimationViewControl::notifyMouseButtonClick);
57
void AnimationViewControl::notifyChangeDataSelector(DataPtr _parent, bool _changeSelectOnly)
59
mParentData = _parent;
61
if (!_changeSelectOnly)
63
connectToProperties();
68
updateSelectedFrame();
72
void AnimationViewControl::connectToProperties()
74
if (mParentData != nullptr)
77
PropertyPtr property = mParentData->getProperty("Rate");
78
if (!property->eventChangeProperty.exist(this, &AnimationViewControl::notifyChangeProperty))
79
property->eventChangeProperty.connect(this, &AnimationViewControl::notifyChangeProperty);
82
property = mParentData->getParent()->getProperty("Size");
83
if (!property->eventChangeProperty.exist(this, &AnimationViewControl::notifyChangeProperty))
84
property->eventChangeProperty.connect(this, &AnimationViewControl::notifyChangeProperty);
87
property = mParentData->getParent()->getProperty("Texture");
88
if (!property->eventChangeProperty.exist(this, &AnimationViewControl::notifyChangeProperty))
89
property->eventChangeProperty.connect(this, &AnimationViewControl::notifyChangeProperty);
91
for (Data::VectorData::const_iterator child = mParentData->getChilds().begin(); child != mParentData->getChilds().end(); child ++)
93
property = (*child)->getProperty("Point");
94
if (!property->eventChangeProperty.exist(this, &AnimationViewControl::notifyChangeProperty))
95
property->eventChangeProperty.connect(this, &AnimationViewControl::notifyChangeProperty);
97
property = (*child)->getProperty("Count");
98
if (!property->eventChangeProperty.exist(this, &AnimationViewControl::notifyChangeProperty))
99
property->eventChangeProperty.connect(this, &AnimationViewControl::notifyChangeProperty);
104
void AnimationViewControl::rebuildAnimations()
106
mAnimation.setTextureName("");
107
mAnimation.clearFrames();
111
if (mParentData != nullptr)
113
mAnimation.setTextureName(mParentData->getParent()->getPropertyValue("Texture"));
114
mAnimation.setSize(mParentData->getParent()->getPropertyValue<MyGUI::IntCoord>("Size").size());
115
mAnimation.setRate(mParentData->getPropertyValue<float>("Rate"));
117
for (Data::VectorData::const_iterator child = mParentData->getChilds().begin(); child != mParentData->getChilds().end(); child ++)
119
size_t count = (*child)->getPropertyValue<size_t>("Count");
120
MyGUI::IntPoint point = (*child)->getPropertyValue<MyGUI::IntPoint>("Point");
121
mAnimation.addFrame(point, count);
125
updateSelectedFrame();
128
mImage->setImageTexture(mAnimation.getTextureName());
130
if (mAnimation.getFrames().size() == 0)
131
mImage->setImageCoord(MyGUI::IntCoord());
135
mFrameInfo->setCaption(MyGUI::utility::toString(mCurrentFrame, " : ", mAnimation.getFrames().size()));
140
void AnimationViewControl::notifyChangeProperty(PropertyPtr _sender)
145
void AnimationViewControl::updateImageCoord()
147
MyGUI::IntSize size = mAnimation.getSize();
148
MyGUI::IntSize parentSize = mImage->getParentSize();
150
mImage->setCoord((parentSize.width - size.width) / 2, (parentSize.height - size.height) / 2, size.width, size.height);
153
void AnimationViewControl::notifyChangeCoord(MyGUI::Widget* _sender)
158
void AnimationViewControl::notifyFrameStart(float _frame)
160
if (mAnimation.getFrames().size() == 0 || !mPlay)
165
float len = mAnimation.getFrames()[mCurrentFrame].second * mAnimation.getRate();
176
void AnimationViewControl::notifyMouseButtonClick(MyGUI::Widget* _sender)
178
if (_sender == mButtonPlay)
181
mButtonPlay->setStateSelected(!mPlay);
184
updateSelectedFrame();
186
else if (_sender == mButtonLeft)
188
if (mAnimation.getFrames().size() != 0 && !mPlay)
190
mCurrentFrame += mAnimation.getFrames().size();
196
else if (_sender == mButtonRight && !mPlay)
198
if (mAnimation.getFrames().size() != 0)
206
void AnimationViewControl::updateFrame()
208
mCurrentFrame %= mAnimation.getFrames().size();
209
MyGUI::IntPoint point = mAnimation.getFrames()[mCurrentFrame].first;
211
mImage->setImageCoord(MyGUI::IntCoord(point.left, point.top, mAnimation.getSize().width, mAnimation.getSize().height));
212
mImage->setImageTile(mAnimation.getSize());
213
mImage->setImageIndex(0);
214
mFrameInfo->setCaption(MyGUI::utility::toString(mCurrentFrame, " : ", mAnimation.getFrames().size()));
217
void AnimationViewControl::updateSelectedFrame()
219
if (mParentData == nullptr || mParentData->getChildSelected() == nullptr)
221
mImage->setImageCoord(MyGUI::IntCoord());
223
mFrameInfo->setCaption(MyGUI::utility::toString(mCurrentFrame, " : ", mAnimation.getFrames().size()));
227
DataPtr selected = mParentData->getChildSelected();
229
mCurrentFrame = mParentData->getChildIndex(selected);