Example #1
0
 private void AddItem(ShopMaterialInterface interfaceToAdd)
 {
     // This gets the currently used page and adds to it.
     // Unfortunately, we need to add extra code to check if the latest page is full.
     if (materialPages.Count > 0)
     {
         for (int i = 0; i < materialPages.Count; i++)
         {
             if (materialPages[i].Count < ITEMS_PER_ROW * ROWS)
             {
                 materialPages[i].Add(interfaceToAdd);
                 return;
             }
         }
         // If we made it this far, then we need a new page
         materialPages.Add(new List <ShopMaterialInterface>()
         {
             interfaceToAdd
         });
     }
     else // pages.Count <= 0
     {
         materialPages.Add(new List <ShopMaterialInterface>());
         materialPages[0].Add(interfaceToAdd);
     }
 }
Example #2
0
        public void Update(User user, bool?onlyBuyStone, GameTime gameTime)
        {
            // If onlyBuyStone == null, don't update anything
            if (onlyBuyStone == true)
            {
                ShopMaterialInterface s = materialInterfaces.Find(x => x.Item == Material.Stone);
                s.Update(user, true, gameTime);
                List <ShopMaterialInterface> woutStone = materialInterfaces.Except(new List <ShopMaterialInterface> {
                    s
                }).ToList();
                for (int i = 0; i < woutStone.Count; i++)
                {
                    woutStone[i].DisableAllButtons();
                }
            }
            else if (onlyBuyStone == false)
            {
                materialButton.Update(gameTime);
                cannonButton.Update(gameTime);
                giftsButton.Update(gameTime);

                switch (state)
                {
                case ShopState.Materials:
                    #region Materials

                    if (slideOffset + X_OFFSET >= windowWidth || slideOffset + (X_OFFSET * -1) <= windowWidth * -1)
                    {
                        slideOffset = 0;
                        slidingOver = false;
                        page        = transitionPage;
                    }

                    if (page <= materialPages.Count - 1)
                    {
                        if (slidingOver)
                        {
                            int offset = 0;
                            if (slideSpd < 0)
                            {
                                offset = (materialInterfaces[0].Width + SPACING) * 5 + X_OFFSET;
                            }
                            else
                            {
                                offset = ((materialInterfaces[0].Width + SPACING) * 5 + X_OFFSET) * -1;
                            }
                            UpdateMaterialPositions(transitionPage, user, offset, true, gameTime);
                        }

                        UpdateMaterialPositions(page, user, 0, true, gameTime);
                    }

                    bool mActive = false;
                    for (int i = 0; i < materialPages[page].Count; i++)
                    {
                        if (materialPages[page][i].HoveringOnItem)
                        {
                            mInfoHover.ResetMaterial(materialPages[page][i].Item);
                            mActive = true;
                            mInfoHover.Update();
                            break;
                        }
                    }
                    mInfoHover.Active = mActive;

                    for (int i = 0; i <= materialPages.Count - 1; i++)
                    {
                        if (materialPages[i].Count <= 0)
                        {
                            materialPages.RemoveAt(i);
                        }
                    }

                    //if (pages.Count <= 1)
                    //{
                    //    // Both buttons should be disabled, as there is only 1 page
                    //    // This must be tested for first, otherwise, since the page always starts equal to 0,
                    //the below criteria will be met
                    //    // and the game will act like there are 2 pages when there is only 1
                    //    nextButton.Active = false;
                    //    prevButton.Active = false;
                    //    // Since there is only one page, we have to set the page integer to 0
                    //    page = 0;
                    //}
                    //else if (page == 0)
                    //{
                    //    // There is another page, but we are on the first. Therefore, we cannot go backwards, so we'll disable the backwards button
                    //    nextButton.Active = true;
                    //    prevButton.Active = false;
                    //}
                    //else if (page + 1 == pages.Count)
                    //{
                    //    // We are on the last page, so the forward button must be disabled
                    //    nextButton.Active = false;
                    //    prevButton.Active = true;
                    //}
                    //else
                    //{
                    //    // We must be somewhere in the middle, so both buttons should be enabled
                    //    nextButton.Active = true;
                    //    prevButton.Active = true;
                    //}

                    //nextButton.Update();
                    //prevButton.Update();

                    if (slidingOver)
                    {
                        slideOffset += slideSpd;
                    }
                    break;
                    #endregion

                case ShopState.Cannons:
                    #region Cannons
                    for (int i = 0; i < cannonInterfaces.Count; i++)
                    {
                        cannonInterfaces[i].Update(user, gameTime);
                    }

                    bool cActive = false;
                    for (int i = 0; i < cannonInterfaces.Count; i++)
                    {
                        if (cannonInterfaces[i].HoveringOnItem)
                        {
                            if (user.Cannons.Where(x => x.CannonType == cannonInterfaces[i].Cannon.CannonType).Count() > 0)
                            {
                                cInfoHover.ResetCannon(user.Cannons.Where(x => x.CannonType == cannonInterfaces[i].Cannon.CannonType).First());
                            }
                            else
                            {
                                cInfoHover.ResetCannon(CannonSettings.SettingsForType(cannonInterfaces[i].Cannon.CannonType));
                            }
                            cActive = true;
                            cInfoHover.Update();
                            break;
                        }
                    }
                    cInfoHover.Active = cActive;

                    break;
                    #endregion

                case ShopState.Gifts:
                    #region Gifts
                    for (int i = 0; i < giftInterfaces.Count; i++)
                    {
                        giftInterfaces[i].Update(user, gameTime);
                    }
                    break;
                    #endregion
                }
            }
        }