//-----------------------------------------------------------------------------
// Handle events of GUI controls of the instructions menu.
//-----------------------------------------------------------------------------

function InstructionsMenuDlg::onWake(%this)
{
   %pXml = loadMenuXML();
   parseInstructionsMenuXML(%pXml);
   %pXml.delete();
   
   Canvas.setWidescreen(InstructionsMenuDlgCenter, 100, false);   
}

function InstructionsMenuDlg::onResize(%this, %width, %height)
{
   %fontSize = 36 * Canvas.scaleSize; if(%fontSize > 62) %fontSize = 62;   
   GuiCenteredBigTextProfile.fontSize = %fontSize;
   GuiLCAButtonProfile2.fontSize = %fontSize;   
   
   %fontSize = 40 * Canvas.scaleSize; if(%fontSize > 62) %fontSize = 62;   
   GuiLCAButtonProfile.fontSize = %fontSize;
   
   TitleInstText.setProfile(GuiDefaultProfile);
   CreditsButton.setProfile(GuiDefaultProfile);
   MainMenuInstButton.setProfile(GuiDefaultProfile);
   
   TitleInstText.setProfile(GuiCenteredBigTextProfile);
   CreditsButton.setProfile(GuiLCAButtonProfile);
   MainMenuInstButton.setProfile(GuiLCAButtonProfile2);
   
   Canvas.setWidescreen(InstructionsMenuDlgCenter, 2000, true);
}

// Parse XML file looking for menu text tags
function parseInstructionsMenuXML(%pXml)
{
   if(!isObject(%pXml))
      return;
      
   // Push the first child element named "instructions" onto the XML document stack.
   if(!%pXml.pushFirstChildElement("instructions"))
   {
      echo("Failed to load 'instructions' tag.");
      return;
   }
   
   if(%pXml.pushFirstChildElement("title"))
   {
      TitleInstText.text = %pXml.attribute("text");
      %pXml.popElement();
   }

   if(%pXml.pushFirstChildElement("credits"))
   {
      CreditsButtonText.text = %pXml.attribute("text");
      %pXml.popElement();
   }

   if(%pXml.pushFirstChildElement("back"))
   {
      MainMenuInstButtonText.text = %pXml.attribute("text");
      %pXml.popElement();
   }
}

// Stop grow/shrink animation of all menu UI elements
function StopMenuShrinkGrowInstructionsMenu()
{
   StopShrinkGrowGUI(CreditsButton);
   StopShrinkGrowGUI(MainMenuInstButton);
}

function CreditsButton::onMouseEnter(%this)
{
   CreditsButtonText.color = "255 128 0 255";
   
   StopMenuShrinkGrowCreditsMenu();
   InitShrinkGrowGUI(%this);
}

function CreditsButton::onMouseLeave(%this)
{
   CreditsButtonText.color = "255 255 255 255";
}

function MainMenuInstButton::onMouseEnter(%this)
{
   MainMenuInstButtonText.color = "255 128 0 255";
   
   StopMenuShrinkGrowCreditsMenu();
   InitShrinkGrowGUI(%this);
}

function MainMenuInstButton::onMouseLeave(%this)
{
   MainMenuInstButtonText.color = "255 0 0 255";
}