<?xml version="1.0" encoding="UTF-8"?>
<!--
$RCSfile: rnmc_hint.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
-->

<rmml>

<composition name="rnmc_Hint">
<xml name="settingsXML"/>
<script><![CDATA[
	//	настройки хинта
	this.hintTextStyle = "DefaultHintText";
	this.hintBorderColor = "#EAA2B4";
	this.hintBorderSize = 1;	
	this.hintBkgColor = "#00FFFFFF";
	this.hintTimeOut  = 2000;
	
	this.borderXOffet = 5;
	this.borderYOffet = 5;
	
	this.maxHintWidth = 300;
	
	this.hintImage = null;
	this.hintText = null;
	this.hintAudio = null;
	this.hintVideo = null;
	this.hintObject = null;

	this.hintBorder = null;

	this.hintType = -1;
	this.hintValue = null;
	this.hintSrc = null;
	this.hintWidth = 0;
	this.hintHeight = 0;
	this.hintScale = 0;
	this.hintBgColor = null;
	this.hintBorderColor = null;
	
// 	ТЕНЬ (тип и параметры)	
//	HINT_SHADOW_NORMAL;
//	HINT_SHADOW_IMAGE
	this.shadowStyle = HINT_NO_SHADOW;
	this.shadowX = 3;
	this.shadowY = 3;
	this.shadowOpacity = 0.50;
	this.shadowColor = "#AA888888";
	this.shadowSrc = null;
	this.shadowObject = null;
	
	function loadHintFromFile(srcFile){
		var xmlNode = null;
		var xmlAttributeMap = null;
		var xmlAttribute = null;
		
		settingsXML.src = srcFile;
		if (!settingsXML.XMLDocument || !settingsXML.XMLDocument.firstChild){
trace("Файл с настройками всплывающей подсказки не найден");
		} else {
			settingsXML.XMLDocument.source = settingsXML.src;
			xmlNode = settingsXML.XMLDocument.firstChild;
			xmlNode = xmlNode.firstChild;
			while(xmlNode){
				if(xmlNode.nodeName == "param"){
					xmlAttributeMap = xmlNode.attributes;
					if (xmlAttributeMap){
						xmlAttribute =  xmlAttributeMap.getNamedItem("timeout");
						if (xmlAttribute != null && xmlAttribute.specified)
							this.hintTimeOut = parseInt(xmlAttribute.value);
						xmlAttribute =  xmlAttributeMap.getNamedItem("width");
						if (xmlAttribute != null && xmlAttribute.specified)
							this.maxHintWidth = Math.abs(parseInt(xmlAttribute.value));
					}
				} else if(xmlNode.nodeName == "text"){
					xmlAttributeMap = xmlNode.attributes;
					if (xmlAttributeMap){
						xmlAttribute =  xmlAttributeMap.getNamedItem("style");
						if (xmlAttribute != null && xmlAttribute.specified)
							this.hintTextStyle = xmlAttribute.value;
					}
				} else if(xmlNode.nodeName == "border"){
					xmlAttributeMap = xmlNode.attributes;
					if (xmlAttributeMap){
						xmlAttribute =  xmlAttributeMap.getNamedItem("size");
						if (xmlAttribute != null && xmlAttribute.specified)
							this.hintBorderSize = parseInt(xmlAttribute.value);
						xmlAttribute =  xmlAttributeMap.getNamedItem("color");
						if (xmlAttribute != null && xmlAttribute.specified)
							this.hintBorderColor = xmlAttribute.value;
						xmlAttribute =  xmlAttributeMap.getNamedItem("xOffset");
						if (xmlAttribute != null && xmlAttribute.specified)
							this.borderXOffet = parseInt(xmlAttribute.value);
						xmlAttribute =  xmlAttributeMap.getNamedItem("yOffset");
						if (xmlAttribute != null && xmlAttribute.specified)
							this.borderYOffet = parseInt(xmlAttribute.value);
					}
				} else if(xmlNode.nodeName == "background"){
					xmlAttributeMap = xmlNode.attributes;
					if (xmlAttributeMap){
						xmlAttribute =  xmlAttributeMap.getNamedItem("color");
						if (xmlAttribute != null && xmlAttribute.specified)
							this.hintBgColor = xmlAttribute.value;
					}
				} else if(xmlNode.nodeName == "shadow"){
					xmlAttributeMap = xmlNode.attributes;
					if (xmlAttributeMap){
						xmlAttribute =  xmlAttributeMap.getNamedItem("style");
						if (xmlAttribute != null && xmlAttribute.specified){
							switch((xmlAttribute.value).toLowerCase()){
							case "shadow_normal":
trace("#FF0000HINT_SHADOW_NORMAL");
								this.shadowStyle = HINT_SHADOW_NORMAL;
								break;
							}
						}
						xmlAttribute =  xmlAttributeMap.getNamedItem("color");
						if (xmlAttribute != null && xmlAttribute.specified)
							this.shadowColor = xmlAttribute.value;
						xmlAttribute =  xmlAttributeMap.getNamedItem("xOffset");
						if (xmlAttribute != null && xmlAttribute.specified)
							this.shadowX = parseInt(xmlAttribute.value);
						xmlAttribute =  xmlAttributeMap.getNamedItem("yOffset");
						if (xmlAttribute != null && xmlAttribute.specified)
							this.shadowY = parseInt(xmlAttribute.value);
					}
				}
				xmlNode = xmlNode.nextSibling;
			}
		}
			
		// image
		this.hintImage = new Image();
		this.hintImage.visible = false;
		this.hintImage.parent = this;
		
		// text field
		this.hintText = new Text();
		this.hintText.visible = false;
		this.hintText.adjustHeight = true;
		this.hintText.parent = this;
		this.hintText.width = 0;
		this.hintText.height = 0;
		
		this.hintAudio = new Audio();
		this.hintAudio.parent = this;
		
		this.hintVideo = new Video();
		this.hintVideo.parent = this;		
		
		this.hintBorder = new Text();
		this.hintBorder.depth = 2;
		this.hintBorder.adjustHeight = false;
		this.hintBorder.parent = this;
		
		this.hintBackground = new Text();
		this.hintBackground.depth = 1;
		this.hintBackground.adjustHeight = false;
		this.hintBackground.parent = this;
		
		//	отрисовка тени
		if(this.shadowStyle != HINT_NO_SHADOW){
			switch(this.shadowStyle){
			case HINT_SHADOW_NORMAL:
trace("shadow color == " + this.shadowColor);
			//	тест тени с помощью текста
				this.shadowObject = new Text();
				this.shadowObject.bkgColor = this.shadowColor;
				this.shadowObject.depth = 3;
				this.shadowObject.opacity = this.shadowOpacity;
				this.shadowObject.visible = false;
				this.shadowObject.parent = this;
				break;
			}
		}
		
		this.depth = Player.UI.depth - 1000;
	}
	
	function startHint(newHintType, newHintContent, newHintScale, newHintBgColor, newHintBorderColor){
		if(newHintType != undefined)
			this.hintType = newHintType;
		if(newHintContent != undefined){
			this.hintSrc = newHintContent;
			this.hintValue = newHintContent;
		}
		if(newHintScale != undefined){
			this.hintScale = newHintScale;
		} else {
			this.hintScale = 1.0;
		}
		if(newHintBgColor != undefined)
			this.hintBgColor = newHintBgColor;
		if(newHintBorderColor != undefined)
			this.hintBorderColor = newHintBorderColor;
		this.hintStartTimeOut = this.setTimeout("this.showHint();", this.hintTimeOut);
	}
	
	function stopHint(){
//trace("Конец хинта!!!!");
		if(this.hintStartTimeOut){
			this.clearTimeout(this.hintStartTimeOut);
			delete this.hintStartTimeOut;
		}
		this.hideHint();
	}
	
	function showHint(){
//trace("showHint() -- Начало показа хинта!!!!");
		switch(this.hintType){
		case HINT_TYPE_IMAGE:
			this.showImageHint(this.hintSrc, Mouse.x, (Mouse.y + 20 - 112), this.hintScale);
			break;
		case HINT_TYPE_TEXT:
			this.showTextHint(this.hintValue, Mouse.x, (Mouse.y + 20 - 112));
			break;
		case HINT_TYPE_EXTERNALTEXT:
			this.showExternalTextHint(this.hintSrc, parseInt(Mouse.x), parseInt(Mouse.y) + 20 - 112);
			break;
		case HINT_TYPE_AUDIO:
			this.showAudioHint(this.hintSrc);
			break;
		case HINT_TYPE_VIDEO:
			this.showVideoHint(this.hintSrc, Mouse.x, (Mouse.y + 20 - 112), this.hintScale);
			break;
		default:
			trace("Wrong hint type");
			break;
		}
	}
	
	function hideHint(){
//trace("scene.Hint.hideObject()");
		this.hintText.visible = false;	
		this.hintText.value   = null;
		this.hintText.src     = null;
		this.hintText.width = 0;
		this.hintText.height = 0;

		this.hintImage.visible = false;
		this.hintImage.src     = null;
		this.hintImage.width = 0;
		this.hintImage.height = 0;

		this.hintAudio.playing = false;
		this.hintAudio.src = null;

		this.hintVideo.playing = false;
		this.hintVideo.visible = false;
		this.hintVideo.src = null;
		this.hintVideo.width = 0;
		this.hintVideo.height = 0;
		
		if (this.hintObject){
			this.hintObject.visible = false;
			this.hintObject.src = null;
			this.hintObject.parent = null;
			this.hintObject = null;
		}

		if(this.shadowObject){
			this.shadowObject.visible = false;
		}
		
		this.hintBorder.visible = false;
		this.hintBackground.visible = false;
	}
	
	function showTextHint(textValue, textX, textY){
//trace("showTextHint(" + textValue);
		this.hideHint();
		
		if(this.hintBgColor)
			this.hintBackground.bkgColor = this.hintBgColor;
		if(this.hintBorderColor)
			this.hintBorder.bkgColor = this.hintBorderColor;
			
		if(scene.StyleManager.styleExists(this.hintTextStyle))
			this.hintText.style  = this.hintTextStyle;
		this.hintText.value  = textValue;
		this.hintText.width  = 0;
		this.hintText.height = 0;

		if(this.hintText.width > this.maxHintWidth){
			this.hintText.width  = this.maxHintWidth;
			this.hintText.height = 0;
		}

		var newCoords = calculateCoords(textX, textY, this.hintText.width, this.hintText.height);
		this.hintText.x = newCoords[0];
		this.hintText.y = newCoords[1];
		this.hintText.visible = true;

		this.hintBackground.x = this.hintText.x - this.borderXOffet;// - this.shadowX;
		this.hintBackground.y = this.hintText.y - this.borderYOffet;// - this.shadowY;
		this.hintBackground.width = this.hintText.width + 2*this.borderXOffet;
		this.hintBackground.height = this.hintText.height + 2*this.borderYOffet;
		
		this.hintBorder.x = (this.hintText.x - this.borderXOffet) - this.hintBorderSize;// - this.shadowX;
		this.hintBorder.y = (this.hintText.y - this.borderYOffet) - this.hintBorderSize;// - this.shadowY;
		this.hintBorder.width = (this.hintText.width + 2*this.borderXOffet) + 2*this.hintBorderSize;
		this.hintBorder.height = (this.hintText.height + 2*this.borderYOffet) + 2*this.hintBorderSize;
		if(this.shadowStyle != HINT_NO_SHADOW){
trace("this.hintBorder.width == "+this.hintBorder.width);
trace("this.hintBorder.height == "+this.hintBorder.height);

			this.displayShadow(this.hintBorder.x, this.hintBorder.y,
								this.hintBorder.width, this.hintBorder.height);
		}
		
		this.hintBackground.visible = true;
		this.hintBorder.visible = true;
	}
	
	function showExternalTextHint(textSrc, textX, textY){
//trace("showExternalTextHint: " + textX + ", " + textY);
		this.hideHint();

		if(this.hintBgColor)
			this.hintBackground.bkgColor = this.hintBgColor;
		if(this.hintBorderColor)
			this.hintBorder.bkgColor = this.hintBorderColor;
		
		if(scene.StyleManager.styleExists(this.hintTextStyle))
			this.hintText.style = this.hintTextStyle;
		this.hintText.src    = textSrc;
		this.hintText.width  = 0;
		this.hintText.height = 0;

		if(this.hintText.width > this.maxHintWidth){
			this.hintText.width  = this.maxHintWidth;
			this.hintText.height = 0;
		}

		var newCoords = calculateCoords(textX, textY, this.hintText.width, this.hintText.height);
		this.hintText.x = newCoords[0];
		this.hintText.y = newCoords[1];
		this.hintText.visible = true;

		this.hintBackground.x = this.hintText.x - this.borderXOffet - this.shadowX;
		this.hintBackground.y = this.hintText.y - this.borderYOffet - this.shadowY;
		this.hintBackground.width = this.hintText.width + 2*this.borderXOffet;
		this.hintBackground.height = this.hintText.height + 2*this.borderYOffet;
		
		this.hintBorder.x = (this.hintText.x - this.borderXOffet) - this.hintBorderSize - this.shadowX;
		this.hintBorder.y = (this.hintText.y - this.borderYOffet) - this.hintBorderSize - this.shadowY;
		this.hintBorder.width = (this.hintText.width + 2*this.borderXOffet) + 2*this.hintBorderSize;
		this.hintBorder.height = (this.hintText.height + 2*this.borderYOffet) + 2*this.hintBorderSize;
		
		if(this.shadowStyle != HINT_NO_SHADOW){
			this.displayShadow(this.hintBorder.x, this.hintBorder.y, this.hintBorder.width, this.hintBorder.height);
		}

		this.hintBackground.visible = true;
		this.hintBorder.visible = true;
	}
	
	// показ хинта-картинки
	function showImageHint(imageSrc, imageX, imageY, imageScale){
		this.hideHint();
		//this.hintImage.width = 0;
		//this.hintImage.height = 0;
		this.hintImage.src = imageSrc;
		this.hintImage.x = imageX;
		this.hintImage.y = imageY;
		if(imageScale != undefined && imageScale > 0){
			this.hintImage.width *= imageScale;
			this.hintImage.height *= imageScale;
		}
		var newCoords = calculateCoords(imageX, imageY, this.hintImage.width, this.hintImage.height);
		this.hintImage.x = newCoords[0];
		this.hintImage.y = newCoords[1];
		this.hintImage.width = newCoords[2];
		this.hintImage.height = newCoords[3];

		this.hintImage.visible = true;
	}

	// показ хинта-картинки
	function showAudioHint(audioSrc){
		this.hideHint();
		this.hintAudio.src = audioSrc;
		this.hintAudio.rewind();
		this.hintAudio.playing = true;
	}
	
	function showVideoHint(videoSrc, imageX, imageY, imageScale){
		this.hideHint();
		this.hintVideo.src = videoSrc;
		//this.hintVideo.rewind();
		
		this.hintVideo.x = imageX;
		this.hintVideo.y = imageY;
		if(imageScale != undefined && imageScale > 0){
			this.hintVideo.width *= imageScale;
			this.hintVideo.height *= imageScale;
		}
		var newCoords = calculateCoords(imageX, imageY, this.hintVideo.width, this.hintVideo.height);
		this.hintVideo.x = newCoords[0];
		this.hintVideo.y = newCoords[1];
		this.hintVideo.width = newCoords[2];
		this.hintVideo.height = newCoords[3];		
		this.hintVideo.visible = true;
		this.hintVideo.playing = true;
	}
	
	function showObjectHint(objName, objSrc, objX, objY, objScale)
	{
		switch (objName){
			case "text":
				this.showExternalTextHint(objSrc, objX, objY);
				break;
			case "image":
				this.showImageHint(objSrc, objX, objY, objScale);
				break;
			case "video":
				this.showVideoHint(objSrc, objX, objY, objScale);
				break;
			case "audio":
				this.showAudioHint(objSrc);
				break;

			case "quicktime":
				this.hintObject = new Composition();
				this.hintObject._class = "rnmc_stdQuickTime";
				break;
			case "qtemul":
				this.hintObject = new Composition();
				this.hintObject._class = "rnmc_stdQTEmulation";			
				break;
			case "flash":
				this.hintObject = new Composition();
				this.hintObject._class = "rnmc_stdFlash";			
				break;
			case "slideshow":
				this.hintObject = new Composition();
				this.hintObject._class = "rnmc_stdSlideshow";			
				break;
			case "animation":
				this.hintObject = new Composition();
				this.hintObject._class = "rnmc_stdAnimation";			
				break;
			case "shape":
				this.hintObject = new Composition();
				this.hintObject._class = "rnmc_stdShape";			
				break;
			case "object3D":
				this.hintObject = new Composition();
				this.hintObject._class = "rnmc_std3DObject";			
				break;
		}

		if (this.hintObject){
			this.hintObject.visible = false;
			this.hintObject.parent = this;

			this.hintObject.objectX = objX;
			this.hintObject.objectY = objY;
			this.hintObject.objectSrc = objSrc;
			this.hintObject.showObject();
			this.hintObject.visible = false;
			var w = this.hintObject.objectContent.width;
			var h = this.hintObject.objectContent.height;
			if(objScale != undefined && objScale > 0){
				w *= objScale;
				h *= objScale;
			}

			var newCoords = this.calculateCoords(objX, objY, w, h);
			this.hintObject.objectX = newCoords[0];
			this.hintObject.objectY = newCoords[1];
			this.hintObject.objectWidth = newCoords[2];
			this.hintObject.objectHeight = newCoords[3];

			this.hintObject.showObject();
			if ("playObject" in this.hintObject)
				this.hintObject.playObject();
		}
	}

	function displayShadow(objectX, objectY, objectWidth, objectHeight){
		if(this.shadowObject){
			this.shadowObject.x = objectX + this.shadowX;
			this.shadowObject.y = objectY + this.shadowY;
			this.shadowObject.width = objectWidth;
			this.shadowObject.height = objectHeight;
			this.shadowObject.visible = true;
		}
	}
	
	// функция пересчета и вписывания в определённую область
	function calculateCoords(objectX, objectY, objectWidth, objectHeight){
		var hintX = 0;
		var hintY = 0;
		var hintWidth = 0;
		var hintHeight = 0;		
		var newCoords = new Array();
		if((objectX + objectWidth + 10) > Player.module.scenes.width){
			hintX = (objectX - objectWidth) - 10;
		} else {
			hintX = objectX + 10;
		};
		if((objectY + objectHeight + 10) > Player.module.scenes.height){
			if((objectY - objectHeight) - 10 < 0){
				//hintY = objectY - Math.round(objectHeight/2);
				hintY = 0;
			} else {
				hintY = (objectY - objectHeight) - 10;
			}
		} else {
			hintY = objectY + 10;
		};
		
		newCoords.push(hintX);
		newCoords.push(hintY);
		newCoords.push(objectWidth);
		newCoords.push(objectHeight);

		return newCoords;
	}

]]></script>
</composition>
</rmml>