Exemple #1
0
        public void SetValueOfStat(CannonStats stat, int value)
        {
            CannonSettings cannon = Cannons[CannonIndex];

            cannon.SetValueOfStat(stat, value);
            Cannons[CannonIndex] = cannon;
        }
        private void UpdatePositions(int page, int xOffset, CannonSettings settings, User user,
                                     GameTime gameTime)
        {
            int row   = 0;
            int lastX = X_OFFSET;
            int lastY = Y_OFFSET;
            int interfacesInCurrentRow = 0;

            foreach (CannonUpgradeInterface cu in pages[page])
            {
                cu.X   = lastX + slideOffset + xOffset;
                lastX += cu.Width + SPACING;
                if (interfacesInCurrentRow >= ITEMS_PER_ROW)
                {
                    row++;
                    lastX  = X_OFFSET;
                    cu.X   = lastX + slideOffset + xOffset;
                    lastX += cu.Width + SPACING;
                    lastY += cu.Height + SPACING;
                    interfacesInCurrentRow = 0;
                }

                cu.Y = lastY;
                interfacesInCurrentRow++;

                cu.Update(settings, user, gameTime);
            }

            lastX = X_OFFSET + slideOffset;
            lastY = Y_OFFSET;
            interfacesInCurrentRow = 0;
            row = 0;
        }
        public CannonInfoHover(CannonSettings cannon, SpriteFont font, GraphicsDevice graphics, int windowWidth)
            : base(graphics, font, cannon.CannonType.ToString().AddSpaces() + " Cannon",
                   Utilities.GetDescOf(cannon.CannonType), new List <NameValue>(), windowWidth)
        {
            stats = new List <NameValue>()
            {
                new NameValue("Damage", cannon.Damage.ToString()),
                new NameValue("Health", cannon.MaxHealth.ToString()),
                new NameValue("Reload Speed", cannon.ReloadSpeed.ToString()),
                new NameValue("Move Speed", cannon.MoveSpeed.ToString()),
                new NameValue("Accuracy", cannon.Accuracy.ToString()),
                new NameValue("Power", cannon.Power.ToString()),
                new NameValue("Defense", cannon.Defense.ToString()),
                new NameValue("Rapid Fire", cannon.RapidFire > 0 ? "Y" : "N"),
            };
            if (cannon.Freezes)
            {
                stats.Add(new NameValue("Effect Added", "Frozen"));
            }
            else
            {
                stats.Add(new NameValue("Effect Added", cannon.EffectAdded.ToString().AddSpaces()));
            }

            for (int i = 0; i < stats.Count; i++)
            {
                statLocs.Add(new Vector2());
            }

            Position();
        }
Exemple #4
0
        public CannonDisplay(CannonSettings cannon, SpriteFont font, int rightX, int y)
        {
            this.font = font;

            cannonBottom     = Utilities.GetBottomOfCannon(cannon.CannonType);
            cannonTube       = Utilities.GetTubeOfCannon(cannon.CannonType);
            cannonTubeRect   = new Rectangle(0, 0, TUBE_WIDTH, TUBE_HEIGHT);
            cannonBottomRect = new Rectangle(0, 0, BOTTOM_WIDTH, BOTTOM_HEIGHT);

            stats = new List <NameValue>()
            {
                new NameValue("Damage", cannon.Damage.ToString()),
                new NameValue("Health", cannon.MaxHealth.ToString()),
                new NameValue("Reload Speed", cannon.ReloadSpeed.ToString()),
                new NameValue("Move Speed", cannon.MoveSpeed.ToString()),
                new NameValue("Accuracy", cannon.Accuracy.ToString()),
                new NameValue("Power", cannon.Power.ToString()),
                new NameValue("Defense", cannon.Defense.ToString()),
                new NameValue("Rapid Fire", cannon.RapidFire > 0 ? "Y" : "N"),
            };
            if (cannon.Freezes)
            {
                stats.Add(new NameValue("Effect Added", "Frozen"));
            }
            else
            {
                stats.Add(new NameValue("Effect Added", cannon.EffectAdded.ToString().AddSpaces()));
            }
            for (int i = 0; i < stats.Count; i++)
            {
                statLocs.Add(new Vector2());
            }
            Position(rightX, y);
        }
Exemple #5
0
        public PreLvlPopup(SpriteFont smallFont, SpriteFont mediumFont, List <ProjectileType> projectileHotbar,
                           List <int> hotbarCounts, int windowWidth, int windowHeight, Action proceed, Action cancel, GraphicsDevice graphics,
                           CannonSettings cannon, Mission mission, User user)
        {
            this.smallFont  = smallFont;
            this.mediumFont = mediumFont;

            bgImg = DrawHelper.AddBorder(new Texture2D(graphics, BG_WIDTH, BG_HEIGHT), 5, new Color(25, 25, 25),
                                         new Color(45, 45, 45));
            bgRect = new Rectangle(windowWidth / 2 - BG_WIDTH / 2, windowHeight / 2 - BG_HEIGHT / 2, BG_WIDTH, BG_HEIGHT);

            hotbarLabel   = Language.Translate("Hotbar");
            hotbarLblLoc  = new Vector2(bgRect.X + SPACING, bgRect.Y + SPACING);
            hotbarDisplay = new HotbarDisplay(projectileHotbar, hotbarCounts, smallFont, (int)hotbarLblLoc.X,
                                              (int)(hotbarLblLoc.Y + mediumFont.MeasureString(hotbarLabel).Y + SPACING / 2));

            cannonDisplay = new CannonDisplay(cannon, smallFont, bgRect.Right - SPACING, bgRect.Y + SPACING);

            goalDisplay = new LevelObjectiveDisplay(mediumFont, bgRect.X + bgRect.Width / 2 - LevelObjectiveDisplay.SIZE / 2,
                                                    cannonDisplay.Bottom, mission);

            proceedButton   = new MenuButton(proceed, Language.Translate("Proceed"), 0, 0, true, mediumFont, graphics);
            cancelButton    = new MenuButton(cancel, Language.Translate("Cancel"), 0, 0, true, mediumFont, graphics);
            proceedButton.X = bgRect.X + (bgRect.Width / 2 - proceedButton.Width);
            cancelButton.X  = bgRect.X + (bgRect.Width / 2 + SPACING);
            proceedButton.Y = cancelButton.Y = bgRect.Bottom - SPACING - proceedButton.Height;

            chanceOfSuccess = Language.Translate("Estimated Chance of Success") + ": " +
                              ChanceOfSuccess(user, mission).ToString() + "%";
            chanceLoc = new Vector2(bgRect.X + bgRect.Width / 2 - mediumFont.MeasureString(chanceOfSuccess).X / 2,
                                    goalDisplay.Bottom + SPACING);
        }
 private void SelectCannon(CannonSettings cannon)
 {
     for (int i = 0; i < cannonInterfaces.Count; i++)
     {
         cannonInterfaces[i].SetSelected(false);
     }
     selectCannon(cannon);
 }
 public void ChangeSettings(CannonSettings settings)
 {
     cannonSettings      = settings;
     slideTimer.WaitTime = GameInfo.ReloadSpeedEquation(settings.ReloadSpeed);
     Speed = settings.MoveSpeed;
     SetImgs(settings.CannonType);
     accuracyBeamRect.Height = settings.Accuracy * ACCURACY_SIZE_MULTIPLIER;
     accuracyBeamRect.Y      = cannonTubeRect.Y - accuracyBeamRect.Height;
 }
        public ShopCannonInterface(CannonSettings cannon, SpriteFont font, int cost,
                                   Action <CannonSettings, int> buy, Action <CannonSettings> select, bool bought, GraphicsDevice graphics,
                                   int x, int y, int width, int height)
        {
            Cannon      = cannon;
            this.buy    = buy;
            this.select = select;
            this.bought = bought;
            this.cost   = cost;
            this.font   = font;

            bgRect = new Rectangle(x, y, width, height);
            bgImg  = new Texture2D(graphics, width, height);
            bgImg  = DrawHelper.AddBorder(bgImg, 3, Color.Gray, Color.LightGray);

            string buttonText = "";

            if (bought)
            {
                buttonText = Language.Translate("Select");
            }
            else
            {
                buttonText = Language.Translate("Buy") + " (" + cost + ")";
            }
            buyOrSelect   = new MenuButton(BuyOrSelect, buttonText, 0, 0, true, font, graphics);
            buyOrSelect.X = bgRect.X + (bgRect.Width / 2 - (buyOrSelect.Width / 2));
            buyOrSelect.Y = bgRect.Bottom - buyOrSelect.Height - SPACING;

            cannonExtImg    = Utilities.GetBottomOfCannon(cannon.CannonType);
            cannonExtRect   = new Rectangle(0, 0, CANNON_WIDTH, (int)(EXT_TUBE_RATIO_HEIGHT * CANNON_HEIGHT));
            cannonExtRect.X = bgRect.X + (bgRect.Width / 2 - (cannonExtRect.Width / 2));

            cannonTubeImg  = Utilities.GetTubeOfCannon(cannon.CannonType);
            cannonTubeRect = new Rectangle(0, 0, (int)(CANNON_WIDTH * TUBE_EXT_RATIO_WIDTH),
                                           (int)(CANNON_HEIGHT - (EXT_TUBE_RATIO_HEIGHT * CANNON_HEIGHT)));
            cannonTubeRect.X = cannonExtRect.X + (cannonExtRect.Width / 2 - (cannonTubeRect.Width / 2));
            cannonTubeRect.Y = bgRect.Y + SPACING;

            cannonExtRect.Y = cannonTubeRect.Y + cannonTubeRect.Height;

            cannonBgImg  = Utilities.RectImage;
            cannonBgRect = new Rectangle(cannonExtRect.X, cannonExtRect.Y, cannonExtRect.Width, cannonExtRect.Height);

            name    = Language.Translate(cannon.CannonType.ToString().AddSpaces());
            namePos = new Vector2(bgRect.X + (bgRect.Width / 2 - (font.MeasureString(name).X / 2)),
                                  cannonExtRect.Bottom);
        }
        public void Update(CannonSettings settings, User user, GameTime gameTime)
        {
            bool atMax = user.CannonSettings.GetValueOfStat(stat) == GameInfo.MaxStats[stat];

            upgradeButton.Active = (user.Coins >= cost) && !atMax;
            upgradeButton.Text   = atMax ? Language.Translate("Max Level") :
                                   Language.Translate("Upgrade") + " " + valueString;
            upgradeButton.Update(gameTime);
            currentValue = settings.GetValueOfStat(stat);

            cost       = GameInfo.GetCostOfStat(stat, settings.GetValueOfStat(stat));
            costString = atMax ? Language.Translate("Max Level") : Language.Translate("Cost") + ": " + cost;
            costPos.X  = bgRect.X + (bgRect.Width / 2 - (font.MeasureString(costString).X / 2));

            Rectangle mouseRect = new Rectangle(Mouse.GetState().X, Mouse.GetState().Y, 1, 1);

            HoveringOnItem = mouseRect.Intersects(iconRect);
        }
 public void Initialize(User user)
 {
     for (int i = 0; i < cannonInterfaces.Count; i++)
     {
         cannonInterfaces[i].SetBought(false);
         cannonInterfaces[i].SetSelected(false);
         if (user.Cannons.Any(x => x.CannonType == cannonInterfaces[i].Cannon.CannonType))
         {
             cannonInterfaces[i].SetBought(true);
             CannonSettings cannon = user.Cannons.First((x) => x.CannonType == cannonInterfaces[i].Cannon.CannonType);
             if (user.Cannons[user.CannonIndex].CannonType == cannonInterfaces[i].Cannon.CannonType)
             {
                 cannonInterfaces[i].SetSelected(true);
             }
         }
         // Update cannon interface to current language
         cannonInterfaces[i].LangChanged();
     }
     UpdateCannonPositions();
     UpdateMaterialPositions(0, null, 0, false, null);
     UpdateGiftPositions();
 }
        public void ResetCannon(CannonSettings cannon)
        {
            name = cannon.CannonType.ToString().AddSpaces() + " Cannon";
            desc = Utilities.GetDescOf(cannon.CannonType);

            stats.Clear();
            stats = new List <NameValue>()
            {
                new NameValue("Damage", cannon.Damage.ToString()),
                new NameValue("Health", cannon.MaxHealth.ToString()),
                new NameValue("Reload Speed", cannon.ReloadSpeed.ToString()),
                new NameValue("Move Speed", cannon.MoveSpeed.ToString()),
                new NameValue("Accuracy", cannon.Accuracy.ToString()),
                new NameValue("Rapid Fire", cannon.RapidFire > 0 ? "Y" : "N"),
            };
            if (cannon.Freezes)
            {
                stats.Add(new NameValue("Effect Added", "Frozen"));
            }
            else
            {
                stats.Add(new NameValue("Effect Added", cannon.EffectAdded.ToString().AddSpaces()));
            }
        }
        public void Update(CannonSettings settings, User user, GameTime gameTime)
        {
            if (slideOffset + X_OFFSET >= windowWidth || slideOffset + (X_OFFSET * -1) <= windowWidth * -1)
            {
                slideOffset = 0;
                slidingOver = false;
                page        = transitionPage;
            }

            if (page <= pages.Count - 1)
            {
                if (slidingOver)
                {
                    int offset = 0;
                    if (slideSpd < 0)
                    {
                        offset = (interfaces[0].Width + SPACING) * 5 + X_OFFSET;
                    }
                    else
                    {
                        offset = ((interfaces[0].Width + SPACING) * 5 + X_OFFSET) * -1;
                    }
                    UpdatePositions(transitionPage, offset, settings, user, gameTime);
                }

                UpdatePositions(page, 0, settings, user, gameTime);
            }

            for (int i = 0; i <= pages.Count - 1; i++)
            {
                if (pages[i].Count <= 0)
                {
                    pages.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;
            }

            bool active = false;

            for (int i = 0; i < pages[page].Count; i++)
            {
                if (pages[page][i].HoveringOnItem)
                {
                    active = true;
                    statInfoHover.ResetStat(pages[page][i].Stat);
                }
            }
            statInfoHover.Active = active;
            if (statInfoHover.Active)
            {
                statInfoHover.Update();
            }
        }
 public void Replace(CannonSettings newValue)
 {
     this = newValue;
 }
        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
                }
            }
        }
 public void SetCannon(CannonSettings cannon)
 {
     Cannon = cannon;
 }