Skip to content

Commit f1594e6

Browse files
committed
Merge pull request #2747 from dingpinglv/develop
Fixed a bug of Cocostudio parser that widget doesn't set layoutComponent
2 parents dfa6d6c + 9ba7709 commit f1594e6

File tree

1 file changed

+75
-78
lines changed

1 file changed

+75
-78
lines changed

extensions/cocostudio/loader/parsers/timelineParser-2.x.js

+75-78
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@
208208
// WIDGET //
209209
////////////
210210

211-
parser.widgetAttributes = function(widget, json){
211+
parser.widgetAttributes = function(widget, json) {
212212
widget.setCascadeColorEnabled(true);
213213
widget.setCascadeOpacityEnabled(true);
214214

@@ -218,33 +218,33 @@
218218
setContentSize(widget, json["Size"]);
219219

220220
var name = json["Name"];
221-
if(name)
221+
if (name)
222222
widget.setName(name);
223223

224224
var actionTag = json["ActionTag"] || 0;
225225
widget.setActionTag(actionTag);
226226
widget.setUserObject(new ccs.ActionTimelineData(actionTag));
227227

228228
var rotationSkewX = json["RotationSkewX"];
229-
if(rotationSkewX)
229+
if (rotationSkewX)
230230
widget.setRotationX(rotationSkewX);
231231

232232
var rotationSkewY = json["RotationSkewY"];
233-
if(rotationSkewY)
233+
if (rotationSkewY)
234234
widget.setRotationY(rotationSkewY);
235235

236236
//var rotation = json["Rotation"];
237237

238238
var flipX = json["FlipX"];
239-
if(flipX)
239+
if (flipX)
240240
widget.setFlippedX(true);
241241

242242
var flipY = json["FlipY"];
243-
if(flipY)
243+
if (flipY)
244244
widget.setFlippedY(true);
245245

246246
var zOrder = json["zOrder"];
247-
if(zOrder != null)
247+
if (zOrder != null)
248248
widget.setLocalZOrder(zOrder);
249249

250250
//var visible = json["Visible"];
@@ -253,7 +253,7 @@
253253
widget.setVisible(visible);
254254

255255
var alpha = json["Alpha"];
256-
if(alpha != null)
256+
if (alpha != null)
257257
widget.setOpacity(alpha);
258258

259259
widget.setTag(json["Tag"] || 0);
@@ -264,100 +264,97 @@
264264
// -- var frameEvent = json["FrameEvent"];
265265

266266
var callBackType = json["CallBackType"];
267-
if(callBackType != null)
267+
if (callBackType != null)
268268
widget.setCallbackType(callBackType);
269269

270270
var callBackName = json["CallBackName"];
271-
if(callBackName)
271+
if (callBackName)
272272
widget.setCallbackName(callBackName);
273273

274274
var position = json["Position"];
275-
if(position != null)
275+
if (position != null)
276276
widget.setPosition(position["X"] || 0, position["Y"] || 0);
277277

278278
var scale = json["Scale"];
279-
if(scale != null){
279+
if (scale != null) {
280280
var scaleX = getParam(scale["ScaleX"], 1);
281281
var scaleY = getParam(scale["ScaleY"], 1);
282282
widget.setScaleX(scaleX);
283283
widget.setScaleY(scaleY);
284284
}
285285

286286
var anchorPoint = json["AnchorPoint"];
287-
if(anchorPoint != null)
287+
if (anchorPoint != null)
288288
widget.setAnchorPoint(anchorPoint["ScaleX"] || 0, anchorPoint["ScaleY"] || 0);
289289

290290
var color = json["CColor"];
291-
if(color != null)
291+
if (color != null)
292292
widget.setColor(getColor(color));
293293

294-
if(widget instanceof ccui.Layout){
295-
var layoutComponent = ccui.LayoutComponent.bindLayoutComponent(widget);
296-
297-
var positionXPercentEnabled = json["PositionPercentXEnable"] || false;
298-
var positionYPercentEnabled = json["PositionPercentYEnable"] || false;
299-
var positionXPercent = 0,
300-
positionYPercent = 0,
301-
PrePosition = json["PrePosition"];
302-
if(PrePosition != null){
303-
positionXPercent = PrePosition["X"] || 0;
304-
positionYPercent = PrePosition["Y"] || 0;
305-
}
306-
var sizeXPercentEnable = json["PercentWidthEnable"] || false;
307-
var sizeYPercentEnable = json["PercentHeightEnable"] || false;
308-
var sizeXPercent = 0,
309-
sizeYPercent = 0,
310-
PreSize = json["PreSize"];
311-
if(PrePosition != null){
312-
sizeXPercent = PreSize["X"] || 0;
313-
sizeYPercent = PreSize["Y"] || 0;
314-
}
315-
var stretchHorizontalEnabled = json["StretchWidthEnable"] || false;
316-
var stretchVerticalEnabled = json["StretchHeightEnable"] || false;
317-
var horizontalEdge = json["HorizontalEdge"];// = ccui.LayoutComponent.horizontalEdge.LEFT;
318-
var verticalEdge = json["VerticalEdge"]; // = ccui.LayoutComponent.verticalEdge.TOP;
319-
var leftMargin = json["LeftMargin"] || 0;
320-
var rightMargin = json["RightMargin"] || 0;
321-
var topMargin = json["TopMargin"] || 0;
322-
var bottomMargin = json["BottomMargin"] || 0;
323-
324-
layoutComponent.setPositionPercentXEnabled(positionXPercentEnabled);
325-
layoutComponent.setPositionPercentYEnabled(positionYPercentEnabled);
326-
layoutComponent.setPositionPercentX(positionXPercent);
327-
layoutComponent.setPositionPercentY(positionYPercent);
328-
layoutComponent.setPercentWidthEnabled(sizeXPercentEnable);
329-
layoutComponent.setPercentHeightEnabled(sizeYPercentEnable);
330-
layoutComponent.setPercentWidth(sizeXPercent);
331-
layoutComponent.setPercentHeight(sizeYPercent);
332-
layoutComponent.setStretchWidthEnabled(stretchHorizontalEnabled);
333-
layoutComponent.setStretchHeightEnabled(stretchVerticalEnabled);
334-
335-
var horizontalEdgeType = ccui.LayoutComponent.horizontalEdge.NONE;
336-
if (horizontalEdge == "LeftEdge"){
337-
horizontalEdgeType = ccui.LayoutComponent.horizontalEdge.LEFT;
338-
}else if (horizontalEdge == "RightEdge"){
339-
horizontalEdgeType = ccui.LayoutComponent.horizontalEdge.RIGHT;
340-
}else if (horizontalEdge == "BothEdge"){
341-
horizontalEdgeType = ccui.LayoutComponent.horizontalEdge.CENTER;
342-
}
343-
layoutComponent.setHorizontalEdge(horizontalEdgeType);
344-
345-
var verticalEdgeType = ccui.LayoutComponent.verticalEdge.NONE;
346-
if (verticalEdge == "TopEdge"){
347-
verticalEdgeType = ccui.LayoutComponent.verticalEdge.TOP;
348-
}else if (verticalEdge == "BottomEdge"){
349-
verticalEdgeType = ccui.LayoutComponent.verticalEdge.BOTTOM;
350-
}else if (verticalEdge == "BothEdge"){
351-
verticalEdgeType = ccui.LayoutComponent.verticalEdge.CENTER;
352-
}
353-
layoutComponent.setVerticalEdge(verticalEdgeType);
294+
var layoutComponent = ccui.LayoutComponent.bindLayoutComponent(widget);
354295

355-
layoutComponent.setTopMargin(topMargin);
356-
layoutComponent.setBottomMargin(bottomMargin);
357-
layoutComponent.setLeftMargin(leftMargin);
358-
layoutComponent.setRightMargin(rightMargin);
296+
var positionXPercentEnabled = json["PositionPercentXEnable"] || false;
297+
var positionYPercentEnabled = json["PositionPercentYEnable"] || false;
298+
var positionXPercent = 0,
299+
positionYPercent = 0,
300+
PrePosition = json["PrePosition"];
301+
if (PrePosition != null) {
302+
positionXPercent = PrePosition["X"] || 0;
303+
positionYPercent = PrePosition["Y"] || 0;
304+
}
305+
var sizeXPercentEnable = json["PercentWidthEnable"] || false;
306+
var sizeYPercentEnable = json["PercentHeightEnable"] || false;
307+
var sizeXPercent = 0,
308+
sizeYPercent = 0,
309+
PreSize = json["PreSize"];
310+
if (PrePosition != null) {
311+
sizeXPercent = PreSize["X"] || 0;
312+
sizeYPercent = PreSize["Y"] || 0;
313+
}
314+
var stretchHorizontalEnabled = json["StretchWidthEnable"] || false;
315+
var stretchVerticalEnabled = json["StretchHeightEnable"] || false;
316+
var horizontalEdge = json["HorizontalEdge"];// = ccui.LayoutComponent.horizontalEdge.LEFT;
317+
var verticalEdge = json["VerticalEdge"]; // = ccui.LayoutComponent.verticalEdge.TOP;
318+
var leftMargin = json["LeftMargin"] || 0;
319+
var rightMargin = json["RightMargin"] || 0;
320+
var topMargin = json["TopMargin"] || 0;
321+
var bottomMargin = json["BottomMargin"] || 0;
322+
323+
layoutComponent.setPositionPercentXEnabled(positionXPercentEnabled);
324+
layoutComponent.setPositionPercentYEnabled(positionYPercentEnabled);
325+
layoutComponent.setPositionPercentX(positionXPercent);
326+
layoutComponent.setPositionPercentY(positionYPercent);
327+
layoutComponent.setPercentWidthEnabled(sizeXPercentEnable);
328+
layoutComponent.setPercentHeightEnabled(sizeYPercentEnable);
329+
layoutComponent.setPercentWidth(sizeXPercent);
330+
layoutComponent.setPercentHeight(sizeYPercent);
331+
layoutComponent.setStretchWidthEnabled(stretchHorizontalEnabled);
332+
layoutComponent.setStretchHeightEnabled(stretchVerticalEnabled);
333+
334+
var horizontalEdgeType = ccui.LayoutComponent.horizontalEdge.NONE;
335+
if (horizontalEdge == "LeftEdge") {
336+
horizontalEdgeType = ccui.LayoutComponent.horizontalEdge.LEFT;
337+
} else if (horizontalEdge == "RightEdge") {
338+
horizontalEdgeType = ccui.LayoutComponent.horizontalEdge.RIGHT;
339+
} else if (horizontalEdge == "BothEdge") {
340+
horizontalEdgeType = ccui.LayoutComponent.horizontalEdge.CENTER;
341+
}
342+
layoutComponent.setHorizontalEdge(horizontalEdgeType);
343+
344+
var verticalEdgeType = ccui.LayoutComponent.verticalEdge.NONE;
345+
if (verticalEdge == "TopEdge") {
346+
verticalEdgeType = ccui.LayoutComponent.verticalEdge.TOP;
347+
} else if (verticalEdge == "BottomEdge") {
348+
verticalEdgeType = ccui.LayoutComponent.verticalEdge.BOTTOM;
349+
} else if (verticalEdge == "BothEdge") {
350+
verticalEdgeType = ccui.LayoutComponent.verticalEdge.CENTER;
359351
}
352+
layoutComponent.setVerticalEdge(verticalEdgeType);
360353

354+
layoutComponent.setTopMargin(topMargin);
355+
layoutComponent.setBottomMargin(bottomMargin);
356+
layoutComponent.setLeftMargin(leftMargin);
357+
layoutComponent.setRightMargin(rightMargin);
361358
};
362359

363360
/**

0 commit comments

Comments
 (0)