Skip to content

Commit e584dbb

Browse files
committed
Merge pull request #1559 from dingpinglv/develop
Fixed a bug of Cocostudio parser that widget doesn't set layoutComponent
2 parents 56e55c9 + d940196 commit e584dbb

File tree

2 files changed

+76
-79
lines changed

2 files changed

+76
-79
lines changed

frameworks/js-bindings/bindings/script/studio/parsers/timelineParser-2.x.js

Lines changed: 75 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@
209209
// WIDGET //
210210
////////////
211211

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

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

221221
var name = json["Name"];
222-
if(name)
222+
if (name)
223223
widget.setName(name);
224224

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

229229
var rotationSkewX = json["RotationSkewX"];
230-
if(rotationSkewX)
230+
if (rotationSkewX)
231231
widget.setRotationX(rotationSkewX);
232232

233233
var rotationSkewY = json["RotationSkewY"];
234-
if(rotationSkewY)
234+
if (rotationSkewY)
235235
widget.setRotationY(rotationSkewY);
236236

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

239239
var flipX = json["FlipX"];
240-
if(flipX)
240+
if (flipX)
241241
widget.setFlippedX(true);
242242

243243
var flipY = json["FlipY"];
244-
if(flipY)
244+
if (flipY)
245245
widget.setFlippedY(true);
246246

247247
var zOrder = json["zOrder"];
248-
if(zOrder != null)
248+
if (zOrder != null)
249249
widget.setLocalZOrder(zOrder);
250250

251251
//var visible = json["Visible"];
@@ -254,7 +254,7 @@
254254
widget.setVisible(visible);
255255

256256
var alpha = json["Alpha"];
257-
if(alpha != null)
257+
if (alpha != null)
258258
widget.setOpacity(alpha);
259259

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

267267
var callBackType = json["CallBackType"];
268-
if(callBackType != null)
268+
if (callBackType != null)
269269
widget.setCallbackType(callBackType);
270270

271271
var callBackName = json["CallBackName"];
272-
if(callBackName)
272+
if (callBackName)
273273
widget.setCallbackName(callBackName);
274274

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

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

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

291291
var color = json["CColor"];
292-
if(color != null)
292+
if (color != null)
293293
widget.setColor(getColor(color));
294294

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

356-
layoutComponent.setTopMargin(topMargin);
357-
layoutComponent.setBottomMargin(bottomMargin);
358-
layoutComponent.setLeftMargin(leftMargin);
359-
layoutComponent.setRightMargin(rightMargin);
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;
360352
}
353+
layoutComponent.setVerticalEdge(verticalEdgeType);
361354

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

364361
/**

0 commit comments

Comments
 (0)