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