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