home *** CD-ROM | disk | FTP | other *** search
/ Champak 66 / Vol 66.iso / games / bob_espo.swf / scripts / __Packages / Menu.as < prev    next >
Encoding:
Text File  |  2013-04-24  |  4.7 KB  |  144 lines

  1. class Menu extends PopUp
  2. {
  3.    var sState;
  4.    var mcRef;
  5.    static var sSOUND_STATE_ON = "SoundOn";
  6.    static var sSOUND_STATE_OFF = "SoundOff";
  7.    static var sMUSIC_STATE_ON = "MusicOn";
  8.    static var sMUSIC_STATE_OFF = "MusicOff";
  9.    static var sMENU_OPTIONS = "Options";
  10.    static var sMENU_QUIT = "Quit";
  11.    function Menu(_mcRef)
  12.    {
  13.       super(_mcRef);
  14.    }
  15.    function doShow()
  16.    {
  17.       if(this.sState == PopUp.sSTATE_IDLE)
  18.       {
  19.          this.setState(PopUp.sSTATE_OPENING);
  20.          Controller.getRef().getSounds().playSound("Menu_In",Controller.nSFX_VOLUME,1);
  21.          this.updateSoundButton();
  22.          this.updateMusicButton();
  23.          Controller.getRef().pauseGame();
  24.       }
  25.    }
  26.    function doHide()
  27.    {
  28.       if(this.sState == PopUp.sSTATE_OPENED)
  29.       {
  30.          this.setState(PopUp.sSTATE_CLOSING);
  31.          Controller.getRef().getSounds().playSound("Menu_Out",Controller.nSFX_VOLUME,1);
  32.          this.updateSoundButton();
  33.          this.updateMusicButton();
  34.          Controller.getRef().unPauseGame();
  35.       }
  36.    }
  37.    function clickSoundButton()
  38.    {
  39.       Controller.getRef().playClickSound();
  40.       if(Controller.getRef().isSoundsMuted())
  41.       {
  42.          Controller.getRef().unMuteSounds();
  43.       }
  44.       else
  45.       {
  46.          Controller.getRef().muteSounds();
  47.       }
  48.       this.updateSoundButton();
  49.    }
  50.    function clickMusicButton()
  51.    {
  52.       Controller.getRef().playClickSound();
  53.       if(Controller.getRef().isMusicMuted())
  54.       {
  55.          Controller.getRef().unMuteMusic();
  56.       }
  57.       else
  58.       {
  59.          Controller.getRef().muteMusic();
  60.       }
  61.       this.updateMusicButton();
  62.    }
  63.    function resume()
  64.    {
  65.       Controller.getRef().playClickSound();
  66.       this.doHide();
  67.    }
  68.    function updateSoundButton()
  69.    {
  70.       if(Controller.getRef().isSoundsMuted())
  71.       {
  72.          this.mcRef.mcState.mcPanel.mcSound.gotoAndStop(Menu.sSOUND_STATE_OFF);
  73.       }
  74.       else
  75.       {
  76.          this.mcRef.mcState.mcPanel.mcSound.gotoAndStop(Menu.sSOUND_STATE_ON);
  77.       }
  78.       this.mcRef.mcState.mcPanel.mcSound.btnSound.onRollOver = Delegate.create(Main.getRef(),Main.getRef().rollOverButton);
  79.       this.mcRef.mcState.mcPanel.mcSound.btnSound.onRelease = Delegate.create(this,this.clickSoundButton);
  80.    }
  81.    function updateMusicButton()
  82.    {
  83.       if(Controller.getRef().isMusicMuted())
  84.       {
  85.          this.mcRef.mcState.mcPanel.mcMusic.gotoAndStop(Menu.sMUSIC_STATE_OFF);
  86.       }
  87.       else
  88.       {
  89.          this.mcRef.mcState.mcPanel.mcMusic.gotoAndStop(Menu.sMUSIC_STATE_ON);
  90.       }
  91.       this.mcRef.mcState.mcPanel.mcMusic.btnMusic.onRollOver = Delegate.create(Main.getRef(),Main.getRef().rollOverButton);
  92.       this.mcRef.mcState.mcPanel.mcMusic.btnMusic.onRelease = Delegate.create(this,this.clickMusicButton);
  93.    }
  94.    function gotoQuitMenu()
  95.    {
  96.       Controller.getRef().playClickSound();
  97.       this.showQuitMenu();
  98.    }
  99.    function gotoOptionsMenu()
  100.    {
  101.       Controller.getRef().playClickSound();
  102.       this.showOptionsMenu();
  103.    }
  104.    function showOptionsMenu()
  105.    {
  106.       this.mcRef.mcState.gotoAndStop(Menu.sMENU_OPTIONS);
  107.       this.updateSoundButton();
  108.       this.updateMusicButton();
  109.       this.mcRef.mcState.mcPanel.btnResume.onRollOver = Delegate.create(Main.getRef(),Main.getRef().rollOverButton);
  110.       this.mcRef.mcState.mcPanel.btnResume.onRelease = Delegate.create(this,this.resume);
  111.       this.mcRef.mcState.mcPanel.btnHowToPlay.onRollOver = Delegate.create(Main.getRef(),Main.getRef().rollOverButton);
  112.       this.mcRef.mcState.mcPanel.btnHowToPlay.onRelease = Delegate.create(Main.getRef(),Main.getRef().clickInstructionsButton);
  113.       this.mcRef.mcState.mcPanel.btnQuit.onRollOver = Delegate.create(Main.getRef(),Main.getRef().rollOverButton);
  114.       this.mcRef.mcState.mcPanel.btnQuit.onRelease = Delegate.create(this,this.gotoQuitMenu);
  115.    }
  116.    function showQuitMenu()
  117.    {
  118.       Controller.getRef().playClickSound();
  119.       this.mcRef.mcState.gotoAndStop(Menu.sMENU_QUIT);
  120.       this.mcRef.mcState.mcPanel.btnYes.onRollOver = Delegate.create(Main.getRef(),Main.getRef().rollOverButton);
  121.       this.mcRef.mcState.mcPanel.btnNo.onRollOver = Delegate.create(Main.getRef(),Main.getRef().rollOverButton);
  122.       this.mcRef.mcState.mcPanel.btnYes.onRelease = Delegate.create(Main.getRef(),Main.getRef().clickQuitButton);
  123.       this.mcRef.mcState.mcPanel.btnNo.onRelease = Delegate.create(this,this.gotoOptionsMenu);
  124.    }
  125.    function Opening()
  126.    {
  127.       if(this.stateFinished())
  128.       {
  129.          this.setState(PopUp.sSTATE_OPENED);
  130.          this.showOptionsMenu();
  131.       }
  132.    }
  133.    function Opened()
  134.    {
  135.    }
  136.    function Closing()
  137.    {
  138.       if(this.stateFinished())
  139.       {
  140.          this.setState(PopUp.sSTATE_IDLE);
  141.       }
  142.    }
  143. }
  144.