Esempio n. 1
0
        private async void OnNewEntry(HistoryEntry he, HistoryList hl)
        {
            last_he = he;
            if (last_he != null)
            {
                if (bodyRadius == null || lastradiusbody != he.WhereAmI)                                                  // try and get radius, this is cleared on target selection
                {
                    StarScan.SystemNode last_sn = await discoveryform.history.StarScan.FindSystemAsync(he.System, false); // find scan if we have one

                    JournalScan sd = last_sn?.Find(he.WhereAmI)?.ScanData;                                                // find body scan data if present, null if not
                    bodyRadius = sd?.nRadius;
                    if (bodyRadius.HasValue)
                    {
                        lastradiusbody = he.WhereAmI;
                        System.Diagnostics.Debug.WriteLine("Compass Radius Set " + lastradiusbody + " " + bodyRadius.Value);
                    }
                }

                switch (he.journalEntry.EventTypeID)
                {
                case JournalTypeEnum.Screenshot:
                    JournalScreenshot js = he.journalEntry as JournalScreenshot;
                    latitude  = js.nLatitude;
                    longitude = js.nLongitude;
                    altitude  = js.nAltitude;
                    break;

                case JournalTypeEnum.Touchdown:
                    JournalTouchdown jt = he.journalEntry as JournalTouchdown;
                    if (jt.PlayerControlled.HasValue && jt.PlayerControlled.Value)
                    {
                        latitude  = jt.Latitude;
                        longitude = jt.Longitude;
                        altitude  = 0;
                    }
                    break;

                case JournalTypeEnum.Location:
                    JournalLocation jl = he.journalEntry as JournalLocation;
                    latitude  = jl.Latitude;
                    longitude = jl.Longitude;
                    altitude  = null;
                    break;

                case JournalTypeEnum.Liftoff:
                    JournalLiftoff jlo = he.journalEntry as JournalLiftoff;
                    if (jlo.PlayerControlled.HasValue && jlo.PlayerControlled.Value)
                    {
                        latitude  = jlo.Latitude;
                        longitude = jlo.Longitude;
                        altitude  = 0;
                    }
                    break;

                case JournalTypeEnum.LeaveBody:
                    latitude  = null;
                    longitude = null;
                    altitude  = null;
                    break;

                case JournalTypeEnum.FSDJump:           // to allow us to do PopulateBookmark..
                case JournalTypeEnum.CarrierJump:
                    break;

                default:
                    return;
                }

                PopulateBookmarkCombo();
                DisplayCompass();
            }
        }
        private async void Display()
        {
            HistoryEntry last_he = userControlSynthesis.CurrentHistoryEntry;             // sync with what its showing

            if (EngineeringWanted != null && SynthesisWanted != null && last_he != null) // if we have all the ingredients (get it!)
            {
                List <MaterialCommodityMicroResource> mcl = discoveryform.history.MaterialCommoditiesMicroResources.GetMaterialsSorted(last_he.MaterialCommodity);

                var totals = MaterialCommoditiesRecipe.TotalList(mcl);                  // start with totals present

                Color textcolour = IsTransparent ? discoveryform.theme.SPanelColor : discoveryform.theme.LabelColor;
                Color backcolour = this.BackColor;
                List <Tuple <Recipes.Recipe, int> > totalWanted = EngineeringWanted.Concat(SynthesisWanted).ToList();

                var shoppinglist = MaterialCommoditiesRecipe.GetShoppingList(totalWanted, mcl);

                JournalScan         sd      = null;
                StarScan.SystemNode last_sn = null;

                if (showListAvailability || showPlanetMats)
                {
                    last_sn = await discoveryform.history.StarScan.FindSystemAsync(last_he.System, useEDSMForSystemAvailability);

                    if (last_he.IsLanded && last_sn != null)           // if found node, and landed
                    {
                        sd = last_sn.Find(last_he.WhereAmI)?.ScanData; // find scan data for this body
                    }
                }

                StringBuilder wantedList = new StringBuilder();

                if (shoppinglist.Any())
                {
                    double available;
                    wantedList.Append("Needed Mats".T(EDTx.UserControlShoppingList_NM) + ":" + Environment.NewLine);
                    List <string> capExceededMats = new List <string>();
                    foreach (var c in shoppinglist)      // and add new..
                    {
                        string present = "";
                        if (showListAvailability && sd != null && sd.HasMaterials)
                        {
                            if (sd.Materials.TryGetValue(c.Item1.Details.FDName, out available))
                            {
                                present = $" {available.ToString("N1")}%";
                            }
                            else
                            {
                                present = " -";
                            }
                        }

                        wantedList.Append($"  {c.Item2} {c.Item1.Details.Name}{present}");
                        int?onHand   = mcl.Where(m => m.Details.Shortname == c.Item1.Details.Shortname).FirstOrDefault()?.Count;
                        int totalReq = c.Item2 + (onHand.HasValue ? onHand.Value : 0);
                        if ((c.Item1.Details.Type == MaterialCommodityMicroResourceType.ItemType.VeryCommon && totalReq > VeryCommonCap) ||
                            (c.Item1.Details.Type == MaterialCommodityMicroResourceType.ItemType.Common && totalReq > CommonCap) ||
                            (c.Item1.Details.Type == MaterialCommodityMicroResourceType.ItemType.Standard && totalReq > StandardCap) ||
                            (c.Item1.Details.Type == MaterialCommodityMicroResourceType.ItemType.Rare && totalReq > RareCap) ||
                            (c.Item1.Details.Type == MaterialCommodityMicroResourceType.ItemType.VeryRare && totalReq > VeryRareCap))
                        {
                            capExceededMats.Add(c.Item1.Details.Name);
                        }
                        if (!last_he.IsLanded && last_sn != null)
                        {
                            var landables = last_sn.Bodies.Where(b => b.ScanData != null && (!b.ScanData.IsEDSMBody || useEDSMForSystemAvailability) &&
                                                                 b.ScanData.HasMaterials && b.ScanData.Materials.ContainsKey(c.Item1.Details.FDName));
                            if (landables.Count() > 0)
                            {
                                wantedList.Append("\n    ");
                                List <Tuple <string, double> > allMats = new List <Tuple <string, double> >();
                                foreach (StarScan.ScanNode sn in landables)
                                {
                                    sn.ScanData.Materials.TryGetValue(c.Item1.Details.FDName, out available);
                                    allMats.Add(new Tuple <string, double>(sn.FullName.Replace(last_he.System.Name, "", StringComparison.InvariantCultureIgnoreCase).Trim(), available));
                                }
                                allMats = allMats.OrderByDescending(m => m.Item2).ToList();
                                int n = 1;
                                foreach (Tuple <string, double> m in allMats)
                                {
                                    if (n % 6 == 0)
                                    {
                                        wantedList.Append("\n    ");
                                    }
                                    wantedList.Append($"{m.Item1.ToUpperInvariant()}: {m.Item2.ToString("N1")}% ");
                                    n++;
                                }
                            }
                        }
                        wantedList.Append("\n");
                    }

                    if (capExceededMats.Any())
                    {
                        wantedList.Append(Environment.NewLine + "Filling Shopping List would exceed capacity for:".T(EDTx.UserControlShoppingList_FS));
                        foreach (string mat in capExceededMats)
                        {
                            wantedList.Append($"\n  {mat}");
                        }
                    }
                }
                else
                {
                    wantedList.Append("No materials currently required.".T(EDTx.UserControlShoppingList_NoMat));
                }

                if (showMaxInjections)
                {
                    var totals2 = MaterialCommoditiesRecipe.TotalList(mcl);                  // start with totals present

                    Tuple <int, int, string, string> basic    = MaterialCommoditiesRecipe.HowManyLeft(mcl, totals2, Recipes.SynthesisRecipes.First(r => r.Name == "FSD" && r.level == "Basic"));
                    Tuple <int, int, string, string> standard = MaterialCommoditiesRecipe.HowManyLeft(mcl, totals2, Recipes.SynthesisRecipes.First(r => r.Name == "FSD" && r.level == "Standard"));
                    Tuple <int, int, string, string> premium  = MaterialCommoditiesRecipe.HowManyLeft(mcl, totals2, Recipes.SynthesisRecipes.First(r => r.Name == "FSD" && r.level == "Premium"));
                    wantedList.Append(Environment.NewLine +
                                      string.Format("Max FSD Injections\r\n   {0} Basic\r\n   {1} Standard\r\n   {2} Premium".T(EDTx.UserControlShoppingList_FSD), basic.Item1, standard.Item1, premium.Item1));
                }

                if (showPlanetMats && sd != null && sd.HasMaterials)
                {
                    wantedList.Append(Environment.NewLine + Environment.NewLine + string.Format("Materials on {0}".T(EDTx.UserControlShoppingList_MO), last_he.WhereAmI) + Environment.NewLine);
                    foreach (KeyValuePair <string, double> mat in sd.Materials)
                    {
                        int?onHand = mcl.Where(m => m.Details.FDName == mat.Key).FirstOrDefault()?.Count;
                        MaterialCommodityMicroResourceType md = GetByFDName(mat.Key);
                        int max = md.MaterialLimit().Value;
                        if (!hidePlanetMatsWithNoCapacity || (onHand.HasValue ? onHand.Value : 0) < max)
                        {
                            wantedList.AppendFormat("   {0} {1}% ({2}/{3})\n", System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(mat.Key.ToLowerInvariant()),
                                                    mat.Value.ToString("N1"), (onHand.HasValue ? onHand.Value : 0), max);
                        }
                    }
                }

                Font font = discoveryform.theme.GetFont;
                pictureBoxList.ClearImageList();
                ExtPictureBox.ImageElement displayList = pictureBoxList.AddTextAutoSize(new Point(0, 0), new Size(1000, 1000), wantedList.ToNullSafeString(), font, textcolour, backcolour, 1.0F);
                pictureBoxList.Render();
                font.Dispose();

                try
                {
                    splitContainerVertical.SplitterDistance = (HorizonalSplitContainerPos ? displayList.Image.Height : displayList.Image.Width) + 8;       // panel left has minimum width to accomodate the text
                }
                catch (Exception e)
                {
                    System.Diagnostics.Debug.WriteLine("Shop list exception " + e);         // swallow the exception - seen an instance of it but wan't reproduce. #2512.
                }

                if (IsTransparent)
                {
                    RevertToNormalSize();
                    int minWidth = Math.Max(((UserControlForm)FindForm()).TitleBarMinWidth(), displayList.Image.Width) + 8;
                    RequestTemporaryResize(new Size(minWidth, displayList.Image.Height + 4));
                }
                else
                {
                    RevertToNormalSize();       // eng/synth is on, normal size
                }
            }

            // if transparent, we don't show the eng/synth panels
            userControlEngineering.Visible = userControlSynthesis.Visible = !IsTransparent;
            userControlEngineering.Enabled = userControlSynthesis.Enabled = !IsTransparent;
        }