public override void Init() { dataGridViewSynthesis.MakeDoubleBuffered(); dataGridViewSynthesis.DefaultCellStyle.WrapMode = DataGridViewTriState.False; dataGridViewSynthesis.RowTemplate.Height = 26; Order = SQLiteDBClass.GetSettingString(DbOSave, "").RestoreArrayFromString(0, SynthesisRecipes.Count); if (Order.Distinct().Count() != Order.Length) // if not distinct.. { for (int i = 0; i < Order.Length; i++) // reset { Order[i] = i; } } Wanted = SQLiteDBClass.GetSettingString(DbWSave, "").RestoreArrayFromString(0, SynthesisRecipes.Count); var rcpes = SynthesisRecipes.Select(r => r.name).Distinct().ToList(); rcpes.Sort(); rfs = new RecipeFilterSelector(rcpes); rfs.Changed += FilterChanged; var lvls = SynthesisRecipes.Select(r => r.level).Distinct().ToList(); lvls.Sort(); lfs = new RecipeFilterSelector(lvls); lfs.Changed += FilterChanged; List <string> matShortNames = SynthesisRecipes.SelectMany(r => r.ingredients).Distinct().ToList(); matLookUp = matShortNames.Select(sn => Tuple.Create <string, string>(sn, MaterialCommodityDB.GetCachedMaterialByShortName(sn).name)).ToList(); List <string> matLongNames = matLookUp.Select(lu => lu.Item2).ToList(); matLongNames.Sort(); mfs = new RecipeFilterSelector(matLongNames); mfs.Changed += FilterChanged; for (int i = 0; i < SynthesisRecipes.Count; i++) // pre-fill array.. preventing the crash on cell edit when you { int rno = Order[i]; MaterialCommoditiesList.SynthesisRecipe r = SynthesisRecipes[rno]; int rown = dataGridViewSynthesis.Rows.Add(); using (DataGridViewRow row = dataGridViewSynthesis.Rows[rown]) { row.Cells[0].Value = r.name; // debug rno + ":" + r.name; row.Cells[1].Value = r.level; row.Cells[6].Value = r.ingredientsstring; row.Tag = rno; row.Visible = false; } } discoveryform.OnNewEntry += Discoveryform_OnNewEntry; uctg.OnTravelSelectionChanged += Display; }
private 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 <MaterialCommodities> mcl = last_he.MaterialCommodity.Sort(false); MaterialCommoditiesList.ResetUsed(mcl); Color textcolour = IsTransparent ? discoveryform.theme.SPanelColor : discoveryform.theme.LabelColor; Color backcolour = this.BackColor; List <Tuple <MaterialCommoditiesList.Recipe, int> > totalWanted = EngineeringWanted.Concat(SynthesisWanted).ToList(); List <MaterialCommodities> shoppinglist = MaterialCommoditiesList.GetShoppingList(totalWanted, mcl); StringBuilder wantedList = new StringBuilder(); if (shoppinglist.Any()) { wantedList.Append("Needed Mats:\n"); foreach (MaterialCommodities c in shoppinglist.OrderBy(mat => mat.name)) // and add new.. { wantedList.AppendFormat(" {0} {1}\n", c.scratchpad, c.name); } int currentMats = mcl.Where(m => m.category == MaterialCommodityDB.MaterialManufacturedCategory || m.category == MaterialCommodityDB.MaterialRawCategory) .Sum(i => i.count); int currentData = mcl.Where(m => m.category == MaterialCommodityDB.MaterialEncodedCategory).Sum(i => i.count); int neededMats = shoppinglist.Where(m => m.category == MaterialCommodityDB.MaterialManufacturedCategory || m.category == MaterialCommodityDB.MaterialRawCategory) .Sum(i => i.scratchpad); int neededData = shoppinglist.Where(m => m.category == MaterialCommodityDB.MaterialEncodedCategory).Sum(i => i.scratchpad); if (currentMats + neededMats > PhysicalInventoryCapacity || currentData + neededData > DataInventoryCapacity) { wantedList.Append("\nNeeded capacity"); if (currentMats + neededMats > PhysicalInventoryCapacity) { wantedList.AppendFormat("\n {0} materials", currentMats + neededMats - PhysicalInventoryCapacity); } if (currentData + neededData > DataInventoryCapacity) { wantedList.AppendFormat("\n {0} data", currentData + neededData - DataInventoryCapacity); } } } else { wantedList.Append("No materials currently required."); } if (showMaxInjections) { MaterialCommoditiesList.ResetUsed(mcl); Tuple <int, int, string> basic = MaterialCommoditiesList.HowManyLeft(mcl, SynthesisRecipes.First(r => r.name == "FSD" && r.level == "Basic")); Tuple <int, int, string> standard = MaterialCommoditiesList.HowManyLeft(mcl, SynthesisRecipes.First(r => r.name == "FSD" && r.level == "Standard")); Tuple <int, int, string> premium = MaterialCommoditiesList.HowManyLeft(mcl, SynthesisRecipes.First(r => r.name == "FSD" && r.level == "Premium")); wantedList.Append($"\nMax FSD Injections\n {basic.Item1} Basic\n {standard.Item1} Standard\n {premium.Item1} Premium"); } Font font = discoveryform.theme.GetFont; pictureBoxList.ClearImageList(); PictureBoxHotspot.ImageElement displayList = pictureBoxList.AddTextAutoSize(new Point(0, 0), new Size(1000, 1000), wantedList.ToNullSafeString(), font, textcolour, backcolour, 1.0F); pictureBoxList.Render(); font.Dispose(); // if transparent, we don't show the eng/synth panels userControlEngineering.Visible = userControlSynthesis.Visible = !IsTransparent; userControlEngineering.Enabled = userControlSynthesis.Enabled = !IsTransparent; splitContainerVertical.Panel1MinSize = displayList.img.Width + 8; // panel left has minimum width to accomodate the text if (IsTransparent) { RevertToNormalSize(); int minWidth = Math.Max(((UserControlForm)FindForm()).TitleBarMinWidth(), displayList.img.Width) + 8; RequestTemporaryResize(new Size(minWidth, displayList.img.Height + 4)); } else { RevertToNormalSize(); // eng/synth is on, normal size } } }
private 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 <MaterialCommodities> mcl = last_he.MaterialCommodity.Sort(false); MaterialCommoditiesList.ResetUsed(mcl); Color textcolour = IsTransparent ? discoveryform.theme.SPanelColor : discoveryform.theme.LabelColor; Color backcolour = this.BackColor; List <Tuple <MaterialCommoditiesList.Recipe, int> > totalWanted = EngineeringWanted.Concat(SynthesisWanted).ToList(); List <MaterialCommodities> shoppinglist = MaterialCommoditiesList.GetShoppingList(totalWanted, mcl); JournalScan sd = null; StarScan.SystemNode last_sn = null; if (last_he.IsLanded && (showListAvailability || showPlanetMats)) { sd = discoveryform.history.GetScans(last_he.System.name).Where(sc => sc.BodyName == last_he.WhereAmI).FirstOrDefault(); } if (!last_he.IsLanded && showSystemAvailability) //replace true with a setting { last_sn = discoveryform.history.starscan.FindSystem(last_he.System, useEDSMForSystemAvailability); } StringBuilder wantedList = new StringBuilder(); if (shoppinglist.Any()) { double available; wantedList.Append("Needed Mats:\n"); foreach (MaterialCommodities c in shoppinglist.OrderBy(mat => mat.name)) // and add new.. { string present = ""; if (showListAvailability) { if (sd != null) { if (sd.Materials.TryGetValue(c.fdname, out available)) { present = $" {available.ToString("N1")}%"; } else { present = " -"; } } } wantedList.Append($" {c.scratchpad} {c.name}{present}"); 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.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.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(); foreach (Tuple <string, double> m in allMats) { wantedList.Append($"{m.Item1}: {m.Item2.ToString("N1")}% "); } } } wantedList.Append("\n"); } int currentMats = mcl.Where(m => m.category == MaterialCommodityDB.MaterialManufacturedCategory || m.category == MaterialCommodityDB.MaterialRawCategory) .Sum(i => i.count); int currentData = mcl.Where(m => m.category == MaterialCommodityDB.MaterialEncodedCategory).Sum(i => i.count); int neededMats = shoppinglist.Where(m => m.category == MaterialCommodityDB.MaterialManufacturedCategory || m.category == MaterialCommodityDB.MaterialRawCategory) .Sum(i => i.scratchpad); int neededData = shoppinglist.Where(m => m.category == MaterialCommodityDB.MaterialEncodedCategory).Sum(i => i.scratchpad); if (currentMats + neededMats > PhysicalInventoryCapacity || currentData + neededData > DataInventoryCapacity) { wantedList.Append("\nCapacity Warning:"); if (currentMats + neededMats > PhysicalInventoryCapacity) { wantedList.Append($"\n {PhysicalInventoryCapacity - currentMats}/{neededMats} materials space free"); } if (currentData + neededData > DataInventoryCapacity) { wantedList.Append($"\n {DataInventoryCapacity - currentData}/{neededData} data space free"); } wantedList.Append("\n"); } } else { wantedList.Append("No materials currently required."); } if (showMaxInjections) { MaterialCommoditiesList.ResetUsed(mcl); Tuple <int, int, string> basic = MaterialCommoditiesList.HowManyLeft(mcl, SynthesisRecipes.First(r => r.name == "FSD" && r.level == "Basic")); Tuple <int, int, string> standard = MaterialCommoditiesList.HowManyLeft(mcl, SynthesisRecipes.First(r => r.name == "FSD" && r.level == "Standard")); Tuple <int, int, string> premium = MaterialCommoditiesList.HowManyLeft(mcl, SynthesisRecipes.First(r => r.name == "FSD" && r.level == "Premium")); wantedList.Append($"\nMax FSD Injections\n {basic.Item1} Basic\n {standard.Item1} Standard\n {premium.Item1} Premium"); } if (showPlanetMats && sd != null) //for user configurable setting { wantedList.Append($"\n\nMaterials on {last_he.WhereAmI}\n"); foreach (KeyValuePair <string, double> mat in sd.Materials) { wantedList.AppendFormat(" {0} {1}%\n", System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(mat.Key.ToLower()), mat.Value.ToString("N1")); } } Font font = discoveryform.theme.GetFont; pictureBoxList.ClearImageList(); PictureBoxHotspot.ImageElement displayList = pictureBoxList.AddTextAutoSize(new Point(0, 0), new Size(1000, 1000), wantedList.ToNullSafeString(), font, textcolour, backcolour, 1.0F); pictureBoxList.Render(); font.Dispose(); // if transparent, we don't show the eng/synth panels userControlEngineering.Visible = userControlSynthesis.Visible = !IsTransparent; userControlEngineering.Enabled = userControlSynthesis.Enabled = !IsTransparent; splitContainerVertical.Panel1MinSize = displayList.img.Width + 8; // panel left has minimum width to accomodate the text if (IsTransparent) { RevertToNormalSize(); int minWidth = Math.Max(((UserControlForm)FindForm()).TitleBarMinWidth(), displayList.img.Width) + 8; RequestTemporaryResize(new Size(minWidth, displayList.img.Height + 4)); } else { RevertToNormalSize(); // eng/synth is on, normal size } } }
private 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 <MaterialCommodities> mcl = last_he.MaterialCommodity.Sort(false); MaterialCommoditiesList.ResetUsed(mcl); Color textcolour = IsTransparent ? discoveryform.theme.SPanelColor : discoveryform.theme.LabelColor; Color backcolour = this.BackColor; List <Tuple <MaterialCommoditiesList.Recipe, int> > totalWanted = EngineeringWanted.Concat(SynthesisWanted).ToList(); string techBrokers = SQLiteDBClass.GetSettingString(DBTechBrokerFilterSave, "None"); if (techBrokers != "None") { List <string> techBrokerList = techBrokers.Split(';').ToList <string>(); foreach (MaterialCommoditiesList.Recipe r in TechBrokerUnlocks) { if (techBrokers == "All" || techBrokerList.Contains(r.name)) { totalWanted.Add(new Tuple <MaterialCommoditiesList.Recipe, int>(r, 1)); } } } List <MaterialCommodities> shoppinglist = MaterialCommoditiesList.GetShoppingList(totalWanted, mcl); JournalScan sd = null; StarScan.SystemNode last_sn = null; if (last_he.IsLanded && (showListAvailability || showPlanetMats)) { sd = discoveryform.history.GetScans(last_he.System.Name).Where(sc => sc.BodyName == last_he.WhereAmI).FirstOrDefault(); } if (!last_he.IsLanded && showSystemAvailability) { last_sn = discoveryform.history.starscan.FindSystem(last_he.System, useEDSMForSystemAvailability); } StringBuilder wantedList = new StringBuilder(); if (shoppinglist.Any()) { double available; wantedList.Append("Needed Mats:\n"); List <string> capExceededMats = new List <string>(); foreach (MaterialCommodities c in shoppinglist.OrderBy(mat => mat.name)) // and add new.. { string present = ""; if (showListAvailability) { if (sd != null) { if (sd.Materials.TryGetValue(c.fdname, out available)) { present = $" {available.ToString("N1")}%"; } else { present = " -"; } } } wantedList.Append($" {c.scratchpad} {c.name}{present}"); int?onHand = mcl.Where(m => m.shortname == c.shortname).FirstOrDefault()?.count; int totalReq = c.scratchpad + (onHand.HasValue ? onHand.Value : 0); if ((c.type == MaterialCommodityDB.MaterialFreqVeryCommon && totalReq > VeryCommonCap) || (c.type == MaterialCommodityDB.MaterialFreqCommon && totalReq > CommonCap) || (c.type == MaterialCommodityDB.MaterialFreqStandard && totalReq > StandardCap) || (c.type == MaterialCommodityDB.MaterialFreqRare && totalReq > RareCap) || (c.type == MaterialCommodityDB.MaterialFreqVeryRare && totalReq > VeryRareCap)) { capExceededMats.Add(c.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.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.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("\nFilling Shopping List would exceed capacity for:"); foreach (string mat in capExceededMats) { wantedList.Append($"\n {mat}"); } } } else { wantedList.Append("No materials currently required."); } if (showMaxInjections) { MaterialCommoditiesList.ResetUsed(mcl); Tuple <int, int, string> basic = MaterialCommoditiesList.HowManyLeft(mcl, SynthesisRecipes.First(r => r.name == "FSD" && r.level == "Basic")); Tuple <int, int, string> standard = MaterialCommoditiesList.HowManyLeft(mcl, SynthesisRecipes.First(r => r.name == "FSD" && r.level == "Standard")); Tuple <int, int, string> premium = MaterialCommoditiesList.HowManyLeft(mcl, SynthesisRecipes.First(r => r.name == "FSD" && r.level == "Premium")); wantedList.Append($"\nMax FSD Injections\n {basic.Item1} Basic\n {standard.Item1} Standard\n {premium.Item1} Premium"); } if (showPlanetMats && sd != null && sd.HasMaterials) { wantedList.Append($"\n\nMaterials on {last_he.WhereAmI}\n"); foreach (KeyValuePair <string, double> mat in sd.Materials) { int?onHand = mcl.Where(m => m.fdname == mat.Key).FirstOrDefault()?.count; MaterialCommodityDB md = MaterialCommodityDB.GetCachedMaterial(mat.Key); int max; if (md.type == MaterialCommodityDB.MaterialFreqVeryCommon) { max = VeryCommonCap; } else if (md.type == MaterialCommodityDB.MaterialFreqCommon) { max = CommonCap; } else if (md.type == MaterialCommodityDB.MaterialFreqStandard) { max = StandardCap; } else if (md.type == MaterialCommodityDB.MaterialFreqRare) { max = RareCap; } else { max = VeryRareCap; } wantedList.AppendFormat(" {0} {1}% ({2}/{3})\n", System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(mat.Key.ToLower(System.Globalization.CultureInfo.InvariantCulture)), mat.Value.ToString("N1"), (onHand.HasValue ? onHand.Value : 0), max); } } Font font = discoveryform.theme.GetFont; pictureBoxList.ClearImageList(); PictureBoxHotspot.ImageElement displayList = pictureBoxList.AddTextAutoSize(new Point(0, 0), new Size(1000, 1000), wantedList.ToNullSafeString(), font, textcolour, backcolour, 1.0F); pictureBoxList.Render(); font.Dispose(); // if transparent, we don't show the eng/synth panels userControlEngineering.Visible = userControlSynthesis.Visible = !IsTransparent; userControlEngineering.Enabled = userControlSynthesis.Enabled = !IsTransparent; buttonTechBroker.Visible = buttonTechBroker.Enabled = !IsTransparent; splitContainerVertical.Panel1MinSize = displayList.img.Width + 8; // panel left has minimum width to accomodate the text if (IsTransparent) { RevertToNormalSize(); int minWidth = Math.Max(((UserControlForm)FindForm()).TitleBarMinWidth(), displayList.img.Width) + 8; RequestTemporaryResize(new Size(minWidth, displayList.img.Height + 4)); } else { RevertToNormalSize(); // eng/synth is on, normal size } } }