<?xml version="1.0" encoding="UTF-8"?>
<rmml>
<!--
$RCSfile: rnmc_steplist.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_StepList">
<xml name="settingsXML"/>

<sequencer name="stepListLoop" playing="false" loop="true">
	<script>
		updateStepList();
	</script>
</sequencer>

<sequencer name="mousePositionChecker" playing="false" loop="true">
	<script>
		isMouseOverList();
	</script>
</sequencer>

<script><![CDATA[
	this.stepListVisibleX = 700;
	this.stepListVisibleY = 3;
	this.stepListHiddenX = 990;
	this.stepListHiddenY = 3;
	this.stepListHitArea = null;
	// пока делим арею на координаты
	this.stepListHitAreaX = null;
	this.stepListHitAreaY = null;
	this.stepListHitAreaWidth = null;
	this.stepListHitAreaHeight = null;
	// ------------
	this.flowDelta = 12;
	this.visitedMarkSrc = null;
	this.backgroundSrc = null;
	this.backgroundX = 0;
	this.backgroundY = 0;
	
	this.listControlX = 45;
	this.listControlY = 34;
	this.listControlWidth = 242;
	this.listControlHeight = 520;
	this.listCurrentColor = null;
	this.listSelectedColor = null;
	
	this.columnsId = null;
	this.columnsWidth = null;
	this.columnsStyle = null;

	this.stepListState = STEPLIST_IDLE;
	
	// дочерние объекты
	this.listControl = null;
	this.stepListBackground = null;
	//this.stepListArea = null;
	this.showListButton = null;
	this.hideListButton = null;	
		
	this.lockListButton = null;// ЛОК СПИСКА НЕ РАБОТАЕТ!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	this.unlockListButton = null;
	
	function initFromFile(settingsFile){
		var xmlNode = null;
		var xmlAttributeMap = null;
		var xmlAttribute = null;
		
		//	настройки колонок
		this.columnsId = new Array();
		this.columnsWidth = new Array();
		this.columnsStyle = 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("visibleX");
						if (xmlAttribute != null && xmlAttribute.specified)
							this.stepListVisibleX = parseInt(xmlAttribute.value);
						xmlAttribute =  xmlAttributeMap.getNamedItem("visibleY");
						if (xmlAttribute != null && xmlAttribute.specified)
							this.stepListVisibleY = parseInt(xmlAttribute.value);
						xmlAttribute =  xmlAttributeMap.getNamedItem("hiddenX");
						if (xmlAttribute != null && xmlAttribute.specified)
							this.stepListHiddenX = parseInt(xmlAttribute.value);
						xmlAttribute =  xmlAttributeMap.getNamedItem("hiddenY");
						if (xmlAttribute != null && xmlAttribute.specified)
							this.stepListHiddenY = parseInt(xmlAttribute.value);
						xmlAttribute =  xmlAttributeMap.getNamedItem("hitArea");
						if (xmlAttribute != null && xmlAttribute.specified)
							this.stepListHitArea = xmlAttribute.value;
						xmlAttribute =  xmlAttributeMap.getNamedItem("flowDelta");
						if (xmlAttribute != null && xmlAttribute.specified)
							this.flowDelta = parseInt(xmlAttribute.value);
						xmlAttribute =  xmlAttributeMap.getNamedItem("visitedSrc");
						if (xmlAttribute != null && xmlAttribute.specified)
							this.visitedMarkSrc = 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 == "button"){
					xmlAttributeMap = xmlNode.attributes;
					if (xmlAttributeMap){
						xmlAttribute = xmlAttributeMap.getNamedItem("id");
						if (xmlAttribute != null && xmlAttribute.specified){
							switch(xmlAttribute.value){
							case "show":
								var newObject = new Composition();
								newObject._class = "rnmc_stdButton";
								newObject.parent = this;
								newObject.visible = false;
								if(newObject.initFromNode(xmlNode)){
									this.showListButton = newObject;
									//this.showListButton.setRollOverCallBack(this, this.buttonDispatcher);
									
								} else {
									newObject.parent = null;
									newObject = null;
								};
								break;
							case "hide":
								var newObject = new Composition();
								newObject._class = "rnmc_stdButton";
								newObject.parent = this;
								newObject.visible = false;
								if(newObject.initFromNode(xmlNode)){
									this.hideListButton = newObject;
									//this.hideListButton.setRollOverCallBack(this, this.buttonDispatcher);
									
								} else {
									newObject.parent = null;
									newObject = null;
								};
								break;
							case "lock":
							case "unlock":
								trace("Кнопка LOCK пока не реализована!!!!!!!!!!!!!!!!!!!!!!!!!!!");
							default:
								trace("ОШИБКА: Список шагов - неизвестный id кнопки: " + xmlAttribute.value);
								break;
							}
						}
					}
				} else if(xmlNode.nodeName == "list"){
					var listNode = xmlNode.firstChild;
					while(listNode){
						if(listNode.nodeName == "param"){
							xmlAttributeMap = listNode.attributes;
							if (xmlAttributeMap){
								xmlAttribute =  xmlAttributeMap.getNamedItem("x");
								if (xmlAttribute != null && xmlAttribute.specified)
									this.listControlX = parseInt(xmlAttribute.value);
								xmlAttribute =  xmlAttributeMap.getNamedItem("y");
								if (xmlAttribute != null && xmlAttribute.specified)
									this.listControlY = parseInt(xmlAttribute.value);
								xmlAttribute =  xmlAttributeMap.getNamedItem("width");
								if (xmlAttribute != null && xmlAttribute.specified)
									this.listControlWidth = parseInt(xmlAttribute.value);
								xmlAttribute =  xmlAttributeMap.getNamedItem("height");
								if (xmlAttribute != null && xmlAttribute.specified)
									this.listControlHeight = parseInt(xmlAttribute.value);
								xmlAttribute =  xmlAttributeMap.getNamedItem("currentColor");
								if (xmlAttribute != null && xmlAttribute.specified)
									this.listCurrentColor = xmlAttribute.value;
								xmlAttribute =  xmlAttributeMap.getNamedItem("selectedColor");
								if (xmlAttribute != null && xmlAttribute.specified)
									this.listSelectedColor = xmlAttribute.value;
							}
						} else if(listNode.nodeName == "column"){
							var columnId = null;
							var columnWidth = 0;
							var columnStyle = null;
							xmlAttributeMap = listNode.attributes;
							if (xmlAttributeMap){
								xmlAttribute =  xmlAttributeMap.getNamedItem("id");
								if (xmlAttribute != null && xmlAttribute.specified)
									columnId = xmlAttribute.value;
								xmlAttribute =  xmlAttributeMap.getNamedItem("width");
								if (xmlAttribute != null && xmlAttribute.specified)
									columnWidth = parseInt(xmlAttribute.value);
								xmlAttribute =  xmlAttributeMap.getNamedItem("style");
								if (xmlAttribute != null && xmlAttribute.specified)
									columnStyle = xmlAttribute.value;
							}
							if(columnId && columnWidth > 0){
								this.columnsId.push(columnId);
								this.columnsWidth.push(columnWidth);
								if(columnStyle && scene.StyleManager.styleExists(columnStyle)){
									this.columnsStyle.push(columnStyle);
								} else {
									this.columnsStyle.push(null);
								}
							}
						}
							
						listNode = listNode.nextSibling;
					}
				}
				xmlNode = xmlNode.nextSibling;
			}
			/* if() // если список неубираемый
			this.x = this.stepListVisibleX;
			this.y = this.stepListVisibleY;
			*/
			// if() // если список убираемый
			this.x = this.stepListHiddenX;
			this.y = this.stepListHiddenY;
			
			// если задана зона при съезде с которой список убирается
			if(this.stepListHitArea){
				this.stepListHitArea = scene.Utils.replaceString(scene.Utils.replaceString(this.stepListHitArea, "[", ""), "]", "");
				var areaParams = (this.stepListHitArea).split(",");
				this.stepListHitAreaX = parseInt(areaParams[0]);
				this.stepListHitAreaY = parseInt(areaParams[1]);
				this.stepListHitAreaWidth = parseInt(areaParams[2]);
				this.stepListHitAreaHeight = parseInt(areaParams[3]);
				/*
				this.stepListArea = new Button();
				this.stepListArea.parent = this;
				this.stepListArea.depth = -20;
				this.stepListArea.x = 0;
				this.stepListArea.y = 0;
				this.stepListArea.enabled = true;
				this.stepListArea.hitArea = this.stepListHitArea;
				*/
			}
			if(this.backgroundSrc){
				this.stepListBackground = new Image();
				this.stepListBackground.src = this.backgroundSrc;
				this.stepListBackground.x = this.backgroundX;
				this.stepListBackground.y = this.backgroundY;
				this.stepListBackground.depth = 10;
				this.stepListBackground.parent = this;
				this.stepListBackground.visible = true;
			}
		}
		return true;
	}
				
	function loadStepList(stepNames){
		if(this.initFromFile("\\Interface\\StepList\\settings.xml")){
			this.listControl = new Composition();
			this.listControl._class = "common_list";
			this.listControl.parent  = this;
			this.listControl.x = this.listControlX;
			this.listControl.y = this.listControlY;
			this.listControl.depth = -10;
			if(this.listSelectedColor){
				this.listControl.markSelected = true;
				this.listControl.selectedItemBgColor = this.listSelectedColor;
			}
			if(this.listCurrentColor){
				this.listControl.markCurrent = true;
				this.listControl.currentItemBgColor = this.listCurrentColor;
			}
			var listWidth = 0;
			for(var i = 0; i < this.columnsId.length; i++){
				listWidth += this.columnsWidth[i];
			}		
			this.listControl.initList(listWidth, this.listControlHeight, this.columnsId.length, this.columnsWidth);
			this.listControl.setReleaseCallback(this, this.onListItemSelected);
			
			// создание новых строк
			for(var i = 0; i  < stepNames.length; i++)
					this.listControl.addListItem();
			
			for(var i = 0; i  < stepNames.length; i++){
				if(this.visitedMarkSrc){
					var newImgObject = new Image();
					newImgObject.src = this.visitedMarkSrc;
					newImgObject.visible = false;
					this.listControl.setRowObject(i, 0, newImgObject);
				} 
				var newTxtObject = new Text();
				newTxtObject.value = (i + 1) + ".  " + stepNames[i];
				newTxtObject.adjustHeight = true;
				newTxtObject.width = this.listControl.getColumnWidth(1);
				this.listControl.setRowObject(i, 1, newTxtObject);
			}
			
			this.listControl.listArea.hitArea = "[0,0," + this.listControl.listWidth + "," + this.listControl.listHeight + "]";
			this.listControl.topIndex = 0;
			this.listControl.calculateTotalItemsHeight();
			this.listControl.calculateMaxIndex();
			this.listControl.showObject();
		
			if(this.showListButton)
				this.showListButton.showObject();
			if(this.hideListButton)
				this.hideListButton.hideObject();
			return true;
		} else {
			return false;
		}
	}
	
	// обработчик выбора некоторого шага
	function onListItemSelected(itemId){
		parent.startStep(itemId);
	}
	
	// помечает текущий шаг
	function selectCurrentStep(stepId){
		this.listControl.markSeletedItem(stepId);
		this.listControl.showRowContent(stepId, 0);
	}
	
	function showStepList(){
		this.stepListState = STEPLIST_SHOW;
		if(this.hideListButton){
			this.showListButton.hideObject();
			this.hideListButton.showObject();
		}
		stepListLoop.playing = true;
	}
	
	function hideStepList(){
		this.stepListState = STEPLIST_HIDE;
		if(this.hideListButton){
			this.showListButton.showObject();
			this.hideListButton.hideObject();
		} else {
			mousePositionChecker.playing = false;
		}
		stepListLoop.playing = true;
	}
	
	// цикл обработки движения
	function updateStepList(){
		var xTargetOffset = 0;
		var yTargetOffset = 0;
		if(this.stepListState == STEPLIST_SHOW){
			// если показываем список
			xTargetOffset = this.stepListVisibleX - this.x;
			yTargetOffset = this.stepListVisibleY - this.y;
		} else if(this.stepListState == STEPLIST_HIDE){
			xTargetOffset = this.stepListHiddenX - this.x;
			yTargetOffset = this.stepListHiddenY - this.y;
		} else {
			stepListLoop.playing = false;
			return;
		}
		if(xTargetOffset != 0){
			if (xTargetOffset > this.flowDelta)
				this.x += this.flowDelta;
			else if (xTargetOffset < - this.flowDelta)
				this.x -= this.flowDelta;
			else
				this.x += xTargetOffset;
		};
		
		if(yTargetOffset != 0){
			if (yTargetOffset > this.flowDelta)
				this.y += this.flowDelta;
			else if (yTargetOffset < - this.flowDelta)
				this.y -= this.flowDelta;
			else
				this.y += yTargetOffset;
		};	
		
		if (xTargetOffset == 0 && yTargetOffset== 0){
			stepListLoop.playing = false;
			if(this.stepListState == STEPLIST_SHOW){
				if(!this.hideListButton)
					mousePositionChecker.playing = true;
			} else if(this.stepListState == STEPLIST_HIDE){
						
			} else {
			
			}
			this.stepListState = STEPLIST_IDLE;
			return;
		};
	}
	
	// пока нет функции проверки вхождения точки в некоторую область
	// приходится проверять самому
	function isMouseOverList(){
		if(xMouse >= this.stepListHitAreaX && xMouse <= this.stepListHitAreaWidth && yMouse >= this.stepListHitAreaY && yMouse <= this.stepListHitAreaHeight){
			// мышь над stepList
		} else {
			this.hideStepList();
		}
	}
	
	function dispatchAction(singleAction){
		for (var i = 0; i < singleAction.length; ++i)
			singleAction[i] = scene.Utils.trim(singleAction[i]);

		switch(singleAction[0]){
		case "showStepList":
			this.showStepList();
			break;
		case "hideStepList":
			this.hideStepList();
			break;
		case "loakStepList":
			break;
		case "unlockStepList":
			break;
		}
	}
	
]]></script>
</composition>
</rmml>