Esempio n. 1
0
 public MenuItemViewModel(MenuItem menuItem) : base(menuItem)
 {
     SubMenuItems = menuItem.SubMenuItems.Select(s => new SubMenuItemViewModel(s)).ToList();
     if (SubMenuItems.Any())
     {
         SubMenuItems.Add(new SubMenuItemViewModel(SubMenuItem.Back));
     }
     _currentSubMenuItem = SubMenuItems.FirstOrDefault();
 }
 public void Deactivate()
 {
     State           = MenuStates.PressStart;
     currentItem     = SubMenuItems.Character;
     controllerIndex = 0;
     controller      = null;
     buyInventory    = new Inventory();
     sellInventory   = new Inventory();
     wealth          = 100;
 }
        internal NewNotePage OpenNewNotePage()
        {
            var entries = MenuItems.Single(x => x.Text == "Wpisy");

            entries.Click();

            var newPost = SubMenuItems.Where(x => x.Text == "Dodaj nowy");

            newPost.Single().Click();

            return(new NewNotePage(_browser));
        }
        private void StepSelection()
        {
            if (!nameEntry.Active)
            {
                if (currentItem > SubMenuItems.Name)
                {
                    if (controller.ButtonPressed(Buttons.DPadDown) ||
                        (controller.LeftStick.Y < -0.5 &&
                         controller.PreviousLeftStick.Y >= -0.5))
                    {
                        int itemIndex = (int)currentItem;
                        if (++itemIndex <= (int)SubMenuItems.Ready)
                        {
                            currentItem = (SubMenuItems)itemIndex;
                        }
                    }
                    else if (controller.ButtonPressed(Buttons.DPadUp) ||
                             (controller.LeftStick.Y > 0.5 &&
                              controller.PreviousLeftStick.Y <= 0.5))
                    {
                        int itemIndex = (int)currentItem;
                        if (--itemIndex >= (int)SubMenuItems.Character)
                        {
                            currentItem = (SubMenuItems)itemIndex;
                        }
                    }
                }

                switch (currentItem)
                {
                case SubMenuItems.Character:
                    if (controller.ButtonPressed(Buttons.A))
                    {
                        if (++character > 5)
                        {
                            character = 0;
                        }
                    }
                    if (controller.ButtonPressed(Buttons.DPadRight) ||
                        (controller.LeftStick.X > 0.5 &&
                         controller.PreviousLeftStick.X <= 0.5))
                    {
                        currentItem = SubMenuItems.Name;
                    }
                    else if (controller.ButtonPressed(Buttons.DPadDown) ||
                             (controller.LeftStick.Y < -0.5 &&
                              controller.PreviousLeftStick.Y >= -0.5))
                    {
                        currentItem = SubMenuItems.Buy;
                    }
                    break;

                case SubMenuItems.Name:
                    if (controller.ButtonPressed(Buttons.A))
                    {
                        nameEntry.Activate(controller);
                    }
                    if (controller.ButtonPressed(Buttons.DPadLeft) ||
                        (controller.LeftStick.X < -0.5 &&
                         controller.PreviousLeftStick.X >= -0.5))
                    {
                        currentItem = SubMenuItems.Character;
                    }
                    else if (controller.ButtonPressed(Buttons.DPadDown) ||
                             (controller.LeftStick.Y < -0.5 &&
                              controller.PreviousLeftStick.Y >= -0.5))
                    {
                        currentItem = SubMenuItems.Buy;
                    }
                    break;

                case SubMenuItems.Buy:
                    if (controller.ButtonPressed(Buttons.DPadRight) ||
                        (controller.LeftStick.X > 0.2 &&
                         controller.PreviousLeftStick.X <= 0.2))
                    {
                        buyInventory.IncrementIndex();
                    }
                    else if (controller.ButtonPressed(Buttons.DPadLeft) ||
                             (controller.LeftStick.X < -0.2 &&
                              controller.PreviousLeftStick.X >= -0.2))
                    {
                        buyInventory.DecrementIndex();
                    }
                    else if (controller.ButtonPressed(Buttons.A))
                    {
                        InventoryItem item = buyInventory.GetCurrentItem().Copy();
                        if (wealth >= item.Value)
                        {
                            wealth       -= item.Value;
                            item.Quantity = 1;
                            sellInventory.AddItem(item);
                        }
                    }
                    else if (controller.ButtonPressed(Buttons.B))
                    {
                        if (sellInventory.GetItem(buyInventory.GetCurrentItem().Name) != null)
                        {
                            InventoryItem item = buyInventory.GetCurrentItem();
                            wealth += item.Value;
                            sellInventory.DepleteItem(item.Name, 1);
                        }
                    }
                    break;

                case SubMenuItems.Ready:
                    if (controller.ButtonPressed(Buttons.A))
                    {
                        State = MenuStates.Ready;
                    }
                    break;
                }

                //if (controller.ButtonPressed(Buttons.B))
                //{
                //    if (currentItem == SubMenuItems.Character)
                //        Deactivate();
                //    else
                //        currentItem = SubMenuItems.Character;
                //}
            }

            nameEntry.Step();
        }