2021-12-24 21:11:44 +08:00
|
|
|
|
#include "Slot.h"
|
2020-10-18 00:27:23 +08:00
|
|
|
|
#include "../model/DragonBonesData.h"
|
|
|
|
|
#include "../model/UserData.h"
|
|
|
|
|
#include "../model/SkinData.h"
|
|
|
|
|
#include "../model/DisplayData.h"
|
|
|
|
|
#include "../model/BoundingBoxData.h"
|
|
|
|
|
#include "../model/TextureAtlasData.h"
|
|
|
|
|
#include "Armature.h"
|
|
|
|
|
#include "Bone.h"
|
|
|
|
|
#include "DeformVertices.h"
|
|
|
|
|
#include "../animation/Animation.h"
|
|
|
|
|
#include "../event/EventObject.h"
|
|
|
|
|
|
|
|
|
|
DRAGONBONES_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
|
|
void Slot::_onClear()
|
|
|
|
|
{
|
|
|
|
|
TransformObject::_onClear();
|
|
|
|
|
|
|
|
|
|
std::vector<std::pair<void*, DisplayType>> disposeDisplayList;
|
|
|
|
|
for (const auto& pair : this->_displayList)
|
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
|
if (pair.first != nullptr && pair.first != _rawDisplay && pair.first != _meshDisplay &&
|
|
|
|
|
std::find(disposeDisplayList.cbegin(), disposeDisplayList.cend(), pair) == disposeDisplayList.cend())
|
2020-10-18 00:27:23 +08:00
|
|
|
|
{
|
|
|
|
|
disposeDisplayList.push_back(pair);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (const auto& pair : disposeDisplayList)
|
|
|
|
|
{
|
|
|
|
|
if (pair.second == DisplayType::Armature)
|
|
|
|
|
{
|
|
|
|
|
static_cast<Armature*>(pair.first)->returnToPool();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_disposeDisplay(pair.first, true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_deformVertices != nullptr)
|
|
|
|
|
{
|
|
|
|
|
_deformVertices->returnToPool();
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
|
if (_meshDisplay && _meshDisplay != _rawDisplay)
|
2020-10-18 00:27:23 +08:00
|
|
|
|
{
|
|
|
|
|
_disposeDisplay(_meshDisplay, false);
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
|
if (_rawDisplay)
|
|
|
|
|
{
|
2020-10-18 00:27:23 +08:00
|
|
|
|
_disposeDisplay(_rawDisplay, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
displayController = "";
|
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
|
_displayDirty = false;
|
|
|
|
|
_zOrderDirty = false;
|
|
|
|
|
_blendModeDirty = false;
|
|
|
|
|
_colorDirty = false;
|
|
|
|
|
_transformDirty = false;
|
|
|
|
|
_visible = true;
|
|
|
|
|
_blendMode = BlendMode::Normal;
|
|
|
|
|
_displayIndex = -1;
|
2020-10-18 00:27:23 +08:00
|
|
|
|
_animationDisplayIndex = -1;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
_zOrder = 0;
|
|
|
|
|
_cachedFrameIndex = -1;
|
|
|
|
|
_pivotX = 0.0f;
|
|
|
|
|
_pivotY = 0.0f;
|
2020-10-18 00:27:23 +08:00
|
|
|
|
_localMatrix.identity();
|
|
|
|
|
_colorTransform.identity();
|
|
|
|
|
_displayList.clear();
|
|
|
|
|
_displayDatas.clear();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
_slotData = nullptr;
|
|
|
|
|
_rawDisplayDatas = nullptr; //
|
|
|
|
|
_displayData = nullptr;
|
|
|
|
|
_boundingBoxData = nullptr;
|
|
|
|
|
_textureData = nullptr;
|
|
|
|
|
_deformVertices = nullptr;
|
|
|
|
|
_rawDisplay = nullptr;
|
|
|
|
|
_meshDisplay = nullptr;
|
|
|
|
|
_display = nullptr;
|
|
|
|
|
_childArmature = nullptr;
|
|
|
|
|
_parent = nullptr;
|
2020-10-18 00:27:23 +08:00
|
|
|
|
_cachedFrameIndices = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DisplayData* Slot::_getDefaultRawDisplayData(unsigned displayIndex) const
|
|
|
|
|
{
|
|
|
|
|
const auto defaultSkin = _armature->_armatureData->defaultSkin;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
if (defaultSkin != nullptr)
|
2020-10-18 00:27:23 +08:00
|
|
|
|
{
|
|
|
|
|
const auto defaultRawDisplayDatas = defaultSkin->getDisplays(_slotData->name);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
if (defaultRawDisplayDatas != nullptr)
|
2020-10-18 00:27:23 +08:00
|
|
|
|
{
|
|
|
|
|
return displayIndex < defaultRawDisplayDatas->size() ? (*defaultRawDisplayDatas)[displayIndex] : nullptr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Slot::_updateDisplayData()
|
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
|
const auto prevDisplayData = _displayData;
|
2020-10-18 00:27:23 +08:00
|
|
|
|
const auto prevVerticesData = _deformVertices != nullptr ? _deformVertices->verticesData : nullptr;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
const auto prevTextureData = _textureData;
|
2020-10-18 00:27:23 +08:00
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
|
DisplayData* rawDisplayData = nullptr;
|
2020-10-18 00:27:23 +08:00
|
|
|
|
VerticesData* currentVerticesData = nullptr;
|
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
|
_displayData = nullptr;
|
2020-10-18 00:27:23 +08:00
|
|
|
|
_boundingBoxData = nullptr;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
_textureData = nullptr;
|
2020-10-18 00:27:23 +08:00
|
|
|
|
|
|
|
|
|
if (_displayIndex >= 0)
|
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
|
if (_rawDisplayDatas != nullptr)
|
2020-10-18 00:27:23 +08:00
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
|
rawDisplayData =
|
|
|
|
|
(unsigned)_displayIndex < _rawDisplayDatas->size() ? (*_rawDisplayDatas)[_displayIndex] : nullptr;
|
2020-10-18 00:27:23 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (rawDisplayData == nullptr)
|
|
|
|
|
{
|
|
|
|
|
rawDisplayData = _getDefaultRawDisplayData(_displayIndex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((unsigned)_displayIndex < _displayDatas.size())
|
|
|
|
|
{
|
|
|
|
|
_displayData = _displayDatas[_displayIndex];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update texture and mesh data.
|
|
|
|
|
if (_displayData != nullptr)
|
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
|
if (_displayData->type == DisplayType::Mesh)
|
2020-10-18 00:27:23 +08:00
|
|
|
|
{
|
|
|
|
|
currentVerticesData = &static_cast<MeshDisplayData*>(_displayData)->vertices;
|
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
else if (_displayData->type == DisplayType::Path)
|
2020-10-18 00:27:23 +08:00
|
|
|
|
{
|
|
|
|
|
// TODO
|
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
else if (rawDisplayData != nullptr)
|
2020-10-18 00:27:23 +08:00
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
|
if (rawDisplayData->type == DisplayType::Mesh)
|
2020-10-18 00:27:23 +08:00
|
|
|
|
{
|
|
|
|
|
currentVerticesData = &static_cast<MeshDisplayData*>(rawDisplayData)->vertices;
|
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
else if (rawDisplayData->type == DisplayType::Path)
|
2020-10-18 00:27:23 +08:00
|
|
|
|
{
|
|
|
|
|
// TODO
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
|
if (_displayData->type == DisplayType::BoundingBox)
|
2020-10-18 00:27:23 +08:00
|
|
|
|
{
|
|
|
|
|
_boundingBoxData = static_cast<BoundingBoxDisplayData*>(_displayData)->boundingBox;
|
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
else if (rawDisplayData != nullptr)
|
2020-10-18 00:27:23 +08:00
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
|
if (rawDisplayData->type == DisplayType::BoundingBox)
|
2020-10-18 00:27:23 +08:00
|
|
|
|
{
|
|
|
|
|
_boundingBoxData = static_cast<BoundingBoxDisplayData*>(rawDisplayData)->boundingBox;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
|
if (_displayData->type == DisplayType::Image)
|
2020-10-18 00:27:23 +08:00
|
|
|
|
{
|
|
|
|
|
_textureData = static_cast<ImageDisplayData*>(_displayData)->texture;
|
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
else if (_displayData->type == DisplayType::Mesh)
|
2020-10-18 00:27:23 +08:00
|
|
|
|
{
|
|
|
|
|
_textureData = static_cast<MeshDisplayData*>(_displayData)->texture;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update bounding box data.
|
|
|
|
|
if (_displayData != nullptr && _displayData->type == DisplayType::BoundingBox)
|
|
|
|
|
{
|
|
|
|
|
_boundingBoxData = static_cast<BoundingBoxDisplayData*>(_displayData)->boundingBox;
|
|
|
|
|
}
|
|
|
|
|
else if (rawDisplayData != nullptr && rawDisplayData->type == DisplayType::BoundingBox)
|
|
|
|
|
{
|
|
|
|
|
_boundingBoxData = static_cast<BoundingBoxDisplayData*>(rawDisplayData)->boundingBox;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_boundingBoxData = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_displayData != prevDisplayData || currentVerticesData != prevVerticesData || _textureData != prevTextureData)
|
|
|
|
|
{
|
|
|
|
|
if (currentVerticesData == nullptr && _textureData != nullptr)
|
|
|
|
|
{
|
|
|
|
|
const auto imageDisplayData = static_cast<ImageDisplayData*>(_displayData);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
const auto scale = _textureData->parent->scale * _armature->_armatureData->scale;
|
|
|
|
|
const auto frame = _textureData->frame;
|
2020-10-18 00:27:23 +08:00
|
|
|
|
|
|
|
|
|
_pivotX = imageDisplayData->pivot.x;
|
|
|
|
|
_pivotY = imageDisplayData->pivot.y;
|
|
|
|
|
|
|
|
|
|
const auto& rect = frame != nullptr ? *frame : _textureData->region;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
float width = rect.width;
|
|
|
|
|
float height = rect.height;
|
2020-10-18 00:27:23 +08:00
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
|
if (_textureData->rotated && frame == nullptr)
|
2020-10-18 00:27:23 +08:00
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
|
width = rect.height;
|
2020-10-18 00:27:23 +08:00
|
|
|
|
height = rect.width;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_pivotX *= width * scale;
|
|
|
|
|
_pivotY *= height * scale;
|
|
|
|
|
|
|
|
|
|
if (frame != nullptr)
|
|
|
|
|
{
|
|
|
|
|
_pivotX += frame->x * scale;
|
|
|
|
|
_pivotY += frame->y * scale;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update replace pivot.
|
|
|
|
|
if (_displayData != nullptr && rawDisplayData != nullptr && _displayData != rawDisplayData)
|
|
|
|
|
{
|
|
|
|
|
rawDisplayData->transform.toMatrix(_helpMatrix);
|
|
|
|
|
_helpMatrix.invert();
|
|
|
|
|
_helpMatrix.transformPoint(0.0f, 0.0f, _helpPoint);
|
|
|
|
|
_pivotX -= _helpPoint.x;
|
|
|
|
|
_pivotY -= _helpPoint.y;
|
|
|
|
|
|
|
|
|
|
_displayData->transform.toMatrix(_helpMatrix);
|
|
|
|
|
_helpMatrix.invert();
|
|
|
|
|
_helpMatrix.transformPoint(0.0f, 0.0f, _helpPoint);
|
|
|
|
|
_pivotX += _helpPoint.x;
|
|
|
|
|
_pivotY += _helpPoint.y;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!DragonBones::yDown)
|
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
|
_pivotY = (_textureData->rotated ? _textureData->region.width : _textureData->region.height) * scale -
|
|
|
|
|
_pivotY;
|
2020-10-18 00:27:23 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_pivotX = 0.0f;
|
|
|
|
|
_pivotY = 0.0f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update original transform.
|
|
|
|
|
if (rawDisplayData != nullptr)
|
|
|
|
|
{
|
|
|
|
|
origin = &rawDisplayData->transform;
|
|
|
|
|
}
|
|
|
|
|
else if (_displayData != nullptr)
|
|
|
|
|
{
|
|
|
|
|
origin = &_displayData->transform;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
origin = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update vertices.
|
2021-12-25 10:04:45 +08:00
|
|
|
|
if (currentVerticesData != prevVerticesData)
|
2020-10-18 00:27:23 +08:00
|
|
|
|
{
|
|
|
|
|
if (_deformVertices == nullptr)
|
|
|
|
|
{
|
|
|
|
|
_deformVertices = BaseObject::borrowObject<DeformVertices>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_deformVertices->init(currentVerticesData, _armature);
|
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
else if (_deformVertices != nullptr && _textureData != prevTextureData) // Update mesh after update frame.
|
|
|
|
|
{
|
2020-10-18 00:27:23 +08:00
|
|
|
|
_deformVertices->verticesDirty = true;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
|
_displayDirty = true;
|
2020-10-18 00:27:23 +08:00
|
|
|
|
_transformDirty = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Slot::_updateDisplay()
|
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
|
const auto prevDisplay = _display != nullptr ? _display : _rawDisplay;
|
2020-10-18 00:27:23 +08:00
|
|
|
|
const auto prevChildArmature = _childArmature;
|
|
|
|
|
|
|
|
|
|
// Update display and child armature.
|
|
|
|
|
if (_displayIndex >= 0 && (std::size_t)_displayIndex < _displayList.size())
|
|
|
|
|
{
|
|
|
|
|
const auto& displayPair = _displayList[_displayIndex];
|
2021-12-25 10:04:45 +08:00
|
|
|
|
_display = displayPair.first;
|
2020-10-18 00:27:23 +08:00
|
|
|
|
if (_display != nullptr && displayPair.second == DisplayType::Armature)
|
|
|
|
|
{
|
|
|
|
|
_childArmature = static_cast<Armature*>(displayPair.first);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
_display = _childArmature->getDisplay();
|
2020-10-18 00:27:23 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_childArmature = nullptr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
|
_display = nullptr;
|
2020-10-18 00:27:23 +08:00
|
|
|
|
_childArmature = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const auto currentDisplay = _display != nullptr ? _display : _rawDisplay;
|
|
|
|
|
if (currentDisplay != prevDisplay)
|
|
|
|
|
{
|
|
|
|
|
_onUpdateDisplay();
|
|
|
|
|
_replaceDisplay(prevDisplay, prevChildArmature != nullptr);
|
|
|
|
|
|
|
|
|
|
_transformDirty = true;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
_visibleDirty = true;
|
2020-10-18 00:27:23 +08:00
|
|
|
|
_blendModeDirty = true;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
_colorDirty = true;
|
2020-10-18 00:27:23 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update frame.
|
|
|
|
|
if (currentDisplay == _rawDisplay || currentDisplay == _meshDisplay)
|
|
|
|
|
{
|
|
|
|
|
_updateFrame();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update child armature.
|
|
|
|
|
if (_childArmature != prevChildArmature)
|
|
|
|
|
{
|
|
|
|
|
if (prevChildArmature != nullptr)
|
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
|
prevChildArmature->_parent = nullptr; // Update child armature parent.
|
2020-10-18 00:27:23 +08:00
|
|
|
|
prevChildArmature->setClock(nullptr);
|
|
|
|
|
if (prevChildArmature->inheritAnimation)
|
|
|
|
|
{
|
|
|
|
|
prevChildArmature->getAnimation()->reset();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_childArmature != nullptr)
|
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
|
_childArmature->_parent = this; // Update child armature parent.
|
2020-10-18 00:27:23 +08:00
|
|
|
|
_childArmature->setClock(_armature->getClock());
|
2021-12-25 10:04:45 +08:00
|
|
|
|
if (_childArmature->inheritAnimation) // Set child armature cache frameRate.
|
2020-10-18 00:27:23 +08:00
|
|
|
|
{
|
|
|
|
|
if (_childArmature->getCacheFrameRate() == 0)
|
|
|
|
|
{
|
|
|
|
|
const auto chacheFrameRate = this->_armature->getCacheFrameRate();
|
|
|
|
|
if (chacheFrameRate != 0)
|
|
|
|
|
{
|
|
|
|
|
_childArmature->setCacheFrameRate(chacheFrameRate);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Child armature action.
|
|
|
|
|
std::vector<ActionData*>* actions = nullptr;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
if (_displayData != nullptr && _displayData->type == DisplayType::Armature)
|
2020-10-18 00:27:23 +08:00
|
|
|
|
{
|
|
|
|
|
actions = &(static_cast<ArmatureDisplayData*>(_displayData)->actions);
|
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
else if (_displayIndex >= 0 && _rawDisplayDatas != nullptr)
|
2020-10-18 00:27:23 +08:00
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
|
auto rawDisplayData = (unsigned)_displayIndex < _rawDisplayDatas->size()
|
|
|
|
|
? (*_rawDisplayDatas)[_displayIndex]
|
|
|
|
|
: nullptr;
|
2020-10-18 00:27:23 +08:00
|
|
|
|
|
|
|
|
|
if (rawDisplayData == nullptr)
|
|
|
|
|
{
|
|
|
|
|
rawDisplayData = _getDefaultRawDisplayData(_displayIndex);
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
|
if (rawDisplayData != nullptr && rawDisplayData->type == DisplayType::Armature)
|
2020-10-18 00:27:23 +08:00
|
|
|
|
{
|
|
|
|
|
actions = &(static_cast<ArmatureDisplayData*>(rawDisplayData)->actions);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (actions != nullptr && !actions->empty())
|
|
|
|
|
{
|
|
|
|
|
for (const auto action : *actions)
|
|
|
|
|
{
|
|
|
|
|
const auto eventObject = BaseObject::borrowObject<EventObject>();
|
|
|
|
|
EventObject::actionDataToInstance(action, eventObject, _armature);
|
|
|
|
|
eventObject->slot = this;
|
|
|
|
|
_armature->_bufferAction(eventObject, false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_childArmature->getAnimation()->play();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Slot::_updateGlobalTransformMatrix(bool isCache)
|
|
|
|
|
{
|
|
|
|
|
const auto& parentMatrix = _parent->globalTransformMatrix;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
globalTransformMatrix = _localMatrix; // Copy.
|
2020-10-18 00:27:23 +08:00
|
|
|
|
globalTransformMatrix.concat(parentMatrix);
|
|
|
|
|
|
|
|
|
|
if (isCache)
|
|
|
|
|
{
|
|
|
|
|
global.fromMatrix(globalTransformMatrix);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_globalDirty = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Slot::_setDisplayIndex(int value, bool isAnimation)
|
|
|
|
|
{
|
|
|
|
|
if (isAnimation)
|
|
|
|
|
{
|
|
|
|
|
if (_animationDisplayIndex == value)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_animationDisplayIndex = value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_displayIndex == value)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_displayIndex = value;
|
|
|
|
|
_displayDirty = true;
|
|
|
|
|
|
|
|
|
|
_updateDisplayData();
|
|
|
|
|
|
|
|
|
|
return _displayDirty;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Slot::_setZorder(int value)
|
|
|
|
|
{
|
|
|
|
|
if (_zOrder == value)
|
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
|
// return false;
|
2020-10-18 00:27:23 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
|
_zOrder = value;
|
2020-10-18 00:27:23 +08:00
|
|
|
|
_zOrderDirty = true;
|
|
|
|
|
|
|
|
|
|
return _zOrderDirty;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Slot::_setColor(const ColorTransform& value)
|
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
|
_colorTransform = value; // copy
|
|
|
|
|
_colorDirty = true;
|
2020-10-18 00:27:23 +08:00
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Slot::_setDisplayList(const std::vector<std::pair<void*, DisplayType>>& value)
|
|
|
|
|
{
|
|
|
|
|
if (!value.empty())
|
|
|
|
|
{
|
|
|
|
|
if (_displayList.size() != value.size())
|
|
|
|
|
{
|
|
|
|
|
_displayList.resize(value.size());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (std::size_t i = 0, l = value.size(); i < l; ++i)
|
|
|
|
|
{
|
|
|
|
|
const auto& eachPair = value[i];
|
2021-12-25 10:04:45 +08:00
|
|
|
|
if (eachPair.first != nullptr && eachPair.first != _rawDisplay && eachPair.first != _meshDisplay &&
|
|
|
|
|
eachPair.second != DisplayType::Armature &&
|
|
|
|
|
std::find(_displayList.cbegin(), _displayList.cend(), eachPair) == _displayList.cend())
|
2020-10-18 00:27:23 +08:00
|
|
|
|
{
|
|
|
|
|
_initDisplay(eachPair.first, true);
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
|
_displayList[i].first = eachPair.first;
|
2020-10-18 00:27:23 +08:00
|
|
|
|
_displayList[i].second = eachPair.second;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (!_displayList.empty())
|
|
|
|
|
{
|
|
|
|
|
_displayList.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_displayIndex >= 0 && (std::size_t)_displayIndex < _displayList.size())
|
|
|
|
|
{
|
|
|
|
|
_displayDirty = _display != _displayList[_displayIndex].first;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_displayDirty = _display != nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_updateDisplayData();
|
|
|
|
|
|
|
|
|
|
return _displayDirty;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Slot::init(const SlotData* slotData, Armature* armatureValue, void* rawDisplay, void* meshDisplay)
|
|
|
|
|
{
|
|
|
|
|
if (_slotData != nullptr)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_slotData = slotData;
|
|
|
|
|
//
|
2021-12-25 10:04:45 +08:00
|
|
|
|
_visibleDirty = true;
|
2020-10-18 00:27:23 +08:00
|
|
|
|
_blendModeDirty = true;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
_colorDirty = true;
|
|
|
|
|
_blendMode = _slotData->blendMode;
|
|
|
|
|
_zOrder = _slotData->zOrder;
|
2020-10-18 00:27:23 +08:00
|
|
|
|
_colorTransform = *(_slotData->color);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
_rawDisplay = rawDisplay;
|
|
|
|
|
_meshDisplay = meshDisplay;
|
2020-10-18 00:27:23 +08:00
|
|
|
|
//
|
|
|
|
|
_armature = armatureValue;
|
|
|
|
|
//
|
|
|
|
|
const auto slotParent = _armature->getBone(_slotData->parent->name);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
if (slotParent != nullptr)
|
2020-10-18 00:27:23 +08:00
|
|
|
|
{
|
|
|
|
|
_parent = slotParent;
|
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
else
|
2020-10-18 00:27:23 +08:00
|
|
|
|
{
|
|
|
|
|
// Never;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_armature->_addSlot(this);
|
|
|
|
|
//
|
|
|
|
|
_initDisplay(_rawDisplay, false);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
if (_rawDisplay != _meshDisplay)
|
2020-10-18 00:27:23 +08:00
|
|
|
|
{
|
|
|
|
|
_initDisplay(_meshDisplay, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_onUpdateDisplay();
|
|
|
|
|
_addDisplay();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Slot::update(int cacheFrameIndex)
|
|
|
|
|
{
|
|
|
|
|
if (_displayDirty)
|
|
|
|
|
{
|
|
|
|
|
_displayDirty = false;
|
|
|
|
|
_updateDisplay();
|
|
|
|
|
|
|
|
|
|
// TODO remove slot offset.
|
2021-12-25 10:04:45 +08:00
|
|
|
|
if (_transformDirty) // Update local matrix. (Only updated when both display and transform are dirty.)
|
2020-10-18 00:27:23 +08:00
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
|
if (origin != nullptr)
|
2020-10-18 00:27:23 +08:00
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
|
global = *origin; // Copy.
|
2020-10-18 00:27:23 +08:00
|
|
|
|
global.add(offset).toMatrix(_localMatrix);
|
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
else
|
2020-10-18 00:27:23 +08:00
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
|
global = offset; // Copy.
|
2020-10-18 00:27:23 +08:00
|
|
|
|
global.toMatrix(_localMatrix);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
|
if (_zOrderDirty)
|
2020-10-18 00:27:23 +08:00
|
|
|
|
{
|
|
|
|
|
_zOrderDirty = false;
|
|
|
|
|
_updateZOrder();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (cacheFrameIndex >= 0 && _cachedFrameIndices != nullptr)
|
|
|
|
|
{
|
|
|
|
|
const auto cachedFrameIndex = (*_cachedFrameIndices)[cacheFrameIndex];
|
2021-12-25 10:04:45 +08:00
|
|
|
|
if (cachedFrameIndex >= 0 && _cachedFrameIndex == cachedFrameIndex) // Same cache.
|
2020-10-18 00:27:23 +08:00
|
|
|
|
{
|
|
|
|
|
_transformDirty = false;
|
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
else if (cachedFrameIndex >= 0) // Has been Cached.
|
2020-10-18 00:27:23 +08:00
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
|
_transformDirty = true;
|
2020-10-18 00:27:23 +08:00
|
|
|
|
_cachedFrameIndex = cachedFrameIndex;
|
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
else if (_transformDirty || _parent->_childrenTransformDirty) // Dirty.
|
2020-10-18 00:27:23 +08:00
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
|
_transformDirty = true;
|
2020-10-18 00:27:23 +08:00
|
|
|
|
_cachedFrameIndex = -1;
|
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
else if (_cachedFrameIndex >= 0) // Same cache, but not set index yet.
|
2020-10-18 00:27:23 +08:00
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
|
_transformDirty = false;
|
2020-10-18 00:27:23 +08:00
|
|
|
|
(*_cachedFrameIndices)[cacheFrameIndex] = _cachedFrameIndex;
|
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
else // Dirty.
|
2020-10-18 00:27:23 +08:00
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
|
_transformDirty = true;
|
2020-10-18 00:27:23 +08:00
|
|
|
|
_cachedFrameIndex = -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (_transformDirty || this->_parent->_childrenTransformDirty)
|
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
|
cacheFrameIndex = -1;
|
|
|
|
|
_transformDirty = true;
|
2020-10-18 00:27:23 +08:00
|
|
|
|
_cachedFrameIndex = -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_display == nullptr)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_visibleDirty)
|
|
|
|
|
{
|
|
|
|
|
_visibleDirty = false;
|
|
|
|
|
_updateVisible();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_blendModeDirty)
|
|
|
|
|
{
|
|
|
|
|
_blendModeDirty = false;
|
|
|
|
|
_updateBlendMode();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_colorDirty)
|
|
|
|
|
{
|
|
|
|
|
_colorDirty = false;
|
|
|
|
|
_updateColor();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_deformVertices != nullptr && _deformVertices->verticesData != nullptr && _display == _meshDisplay)
|
|
|
|
|
{
|
|
|
|
|
const auto isSkinned = _deformVertices->verticesData->weight != nullptr;
|
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
|
if (_deformVertices->verticesDirty || (isSkinned && _deformVertices->isBonesUpdate()))
|
2020-10-18 00:27:23 +08:00
|
|
|
|
{
|
|
|
|
|
_deformVertices->verticesDirty = false;
|
|
|
|
|
_updateMesh();
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
|
if (isSkinned) // Compatible.
|
2020-10-18 00:27:23 +08:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_transformDirty)
|
|
|
|
|
{
|
|
|
|
|
_transformDirty = false;
|
|
|
|
|
|
|
|
|
|
if (_cachedFrameIndex < 0)
|
|
|
|
|
{
|
|
|
|
|
const auto isCache = cacheFrameIndex >= 0;
|
|
|
|
|
_updateGlobalTransformMatrix(isCache);
|
|
|
|
|
|
|
|
|
|
if (isCache && _cachedFrameIndices != nullptr)
|
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
|
_cachedFrameIndex = (*_cachedFrameIndices)[cacheFrameIndex] =
|
|
|
|
|
_armature->_armatureData->setCacheFrame(globalTransformMatrix, global);
|
2020-10-18 00:27:23 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_armature->_armatureData->getCacheFrame(globalTransformMatrix, global, _cachedFrameIndex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_updateTransform();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Slot::updateTransformAndMatrix()
|
|
|
|
|
{
|
|
|
|
|
if (_transformDirty)
|
|
|
|
|
{
|
|
|
|
|
_transformDirty = false;
|
|
|
|
|
_updateGlobalTransformMatrix(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
|
void Slot::replaceDisplayData(DisplayData* displayData, int displayIndex)
|
2020-10-18 00:27:23 +08:00
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
|
if (displayIndex < 0)
|
2020-10-18 00:27:23 +08:00
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
|
if (_displayIndex < 0)
|
2020-10-18 00:27:23 +08:00
|
|
|
|
{
|
|
|
|
|
displayIndex = 0;
|
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
else
|
2020-10-18 00:27:23 +08:00
|
|
|
|
{
|
|
|
|
|
displayIndex = _displayIndex;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
|
if (_displayDatas.size() <= (unsigned)displayIndex)
|
|
|
|
|
{
|
2020-10-18 00:27:23 +08:00
|
|
|
|
_displayDatas.resize(displayIndex + 1, nullptr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_displayDatas[displayIndex] = displayData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Slot::containsPoint(float x, float y)
|
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
|
if (_boundingBoxData == nullptr)
|
2020-10-18 00:27:23 +08:00
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
updateTransformAndMatrix();
|
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
|
_helpMatrix = globalTransformMatrix; // Copy.
|
2020-10-18 00:27:23 +08:00
|
|
|
|
_helpMatrix.invert();
|
|
|
|
|
_helpMatrix.transformPoint(x, y, _helpPoint);
|
|
|
|
|
|
|
|
|
|
return _boundingBoxData->containsPoint(_helpPoint.x, _helpPoint.y);
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
|
int Slot::intersectsSegment(float xA,
|
|
|
|
|
float yA,
|
|
|
|
|
float xB,
|
|
|
|
|
float yB,
|
|
|
|
|
Point* intersectionPointA,
|
|
|
|
|
Point* intersectionPointB,
|
|
|
|
|
Point* normalRadians)
|
2020-10-18 00:27:23 +08:00
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
|
if (_boundingBoxData == nullptr)
|
2020-10-18 00:27:23 +08:00
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
updateTransformAndMatrix();
|
|
|
|
|
_helpMatrix = globalTransformMatrix;
|
|
|
|
|
_helpMatrix.invert();
|
|
|
|
|
_helpMatrix.transformPoint(xA, yA, _helpPoint);
|
|
|
|
|
xA = _helpPoint.x;
|
|
|
|
|
yA = _helpPoint.y;
|
|
|
|
|
_helpMatrix.transformPoint(xB, yB, _helpPoint);
|
|
|
|
|
xB = _helpPoint.x;
|
|
|
|
|
yB = _helpPoint.y;
|
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
|
const auto intersectionCount =
|
|
|
|
|
_boundingBoxData->intersectsSegment(xA, yA, xB, yB, intersectionPointA, intersectionPointB, normalRadians);
|
2020-10-18 00:27:23 +08:00
|
|
|
|
if (intersectionCount > 0)
|
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
|
if (intersectionCount == 1 || intersectionCount == 2)
|
2020-10-18 00:27:23 +08:00
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
|
if (intersectionPointA != nullptr)
|
2020-10-18 00:27:23 +08:00
|
|
|
|
{
|
|
|
|
|
globalTransformMatrix.transformPoint(intersectionPointA->x, intersectionPointA->y, *intersectionPointA);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
if (intersectionPointB != nullptr)
|
2020-10-18 00:27:23 +08:00
|
|
|
|
{
|
|
|
|
|
intersectionPointB->x = intersectionPointA->x;
|
|
|
|
|
intersectionPointB->y = intersectionPointA->y;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
else if (intersectionPointB != nullptr)
|
2020-10-18 00:27:23 +08:00
|
|
|
|
{
|
|
|
|
|
globalTransformMatrix.transformPoint(intersectionPointB->x, intersectionPointB->y, *intersectionPointB);
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
else
|
2020-10-18 00:27:23 +08:00
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
|
if (intersectionPointA != nullptr)
|
2020-10-18 00:27:23 +08:00
|
|
|
|
{
|
|
|
|
|
globalTransformMatrix.transformPoint(intersectionPointA->x, intersectionPointA->y, *intersectionPointA);
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
|
if (intersectionPointB != nullptr)
|
2020-10-18 00:27:23 +08:00
|
|
|
|
{
|
|
|
|
|
globalTransformMatrix.transformPoint(intersectionPointB->x, intersectionPointB->y, *intersectionPointB);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (normalRadians != nullptr)
|
|
|
|
|
{
|
|
|
|
|
globalTransformMatrix.transformPoint(cos(normalRadians->x), sin(normalRadians->x), _helpPoint, true);
|
|
|
|
|
normalRadians->x = atan2(_helpPoint.y, _helpPoint.x);
|
|
|
|
|
|
|
|
|
|
globalTransformMatrix.transformPoint(cos(normalRadians->y), sin(normalRadians->y), _helpPoint, true);
|
|
|
|
|
normalRadians->y = atan2(_helpPoint.y, _helpPoint.x);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return intersectionCount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Slot::setVisible(bool value)
|
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
|
if (_visible == value)
|
2020-10-18 00:27:23 +08:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_visible = value;
|
|
|
|
|
_updateVisible();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Slot::setDisplayIndex(int value)
|
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
|
if (_setDisplayIndex(value))
|
2020-10-18 00:27:23 +08:00
|
|
|
|
{
|
|
|
|
|
update(-1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
|
// TODO lsc check
|
2020-10-18 00:27:23 +08:00
|
|
|
|
void Slot::setDisplayList(const std::vector<std::pair<void*, DisplayType>>& value)
|
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
|
const auto backupDisplayList = _displayList; // copy
|
|
|
|
|
auto disposeDisplayList = backupDisplayList; // copy
|
2020-10-18 00:27:23 +08:00
|
|
|
|
disposeDisplayList.clear();
|
|
|
|
|
|
|
|
|
|
if (_setDisplayList(value))
|
|
|
|
|
{
|
|
|
|
|
update(-1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (const auto& pair : backupDisplayList)
|
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
|
if (pair.first != nullptr && pair.first != _rawDisplay && pair.first != _meshDisplay &&
|
2020-10-18 00:27:23 +08:00
|
|
|
|
std::find(_displayList.cbegin(), _displayList.cend(), pair) == _displayList.cend() &&
|
2021-12-25 10:04:45 +08:00
|
|
|
|
std::find(disposeDisplayList.cbegin(), disposeDisplayList.cend(), pair) == disposeDisplayList.cend())
|
2020-10-18 00:27:23 +08:00
|
|
|
|
{
|
|
|
|
|
disposeDisplayList.push_back(pair);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (const auto& pair : disposeDisplayList)
|
|
|
|
|
{
|
|
|
|
|
if (pair.second == DisplayType::Armature)
|
|
|
|
|
{
|
|
|
|
|
static_cast<Armature*>(pair.first)->returnToPool();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_disposeDisplay(pair.first, true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Slot::setRawDisplayDatas(const std::vector<DisplayData*>* value)
|
|
|
|
|
{
|
|
|
|
|
if (_rawDisplayDatas == value)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
|
_displayDirty = true;
|
2020-10-18 00:27:23 +08:00
|
|
|
|
_rawDisplayDatas = value;
|
|
|
|
|
|
|
|
|
|
if (_rawDisplayDatas != nullptr)
|
|
|
|
|
{
|
|
|
|
|
_displayDatas.resize(_rawDisplayDatas->size());
|
|
|
|
|
|
|
|
|
|
for (std::size_t i = 0, l = _displayDatas.size(); i < l; ++i)
|
|
|
|
|
{
|
|
|
|
|
auto rawDisplayData = (*_rawDisplayDatas)[i];
|
|
|
|
|
|
|
|
|
|
if (rawDisplayData == nullptr)
|
|
|
|
|
{
|
|
|
|
|
rawDisplayData = _getDefaultRawDisplayData(i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_displayDatas[i] = rawDisplayData;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
else
|
2020-10-18 00:27:23 +08:00
|
|
|
|
{
|
|
|
|
|
_displayDatas.clear();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Slot::setDisplay(void* value, DisplayType displayType)
|
|
|
|
|
{
|
|
|
|
|
if (_display == value)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const auto displayListLength = _displayList.size();
|
|
|
|
|
if (_displayIndex < 0 && displayListLength == 0) // Emprty
|
|
|
|
|
{
|
|
|
|
|
_displayIndex = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_displayIndex < 0)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
|
auto relpaceDisplayList = _displayList; // copy
|
2020-10-18 00:27:23 +08:00
|
|
|
|
if (displayListLength <= (std::size_t)_displayIndex)
|
|
|
|
|
{
|
|
|
|
|
relpaceDisplayList.resize(_displayIndex + 1);
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
|
relpaceDisplayList[_displayIndex].first = value;
|
2020-10-18 00:27:23 +08:00
|
|
|
|
relpaceDisplayList[_displayIndex].second = displayType;
|
|
|
|
|
|
|
|
|
|
setDisplayList(relpaceDisplayList);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Slot::setChildArmature(Armature* value)
|
|
|
|
|
{
|
|
|
|
|
if (_childArmature == value)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setDisplay(value, DisplayType::Armature);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DRAGONBONES_NAMESPACE_END
|