1 /****************************************************************************
  2  Copyright (c) 2010-2012 cocos2d-x.org
  3 
  4  http://www.cocos2d-x.org
  5 
  6  Permission is hereby granted, free of charge, to any person obtaining a copy
  7  of this software and associated documentation files (the "Software"), to deal
  8  in the Software without restriction, including without limitation the rights
  9  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 10  copies of the Software, and to permit persons to whom the Software is
 11  furnished to do so, subject to the following conditions:
 12 
 13  The above copyright notice and this permission notice shall be included in
 14  all copies or substantial portions of the Software.
 15 
 16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 19  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 21  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 22  THE SOFTWARE.
 23  ****************************************************************************/
 24 /**
 25  * @namespace Base object for ccs.uiReader
 26  */
 27 ccs.uiReader = /** @lends ccs.uiReader# */{
 28     _filePath: "",
 29     _olderVersion: false,
 30     _fileDesignSizes: {},
 31 
 32     /**
 33      * get version
 34      * @param {String} str
 35      * @returns {Number}
 36      */
 37     getVersionInteger: function (str) {
 38         if(!str)
 39             return 0;
 40         var strVersion = str;
 41         var versionLength = strVersion.length;
 42         if (versionLength < 7) {
 43             return 0;
 44         }
 45         var pos = strVersion.indexOf(".");
 46         var t = strVersion.substr(0, pos);
 47         strVersion = strVersion.substr(pos + 1, versionLength - 1);
 48 
 49         pos = strVersion.indexOf(".");
 50         var h = strVersion.substr(0, pos);
 51         strVersion = strVersion.substr(pos + 1, versionLength - 1);
 52 
 53         pos = strVersion.indexOf(".");
 54         var te = strVersion.substr(0, pos);
 55         strVersion = strVersion.substr(pos + 1, versionLength - 1);
 56 
 57         pos = strVersion.indexOf(".");
 58         var s;
 59         if (pos == -1) {
 60             s = strVersion;
 61         } else {
 62             s = strVersion.substr(0, pos);
 63         }
 64 
 65         var it = parseInt(t);
 66         var ih = parseInt(h);
 67         var ite = parseInt(te);
 68         var is = parseInt(s);
 69 
 70         var version = it * 1000 + ih * 100 + ite * 10 + is;
 71         return version;
 72     },
 73 
 74     /**
 75      * store file designSize
 76      * @param {String} fileName
 77      * @param {cc.Size} size
 78      */
 79     storeFileDesignSize: function (fileName, size) {
 80         this._fileDesignSizes[fileName] = size;
 81     },
 82 
 83     /**
 84      *
 85      * @param {String} fileName
 86      * @returns {cc.Size}
 87      */
 88     getFileDesignSize: function (fileName) {
 89         return this._fileDesignSizes[fileName];
 90     },
 91 
 92     /**
 93      *  create uiWidget from a josn file that exported by cocostudio UI editor
 94      * @param {String} fileName
 95      * @returns {ccui.Widget}
 96      */
 97     widgetFromJsonFile: function (fileName) {
 98         var jsonDict = cc.loader.getRes(fileName);
 99         if(!jsonDict) throw "Please load the resource first : " + fileName;
100 
101         var tempFilePath = cc.path.dirname(fileName);
102         this._filePath = tempFilePath == "" ? tempFilePath : tempFilePath + "/";
103 
104         var fileVersion = jsonDict["version"];
105         var pReader, widget;
106         var versionInteger = this.getVersionInteger(fileVersion);
107         if (fileVersion) {
108             if (versionInteger < 250) {
109                 pReader = new ccs.WidgetPropertiesReader0250();
110                 widget = pReader.createWidget(jsonDict, this._filePath, fileName);
111             } else {
112                 pReader = new ccs.WidgetPropertiesReader0300();
113                 widget = pReader.createWidget(jsonDict, this._filePath, fileName);
114             }
115         } else {
116             pReader = new ccs.WidgetPropertiesReader0250();
117             widget = pReader.createWidget(jsonDict, this._filePath, fileName);
118         }
119 
120         if (!fileVersion || versionInteger < 250) {
121             this._olderVersion = true;
122         }
123         jsonDict = null;
124         return widget;
125     },
126 
127     /**
128      * Clear data: Release all actions.
129      */
130     clear: function () {
131         this._filePath = "";
132         this._olderVersion = false;
133         this._fileDesignSizes = {};
134     }
135 };
136 
137 
138 ccs.WidgetPropertiesReader = ccs.Class.extend({
139     _filePath: "",
140     createWidget: function (jsonDict, fullPath, fileName) {
141     },
142     widgetFromJsonDictionary: function (data) {
143     }
144 });
145 ccs.WidgetPropertiesReader0250 = ccs.WidgetPropertiesReader.extend({
146     createWidget: function (jsonDict, fullPath, fileName) {
147         this._filePath = fullPath == "" ? fullPath : cc.path.join(fullPath, "/");
148         var textures = jsonDict["textures"];
149         for (var i = 0; i < textures.length; i++) {
150             var file = textures[i];
151             var tp = fullPath;
152             tp += file;
153             cc.spriteFrameCache.addSpriteFrames(tp);
154         }
155         var fileDesignWidth = jsonDict["designWidth"];
156         var fileDesignHeight = jsonDict["designHeight"];
157         if (fileDesignWidth <= 0 || fileDesignHeight <= 0) {
158             cc.log("Read design size error!");
159             var winSize = cc.director.getWinSize();
160             ccs.uiReader.storeFileDesignSize(fileName, winSize);
161         }
162         else {
163             ccs.uiReader.storeFileDesignSize(fileName, cc.size(fileDesignWidth, fileDesignHeight));
164         }
165         var widgetTree = jsonDict["widgetTree"];
166         var widget = this.widgetFromJsonDictionary(widgetTree);
167 
168         var size = widget.getContentSize();
169         if (size.width == 0 && size.height == 0) {
170             widget.setSize(cc.size(fileDesignWidth, fileDesignHeight));
171         }
172 
173         var actions = jsonDict["animation"];
174         var rootWidget = widget;
175         ccs.actionManager.initWithDictionary(fileName, actions, rootWidget);
176 
177         widgetTree = null;
178         actions = null;
179         return widget;
180     },
181     widgetFromJsonDictionary: function (data) {
182         var widget = null;
183         var classname = data["classname"];
184         var uiOptions = data["options"];
185         if (classname == "Button") {
186             widget = ccui.Button.create();
187             this.setPropsForButtonFromJsonDictionary(widget, uiOptions);
188         }
189         else if (classname == "CheckBox") {
190             widget = ccui.CheckBox.create();
191             this.setPropsForCheckBoxFromJsonDictionary(widget, uiOptions);
192         }
193         else if (classname == "Label") {
194             widget = ccui.Text.create();
195             this.setPropsForLabelFromJsonDictionary(widget, uiOptions);
196         }
197         else if (classname == "LabelAtlas") {
198             widget = ccui.TextAtlas.create();
199             this.setPropsForLabelAtlasFromJsonDictionary(widget, uiOptions);
200         }
201         else if (classname == "LoadingBar") {
202             widget = ccui.LoadingBar.create();
203             this.setPropsForLoadingBarFromJsonDictionary(widget, uiOptions);
204         } else if (classname == "ScrollView") {
205             widget = ccui.ScrollView.create();
206             this.setPropsForScrollViewFromJsonDictionary(widget, uiOptions);
207         }
208         else if (classname == "TextArea") {
209             widget = ccui.Text.create();
210             this.setPropsForLabelFromJsonDictionary(widget, uiOptions);
211         }
212         else if (classname == "TextButton") {
213             widget = ccui.Button.create();
214             this.setPropsForButtonFromJsonDictionary(widget, uiOptions);
215         }
216         else if (classname == "TextField") {
217             widget = ccui.TextField.create();
218             this.setPropsForTextFieldFromJsonDictionary(widget, uiOptions);
219         }
220         else if (classname == "ImageView") {
221             widget = ccui.ImageView.create();
222             this.setPropsForImageViewFromJsonDictionary(widget, uiOptions);
223         }
224         else if (classname == "Panel") {
225             widget = ccui.Layout.create();
226             this.setPropsForLayoutFromJsonDictionary(widget, uiOptions);
227         }
228         else if (classname == "Slider") {
229             widget = ccui.Slider.create();
230             this.setPropsForSliderFromJsonDictionary(widget, uiOptions);
231         }
232         else if (classname == "LabelBMFont") {
233             widget = ccui.TextBMFont.create();
234             this.setPropsForLabelBMFontFromJsonDictionary(widget, uiOptions);
235         }
236         else if (classname == "DragPanel") {
237             widget = ccui.ScrollView.create();
238             this.setPropsForScrollViewFromJsonDictionary(widget, uiOptions);
239         }
240         var children = data["children"];
241         for (var i = 0; i < children.length; i++) {
242             var subData = children[i];
243             var child = this.widgetFromJsonDictionary(subData);
244             if (child) {
245                 widget.addChild(child);
246             }
247             subData = null;
248         }
249 
250         uiOptions = null;
251         return widget;
252     },
253 
254 
255     setPropsForWidgetFromJsonDictionary: function (widget, options) {
256         if (options["ignoreSize"] !== undefined) {
257             widget.ignoreContentAdaptWithSize(options["ignoreSize"]);
258         }
259 
260         var w = options["width"];
261         var h = options["height"];
262         widget.setSize(cc.size(w, h));
263 
264         widget.setTag(options["tag"]);
265         widget.setActionTag(options["actiontag"]);
266         widget.setTouchEnabled(options["touchAble"]);
267         var name = options["name"];
268         var widgetName = name ? name : "default";
269         widget.setName(widgetName);
270         var x = options["x"];
271         var y = options["y"];
272         widget.setPosition(x, y);
273         if (options["scaleX"] !== undefined) {
274             widget.setScaleX(options["scaleX"]);
275         }
276         if (options["scaleY"] !== undefined) {
277             widget.setScaleY(options["scaleY"]);
278         }
279         if (options["rotation"] !== undefined) {
280             widget.setRotation(options["rotation"]);
281         }
282         if (options["visible"] !== undefined) {
283             widget.setVisible(options["visible"]);
284         }
285 
286         var z = options["ZOrder"];
287         widget.setLocalZOrder(z);
288     },
289 
290     setColorPropsForWidgetFromJsonDictionary: function (widget, options) {
291         if (options["opacity"] !== undefined) {
292             widget.setOpacity(options["opacity"]);
293         }
294         var colorR = options["colorR"] !== undefined ? options["colorR"] : 255;
295         var colorG = options["colorG"] !== undefined ? options["colorG"] : 255;
296         var colorB = options["colorB"] !== undefined ? options["colorB"] : 255;
297         widget.setColor(cc.color(colorR, colorG, colorB));
298         var apx = options["anchorPointX"] !== undefined ? options["anchorPointX"] : ((widget.getWidgetType() == ccui.Widget.TYPE_WIDGET) ? 0.5 : 0);
299         var apy = options["anchorPointY"] !== undefined ? options["anchorPointY"] : ((widget.getWidgetType() == ccui.Widget.TYPE_WIDGET) ? 0.5 : 0);
300         widget.setAnchorPoint(apx, apy);
301         var flipX = options["flipX"];
302         var flipY = options["flipY"];
303         widget.setFlippedX(flipX);
304         widget.setFlippedY(flipY);
305     },
306 
307     setPropsForButtonFromJsonDictionary: function (widget, options) {
308         this.setPropsForWidgetFromJsonDictionary(widget, options);
309         var button = widget;
310         var scale9Enable = options["scale9Enable"];
311         button.setScale9Enabled(scale9Enable);
312 
313         var normalFileName = options["normal"];
314         var pressedFileName = options["pressed"];
315         var disabledFileName = options["disabled"];
316 
317         var normalFileName_tp = normalFileName ? this._filePath + normalFileName : null;
318         var pressedFileName_tp = pressedFileName ? this._filePath + pressedFileName : null;
319         var disabledFileName_tp = disabledFileName ? this._filePath + disabledFileName : null;
320         var useMergedTexture = options["useMergedTexture"];
321         if (scale9Enable) {
322             var cx = options["capInsetsX"];
323             var cy = options["capInsetsY"];
324             var cw = options["capInsetsWidth"];
325             var ch = options["capInsetsHeight"];
326 
327             if (useMergedTexture) {
328                 button.loadTextures(normalFileName, pressedFileName, disabledFileName, ccui.Widget.PLIST_TEXTURE);
329             }
330             else {
331                 button.loadTextures(normalFileName_tp, pressedFileName_tp, disabledFileName_tp);
332             }
333             //button.setCapInsets(cc.rect(cx, cy, cw, ch));
334             if (options["scale9Width"] !== undefined && options["scale9Height"] !== undefined) {
335                 var swf = options["scale9Width"];
336                 var shf = options["scale9Height"];
337                 button.setSize(cc.size(swf, shf));
338             }
339         }
340         else {
341             if (useMergedTexture) {
342                 button.loadTextures(normalFileName, pressedFileName, disabledFileName, ccui.Widget.PLIST_TEXTURE);
343             }
344             else {
345                 button.loadTextures(normalFileName_tp, pressedFileName_tp, disabledFileName_tp);
346             }
347         }
348         if (options["text"] !== undefined) {
349             var text = options["text"] || "";
350             if (text)
351                 button.setTitleText(text);
352         }
353         if (options["fontSize"] !== undefined) {
354             button.setTitleFontSize(options["fontSize"]);
355         }
356         if (options["fontName"] !== undefined) {
357             button.setTitleFontName(options["fontName"]);
358         }
359         var cr = options["textColorR"] !== undefined ? options["textColorR"] : 255;
360         var cg = options["textColorG"] !== undefined ? options["textColorG"] : 255;
361         var cb = options["textColorB"] !== undefined ? options["textColorB"] : 255;
362         var tc = cc.color(cr, cg, cb);
363         button.setTitleColor(tc);
364         this.setColorPropsForWidgetFromJsonDictionary(widget, options);
365     },
366 
367     setPropsForCheckBoxFromJsonDictionary: function (widget, options) {
368         this.setPropsForWidgetFromJsonDictionary(widget, options);
369         var checkBox = widget;
370         var backGroundFileName = options["backGroundBox"];
371         var backGroundSelectedFileName = options["backGroundBoxSelected"];
372         var frontCrossFileName = options["frontCross"];
373         var backGroundDisabledFileName = options["backGroundBoxDisabled"];
374         var frontCrossDisabledFileName = options["frontCrossDisabled"];
375 
376         var locFilePath = this._filePath;
377 
378         var backGroundFileName_tp = backGroundFileName ? locFilePath + backGroundFileName : null;
379         var backGroundSelectedFileName_tp = backGroundSelectedFileName ? locFilePath + backGroundSelectedFileName : null;
380         var frontCrossFileName_tp = frontCrossFileName ? locFilePath + frontCrossFileName : null;
381         var backGroundDisabledFileName_tp = backGroundDisabledFileName ? locFilePath + backGroundDisabledFileName : null;
382         var frontCrossDisabledFileName_tp = frontCrossDisabledFileName ? locFilePath + frontCrossDisabledFileName : null;
383         var useMergedTexture = options["useMergedTexture"];
384 
385         if (useMergedTexture) {
386             checkBox.loadTextures(backGroundFileName, backGroundSelectedFileName, frontCrossFileName, backGroundDisabledFileName, frontCrossDisabledFileName, ccui.Widget.PLIST_TEXTURE);
387         }
388         else {
389             checkBox.loadTextures(backGroundFileName_tp, backGroundSelectedFileName_tp, frontCrossFileName_tp, backGroundDisabledFileName_tp, frontCrossDisabledFileName_tp);
390         }
391 
392         checkBox.setSelectedState(options["selectedState"] || false);
393         this.setColorPropsForWidgetFromJsonDictionary(widget, options);
394     },
395 
396     setPropsForImageViewFromJsonDictionary: function (widget, options) {
397         this.setPropsForWidgetFromJsonDictionary(widget, options);
398 
399         var imageView = widget;
400         var imageFileName = options["fileName"];
401         var scale9Enable = options["scale9Enable"] || false;
402         imageView.setScale9Enabled(scale9Enable);
403 
404         var tp_i = this._filePath;
405         var imageFileName_tp = null;
406         if (imageFileName) {
407             imageFileName_tp = tp_i + imageFileName;
408         }
409 
410         var useMergedTexture = options["useMergedTexture"];
411         if (scale9Enable) {
412             if (useMergedTexture) {
413                 imageView.loadTexture(imageFileName, ccui.Widget.PLIST_TEXTURE);
414             }
415             else {
416                 imageView.loadTexture(imageFileName_tp);
417             }
418 
419             if (options["scale9Width"] !== undefined && options["scale9Height"] !== undefined) {
420                 var swf = options["scale9Width"];
421                 var shf = options["scale9Height"];
422                 imageView.setSize(cc.size(swf, shf));
423             }
424 
425             var cx = options["capInsetsX"];
426             var cy = options["capInsetsY"];
427             var cw = options["capInsetsWidth"];
428             var ch = options["capInsetsHeight"];
429             imageView.setCapInsets(cc.rect(cx, cy, cw, ch));
430 
431         }
432         else {
433             if (useMergedTexture) {
434                 imageView.loadTexture(imageFileName, ccui.Widget.PLIST_TEXTURE);
435             }
436             else {
437                 imageView.loadTexture(imageFileName_tp);
438             }
439         }
440         this.setColorPropsForWidgetFromJsonDictionary(widget, options);
441     },
442 
443     setPropsForLabelFromJsonDictionary: function (widget, options) {
444         this.setPropsForWidgetFromJsonDictionary(widget, options);
445         var label = widget;
446         var touchScaleChangeAble = options["touchScaleEnable"];
447         label.setTouchScaleChangeEnabled(touchScaleChangeAble);
448         var text = options["text"];
449         label.setText(text);
450         if (options["fontSize"] !== undefined) {
451             label.setFontSize(options["fontSize"]);
452         }
453         if (options["fontName"] !== undefined) {
454             label.setFontName(options["fontName"]);
455         }
456         if (options["areaWidth"] !== undefined && options["areaHeight"] !== undefined) {
457             var size = cc.size(options["areaWidth"], options["areaHeight"]);
458             label.setTextAreaSize(size);
459         }
460         if (options["hAlignment"]) {
461             label.setTextHorizontalAlignment(options["hAlignment"]);
462         }
463         if (options["vAlignment"]) {
464             label.setTextVerticalAlignment(options["vAlignment"]);
465         }
466         this.setColorPropsForWidgetFromJsonDictionary(widget, options);
467     },
468 
469     setPropsForLabelAtlasFromJsonDictionary: function (widget, options) {
470         this.setPropsForWidgetFromJsonDictionary(widget, options);
471         var labelAtlas = widget;
472         var sv = (options["stringValue"] !== undefined);
473         var cmf = (options["charMapFile"] !== undefined);
474         var iw = (options["itemWidth"] !== undefined);
475         var ih = (options["itemHeight"] !== undefined);
476         var scm = (options["startCharMap"] !== undefined);
477         if (sv && cmf && iw && ih && scm && options["charMapFile"]) {
478             var cmft = options["charMapFile"];
479             var cmf_tp = this._filePath + cmft;
480 
481             labelAtlas.setProperty(options["stringValue"], cmf_tp, options["itemWidth"], options["itemHeight"], options["startCharMap"]);
482         }
483         this.setColorPropsForWidgetFromJsonDictionary(widget, options);
484     },
485 
486     setPropsForLayoutFromJsonDictionary: function (widget, options) {
487         this.setPropsForWidgetFromJsonDictionary(widget, options);
488         var containerWidget = widget;
489         if (!(containerWidget instanceof ccui.ScrollView) && !(containerWidget instanceof ccui.ListView)) {
490             containerWidget.setClippingEnabled(options["clipAble"]);
491         }
492         var panel = widget;
493         var backGroundScale9Enable = options["backGroundScale9Enable"];
494         panel.setBackGroundImageScale9Enabled(backGroundScale9Enable);
495         var cr = options["bgColorR"];
496         var cg = options["bgColorG"];
497         var cb = options["bgColorB"];
498 
499         var scr = options["bgStartColorR"];
500         var scg = options["bgStartColorG"];
501         var scb = options["bgStartColorB"];
502 
503         var ecr = options["bgEndColorR"];
504         var ecg = options["bgEndColorG"];
505         var ecb = options["bgEndColorB"];
506 
507         var bgcv1 = options["vectorX"];
508         var bgcv2 = options["vectorY"];
509         panel.setBackGroundColorVector(cc.p(bgcv1, bgcv2));
510 
511         var co = options["bgColorOpacity"];
512 
513         var colorType = options["colorType"];
514         panel.setBackGroundColorType(colorType);
515         panel.setBackGroundColor(cc.color(scr, scg, scb), cc.color(ecr, ecg, ecb));
516         panel.setBackGroundColor(cc.color(cr, cg, cb));
517         panel.setBackGroundColorOpacity(co);
518 
519         var imageFileName = options["backGroundImage"];
520         var imageFileName_tp = imageFileName ? this._filePath + imageFileName : null;
521         var useMergedTexture = options["useMergedTexture"];
522         if (useMergedTexture) {
523             panel.setBackGroundImage(imageFileName, ccui.Widget.PLIST_TEXTURE);
524         }
525         else {
526             panel.setBackGroundImage(imageFileName_tp);
527         }
528         if (backGroundScale9Enable) {
529             var cx = options["capInsetsX"];
530             var cy = options["capInsetsY"];
531             var cw = options["capInsetsWidth"];
532             var ch = options["capInsetsHeight"];
533             panel.setBackGroundImageCapInsets(cc.rect(cx, cy, cw, ch));
534         }
535         this.setColorPropsForWidgetFromJsonDictionary(widget, options);
536     },
537 
538 
539     setPropsForScrollViewFromJsonDictionary: function (widget, options) {
540         this.setPropsForLayoutFromJsonDictionary(widget, options);
541         var scrollView = widget;
542         var innerWidth = options["innerWidth"];
543         var innerHeight = options["innerHeight"];
544         scrollView.setInnerContainerSize(cc.size(innerWidth, innerHeight));
545         var direction = options["direction"];
546         scrollView.setDirection(direction);
547         scrollView.setBounceEnabled(options["bounceEnable"]);
548         this.setColorPropsForWidgetFromJsonDictionary(widget, options);
549     },
550 
551     setPropsForContainerWidgetFromJsonDictionary: function (widget, options) {
552         this.setPropsForWidgetFromJsonDictionary(widget, options);
553         var containerWidget = widget;
554         if (containerWidget instanceof ccui.ScrollView ||
555             containerWidget instanceof ccui.ListView) {
556             containerWidget.setClippingEnabled(options["clipAble"]);
557         }
558         this.setColorPropsForWidgetFromJsonDictionary(widget, options);
559     },
560 
561     setPropsForSliderFromJsonDictionary: function (widget, options) {
562 
563         this.setPropsForWidgetFromJsonDictionary(widget, options);
564         var slider = widget;
565 
566         var barTextureScale9Enable = options["barTextureScale9Enable"] || false;
567         slider.setScale9Enabled(barTextureScale9Enable);
568         var barLength = options["length"];
569         var useMergedTexture = options["useMergedTexture"];
570         var bt = (options["barFileName"] !== undefined);
571         if (bt) {
572             if (barTextureScale9Enable) {
573                 var imageFileName = options["barFileName"];
574                 var imageFileName_tp = imageFileName ? this._filePath + imageFileName : null;
575                 if (useMergedTexture) {
576                     slider.loadBarTexture(imageFileName, ccui.Widget.PLIST_TEXTURE);
577                 }
578                 else {
579                     slider.loadBarTexture(imageFileName_tp);
580                 }
581                 slider.setSize(cc.size(barLength, slider.getContentSize().height));
582             }
583             else {
584                 var imageFileName = options["barFileName"];
585                 var imageFileName_tp = imageFileName ? this._filePath + imageFileName : null;
586                 if (useMergedTexture) {
587                     slider.loadBarTexture(imageFileName, ccui.Widget.PLIST_TEXTURE);
588                 }
589                 else {
590                     slider.loadBarTexture(imageFileName_tp);
591                 }
592             }
593         }
594 
595         var normalFileName = options["ballNormal"];
596         var pressedFileName = options["ballPressed"];
597         var disabledFileName = options["ballDisabled"];
598 
599         var normalFileName_tp = normalFileName ? this._filePath + normalFileName : null;
600         var pressedFileName_tp = pressedFileName ? this._filePath + pressedFileName : null;
601         var disabledFileName_tp = disabledFileName ? this._filePath + disabledFileName : null;
602         if (useMergedTexture) {
603             slider.loadSlidBallTextures(normalFileName, pressedFileName, disabledFileName, ccui.Widget.PLIST_TEXTURE);
604         }
605         else {
606             slider.loadSlidBallTextures(normalFileName_tp, pressedFileName_tp, disabledFileName_tp);
607         }
608         slider.setPercent(options["percent"]);
609 
610         var imageFileName = options["progressBarFileName"];
611         var imageFileName_tp = imageFileName ? this._filePath + imageFileName : null;
612         if (useMergedTexture) {
613             slider.loadProgressBarTexture(imageFileName, ccui.Widget.PLIST_TEXTURE);
614         }
615         else {
616             slider.loadProgressBarTexture(imageFileName_tp);
617         }
618         this.setColorPropsForWidgetFromJsonDictionary(widget, options);
619     },
620 
621     setPropsForTextAreaFromJsonDictionary: function (widget, options) {
622         this.setPropsForWidgetFromJsonDictionary(widget, options);
623         var textArea = widget;
624         textArea.setText(options["text"]);
625         if (options["fontSize"] !== undefined) {
626             textArea.setFontSize(options["fontSize"]);
627         }
628         var cr = options["colorR"]
629         var cg = options["colorG"];
630         var cb = options["colorB"];
631         textArea.setColor(cc.color(cr, cg, cb));
632         textArea.setFontName(options["fontName"]);
633         if (options["areaWidth"] !== undefined && options["areaHeight"] !== undefined) {
634             var size = cc.size(options["areaWidth"], options["areaHeight"]);
635             textArea.setTextAreaSize(size);
636         }
637         if (options["hAlignment"]) {
638             textArea.setTextHorizontalAlignment(options["hAlignment"]);
639         }
640         if (options["vAlignment"]) {
641             textArea.setTextVerticalAlignment(options["vAlignment"]);
642         }
643         this.setColorPropsForWidgetFromJsonDictionary(widget, options);
644     },
645 
646     setPropsForTextButtonFromJsonDictionary: function (widget, options) {
647         this.setPropsForButtonFromJsonDictionary(widget, options);
648 
649         var textButton = widget;
650         textButton.setTitleText(options["text"] || "");
651         var cri = options["textColorR"] !== undefined ? options["textColorR"] : 255;
652         var cgi = options["textColorG"] !== undefined ? options["textColorG"] : 255;
653         var cbi = options["textColorB"] !== undefined ? options["textColorB"] : 255;
654         textButton.setTitleColor(cc.color(cri, cgi, cbi));
655         if (options["fontSize"] !== undefined) {
656             textButton.setTitleFontSize(options["fontSize"]);
657         }
658         if (options["fontName"] !== undefined) {
659             textButton.setTitleFontName(options["fontName"]);
660         }
661         this.setColorPropsForWidgetFromJsonDictionary(widget, options);
662     },
663 
664     setPropsForTextFieldFromJsonDictionary: function (widget, options) {
665         this.setPropsForWidgetFromJsonDictionary(widget, options);
666         var textField = widget;
667         if (options["placeHolder"] !== undefined) {
668             textField.setPlaceHolder(options["placeHolder"]);
669         }
670         textField.setText(options["text"]);
671         if (options["fontSize"] !== undefined) {
672             textField.setFontSize(options["fontSize"]);
673         }
674         if (options["fontName"] !== undefined) {
675             textField.setFontName(options["fontName"]);
676         }
677         if (options["touchSizeWidth"] !== undefined && options["touchSizeHeight"] !== undefined) {
678             textField.setTouchSize(cc.size(options["touchSizeWidth"], options["touchSizeHeight"]));
679         }
680 
681         var dw = options["width"];
682         var dh = options["height"];
683         if (dw > 0.0 || dh > 0.0) {
684             //textField.setSize(CCSizeMake(dw, dh));
685         }
686         var maxLengthEnable = options["maxLengthEnable"];
687         textField.setMaxLengthEnabled(maxLengthEnable);
688 
689         if (maxLengthEnable) {
690             var maxLength = options["maxLength"];
691             textField.setMaxLength(maxLength);
692         }
693         var passwordEnable = options["passwordEnable"];
694         textField.setPasswordEnabled(passwordEnable);
695         if (passwordEnable) {
696             textField.setPasswordStyleText(options["passwordStyleText"]);
697         }
698         this.setColorPropsForWidgetFromJsonDictionary(widget, options);
699     },
700 
701     setPropsForLoadingBarFromJsonDictionary: function (widget, options) {
702 
703         this.setPropsForWidgetFromJsonDictionary(widget, options);
704         var loadingBar = widget;
705         var useMergedTexture = options["useMergedTexture"];
706         var imageFileName = options["texture"];
707         var imageFileName_tp = imageFileName ? this._filePath + imageFileName : null;
708         if (useMergedTexture) {
709             loadingBar.loadTexture(imageFileName, ccui.Widget.PLIST_TEXTURE);
710         }
711         else {
712             loadingBar.loadTexture(imageFileName_tp);
713         }
714         loadingBar.setDirection(options["direction"]);
715         loadingBar.setPercent(options["percent"]);
716         this.setColorPropsForWidgetFromJsonDictionary(widget, options);
717     },
718 
719     setPropsForListViewFromJsonDictionary: function (widget, options) {
720         this.setPropsForLayoutFromJsonDictionary(widget, options);
721     },
722 
723     setPropsForPageViewFromJsonDictionary: function (widget, options) {
724         this.setPropsForLayoutFromJsonDictionary(widget, options);
725     },
726 
727     setPropsForLabelBMFontFromJsonDictionary: function (widget, options) {
728         this.setPropsForWidgetFromJsonDictionary(widget, options);
729         var labelBMFont = widget;
730         var cmft = options["fileName"];
731         var cmf_tp = this._filePath + cmft;
732         labelBMFont.setFntFile(cmf_tp);
733         var text = options["text"];
734         labelBMFont.setText(text);
735         this.setColorPropsForWidgetFromJsonDictionary(widget, options);
736     }
737 });
738 
739 ccs.WidgetPropertiesReader0300 = ccs.WidgetPropertiesReader.extend({
740     createWidget: function (jsonDict, fullPath, fileName) {
741         this._filePath = fullPath == "" ? fullPath : cc.path.join(fullPath, "/");
742         var textures = jsonDict["textures"];
743         for (var i = 0; i < textures.length; i++) {
744             var file = textures[i];
745             var tp = fullPath;
746             tp += file;
747             cc.spriteFrameCache.addSpriteFrames(tp);
748         }
749         var fileDesignWidth = jsonDict["designWidth"];
750         var fileDesignHeight = jsonDict["designHeight"];
751         if (fileDesignWidth <= 0 || fileDesignHeight <= 0) {
752             cc.log("Read design size error!");
753             var winSize = cc.director.getWinSize();
754             ccs.uiReader.storeFileDesignSize(fileName, winSize);
755         }
756         else {
757             ccs.uiReader.storeFileDesignSize(fileName, cc.size(fileDesignWidth, fileDesignHeight));
758         }
759         var widgetTree = jsonDict["widgetTree"];
760         var widget = this.widgetFromJsonDictionary(widgetTree);
761 
762         var size = widget.getContentSize();
763         if (size.width == 0 && size.height == 0) {
764             widget.setSize(cc.size(fileDesignWidth, fileDesignHeight));
765         }
766 
767         var actions = jsonDict["animation"];
768         var rootWidget = widget;
769         ccs.actionManager.initWithDictionary(fileName, actions, rootWidget);
770 
771         widgetTree = null;
772         actions = null;
773         return widget;
774     },
775     widgetFromJsonDictionary: function (data) {
776         var widget = null;
777         var classname = data["classname"];
778         var uiOptions = data["options"];
779         if (classname == "Button") {
780             widget = ccui.Button.create();
781             this.setPropsForButtonFromJsonDictionary(widget, uiOptions);
782         }
783         else if (classname == "CheckBox") {
784             widget = ccui.CheckBox.create();
785             this.setPropsForCheckBoxFromJsonDictionary(widget, uiOptions);
786         }
787         else if (classname == "Label") {
788             widget = ccui.Text.create();
789             this.setPropsForLabelFromJsonDictionary(widget, uiOptions);
790         }
791         else if (classname == "LabelAtlas") {
792             widget = ccui.TextAtlas.create();
793             this.setPropsForLabelAtlasFromJsonDictionary(widget, uiOptions);
794         }
795         else if (classname == "LoadingBar") {
796             widget = ccui.LoadingBar.create();
797             this.setPropsForLoadingBarFromJsonDictionary(widget, uiOptions);
798         } else if (classname == "ScrollView") {
799             widget = ccui.ScrollView.create();
800             this.setPropsForScrollViewFromJsonDictionary(widget, uiOptions);
801         }
802         else if (classname == "TextArea") {
803             widget = ccui.Text.create();
804             this.setPropsForLabelFromJsonDictionary(widget, uiOptions);
805         }
806         else if (classname == "TextButton") {
807             widget = ccui.Button.create();
808             this.setPropsForButtonFromJsonDictionary(widget, uiOptions);
809         }
810         else if (classname == "TextField") {
811             widget = ccui.TextField.create();
812             this.setPropsForTextFieldFromJsonDictionary(widget, uiOptions);
813         }
814         else if (classname == "ImageView") {
815             widget = ccui.ImageView.create();
816             this.setPropsForImageViewFromJsonDictionary(widget, uiOptions);
817         }
818         else if (classname == "Panel") {
819             widget = ccui.Layout.create();
820             this.setPropsForLayoutFromJsonDictionary(widget, uiOptions);
821         }
822         else if (classname == "Slider") {
823             widget = ccui.Slider.create();
824             this.setPropsForSliderFromJsonDictionary(widget, uiOptions);
825         }
826         else if (classname == "LabelBMFont") {
827             widget = ccui.TextBMFont.create();
828             this.setPropsForLabelBMFontFromJsonDictionary(widget, uiOptions);
829         }
830         else if (classname == "DragPanel") {
831             widget = ccui.ScrollView.create();
832             this.setPropsForScrollViewFromJsonDictionary(widget, uiOptions);
833         }
834         else if (classname == "ListView") {
835             widget = ccui.ListView.create();
836             this.setPropsForListViewFromJsonDictionary(widget, uiOptions);
837         }
838         else if (classname == "PageView") {
839             widget = ccui.PageView.create();
840             this.setPropsForPageViewFromJsonDictionary(widget, uiOptions);
841         }
842         var children = data["children"];
843         for (var i = 0; i < children.length; i++) {
844             var subData = children[i];
845             var child = this.widgetFromJsonDictionary(subData);
846             if (child) {
847                 if (widget instanceof ccui.PageView && child instanceof ccui.Layout) {
848                     widget.addPage(child);
849                 } else if (widget instanceof ccui.ListView) {
850                     widget.pushBackCustomItem(child);
851                 } else {
852                     widget.addChild(child);
853                 }
854             }
855             subData = null;
856         }
857 
858         uiOptions = null;
859         return widget;
860     },
861 
862 
863     setPropsForWidgetFromJsonDictionary: function (widget, options) {
864         var name = options["name"];
865         var widgetName = name ? name : "default";
866         widget.setName(widgetName);
867 
868         if (options["ignoreSize"] !== undefined) {
869             widget.ignoreContentAdaptWithSize(options["ignoreSize"]);
870         }
871         widget.setSizeType(options["sizeType"]);
872         widget.setPositionType(options["positionType"]);
873 
874         widget.setSizePercent(cc.p(options["sizePercentX"], options["sizePercentY"]));
875         widget.setPositionPercent(cc.p(options["positionPercentX"], options["positionPercentY"]));
876 
877         var w = options["width"];
878         var h = options["height"];
879         widget.setSize(cc.size(w, h));
880 
881         widget.setTag(options["tag"]);
882         widget.setActionTag(options["actiontag"]);
883         widget.setTouchEnabled(options["touchAble"]);
884 
885         var x = options["x"];
886         var y = options["y"];
887         widget.setPosition(x, y);
888         if (options["scaleX"] !== undefined) {
889             widget.setScaleX(options["scaleX"]);
890         }
891         if (options["scaleY"] !== undefined) {
892             widget.setScaleY(options["scaleY"]);
893         }
894         if (options["rotation"] !== undefined) {
895             widget.setRotation(options["rotation"]);
896         }
897         if (options["visible"] !== undefined) {
898             widget.setVisible(options["visible"]);
899         }
900 
901         widget.setLocalZOrder(options["ZOrder"]);
902         var layoutParameterDic = options["layoutParameter"];
903         if (layoutParameterDic) {
904             var paramType = layoutParameterDic["type"];
905             var parameter;
906             switch (paramType) {
907                 case 0:
908                     break;
909                 case 1:
910                     parameter = ccui.LinearLayoutParameter.create();
911                     var gravity = layoutParameterDic["gravity"];
912                     parameter.setGravity(gravity);
913                     break;
914                 case 2:
915                     parameter = ccui.RelativeLayoutParameter.create();
916                     var relativeName = layoutParameterDic["relativeName"];
917                     parameter.setRelativeName(relativeName);
918                     var relativeToName = layoutParameterDic["relativeToName"];
919                     parameter.setRelativeToWidgetName(relativeToName);
920                     parameter.setAlign(layoutParameterDic["align"]);
921                     break;
922                 default:
923                     break;
924             }
925             var mgl = layoutParameterDic["marginLeft"];
926             var mgt = layoutParameterDic["marginTop"];
927             var mgr = layoutParameterDic["marginRight"];
928             var mgb = layoutParameterDic["marginDown"];
929             parameter.setMargin(new ccui.Margin(mgl, mgt, mgr, mgb));
930             widget.setLayoutParameter(parameter);
931         }
932     },
933 
934     setColorPropsForWidgetFromJsonDictionary: function (widget, options) {
935         if (options["opacity"] !== undefined) {
936             widget.setOpacity(options["opacity"]);
937         }
938         var colorR = options["colorR"] !== undefined ? options["colorR"] : 255;
939         var colorG = options["colorG"] !== undefined ? options["colorG"] : 255;
940         var colorB = options["colorB"] !== undefined ? options["colorB"] : 255;
941         widget.setColor(cc.color(colorR, colorG, colorB));
942         var apx = options["anchorPointX"] !== undefined ? options["anchorPointX"] : ((widget.getWidgetType() == ccui.Widget.TYPE_WIDGET) ? 0.5 : 0);
943         var apy = options["anchorPointY"] !== undefined ? options["anchorPointY"] : ((widget.getWidgetType() == ccui.Widget.TYPE_WIDGET) ? 0.5 : 0);
944         widget.setAnchorPoint(apx, apy);
945         var flipX = options["flipX"];
946         var flipY = options["flipY"];
947         widget.setFlippedX(flipX);
948         widget.setFlippedY(flipY);
949     },
950 
951     setPropsForButtonFromJsonDictionary: function (widget, options) {
952 
953 
954         this.setPropsForWidgetFromJsonDictionary(widget, options);
955         var button = widget;
956         var scale9Enable = options["scale9Enable"];
957         button.setScale9Enabled(scale9Enable);
958 
959         var normalDic = options["normalData"];
960         var normalType = normalDic["resourceType"];
961         switch (normalType) {
962             case 0:
963                 var normalFileName = normalDic["path"];
964                 var normalFileName_tp = normalFileName ? this._filePath + normalFileName : null;
965                 button.loadTextureNormal(normalFileName_tp);
966                 break;
967             case 1:
968                 var normalFileName = normalDic["path"];
969                 button.loadTextureNormal(normalFileName, ccui.Widget.PLIST_TEXTURE);
970                 break;
971             default:
972                 break;
973         }
974         normalDic = null;
975         var pressedDic = options["pressedData"];
976         var pressedType = pressedDic["resourceType"];
977         switch (pressedType) {
978             case 0:
979                 var pressedFileName = pressedDic["path"];
980                 var pressedFileName_tp = pressedFileName ? this._filePath + pressedFileName : null;
981                 button.loadTexturePressed(pressedFileName_tp);
982                 break;
983             case 1:
984                 var pressedFileName = pressedDic["path"];
985                 button.loadTexturePressed(pressedFileName, ccui.Widget.PLIST_TEXTURE);
986                 break;
987             default:
988                 break;
989         }
990         pressedDic = null;
991         var disabledDic = options["disabledData"];
992         var disabledType = disabledDic["resourceType"];
993         switch (disabledType) {
994             case 0:
995                 var disabledFileName = disabledDic["path"];
996                 var disabledFileName_tp = disabledFileName ? this._filePath + disabledFileName : null;
997                 button.loadTextureDisabled(disabledFileName_tp);
998                 break;
999             case 1:
1000                 var disabledFileName = disabledDic["path"];
1001                 button.loadTextureDisabled(disabledFileName, ccui.Widget.PLIST_TEXTURE);
1002                 break;
1003             default:
1004                 break;
1005         }
1006         disabledDic = null;
1007         if (scale9Enable) {
1008             var cx = options["capInsetsX"];
1009             var cy = options["capInsetsY"];
1010             var cw = options["capInsetsWidth"];
1011             var ch = options["capInsetsHeight"];
1012 
1013             button.setCapInsets(cc.rect(cx, cy, cw, ch));
1014             if (options["scale9Width"] !== undefined && options["scale9Height"] !== undefined) {
1015                 var swf = options["scale9Width"];
1016                 var shf = options["scale9Height"];
1017                 button.setSize(cc.size(swf, shf));
1018             }
1019         }
1020         if (options["text"] !== undefined) {
1021             var text = options["text"] || "";
1022             if (text)
1023                 button.setTitleText(text);
1024         }
1025         if (options["fontSize"] !== undefined) {
1026             button.setTitleFontSize(options["fontSize"]);
1027         }
1028         if (options["fontName"] !== undefined) {
1029             button.setTitleFontName(options["fontName"]);
1030         }
1031         var cr = options["textColorR"] !== undefined ? options["textColorR"] : 255;
1032         var cg = options["textColorG"] !== undefined ? options["textColorG"] : 255;
1033         var cb = options["textColorB"] !== undefined ? options["textColorB"] : 255;
1034         var tc = cc.color(cr, cg, cb);
1035         button.setTitleColor(tc);
1036         this.setColorPropsForWidgetFromJsonDictionary(widget, options);
1037     },
1038 
1039     setPropsForCheckBoxFromJsonDictionary: function (widget, options) {
1040         this.setPropsForWidgetFromJsonDictionary(widget, options);
1041         var checkBox = widget;
1042         var backGroundDic = options["backGroundBoxData"];
1043         var backGroundType = backGroundDic["resourceType"];
1044         switch (backGroundType) {
1045             case 0:
1046                 var backGroundFileName = backGroundDic["path"];
1047                 var backGroundFileName_tp = backGroundFileName ? this._filePath + backGroundFileName : null;
1048                 checkBox.loadTextureBackGround(backGroundFileName_tp);
1049                 break;
1050             case 1:
1051                 var backGroundFileName = backGroundDic["path"];
1052                 checkBox.loadTextureBackGround(backGroundFileName, ccui.Widget.PLIST_TEXTURE);
1053                 break;
1054             default:
1055                 break;
1056         }
1057         backGroundDic = null;
1058         var backGroundSelectedDic = options["backGroundBoxSelectedData"];
1059         var backGroundSelectedType = backGroundSelectedDic["resourceType"];
1060         switch (backGroundSelectedType) {
1061             case 0:
1062                 var backGroundSelectedFileName = backGroundSelectedDic["path"];
1063                 var backGroundSelectedFileName_tp = backGroundSelectedFileName ? this._filePath + backGroundSelectedFileName : null;
1064                 checkBox.loadTextureBackGroundSelected(backGroundSelectedFileName_tp);
1065                 break;
1066             case 1:
1067                 var backGroundSelectedFileName = backGroundSelectedDic["path"];
1068                 checkBox.loadTextureBackGroundSelected(backGroundSelectedFileName, ccui.Widget.PLIST_TEXTURE);
1069                 break;
1070             default:
1071                 break;
1072         }
1073         backGroundSelectedDic = null;
1074 
1075         var frontCrossDic = options["frontCrossData"];
1076         var frontCrossType = frontCrossDic["resourceType"];
1077         switch (frontCrossType) {
1078             case 0:
1079                 var frontCrossFileName = frontCrossDic["path"];
1080                 var frontCrossFileName_tp = frontCrossFileName ? this._filePath + frontCrossFileName : null;
1081                 checkBox.loadTextureFrontCross(frontCrossFileName_tp);
1082                 break;
1083             case 1:
1084                 var frontCrossFileName = frontCrossDic["path"];
1085                 checkBox.loadTextureFrontCross(frontCrossFileName, ccui.Widget.PLIST_TEXTURE);
1086                 break;
1087             default:
1088                 break;
1089         }
1090         frontCrossDic = null;
1091 
1092         var backGroundDisabledDic = options["backGroundBoxDisabledData"];
1093         var backGroundDisabledType = backGroundDisabledDic["resourceType"];
1094         switch (backGroundDisabledType) {
1095             case 0:
1096                 var backGroundDisabledFileName = backGroundDisabledDic["path"];
1097                 var backGroundDisabledFileName_tp = backGroundDisabledFileName ? this._filePath + backGroundDisabledFileName : null;
1098                 checkBox.loadTextureBackGroundDisabled(backGroundDisabledFileName_tp);
1099                 break;
1100             case 1:
1101                 var backGroundDisabledFileName = backGroundDisabledDic["path"];
1102                 checkBox.loadTextureBackGroundDisabled(backGroundDisabledFileName, ccui.Widget.PLIST_TEXTURE);
1103                 break;
1104             default:
1105                 break;
1106         }
1107         backGroundDisabledDic = null;
1108 
1109         var frontCrossDisabledDic = options["frontCrossDisabledData"];
1110         var frontCrossDisabledType = frontCrossDisabledDic["resourceType"];
1111         switch (frontCrossDisabledType) {
1112             case 0:
1113                 var frontCrossDisabledFileName = options["path"];
1114                 var frontCrossDisabledFileName_tp = frontCrossDisabledFileName ? this._filePath + frontCrossDisabledFileName : null;
1115                 checkBox.loadTextureFrontCrossDisabled(frontCrossDisabledFileName_tp);
1116                 break;
1117             case 1:
1118                 var frontCrossDisabledFileName = options["path"];
1119                 checkBox.loadTextureFrontCrossDisabled(frontCrossDisabledFileName, ccui.Widget.PLIST_TEXTURE);
1120                 break;
1121             default:
1122                 break;
1123         }
1124         frontCrossDisabledDic = null;
1125 
1126         var selectedState = options["selectedState"] || false;
1127         widget.setSelectedState(selectedState);
1128         this.setColorPropsForWidgetFromJsonDictionary(widget, options);
1129     },
1130 
1131     setPropsForImageViewFromJsonDictionary: function (widget, options) {
1132         this.setPropsForWidgetFromJsonDictionary(widget, options);
1133 
1134         var imageView = widget;
1135 
1136         var imageFileNameDic = options["fileNameData"];
1137         var imageFileNameType = imageFileNameDic["resourceType"];
1138         switch (imageFileNameType) {
1139             case 0:
1140                 var tp_i = this._filePath;
1141                 var imageFileName = imageFileNameDic["path"];
1142                 var imageFileName_tp = null;
1143                 if (imageFileName) {
1144                     imageFileName_tp = tp_i + imageFileName;
1145                     imageView.loadTexture(imageFileName_tp);
1146                 }
1147                 break;
1148             case 1:
1149                 var imageFileName = imageFileNameDic["path"];
1150                 imageView.loadTexture(imageFileName, ccui.Widget.PLIST_TEXTURE);
1151                 break;
1152             default:
1153                 break;
1154         }
1155         imageFileNameDic = null;
1156 
1157         var scale9Enable = options["scale9Enable"] || false;
1158         imageView.setScale9Enabled(scale9Enable);
1159 
1160         if (scale9Enable) {
1161             if (options["scale9Width"] !== undefined && options["scale9Height"] !== undefined) {
1162                 var swf = options["scale9Width"];
1163                 var shf = options["scale9Height"];
1164                 imageView.setSize(cc.size(swf, shf));
1165             }
1166 
1167             var cx = options["capInsetsX"];
1168             var cy = options["capInsetsY"];
1169             var cw = options["capInsetsWidth"];
1170             var ch = options["capInsetsHeight"];
1171 
1172             imageView.setCapInsets(cc.rect(cx, cy, cw, ch));
1173 
1174         }
1175         this.setColorPropsForWidgetFromJsonDictionary(widget, options);
1176     },
1177 
1178     setPropsForLabelFromJsonDictionary: function (widget, options) {
1179         this.setPropsForWidgetFromJsonDictionary(widget, options);
1180         var label = widget;
1181         var touchScaleChangeAble = options["touchScaleEnable"];
1182         label.setTouchScaleChangeEnabled(touchScaleChangeAble);
1183         var text = options["text"];
1184         label.setText(text);
1185         if (options["fontSize"] !== undefined) {
1186             label.setFontSize(options["fontSize"]);
1187         }
1188         if (options["fontName"] !== undefined) {
1189             label.setFontName(options["fontName"]);
1190         }
1191         if (options["areaWidth"] !== undefined && options["areaHeight"] !== undefined) {
1192             var size = cc.size(options["areaWidth"], options["areaHeight"]);
1193             label.setTextAreaSize(size);
1194         }
1195         if (options["hAlignment"]) {
1196             label.setTextHorizontalAlignment(options["hAlignment"]);
1197         }
1198         if (options["vAlignment"]) {
1199             label.setTextVerticalAlignment(options["vAlignment"]);
1200         }
1201         this.setColorPropsForWidgetFromJsonDictionary(widget, options);
1202     },
1203 
1204     setPropsForLabelAtlasFromJsonDictionary: function (widget, options) {
1205         this.setPropsForWidgetFromJsonDictionary(widget, options);
1206         var labelAtlas = widget;
1207         var sv = (options["stringValue"] !== undefined);
1208         var cmf = (options["charMapFile"] !== undefined);
1209         var iw = (options["itemWidth"] !== undefined);
1210         var ih = (options["itemHeight"] !== undefined);
1211         var scm = (options["startCharMap"] !== undefined);
1212         if (sv && cmf && iw && ih && scm) {
1213 
1214             var cmftDic = options["charMapFileData"];
1215             var cmfType = cmftDic["resourceType"];
1216             switch (cmfType) {
1217                 case 0:
1218                     var cmfPath = cmftDic["path"];
1219                     var cmf_tp = this._filePath + cmfPath;
1220                     labelAtlas.setProperty(options["stringValue"], cmf_tp, options["itemWidth"], options["itemHeight"], options["startCharMap"]);
1221                     break;
1222                 case 1:
1223                     cc.log("Wrong res type of LabelAtlas!");
1224                     break;
1225                 default:
1226                     break;
1227             }
1228             cmftDic = null;
1229         }
1230         this.setColorPropsForWidgetFromJsonDictionary(widget, options);
1231     },
1232 
1233     setPropsForLayoutFromJsonDictionary: function (widget, options) {
1234         this.setPropsForWidgetFromJsonDictionary(widget, options);
1235         var panel = widget;
1236         if (!(panel instanceof ccui.ScrollView) && !(panel instanceof ccui.ListView)) {
1237             panel.setClippingEnabled(options["clipAble"]);
1238         }
1239         var backGroundScale9Enable = options["backGroundScale9Enable"];
1240         panel.setBackGroundImageScale9Enabled(backGroundScale9Enable);
1241         var cr = options["bgColorR"];
1242         var cg = options["bgColorG"];
1243         var cb = options["bgColorB"];
1244 
1245         var scr = options["bgStartColorR"];
1246         var scg = options["bgStartColorG"]
1247         var scb = options["bgStartColorB"];
1248 
1249         var ecr = options["bgEndColorR"];
1250         var ecg = options["bgEndColorG"];
1251         var ecb = options["bgEndColorB"];
1252 
1253         var bgcv1 = options["vectorX"];
1254         var bgcv2 = options["vectorY"];
1255         panel.setBackGroundColorVector(cc.p(bgcv1, bgcv2));
1256 
1257         var co = options["bgColorOpacity"];
1258 
1259         var colorType = options["colorType"];
1260         panel.setBackGroundColorType(colorType);
1261         panel.setBackGroundColor(cc.color(scr, scg, scb), cc.color(ecr, ecg, ecb));
1262         panel.setBackGroundColor(cc.color(cr, cg, cb));
1263         panel.setBackGroundColorOpacity(co);
1264 
1265 
1266         var imageFileNameDic = options["backGroundImageData"] || {};
1267         var imageFileNameType = imageFileNameDic["resourceType"];
1268         switch (imageFileNameType) {
1269             case 0:
1270                 var imageFileName = imageFileNameDic["path"];
1271                 var imageFileName_tp = imageFileName ? this._filePath + imageFileName : null;
1272                 panel.setBackGroundImage(imageFileName_tp);
1273                 break;
1274             case 1:
1275                 var imageFileName = imageFileNameDic["path"];
1276                 panel.setBackGroundImage(imageFileName, ccui.Widget.PLIST_TEXTURE);
1277                 break;
1278             default:
1279                 break;
1280         }
1281         imageFileNameDic = null;
1282 
1283         if (backGroundScale9Enable) {
1284             var cx = options["capInsetsX"];
1285             var cy = options["capInsetsY"];
1286             var cw = options["capInsetsWidth"];
1287             var ch = options["capInsetsHeight"];
1288             panel.setBackGroundImageCapInsets(cc.rect(cx, cy, cw, ch));
1289         }
1290         panel.setLayoutType(options["layoutType"]);
1291         this.setColorPropsForWidgetFromJsonDictionary(widget, options);
1292     },
1293 
1294 
1295     setPropsForScrollViewFromJsonDictionary: function (widget, options) {
1296         this.setPropsForLayoutFromJsonDictionary(widget, options);
1297         var scrollView = widget;
1298         var innerWidth = options["innerWidth"];
1299         var innerHeight = options["innerHeight"];
1300         scrollView.setInnerContainerSize(cc.size(innerWidth, innerHeight));
1301         var direction = options["direction"];
1302         scrollView.setDirection(direction);
1303         scrollView.setBounceEnabled(options["bounceEnable"]);
1304         this.setColorPropsForWidgetFromJsonDictionary(widget, options);
1305     },
1306 
1307     setPropsForSliderFromJsonDictionary: function (widget, options) {
1308         this.setPropsForWidgetFromJsonDictionary(widget, options);
1309         var slider = widget;
1310 
1311         var barTextureScale9Enable = options["barTextureScale9Enable"] || false;
1312         slider.setScale9Enabled(barTextureScale9Enable);
1313         var barLength = options["length"];
1314         var bt = (options["barFileName"] !== undefined);
1315         if (bt) {
1316             if (barTextureScale9Enable) {
1317                 var imageFileNameDic = options["barFileNameData"];
1318                 var imageFileType = imageFileNameDic["resourceType"];
1319                 switch (imageFileType) {
1320                     case 0:
1321                         var imageFileName = imageFileNameDic["path"];
1322                         var imageFileName_tp = imageFileName ? this._filePath + imageFileName : null;
1323                         slider.loadBarTexture(imageFileName_tp);
1324                         break;
1325                     case 1:
1326                         var imageFileName = imageFileNameDic["path"];
1327                         slider.loadBarTexture(imageFileName, ccui.Widget.PLIST_TEXTURE);
1328                         break;
1329                     default:
1330                         break;
1331                 }
1332 
1333                 slider.setSize(cc.size(barLength, slider.getContentSize().height));
1334                 imageFileNameDic = null;
1335             }
1336             else {
1337                 var imageFileNameDic = options["barFileNameData"];
1338                 var imageFileType = imageFileNameDic["resourceType"];
1339                 switch (imageFileType) {
1340                     case 0:
1341                         var imageFileName = imageFileNameDic["path"];
1342                         var imageFileName_tp = imageFileName ? this._filePath + imageFileName : null;
1343                         slider.loadBarTexture(imageFileName_tp);
1344                         break;
1345                     case 1:
1346                         var imageFileName = imageFileNameDic["path"];
1347                         slider.loadBarTexture(imageFileName, ccui.Widget.PLIST_TEXTURE);
1348                         break;
1349                     default:
1350                         break;
1351                 }
1352                 imageFileNameDic = null;
1353             }
1354         }
1355 
1356         var normalDic = options["ballNormalData"];
1357         var normalType = normalDic["resourceType"];
1358         switch (normalType) {
1359             case 0:
1360                 var normalFileName = normalDic["path"];
1361                 var normalFileName_tp = normalFileName ? this._filePath + normalFileName : null;
1362                 slider.loadSlidBallTextureNormal(normalFileName_tp);
1363                 break;
1364             case 1:
1365                 var normalFileName = normalDic["path"];
1366                 slider.loadSlidBallTextureNormal(normalFileName, ccui.Widget.PLIST_TEXTURE);
1367                 break;
1368             default:
1369                 break;
1370         }
1371         normalDic = null;
1372 
1373         var pressedDic = options["ballPressedData"];
1374         var pressedType = pressedDic["resourceType"];
1375         switch (pressedType) {
1376             case 0:
1377                 var pressedFileName = pressedDic["path"];
1378                 var pressedFileName_tp = pressedFileName ? this._filePath + pressedFileName : null;
1379                 slider.loadSlidBallTexturePressed(pressedFileName_tp);
1380                 break;
1381             case 1:
1382                 var pressedFileName = pressedDic["path"];
1383                 slider.loadSlidBallTexturePressed(pressedFileName, ccui.Widget.PLIST_TEXTURE);
1384                 break;
1385             default:
1386                 break;
1387         }
1388         pressedDic = null;
1389 
1390         var disabledDic = options["ballDisabledData"];
1391         var disabledType = disabledDic["resourceType"];
1392         switch (disabledType) {
1393             case 0:
1394                 var disabledFileName = disabledDic["path"];
1395                 var disabledFileName_tp = disabledFileName ? this._filePath + disabledFileName : null;
1396                 slider.loadSlidBallTextureDisabled(disabledFileName_tp);
1397                 break;
1398             case 1:
1399                 var disabledFileName = disabledDic["path"];
1400                 slider.loadSlidBallTextureDisabled(disabledFileName, ccui.Widget.PLIST_TEXTURE);
1401                 break;
1402             default:
1403                 break;
1404         }
1405         disabledDic = null;
1406 
1407         var progressBarDic = options["progressBarData"];
1408         var progressBarType = progressBarDic["resourceType"];
1409         switch (progressBarType) {
1410             case 0:
1411                 var imageFileName = progressBarDic["path"];
1412                 var imageFileName_tp = imageFileName ? this._filePath + imageFileName : null;
1413                 slider.loadProgressBarTexture(imageFileName_tp);
1414                 break;
1415             case 1:
1416                 var imageFileName = progressBarDic["path"];
1417                 slider.loadProgressBarTexture(imageFileName, ccui.Widget.PLIST_TEXTURE);
1418                 break;
1419             default:
1420                 break;
1421         }
1422         this.setColorPropsForWidgetFromJsonDictionary(widget, options);
1423 
1424         slider.setPercent(options["percent"]);
1425     },
1426 
1427     setPropsForTextAreaFromJsonDictionary: function (widget, options) {
1428         this.setPropsForWidgetFromJsonDictionary(widget, options);
1429         var textArea = widget;
1430         textArea.setText(options["text"]);
1431         if (options["fontSize"] !== undefined) {
1432             textArea.setFontSize(options["fontSize"]);
1433         }
1434         var cr = options["colorR"]
1435         var cg = options["colorG"];
1436         var cb = options["colorB"];
1437         textArea.setColor(cc.color(cr, cg, cb));
1438         textArea.setFontName(options["fontName"]);
1439         if (options["areaWidth"] !== undefined && options["areaHeight"] !== undefined) {
1440             var size = cc.size(options["areaWidth"], options["areaHeight"]);
1441             textArea.setTextAreaSize(size);
1442         }
1443         if (options["hAlignment"]) {
1444             textArea.setTextHorizontalAlignment(options["hAlignment"]);
1445         }
1446         if (options["vAlignment"]) {
1447             textArea.setTextVerticalAlignment(options["vAlignment"]);
1448         }
1449         this.setColorPropsForWidgetFromJsonDictionary(widget, options);
1450     },
1451 
1452     setPropsForTextButtonFromJsonDictionary: function (widget, options) {
1453         this.setPropsForButtonFromJsonDictionary(widget, options);
1454 
1455         var textButton = widget;
1456         textButton.setTitleText(options["text"] || "");
1457         var cri = options["textColorR"] !== undefined ? options["textColorR"] : 255;
1458         var cgi = options["textColorG"] !== undefined ? options["textColorG"] : 255;
1459         var cbi = options["textColorB"] !== undefined ? options["textColorB"] : 255;
1460         textButton.setTitleColor(cc.color(cri, cgi, cbi));
1461         if (options["fontSize"] !== undefined) {
1462             textButton.setTitleFontSize(options["fontSize"]);
1463         }
1464         if (options["fontName"] !== undefined) {
1465             textButton.setTitleFontName(options["fontName"]);
1466         }
1467         this.setColorPropsForWidgetFromJsonDictionary(widget, options);
1468     },
1469 
1470     setPropsForTextFieldFromJsonDictionary: function (widget, options) {
1471         this.setPropsForWidgetFromJsonDictionary(widget, options);
1472         var textField = widget;
1473         if (options["placeHolder"] !== undefined) {
1474             textField.setPlaceHolder(options["placeHolder"]);
1475         }
1476         textField.setText(options["text"]);
1477         if (options["fontSize"] !== undefined) {
1478             textField.setFontSize(options["fontSize"]);
1479         }
1480         if (options["fontName"] !== undefined) {
1481             textField.setFontName(options["fontName"]);
1482         }
1483         if (options["touchSizeWidth"] !== undefined && options["touchSizeHeight"] !== undefined) {
1484             textField.setTouchSize(cc.size(options["touchSizeWidth"], options["touchSizeHeight"]));
1485         }
1486 
1487         var dw = options["width"];
1488         var dh = options["height"];
1489         if (dw > 0.0 || dh > 0.0) {
1490             //textField.setSize(CCSizeMake(dw, dh));
1491         }
1492         var maxLengthEnable = options["maxLengthEnable"];
1493         textField.setMaxLengthEnabled(maxLengthEnable);
1494 
1495         if (maxLengthEnable) {
1496             var maxLength = options["maxLength"];
1497             textField.setMaxLength(maxLength);
1498         }
1499         var passwordEnable = options["passwordEnable"];
1500         textField.setPasswordEnabled(passwordEnable);
1501         if (passwordEnable) {
1502             textField.setPasswordStyleText(options["passwordStyleText"]);
1503         }
1504         this.setColorPropsForWidgetFromJsonDictionary(widget, options);
1505     },
1506 
1507     setPropsForLoadingBarFromJsonDictionary: function (widget, options) {
1508         this.setPropsForWidgetFromJsonDictionary(widget, options);
1509         var loadingBar = widget;
1510 
1511         var imageFileNameDic = options["textureData"];
1512         var imageFileNameType = imageFileNameDic["resourceType"];
1513         switch (imageFileNameType) {
1514             case 0:
1515                 var tp_i = this._filePath;
1516                 var imageFileName = imageFileNameDic["path"];
1517                 var imageFileName_tp = null;
1518                 if (imageFileName) {
1519                     imageFileName_tp = tp_i + imageFileName;
1520                     loadingBar.loadTexture(imageFileName_tp);
1521                 }
1522                 break;
1523             case 1:
1524                 var imageFileName = imageFileNameDic["path"];
1525                 loadingBar.loadTexture(imageFileName, ccui.Widget.PLIST_TEXTURE);
1526                 break;
1527             default:
1528                 break;
1529         }
1530         imageFileNameDic = null;
1531 
1532         var scale9Enable = options["scale9Enable"];
1533         loadingBar.setScale9Enabled(scale9Enable);
1534 
1535         if (scale9Enable) {
1536             var cx = options["capInsetsX"];
1537             var cy = options["capInsetsY"];
1538             var cw = options["capInsetsWidth"];
1539             var ch = options["capInsetsHeight"];
1540 
1541             loadingBar.setCapInsets(cc.rect(cx, cy, cw, ch));
1542 
1543             var width = options["width"];
1544             var height = options["height"];
1545             loadingBar.setSize(cc.size(width, height));
1546         }
1547 
1548         loadingBar.setDirection(options["direction"]);
1549         loadingBar.setPercent(options["percent"]);
1550         this.setColorPropsForWidgetFromJsonDictionary(widget, options);
1551 
1552     },
1553 
1554     setPropsForListViewFromJsonDictionary: function (widget, options) {
1555         this.setPropsForLayoutFromJsonDictionary(widget, options);
1556         var innerWidth = options["innerWidth"] || 0;
1557         var innerHeight = options["innerHeight"] || 0;
1558         widget.setInnerContainerSize(cc.size(innerWidth, innerHeight));
1559         widget.setDirection(options["direction"] || 0);
1560         widget.setGravity(options["gravity"] || 0);
1561         widget.setItemsMargin(options["itemMargin"] || 0);
1562     },
1563 
1564     setPropsForPageViewFromJsonDictionary: function (widget, options) {
1565         this.setPropsForLayoutFromJsonDictionary(widget, options);
1566     },
1567 
1568     setPropsForLabelBMFontFromJsonDictionary: function (widget, options) {
1569         this.setPropsForWidgetFromJsonDictionary(widget, options);
1570 
1571         var labelBMFont = widget;
1572 
1573         var cmftDic = options["fileNameData"];
1574         var cmfType = cmftDic["resourceType"];
1575         switch (cmfType) {
1576             case 0:
1577                 var cmfPath = cmftDic["path"];
1578                 var cmf_tp = this._filePath + cmfPath;
1579                 labelBMFont.setFntFile(cmf_tp);
1580                 break;
1581             case 1:
1582                 cc.log("Wrong res type of LabelAtlas!");
1583                 break;
1584             default:
1585                 break;
1586         }
1587         cmftDic = null;
1588 
1589         var text = options["text"];
1590         labelBMFont.setText(text);
1591 
1592         this.setColorPropsForWidgetFromJsonDictionary(widget, options);
1593     }
1594 });
1595