private SKRect GetAnotationScreenRect(FishModel fish)
        {
            // get marker location
            var markerScreenPos = GetMarkerOnScreenPos(fish);

            // get annotation
            SKBitmap annotation = null;

            var annotationType = GetAnnotationDisplayType(fish);

            switch (annotationType)
            {
            case AnnotationDisplayType.Center:
                annotation = fishAnnotations[fish].OnscreenAnnotation;
                SKRect rect = new SKRect(0, 0, annotation.Width, annotation.Height);
                rect.Location = markerScreenPos;
                rect.Offset(-(annotation.Width / 2), -(annotation.Height / 2 + lineLength));
                return(rect);

            case AnnotationDisplayType.Left:
                annotation = fishAnnotations[fish].LeftAnnotation;
                SKRect left = new SKRect(0, 0, annotation.Width, annotation.Height);
                left.Offset(0, markerScreenPos.Y - (annotation.Height / 2 + lineLength));
                return(left);

            case AnnotationDisplayType.Right:
                annotation = fishAnnotations[fish].RightAnnotation;
                SKRect right = new SKRect(0, 0, annotation.Width, annotation.Height);
                right.Offset(ScreenWindowRect.Width - annotation.Width, markerScreenPos.Y - (annotation.Height / 2 + lineLength));
                return(right);
            }
            return(SKRect.Empty);
        }
        private SKPoint GetMarkerOnScreenPos(FishModel fish)
        {
            var markerPos = GetMarkerAbsolutePos(fish);

            markerPos.Offset(-ScrollPosition, 0);
            return(markerPos);
        }
Exemplo n.º 3
0
        private async Task <FishAnnotation> CreateAnnotations(FishModel fish)
        {
            var annotation = new FishAnnotation();
            // create an image for the fish
            await annotation.CreateAnnotations(fish);

            return(annotation);
        }
        private SKPoint GetMarkerAbsolutePos(FishModel fish)
        {
            SKPoint markerPos = new SKPoint()
            {
                X = (float)(backgroundBitmap.Width * fish.AnchorX),
                Y = (float)(backgroundBitmap.Height * fish.AnchorY)
            };

            return(markerPos);
        }
        public FishModel GetFishByName(string name)
        {
            var fish = this.dbContext.Fish.Include(f => f.Lakes).FirstOrDefault(f => f.Name == name);

            if (fish != null)
            {
                return(FishModel.CastWithIncludedLakes(fish));
            }

            return(null);
        }
        public IEnumerable <AnimalCrossingNewHorizonsFish> Get()
        {
            FishModel model = new FishModel();

            return(model.Get().Select(fish => new AnimalCrossingNewHorizonsFish
            {
                Name = fish.Name,
                ImageURL = "",
                Price = uint.Parse(fish.Price.Replace(",", String.Empty))
            }));
        }
        private AnnotationDisplayType GetAnnotationDisplayType(FishModel fish)
        {
            var markerPos = GetMarkerAbsolutePos(fish);

            if (markerPos.X < ScreenWindowRect.Left)
            {
                return(AnnotationDisplayType.Left);
            }

            if (markerPos.X > ScreenWindowRect.Right)
            {
                return(AnnotationDisplayType.Right);
            }

            return(AnnotationDisplayType.Center);
        }
Exemplo n.º 8
0
        public FishModel UpdateFish(int id, FishModel model, out string errorMsg)
        {
            var theFish = GetFishById(id);

            if (theFish == null)
            {
                errorMsg = "fish not found";
                throw new Exception(errorMsg);
            }
            theFish.DateModified = DateTime.Now;
            theFish.Specie       = model.Specie;

            // fish is assumed to be saved at this point.

            errorMsg = "";
            return(theFish);
        }
Exemplo n.º 9
0
        public async Task CreateLeftAnnotation(FishModel fish)
        {
            SKBitmap bitmap = await CreateBaseAnnotation(fish);

            using (SKCanvas canvas = new SKCanvas(bitmap))
            {
                // draw the arrow
                SKPath path       = new SKPath();
                var    halfHeight = (float)(bitmap.Height * .5);
                path.MoveTo(0, halfHeight);
                path.LineTo(padding, halfHeight - padding);
                path.LineTo(padding, halfHeight + padding);
                path.LineTo(0, halfHeight);
                path.Close();
                canvas.DrawPath(path, annotationBackground);
            }
            LeftAnnotation = bitmap;
        }
Exemplo n.º 10
0
        public IHttpActionResult UpdateFish([FromBody] FishModel fish, int id)
        {
            var fishToUpdate = repo.GetFishById(id);

            if (fish == null)
            {
                return(NotFound());
            }

            string errorMsg = string.Empty;

            try
            {
                var updatedFish = repo.UpdateFish(id, fish, out errorMsg);
                return(Ok(updatedFish));
            }
            catch (Exception)
            {
                return(BadRequest(errorMsg));
            }
        }
Exemplo n.º 11
0
        internal async Task CreateAnnotations(FishModel fish)
        {
            // create a bitmap
            SKBitmap bitmap = new SKBitmap(Width + 2 * Padding, Height + 2 * Padding);

            using (SKCanvas canvas = new SKCanvas(bitmap))
            {
                canvas.Clear();
                // draw a rounded rect
                SKRect outline = new SKRect(0, 0, bitmap.Width, bitmap.Height);
                outline.Inflate(-Padding, -Padding);
                canvas.DrawRoundRect(outline, Radius, Radius, annotationBackground);

                // draw a fish in the middle
                outline.Inflate(-Padding, -Padding);
                var fishImage = await BitmapHelper.LoadBitmapFromUrl(fish.Image);

                canvas.DrawBitmap(fishImage, outline);
            }
            OnscreenAnnotation = bitmap;
        }
        public void CallFindByNameFromService_AndSetFishToViewModel()
        {
            // Arrange
            var mockedFish = new FishModel {
                Name = "First"
            };

            var mockedFishService = new Mock <IFishService>();

            mockedFishService.Setup(s => s.GetFishByName(It.IsAny <string>())).Returns(mockedFish).Verifiable();

            var controller = new FishListController(mockedFishService.Object);

            // Act
            var view  = controller.Details(null) as ViewResult;
            var model = view.ViewData.Model as FishListViewModel;

            // Assert
            Assert.AreEqual(mockedFish, model.SelectedFish);
            mockedFishService.Verify(s => s.GetFishByName(It.IsAny <string>()), Times.Once);
        }
Exemplo n.º 13
0
        internal async Task <SKBitmap> CreateBaseAnnotation(FishModel fish)
        {
            // create a bitmap
            SKBitmap bitmap = new SKBitmap(width + 2 * padding, height + 2 * padding);

            using (SKCanvas canvas = new SKCanvas(bitmap))
            {
                canvas.Clear();

                // draw a rounded rect
                SKRect outline = new SKRect(0, 0, bitmap.Width, bitmap.Height);
                outline.Inflate(-padding, -padding);
                canvas.DrawRoundRect(outline, radius, radius, annotationBackground);

                // draw a fish in the middle
                outline.Inflate(-padding, -padding);
                var fishImage = await BitmapHelper.LoadBitmapFromUrl(fish.Image);

                //canvas.DrawBitmap(fishImage, outline);
                canvas.DrawBitmap(fishImage, outline, BitmapStretch.AspectFit, BitmapAlignment.Center, BitmapAlignment.Center);
            }
            return(bitmap);
        }
Exemplo n.º 14
0
        public IHttpActionResult GetFishById([FromUri] int id)
        {
            FishModel fish = repo.GetFishById(id);

            return(Ok(fish));
        }
Exemplo n.º 15
0
        /* GameEvents_OnUpdateTick
         * Triggers 60 times per second.
         * Use one of the methods here https://stardewvalleywiki.com/Modding:Modder_Guide/APIs/Events#Game for other time durations
         */
        private void GameEvents_OnUpdateTick(object sender, EventArgs e)
        {
            if (Game1.player.CurrentTool is FishingRod rod)
            {
                if (rod.fishCaught && !this.PlayerReceivedFish)
                {
                    // Prevents the mod from giving the player 1 fish per tick ;)
                    this.PlayerReceivedFish = true;

                    this.whichFish = this.Helper.Reflection.GetField <int>(rod, "whichFish").GetValue();

                    // construct a temporary fish item to figure out what the caught fish's name is
                    FishItem tempFish = new FishItem(this.whichFish);

                    if (tempFish.Category == -4)   // is a fish

                    // get the list of fish in the Population with that name
                    {
                        List <FishModel> fishOfType;
                        this.population.TryGetValue(tempFish.Name, out fishOfType);

                        // get a random fish of that type from the population
                        int       numFishOfType     = fishOfType.Count;
                        int       selectedFishIndex = ModEntry.rand.Next(0, numFishOfType);
                        FishModel selectedFish      = fishOfType[selectedFishIndex];

                        this.Helper.Reflection.GetField <int>(rod, "fishSize").SetValue((int)Math.Round(selectedFish.length));

                        // store a new custom fish item
                        Item customFish = (Item) new FishItem(this.whichFish, selectedFish);
                        FishItem.itemToAdd = customFish as FishItem;
                        this.FishCaught    = customFish;

                        // make sure the fish in the ocean will be regenerated at the end of the day
                        this.AllFishCaughtToday.Add(new Tuple <string, int>(selectedFish.name, selectedFish.uniqueID));

                        // Prompt the player to throw back the fish
                        this.PromptThrowBackFish(selectedFish.name, selectedFish.uniqueID);
                    }
                }
            }


            if (Game1.activeClickableMenu is BobberBar && this.Bobber != null)
            {
                SBobberBar bobber = this.Bobber;

                if (!this.BeganFishingGame)
                {
                    this.OnFishingBegin();
                    this.PlayerReceivedFish = false;
                    this.BeganFishingGame   = true;
                }
            }
            else if (this.EndedFishingGame)
            {
                this.OnFishingEnd();
                this.EndedFishingGame = false;
            }
            else if (this.BeganFishingGame)
            {
                {}

                this.EndedFishingGame = true;
                this.BeganFishingGame = false;
            }
        }
Exemplo n.º 16
0
        public async Task CreateOnScreenAnnotation(FishModel fish)
        {
            int bitmapHeight = height + (2 * padding);

            // measure header
            string headerText   = fish.Name;
            SKRect headerBounds = new SKRect();

            headerPaint.MeasureText(headerText, ref headerBounds);

            string bodyText   = fish.FishSize;
            SKRect bodyBounds = new SKRect();

            bodyPaint.MeasureText(bodyText, ref bodyBounds);

            // position our fish
            SKRect fishBounds = new SKRect(0, 0, (height - padding * 2), (height - padding * 2));

            fishBounds.Offset(2 * padding, 2 * padding);

            // position the text
            var lineSpacing     = 10;
            var totalLineHeight = headerBounds.Height + lineSpacing + bodyBounds.Height;
            var topSpacing      = (bitmapHeight - totalLineHeight) / 2;

            headerBounds.Location = new SKPoint(fishBounds.Right + padding, topSpacing);
            bodyBounds.Location   = new SKPoint(fishBounds.Right + padding, headerBounds.Bottom + lineSpacing);

            var bitmapWidth = headerBounds.Width + fishBounds.Width + (5 * padding);

            SKBitmap bitmap = new SKBitmap((int)bitmapWidth, bitmapHeight);

            using (SKCanvas canvas = new SKCanvas(bitmap))
            {
                canvas.Clear();
                // draw a rounded rect
                SKRect outline = new SKRect(0, 0, bitmap.Width, bitmap.Height);
                outline.Inflate(-padding, -padding);
                canvas.DrawRoundRect(outline, radius, radius, annotationBackground);

                // draw our fish
                var fishImage = await BitmapHelper.LoadBitmapFromUrl(fish.Image);

                canvas.DrawBitmap(fishImage, fishBounds, BitmapStretch.AspectFit, BitmapAlignment.Center, BitmapAlignment.Center);

                // draw our text
                canvas.DrawText(headerText, headerBounds.Left, headerBounds.Bottom, headerPaint);
                canvas.DrawText(bodyText, bodyBounds.Left, bodyBounds.Bottom, bodyPaint);

                // draw an arrow
                SKPath path      = new SKPath();
                var    halfWidth = (float)(bitmap.Width * .5);
                path.MoveTo(halfWidth, bitmap.Height);
                path.LineTo(halfWidth - padding, bitmap.Height - padding);
                path.LineTo(halfWidth + padding, bitmap.Height - padding);
                path.LineTo(halfWidth, bitmap.Height);
                path.Close();
                canvas.DrawPath(path, annotationBackground);
            }
            OnscreenAnnotation = bitmap;
        }