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