Example #1
0
        public override void receiveLeftClick(int x, int y, bool playSound = true)
        {
            if (Game1.globalFade)
            {
                return;
            }
            if (_movingAnimal.GetValue())
            {
                Building buildingAt = (Game1.getLocationFromName("Farm") as Farm).getBuildingAt(new Vector2((float)((x + Game1.viewport.X) / Game1.tileSize), (float)((y + Game1.viewport.Y) / Game1.tileSize)));
                if
                (
                    buildingAt != null &&
                    buildingAt.buildingType.Value.Contains(this._farmAnimal.buildingTypeILiveIn.Value) &&
                    !((AnimalHouse)buildingAt.indoors.Value).isFull() &&
                    !buildingAt.Equals((object)this._farmAnimal.home) &&
                    PregnancyController.IsAnimalPregnant(this._farmAnimal.myID.Value) &&
                    PregnancyController.CheckBuildingLimit(((AnimalHouse)buildingAt.indoors.Value))
                )
                {
                    if (this.okButton != null && this.okButton.containsPoint(x, y))
                    {
                        Game1.globalFadeToBlack(new Game1.afterFadeFunction(this.prepareForReturnFromPlacement), 0.02f);
                        Game1.playSound("smallSelect");
                    }
                    Game1.showRedMessage(DataLoader.i18n.Get("Menu.AnimalQueryMenu.PregnancyBuildingLimit", new { buildingType = this._farmAnimal.displayHouse }));
                    return;
                }
            }
            else if (this.confirmingMeat)
            {
                if (this.yesButton.containsPoint(x, y))
                {
                    (this._farmAnimal.home.indoors.Value as AnimalHouse)?.animalsThatLiveHere.Remove(this._farmAnimal.myID.Value);
                    this._farmAnimal.health.Value = -1;
                    int num1 = this._farmAnimal.frontBackSourceRect.Width / 2;
                    for (int index = 0; index < num1; ++index)
                    {
                        int num2 = Game1.random.Next(25, 200);
                        Game1.currentLocation.temporarySprites.Add(new TemporaryAnimatedSprite(5, this._farmAnimal.position + new Vector2((float)Game1.random.Next(-Game1.tileSize / 2, this._farmAnimal.frontBackSourceRect.Width * 3), (float)Game1.random.Next(-Game1.tileSize / 2, this._farmAnimal.frontBackSourceRect.Height * 3)), new Color((int)byte.MaxValue - num2, (int)byte.MaxValue, (int)byte.MaxValue - num2), 8, false, Game1.random.NextDouble() < 0.5 ? 50f : (float)Game1.random.Next(30, 200), 0, Game1.tileSize, -1f, Game1.tileSize, Game1.random.NextDouble() < 0.5 ? 0 : Game1.random.Next(0, 600))
                        {
                            scale  = (float)Game1.random.Next(2, 5) * 0.25f,
                            alpha  = (float)Game1.random.Next(2, 5) * 0.25f,
                            motion = new Vector2(0.0f, (float)-Game1.random.NextDouble())
                        });
                    }
                    Game1.playSound("newRecipe");
                    Game1.playSound("money");
                    Game1.exitActiveMenu();
                    Game1.player.Stamina -= ((float)4f - (float)Game1.player.FarmingLevel * 0.2f);
                    Game1.player.Stamina -= ((float)4f - (float)Game1.player.FarmingLevel * 0.2f);
                    Game1.player.gainExperience(0, 5);
                    MeatController.AddItemsToInventoryByMenuIfNecessary(MeatController.CreateMeat(this._farmAnimal));
                }
                else
                {
                    if (!this.noButton.containsPoint(x, y))
                    {
                        return;
                    }
                    this.confirmingMeat = false;
                    Game1.playSound("smallSelect");
                    if (!Game1.options.SnappyMenus)
                    {
                        return;
                    }
                    this.currentlySnappedComponent = this.getComponentWithID(103);
                    this.snapCursorToCurrentSnappedComponent();
                }
                return;
            }
            else if (!_confirmingSell.GetValue())
            {
                if (this.meatButton?.containsPoint(x, y) ?? false)
                {
                    this.confirmingMeat = true;
                    ClickableTextureComponent textureComponent1 = new ClickableTextureComponent(new Microsoft.Xna.Framework.Rectangle(Game1.viewport.Width / 2 - Game1.tileSize - 4, Game1.viewport.Height / 2 - Game1.tileSize / 2, Game1.tileSize, Game1.tileSize), Game1.mouseCursors, Game1.getSourceRectForStandardTileSheet(Game1.mouseCursors, 46, -1, -1), 1f, false);
                    textureComponent1.myID            = 111;
                    textureComponent1.rightNeighborID = 105;
                    this.yesButton = textureComponent1;
                    ClickableTextureComponent textureComponent2 = new ClickableTextureComponent(new Microsoft.Xna.Framework.Rectangle(Game1.viewport.Width / 2 + 4, Game1.viewport.Height / 2 - Game1.tileSize / 2, Game1.tileSize, Game1.tileSize), Game1.mouseCursors, Game1.getSourceRectForStandardTileSheet(Game1.mouseCursors, 47, -1, -1), 1f, false);
                    textureComponent2.myID           = 105;
                    textureComponent2.leftNeighborID = 111;
                    this.noButton = textureComponent2;
                    Game1.playSound("smallSelect");
                    if (!Game1.options.SnappyMenus)
                    {
                        return;
                    }
                    this.populateClickableComponentList();
                    this.currentlySnappedComponent = (ClickableComponent)this.noButton;
                    this.snapCursorToCurrentSnappedComponent();
                }
                else if (this.animalContestIndicator?.containsPoint(x, y) ?? false && AnimalContestController.CanChangeParticipant(this._farmAnimal))
                {
                    this.animalContestIndicator = null;
                    AnimalContestController.RemoveAnimalParticipant(this._farmAnimal);
                    Game1.player.addItemByMenuIfNecessary(new ParticipantRibbon());
                }
            }

            base.receiveLeftClick(x, y, playSound);
        }
Example #2
0
 public override void performHoverAction(int x, int y)
 {
     base.performHoverAction(x, y);
     if (_movingAnimal.GetValue())
     {
         Vector2  tile             = new Vector2((float)((x + Game1.viewport.X) / Game1.tileSize), (float)((y + Game1.viewport.Y) / Game1.tileSize));
         Farm     locationFromName = Game1.getLocationFromName("Farm") as Farm;
         Building buildingAt       = locationFromName.getBuildingAt(tile);
         if (buildingAt != null)
         {
             if (buildingAt.color.Equals(Color.LightGreen * 0.8f) &&
                 PregnancyController.IsAnimalPregnant(this._farmAnimal.myID.Value) &&
                 PregnancyController.CheckBuildingLimit((buildingAt.indoors.Value as AnimalHouse)))
             {
                 buildingAt.color.Value = Color.Red * 0.8f;
             }
         }
     }
     else
     {
         if (this.meatButton != null)
         {
             if (this.meatButton.containsPoint(x, y))
             {
                 this.meatButton.scale = Math.Min(4.1f, this.meatButton.scale + 0.05f);
                 _hoverText.SetValue(DataLoader.i18n.Get("Menu.AnimalQueryMenu.ExchangeAnimalForMeat"));
             }
             else
             {
                 this.meatButton.scale = Math.Max(4f, this.sellButton.scale - 0.05f);
             }
         }
         if (this.pregnantStatus != null)
         {
             if (this.pregnantStatus.containsPoint(x, y))
             {
                 int daysUtilBirth = PregnancyController.GetPregnancyItem(this._farmAnimal.myID.Value).DaysUntilBirth;
                 if (daysUtilBirth > 1)
                 {
                     _hoverText.SetValue(DataLoader.i18n.Get("Menu.AnimalQueryMenu.DaysUntilBirth", new { numberOfDays = daysUtilBirth }));
                 }
                 else
                 {
                     _hoverText.SetValue(DataLoader.i18n.Get("Menu.AnimalQueryMenu.ReadyForBirth"));
                 }
             }
         }
         if (this.treatStatus != null)
         {
             if (this.treatStatus.containsPoint(x, y))
             {
                 int daysUntilNextTreat = TreatsController.DaysUntilNextTreat(this._farmAnimal);
                 if (daysUntilNextTreat > 1)
                 {
                     _hoverText.SetValue(DataLoader.i18n.Get("Menu.AnimalQueryMenu.WantsTreatInDays", new { numberOfDays = daysUntilNextTreat }));
                 }
                 else if (daysUntilNextTreat == 1)
                 {
                     _hoverText.SetValue(DataLoader.i18n.Get("Menu.AnimalQueryMenu.WantsTreatTomorrow"));
                 }
                 else
                 {
                     _hoverText.SetValue(DataLoader.i18n.Get("Menu.AnimalQueryMenu.WantsTreat"));
                 }
             }
         }
         if (this.animalContestIndicator != null)
         {
             if (this.animalContestIndicator.containsPoint(x, y))
             {
                 if (AnimalContestController.CanChangeParticipant(this._farmAnimal))
                 {
                     _hoverText.SetValue(DataLoader.i18n.Get("Menu.AnimalQueryMenu.ChangeParticipant"));
                 }
                 else if (AnimalContestController.HasParticipated(this._farmAnimal) && AnimalContestController.HasWon(this._farmAnimal))
                 {
                     SDate date = AnimalContestController.GetParticipantDate(this._farmAnimal);
                     _hoverText.SetValue(DataLoader.i18n.Get("Menu.AnimalQueryMenu.Winner", new { contestDate = Utility.getDateStringFor(date.Day, Utility.getSeasonNumber(date.Season), date.Year) }));
                 }
                 else
                 {
                     SDate date = AnimalContestController.GetParticipantDate(this._farmAnimal);
                     _hoverText.SetValue(DataLoader.i18n.Get("Menu.AnimalQueryMenu.ContestParticipant", new { contestDate = Utility.getDateStringFor(date.Day, Utility.getSeasonNumber(date.Season), date.Year) }));
                 }
             }
         }
     }
 }