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

last change: $Date: 2008-09-30 19:58:58 +0400 (Вт, 30 сен 2008) $
             $Author: toha $

  Lacerta Project
  version 1.0.0.1
  Copyright (C) 2008 RNMC
-->
<composition name="rnmc_stdStepList" class="rnmc_stdMediaGroup" x="0" y="0">
<script><![CDATA[

  this.objectHitArea = null;

// элемент список
  this.listX = 0;
  this.listY = 0;
//  this.listWidth = 0;
  this.listHeight = 0;
  this.listDepth  = 0;
  this.listControl = null;
  this.listVisible = true;
  this.listSelectedColor = "";
  this.listCurrentColor = "";
  this.visitedMarkSrc = null;
  this.visitedMarkItem = -1;
  
//  параметры отдельных элементов списка
  this.oddStep  = null;
  this.evenStep  = null;
  this.defaultStep  = null;

//  
  this.mouseStateOver = false;

  function initFromNode(srcNode){
    var xmlNode = null;
    var xmlAttributeMap = null;
    var xmlAttribute = null;

    this.x = 0;
    this.y = 0;
    this.childObjects =  new Array();

    this.columnsWidth = new Array();

    var srcBase = null;
    if (srcNode.ownerDocument.source){
      var tmp = new String(srcNode.ownerDocument.source).replace("/\/.g", "\\").split("\\")
      tmp.pop();
      srcBase = tmp.join("\\");
    }

    xmlAttributeMap = srcNode.attributes;
    if (xmlAttributeMap){
      xmlAttribute =  xmlAttributeMap.getNamedItem("id");
      if (xmlAttribute != null && xmlAttribute.specified)
        this.id = xmlAttribute.value;
      xmlAttribute = xmlAttributeMap.getNamedItem("visible");
      if (xmlAttribute != null && xmlAttribute.specified){
        if(xmlAttribute.value == "true")
          this.visibility = OBJECT_VISIBILITY_TRUE;
        else if(xmlAttribute.value == "false")
          this.visibility = OBJECT_VISIBILITY_FALSE;
      }
      xmlAttribute =  xmlAttributeMap.getNamedItem("enabled");
      if (xmlAttribute != null && xmlAttribute.specified && xmlAttribute.value == "false")
        this.disabled = true;
      xmlAttribute =  xmlAttributeMap.getNamedItem("restriction");
      if (xmlAttribute != null && xmlAttribute.specified){
        switch((xmlAttribute.value).toLowerCase()){
        case "exclusive_visible":
          this.watchRestriction = RESTRICTION_EXCLUSIVE_VISIBLE;
           break;
        case "exclusive_pressed":
          this.watchRestriction = RESTRICTION_EXCLUSIVE_PRESSED;
          break;
        default:
          trace("rnmc_stdGroup: неизвестное ограничение (restriction == " + xmlAttribute.value + ")");
          break;
        }
      }
    }
    xmlNode = srcNode.firstChild;
    this.loadChildsObject(srcNode);
    while(xmlNode){
      if(xmlNode.nodeName == "param"){
        this.parseParamNode(xmlNode);

        xmlAttributeMap = xmlNode.attributes;
        if (xmlAttributeMap){
/*
          xmlAttribute =  xmlAttributeMap.getNamedItem("x");
          if (xmlAttribute != null && xmlAttribute.specified)
            this.x = parseInt(xmlAttribute.value);
          xmlAttribute =  xmlAttributeMap.getNamedItem("y");
          if (xmlAttribute != null && xmlAttribute.specified)
            this.y = parseInt(xmlAttribute.value);
          xmlAttribute =  xmlAttributeMap.getNamedItem("depth");
          if (xmlAttribute != null && xmlAttribute.specified)
            this.depth = parseInt(xmlAttribute.value);
*/
          xmlAttribute =  xmlAttributeMap.getNamedItem("hitArea");
          if (xmlAttribute != null && xmlAttribute.specified)
            this.objectHitArea = xmlAttribute.value;
        }
      } else if(xmlNode.nodeName == "actions"){
      //  пока используется местное переопределение
      //  требуется доделывать медиа-группу
        this.parseActionsNode(xmlNode);
      } else if(xmlNode.nodeName == "effects"){
        this.parseEffectsNode(xmlNode);
      } else if(xmlNode.nodeName == "condition"){
        this.parseConditionNode(xmlNode);
      } else if(xmlNode.nodeName == "list"){
        var tableNode = xmlNode.firstChild;
        while(tableNode){
          if(tableNode.nodeName == "param"){
            xmlAttributeMap = tableNode.attributes;
            if (xmlAttributeMap){
              xmlAttribute =  xmlAttributeMap.getNamedItem("visible");
              if (xmlAttribute != null && xmlAttribute.specified){
                if((xmlAttribute.value).toLowerCase() == "false"){
                  this.listVisible = false;
                } else {
                  this.listVisible = true;
                }
              }
              xmlAttribute =  xmlAttributeMap.getNamedItem("x");
              if (xmlAttribute != null && xmlAttribute.specified)
                this.listX = parseInt(xmlAttribute.value);
              xmlAttribute =  xmlAttributeMap.getNamedItem("y");
              if (xmlAttribute != null && xmlAttribute.specified)
                this.listY = parseInt(xmlAttribute.value);
              xmlAttribute =  xmlAttributeMap.getNamedItem("width");
              if (xmlAttribute != null && xmlAttribute.specified)
                this.listWidth = parseInt(xmlAttribute.value);
              xmlAttribute =  xmlAttributeMap.getNamedItem("height");
              if (xmlAttribute != null && xmlAttribute.specified)
                this.listHeight = 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;
              xmlAttribute =  xmlAttributeMap.getNamedItem("depth");
              if (xmlAttribute != null && xmlAttribute.specified)
                this.listDepth = parseInt(xmlAttribute.value);
            }
          } else if(tableNode.nodeName == "visitedmark"){
            xmlAttributeMap = tableNode.attributes;
            if (xmlAttributeMap){
              xmlAttribute =  xmlAttributeMap.getNamedItem("src");
              if (xmlAttribute != null && xmlAttribute.specified)
                this.visitedMarkSrc =
                  scene.Utils.makePathSrc(srcBase, xmlAttribute.value);
            }
          } else if(tableNode.nodeName == "step"){
            var itemNode = tableNode.firstChild;
            var newStep = new Array();
            var newColWidth = new Array();
            xmlAttributeMap = tableNode.attributes;
            if (xmlAttributeMap){
              xmlAttribute =  xmlAttributeMap.getNamedItem("id");
              if (xmlAttribute != null && xmlAttribute.specified){
                if((xmlAttribute.value).toLowerCase() == "even"){
                  newStep.id = "even";
                } else if((xmlAttribute.value).toLowerCase() == "odd"){
                  newStep.id = "odd";
                } else if((xmlAttribute.value).toLowerCase() == "total"){
                  newStep.id = "total";
                }
              } else {
                newStep.id = "default";
              }
            }

            while(itemNode){
              if(itemNode.nodeName == "item" && itemNode.textContent){
                var newItem = new Array();
                xmlAttributeMap = itemNode.attributes;
                if (xmlAttributeMap){
                  xmlAttribute =  xmlAttributeMap.getNamedItem("width");
                  if (xmlAttribute != null && xmlAttribute.specified){
                    newItem.width = parseInt(xmlAttribute.value);
                    newColWidth.push(newItem.width);
                  }
                  xmlAttribute =  xmlAttributeMap.getNamedItem("style");
                  if (xmlAttribute != null && xmlAttribute.specified)
                    newItem.style = xmlAttribute.value;
                  xmlAttribute =  xmlAttributeMap.getNamedItem("bgColor");
                  if (xmlAttribute != null && xmlAttribute.specified)
                    newItem.bgColor = xmlAttribute.value;
                  newItem.content = itemNode.textContent;
                }
                newStep.push(newItem);
              }
              itemNode = itemNode.nextSibling;
            }
          //  записываем актуальные значения ширины каждого столбца
          //  (надо для списка, но его надо переделать)
            for(var i = 0; i < newColWidth.length; i++){
              if(this.columnsWidth[i]){
                if(newColWidth[i] > this.columnsWidth[i]){
                  this.columnsWidth[i] = newColWidth[i];
                }
              } else {
                this.columnsWidth[i] = newColWidth[i];
              }
            }
            switch(newStep.id){
            case "even":
              this.evenStep  = newStep;
              break;
            case "odd":
              this.oddStep  = newStep;
              break;
            case "default":
              this.defaultStep  = newStep;
              break;
            }
          } 
          tableNode = tableNode.nextSibling;
        }
      } 
      xmlNode = xmlNode.nextSibling;
    }
  //  если есть ограничения на нажатия кнопок
    if(this.watchRestriction == RESTRICTION_EXCLUSIVE_PRESSED){
      for(var i = 0; i < this.childObjects.length; i++){
        if(this.childObjects[i].type == "rnmc_stdButton"){
          this.childObjects[i].setPressCallBack(this, this.notifyChildButtonPressed);
          this.childObjects[i].setReleaseCallBack(this, this.notifyChildButtonPressed);
        }
      }
    }
    return true;
  };

//  переопределен для корректной работы onRollOver, onRollOut
  function parseActionsNode(srcNode){
    var xmlAttributeMap = null;
    var xmlAttribute = null;

    if(srcNode.nodeName == "actions"){
      if(!this.stepListActions)
        this.stepListActions = new Array();
      newActionsArray = scene.Utils.parseActionsNode(srcNode, "onRollOver");
      if(newActionsArray && newActionsArray.length > 0){
        this.stepListActions[EVENT_ON_ROLLOVER] = new Array();
        for(var i = 0 ; i < newActionsArray.length; i++)
          this.stepListActions[EVENT_ON_ROLLOVER].push(newActionsArray[i]);
      }
      newActionsArray = scene.Utils.parseActionsNode(srcNode, "onRollOut");
      if(newActionsArray && newActionsArray.length > 0){
        this.stepListActions[EVENT_ON_ROLLOUT] = new Array();
        for(var i = 0 ; i < newActionsArray.length; i++)
          this.stepListActions[EVENT_ON_ROLLOUT].push(newActionsArray[i]);
      }
      if(!this.actionsList)
        this.actionsList = new Array();
      newActionsArray = scene.Utils.parseActionsNode(srcNode, "onShow");
      if(newActionsArray && newActionsArray.length > 0){
        this.actionsList[EVENT_ON_SHOW] = new Array();
        for(var i = 0 ; i < newActionsArray.length; i++)
          this.actionsList[EVENT_ON_SHOW].push(newActionsArray[i]);
      }
      newActionsArray = scene.Utils.parseActionsNode(srcNode, "onHide");
      if(newActionsArray && newActionsArray.length > 0){
        this.actionsList[EVENT_ON_HIDE] = new Array();
        for(var i = 0 ; i < newActionsArray.length; i++)
          this.actionsList[EVENT_ON_HIDE].push(newActionsArray[i]);
      }
      newActionsArray = scene.Utils.parseActionsNode(srcNode, "onStartEffect");
      if(newActionsArray && newActionsArray.length > 0){
        this.actionsList[EVENT_ON_START_EFFECT] = new Array();
        for(var i = 0 ; i < newActionsArray.length; i++)
          this.actionsList[EVENT_ON_START_EFFECT].push(newActionsArray[i]);
      }
      newActionsArray = scene.Utils.parseActionsNode(srcNode, "onCompleteEffect");
      if(newActionsArray && newActionsArray.length > 0){
        this.actionsList[EVENT_ON_COMPLETE_EFFECT] = new Array();
        for(var i = 0 ; i < newActionsArray.length; i++)
          this.actionsList[EVENT_ON_COMPLETE_EFFECT].push(newActionsArray[i]);
      }
      newActionsArray = null;
    }
    return true;
  }

  function showObject(){
    rnmc_stdMediaGroup_showObject();
    //  искусственное 
    if(this.objectHitArea && this.stepListActions && 
      (this.stepListActions[EVENT_ON_ROLLOVER] || this.stepListActions[EVENT_ON_ROLLOUT])){

      // Делаем заплатку для совместимости с версиями плеера 1 и 2 
      if (this.objectHitArea != "bounds" &&
          this.objectHitArea != "opacity" &&
          !Player.version){
        this.groupArea = new Button();
        this.groupArea.parent = this;
        this.groupArea.depth = 100;
        this.groupArea.hitArea = this.objectHitArea;
        this.groupArea.visible = true;
      }
      this.onMouseMove = mouseMoveHandler;

      this.hitArea = this.objectHitArea;
      this.onMouseMove = mouseMoveHandler;
    }
    if(!this.listControl){
      this.listControl = new Composition();
      this.listControl._class = "common_list";
      this.listControl.parent  = this;
      this.listControl.x = this.listX;
      this.listControl.y = this.listY;
      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.columnsWidth.length; i++){
        listWidth += this.columnsWidth[i];
      }
      this.listControl.initList(listWidth, this.listHeight,
        this.columnsWidth.length, this.columnsWidth);
      this.listControl.depth = this.listDepth;
      this.listControl.setReleaseCallback(this, this.onListItemSelected);

    // создание новых строк
      var totalSteps = parent.resultManager.getStepsTotal();
      for(var i = 0; i  < totalSteps; i++)
        this.listControl.addListItem();

      for(var i = 0; i  < totalSteps; i++){
        var currentStepSettings = null;
        if(this.evenStep && this.oddStep){
          if(((i + 1) % 2) == 0){
            currentStepSettings =  this.evenStep;
          } else {
            currentStepSettings = this.oddStep;
          }
        } else {
          currentStepSettings = this.defaultStep;
        }

        for(var j = 0; currentStepSettings && j < currentStepSettings.length; j++){
          var srcItemStr = currentStepSettings[j].content;
          var newListItem = null;    
          if(srcItemStr.indexOf("%VisitedMark%") >= 0){
            newListItem = new Image();
            newListItem.src = this.visitedMarkSrc;
            newListItem.visible = false;
            this.visitedMarkItem = j;
          } else {
            var re = new RegExp("(%StepIndex%)", "g");
            srcItemStr = srcItemStr.replace(re, (i+1));
            re = null;
            re = new RegExp("(%StepName%)", "g");
            srcItemStr = srcItemStr.replace(re, parent.resultManager.getStepName(i));
            re = null;

            newListItem = new Text();
            newListItem.width = this.listControl.getColumnWidth(j);
            newListItem.value = srcItemStr;
            newListItem.adjustHeight = true;
            if(currentStepSettings[j].style
              && scene.StyleManager.styleExists(currentStepSettings[j].style))
              newListItem.style = currentStepSettings[j].style;
            if(currentStepSettings[j].bgColor)
              newListItem.bkgColor = currentStepSettings[j].bgColor;
          }
          this.listControl.setRowObject(i, j, newListItem);
          newListItem = null;
        }
      }

      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();
    }
  }

// обработчик выбора некоторого шага
  function onListItemSelected(itemId){
    parent.startStep(itemId);
  }

// помечает текущий шаг
  function selectCurrentStep(stepId){
    this.listControl.markSeletedItem(stepId);
    this.listControl.showRowContent(stepId, this.visitedMarkItem);
  }

  function dispatchAction(singleAction){
    this.doAction(singleAction);
  }

//  необходима для праильного отслеживания съезда и наезда на группу (весь список)
  function mouseMoveHandler(){
    var testX = Mouse.x;
    var testY = Mouse.y;
    
    var is_in_zone = false;
    
    if (this.objectHitArea == "bounds" ||
        this.objectHitArea == "opacity" ||
        Player.version){
      is_in_zone = this.isPointIn(testX, testY);
    } else {
      is_in_zone = this.groupArea.isPointIn(testX, testY);
    }
   
    if(is_in_zone){
      if(this.mouseStateOver == false){
        if(this.stepListActions && this.stepListActions[EVENT_ON_ROLLOVER]){
          for(var i = 0; i < this.stepListActions[EVENT_ON_ROLLOVER].length; i++){
            this.dispatchAction(this.stepListActions[EVENT_ON_ROLLOVER][i]);
          }
        }
        this.mouseStateOver = true;
      }
    } else {
      if(this.mouseStateOver == true){
        if(this.stepListActions && this.stepListActions[EVENT_ON_ROLLOUT]){
          for(var i = 0; i < this.stepListActions[EVENT_ON_ROLLOUT].length; i++){
            this.dispatchAction(this.stepListActions[EVENT_ON_ROLLOUT][i]);
          }
        }
        this.mouseStateOver = false;
      }
    }
  }
]]> </script>
</composition>
</rmml>
