public override void OnExit()
        {
            base.OnExit();

            HitMeButton.ButtonUpAction -= HandleHitMeButtonButtonUpAction;
            PauseButton.ButtonUpAction -= HandlePauseButtonButtonUpAction;
            QualityManager.MatchScoreDetected -= HandleQualityManagerMatchScoreDetected;
            QualityManager.FailedMatchDetected -= HandleQualityManagerFailedMatchDetected;
            CardManager.Instance.NoMatchesPossibleDetected -= HandleCardManagerInstanceNoMatchesPossibleDetected;
            GameScene.LevelChangeDetected -= HandleGameSceneLevelChangeDetected;
            GroupCrystallonEntity.BreakDetected -= HandleGroupCrystallonEntityBreakDetected;
            PausePanel.QuitButtonPressDetected -= HandlePausePanelQuitButtonPressDetected;
            PausePanel.ResetButtonPressDetected -= HandlePausePanelResetButtonPressDetected;
            CubeCrystallonEntity.CubeCompleteDetected -= HandleCubeCrystallonEntityCubeCompleteDetected;
            CardManager.Instance.CardSpawned -= HandleCardManagerInstanceCardSpawned;
            if(GameScene.currentLevel == 999) {
                GameTimer.BarEmptied -= HandleGameTimerBarEmptied;
                GameTimer.BarFilled -= HandleGameTimerBarFilled;
                if (BonusBar != null) {
                    BonusBar.BarFilled -= HandleBonusBarBarFilled;
                    BonusBar.BarEmptied -= HandleBonusBarBarEmptied;
                }
                (_nextLevelPanel as InfiniteModeEndPanel).RetryDetected -= HandlePausePanelResetButtonPressDetected;
                (_nextLevelPanel as InfiniteModeEndPanel).QuitDetected -= Handle_nextLevelPanelQuitButtonPressDetected;
            } else {
                (_nextLevelPanel as NextLevelPanel).ReplayDetected -= HandlePausePanelResetButtonPressDetected;
                (_nextLevelPanel as NextLevelPanel).NextLevelDetected -= Handle_nextLevelPanelButtonButtonUpAction;
                (_nextLevelPanel as NextLevelPanel).QuitDetected -= Handle_nextLevelPanelQuitButtonPressDetected;
                (_nextLevelPanel as NextLevelPanel).LevelSelectDetected -= Handle_nextLevelPanelLevelSelectDetected;
            }

            _nextLevelPanel = null;
            HitMeButton = null;
            PauseButton = null;
            pausePanel = null;
            levelTitle = null;
            _messagePanel = null;
            _scene = null;

            #if METRICS
            if(ExitCode == LevelExitCode.NULL){
                DataStorage.CollectMetrics();
            }
            DataStorage.RemoveMetric("Goal");
            DataStorage.RemoveMetric("Score");
            DataStorage.RemoveMetric("Time");
            DataStorage.RemoveMetric("No-Match Time");
            DataStorage.RemoveMetric("Met-Goal Time");
            DataStorage.RemoveMetric("Breaks");
            DataStorage.RemoveMetric("Hit Me");
            DataStorage.RemoveMetric("Exit Code");
            #endif
        }
        private void Initialize()
        {
            FontMap map = FontManager.Instance.GetMap( FontManager.Instance.GetInGame("Bariol", 25, "Bold") );
            FontMap bigMap = FontManager.Instance.GetMap( FontManager.Instance.GetInGame("Bariol", 44, "Bold") );

            // CREATE PAUSE MENU
            pausePanel = new PausePanel(_scene);
            _scene.DialogLayer.AddChild(pausePanel);
            pausePanel.Hide();

            // CREATE THE HUD BAR AT THE TOP OF THE SCREEN
            GameHudBar = new Node(){
                Position = new Vector2(0.0f, 473.0f)
            };
            this.AddChild(GameHudBar);

            HudBarMask = Support.UnicolorSprite("white", 255, 255, 255, 255);
            HudBarMask.Color = LevelManager.Instance.BackgroundColor;
            HudBarMask.Scale = new Vector2(60.0f, 4.4375f);
            GameHudBar.AddChild(HudBarMask);

            // CREATE THE LEVEL TITLE HUD
            levelTitle = new LevelTitleMkTwo() {
                SlideInDirection = SlideDirection.RIGHT,
                SlideOutDirection = SlideDirection.LEFT,
                Offset = new Vector2(0.0f, 0.0f),
            //				Lifetime = 4.0f
            };
            this.AddChild(levelTitle, -1);

            // CREATE THE END-OF-LEVEL DROP-DOWN PANEL
            if (GameScene.currentLevel == 999) {
                // INFINITE MODE VERSION
                _nextLevelPanel = new InfiniteModeEndPanel(){
                    Offset = new Vector2(Director.Instance.GL.Context.Screen.Width-248.0f, 0.0f),

                };
            } else {
                // PUZZLE/TUTORIAL MODE VERSION
                _nextLevelPanel = new NextLevelPanel(){
                    Offset = new Vector2(510.0f, 0.0f),

                };
            }
            GameHudBar.AddChild(_nextLevelPanel, -1);

            // CREATE MESSAGE PANEL
            _messagePanel = new MessagePanel(920.0f, 148.0f ){
                SourceObject = this,
                Offset = new Vector2(20.0f, 0.0f),
                Position = new Vector2(0.0f, -148.0f),
                Lifetime = 0.0f
            };
            this.AddChild(_messagePanel);
            _messagePanel.body = GamePhysics.Instance.RegisterPhysicsBody(GamePhysics.Instance.SceneShapes[4], float.MaxValue, 0.0f, _messagePanel.Position / GamePhysics.PtoM);
            _messagePanel.AdHocDraw += () => {
                _messagePanel.body.Position = _messagePanel.Position / GamePhysics.PtoM;
            };

            // SCORE STUFF
            //			ScoreIcon = Support.SpriteFromFile("/Application/assets/images/handIcon.png");
            ScoreIcon = Support.SpriteFromAtlas("crystallonUI", "handIcon.png");
            ScoreIcon.Position = new Vector2(184.0f, 16.0f);
            ScoreIcon.RegisterPalette(1);
            GameHudBar.AddChild(ScoreIcon);

            ScoreTitleText = new Label("score", map);
            ScoreTitleText.Position = new Vector2(287, 25.0f);
            ScoreTitleText.RegisterPalette(1);

            BlueBox = Support.UnicolorSprite("white", 255,255,255,255);
            BlueBox.Scale = new Vector2(6.25f, 4.4375f);
            BlueBox.Position = new Vector2(354.0f, 0.0f);
            BlueBox.RegisterPalette(2);

            ScoreText = new Label("", bigMap) {
                Position = SCORE_TEXT_POS
            };
            ScoreText.RegisterPalette(1);
            GameHudBar.AddChild(ScoreText);

            // CUBE STUFF
            //			CubeIcon = Support.SpriteFromFile("/Application/assets/images/stopIcon.png");
            CubeIcon = Support.SpriteFromAtlas("crystallonUI", "stopIcon.png");
            CubeIcon.Position = new Vector2(20.0f,16.0f);
            CubeIcon.RegisterPalette(2);
            GameHudBar.AddChild(CubeIcon);

            CubesTitleText = new Label("cubes", map);
            CubesTitleText.Position = new Vector2(63.0f, 25.0f);
            CubesTitleText.RegisterPalette(2);

            RedBox = Support.UnicolorSprite("white", 255,255,255,255);
            RedBox.Position = new Vector2(130.0f, 0.0f);
            RedBox.Scale = new Vector2(6.25f, 4.4375f);
            RedBox.RegisterPalette(1);

            CubeText = new Label("", bigMap){
                Position = CUBES_TEXT_POS
            };
            CubeText.RegisterPalette(2);
            GameHudBar.AddChild(CubeText);

            // TIMER & STRIKES STUFF
            GameTimer = new TimerEntity();
            if (GameScene.currentLevel == 999) {	// ------------------- IF CHALLENGE MODE
                if(GameScene.gameTimeLimit > 0.0f) {
                    GameTimer.Position = new Vector2(348.0f, 16.0f);	// ----- ADD THE TIME BAR
                    GameHudBar.AddChild(GameTimer);
                } else {
                    BonusBar = new BonusTimer() {
            //						Position = new Vector2(348.0f, 44.0f)
                        Position = new Vector2(348.0f, 16.0f)
                    };
                    GameHudBar.AddChild(BonusBar);
                }

                Strikes = new StrikeHud() {
                    Position = new Vector2(395.0f, 44.0f)
                };
                GameHudBar.AddChild(Strikes);
            }

            // PAUSE BUTTON
            PauseButton = new BetterButton("/Application/assets/images/UI/BetterButtonTransparent.png", 115.0f, 71.0f) {
                Text = "",
            //				Icon = Support.SpriteFromFile("Application/assets/images/UI/pause.png"),
                Icon = Support.SpriteFromAtlas("crystallonUI", "pause.png"),
            //				Position = new Vector2(845.0f, 473.0f),
                Position = new Vector2(845.0f, 0.0f)
            };
            //			this.AddChild(PauseButton);
            GameHudBar.AddChild(PauseButton);
            PauseButton.background.RegisterPalette(2);
            PauseButton.background.Scale = new Vector2(115.0f/32.0f, 71.0f/16.0f);
            PauseButton.Icon.RegisterPalette(2);
            PauseButton.ButtonUpAction += HandlePauseButtonButtonUpAction;

            // HIT ME BUTTON
            HitMeButton = new BetterButton("/Application/assets/images/UI/BetterButtonTransparent.png", 115.0f, 71.0f) {
                Text = "",
            //				Icon = Support.SpriteFromFile("Application/assets/images/UI/plus.png"),
                Icon = Support.SpriteFromAtlas("crystallonUI", "plus.png"),
            //				Position = new Vector2(720.0f, 473.0f),
                Position = new Vector2(720.0f, 0.0f)
            };
            HitMeButton.On(!LevelManager.Instance.HitMeDisabled);
            //			this.AddChild(HitMeButton);
            GameHudBar.AddChild(HitMeButton);
            HitMeButton.background.RegisterPalette(1);
            HitMeButton.background.Scale = new Vector2(115.0f/32.0f, 71.0f/16.0f);
            HitMeButton.Icon.RegisterPalette(1);
            HitMeButton.ButtonUpAction += HandleHitMeButtonButtonUpAction;

            HudBarLine = Support.UnicolorSprite("white", 255, 255, 255, 255);
            HudBarLine.RegisterPalette(0);
            HudBarLine.Scale = new Vector2(60.0f, 0.125f);
            GameHudBar.AddChild(HudBarLine);

            _initialized = true;
        }
        // CONSTRUCTOR ---------------------------------------------------------
        public OptionsMenuScreen(MenuSystemScene pMenuSystem)
        {
            MenuSystem = pMenuSystem;

            // SLIDERS -----------------------

            // MUSIC SLIDER
            musicVolume = Support.MusicSystem.Instance.Volume;
            effectsVolume = Support.SoundSystem.Instance.Volume;
            orbitDistance = SelectionGroup.EASE_DISTANCE;
            stickiness = SelectionGroup.MAXIMUM_PICKUP_VELOCITY;

            float anchorX = (960.0f - (2.0f * (float)SLIDER_TRACK_LENGTH + SLIDER_H_GAP)) / 2.0f;
            float anchorY = 397.0f;

            musicSlider = new Slider(SLIDER_TRACK_LENGTH) {
                Text = "music volume",
                max = 1.0f,
                min = 0.0f,
                Position = new Vector2(anchorX, anchorY),
                OnChange = (volume) => {
                    Support.MusicSystem.Instance.SetVolume(volume);
                }
            };
            musicSlider.SetSliderValue((float)(DataStorage.options[0]/100.0f));
            musicSlider.RegisterPalette(2);

            // SOUND EFFECTS SLIDER
            effectsSlider = new Slider(SLIDER_TRACK_LENGTH) {
                Text = "sound effects volume",
                max = 1.0f,
                min = 0.0f,
                Position = new Vector2(anchorX, anchorY - SLIDER_V_GAP),
                OnChange = (volume) => {
                    Support.SoundSystem.Instance.SetVolume(volume);
                    Support.SoundSystem.Instance.Play( LevelManager.Instance.SoundPrefix + "high.wav" );
                }
            };
            effectsSlider.SetSliderValue((float)(DataStorage.options[1]/100.0f));
            effectsSlider.RegisterPalette(1);

            // SELECTION SENSITIVITY SLIDER
            stickySlider = new Slider(SLIDER_TRACK_LENGTH) {
                Text = "selection sensitivity",
                max = 1000.0f,
                min = 300.0f,
                Position = new Vector2(anchorX + musicSlider.Length + SLIDER_H_GAP, anchorY),
                OnChange = (velocity) => {
                    SelectionGroup.MAXIMUM_PICKUP_VELOCITY = velocity;
                }
            };
            stickySlider.SetSliderValue((float)DataStorage.options[3]);
            stickySlider.RegisterPalette(1);

            // ORBIT DISTANCE SLIDER
            orbitSlider = new Slider(SLIDER_TRACK_LENGTH) {
                Text = "selection float distance",
                max = 120.0f,
                min = 60.0f,
                Position = new Vector2(stickySlider.Position.X, anchorY - SLIDER_V_GAP),
                OnChange = (radius) => {
                    SelectionGroup.EASE_DISTANCE = radius;
                }
            };
            orbitSlider.SetSliderValue((float)DataStorage.options[2]);
            orbitSlider.RegisterPalette(0);

            // BUTTONS -------------------------------

            // OK BUTTON
            OKButton = new BetterButton(BUTTON_WIDTH, BUTTON_HEIGHT) {
                Text = "ok",
                Position = new Vector2(960.0f-BUTTON_WIDTH, 0.0f),
            //				Color = new Vector4(0.8980f, 0.0745f, 0.0745f, 1.0f)
            };
            OKButton.background.RegisterPalette(1);

            // CANCEL BUTTON
            CancelButton = new BetterButton(BUTTON_WIDTH, BUTTON_HEIGHT) {
                Text = "cancel",
                Position = new Vector2(OKButton.Position.X, BUTTON_HEIGHT),
            //				Color = new Vector4(0.1608f, 0.8863f, 0.8863f, 1.0f)
            };
            CancelButton.background.RegisterPalette(2);

            // CLEAR DATA BUTTON
            ClearButton = new BetterButton(BUTTON_WIDTH, BUTTON_HEIGHT) {
                Text = "clear all data",
                Position = new Vector2(0.0f, 0.0f),
            //				Color = new Vector4(0.1608f, 0.8863f, 0.8863f, 1.0f)
            };
            ClearButton.background.RegisterPalette(2);

            // CLEAR DATA CONFIRMATION PANEL -------------------------

            // CLEAR MESSAGE PANEL
            ClearPanel = new MessagePanel(BUTTON_WIDTH, 165.0f) {
                TitleText = "really?",
                Text = "erase all your progress?\nthis cannot be undone.",
                Offset = new Vector2(0.0f, 0.0f),//OKButton.Height),
                Width = OKButton.Width
            };
            ClearPanel.BackgroundAlpha = 1.0f;

            // CLEAR DATA CONFIRMATION BUTTON
            ClearOKButton = new BetterButton(BUTTON_WIDTH, BUTTON_HEIGHT) {
                Text = "make it so",
                Position = new Vector2(0.0f, 0.0f),
            //				Color = new Vector4(0.8980f, 0.0745f, 0.0745f, 1.0f)
            };
            ClearOKButton.background.RegisterPalette(1);

            this.AddChild(musicSlider);
            this.AddChild(effectsSlider);
            this.AddChild(stickySlider);
            this.AddChild(orbitSlider);
            this.AddChild(OKButton);
            this.AddChild(CancelButton);
            this.AddChild(ClearButton);
            this.AddChild(ClearPanel);

            ClearPanel.AddChild(ClearOKButton);
        }