<?xml version="1.0" encoding="UTF-8"?>
<rmml>
<!--
$RCSfile:  rnmc_result_panel.xml $
$Revision: 745 $

last change: $Date: 2008-09-15 14:44:27 +0400 (Пн, 15 сен 2008) $
             $Author: toha $

	Lacerta Project
	version 1.0.0.1
	Copyright (C) 2008 RNMC
-->

<composition name="rnmc_ResultPanel">
<xml name="settingsXML"/>
<script><![CDATA[
//	настройки панели
	this.panelMode = "IMAGE_DISPLAYING";

//	положение
	this.panelX = 0;
	this.panelY = 567;
//	путь к фоновой картинке и её смещение относительно всей панели
	this.backgroundSrc = "/interface/resultpanel/background.png";
	this.backgroundX = 0;
	this.backgroundY = 0;
//	сама картинка
	this.background = null;
	
//	положение контейнера для маркеров
	this.containerX = 0;
	this.containerY = 0;
	this.containerWidth = 100;
	this.spaceWidth = 10;
	
	this.markersArray = null;
	this.scrollTop = 0;
	//this.scrollBottom = 0;

//	объекты кнопок скролла	
	this.scrollBackButton = null;
	this.scrollForwardButton = null;

	function initFromFile(settingsFile){
		var xmlNode = null;
		var xmlAttributeMap = null;
		var xmlAttribute = null;
		
		this.markersArray = new Array();
		
		if(!resourceExists(settingsFile)){
			trace("ОШИБКА: Файл настроек списка шагов " + settingsFile + " не найден.");
			return false;
		}
		settingsXML.src = settingsFile;
		if (!settingsXML.XMLDocument){
			// Если загружаемый файл не правильный - пишем в трэйсер и выходим
			trace("Файл " + settingsFile + " не является правильным XML файлом.");
			return false;
		} else {
			settingsXML.XMLDocument.source = settingsXML.src;
			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("bgSrc");
						if (xmlAttribute != null && xmlAttribute.specified)
							this.backgroundSrc = xmlAttribute.value;
						xmlAttribute =  xmlAttributeMap.getNamedItem("bgX");
						if (xmlAttribute != null && xmlAttribute.specified)
							this.backgroundX = parseInt(xmlAttribute.value);
						xmlAttribute =  xmlAttributeMap.getNamedItem("bgY");
						if (xmlAttribute != null && xmlAttribute.specified)
							this.backgroundY = parseInt(xmlAttribute.value);
					}
				} else if(xmlNode.nodeName == "container"){
					xmlAttributeMap = xmlNode.attributes;
					if (xmlAttributeMap){
						xmlAttribute =  xmlAttributeMap.getNamedItem("x");
						if (xmlAttribute != null && xmlAttribute.specified)
							this.containerX = parseInt(xmlAttribute.value);
						xmlAttribute =  xmlAttributeMap.getNamedItem("y");
						if (xmlAttribute != null && xmlAttribute.specified)
							this.containerY = parseInt(xmlAttribute.value);
						xmlAttribute =  xmlAttributeMap.getNamedItem("width");
						if (xmlAttribute != null && xmlAttribute.specified)
							this.containerWidth = parseInt(xmlAttribute.value);
						xmlAttribute =  xmlAttributeMap.getNamedItem("spacer");
						if (xmlAttribute != null && xmlAttribute.specified)
							this.spaceWidth = parseInt(xmlAttribute.value);
					}
				} else if(xmlNode.nodeName == "markers"){
					xmlAttributeMap = xmlNode.attributes;
					if (xmlAttributeMap){
						xmlAttribute =  xmlAttributeMap.getNamedItem("x");
						if (xmlAttribute != null && xmlAttribute.specified)
							this.containerX = parseInt(xmlAttribute.value);
						xmlAttribute =  xmlAttributeMap.getNamedItem("y");
						if (xmlAttribute != null && xmlAttribute.specified)
							this.containerY = parseInt(xmlAttribute.value);
						xmlAttribute =  xmlAttributeMap.getNamedItem("width");
						if (xmlAttribute != null && xmlAttribute.specified)
							this.containerWidth = xmlAttribute.value;
					}
				} else if(xmlNode.nodeName == "button"){
					var newObject = scene.Utils.initStdButtonFromNode(xmlNode, this);
					if(newObject){
						if(newObject.id == "back"){
							this.scrollBackButton = newObject;
						} else if(newObject.id == "forward"){
							this.scrollForwardButton = newObject;
						} else {
							newObject.parent = null;
							newObject = null;
						}
					}
				}
				xmlNode = xmlNode.nextSibling;
			}
		}
		return true;
	}
	
//	
	function showObject(){
		if(this.backgroundSrc && !this.background){
			this.background = new Image();
			this.background.src = this.backgroundSrc;
			this.background.x = this.backgroundX;
			this.background.y = this.backgroundY;
			this.background.parent = this;
			this.background.visible = true;			
		}
		if(this.scrollBackButton){
			this.scrollBackButton.setReleaseCallBack(this, this.scrollBack);
			this.scrollBackButton.showObject();
		}
		if(this.scrollForwardButton){
			this.scrollForwardButton.setReleaseCallBack(this, this.scrollForward);
			this.scrollForwardButton.showObject();
		}
		this.x = this.panelX;
		this.y = this.panelY;
		this.visible = true;
	}
	
	function hideObject(){
		this.visible = false;
	}
	
//	стартует новую секцию результатов
	function startNewSection(){
		var newMarker = new Object();
		newMarker.width = 20;
		newMarker.parent = this;
		this.markersArray.push(newMarker);
	}
	
	function updateResultPanel(){	
		var uBoundReached = false;
		var currentPlaceX = 0;
		var currentPlaceY = 0;
		//	рассчитываем количество занятого места
		for(var i = 0; i < this.markersArray.length; i++){
			if(uBoundReached){
				this.markersArray[i].visible = false;
			}
			if(i < this.scrollTop){
				this.markersArray[i].visible = false;
			} else {
				this.markersArray[i].x = this.containerX + currentPlaceX;
				currentPlaceX += this.markersArray[i].width;
				if(currentPlaceX < this.containerWidth){
					
					this.markersArray[i].visible = true;
				} else {
					uBoundReached = true;
					this.markersArray[i].visible = false;
				}
				currentPlaceX += this.spaceWidth;				
			}
		}
		//	запоминаем скока осталось свободного места в контейнере
		this.containerFreeWidth = this.containerWidth - currentPlaceX;	
	}
	
	function addResult(resultValue, annotationText){
		if(resultValue >= 0 && resultValue <= 100){
			switch(this.panelMode){
			case "IMAGE_DISPLAYING":
				var newMarker = new Image();
				if(resultValue == 100){
					newMarker.src = "/interface/resultpanel/result_100.png";
				} else if(resultValue == 0){
					newMarker.src = "/interface/resultpanel/result_0.png";
				}
				var newMarkerCoords = this.getNewMarkerPlace();
				newMarker.x = newMarkerCoords[0];
				newMarker.y = newMarkerCoords[1];
				newMarker.depth = -10;
				newMarker.parent = this;
				newMarker.visible = false;
				newMarker.resultValue = resultValue;
				if(annotationText)
					newMarker.resultAnnotation = annotationText;			
				this.markersArray.push(newMarker);
				break;
			}
		}
		if(this.containerFreeWidth <= this.markersArray[this.markersArray.length - 1].width){
			this.scrollTop++;
		}
		this.updateResultPanel(true);
	}
	
	function getNewMarkerPlace(){
		var curX = this.containerX;
		var curY = this.containerY;
		for(var i = 0; i < this.markersArray.length; i++){
			curX += this.markersArray[i].width;
			curX += this.spaceWidth;
		}
		var newCoords = new Array(curX,curY);
		return newCoords;
	}	
	
//	скроллит назад на itemsCount
	function scrollBack(itemsCount){
		if(this.scrollTop > 0){
			this.scrollTop--;
			this.updateResultPanel();
		}
	}
	
//	скроллит вперёд на itemsCount
	function scrollForward(itemsCount){
		if( this.scrollTop < this.markersArray.length - 1){
			this.scrollTop++;
			this.updateResultPanel();
		}
	}
	
]]></script>
</composition>
</rmml>
