<?xml version="1.0" encoding="UTF-8"?>
<rmml>
<!--
$RCSfile:  rnmc_local_indicator.xml $
$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_LocalSTepIndicator">
<xml name="settingsXML"/>
<script><![CDATA[

	this.panelX = 903;
	this.panelY = 11;
	this.panelDepth = -4000;
	
	this.resultText = null;
	this.errorsText = null;
	this.helpsText = null;
	
	this.backImage = null;
	this.markWrong = null;
	this.markRight = null;
	
	
	this.childObjects = null;

	function initFromFile(settingsFile){
		var xmlNode = null;
		var xmlAttributeMap = null;
		var xmlAttribute = null;
		
		if(!resourceExists(settingsFile)){
			trace("ОШИБКА: Файл настроек списка шагов " + settingsFile + " не найден.");
			return false;
		}
		settingsXML.src = settingsFile;
		if (!settingsXML.XMLDocument){
			// Если загружаемый файл не правильный - пишем в трэйсер и выходим
			trace("Файл " + settingsFile + " не является правильным XML файлом.");
			return false;
		} else {
			settingsXML.XMLDocument.source = settingsXML.src;
			this.childObjects = new Array();
			
			xmlNode = settingsXML.XMLDocument.firstChild.firstChild;
			while(xmlNode){
				if(xmlNode.nodeName == "param"){
					xmlAttributeMap = xmlNode.attributes;
					if (xmlAttributeMap){
						xmlAttribute =  xmlAttributeMap.getNamedItem("x");
						if (xmlAttribute != null && xmlAttribute.specified)
							this.panelX = parseInt(xmlAttribute.value);
						xmlAttribute =  xmlAttributeMap.getNamedItem("y");
						if (xmlAttribute != null && xmlAttribute.specified)
							this.panelY = parseInt(xmlAttribute.value);
						xmlAttribute =  xmlAttributeMap.getNamedItem("depth");
						if (xmlAttribute != null && xmlAttribute.specified)
							this.panelDepth = parseInt(xmlAttribute.value);
					}
				} else if(xmlNode.nodeName == "text"){
					var newObject = scene.Utils.initStdTextFromNode(xmlNode, this);
					if(newObject){
						if(newObject.id == "ResultCounter"){
							this.txtResult = newObject;
						} else if(newObject.id == "ErrorsCounter"){
							this.txtErrors = newObject;
						} else if(newObject.id == "HelpsCounter"){
							this.txtHelps = newObject;
						}
						this.childObjects.push(newObject);
					}
				} else if(xmlNode.nodeName == "image"){
					var newObject = scene.Utils.initStdImageFromNode(xmlNode, this);
					if(newObject){
						if(newObject.id == "ResultChanged"){
							this.resultChangedIndicator = newObject;
						} else if(newObject.id == "ErrorsChanged"){
							this.errorsChangedIndicator = newObject;
						} else if(newObject.id == "HelpsChanged"){
							this.helpsChangedIndicator = newObject;
						}
						this.childObjects.push(newObject);
					}
				}
				xmlNode = xmlNode.nextSibling;
			}
		}
		return true;
	}
	
	function showObject(){
		this.x = this.panelX;
		this.y = this.panelY;
		this.depth = this.panelDepth;
		
		if(this.txtErrors){
			this.txtErrors.setTextValue("0");
			this.txtErrors.showObject();
		}
		if(this.txtHelps){
			this.txtHelps.setTextValue("0");
			this.txtHelps.showObject();
		}
		if(this.txtResult){
			this.txtResult.setTextValue("0%");
			this.txtResult.showObject();
		}
		
		for(var i = 0; i < this.childObjects.length; i++){
			if(this.childObjects[i].visibility == OBJECT_VISIBILITY_TRUE){
				this.childObjects[i].showObject();
			}
		}		
		this.visible = true;
	}
		
	function hideObject(){
		this.visible = false;
	}
	
	function initializeObject(){
		
	}
	
	function onResultManagerEventOccuried(resultManagerEvent, newParamValue){
		switch(resultManagerEvent){
		case ON_STEP_RESULT_CHANGED:
			if(this.txtResult && newParamValue >=0){
				if(this.resultChangedIndicator){
					this.resultChangedIndicator.showObject();
				}
				this.txtResult.setTextValue(newParamValue + "%");
			} else {
				if(this.resultChangedIndicator){
					this.resultChangedIndicator.hideObject();
				}
			}
			break;
		case ON_STEP_ERRORS_CHANGED:
			if(this.txtErrors && newParamValue >=0){
				if(this.errorsChangedIndicator){
					this.errorsChangedIndicator.showObject();
				}
				this.txtErrors.setTextValue(newParamValue);
			} else {
				if(this.errorsChangedIndicator){
					this.errorsChangedIndicator.hideObject();
				}
			}
			break;
		case ON_STEP_HELPS_CHANGED:
			if(this.txtHelps && newParamValue >=0){
				if(this.helpsChangedIndicator){
					this.helpsChangedIndicator.showObject();
				}
				this.txtHelps.setTextValue(newParamValue);
			} else {
				if(this.helpsChangedIndicator){
					this.helpsChangedIndicator.hideObject();
				}
			}
			break;
		}
	}
	
]]></script>
</composition>
</rmml>
