//
// Tutorial script
//


// Callback for mouse move events
function SceneGui::onMouseMove(%this)
{
   if(%this.redSlashedCursorShow $= true)
   {
      %pos = Canvas.getCursorPos();
      %x = getWord(%pos, 0);
      %y = getWord(%pos, 1);
      %rect2 = GuiCenter.getPosition();
      %this.redSlashedCursor.setPosition(%x-25 - getWord(%rect2,0), %y-25 - getWord(%rect2,1));
   }
   
   if(%this.tutIsPlaying $= true)
      %this.schedule(33, "onMouseMove");
}

// This function only initializes the tutorial variables.
// For playing the tutorial, call SceneGui.playTutorial().
function SceneGui::initTutorial(%this)
{
   %this.tutIsPlaying = false;
   %this.tutCurState = 0;
   %this.doNotReplay = false;
   
   // Number of items in SceneGui.clickTutButton (beginning from index 0)
   %this.tutClickButtonNum = 0;
   // List of objects marked as clickable for the current tutorial state
   // Range is 0 to SceneGui.clickTutButton-1
   %this.tutClickButton[0] = false;   
      
   if($PlayTutorial !$= true)
      return;
   
   // Saved meter position and number of shopping list items
   %this.savedMeterPositionRight = $pref::MeterPositionRight;
   %this.savedNShoppingListItems5 = $pref::NShoppingListItems5;
   
   $pref::MeterPositionRight = "true";
   $pref::NShoppingListItems5 = "false";
         
   // Create a red slashed circle for showing when a wrong GUI element
   // is clicked during the tutorial
   %this.redSlashedCursor = new GuiBitmapCtrl() {
      canSaveDynamicFields = "0";
      Enabled = "1";
      isContainer = "0";
      HorizSizing = "relative";
      VertSizing = "relative";
      Position = "0 0";
      Extent = "50 50";
      MinExtent = "2 2";
      canSave = "1";
      Visible = "0";
      hovertime = "1000";
      alpha = "1";
      color = "255 255 255 255";
      unitClip = "0 0 1 1";
      bitmap = "scriptsAndAssets/data/ui/tutorial/wrong";
      wrap = "0";
   };

   GuiCenter.add(%this.redSlashedCursor);
   GuiCenter.pushToBack(%this.redSlashedCursor);
   
   %this.redSlashedCursorEventID = -1;
   %this.redSlashedCursorShow = false;
}

// This function returns TRUE if the object %button is clickable for the
// current tutorial state. FALSE otherwise
function SceneGui::isClickable(%this, %button)
{
   if(%this.tutIsPlaying $= false)
      return true;
   
   // Iterate through the list of clickable items
   for(%i=0; %i<%this.tutClickButtonNum; %i++)
   {
      if(%this.tutClickButton[%i] $= %button)
      {
         // Check for specific behavior of each tutorial state
         if(%this.tutCurState $= 5)
         {
            if(%button $= ButtonCam4)
               %this.onTutorialBoxArrow();
         }
         
         if(%this.tutCurState $= 7)
         {
            if(%button $= ButtonCam2)
               %this.onTutorialBoxArrow();            
         }
         
         if(%this.tutCurState $= 13) // 13
         {
            if(%button $= ShopButton7)
               %this.onTutorialBoxArrow();
         }

         return true;
      }
   }

   %this.enableRedSlashedCursor(0.5);
   
   return false;
}

// Shows a red slashed circle cursor for %time seconds
function SceneGui::enableRedSlashedCursor(%this, %time)
{
   %this.redSlashedCursorShow = true;
   
   // Show red slashed cursor
   if(isEventPending(%this.redSlashedCursorEventID))
      cancel(%this.redSlashedCursorEventID);
   else
   {
      Canvas.hideCursor();
   }

   %pos = Canvas.getCursorPos();
   %x = getWord(%pos, 0);
   %y = getWord(%pos, 1);
   %rect2 = GuiCenter.getPosition();
   %this.redSlashedCursor.setPosition(%x-25 - getWord(%rect2,0), %y-25 - getWord(%rect2,1));
      
   %this.onMouseMove();
   %this.redSlashedCursor.setVisible(true);
   %this.schedule(%time * 1000, "disableRedSlashedCursor");
}

// Hides the red slashed circle cursor enabled by 
// SceneGui::enableRedSlashedCursor
function SceneGui::disableRedSlashedCursor(%this)
{
   %this.redSlashedCursorShow = false;
   %this.redSlashedCursor.setVisible(false);
   
   %pos = Canvas.getCursorPos();
   Canvas.setCursorPos(%pos);
   Canvas.showCursor();
}

// Plays the tutorial (only works when called at Spy Take 1)
function SceneGui::playTutorial(%this)
{
   if($PlayTutorial !$= true)
      return;
   
   if($CurSceneName !$= "SpyLevel" || $CurTake !$= 1)
   {
      echo("Tutorial only works at Spy Level Take 1");
      return;
   }
   
   PauseDummy.setVisible(false);   
   
   MissionInfo.timelineAniRef = "";
      
   %this.loadTutorialXML();
   
   TutorialBox.setVisible(true);
   TutorialBoxArrow.setVisible(true);
   TutorialBoxArrowText.setText(%this.continueText);
   TutorialBoxArrowText.setVisible(true);
   TutorialBoxSkip.setVisible(true);   
   
   %this.tutIsPlaying = true;
   
   %this.tutCurState = 0;
   
   %this.enterTutorial1();
}

// Called when the arrow at the tutorial box is clicked
function SceneGui::onTutorialBoxArrow(%this)
{
   %state = %this.tutCurState;
   %text = "%this.exitTutorialState" @ %state @ "();";
   eval(%text);
   %text = "%this.enterTutorialState" @ %state+1 @ "();";
   eval(%text);   
}

// Grays out and disable (if %state is TRUE) or not (if %state is FALSE) a given
// minicamera (%number, between 1-4)
function SceneGui::grayOutCamera(%this, %number, %state)
{
   %obj = ("Cam" @ %number);
   
   if(%state $= true)
   {
      %obj.useOverlayColor = true;
      %obj.setOverlayColor(0.5, 0.5, 0.5, 1);
   }
   else
   {
      %obj.useOverlayColor = false;
   }
}

// Parse XML file looking for tutorial text tags
function SceneGui::loadTutorialXML(%this)
{
   echo("Load Tutorial XML");
   %path = "./scriptsAndAssets/data/ui/tutorial/tutorial.xml";
      
   %pXml = new SimXMLDocument();
   // Load and parse XML file.
   if(!%pXml.loadFile(%path))
   {
      echo("Failed to load " @ %path);
      return;
   }
   
   // Push the first child element named "tutorial" onto 
   // the XML document stack.
   if(!%pXml.pushFirstChildElement("tutorial"))
   {
      echo("Failed to load tutorial tag.");
      return;
   }
   
   %this.continueText = %pXml.attribute("continuetext");
      
   %this.dirTriggerNum = 0;
   if(!%pXml.pushFirstChildElement("state"))
   {
      echo("Tutorial state tags not found.");
      return;
   }
   
   while(true)
   {
      // State number
      %stateNum = %pXml.attributeS32("number");
            
      %textNum = 0;
      if(%pXml.pushFirstChildElement("bubble"))
      {
         %text = %pXml.attribute("text");
         echo("Text: " @ %text);
         %this.tutTrigger[%stateNum,"text",%textNum]    = %pXml.attribute("text");
         %this.tutTrigger[%stateNum,"imageid",%textNum] = %pXml.attributeS32("imageid");               
         %textNum++;            
         
         while(true)
         {
            // Go to next bubble tag
            if(%pXml.nextSiblingElement("bubble"))
            {
               %text = %pXml.attribute("text");
               echo("Text: " @ %text);
               %this.tutTrigger[%stateNum,"text",%textNum]    = %pXml.attribute("text");
               %this.tutTrigger[%stateNum,"imageid",%textNum] = %pXml.attributeS32("imageid");
               %textNum++;
            }
            else
            {
               %this.tutTrigger[%stateNum,"text",%textNum] = "";
               break;
            }
         }
         %pXml.popElement();
      }
      else
         %this.tutTrigger[%stateNum,"text",%textNum] = "";      
      
      // Go to next animation tag
      if(!%pXml.nextSiblingElement("state"))
         break;
   }
   
   %pXml.popElement();
   
   %pXml.delete();   
}

// Show the highlight effect in a given shopping list item
function SceneGui::playPulseHint(%this, %itemIdx)
{
   %winScaleX = 1.0 / 800 * getWord(GuiCenter.getExtent(),0);
   %winScaleY = 1.0 / 600 * getWord(GuiCenter.getExtent(),1);
   
   %obj = ("ShopItem"@%itemIdx);
   %shopItemX = getWord(%obj.getPosition(),0);
   %shopItemY = getWord(%obj.getPosition(),1);
   %shopItemW = getWord(%obj.getExtent(),0);
   %shopItemH = getWord(%obj.getExtent(),1);
   
   %extX = getWord(ClickHintEffect.getExtent(),0);
   %extY = getWord(ClickHintEffect.getExtent(),1);
   
   %posX = %shopItemX + (%shopItemW - %extX) / 2;
   %posY = %shopItemY + (%shopItemH - %extY) / 2;
   
   ClickHintEffect.setPosition(%posX, %posY);
   ClickHintEffect.setAlpha(1);
   ClickHintEffect.setVisible(true);

   ClickHintEffect.setFps(0);
   ClickHintEffect.rewind();
   ClickHintEffect.play(false);   
}

// Stop the highlight effect played with SceneGui.playPulseHint
function SceneGui::stopPulseHint(%this)
{
   ClickHintEffect.stop();
   ClickHintEffect.setVisible(false);
}

// Show a pulsing arrow pointing at a given camera
function SceneGui::showCamArrow(%this, %camIdx)
{
   %winScaleX = 1.0 / 800 * getWord(GuiCenter.getExtent(),0);
   %winScaleY = 1.0 / 600 * getWord(GuiCenter.getExtent(),1);
   
   %camPos[1] = "55 438";
   %camPos[2] = "232 420";
   %camPos[3] = "370 425";
   %camPos[4] = "523 427";
   %camPos[5] = "630 70";
   
   ("TutorialArrow"@%camIdx).setPosition(
      getWord(%camPos[%camIdx],0)*%winScaleX, 
      getWord(%camPos[%camIdx],1)*%winScaleY);
   ("TutorialArrow"@%camIdx).setAlpha(0.4);
   ("TutorialArrow"@%camIdx).setVisible(true);   
 
   %this.blinkPulseCamArrow[%camIdx] = true;
   %this.stopPulseCamArrow[%camIdx] = false;
   %this.pulseCamArrowFadeIn(%camIdx);
}

// Used by SceneGui::showCamArrow
function SceneGui::pulseCamArrowFadeIn(%this, %camIdx)
{
   if(%this.stopPulseCamArrow[%camIdx] $= true)
   {
      ("TutorialArrow"@%camIdx).setVisible(false);
      return;
   }
      
   if(%this.blinkPulseCamArrow[%camIdx] $= true)
      ("TutorialArrow"@%camIdx).animateAlpha(1, 0, 300, "0 0");
   else
      ("TutorialArrow"@%camIdx).setAlpha(1);
   %this.pulseCamArrowID[%camIdx] = scheduleObjLCA(%this, "Tutorial", 300, "pulseCamArrowFadeOut", 1, %camIdx);
}

// Used by SceneGui::showCamArrow
function SceneGui::pulseCamArrowFadeOut(%this, %camIdx)
{
   if(%this.blinkPulseCamArrow[%camIdx] $= true)
      ("TutorialArrow"@%camIdx).animateAlpha(0.4, 0, 300, "0 0");
   else
      ("TutorialArrow"@%camIdx).setAlpha(1);
   %this.pulseCamArrowID[%camIdx] = scheduleObjLCA(%this, "Tutorial", 300, "pulseCamArrowFadeIn", 1, %camIdx);
}

// Stop the pulsing arrow at a given camera
function SceneGui::hideCamArrow(%this, %camIdx)
{
   cancelScheduleLCA(%this.pulseCamArrowID[%camIdx]);
   %this.stopPulseCamArrow[%camIdx] = true;
   ("TutorialArrow"@%camIdx).setAlpha(0);
}

function SceneGui::setBlinkCamArrow(%this, %camIdx, %blink)
{
   %this.blinkPulseCamArrow[%camIdx] = %blink;
}

// Show the tutorial text box and contents
function SceneGui::showTutorialTextBox(%this)
{
   TutorialBox.animateAlpha(1, 0, 100, "0 0");
   TutorialBoxText.animateAlpha(1, 0, 100, "0 0");
   TutorialBoxArrow.animateAlpha(1, 0, 100, "0 0");
   TutorialBoxArrowText.animateAlpha(1, 0, 100, "0 0");
   TutorialBoxSkip.animateAlpha(1, 0, 100, "0 0");
}

// Hide the tutorial text box and contents
function SceneGui::hideTutorialTextBox(%this)
{
   TutorialBox.animateAlpha(0, 0, 100, "0 0");
   TutorialBoxText.animateAlpha(0, 0, 100, "0 0");
   TutorialBoxArrow.animateAlpha(0, 0, 100, "0 0");
   TutorialBoxArrowText.animateAlpha(0, 0, 100, "0 0");
}

// Start pulsing a camera red light
function SceneGui::startPulseCamLight(%this, %lightIdx)
{
   %this.stopPulseCamLight[%lightIdx] = false;
   %this.pulseCamLight1(%lightIdx);
}

// Stop pulsing a camera red light
function SceneGui::stopPulseCamLight(%this, %lightIdx)
{
   %this.stopPulseCamLight[%lightIdx] = true;
}

// Used by SceneGui::startPulseCamLight
function SceneGui::pulseCamLight1(%this, %lightIdx)
{
   %obj = ("CamLight"@%lightIdx);   
   
   if(%this.stopPulseCamLight[%lightIdx] $= true)
   {
      %obj.setAlpha(1);
      return;
   }
   
   %obj.animateAlpha(0, 0, 500, "0 0");
   scheduleObjLCA(%this, "Tutorial", 500, "pulseCamLight2", 1, %lightIdx);   
}

// Used by SceneGui::startPulseCamLight
function SceneGui::pulseCamLight2(%this, %lightIdx)
{
   %obj = ("CamLight"@%lightIdx);
   %obj.animateAlpha(1, 0, 500, "0 0");
   scheduleObjLCA(%this, "Tutorial", 500, "pulseCamLight1", 1, %lightIdx);   
}

// Pause HO game for tutorial
function SceneGui::pauseHOGameTutorial(%this)
{   
   // Pause elapsed time
   %this.elapsedTimePause = getRealTime();
  
   pauseAnims();
   
   pauseSchedulesLCA("HO");
   
   %this.pauseTriggerCtrl();
   
   %this.pauseAudio();
}

// Resume HO game previously paused with SceneGui::pauseHOGameTutorial
function SceneGui::resumeHOGameTutorial(%this)
{
   resumeSchedulesLCA("HO");
   
   %this.resumeTriggerCtrl();
   
   %this.resumeAudio();
 
   // Resume elapsed time
   %this.timeElapsedBase += getRealTime()-%this.elapsedTimePause;
   
   resumeAnims();  
}










// State #1
function SceneGui::enterTutorial1(%this)
{
   PauseDummy.setVisible(false);
   
   %this.tutCurState = 1;
      
   // Disable cameras 1, 3 and 4
   Cam1.useOverlayColor = true;
   Cam3.useOverlayColor = true;
   Cam4.useOverlayColor = true;
   Cam1.setOverlayColor(0.5, 0.5, 0.5, 1);
   Cam3.setOverlayColor(0.5, 0.5, 0.5, 1);
   Cam4.setOverlayColor(0.5, 0.5, 0.5, 1);
   
   // Show text box
   %text = %this.tutTrigger[%this.tutCurState,"text",0];
   TutorialBoxText.setText(%text);
   TutorialBoxText.setVisible(true);
   %this.showTutorialTextBox();
}

function SceneGui::exitTutorialState1(%this)
{
   TutorialBoxSkip.animateAlpha(0, 0, 250, "0 0");
}

// State #2
function SceneGui::enterTutorialState2(%this)
{
   %this.tutCurState = 2;
   %text = %this.tutTrigger[%this.tutCurState,"text",0];
   TutorialBoxText.setText(%text);
   
   %this.showCamArrow(1);
   %this.showCamArrow(2);
   %this.showCamArrow(3);
   %this.showCamArrow(4);
}

function SceneGui::exitTutorialState2(%this)
{
   TutorialBoxSkip.setVisible(false);
}

// State #3
function SceneGui::enterTutorialState3(%this)
{
   %this.tutCurState = 3;
   %text = %this.tutTrigger[%this.tutCurState,"text",0];
   TutorialBoxText.setText(%text);
}

function SceneGui::exitTutorialState3(%this)
{
   %this.hideCamArrow(1);
   %this.hideCamArrow(3);
   %this.hideCamArrow(4);   
}

// State #4
function SceneGui::enterTutorialState4(%this)
{
   %winScaleX = 1.0 / 800 * getWord(GuiCenter.getExtent(),0);
   %winScaleY = 1.0 / 600 * getWord(GuiCenter.getExtent(),1);
   
   %this.tutCurState = 4;
   %text = %this.tutTrigger[%this.tutCurState,"text",0];
   TutorialBoxText.setText(%text);
      
   // Offset the text box towards above
   TutorialBoxArrow.setPosition(498*%winScaleX, (372-45)*%winScaleY); // 508 380
   TutorialBoxArrowText.setPosition(490*%winScaleX, (395-45)*%winScaleY);
   TutorialBox.setPosition(87*%winScaleX, (352-45)*%winScaleY);
   TutorialBoxText.setPosition(147*%winScaleX, (357-45)*%winScaleY);
   
   // Offset the arrow #2 so it points to red light
   %this.setBlinkCamArrow(2, false);
   TutorialArrow2.setPosition(252*%winScaleX, 380*%winScaleY);
   
   %this.triggerCamBorder(2);
   %this.startPulseCamLight(2);
}

function SceneGui::exitTutorialState4(%this)
{
   %winScaleX = 1.0 / 800 * getWord(GuiCenter.getExtent(),0);
   %winScaleY = 1.0 / 600 * getWord(GuiCenter.getExtent(),1);
   
   // Offset the text box to original position
   TutorialBoxArrow.setPosition(498*%winScaleX, (372-0)*%winScaleY);
   TutorialBoxArrowText.setPosition(490*%winScaleX, (395-0)*%winScaleY);
   TutorialBox.setPosition(87*%winScaleX, (352-0)*%winScaleY);
   TutorialBoxText.setPosition(147*%winScaleX, (357-0)*%winScaleY);
   
   %this.hideCamArrow(2);
   cancelScheduleLCA(%this.triggerCamEventID);
   %this.stopPulseCamLight(2);   
}

// State #5
function SceneGui::enterTutorialState5(%this)
{
   %this.tutCurState = 5;
   %text = %this.tutTrigger[%this.tutCurState,"text",0];
   TutorialBoxText.setText(%text);

   Cam4.useOverlayColor = false;
   %this.showCamArrow(4);
   %this.setBlinkCamArrow(4, false);
   
   %this.triggerCamBorder(4);
   TutorialBoxArrow.setVisible(false);
   TutorialBoxArrowText.setVisible(false);
   
   %this.tutClickButtonNum = 1;
   %this.tutClickButton[0] = ButtonCam4;
}

function SceneGui::exitTutorialState5(%this)
{
   %this.hideCamArrow(4);
   %this.tutClickButtonNum = 0;
   
   cancelScheduleLCA(%this.triggerCamEventID);
   BorderCam4.setAlpha(0);
   BorderCam4.Visible = false;
}

// State #6
function SceneGui::enterTutorialState6(%this)
{   
   // Unpause camera 4
   Camera4.playThread(0);
   
   %this.tutCurState = 6;
   %text = %this.tutTrigger[%this.tutCurState,"text",0];
   TutorialBoxText.setText(%text);
   
   TutorialBoxArrow.setVisible(true);
   TutorialBoxArrowText.setVisible(true);
}

function SceneGui::exitTutorialState6(%this)
{
}

// State #7
function SceneGui::enterTutorialState7(%this)
{
   %this.tutCurState = 7;
   %text = %this.tutTrigger[%this.tutCurState,"text",0];
   TutorialBoxText.setText(%text);
   
   %this.showCamArrow(2);
   %this.setBlinkCamArrow(2, false);
   
   %this.triggerCamBorder(2);
   TutorialBoxArrow.setVisible(false);
   TutorialBoxArrowText.setVisible(false);
   
   %this.tutClickButtonNum = 1;
   %this.tutClickButton[0] = ButtonCam2;   
}

function SceneGui::exitTutorialState7(%this)
{
   %this.hideCamArrow(2);
   %this.tutClickButtonNum = 0;
   
   cancelScheduleLCA(%this.triggerCamEventID);
   BorderCam2.setAlpha(0);
   BorderCam2.Visible = false;   
   
//   Cam1.useOverlayColor = false;
//   Cam3.useOverlayColor = false;
}

// State #8
function SceneGui::enterTutorialState8(%this)
{
   %winScaleX = 1.0 / 800 * getWord(GuiCenter.getExtent(),0);
   %winScaleY = 1.0 / 600 * getWord(GuiCenter.getExtent(),1);
   
   %this.tutCurState = 8;
   %text = %this.tutTrigger[%this.tutCurState,"text",0];
   TutorialBoxText.setText(%text);
   
   // Offset the text box towards above
   TutorialBoxArrow.setPosition(498*%winScaleX, (372-325)*%winScaleY);
   TutorialBoxArrowText.setPosition(490*%winScaleX, (395-325)*%winScaleY);
   TutorialBox.setPosition(87*%winScaleX, (352-325)*%winScaleY);
   TutorialBoxText.setPosition(147*%winScaleX, (357-325)*%winScaleY);
   
   TutorialBoxArrow.setVisible(true);
   TutorialBoxArrowText.setVisible(true);
   
   %this.showCamArrow(5);
}

function SceneGui::exitTutorialState8(%this)
{   
}

// State #9
function SceneGui::enterTutorialState9(%this)
{
   %winScaleX = 1.0 / 800 * getWord(GuiCenter.getExtent(),0);
   %winScaleY = 1.0 / 600 * getWord(GuiCenter.getExtent(),1);
   
   %this.tutCurState = 9;
   %text = %this.tutTrigger[%this.tutCurState,"text",0];
   TutorialBoxText.setText(%text);
   
   TutorialArrow5.setPosition(37*%winScaleX, 105*%winScaleY);
   
   TutorialBoxArrow.setVisible(false);
   TutorialBoxArrowText.setVisible(false);
   
   %this.tutClickButtonNum = 1;
   %this.tutClickButton[0] = Ladder;
   
   %this.playPulseHint(4);
}

function SceneGui::exitTutorialState9(%this)
{
   %winScaleX = 1.0 / 800 * getWord(GuiCenter.getExtent(),0);
   %winScaleY = 1.0 / 600 * getWord(GuiCenter.getExtent(),1);
   
   // Offset the text box to original position
   TutorialBoxArrow.setPosition(498*%winScaleX, (372-0)*%winScaleY);
   TutorialBoxArrowText.setPosition(490*%winScaleX, (395-0)*%winScaleY);
   TutorialBox.setPosition(87*%winScaleX, (352-0)*%winScaleY);
   TutorialBoxText.setPosition(147*%winScaleX, (357-0)*%winScaleY);   
   
   TutorialBoxArrow.setVisible(true);
   TutorialBoxArrowText.setVisible(true);
   
   %this.tutClickButtonNum = 0;
   
   %this.stopPulseHint();
}

// State #10
function SceneGui::enterTutorialState10(%this)
{
   %winScaleX = 1.0 / 800 * getWord(GuiCenter.getExtent(),0);
   %winScaleY = 1.0 / 600 * getWord(GuiCenter.getExtent(),1);
   
   %this.tutCurState = 10;
   %text = %this.tutTrigger[%this.tutCurState,"text",0];
   TutorialBoxText.setText(%text);
   
   TutorialArrow5.setPosition(565*%winScaleX, 115*%winScaleY);
}

function SceneGui::exitTutorialState10(%this)
{
   %this.hideCamArrow(5);   
}

// State #11
function SceneGui::enterTutorialState11(%this)
{
   %this.tutCurState = 11;
   %text = %this.tutTrigger[%this.tutCurState,"text",0];
   TutorialBoxText.setText(%text);
}

function SceneGui::exitTutorialState11(%this)
{
}

// State #12
function SceneGui::enterTutorialState12(%this)
{
   %winScaleX = 1.0 / 800 * getWord(GuiCenter.getExtent(),0);
   %winScaleY = 1.0 / 600 * getWord(GuiCenter.getExtent(),1);
   
   %this.tutCurState = 12;
   %text = %this.tutTrigger[%this.tutCurState,"text",0];
   TutorialBoxText.setText(%text);
   
   %this.showCamArrow(5); 
   TutorialArrow5.setPosition(630*%winScaleX, 187*%winScaleY);
   %this.playPulseHint(7);   
}

function SceneGui::exitTutorialState12(%this)
{
}

// State #13
function SceneGui::enterTutorialState13(%this)
{
   %this.tutCurState = 13;
   %text = %this.tutTrigger[%this.tutCurState,"text",0];
   TutorialBoxText.setText(%text);
      
   %this.tutClickButtonNum = 1;
   %this.tutClickButton[0] = ShopButton7;
   
   TutorialBoxArrow.setVisible(false);
   TutorialBoxArrowText.setVisible(false);
}

function SceneGui::exitTutorialState13(%this)
{
   %this.stopPulseHint();
   
   %this.tutClickButtonNum = 0;
   
   TutorialBoxArrow.setVisible(true);   
   TutorialBoxArrowText.setVisible(true);
}

// State #14
function SceneGui::enterTutorialState14(%this)
{
   %winScaleX = 1.0 / 800 * getWord(GuiCenter.getExtent(),0);
   %winScaleY = 1.0 / 600 * getWord(GuiCenter.getExtent(),1);
   
   %this.tutCurState = 14;
   %text = %this.tutTrigger[%this.tutCurState,"text",0];
   TutorialBoxText.setText(%text);     
   
   TutorialArrow5.setPosition(625*%winScaleX, 445*%winScaleY);
}

function SceneGui::exitTutorialState14(%this)
{
   %this.hideCamArrow(5);   
}

// State #15
function SceneGui::enterTutorialState15(%this)
{
   %this.tutCurState = 15;
   %text = %this.tutTrigger[%this.tutCurState,"text",0];
   TutorialBoxText.setText(%text);     
}

function SceneGui::exitTutorialState15(%this)
{
}

// State #16
function SceneGui::enterTutorialState16(%this)
{
   %this.tutCurState = 16;
   %text = %this.tutTrigger[%this.tutCurState,"text",0];
   TutorialBoxText.setText(%text);     
}

function SceneGui::exitTutorialState16(%this)
{
}

// State #17
function SceneGui::enterTutorialState17(%this)
{
   %this.tutCurState = 17;
   %text = %this.tutTrigger[%this.tutCurState,"text",0];
   TutorialBoxText.setText(%text);     
   
   Cam1.useOverlayColor = false;
   Cam3.useOverlayColor = false;
}

function SceneGui::exitTutorialState17(%this)
{
}

// State #18
function SceneGui::enterTutorialState18(%this)
{
   %this.tutCurState = 18;
   %text = %this.tutTrigger[%this.tutCurState,"text",0];
   TutorialBoxText.setText(%text);     
}

function SceneGui::exitTutorialState18(%this)
{
   %this.hideTutorialTextBox();
   %this.resumeHOGameTutorial();

   // Restore preferences
   $pref::MeterPositionRight = %this.savedMeterPositionRight;
   $pref::NShoppingListItems5 = %this.savedNShoppingListItems5;   
   
   $ReplayButtonPressed = true;
      
   $PlayTutorial = false;
   MainMenuGui.goHome();
   MainMenuGui.pushThread(loadlevel_menu_thread);
}

// State #19
function SceneGui::enterTutorialState19(%this)
{
   %this.tutCurState = 19;
}

// Pressed skip button
function SceneGui::onTutorialSkip(%this)
{
   %state = %this.tutCurState;
   %text = "%this.exitTutorialState" @ %state @ "();";
   eval(%text);
   
   %this.exitTutorialState18();   
}

function SceneGui::onTutorialQuit(%this)
{
   %state = %this.tutCurState;
   %text = "%this.exitTutorialState" @ %state @ "();";
   eval(%text);
   
   %this.doNotReplay = true;
   
//   $PlayTutorial = false;
//   $ReplayButtonPressed = false;
   
   %this.hideTutorialTextBox();
   %this.resumeHOGameTutorial();   
   
   %this.loadOutroScreen();
}

function TutorialBoxSkip::onMouseEnter(%this){
   %this.setBitmap("scriptsAndAssets/data/ui/minigame/skip_rollover.png");
}

function TutorialBoxSkip::onMouseLeave(%this){
   %this.setBitmap("scriptsAndAssets/data/ui/minigame/skip.png");
}

function TutorialBoxSkip::onMouseDown(%this){
   %this.setBitmap("scriptsAndAssets/data/ui/minigame/skip_pressed.png");
}