520389e3
xiaoyu
接入cocos源码,编译未通过,继续修改
|
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
|
/****************************************************************************
Copyright (c) 2013-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "editor-support/cocostudio/CCDisplayManager.h"
#include "editor-support/cocostudio/CCBone.h"
#include "editor-support/cocostudio/CCArmature.h"
#include "editor-support/cocostudio/CCUtilMath.h"
#include "editor-support/cocostudio/CCSkin.h"
#include "2d/CCParticleSystemQuad.h"
using namespace cocos2d;
namespace cocostudio {
DisplayManager *DisplayManager::create(Bone *bone)
{
DisplayManager *pDisplayManager = new (std::nothrow) DisplayManager();
if (pDisplayManager && pDisplayManager->init(bone))
{
pDisplayManager->autorelease();
return pDisplayManager;
}
CC_SAFE_DELETE(pDisplayManager);
return nullptr;
}
DisplayManager::DisplayManager()
: _displayRenderNode(nullptr)
, _displayType(CS_DISPLAY_MAX)
, _currentDecoDisplay(nullptr)
, _displayIndex(-1)
, _forceChangeDisplay(false)
, _visible(true)
, _bone(nullptr)
{
}
DisplayManager::~DisplayManager()
{
_decoDisplayList.clear();
if( _displayRenderNode )
{
_displayRenderNode->removeFromParentAndCleanup(true);
if(_displayRenderNode->getReferenceCount() > 0)
CC_SAFE_RELEASE_NULL(_displayRenderNode);
}
}
bool DisplayManager::init(Bone *bone)
{
bool ret = false;
do
{
_bone = bone;
initDisplayList(bone->getBoneData());
ret = true;
}
while (0);
return ret;
}
void DisplayManager::addDisplay(DisplayData *displayData, int index)
{
DecorativeDisplay *decoDisplay = nullptr;
if( (index >= 0) && (index < _decoDisplayList.size()) )
{
decoDisplay = (DecorativeDisplay *)_decoDisplayList.at(index);
}
else
{
decoDisplay = DecorativeDisplay::create();
_decoDisplayList.pushBack(decoDisplay);
}
DisplayFactory::addDisplay(_bone, decoDisplay, displayData);
//! if changed display index is current display index, then change current display to the new display
if(index == _displayIndex)
{
_displayIndex = -1;
changeDisplayWithIndex(index, false);
}
}
void DisplayManager::addDisplay(Node *display, int index)
{
DecorativeDisplay *decoDisplay = nullptr;
if( (index >= 0) && (index < _decoDisplayList.size()) )
{
decoDisplay = _decoDisplayList.at(index);
}
else
{
decoDisplay = DecorativeDisplay::create();
_decoDisplayList.pushBack(decoDisplay);
}
DisplayData *displayData = nullptr;
if (Skin *skin = dynamic_cast<Skin *>(display))
{
skin->setBone(_bone);
displayData = SpriteDisplayData::create();
DisplayFactory::initSpriteDisplay(_bone, decoDisplay, skin->getDisplayName().c_str(), skin);
if (SpriteDisplayData *spriteDisplayData = (SpriteDisplayData *)decoDisplay->getDisplayData())
{
skin->setSkinData(spriteDisplayData->skinData);
((SpriteDisplayData *)displayData)->skinData = spriteDisplayData->skinData;
}
else
{
bool find = false;
for (long i = _decoDisplayList.size()-2; i>=0; i--)
{
DecorativeDisplay *dd = _decoDisplayList.at(i);
SpriteDisplayData *sdd = static_cast<SpriteDisplayData*>(dd->getDisplayData());
if (sdd)
{
find = true;
skin->setSkinData(sdd->skinData);
static_cast<SpriteDisplayData*>(displayData)->skinData = sdd->skinData;
break;
}
}
if (!find)
{
BaseData baseData;
skin->setSkinData(baseData);
}
}
}
else if (dynamic_cast<ParticleSystemQuad *>(display))
{
displayData = ParticleDisplayData::create();
display->removeFromParent();
display->cleanup();
Armature *armature = _bone->getArmature();
if (armature)
{
display->setParent(armature);
}
}
else if(Armature *armature = dynamic_cast<Armature *>(display))
{
displayData = ArmatureDisplayData::create();
displayData->displayName = armature->getName();
armature->setParentBone(_bone);
}
else
{
displayData = DisplayData::create();
}
decoDisplay->setDisplay(display);
decoDisplay->setDisplayData(displayData);
//! if changed display index is current display index, then change current display to the new display
if(index == _displayIndex)
{
_displayIndex = -1;
changeDisplayWithIndex(index, false);
}
}
void DisplayManager::removeDisplay(int index)
{
if(index == _displayIndex)
{
setCurrentDecorativeDisplay(nullptr);
_displayIndex = -1;
}
_decoDisplayList.erase(index);
}
const cocos2d::Vector<DecorativeDisplay*>& DisplayManager::getDecorativeDisplayList() const
{
return _decoDisplayList;
}
void DisplayManager::changeDisplayWithIndex(int index, bool force)
{
CCASSERT( index < (int)_decoDisplayList.size(), "the _index value is out of range");
_forceChangeDisplay = force;
//! If index is equal to current display index,then do nothing
if ( _displayIndex == index)
return;
_displayIndex = index;
//! If displayIndex < 0, it means you want to hide you display
if (_displayIndex < 0)
{
if(_displayRenderNode)
{
_displayRenderNode->removeFromParentAndCleanup(true);
setCurrentDecorativeDisplay(nullptr);
}
return;
}
DecorativeDisplay *decoDisplay = (DecorativeDisplay *)_decoDisplayList.at(_displayIndex);
setCurrentDecorativeDisplay(decoDisplay);
}
void DisplayManager::changeDisplayWithName(const std::string& name, bool force)
{
for (int i = 0; i<_decoDisplayList.size(); i++)
{
if (_decoDisplayList.at(i)->getDisplayData()->displayName == name)
{
changeDisplayWithIndex(i, force);
break;
}
}
}
void DisplayManager::setCurrentDecorativeDisplay(DecorativeDisplay *decoDisplay)
{
#if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT || ENABLE_PHYSICS_SAVE_CALCULATED_VERTEX
if (_currentDecoDisplay && _currentDecoDisplay->getColliderDetector())
{
_currentDecoDisplay->getColliderDetector()->setActive(false);
}
#endif
_currentDecoDisplay = decoDisplay;
#if ENABLE_PHYSICS_BOX2D_DETECT || ENABLE_PHYSICS_CHIPMUNK_DETECT || ENABLE_PHYSICS_SAVE_CALCULATED_VERTEX
if (_currentDecoDisplay && _currentDecoDisplay->getColliderDetector())
{
_currentDecoDisplay->getColliderDetector()->setActive(true);
}
#endif
Node *displayRenderNode = _currentDecoDisplay == nullptr ? nullptr : _currentDecoDisplay->getDisplay();
if (_displayRenderNode)
{
if (dynamic_cast<Armature *>(_displayRenderNode) != nullptr)
{
_bone->setChildArmature(nullptr);
}
_displayRenderNode->removeFromParentAndCleanup(true);
_displayRenderNode->release();
}
_displayRenderNode = displayRenderNode;
if(_displayRenderNode)
{
if (Armature *armature = dynamic_cast<Armature *>(_displayRenderNode))
{
_bone->setChildArmature(armature);
armature->setParentBone(_bone);
}
else if (ParticleSystemQuad *particle = dynamic_cast<ParticleSystemQuad *>(_displayRenderNode))
{
particle->resetSystem();
}
_displayRenderNode->setColor(_bone->getDisplayedColor());
_displayRenderNode->setOpacity(_bone->getDisplayedOpacity());
_displayRenderNode->retain();
_displayRenderNode->setVisible(_visible);
_displayType = _currentDecoDisplay->getDisplayData()->displayType;
}
else
{
_displayType = CS_DISPLAY_MAX;
}
}
Node *DisplayManager::getDisplayRenderNode() const
{
return _displayRenderNode;
}
DisplayType DisplayManager::getDisplayRenderNodeType() const
{
return _displayType;
}
int DisplayManager::getCurrentDisplayIndex() const
{
return _displayIndex;
}
DecorativeDisplay *DisplayManager::getCurrentDecorativeDisplay() const
{
return _currentDecoDisplay;
}
DecorativeDisplay *DisplayManager::getDecorativeDisplayByIndex( int index) const
{
return _decoDisplayList.at(index);
}
void DisplayManager::initDisplayList(BoneData *boneData)
{
_decoDisplayList.clear();
CS_RETURN_IF(!boneData);
for(auto& object : boneData->displayDataList)
{
DisplayData *displayData = static_cast<DisplayData *>(object);
DecorativeDisplay *decoDisplay = DecorativeDisplay::create();
decoDisplay->setDisplayData(displayData);
DisplayFactory::createDisplay(_bone, decoDisplay);
_decoDisplayList.pushBack(decoDisplay);
}
}
bool DisplayManager::containPoint(Vec2 &point)
{
if(!_visible || _displayIndex < 0)
{
return false;
}
bool ret = false;
switch (_currentDecoDisplay->getDisplayData()->displayType)
{
case CS_DISPLAY_SPRITE:
{
/*
* First we first check if the point is in the sprite content rect. If false, then we continue to check
* the contour point. If this step is also false, then we can say the bone not contain this point.
*
*/
Vec2 outPoint;
Sprite *sprite = (Sprite *)_currentDecoDisplay->getDisplay();
Sprite *child = (Sprite *)sprite->getChildByTag(0);
if(nullptr != child)
sprite = child;
if (nullptr != sprite)
ret = CC_SPRITE_CONTAIN_POINT_WITH_RETURN(sprite, point, outPoint);
}
break;
default:
break;
}
return ret;
}
bool DisplayManager::containPoint(float x, float y)
{
Vec2 p(x, y);
return containPoint(p);
}
void DisplayManager::setVisible(bool visible)
{
if(!_displayRenderNode)
return;
_visible = visible;
_displayRenderNode->setVisible(visible);
}
bool DisplayManager::isVisible() const
{
return _visible;
}
Size DisplayManager::getContentSize() const
{
CS_RETURN_IF(!_displayRenderNode) Size(0, 0);
return _displayRenderNode->getContentSize();
}
Rect DisplayManager::getBoundingBox() const
{
CS_RETURN_IF(!_displayRenderNode) Rect(0, 0, 0, 0);
return _displayRenderNode->getBoundingBox();
}
Vec2 DisplayManager::getAnchorPoint() const
{
CS_RETURN_IF(!_displayRenderNode) Vec2(0, 0);
return _displayRenderNode->getAnchorPoint();
}
Vec2 DisplayManager::getAnchorPointInPoints() const
{
CS_RETURN_IF(!_displayRenderNode) Vec2(0, 0);
return _displayRenderNode->getAnchorPointInPoints();
}
}
|