// Initialize particle effects manager for the director meter
function ParticleFxDirMeter::onWake(%this)
{   
   %this.particleMax = 500;
   %this.particleInUse = -1;  
   %this.particleIdxTable = 0;   
   
   // Create particles
   for(%i=0; %i<%this.particleMax; %i++)
   {
      %obj = ("PDM"@%i);
      if(!isObject(%obj))      
         %newP = new GuiPlasticBitmapCtrl(%obj);
      else
         %newP = %obj;
      %newP.useAddBlending = "1";         
      %newP.setVisible(false);
      ParticleFxDirMeter.add(%newP);
   }   
}

// Returns the ID of a particle
function ParticleFxDirMeter::getAvailableParticle(%this)
{     
   %this.particleInUse++;
   return %this.particleInUse % %this.particleMax;
}

// Hide particles when end of animation is reached
function ParticleFxDirMeter::onDeathGroup(%this, %idxTable, %idxNum)  
{
   for(%i=0; %i<%idxNum; %i++)
      ("P"@%this.particleTable[%idxTable, %i]).setVisible(false);
}

// Do an explosion effect
// %x and %y are the screen location of the particle generation
// %aniTime is the total animation time, in seconds
// %scale is a scale factor of the particle
function ParticleFxDirMeter::ExplosionFx(%this, %x, %y, %aniTime, %scale)
{
   %scalex = %scale * (1.0 / 800 * getWord(GuiCenter.getExtent(),0));
   %scaley = %scale * (1.0 / 600 * getWord(GuiCenter.getExtent(),1));

   %this.particleIdxTable++;
   %this.particleIdxNum[%this.particleIdxTable] = 0;

   for(%i=0; %i<250; %i++)
   {
      %idx = %this.getAvailableParticle();
         
      %this.particleTable[%this.particleIdxTable, %this.particleIdxNum[%this.particleIdxTable]] = %idx;
      %this.particleIdxNum[%this.particleIdxTable]++;
      
      ("PDM"@%idx).particleScore(%x, %y, %aniTime, %scalex, %scaley);      
   }
     
   %particleIdx = %this.particleIdxTable;
   %particleNum = %this.particleIdxNum[%this.particleIdxTable];
   scheduleObjLCA(%this, "HO", %aniTime*1000, "onDeathGroup", 2, 
      %particleIdx, %particleNum);   
}
