1 /****************************************************************************
  2  Copyright (c) 2013-2014 Chukong Technologies Inc.
  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 
 26 /*
 27  This file is for compatibility compatibility with older versions of GUIReader and SceneReader
 28  todo: deprecated all
 29  */
 30 
 31 (function(){
 32 
 33     ccs.uiReader = {
 34 
 35         _fileDesignSizes: {},
 36 
 37         //@deprecated This function will be deprecated sooner or later please use ccs.load
 38         /**
 39          * Create CCUI Node
 40          * @param file
 41          * @returns {*}
 42          */
 43         widgetFromJsonFile: function(file){
 44             var json = cc.loader.getRes(file);
 45             if(json)
 46                 this._fileDesignSizes[file] = cc.size(json["designWidth"]||0, json["designHeight"]||0);
 47 
 48             var version = json["Version"] || json["version"];
 49             var versionNum = ccs.uiReader.getVersionInteger(version);
 50             if(!version || versionNum >= 1700){
 51                 cc.warn("Not supported file types, Please try use the ccs.load");
 52                 return null;
 53             }
 54             return ccs._load(file, "ccui");
 55         },
 56 
 57         //@deprecated This function will be deprecated sooner or later please use parser.registerParser
 58         /**
 59          * Register a custom Widget reader
 60          * @param classType
 61          * @param ins
 62          * @param object
 63          * @param callback
 64          * @deprecated This function will be deprecated sooner or later please use parser.registerParser
 65          */
 66         registerTypeAndCallBack: function(classType, ins, object, callback){
 67             var parser = ccs._load.getParser("ccui")["*"];
 68             var func = callback.bind(object);
 69             parser.registerParser(classType, function(options, resourcePath){
 70                 var widget = new ins();
 71                 var uiOptions = options["options"];
 72                 object.setPropsFromJsonDictionary && object.setPropsFromJsonDictionary(widget, uiOptions);
 73                 this.generalAttributes(widget, uiOptions);
 74                 var customProperty = uiOptions["customProperty"];
 75                 if(customProperty)
 76                     customProperty = JSON.parse(customProperty);
 77                 else
 78                     customProperty = {};
 79                 func(classType, widget, customProperty);
 80                 this.colorAttributes(widget, uiOptions);
 81                 this.anchorPointAttributes(widget, uiOptions);
 82                 this.parseChild.call(this, widget, options, resourcePath);
 83                 return widget;
 84             });
 85         },
 86 
 87         //@deprecated This function will be deprecated sooner or later
 88         /**
 89          * Gets the version number by version string.
 90          * @param {String} version version string.
 91          * @returns {Number}
 92          */
 93         getVersionInteger: function(version){
 94             if(!version || typeof version !== "string") return 0;
 95             var arr = version.split(".");
 96             if (arr.length !== 4)
 97                 return 0;
 98             var num = 0;
 99             arr.forEach(function(n, i){
100                 num += n * Math.pow(10, 3 - i);
101             });
102             return num;
103         },
104 
105         //@deprecated This function will be deprecated sooner or later
106         /**
107          * stores the designSize of UI file.
108          * @param {String} fileName
109          * @param {cc.Size} size
110          */
111         storeFileDesignSize: function (fileName, size) {
112             this._fileDesignSizes[fileName] = size;
113         },
114 
115         //@deprecated This function will be deprecated sooner or later
116         /**
117          * Gets the design size by filename.
118          * @param {String} fileName
119          * @returns {cc.Size}
120          */
121         getFileDesignSize: function (fileName) {
122             return this._fileDesignSizes[fileName];
123         },
124 
125         //@deprecated This function will be deprecated sooner or later
126         /**
127          * Returns the file path
128          * @returns {string}
129          */
130         getFilePath: function(){
131             return this._filePath;
132         },
133 
134         //@deprecated This function will be deprecated sooner or later
135         setFilePath: function(path){
136             this._filePath = path;
137         },
138 
139         //@deprecated This function will be deprecated sooner or later
140         /**
141          * Returns the parsed object map. (analytic function)
142          * @returns {Object}
143          */
144         getParseObjectMap: function(){
145             return ccs._load.getParser("ccui")["*"]["parsers"];
146         },
147 
148         //@deprecated This function will be deprecated sooner or later
149         /**
150          * Returns the parsed callback map. (analytic function)
151          * @returns {*}
152          */
153         getParseCallBackMap: function(){
154             return ccs._load.getParser("ccui")["*"]["parsers"];
155         },
156 
157         //@deprecated This function will be deprecated sooner or later
158         clear: function(){}
159     };
160 
161     var parser = ccs._load.getParser("ccui")["*"];
162     ccs.imageViewReader  = {setPropsFromJsonDictionary: parser.ImageViewAttributes};
163     ccs.buttonReader     = {setPropsFromJsonDictionary: parser.ButtonAttributes};
164     ccs.checkBoxReader   = {setPropsFromJsonDictionary: parser.CheckBoxAttributes};
165     ccs.labelAtlasReader = {setPropsFromJsonDictionary: parser.TextAtlasAttributes};
166     ccs.labelBMFontReader= {setPropsFromJsonDictionary: parser.TextBMFontAttributes};
167     ccs.labelReader      = {setPropsFromJsonDictionary: parser.TextAttributes};
168     ccs.layoutReader     = {setPropsFromJsonDictionary: parser.LayoutAttributes};
169     ccs.listViewReader   = {setPropsFromJsonDictionary: parser.ListViewAttributes};
170     ccs.loadingBarReader = {setPropsFromJsonDictionary: parser.LoadingBarAttributes};
171     ccs.pageViewReader   = {setPropsFromJsonDictionary: parser.PageViewAttributes};
172     ccs.scrollViewReader = {setPropsFromJsonDictionary: parser.ScrollViewAttributes};
173     ccs.sliderReader     = {setPropsFromJsonDictionary: parser.SliderAttributes};
174     ccs.textFieldReader  = {setPropsFromJsonDictionary: parser.TextFieldAttributes};
175 })();
176 
177 (function(){
178     ccs.sceneReader = {
179 
180         _node: null,
181 
182         //@deprecated This function will be deprecated sooner or later please use ccs.load
183         /**
184          * Create Scene Node
185          * @param file
186          * @returns {*}
187          */
188         createNodeWithSceneFile: function(file){
189             var node = ccs._load(file, "scene");
190             this._node = node;
191             return node;
192         },
193 
194         /**
195          * Get a node by tag.
196          * @param {Number} tag
197          * @returns {cc.Node|null}
198          */
199         getNodeByTag: function(tag){
200             if (this._node == null)
201                 return null;
202             if (this._node.getTag() === tag)
203                 return this._node;
204             return this._nodeByTag(this._node, tag);
205         },
206 
207         _nodeByTag: function (parent, tag) {
208             if (parent == null)
209                 return null;
210             var retNode = null;
211             var children = parent.getChildren();
212             for (var i = 0; i < children.length; i++) {
213                 var child = children[i];
214                 if (child && child.getTag() === tag) {
215                     retNode = child;
216                     break;
217                 } else {
218                     retNode = this._nodeByTag(child, tag);
219                     if (retNode)
220                         break;
221                 }
222             }
223             return retNode;
224         },
225 
226         //@deprecated This function will be deprecated sooner or later
227         /**
228          * Returns the version of ccs.SceneReader.
229          * @returns {string}
230          */
231         version: function(){
232             return "*";
233         },
234 
235         //@deprecated This function will be deprecated sooner or later
236         /**
237          * Sets the listener to reader.
238          * Cannot use
239          */
240         setTarget: function(){},
241 
242         //@deprecated This function will be deprecated sooner or later
243         /**
244          * Clear all triggers and stops all sounds.
245          */
246         clear: function(){
247             ccs.triggerManager.removeAll();
248             cc.audioEngine.end();
249         }
250     };
251 })();