Example #1
0
        private IGameOption _renderOption(IGameOption opt, FlorineSkiaOptionSet Container)
        {
            FlorineSkiaOption newOpt = new FlorineSkiaOption(opt, Container);

            if (null != newOpt.SubOptions)
            {
                newOpt.SubOptions = _renderOptionSet(opt.SubOptions);
            }

            // Absurdly Hackity
            String pathType = "food";

            if (opt is Activity)
            {
                //Activity
                newOpt.Description       = ((Activity)opt).Description;
                Container.SelectionModel = FlorineSkiaOptionSet.SelectionType.SELECT_MOVE;
                pathType = "activities";
                string  tokenName   = opt.OptionName;
                SKImage ResultImage = ResourceLoader.LoadImage("Images/" + pathType + "/" + tokenName.ToLower() + ".png");
                newOpt.Picture = new SelectableOptionImage()
                {
                    FoodImage = ((null == ResultImage) ?
                                 (IFlorineSkiaDrawable)(new ImageText(tokenName))
                        : (IFlorineSkiaDrawable)(new FlOval()
                    {
                        mainImage = ResultImage,
                        backgroundColor = new SKPaint()
                        {
                            Color = new SKColor(230, 230, 230)
                        }
                    }))
                };
            }
            else
            {
                // Food
                FlorineSkiaOption SourceOpt = opt as FlorineSkiaOption;
                Food.FoodOption   food_data = opt as Food.FoodOption;
                if (null == food_data && SourceOpt != null)
                {
                    food_data = SourceOpt.SourceOpt as Food.FoodOption;
                }

                if (null != food_data)
                {
                    newOpt.Description = food_data.Parent.Description;
                }
                else
                {
                    newOpt.Description = "Desc Missing";
                }
                List <Tuple <float, SKColor> > MacroNuts = new List <Tuple <float, SKColor> >();
                List <Tuple <float, SKColor> > MicroNuts = new List <Tuple <float, SKColor> >();

                if (null != food_data && food_data.Parent.IsKnown)
                {
                    // Populate nutrient info bars.
                    // List<Tuple<float, SKColor>>

                    foreach (KeyValuePair <Nutrient, NutrientAmount> kvp in food_data.Parent.Nutrients)
                    {
                        FlorineSkiaNutrient AdjNut = new FlorineSkiaNutrient(kvp.Key);
                        float RelativeAmount       = kvp.Key.RatioRDV(kvp.Value);

                        //45 * ((float)(kvp.Value) / (float)(kvp.Key.DailyTarget));
                        //if (RelativeAmount > 45.0f) { RelativeAmount = 45.0f; }
                        if (kvp.Key.Class == Nutrient.NutrientType.Macro)
                        {
                            RelativeAmount *= 180f / 4f;
                            MacroNuts.Add(new Tuple <float, SKColor>(
                                              RelativeAmount,
                                              AdjNut.RingColor
                                              ));
                        }
                        else
                        {
                            if (RelativeAmount > 1f)
                            {
                                RelativeAmount = 1f;
                            }
                            RelativeAmount *= 180 / 6f;
                            MicroNuts.Add(new Tuple <float, SKColor>(
                                              RelativeAmount,
                                              AdjNut.RingColor
                                              ));
                        }
                    }
                }
                string tokenName = opt.OptionName;
                switch (tokenName)
                {
                case "Grilled Cheese":
                    tokenName = "grilledcheese"; break;

                case "Pancakes":
                    tokenName = "pancakes"; break;

                case "Fruit":
                    tokenName = "fruit"; break;

                case "Eggs":
                    tokenName = "eggs"; break;

                case "Cereal":
                    tokenName = "cereal"; break;

                case "Toaster Pastry":
                    tokenName = "toastedpastry"; break;

                case "Toast":
                case "White Toast":
                case "Wheat Toast":
                case "Multigrain Toast":
                    tokenName = "toast"; break;

                case "Strawberry Yogurt":
                    tokenName = "yogurt"; break;

                case "Eggs, Bacon, and Toast":
                    tokenName = "toasteggsbacon"; break;

                case "Hamburger":
                    tokenName = "hamburger"; break;

                case "Chocolate Ice Cream":
                    tokenName = "icecream"; break;

                case "Instant Noodles":
                    tokenName = "instantnoodles"; break;

                case "Lamb Chops":
                    tokenName = "lambchops"; break;

                case "Meatball Sub":
                    tokenName = "meatballhero"; break;

                case "Peanut Butter & Jelly":
                    tokenName = "pbj"; break;

                case "Pepperoni Pizza Slice":
                    tokenName = "pizza"; break;

                case "Vegetable Soup":
                    tokenName = "soup"; break;

                case "Spaghetti":
                    tokenName = "spaghetti"; break;

                case "Spaghetti w/ Meatballs":
                    tokenName = "spaghettiwmeatball"; break;

                case "Sushi Serving":
                    tokenName = "sushi"; break;

                case "Tacos":
                    tokenName = "tacos"; break;

                case "Donuts":
                    tokenName = "donuts"; break;

                case "Cinnamon Roll":
                    tokenName = "cinnamonroll"; break;

                case "Hamburger Combo":
                    tokenName = "hamburgercombo"; break;

                case "Turkey Sandwich":
                    tokenName = "sandwich"; break;

                case "Sandwich with Chips":
                    tokenName = "sandwichwchips"; break;

                case "Salad":
                    tokenName = "salad"; break;

                case "Fruit Smoothie":
                    tokenName = "fruitsmoothie"; break;
                }

                SKImage ResultImage = ResourceLoader.LoadImage("Images/" + pathType + "/" + tokenName + ".png");
                if (opt is FlorineHardCodedData.HardCodedDataFoundry.NoSelectFoodOption)
                {
                    newOpt.Picture = new SelectableOptionImage()
                    {
                        FoodImage = new LayeredImage()
                        {
                            Layers =
                            {
                                new ImageText(opt.OptionName)
                                {
                                    Overflow = ImageText.WrapType.DiamondWrap, FontSize = 32f
                                },
                                new FlOval()
                                {
                                    mainImage       = null,
                                    backgroundColor = new SKPaint()
                                    {
                                        Color = new SKColor(212, 175, 5)
                                    },
                                    RightRing = MicroNuts,
                                    LeftRing  = MacroNuts,
                                }
                            }
                        }
                    };
                }
                else
                {
                    newOpt.Picture = new SelectableOptionImage()
                    {
                        FoodImage = ((null == ResultImage) ?
                                     (IFlorineSkiaDrawable)(new ImageText(opt.OptionName))
                            : (IFlorineSkiaDrawable)(new FlOval()
                        {
                            mainImage = ResultImage,
                            backgroundColor = new SKPaint()
                            {
                                Color = new SKColor(230, 230, 230)
                            },
                            RightRing = MicroNuts,
                            LeftRing = MacroNuts,
                        }))
                    };
                }
            }

            return(newOpt);
        }
Example #2
0
 public bool ToggleOption(IGameOption opt)
 {
     if (!opt.Enabled)
     {
         return(false);
     }
     if (_selected.Contains(opt))
     {
         if (SelectionModel == SelectionType.SELECT_MOVE)
         {
             return(true);
         }
         UpdaterHook.DisplayIt(string.Empty);
         _selected.Remove(opt);
         return(false);
     }
     if (_selected.Count > SelectionLimit || SelectionLimit == 0)
     {
         return(false);
     }
     if (_selected.Count == SelectionLimit)
     {
         if (SelectionModel == SelectionType.SELECT_MOVE)
         {
             // Remove the first item on the list to clear room.
             FlorineSkiaOption deadOpt = _selected[0] as FlorineSkiaOption;
             _selected.RemoveAt(0);
             if (null != deadOpt)
             {
                 deadOpt.Redraw();
             }
         }
         else
         {
             // Default refuse to add the option
             return(false);
         }
     }
     foreach (IGameOption nopt in this)
     {
         if (nopt == opt)
         {
             _selected.Add(opt);
             FlorineSkiaOption showOpt = opt as FlorineSkiaOption;
             if (null != showOpt)
             {
                 string          Description = showOpt.Description;
                 List <string>   Details     = new List <string>();
                 Food.FoodOption fOpt        = showOpt.SourceOpt as Food.FoodOption;
                 if (null != fOpt)
                 {
                     if (fOpt.Parent.IsKnown && !fOpt.Parent.IsKnown)
                     {
                         StringBuilder SB = new StringBuilder();
                         SB.Append("Calories").Append(": ").Append(fOpt.Parent.Nutrients.AsCalories()).AppendLine();
                         Details.Add(SB.ToString());
                         foreach (KeyValuePair <Nutrient, NutrientAmount> kvp in fOpt.Parent.Nutrients)
                         {
                             if (kvp.Value > double.Epsilon)
                             {
                                 if (kvp.Key.Class == Nutrient.NutrientType.Macro)
                                 {
                                     Details.Add(kvp.Key.Name + ": " + kvp.Value.ToString("F0") + "g");
                                 }
                                 else
                                 {
                                     float  Ratio       = kvp.Key.RatioRDV(kvp.Value);
                                     string RatioString = Ratio.ToString("P0");
                                     Details.Add(kvp.Key.Name + ": " + RatioString);
                                 }
                             }
                         }
                     }
                 }
                 UpdaterHook.DisplayIt(Description, Details);
             }
             return(true);
         }
     }
     return(false);
 }