Skip to content

Commit c88d483

Browse files
author
Chenguang Liu
committed
Merge remote-tracking branch 'origin/dev'
2 parents 4a66e16 + c3fab97 commit c88d483

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+5538
-3005
lines changed

src/dragonBones/Armature.as

Lines changed: 363 additions & 215 deletions
Large diffs are not rendered by default.

src/dragonBones/Bone.as

Lines changed: 230 additions & 378 deletions
Large diffs are not rendered by default.

src/dragonBones/Slot.as

Lines changed: 326 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,326 @@
1+
package dragonBones
2+
{
3+
import dragonBones.core.DBObject;
4+
import dragonBones.core.dragonBones_internal;
5+
import dragonBones.display.IDisplayBridge;
6+
import dragonBones.objects.DisplayData;
7+
8+
import flash.geom.Matrix;
9+
10+
use namespace dragonBones_internal;
11+
12+
public class Slot extends DBObject
13+
{
14+
/** @private */
15+
dragonBones_internal var _dislayDataList:Vector.<DisplayData>;
16+
/** @private */
17+
dragonBones_internal var _displayBridge:IDisplayBridge;
18+
/** @private */
19+
dragonBones_internal var _originZOrder:Number;
20+
/** @private */
21+
dragonBones_internal var _tweenZorder:Number;
22+
/** @private */
23+
dragonBones_internal var _isDisplayOnStage:Boolean;
24+
25+
private var _isHideDisplay:Boolean;
26+
private var _offsetZOrder:Number;
27+
private var _displayIndex:int;
28+
29+
public function get zOrder():Number
30+
{
31+
return _originZOrder + _tweenZorder + _offsetZOrder;
32+
}
33+
34+
public function set zOrder(value:Number):void
35+
{
36+
if(zOrder != value)
37+
{
38+
_offsetZOrder = value - _originZOrder - _tweenZorder;
39+
if(this._armature)
40+
{
41+
this._armature._slotsZOrderChanged = true;
42+
}
43+
}
44+
}
45+
46+
/**
47+
* The DisplayObject belonging to this Bone instance. Instance type of this object varies from flash.display.DisplayObject to startling.display.DisplayObject and subclasses.
48+
*/
49+
public function get display():Object
50+
{
51+
var display:Object = _displayList[_displayIndex];
52+
if(display is Armature)
53+
{
54+
return display.display;
55+
}
56+
return display;
57+
}
58+
public function set display(value:Object):void
59+
{
60+
_displayList[_displayIndex] = value;
61+
setDisplay(value);
62+
}
63+
64+
/**
65+
* The sub-armature of this Slot instance.
66+
*/
67+
public function get childArmature():Armature
68+
{
69+
return _displayList[_displayIndex] as Armature;
70+
}
71+
public function set childArmature(value:Armature):void
72+
{
73+
_displayList[_displayIndex] = value;
74+
if(value)
75+
{
76+
setDisplay(value.display);
77+
}
78+
}
79+
80+
private var _displayList:Array;
81+
/**
82+
* The DisplayObject list belonging to this Slot instance.
83+
*/
84+
public function get displayList():Array
85+
{
86+
return _displayList;
87+
}
88+
public function set displayList(value:Array):void
89+
{
90+
if(!value)
91+
{
92+
throw new ArgumentError();
93+
}
94+
var i:int = _displayList.length = value.length;
95+
while(i --)
96+
{
97+
_displayList[i] = value[i];
98+
}
99+
100+
if(_displayIndex >= 0)
101+
{
102+
_displayIndex = -1;
103+
changeDisplay(_displayIndex);
104+
}
105+
}
106+
107+
private function setDisplay(display:Object):void
108+
{
109+
if(_displayBridge.display)
110+
{
111+
_displayBridge.display = display;
112+
}
113+
else
114+
{
115+
_displayBridge.display = display;
116+
if(this._armature)
117+
{
118+
_displayBridge.addDisplay(this._armature.display);
119+
this._armature._slotsZOrderChanged = true;
120+
}
121+
}
122+
123+
updateChildArmatureAnimation();
124+
125+
if(!_isHideDisplay && _displayBridge.display)
126+
{
127+
_isDisplayOnStage = true;
128+
}
129+
else
130+
{
131+
_isDisplayOnStage = false;
132+
}
133+
}
134+
135+
/** @private */
136+
dragonBones_internal function changeDisplay(displayIndex:int):void
137+
{
138+
if(displayIndex < 0)
139+
{
140+
if(!_isHideDisplay)
141+
{
142+
_isHideDisplay = true;
143+
_displayBridge.removeDisplay();
144+
updateChildArmatureAnimation();
145+
}
146+
}
147+
else
148+
{
149+
if(_isHideDisplay)
150+
{
151+
_isHideDisplay = false;
152+
var changeShowState:Boolean = true;
153+
if(this._armature)
154+
{
155+
_displayBridge.addDisplay(this._armature.display);
156+
this._armature._slotsZOrderChanged = true;
157+
}
158+
}
159+
160+
var length:uint = _displayList.length;
161+
if(displayIndex >= length && length > 0)
162+
{
163+
displayIndex = length - 1;
164+
}
165+
if(_displayIndex != displayIndex)
166+
{
167+
_displayIndex = displayIndex;
168+
169+
var content:Object = _displayList[_displayIndex];
170+
if(content is Armature)
171+
{
172+
setDisplay((content as Armature).display);
173+
}
174+
else
175+
{
176+
setDisplay(content);
177+
}
178+
179+
if(_dislayDataList && _displayIndex <= _dislayDataList.length)
180+
{
181+
this._origin.copy(_dislayDataList[_displayIndex].transform);
182+
}
183+
}
184+
else if(changeShowState)
185+
{
186+
updateChildArmatureAnimation();
187+
}
188+
}
189+
190+
if(!_isHideDisplay && _displayBridge.display)
191+
{
192+
_isDisplayOnStage = true;
193+
}
194+
else
195+
{
196+
_isDisplayOnStage = false;
197+
}
198+
}
199+
200+
/**
201+
* @inheritDoc
202+
*/
203+
override public function set visible(value:Boolean):void
204+
{
205+
if(value != this._visible)
206+
{
207+
this._visible = value;
208+
updateVisible(this._visible);
209+
}
210+
}
211+
212+
/** @private */
213+
override dragonBones_internal function setArmature(value:Armature):void
214+
{
215+
super.setArmature(value);
216+
if(this._armature)
217+
{
218+
this._armature._slotsZOrderChanged = true;
219+
_displayBridge.addDisplay(this._armature.display);
220+
}
221+
else
222+
{
223+
_displayBridge.removeDisplay();
224+
}
225+
}
226+
227+
public function Slot(displayBrideg:IDisplayBridge)
228+
{
229+
super();
230+
_displayBridge = displayBrideg;
231+
_displayList = [];
232+
_displayIndex = -1;
233+
_scaleType = 1;
234+
235+
_originZOrder = 0;
236+
_tweenZorder = 0;
237+
_offsetZOrder = 0;
238+
239+
_isDisplayOnStage = false;
240+
_isHideDisplay = false;
241+
}
242+
243+
/**
244+
* @inheritDoc
245+
*/
246+
override public function dispose():void
247+
{
248+
if(!_displayBridge)
249+
{
250+
return;
251+
}
252+
super.dispose();
253+
254+
_displayBridge.dispose();
255+
_displayList.length = 0;
256+
257+
_displayBridge = null;
258+
_displayList = null;
259+
_dislayDataList = null;
260+
}
261+
262+
/** @private */
263+
override dragonBones_internal function update():void
264+
{
265+
super.update();
266+
267+
if(_isDisplayOnStage)
268+
{
269+
var pivotX:Number = _parent._tweenPivot.x;
270+
var pivotY:Number = _parent._tweenPivot.y;
271+
if(pivotX || pivotY)
272+
{
273+
var parentMatrix:Matrix = _parent._globalTransformMatrix;
274+
this._globalTransformMatrix.tx += parentMatrix.a * pivotX + parentMatrix.c * pivotY;
275+
this._globalTransformMatrix.ty += parentMatrix.b * pivotX + parentMatrix.d * pivotY;
276+
}
277+
278+
_displayBridge.updateTransform(this._globalTransformMatrix, this._global);
279+
}
280+
}
281+
282+
/** @private */
283+
dragonBones_internal function updateVisible(value:Boolean):void
284+
{
285+
_displayBridge.visible = this._parent.visible && this._visible && value;
286+
}
287+
288+
private function updateChildArmatureAnimation():void
289+
{
290+
var childArmature:Armature = this.childArmature;
291+
292+
if(childArmature)
293+
{
294+
if(_isHideDisplay)
295+
{
296+
childArmature.animation.stop();
297+
childArmature.animation._lastAnimationState = null;
298+
}
299+
else
300+
{
301+
if(
302+
this._armature &&
303+
this._armature.animation.lastAnimationState &&
304+
childArmature.animation.hasAnimation(this._armature.animation.lastAnimationState.name)
305+
)
306+
{
307+
childArmature.animation.gotoAndPlay(this._armature.animation.lastAnimationState.name);
308+
}
309+
else
310+
{
311+
childArmature.animation.play();
312+
}
313+
}
314+
}
315+
}
316+
317+
/**
318+
* Change all DisplayObject attached to this Bone instance.
319+
* @param displayList An array of valid DisplayObject to attach to this Bone.
320+
*/
321+
public function changeDisplayList(displayList:Array):void
322+
{
323+
this.displayList = displayList;
324+
}
325+
}
326+
}

0 commit comments

Comments
 (0)