protected override void OnStart()
        {
            if (mode == Mode.Client)
            {
                RegisterNotification(NetworkNotifications.ConnectedToServer, ConnectedToServerNotification);
                StartDiscovery();
            }
            else if (mode == Mode.Server)
            {
                RegisterNotification(NetworkNotifications.ClientConnected, ClientConnectedNotification);
                RegisterNotification(NetworkNotifications.LocalClientDiscovered, LocalClientDiscoveredNotification);
                StartServer();
            }

            Screen screen = new Screen();
            Button button = new TempButton("Cancel");
            button.id = (int)ButtonId.Cancel;
            button.buttonDelegate = OnCancelButtonPressed;
            button.alignX = button.alignY = button.parentAlignX = button.parentAlignY = View.ALIGN_CENTER;
            screen.AddView(button);
            screen.SetCancelButton(button);

            Font font = Helper.fontSystem;
            TextView textView = new TextView(font, mode.ToString());
            textView.alignX = View.ALIGN_CENTER;
            textView.x = 0.5f * screen.width;
            textView.y = 10;
            screen.AddView(textView);

            StartScreen(screen);
        }
 protected void StartNextScreen(Screen screen)
 {
     screenManager.StartScreen(screen, false);
 }
 protected void StartScreen(Screen screen)
 {
     screenManager.StartScreen(screen);
 }
 private void Suspend(Screen screen)
 {
     screen.Suspend();
     if (listener != null)
     {
         listener.OnScreenSuspended(this, screen);
     }
 }
 public bool IsCurrent(Screen screen)
 {
     return CurrentScreen() == screen;
 }
 private void Resume(Screen screen)
 {
     screen.Resume();
     if (listener != null)
     {
         listener.OnScreenResumed(this, screen);
     }
 }
 private void Stop(Screen screen)
 {
     screen.Stop();
     if (listener != null)
     {
         listener.OnScreenStopped(this, screen);
     }
 }
 public void StartScreen(Screen screen)
 {
     StartScreen(screen, false);
 }
        public void StartScreen(Screen screen, bool replaceCurrent)
        {
            if (screens.Contains(screen))
            {
                throw new InvalidOperationException("Screen already started: " + screen);
            }

            if (currentScreen != null)
            {
                if (replaceCurrent)
                {
                    currentScreen.screenManager = null;
                    updatables.Remove(currentScreen);
                    drawables.Remove(currentScreen);
                    screens.Remove(currentScreen);

                    Stop(currentScreen);
                }
                else
                {
                    if (!screen.AllowsUpdatePrevious)
                    {
                        Suspend(currentScreen);
                        updatables.Remove(currentScreen);
                    }

                    if (!screen.AllowsDrawPrevious)
                    {
                        drawables.Remove(currentScreen);
                    }
                }
            }

            currentScreen = screen;

            screens.Add(screen);
            screen.screenManager = this;

            Start(screen);

            updatables.Add(screen);
            drawables.Add(screen);
        }
 public virtual void OnScreenResumed(ScreenManager manager, Screen screen)
 {
 }
        public void RemoveScreen(Screen screen)
        {
            if (screen.screenManager != this)
            {
                throw new InvalidOperationException("Screen doesn't belong to this container: " + screen);
            }

            if (!screens.Contains(screen))
            {
                throw new InvalidOperationException("Screen manager doesn't contain the screen: " + screen);
            }

            screens.Remove(screen);
            updatables.Remove(screen);
            drawables.Remove(screen);

            if (screen == currentScreen)
            {
                if (screens.Count > 0)
                {
                    currentScreen = screens[screens.Count - 1];
                    if (!screen.AllowsDrawPrevious)
                    {
                        drawables.Add(currentScreen);
                    }

                    if (!screen.AllowsUpdatePrevious)
                    {
                        Resume(currentScreen);
                        updatables.Add(currentScreen);
                    }
                }
                else
                {
                    currentScreen = null;
                }
            }

            screen.screenManager = null;
            Stop(screen);
        }
 public bool IsCurrentScreen(Screen screen)
 {
     return screenManager.IsCurrent(screen);
 }
 public void StartScreen(Screen screen)
 {
     screenManager.StartScreen(screen, true);
 }
 public void StartNextScreen(Screen screen)
 {
     screenManager.StartScreen(screen, false);
 }
 public virtual void OnScreenSuspended(ScreenManager manager, Screen screen)
 {
 }
 public virtual void OnScreenStopped(ScreenManager manager, Screen screen)
 {
 }