예제 #1
0
 public NavigationState(string name, IScreenState screenState, bool completeWhenUnload = true)
 {
     Name                    = name;
     ScreenState             = screenState;
     Completion              = new TaskCompletionSource <bool> ();
     this.completeWhenUnload = completeWhenUnload;
 }
예제 #2
0
        /// <summary>
        /// Инициализация объекта игры и связывание с размером формы
        /// </summary>
        /// <param name="form">объект формы</param>
        public static void Init(Form form)
        {
            Log.AddMessage($"Загрузка объектов");
            // Графическое устройство для вывода графики
            Graphics graphics;

            // Предоставляет доступ к главному
            //  буферу графического контекства для текущего приложения
            _context = BufferedGraphicsManager.Current;
            graphics = form.CreateGraphics(); // Создаем объект - поверхность рисования и связываем его с формой

            // Запоминаем размеры формы
            Width  = form.Width;
            Height = form.Height;

            // Связываем буфер в памяти с графическим объектом
            // для того, чтобы рисовать в буфере
            Buffer  = _context.Allocate(graphics, new Rectangle(0, 0, Width, Height));
            _random = new Random();

            _currentScreen = new MainMenuScreen();

            _timer.Start();
            _timer.Tick += Timer_Tick;

            form.MouseUp += Form_MouseUp;
            form.KeyDown += Form_KeyDown;
            Log.AddMessage($"Загрузка объектов завершена");
        }
예제 #3
0
        async Task <bool> PopNavigationState()
        {
            NavigationState navigationState = navigationStateStack [navigationStateStack.Count - 1];
            IScreenState    screenToPop     = navigationState.ScreenState;

            navigationStateStack.RemoveAt(navigationStateStack.Count - 1);

            NavigationState lastState = LastNavigationState();

            if (!await screenToPop.HideState())
            {
                return(false);
            }
            if (!await App.Current.Navigation.Pop(lastState?.ScreenState.Panel))
            {
                return(false);
            }
            await App.Current.EventsBroker.Publish(new NavigationEvent { Name = Current.Name });

            if (!await navigationState.Unload())
            {
                return(false);
            }
            screenToPop.Dispose();
            return(true);
        }
예제 #4
0
        public virtual void EnableControl(IScreenState state)
        {
            switch (_activationMode)
            {
            case ActivationMode.ReadOnly:
                Disable();
                break;

            case ActivationMode.AlwaysActive:
                Enable();
                break;

            case ActivationMode.Normal:
                if (state.IsControlEnabled(Driver.Control))
                {
                    Enable();
                    PostEnable();
                }
                else
                {
                    Disable();
                }

                break;
            }
        }
예제 #5
0
        async Task <bool> PushNavigationState(string transition, IScreenState state)
        {
            NavigationState navState;

            if (transition == home?.Name)
            {
                navState = home;
            }
            else
            {
                navState = new NavigationState(transition, state);
                navigationStateStack.Add(navState);
            }
            if (!await App.Current.Navigation.Push(state.Panel))
            {
                return(false);
            }
            if (!await navState.Show())
            {
                return(false);
            }
            await App.Current.EventsBroker.Publish(new NavigationEvent { Name = transition });

            return(true);
        }
예제 #6
0
        public void ChangeStateTo(ENUM stateName)
        {
            IScreenState state = GetState(stateName);

            _binder.EnableControls(state);
            CurrentState = state;
        }
예제 #7
0
        public void MakeReadOnly(bool readOnly)
        {
            IScreenState state = readOnly
                                                     ? (IScreenState) new DisableAllScreenState()
                                                     : new EnableAllScreenState();

            EnableControls(state);
        }
예제 #8
0
        public override void EnableControl(IScreenState state)
        {
            Assert.ArgumentNotNull(state, nameof(state));

            Latched = true;
            base.EnableControl(state);
            Latched = false;
        }
예제 #9
0
 /// <summary>
 /// Метод переключения текущей сцены, обеспечивает переход между объектами сцен
 /// </summary>
 public static void changeScreen(IScreenState scene)
 {
     _currentScreen = scene;
     Log.AddMessage($"Загрузка сцены");
     _currentScreen.Load();
     Log.AddMessage($"Загрузка сцены завершена");
     FileLog.Stop();
     Log.AddMessage($"Запись в файл прекращена");
 }
예제 #10
0
 /// <summary>
 /// Deactivate the child whenever the parent is deactivated
 /// </summary>
 /// <example>child.DeactivateWith(this)</example>
 /// <param name="child">Child to deactivate whenever the parent is deacgtivated</param>
 /// <param name="parent">Parent to observe</param>
 public static void DeactivateWith(this IScreenState child, IScreenState parent)
 {
     var weakChild = new WeakReference<IScreenState>(child);
     EventHandler<DeactivationEventArgs> handler = null;
     handler = (o, e) =>
     {
         IScreenState strongChild;
         if (weakChild.TryGetTarget(out strongChild))
             strongChild.Deactivate();
         else
             parent.Deactivated -= handler;
     };
     parent.Deactivated += handler;
 }
예제 #11
0
        async Task <bool> PushModalState(NavigationState state, IScreenState current)
        {
            modalStateStack.Add(state);
            if (!await state.Show())
            {
                return(false);
            }

            await App.Current.EventsBroker.Publish(new NavigationEvent { Name = state.ScreenState.Name, IsModal = true });

            await App.Current.Navigation.PushModal(state.ScreenState.Panel, current.Panel);

            return(true);
        }
예제 #12
0
 /// <summary>
 /// Close the child whenever the parent is closed
 /// </summary>
 /// <example>child.CloseWith(this)</example>
 /// <param name="child">Child to close when the parent is closed</param>
 /// <param name="parent">Parent to observe</param>
 public static void CloseWith(this IScreenState child, IScreenState parent)
 {
     var weakChild = new WeakReference<IScreenState>(child);
     EventHandler<CloseEventArgs> handler = null;
     handler = (o, e) =>
     {
         IScreenState strongChild;
         if (weakChild.TryGetTarget(out strongChild))
             TryClose(strongChild);
         else
             parent.Closed -= handler;
     };
     parent.Closed += handler;
 }
예제 #13
0
 /// <summary>
 /// Sets the home transition. Needs to be registered first.
 /// </summary>
 /// <returns>True if the home transition could be executed. False otherwise</returns>
 /// <param name="transition">Transition.</param>
 public async Task <bool> SetHomeTransition(string transition, dynamic properties)
 {
     try {
         Log.Debug("Setting Home to " + transition);
         IScreenState homeState = destination [transition] ();
         if (!await homeState.LoadState(properties))
         {
             return(false);
         }
         home = new NavigationState(transition, homeState);
         return(await MoveToHome(true));
     } catch (Exception ex) {
         Log.Exception(ex);
         throw;
     }
 }
예제 #14
0
        /// <summary>
        /// Moves to a Modal window
        /// </summary>
        /// <returns>True if the Move could be performed. False otherwise</returns>
        /// <param name="transition">Transition.</param>
        public async Task <bool> MoveToModal(string transition, dynamic properties, bool waitUntilClose = false)
        {
            Log.Debug("Moving to " + transition + " in modal mode");

            if (!destination.ContainsKey(transition))
            {
                Log.Debug("Moving failed because transition " + transition + " is not in destination dictionary.");
                return(false);
            }

            try {
                IScreenState    state           = destination [transition] ();
                NavigationState transitionState = new NavigationState(transition, state, !waitUntilClose);

                NavigationState lastState = LastState();
                if (!CanMove(lastState))
                {
                    return(false);
                }

                if (!await lastState.Freeze(transitionState))
                {
                    return(false);
                }

                bool ok = await state.LoadState(properties);

                if (ok)
                {
                    await PushModalState(transitionState, LastState()?.ScreenState);

                    NavigationState resultantState = LastState();
                    if (waitUntilClose && resultantState.Name == transition)
                    {
                        await resultantState.Completion.Task;
                    }
                }
                else
                {
                    Log.Debug("Moving failed because panel " + state.Name + " cannot move.");
                }
                return(ok);
            } catch (Exception ex) {
                Log.Exception(ex);
                throw;
            }
        }
 public ScreenManager(ContentManager content)
 {
     playScreen = new PlayScreen(this);
     playScreen.Load(content);
     pauseScreen = new PauseScreen(this);
     pauseScreen.Load(content);
     gameOverScreen = new GameOverScreen(this);
     gameOverScreen.Load(content);
     nextLevel1Screen = new NextLevel1Screen(this);
     nextLevel1Screen.Load(content);
     nextLevel2Screen = new NextLevel2Screen(this);
     nextLevel2Screen.Load(content);
     mainMenuScreen = new MainMenuScreen(this);
     mainMenuScreen.Load(content);
     controlsScreen = new ControlsScreen(this);
     controlsScreen.Load(content);
     currentScreen = mainMenuScreen;
 }
예제 #16
0
        /// <summary>
        /// Deactivate the child whenever the parent is deactivated
        /// </summary>
        /// <example>child.DeactivateWith(this)</example>
        /// <param name="child">Child to deactivate whenever the parent is deacgtivated</param>
        /// <param name="parent">Parent to observe</param>
        public static void DeactivateWith(this IScreenState child, IScreenState parent)
        {
            var weakChild = new WeakReference <IScreenState>(child);
            EventHandler <DeactivationEventArgs> handler = null;

            handler = (o, e) =>
            {
                IScreenState strongChild;
                if (weakChild.TryGetTarget(out strongChild))
                {
                    strongChild.Deactivate();
                }
                else
                {
                    parent.Deactivated -= handler;
                }
            };
            parent.Deactivated += handler;
        }
예제 #17
0
        /// <summary>
        /// Close the child whenever the parent is closed
        /// </summary>
        /// <example>child.CloseWith(this)</example>
        /// <param name="child">Child to close when the parent is closed</param>
        /// <param name="parent">Parent to observe</param>
        public static void CloseWith(this IScreenState child, IScreenState parent)
        {
            var weakChild = new WeakReference <IScreenState>(child);
            EventHandler <CloseEventArgs> handler = null;

            handler = (o, e) =>
            {
                IScreenState strongChild;
                if (weakChild.TryGetTarget(out strongChild))
                {
                    TryClose(strongChild);
                }
                else
                {
                    parent.Closed -= handler;
                }
            };
            parent.Closed += handler;
        }
예제 #18
0
        async Task <bool> PopModalState(NavigationState current)
        {
            NavigationState navigationState = modalStateStack [modalStateStack.Count - 1];
            IScreenState    screenToPop     = navigationState.ScreenState;

            if (!await screenToPop.HideState())
            {
                return(false);
            }
            if (!await navigationState.Unload())
            {
                return(false);
            }
            modalStateStack.RemoveAt(modalStateStack.Count - 1);
            await App.Current.EventsBroker.Publish(new NavigationEvent { Name = Current.Name, IsModal = modalStateStack.Any() });

            await App.Current.Navigation.PopModal(screenToPop.Panel);

            screenToPop.Dispose();
            return(true);
        }
예제 #19
0
 public void EnableControls(IScreenState state)
 {
     // no-op;
 }
 /// <summary>
 /// Zal het huidige scherm veranderen naar de goToScreen
 /// </summary>
 /// <param name="goToScreen">Het volgende scherm dat geladen moet worden</param>
 public void SetState(IScreenState goToScreen)
 {
     currentScreen = goToScreen;
 }
예제 #21
0
 public void EnableControls(IScreenState state)
 {
     IsLatched = true;
     _allElements.ForEach(element => element.EnableControl(state));
     IsLatched = false;
 }
예제 #22
0
 public void SetState(IScreenState s)
 {
     this.screenState = s;
     screenState.Display(this);
 }
예제 #23
0
 /// <summary>
 /// Activate, Deactivate, or Close the child whenever the parent is Activated, Deactivated, or Closed
 /// </summary>
 /// <example>child.ConductWith(this)</example>
 /// <param name="child">Child to conduct with the parent</param>
 /// <param name="parent">Parent to observe</param>
 public static void ConductWith(this IScreenState child, IScreenState parent)
 {
     child.ActivateWith(parent);
     child.DeactivateWith(parent);
     child.CloseWith(parent);
 }
예제 #24
0
 /// <summary>
 /// Activate, Deactivate, or Close the child whenever the parent is Activated, Deactivated, or Closed
 /// </summary>
 /// <example>child.ConductWith(this)</example>
 /// <param name="child">Child to conduct with the parent</param>
 /// <param name="parent">Parent to observe</param>
 public static void ConductWith(this IScreenState child, IScreenState parent)
 {
     child.ActivateWith(parent);
     child.DeactivateWith(parent);
     child.CloseWith(parent);
 }