<?xml version="1.0" encoding="UTF-8"?>
<rmml>
<!--
$RCSfile: rnmc_control_manager.xml,v $
$Revision: 957 $

last change: $Date: 2009-02-17 14:00:06 +0300 (Вт, 17 фев 2009) $
             $Author: toha $

	Lacerta Project
	version 1.0.0.1
	Copyright (C) 2007-2009 RNMC
-->

<composition name="rnmc_ControlManager">
<xml name="controlsXML"/>
<script><![CDATA[
	this.definedControls = null;
		
	function loadControlsFromFile(srcFile){
		var xmlNode;
		var xmlAttributeMap;
		var xmlAttribute;
		
		this.definedControls = new Array();
		
		controlsXML.src = srcFile;
		if (!controlsXML.XMLDocument){
			// Если загружаемый файл не правильный - пишем в трэйсер и выходим
			trace("Файл " + srcFile + " не является правильным XML файлом.");
			return false;
		} else {
			controlsXML.XMLDocument.source = controlsXML.src;
			if (!controlsXML.XMLDocument || !controlsXML.XMLDocument.firstChild)
				return false;
			xmlNode = controlsXML.XMLDocument.firstChild.firstChild;
			while(xmlNode){
				if(xmlNode.nodeName == "button"){
					xmlAttributeMap = xmlNode.attributes;
					if (xmlAttributeMap){
						xmlAttribute = xmlAttributeMap.getNamedItem("name");
						if(xmlAttribute != null && xmlAttribute.specified
							&& xmlAttribute.value != ""){
							var newControl = new Array();
							newControl.push(xmlAttribute.value);
							newControl.push(CONTROL_TYPE_BUTTON);
							newControl.push(xmlNode);
							this.definedControls.push(newControl);
						}
					}
				} else if(xmlNode.nodeName == "playcontrol"){
					xmlAttributeMap = xmlNode.attributes;
					if (xmlAttributeMap){
						xmlAttribute = xmlAttributeMap.getNamedItem("name");
						if(xmlAttribute != null && xmlAttribute.specified
							&& xmlAttribute.value != ""){
							var newControl = new Array();
							newControl.push(xmlAttribute.value);
							newControl.push(CONTROL_TYPE_PLAYCONTROL);
							newControl.push(xmlNode);
							this.definedControls.push(newControl);
						}
					}
				} else if(xmlNode.nodeName == "group"){
					xmlAttributeMap = xmlNode.attributes;
					if (xmlAttributeMap){
						xmlAttribute = xmlAttributeMap.getNamedItem("name");
						if(xmlAttribute != null && xmlAttribute.specified
							&& xmlAttribute.value != ""){
							var newControl = new Array();
							newControl.push(xmlAttribute.value);
							newControl.push(CONTROL_TYPE_GROUP);
							newControl.push(xmlNode);
							this.definedControls.push(newControl);
						}
					}
				} else if(xmlNode.nodeName == "text"){
					xmlAttributeMap = xmlNode.attributes;
					if (xmlAttributeMap){
						xmlAttribute = xmlAttributeMap.getNamedItem("name");
						if(xmlAttribute != null && xmlAttribute.specified
							&& xmlAttribute.value != ""){
							var newControl = new Array();
							newControl.push(xmlAttribute.value);
							newControl.push(CONTROL_TYPE_TEXTBOX);
							newControl.push(xmlNode);
							this.definedControls.push(newControl);
						}
					}
				} else {
					xmlAttributeMap = xmlNode.attributes;
					if (xmlAttributeMap){
						xmlAttribute = xmlAttributeMap.getNamedItem("name");
						if(xmlAttribute != null && xmlAttribute.specified
							&& xmlAttribute.value != ""){
							var newControl = new Array();
							newControl.push(xmlAttribute.value);
							newControl.push(CONTROL_TYPE_UNKNOW);
							newControl.push(xmlNode);
							this.definedControls.push(newControl);
						}
					}				
				}
				xmlNode = xmlNode.nextSibling;
			};
		}
	};
	
	function getControl(controlName, parentObject){
		for(var i = 0; i < this.definedControls.length; i++){
			if(controlName == this.definedControls[i][0]){
				switch(this.definedControls[i][1]){
				case CONTROL_TYPE_UNKNOW:
					var newObject = scene.Utils.initStdObjectFromNode(this.definedControls[i][2], parentObject);
					return newObject;
					break;
				case CONTROL_TYPE_BUTTON:
					var newObject = new Composition();
					newObject._class = "rnmc_stdButton";
					newObject.parent = parentObject;
					newObject.initFromNode(this.definedControls[i][2]);
					return newObject;
				break;
				case CONTROL_TYPE_PLAYCONTROL:
					var newObject = new Composition();
					newObject._class = "rnmc_stdPlayControl";
					newObject.parent = parentObject;
					newObject.initFromNode(this.definedControls[i][2]);
					return newObject;
				break;
				case CONTROL_TYPE_TEXTBOX:
					var newObject = new Composition();
					newObject._class = "rnmc_stdText";
					newObject.parent = parentObject;
					newObject.initFromNode(this.definedControls[i][2]);
					return newObject;
				break;
				case CONTROL_TYPE_GROUP:
//trace("#FF0000 case CONTROL_TYPE_GROUP:");
					var newObject = new Composition();
					newObject._class = "rnmc_stdControlGroup";
					newObject.parent = parentObject;
					newObject.initFromNode(this.definedControls[i][2]);
					return newObject;
				break;
				}
			}
		}		
	};
	
	function getControlNode(controlName){
		for(var i = 0; i < this.definedControls.length; i++){
			if(controlName == this.definedControls[i][0]){
				return this.definedControls[i][2];
			}
		}
		trace("ОШИБКА: нет контролов с данным именем - " + controlName);
		return;
	};	
]]></script>
</composition>
</rmml>