// ZL- This file holds the files for controlling the game's Iphone. We can use this for storing the pictures taken, goals, score, etc. . . 
// I just want to point out this is not at all network safe, and done so for expidiency and following preset standards

$IPHONE_PICTURE_ONE = 0;
$IPHONE_PICTURE_TWO = 1;
$IPHONE_PICTURE_THREE = 2;
$IPHONE_PICTURE_FOUR = 3;

$IPHONE_LEVEL_ONE = 0;
$IPHONE_LEVEL_TWO = 1;
$IPHONE_LEVEL_THREE = 2;

// Array for bitmaps, text for the levels

// Level 1

// Picture 1  
$IPHONE_BITMAPS[0,0] = "StitchCutDye/client/ui/evidencePix/evidence_1_1_bodycount.png";
$IPHONE_HINT_TEXT[0,0] = "How Many Pawns are Involved?";
$IPHONE_CHECK_TEXT[0,0] = "Exhibit A: Body Count";
// Picture 2
$IPHONE_BITMAPS[0,1] = "StitchCutDye/client/ui/evidencePix/evidence_1_2_prisoner.png";
$IPHONE_HINT_TEXT[0,1] = "Who's Life is at Stake?";
$IPHONE_CHECK_TEXT[0,1] = "Exhibit B: Iraqi Prisoner";
// Picture 3
$IPHONE_BITMAPS[0,2] = "StitchCutDye/client/ui/evidencePix/evidence_1_3_hangerPlan.png";
$IPHONE_HINT_TEXT[0,2] = "Who's Calling the Shots?";
$IPHONE_CHECK_TEXT[0,2] = "Exhibit C: Key Players";
// Picture 4
$IPHONE_BITMAPS[0,3] = "StitchCutDye/client/ui/evidencePix/evidence_1_4_bodiesLoaded.png";
$IPHONE_HINT_TEXT[0,3] = "What is the Method?";
$IPHONE_CHECK_TEXT[0,3] = "Exhibit D: The Bodies";

// Level 2

// Picture 1
$IPHONE_BITMAPS[1,0] = "StitchCutDye/client/ui/evidencePix/evidence_2_1_bodiesonconveyorbelt.png";
$IPHONE_HINT_TEXT[1,0] = "What Happens to the Bodies?";
$IPHONE_CHECK_TEXT[1,0] = "Exhibit E: Stripping the Skin";
// Picture 2
$IPHONE_BITMAPS[1,1] = "StitchCutDye/client/ui/evidencePix/evidence_2_2_plastinationProcess.png";
$IPHONE_HINT_TEXT[1,1] = "What is the Process?";
$IPHONE_CHECK_TEXT[1,1] = "Exhibit F: Plastinating the Bodies";
// Picture 3
$IPHONE_BITMAPS[1,2] = "StitchCutDye/client/ui/evidencePix/evidence_2_3_labenvironmentvonknox.png";
$IPHONE_HINT_TEXT[1,2] = "How is the Skin Used?";
$IPHONE_CHECK_TEXT[1,2] = "Exhibit G: Preparing the Skin for Stem Cells";
// Picture 4
$IPHONE_BITMAPS[1,3] = "StitchCutDye/client/ui/evidencePix/evidence_2_4_roomofcuriosities.png";
$IPHONE_HINT_TEXT[1,3] = "Why Put the Bodies on Display?";
$IPHONE_CHECK_TEXT[1,3] = "Exhibit H: Red Herring: A Cabinet of Curiosities";

// Level 3

// Picture 1
$IPHONE_BITMAPS[2,0] = "StitchCutDye/client/ui/evidencePix/evidence_3_1_organtuneupconference.png";
$IPHONE_HINT_TEXT[2,0] = "What's an Organ Tune-Up?";
$IPHONE_CHECK_TEXT[2,0] = "Exhibit I: Illegal Marketing";
// Picture 2
$IPHONE_BITMAPS[2,1] = "StitchCutDye/client/ui/evidencePix/evidence_3_2_uraniumblastocyst.png";
$IPHONE_HINT_TEXT[2,1] = "What Experimental Techniques are Used?";
$IPHONE_CHECK_TEXT[2,1] = "Exhibit J: Uranium Infected Blastocyst";
// Picture 3
$IPHONE_BITMAPS[2,2] = "StitchCutDye/client/ui/evidencePix/evidence_3_3_monsterinnursery.png";
$IPHONE_HINT_TEXT[2,2] = "What goes Wrong?";
$IPHONE_CHECK_TEXT[2,2] = "Exhibit K: Mutant O & C Broke Loose";
// Picture 4
$IPHONE_BITMAPS[2,3] = "StitchCutDye/client/ui/evidencePix/evidence_3_4_tsofedgarkillingdrfuchs.png";
$IPHONE_HINT_TEXT[2,3] = "Who's the Mastermind?";
$IPHONE_CHECK_TEXT[2,3] = "Exhibit L: The Vice President";



$IPHONE_TIME_POINTS = 10;

$IPHONE_PHOTO_POINTS[0] = 20;
$IPHONE_PHOTO_POINTS[1] = 20;
$IPHONE_PHOTO_POINTS[2] = 20;
$IPHONE_PHOTO_POINTS[3] = 20;

$IPHONE_KICKOUT_POINTS = -5;
$IPHONE_MIC_POINTS = 15;
$IPHONE_CLUE_POINTS = 50;

// Use the above like this
// Whererver you want points in a trigger add
// IPhone_AddPoints(Iphone, $IPHONE_XXXXX_POINTS);
// Of course, feel free to change the XXXXXX to whatever, like AUDIO or something

function IPhone_AddPoints(%this, %points)
{
   $VMPlayer.schedule(1000, PlaySong, "~/data/sound/sound/SFX/success_playful_01.ogg.ogg");
   %this.LevelPoints += %points;
   $TotalPoints += %points;
   %decimal = strstr(%this.LevelPoints, ".");
   if(%decimal != -1)
   {
      // Strip the decimals
      %this.LevelPoints = getSubStr(%this.LevelPoints,0,%decimal);
   }
   if(%this.LevelPoints >= 0)
   {
      // Lastly, let's add 0's if needed
      %num = 4 - strlen(%this.LevelPoints);
      %text = "" @ %this.LevelPoints;
      for(%i = 0; %i < %num; %i++)
      {
         %text = "0" @ %text;      
      }
   }
   else
   {
      %points = 0 - %this.LevelPoints;
      
      // Lastly, let's add 0's if needed
      %num = 4 - strlen(%points);
      %text = "" @ %points;
      for(%i = 0; %i < %num; %i++)
      {
         %text = "0" @ %text;      
      }  
      %text = "-" @ %text;
   }
   
   Score.setText( %text);  
}

function IPhone_GotAllPictures(%this)
{
   if(%this.PhotoTaken[$IPHONE_PICTURE_ONE] == false)
   {
      return false;  
   }
   if(%this.PhotoTaken[$IPHONE_PICTURE_TWO] == false)
   {
      return false;  
   }
   if(%this.PhotoTaken[$IPHONE_PICTURE_THREE] == false)
   {
      return false;  
   }
   if(%this.PhotoTaken[$IPHONE_PICTURE_FOUR] == false)
   {
      return false;  
   }
   return true;
}


function IPhone_Create(%level)
{
   if(!isObject(IPhone))
   {
      // Constants for the iphone
      new SimObject(IPhone)
      {
         mainGUI = IphoneGui;
         canTakePicture = false;
         flashSpeed = 200;
         pictureTimer = 5000;
         timeToRemovePicture = 2000;
         lastActivePhoto = 0;
         LevelPoints = $TotalPoints;
         PhotoTaken[$IPHONE_PICTURE_ONE] = false;
         PhotoTaken[$IPHONE_PICTURE_TWO] = false;
         PhotoTaken[$IPHONE_PICTURE_THREE] = false;
         PhotoTaken[$IPHONE_PICTURE_FOUR] = false; 
         ShownEnd = false; 
      };
   }
   IPhone.curLevel = %level;
   
   // SEtup the journal
   for(%i = 0; %i < 4;%i++)
   {
      SCD_Screenshot.SCD_ScreenshotDlg_InitJournalPage(%i,$IPHONE_BITMAPS[%level,%i],$IPHONE_HINT_TEXT[%level,%i],$IPHONE_CHECK_TEXT[%level,%i]);
   }
   SCD_Screenshot.lastActivePhoto = 0;
   return IPhone;
}

// So, we've entered the time when we can take a picture, it's valid
function IPhone_ShowPictureChance(%this, %timer,%picture, %player, %trigger)
{
   if(%this.PhotoTaken[%picture] == false)
   {
      // Setup the bitmap now
      IPhonePhoto.setBitmap($IPHONE_BITMAPS[%this.curLevel,%picture]);
      %this.canTakePicture = true;
      %this.startTime = getSimTime();
      %this.picture = %picture;
      %this.player = %player;
      %this.trigger = %trigger;
      %this.pictureTimer = %timer;
      IPhone_FlashCameraIcon(%this);
      schedule(%this.pictureTimer, 0, IPhone_ShowPictureChanceOver, %this); 
   }
}

function IPhone_ShowPictureChanceOver(%this)
{
   // Check if we've already take the pciture
   if(%this.canTakePicture)
   { 
      // No pic, so stop the flashing
      IPhone_StopCameraFlash(%this);
      %this.canTakePicture = false;
      %this.player.unlockPlayerToDirection();      
      // We also need to add the trigger back
      levelTriggers.remove( %this.trigger );
   }
}

function IPhone_FlashCameraIcon(%this)
{
   IphoneIcon.setVisible(!IphoneIcon.isVisible());
   %this.CameraIconFlashSchedule = schedule(%this.flashSpeed, 0, IPhone_FlashCameraIcon, IPhone); 
}

function IPhone_StopCameraFlash(%this)
{
   IphoneIcon.setVisible(false);
   cancel(%this.CameraIconFlashSchedule);
}


      
function IPhone_FlashMicIcon(%this)
{
   MicIcon.setVisible(!MicIcon.isVisible());
   %this.MicIconFlashSchedule = schedule(%this.flashSpeed, 0, IPhone_FlashMicIcon, IPhone); 
}

function IPhone_StopMicFlash(%this)
{
   MicIcon.setVisible(false);
   cancel(%this.MicIconFlashSchedule);
}

      
function IPhone_FlashClueIcon(%this)
{
   ClueIcon.setVisible(!ClueIcon.isVisible());
   %this.ClueIconFlashSchedule = schedule(%this.flashSpeed, 0, IPhone_FlashClueIcon, IPhone); 
}

function IPhone_StopClueFlash(%this)
{
   ClueIcon.setVisible(false);
   cancel(%this.ClueIconFlashSchedule);
}

function IPhone_FlashJournalIcon(%this)
{
   iPhoneActivation.setVisible(!iPhoneActivation.isVisible());
   %this.JournalIconFlashSchedule = schedule(%this.flashSpeed, 0, IPhone_FlashJournalIcon, IPhone); 
}

function IPhone_StopJournalFlash(%this)
{
   iPhoneActivation.setVisible(false);
   cancel(%this.JournalIconFlashSchedule);
}

function IPhone_IsPhotoTaken(%this, %picture)
{
   return %this.PhotoTaken[%picture];
}

// Picutre is take, great, let's show your iphone, all the standard stuff here
function IPhone_TakePicture(%this)
{
   echo("Taking Picture");
   if(%this.canTakePicture)
   {
      // Axe the trigger
      %this.canTakePicture = false;
      
      // Stop the flashing
      IPhone_StopCameraFlash(%this);
      
      // Hide normal GUI and show the picture taking
      Canvas.pushDialog(IphoneGui);
      
      
      %this.PhotoTaken[%this.picture] = true;

      
      // TODO: Play a snap sound
      $VMPlayer.PlaySong("~/data/sound/sound/SFX/cameraclick02.ogg");
       
      // Compute time they've taken the photo
      %elapsedTime = getSimTime() - %this.startTime;

      %timePoints = $IPHONE_TIME_POINTS*(1 - (%elapsedTime / %this.pictureTimer));
      
      // Activate the journal we just took a picture of
      SCD_Screenshot.SCD_ScreenshotDlg_ActivateJournalPage(%this.picture);
      
      // Probably show a GUI or something
      IPhone_AddPoints(%this, %timePoints + $IPHONE_PHOTO_POINTS[%this.picture]);
      
    //  %this.player.unlockPlayerToDirection();

      // now, we're taking the photo, setup a timer to show the journal
      schedule(%this.timeToRemovePicture, 0, IPhone_TakePictureOver, %this); 
            
      // Try the blinking Iphone
      /*
      // now, we're taking the photo, setup a timer to show the journal
      schedule(%this.timeToShowJournal, 0, IPhone_ShowJournal, %this); 
      
      // Close out the Iphone Photo
      Canvas.schedule(%this.timeToShowJournal, popDialog, IphoneGui);
      */ 
   }
}

function IPhone_TakePictureOver(%this)
{
   Canvas.popDialog(IphoneGui);
   IPhone_FlashJournalIcon(%this);
   %this.lastActivePhoto = %this.picture;
}

function IPhone_ShowJournal(%this)
{
      IPhone_StopJournalFlash(%this);
      // Show the Journal in the IPhone
      SCD_Screenshot.SCD_ScreenshotDlg_OpenJournal(%this.lastActivePhoto);

}


function IPhone_CloseJournal(%this)
{
   %this.lastActivePhoto = SCD_Screenshot.lastActivePhoto;
   SCD_Screenshot.SCD_ScreenshotDlg_CloseJournal();
   // Check if first, we need to show the player a GUI
   if(IPhone_GotAllPictures(IPhone) && (%this.ShownEnd == false))
   {
          %this.ShownEnd = true;
         // push popup
         SCDPopupText.setBitmap( "StitchCutDye/data/popupTextGraphics/gotAllpoints.png" );
         SCDPopupText.setVisible( true );
         SCDPopupText.schedule( 5000, setVisible, false ); 
   }      
}



