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

last change: $Date: 2009-02-18 16:42:40 +0300 (Ср, 18 фев 2009) $
             $Author: toha $

	Lacerta Project
	version 1.0.0.1
	Copyright (C) 2007-2009 RNMC
-->
<composition name="rnmc_stdEffect">
<script><![CDATA[
	this.id = null;
	this.uninterrupted = false;
	this.effectEvent = null;

	this.effectRunning = false;
	
//	по умолчанию эффект можно стартовать повторно
//	(даже если он ещё не завершился)
	this.uninterrupted = false;
	
	this.effectType = NO_EFFECT;
	this.effectDuration = 0;
	this.targetObject = null;

	function setTargetObject(trgObject){
		if(trgObject != undefined && trgObject != null){
			this.targetObject = trgObject;		
		} else {
			return false;
		}
	}
	
	function initFromNode(srcNode){
//trace("rnmc_stdEffect.initFromNode()");
		var xmlNode = null;
		var xmlAttributeMap = null;
		var xmlAttribute = null;

		xmlAttributeMap = srcNode.attributes;
		if (xmlAttributeMap){
			xmlAttribute = xmlAttributeMap.getNamedItem("id");
			if (xmlAttribute != null && xmlAttribute.specified)
				this.id = xmlAttribute.value;
			xmlAttribute = xmlAttributeMap.getNamedItem("uninterrupted");
			if (xmlAttribute != null && xmlAttribute.specified){
				if(xmlAttribute.value.toLowerCase() == "true")
					this.uninterrupted = true;
			}
			xmlAttribute = xmlAttributeMap.getNamedItem("event");
			if (xmlAttribute != null && xmlAttribute.specified){
				switch(xmlAttribute.value){
				case "onShow":
					this.effectEvent = EVENT_ON_SHOW;					
					break;
				case "onHide":
					this.effectEvent = EVENT_ON_HIDE;					
					break;
				case "onRollOver":
					this.effectEvent = EVENT_ON_ROLLOVER;					
					break;
				case "onRollOut":
					this.effectEvent = EVENT_ON_ROLLOUT;					
					break;
				case "onPress":
					this.effectEvent = EVENT_ON_PRESS;					
					break;
				case "onRelease":
					this.effectEvent = EVENT_ON_RELEASE;					
					break;				
				}
			}
		}
		if(srcNode.textContent){
			var nodeContent = srcNode.textContent;
			nodeContent = scene.Utils.replaceString(nodeContent, " ", ""); 
			nodeContent = scene.Utils.replaceString(nodeContent, "\r", ""); 
			nodeContent = scene.Utils.replaceString(nodeContent, "\t", ""); 
			nodeContent = scene.Utils.replaceString(nodeContent, "\n", "");
			this.parseStringToEffect(nodeContent);
		}
		return true;
	}
	
/*
	//	Пример создания объекта эффект
	var newEffect = new Composition();
	newEffect._class = "rnmc_stdEffect";
	newEffect.parent = ...;
	newEffect.initEffect("effect01", EVENT_ON_SHOW, "fade:0.05,0,1");
	
*/
//	Функция инициализации эффекта
	function initEffect(/*string*/ effectId, /*int*/ effectEvent, effectString){
		if(effectId != undefined)
			this.id = xmlAttribute.value;
		if(effectEvent != undefined)
			this.effectEvent = effectEvent;	
		if(effectString != undefined && effectString != null)
			this.parseStringToEffect(effectString);
	}
	
//	Функция разбора эффекта из строчки
//	private
	function parseStringToEffect(srcString){
		var index = srcString.indexOf(":");
		if (index != -1)
			effectParams = srcString.split(":");
		else
		{
			index = srcString.indexOf(",");
			effectParams = new Array();
			effectParams.push(srcString.substr(0,index));
			effectParams.push(srcString.substr(index+1));
		}
		switch(effectParams[0].toLowerCase()){
		case "fade":
			parseEffectParams(EFFECT_FADE, effectParams[1]);
			break;
 		case "fade_ms":
				//	формат следующий: fade,speed(float),startOpacity(float),finishOpacity(float)
			parseEffectParams(EFFECT_FADE, effectParams[1]);
			this.effectDelta = 40/theTime*theDiapason; 
			break; 
		case "move":
			//	формат следующий: move,speed(int),startX(int),startY(int),finishX(int),finishtY(int)
			parseEffectParams(EFFECT_MOVE, effectParams[1]);
			break;
		case "move_ms":
			//	формат следующий: move,speed(int),startX(int),startY(int),finishX(int),finishtY(int)
			parseEffectParams(EFFECT_MOVE, effectParams[1]);
			this.effectDelta = 40/theTime*theDiapason;
			break;
		case "scale":
			//	формат следующий: scale,speed(int),startX(int),startY(int),finishX(int),finishtY(int)
			parseEffectParams(EFFECT_SCALE, effectParams[1]);
			break;
		default:
			this.effectType = NO_EFFECT;
			return false;
		}
	}
	
//	разбирает строку с параметрами эффекта
	function parseEffectParams(fxType, fxParam){
		switch(fxType){
			case EFFECT_FADE:
				//	формат следующий: speed(float),startOpacity(float),finishOpacity(float)
				this.effectType = fxType;
				var tmpParams = fxParam.split(",");
				if(tmpParams[0] != null)
					this.effectDelta = Math.abs(parseFloat(tmpParams[0]));
				if(tmpParams[1] != null)
					this.objectStartOpacity = parseFloat(tmpParams[1]);
				if(tmpParams[2] != null)
					this.objectFinishOpacity = parseFloat(tmpParams[2]);
				break;
			case EFFECT_MOVE:
				//	формат следующий: flowSpeed(int),{(pointX(int),pointY(int)),(pointX(int),pointY(int)),...}
				this.effectType = fxType;
				var tempParams = fxParam.split(",");
				if(tempParams[0])		
					this.effectDelta = parseInt(tempParams[0]);
				var pointsStr = tempParams[1];
				var pointsArray = null;
				for(var i = 2; i < tempParams.length; i++){
					pointsStr = pointsStr + "," + tempParams[i];
				}
				pointsArray = scene.Utils.parsePolygonToArray(pointsStr);

				//	ПОКА СДЕЛАНО ДВИЖЕНИЕ ИЗ ОДНОЙ ТОЧКИ В ДРУГУЮ
				if(pointsArray[0].x != null)		
					this.objectStartX = parseInt(pointsArray[0].x);
				if(pointsArray[0].y != null)
					this.objectStartY = parseInt(pointsArray[0].y);
				if(pointsArray[1] && pointsArray[1].x != null)
					this.objectFinishX = parseInt(pointsArray[1].x);
				if(pointsArray[1] && pointsArray[1].y != null)
					this.objectFinishY = parseInt(pointsArray[1].y);
				break;
			case EFFECT_SCALE:
				this.effectType = fxType;
				var tempParams = fxParam.split(",");
				if(effectParams[0] != null)
					this.effectDelta = Math.abs(parseFloat(effectParams[0]));
				if(effectParams[1] != null){
					switch(effectParams[1]){
					case "lefttop":
						this.scaleFrom = EFFECT_SCALE_LEFTTOP;
						break;
					case "leftbottom":
						this.scaleFrom = EFFECT_SCALE_LEFTBOTTOM;
						break;
					case "center":
						this.scaleFrom = EFFECT_SCALE_CENTER;
						break;
					case "righttop":
						this.scaleFrom = EFFECT_SCALE_RIGHTTOP;
						break;
					case "rightbottom":
						this.scaleFrom = EFFECT_SCALE_RIGHTBOTTOM;
						break;
					}
				}
				if(effectParams[2] != null)
					this.objectStartWidth = parseInt(effectParams[3]);
				if(effectParams[3] != null)
					this.objectStartHeight = parseInt(effectParams[4]);
				if(effectParams[4] != null)
					this.objectFinishWidth = parseInt(effectParams[5]);
				if(effectParams[5] != null)
					this.objectFinishHeight = parseInt(effectParams[6]);

				this.horizontalDelta = Math.round((Math.abs(this.objectFinishWidth - this.objectStartWidth))/this.effectDelta);
				this.verticalDelta = Math.round((Math.abs(this.objectFinishHeight - this.objectStartHeight))/this.effectDelta);		
				break;
			defualt:
				this.effectType = NO_EFFECT;
				return false;
		}
		return true;
	}	
	
//	устанавливает функцию обратного вызова
	function setCallBack(pointerToObject, callbackFunction){
		this.callBackObject = pointerToObject;
		this.callBackFunction = callbackFunction;
	}
	
//	очищает функцию обратного вызова (!!!)
	function clearCallBack(){
		this.callBackObject = null;
		this.callBackFunction = null;
	}
		
//	стартует эффект
//	если эффект был задан неверно, то effectType == NO_EFFECT и функция вернёт 0;
	function startEffect(){
		if(!this.targetObject)
			return;
		//var returnValue = 0;
		var mayStartEffect = true;
		if(this.uninterrupted && this.effectRunning){
			mayStartEffect = false;
		}
		if(mayStartEffect){
			switch(this.effectType){
			case NO_EFFECT:
				updateSequencer.playing = false;
				//	прям сразу сообщаем что эффект завершился
				break;
			case EFFECT_FADE:
				if(this.objectStartOpacity != this.objectFinishOpacity){
					this.targetObject.opacity = this.objectStartOpacity;
					this.targetObject.visible = true;
					this.effectRunning = true;
					updateSequencer.playing = true;
				} else {
					this.targetObject.opacity = this.objectStartOpacity;
					this.targetObject.visible = true;
				}
			//	returnValue = 1;
				break;
			case EFFECT_MOVE:
//trace("startEffect: MOVE: " + this.objectStartX + ", " + this.objectStartY);
				this.targetObject.x = this.objectStartX;
				this.targetObject.y = this.objectStartY;
				this.targetObject.visible = true;
				this.effectRunning = true;
				updateSequencer.playing = true;
				//returnValue = 1;
				break;
			case EFFECT_SCALE:
				/*this.targetObject.width = this.objectStartWidth;
				this.targetObject.height = this.objectStartHeight;
				*/
				this.currentScale = 0;
				this.targetObject.visible = true;
				this.effectRunning = true;
				updateSequencer.playing = true;
				//returnValue = 1;
				break;
			}
		}
		//return 	returnValue;
	}
	
	function stopEffect(){
		this.effectRunning = true;
		updateSequencer.playing = true;			
		this.targetObject = null;
		this.clearCallBack();
	}
	
	function updateObject(){
		if(!this.targetObject){
			updateSequencer.playing = false;
			return;
		}
		switch(effectType){
		case NO_EFFECT:
			this.effectRunning = false;
			this.targetObject = null;
			updateSequencer.playing = false;
			break;
		case EFFECT_FADE:
			if(this.objectStartOpacity < this.objectFinishOpacity){
				if(this.targetObject.opacity >= (this.objectFinishOpacity - this.effectDelta)){
					this.targetObject.opacity = this.objectFinishOpacity;
					this.effectRunning = false;
					this.targetObject = null;
					updateSequencer.playing = false;
					//	==============================================
					if(this.callBackFunction != null && this.callBackObject != null)
						this.callBackFunction.call(this.callBackObject, this);
					//	==============================================
				} else {
					this.targetObject.opacity += this.effectDelta;
				}
			} else {
				if(this.targetObject.opacity <= this.effectDelta){
					this.targetObject.opacity = this.objectFinishOpacity;
					this.effectRunning = false;
					this.targetObject = null;
					updateSequencer.playing = false;
					//	==============================================
					if(this.callBackFunction != null && this.callBackObject != null)
						this.callBackFunction.call(this.callBackObject, this);
					//	==============================================
				} else {
					this.targetObject.opacity -= this.effectDelta;
				}
			}
			break;
		case EFFECT_MOVE:
			if(scene.Hint)
				scene.Hint.stopHint();
			if(parent.rolloverMenuObject)
				 parent.rolloverMenuObject.hideObject();
			var xTargetOffset = 0;
			var yTargetOffset = 0;
			var deltaX = 0;
			var deltaY = 0;
			xTargetOffset = this.objectFinishX - this.targetObject.x;
			yTargetOffset = this.objectFinishY - this.targetObject.y;
			if(xTargetOffset != 0){
				if (xTargetOffset > this.effectDelta)
					this.targetObject.x += this.effectDelta;
				else if (xTargetOffset < - this.effectDelta)
					this.targetObject.x -= this.effectDelta;
				else
					this.targetObject.x += xTargetOffset;
			};
			
			if(yTargetOffset != 0){
				if (yTargetOffset > this.effectDelta)
					this.targetObject.y += this.effectDelta;
				else if (yTargetOffset < - this.effectDelta)
					this.targetObject.y -= this.effectDelta;
				else
					this.targetObject.y += yTargetOffset;
			};
			
			deltaX =  this.objectFinishX - this.targetObject.x - xTargetOffset;
			deltaY =  this.objectFinishY - this.targetObject.y - yTargetOffset;
			
		// переместить присоединенный контрол
			if(parent.controlAttachPoint && parent.attachedControl){
				parent.attachedControl.x -= deltaX;
				parent.attachedControl.y -= deltaY;
			}

		// переместить присоединенную подпись
			if(parent.titleObject && parent.titleAttachStyle != AUTOATTACH_NO){
				parent.titleObject.x -= deltaX;
				parent.titleObject.y -= deltaY;
			}

		// переместить скролинг
			if(parent.objectContent && parent.objectContent.scroller){
				parent.objectContent.scroller.x -= deltaX;
				parent.objectContent.scroller.y -= deltaY;
			}	
			
			if (xTargetOffset == 0 && yTargetOffset== 0){
				//	=================================================
				//	для шаблона интграция	
				if(this.hiddenObject)
					parent.parent.hideDragObject(this.hiddenObject);				
				if(this.integration)				
					this.targetObject.depth = parent.originalDepth - 1;	
				//	=================================================
				
				this.effectRunning = false;
				this.targetObject = null;
					updateSequencer.playing = false;
				//	==============================================
				if(this.callBackFunction != null && this.callBackObject != null)
						this.callBackFunction.call(this.callBackObject, this);
				//	==============================================
				return;
			};
		case EFFECT_SCALE:
			switch(this.scaleFrom){
			case EFFECT_SCALE_CENTER:
				if(this.objectStartWidth < this.objectFinishWidth && this.objectStartHeight < this.objectFinishHeight){
					if(this.currentScale >= (1 - this.effectDelta)){
						this.targetObject.width = this.objectFinishWidth;
						this.targetObject.height = this.objectFinishHeight;
						this.effectRunning = false;
						this.targetObject = null;
						updateSequencer.playing = false;
						//	==============================================
						if(this.callBackFunction != null && this.callBackObject != null)
							this.callBackFunction.call(this.callBackObject, this);
						//	==============================================
					} else {
						this.targetObject.width = Math.round(this.objectFinishWidth*this.currentScale);
						this.targetObject.height = Math.round(this.objectFinishHeight*this.currentScale);
						currentScale += this.effectDelta;
					}
				} 
				break;
			case EFFECT_SCALE_LEFTTOP:
				/*
				var widthOffset = 0;
				var heightOffset = 0;
							
				widthOffset = this.objectFinishWidth - this.targetObject.width;
				heightOffset = this.objectFinishHeight - this.targetObject.height;
				if(widthOffset != 0){
					if (widthOffset > this.horizontalDelta)
						this.targetObject.width += this.horizontalDelta;
					else if (widthOffset < - this.horizontalDelta)
						this.targetObject.width -= this.horizontalDelta;
					else
						this.targetObject.width += widthOffset;
				};
				
				if(heightOffset != 0){
					if (heightOffset > this.verticalDelta)
						this.targetObject.height += this.verticalDelta;
					else if (heightOffset < - this.verticalDelta)
						this.targetObject.height -= this.verticalDelta;
					else
						this.targetObject.height += heightOffset;
				};	
				
				if (widthOffset == 0 && heightOffset == 0){
					updateSequencer.playing = false;
					return;
				};
				*/
				if(this.objectStartWidth < this.objectFinishWidth && this.objectStartHeight < this.objectFinishHeight){
					if(this.currentScale >= (1 - this.effectDelta)){
						this.targetObject.width = this.objectFinishWidth;
						this.targetObject.height = this.objectFinishHeight;
						this.targetObject = null;
					updateSequencer.playing = false;
					} else {
						this.targetObject.width = Math.round(this.objectFinishWidth*this.currentScale);
						this.targetObject.height = Math.round(this.objectFinishHeight*this.currentScale);
						currentScale += this.effectDelta;
					}
				} 
				break;
			case EFFECT_SCALE_LEFTBOTTOM:
				break;
			EFFECT_SCALE_RIGHTTOP:
				break;
			EFFECT_SCALE_RIGHTBOTTOM:
				break;
			}
		default: break;
		}
	}
]]></script>
<sequencer name="updateSequencer" playing="false" loop="true">
<script>
	updateObject();
</script>
</sequencer>
</composition>
</rmml>