Exemple #1
0
        public override void FillInformation(ISystem sys, out string info, out string detailed)
        {
            MaterialCommodityMicroResourceType mcd = MaterialCommodityMicroResourceType.GetByFDName(Resource.Name);     // may be null

            info     = BaseUtils.FieldBuilder.Build("", Resource.FriendlyName, "< (;)", mcd?.TranslatedCategory, "< ; items".T(EDTx.JournalEntry_MatC), Resource.Count);
            detailed = "";
        }
        public override void FillInformation(ISystem sys, out string info, out string detailed)
        {
            MaterialCommodityMicroResourceType mcd = MaterialCommodityMicroResourceType.GetByFDName(Type);

            if (mcd != null)
            {
                info = BaseUtils.FieldBuilder.Build("", Type_Localised, "< (", mcd.TranslatedCategory, ";)", mcd.TranslatedType, "Total: ".T(EDTx.JournalEntry_Total), Total);
            }
            else
            {
                info = Type_Localised;
            }
            detailed = "";
        }
 public bool FromString(string s)                    // serialise from string
 {
     string[] parts = s.Split(',');
     if (parts.Length == 4)
     {
         fromelement = MaterialCommodityMicroResourceType.GetByFDName(parts[0]);
         element     = MaterialCommodityMicroResourceType.GetByFDName(parts[1]);
         return(fromelement != null && element != null && parts[2].InvariantParse(out offer) && parts[3].InvariantParse(out receive));
     }
     else
     {
         return(false);
     }
 }
Exemple #4
0
        public override void FillInformation(ISystem sys, out string info, out string detailed)
        {
            info = BaseUtils.FieldBuilder.Build("", FriendlyName);
            MaterialCommodityMicroResourceType mcd = MaterialCommodityMicroResourceType.GetByFDName(Name);

            if (mcd != null)
            {
                info += BaseUtils.FieldBuilder.Build(" (", mcd.TranslatedCategory, ";)", mcd.TranslatedType);
            }

            if (DiscoveryNumber > 0)
            {
                info += string.Format(", Discovery {0}".T(EDTx.JournalMaterialDiscovered_DN), DiscoveryNumber);
            }
            detailed = "";
        }
            public int[] content;                  // number in each cat, high/med/low

            public static MaterialsFound Find(string fdname, List <MaterialsFound> list)
            {
                MaterialsFound mat = list.Find(x => x.matnamefd2.Equals(fdname, StringComparison.InvariantCultureIgnoreCase));

                if (mat == null)
                {
                    mat                   = new MaterialsFound();
                    mat.matnamefd2        = fdname;
                    mat.friendlyname      = MaterialCommodityMicroResourceType.GetByFDName(fdname)?.Name ?? fdname;
                    mat.prospectedamounts = new List <double>();
                    mat.content           = new int[3];
                    list.Add(mat);
                }

                return(mat);
            }
        private async void DrawSystem(HistoryEntry he, bool force)
        {
            var samesys = last_he?.System != null && he?.System != null && he.System.Name == last_he.System.Name;

            //System.Diagnostics.Debug.WriteLine("Scan grid " + samesys + " F:" + force);

            StarScan.SystemNode scannode = null;

            if (he == null)     //  no he, no display
            {
                last_he = he;
                dataGridViewScangrid.Rows.Clear();
                SetControlText("No Scan".T(EDTx.NoScan));
                return;
            }
            else
            {
                scannode = await discoveryform.history.StarScan.FindSystemAsync(he.System, checkBoxEDSM.Checked); // get data with EDSM maybe

                if (scannode == null)                                                                             // no data, clear display, clear any last_he so samesys is false next time
                {
                    last_he = null;
                    dataGridViewScangrid.Rows.Clear();
                    SetControlText("No Scan".T(EDTx.NoScan));
                    return;
                }

                if (samesys && !force)      // same system, no force, no redisplay
                {
                    return;
                }
            }

            last_he = he;

            // only record first row if same system
            var firstdisplayedrow = (dataGridViewScangrid.RowCount > 0 && samesys) ? dataGridViewScangrid.SafeFirstDisplayedScrollingRowIndex() : -1;

            toolStripJumponiumProgressBar.Visible = false;
            toolStripJumponiumProgressBar.Value   = 0;                             // reset the jumponium progress

            dataGridViewScangrid.RowTemplate.MinimumHeight = Font.ScalePixels(64); // based on icon size
            bodysize = dataGridViewScangrid.RowTemplate.MinimumHeight;
            iconsize = bodysize / 4;

            dataGridViewScangrid.Rows.Clear();

            var all_nodes = scannode.Bodies.ToList(); // flatten tree of scan nodes to prepare for listing

            var stars       = 0;
            var planets     = 0;
            var terrestrial = 0;
            var gasgiants   = 0;
            var moons       = 0;

            List <MaterialCommodityMicroResource> historicmcl = discoveryform.history.MaterialCommoditiesMicroResources.Get(last_he.MaterialCommodity);
            List <MaterialCommodityMicroResource> curmcl      = discoveryform.history.MaterialCommoditiesMicroResources.GetLast();

            HashSet <string> jumponiums = new HashSet <string>();

            foreach (StarScan.ScanNode sn in all_nodes)
            {
                // define strings to be populated
                var bdClass   = new StringBuilder();
                var bdDist    = new StringBuilder();
                var bdDetails = new StringBuilder();

                if (sn.NodeType == StarScan.ScanNodeType.ring)
                {
                    // do nothing, by now
                }
                else if (sn.NodeType == StarScan.ScanNodeType.beltcluster)
                {
                    // if have a scan, we show belts, and its not edsm body, or getting edsm
                    if (sn.ScanData?.BodyName != null && IsSet(CtrlList.showBelts) && (!sn.ScanData.IsEDSMBody || checkBoxEDSM.Checked))
                    {
                        bdClass.Clear();
                        bdClass.Append("Belt Cluster");

                        if (sn.ScanData.ScanType == "Detailed")
                        {
                            bdDetails.Append("Scanned");
                        }
                        else
                        {
                            bdDetails.Append("No scan data available");
                        }

                        if (Math.Abs(sn.ScanData.DistanceFromArrivalLS) > 0)
                        {
                            bdDist.AppendFormat("{0:0.00}AU ({1:0.0}ls)", sn.ScanData.DistanceFromArrivalLS / JournalScan.oneAU_LS, sn.ScanData.DistanceFromArrivalLS);
                        }

                        var img = global::EDDiscovery.Icons.Controls.Belt;

                        dataGridViewScangrid.Rows.Add(new object[] { null, sn.ScanData.BodyDesignationOrName, bdClass, bdDist, bdDetails });

                        var cur = dataGridViewScangrid.Rows[dataGridViewScangrid.Rows.Count - 1];

                        cur.Tag          = img;
                        cur.Cells[0].Tag = null;
                        cur.Cells[4].Tag = cur.Cells[0].ToolTipText = cur.Cells[1].ToolTipText = cur.Cells[2].ToolTipText = cur.Cells[3].ToolTipText = cur.Cells[4].ToolTipText =
                            sn.ScanData.DisplayString(0, historicmcl, curmcl);
                    }
                }
                // must have scan data and a name to be good, and either not edsm body or edsm check
                else if (sn.ScanData?.BodyName != null && (!sn.ScanData.IsEDSMBody || checkBoxEDSM.Checked))
                {
                    var overlays = new StarColumnOverlays();

                    if (sn.ScanData.IsStar)
                    {
                        // is a star, so populate its information field with relevant data
                        stars++;

                        // star class
                        if (sn.ScanData.StarTypeText != null)
                        {
                            bdClass.Append(sn.ScanData.StarTypeText);
                        }

                        // is the main star?
                        if (sn.ScanData.BodyName.EndsWith(" A", StringComparison.Ordinal))
                        {
                            bdDist.AppendFormat("Main Star".T(EDTx.UserControlScanGrid_MainStar));
                        }
                        // if not, then tell us its hierarchy leveland distance from main star
                        else if (sn.ScanData.nSemiMajorAxis.HasValue)
                        {
                            if (sn.ScanData.IsStar || sn.ScanData.nSemiMajorAxis.Value > JournalScan.oneAU_m / 10)
                            {
                                bdDist.AppendFormat("{0:0.00}AU ({1:0.00}ls)", (sn.ScanData.nSemiMajorAxis.Value / JournalScan.oneAU_m), sn.ScanData.nSemiMajorAxis.Value / JournalScan.oneLS_m);
                            }
                            else
                            {
                                bdDist.AppendFormat("{0}km", (sn.ScanData.nSemiMajorAxis.Value / 1000).ToString("N1"));
                            }
                        }

                        // display stellar bodies mass, in sols
                        if (sn.ScanData.nStellarMass.HasValue)
                        {
                            bdDetails.Append("Mass".T(EDTx.UserControlScanGrid_Mass)).Append(": ").Append(sn.ScanData.nStellarMass.Value.ToString("N2")).Append(", ");
                        }

                        // display stellar bodies radius in sols
                        if (sn.ScanData.nRadius.HasValue)
                        {
                            bdDetails.Append("Radius".T(EDTx.UserControlScanGrid_Radius)).Append(": ").Append((sn.ScanData.nRadius.Value / JournalScan.oneSolRadius_m).ToString("N2")).Append(", ");
                        }

                        // show the temperature
                        if (sn.ScanData.nSurfaceTemperature.HasValue)
                        {
                            bdDetails.Append("Temperature".T(EDTx.UserControlScanGrid_Temperature)).Append(": ").Append((sn.ScanData.nSurfaceTemperature.Value)).Append("K.");
                        }

                        // habitable zone for stars - do not display for black holes.
                        if (sn.ScanData.StarTypeID != EDStar.H)
                        {
                            if (IsSet(CtrlList.showHabitable))
                            {
                                string hz = sn.ScanData.CircumstellarZonesString(false, JournalScan.CZPrint.CZHab);
                                bdDetails.AppendFormat(Environment.NewLine + hz);
                            }
                            if (IsSet(CtrlList.showMetalRich))
                            {
                                string hz = sn.ScanData.CircumstellarZonesString(false, JournalScan.CZPrint.CZMR);
                                bdDetails.AppendFormat(Environment.NewLine + hz);
                            }
                            if (IsSet(CtrlList.showWaterWorlds))
                            {
                                string hz = sn.ScanData.CircumstellarZonesString(false, JournalScan.CZPrint.CZWW);
                                bdDetails.AppendFormat(Environment.NewLine + hz);
                            }
                            if (IsSet(CtrlList.showEarthLike))
                            {
                                string hz = sn.ScanData.CircumstellarZonesString(false, JournalScan.CZPrint.CZEL);
                                bdDetails.AppendFormat(Environment.NewLine + hz);
                            }
                            if (IsSet(CtrlList.showAmmonia))
                            {
                                string hz = sn.ScanData.CircumstellarZonesString(false, JournalScan.CZPrint.CZAW);
                                bdDetails.AppendFormat(Environment.NewLine + hz);
                            }
                            if (IsSet(CtrlList.showIcyBodies))
                            {
                                string hz = sn.ScanData.CircumstellarZonesString(false, JournalScan.CZPrint.CZIP);
                                bdDetails.AppendFormat(Environment.NewLine + hz);
                            }
                        }
                    }
                    else
                    {
                        // is a non-stellar body

                        // is terraformable? If so, prepend it to the body class
                        if (sn.ScanData.Terraformable)
                        {
                            bdClass.Append("Terraformable".T(EDTx.UserControlScanGrid_Terraformable)).Append(", ");
                        }

                        if (sn.NodeType == StarScan.ScanNodeType.body)      // Planet, not barycenter/belt
                        {
                            bdClass.Append(sn.ScanData.PlanetTypeText);

                            if (sn.Level <= 1)      // top level planet
                            {
                                planets++;

                                if (sn.ScanData.GasWorld)
                                {
                                    gasgiants++;
                                }
                                else
                                {
                                    terrestrial++;
                                }

                                bdDist.AppendFormat("{0:0.00}AU ({1:0.0}ls)", sn.ScanData.DistanceFromArrivalLS / JournalScan.oneAU_LS, sn.ScanData.DistanceFromArrivalLS);
                            }
                            else
                            {
                                moons++;

                                bdClass.Append(" ").Append("Moon".T(EDTx.UserControlScanGrid_Moon));

                                // moon distances from center body are measured from in SemiMajorAxis
                                if (sn.ScanData.nSemiMajorAxis.HasValue)
                                {
                                    bdDist.AppendFormat("{0:0.0}ls ({1:0}km)", sn.ScanData.nSemiMajorAxis.Value / JournalScan.oneLS_m, sn.ScanData.nSemiMajorAxis.Value / 1000);
                                }
                            }
                        }

                        // Details

                        // display non-stellar bodies radius in earth radiuses
                        if (sn.ScanData.nRadius.HasValue)
                        {
                            bdDetails.Append("Radius".T(EDTx.UserControlScanGrid_Radius)).Append(": ").Append((sn.ScanData.nRadius.Value / 1000.0).ToString("N0") + "km (").
                            Append((sn.ScanData.nRadius.Value / JournalScan.oneEarthRadius_m).ToString("N2")).Append("ER), ");
                        }

                        // show the temperature, both in K and C degrees
                        if (sn.ScanData.nSurfaceTemperature.HasValue)
                        {
                            bdDetails.Append("Temperature".T(EDTx.UserControlScanGrid_Temperature)).Append(": ").Append((sn.ScanData.nSurfaceTemperature.Value).ToString("N2")).Append("K, (").Append((sn.ScanData.nSurfaceTemperature.Value - 273).ToString("N2")).Append("C).");
                        }

                        // print the main atmospheric composition and pressure, if presents
                        if (sn.ScanData.Atmosphere != "none")
                        {
                            bdDetails.Append(Environment.NewLine).Append(sn.ScanData.Atmosphere);
                            if (sn.ScanData.nSurfacePressure.HasValue)
                            {
                                bdDetails.Append(", ").Append((sn.ScanData.nSurfacePressure.Value / JournalScan.oneAtmosphere_Pa).ToString("N3")).Append("Pa.");
                            }
                        }

                        // tell us that a bodie is landable, and shows its gravity
                        if (sn.ScanData.IsLandable)
                        {
                            var Gg = "";

                            if (sn.ScanData.nSurfaceGravity.HasValue)
                            {
                                var g = sn.ScanData.nSurfaceGravity / JournalScan.oneGee_m_s2;
                                Gg = " (G: " + g.Value.ToString("N1") + ")";
                            }

                            bdDetails.Append(Environment.NewLine).Append("Landable".T(EDTx.UserControlScanGrid_Landable)).Append(Gg).Append(". ");
                            overlays.landable = true;
                        }

                        // tell us that there is some volcanic activity
                        if (sn.ScanData.Volcanism.HasChars())
                        {
                            bdDetails.Append(Environment.NewLine).Append("Geological activity".T(EDTx.UserControlScanGrid_Geologicalactivity)).Append(": ").Append(sn.ScanData.Volcanism).Append(". ");
                            overlays.volcanism = true;
                        }

                        if (sn.ScanData.Mapped)
                        {
                            bdDetails.Append(Environment.NewLine).Append("Surface mapped".T(EDTx.UserControlScanGrid_Surfacemapped)).Append(". ");
                            overlays.mapped = true;
                        }

                        if (sn.Organics != null)
                        {
                            string ol = JournalScanOrganic.OrganicList(sn.Organics);
                            bdDetails.Append(Environment.NewLine).Append(ol);
                        }

                        // materials
                        if (sn.ScanData.HasMaterials)
                        {
                            var ret = "";
                            foreach (KeyValuePair <string, double> mat in sn.ScanData.Materials)
                            {
                                var mc = MaterialCommodityMicroResourceType.GetByFDName(mat.Key);
                                if (mc?.IsJumponium == true)
                                {
                                    ret = ret.AppendPrePad(mc.Name, ", ");
                                    overlays.materials = true;
                                }
                            }

                            if (ret.Length > 0 && IsSet(CtrlList.showMaterials))
                            {
                                bdDetails.Append(Environment.NewLine).Append("This body contains: ".T(EDTx.UserControlScanGrid_BC)).Append(ret);
                            }
                        }
                    }

                    // have some belt, ring or other special structure?
                    if (sn.ScanData.HasRings)
                    {
                        for (int r = 0; r < sn.ScanData.Rings.Length; r++)
                        {
                            if (sn.ScanData.Rings[r].Name.EndsWith("Belt", StringComparison.Ordinal))
                            {
                                if (IsSet(CtrlList.showBelts))
                                {
                                    // is a belt
                                    bdDetails.Append(Environment.NewLine).Append("Belt: ".T(EDTx.UserControlScanGrid_Belt));
                                    var RingName = sn.ScanData.Rings[r].Name;
                                    bdDetails.Append(JournalScan.StarPlanetRing.DisplayStringFromRingClass(sn.ScanData.Rings[r].RingClass)).Append(" ");
                                    bdDetails.Append((sn.ScanData.Rings[r].InnerRad / JournalScan.oneLS_m).ToString("N2")).Append("ls to ").Append((sn.ScanData.Rings[r].OuterRad / JournalScan.oneLS_m).ToString("N2")).Append("ls. ");
                                }
                            }
                            else
                            {
                                if (IsSet(CtrlList.showRings))
                                {
                                    // is a ring
                                    bdDetails.Append(Environment.NewLine).Append("Ring: ".T(EDTx.UserControlScanGrid_Ring));
                                    var RingName = sn.ScanData.Rings[r].Name;
                                    bdDetails.Append(JournalScan.StarPlanetRing.DisplayStringFromRingClass(sn.ScanData.Rings[r].RingClass)).Append(" ");
                                    bdDetails.Append((sn.ScanData.Rings[r].InnerRad / JournalScan.oneLS_m).ToString("N2")).Append("ls to ").Append((sn.ScanData.Rings[r].OuterRad / JournalScan.oneLS_m).ToString("N2")).Append("ls. ");
                                }
                            }
                        }
                    }

                    // give estimated value
                    if (IsSet(CtrlList.showValues))
                    {
                        var value = sn.ScanData.EstimatedValue;
                        bdDetails.Append(Environment.NewLine).Append("Value".T(EDTx.UserControlScanGrid_Value)).Append(" ").Append(value.ToString("N0"));
                    }

                    if (sn.ScanData.IsEDSMBody)
                    {
                        bdDetails.Append(Environment.NewLine).Append("EDSM");
                    }

                    // pick an image

                    Bitmap img = (Bitmap)BaseUtils.Icons.IconSet.GetIcon(sn.ScanData.GetStarPlanetTypeImageName());

                    dataGridViewScangrid.Rows.Add(new object[] { null, sn.ScanData.BodyDesignationOrName, bdClass, bdDist, bdDetails });

                    var cur = dataGridViewScangrid.Rows[dataGridViewScangrid.Rows.Count - 1];

                    cur.Tag = img;

                    cur.Cells[0].Tag = overlays;
                    cur.Cells[4].Tag = cur.Cells[0].ToolTipText = cur.Cells[1].ToolTipText = cur.Cells[2].ToolTipText = cur.Cells[3].ToolTipText = cur.Cells[4].ToolTipText =
                        sn.ScanData.DisplayString(0, historicmcl, curmcl);

                    sn.ScanData.Jumponium(jumponiums);      // add to jumponiums hash any seen
                }
            }

            toolStripJumponiumProgressBar.Value   = jumponiums.Count;
            toolStripJumponiumProgressBar.Visible = toolStripJumponiumProgressBar.Value > 0;

            //System.Diagnostics.Debug.WriteLine("Jumponiums " + toolStripJumponiumProgressBar.Value + " " + toolStripJumponiumProgressBar.Visible);

            if (toolStripJumponiumProgressBar.Value == 8)
            {
                toolStripJumponiumProgressBar.ToolTipText = "This is a green system, as it has all existing jumponium materials available!".T(EDTx.UserControlScanGrid_GS);
            }
            else
            {
                toolStripJumponiumProgressBar.ToolTipText = toolStripJumponiumProgressBar.Value + " jumponium materials found in system.".T(EDTx.UserControlScanGrid_JS);
            }

            string report = string.Format("Scan Summary for {0}: {1} stars; {2} planets ({3} terrestrial, {4} gas giants), {5} moons".T(EDTx.UserControlScanGrid_ScanSummaryfor), scannode.System.Name, stars, planets, terrestrial, gasgiants, moons);

            report = "~" + scannode.ScanValue(checkBoxEDSM.Checked).ToString() + " cr " + report;
            SetControlText(scannode.System.Name);
            toolStripStatusTotalValue.Text = report;

            if (firstdisplayedrow >= 0 && firstdisplayedrow < dataGridViewScangrid.RowCount)
            {
                dataGridViewScangrid.SafeFirstDisplayedScrollingRowIndex(firstdisplayedrow);
            }
        }
        // curmats may be null
        Point CreateMaterialNodes(List <ExtPictureBox.ImageElement> pc, JournalScan sn, List <MaterialCommodityMicroResource> historicmats, List <MaterialCommodityMicroResource> curmats,
                                  Point matpos, Size matsize)
        {
            Point startpos  = matpos;
            Point maximum   = matpos;
            int   noperline = 0;

            string matclicktext = sn.DisplayMaterials(2, historicmats, curmats);

            foreach (KeyValuePair <string, double> sd in sn.Materials)
            {
                string tooltip = sn.DisplayMaterial(sd.Key, sd.Value, historicmats, curmats);

                Color  fillc = Color.Yellow;
                string abv   = sd.Key.Substring(0, 1);

                MaterialCommodityMicroResourceType mc = MaterialCommodityMicroResourceType.GetByFDName(sd.Key);

                if (mc != null)
                {
                    abv   = mc.Shortname;
                    fillc = mc.Colour;
                    //System.Diagnostics.Debug.WriteLine("Colour {0} {1}", fillc.ToString(), fillc.GetBrightness());

                    if (HideFullMaterials)                 // check full
                    {
                        int?limit = mc.MaterialLimit();
                        MaterialCommodityMicroResource matnow = curmats?.Find(x => x.Details == mc);  // allow curmats = null

                        // debug if (matnow != null && mc.shortname == "Fe")  matnow.count = 10000;

                        if (matnow != null && limit != null && matnow.Count >= limit)        // and limit
                        {
                            continue;
                        }
                    }

                    if (ShowOnlyMaterialsRare && mc.IsCommonMaterial)
                    {
                        continue;
                    }
                }

                System.Drawing.Imaging.ColorMap colormap = new System.Drawing.Imaging.ColorMap();
                colormap.OldColor = Color.White;    // this is the marker colour to replace
                colormap.NewColor = fillc;

                Bitmap mat = BaseUtils.BitMapHelpers.ReplaceColourInBitmap((Bitmap)BaseUtils.Icons.IconSet.GetIcon("Controls.Scan.Bodies.Material"), new System.Drawing.Imaging.ColorMap[] { colormap });

                BaseUtils.BitMapHelpers.DrawTextCentreIntoBitmap(ref mat, abv, Font, fillc.GetBrightness() > 0.4f ?  Color.Black : Color.White);

                ExtPictureBox.ImageElement ie = new ExtPictureBox.ImageElement(
                    new Rectangle(matpos.X, matpos.Y, matsize.Width, matsize.Height), mat, tooltip + "\n\n" + "All " + matclicktext, tooltip);

                pc.Add(ie);

                maximum = new Point(Math.Max(maximum.X, matpos.X + matsize.Width), Math.Max(maximum.Y, matpos.Y + matsize.Height));

                if (++noperline == 4)
                {
                    matpos    = new Point(startpos.X, matpos.Y + matsize.Height + materiallinespacerxy);
                    noperline = 0;
                }
                else
                {
                    matpos.X += matsize.Width + materiallinespacerxy;
                }
            }

            return(maximum);
        }
Exemple #8
0
        private void Display()
        {
            DataGridViewColumn sortcol   = dataGridViewMarketData.SortedColumn != null ? dataGridViewMarketData.SortedColumn : dataGridViewMarketData.Columns[0];
            SortOrder          sortorder = dataGridViewMarketData.SortOrder;

            dataViewScrollerPanel.SuspendLayout();

            int    firstdisplayed = dataGridViewMarketData.SafeFirstDisplayedScrollingRowIndex();
            string commodity      = (dataGridViewMarketData.CurrentRow != null) ? (string)dataGridViewMarketData.CurrentRow.Cells[1].Value : null;
            int    currentoffset  = (dataGridViewMarketData.CurrentRow != null) ? Math.Max(0, dataGridViewMarketData.CurrentRow.Index - firstdisplayed) : 0;

            dataGridViewMarketData.Rows.Clear();

            HistoryEntry left  = (eddmd_left != null) ? eddmd_left : last_eddmd; // if we have a selected left, use it, else use the last eddmd
            HistoryEntry cargo = (eddmd_left != null) ? eddmd_left : last_he;    // if we have a selected left, use it, else use the last he

            if (left != null)                                                    // we know it has a journal entry of EDD commodity..
            {
                //System.Diagnostics.Debug.WriteLine(Environment.NewLine + "From " + current_displayed?.WhereAmI + " to " + left.WhereAmI);

                JournalCommodityPricesBase ecp  = left.journalEntry as JournalCommodityPricesBase;
                List <CCommodities>        list = ecp.Commodities;

                //System.Diagnostics.Debug.WriteLine("Test Right " + eddmd_right?.WhereAmI + " vs " + left.WhereAmI);
                if (eddmd_right != null && !Object.ReferenceEquals(eddmd_right, left))   // if got a comparision, and not the same data..
                {
                    if (checkBoxAutoSwap.Checked &&
                        left.System.Name.Equals(eddmd_right.System.Name) &&    // if left system being displayed is same as right system
                        left.WhereAmI.Equals(eddmd_right.WhereAmI))            // that means we can autoswap comparisions around
                    {
                        //System.Diagnostics.Debug.WriteLine("Arrived at last left station, repick " + current_displayed.WhereAmI + " as comparision");

                        int index = comboboxentries.FindIndex(x => x.System.Name.Equals(current_displayed.System.Name) && x.WhereAmI.Equals(current_displayed.WhereAmI));
                        if (index >= 0)       // if found it, swap to last instance of system
                        {
                            comboBoxCustomTo.Enabled       = false;
                            comboBoxCustomTo.SelectedIndex = index + 1;
                            comboBoxCustomTo.Enabled       = true;
                            eddmd_right = comboboxentries[index];
                            //System.Diagnostics.Debug.WriteLine("Right is now " + eddmd_right.WhereAmI);
                        }
                    }

                    //System.Diagnostics.Debug.WriteLine("Right " + eddmd_right.System.Name + " " + eddmd_right.WhereAmI);
                    list = CCommodities.Merge(list, ((JournalCommodityPricesBase)eddmd_right.journalEntry).Commodities);
                }
                List <MaterialCommodityMicroResource> mclist   = discoveryform.history.MaterialCommoditiesMicroResources.GetCommoditiesSorted(cargo.MaterialCommodity);   // stuff we have..  commodities only
                List <MaterialCommodityMicroResource> notfound = new List <MaterialCommodityMicroResource>();
                foreach (MaterialCommodityMicroResource m in mclist)
                {
                    int index = list.FindIndex(x => x.fdname.EqualsAlphaNumOnlyNoCase(m.Details.FDName));   // try and match, remove any spaces/_ and lower case it for matching
                    if (index >= 0)
                    {
                        list[index].CargoCarried = m.Count; // found it, set cargo count..
                    }
                    else
                    {
                        notfound.Add(m);        // not found, add to list for bottom
                    }
                }

                FontFamily ff       = new FontFamily(this.Font.Name);
                bool       buyonly  = checkBoxBuyOnly.Checked;
                bool       sellonly = checkBoxSellOnly.Checked;

                foreach (CCommodities c in list)
                {
                    if (sellonly ? c.buyPrice == 0 : (!buyonly || (c.buyPrice > 0 || c.ComparisionBuy)))
                    {
                        MaterialCommodityMicroResourceType mc = MaterialCommodityMicroResourceType.GetByFDName(c.fdname);

                        string name = mc?.Name ?? c.locName;
                        if (c.ComparisionRightOnly)
                        {
                            name += " @ " + eddmd_right.WhereAmI;
                        }

                        object[] rowobj = { mc?.TranslatedType ?? c.loccategory.Alt(c.category),
                                            name,
                                            c.sellPrice > 0 ? c.sellPrice.ToString() : "",
                                            c.buyPrice > 0 ? c.buyPrice.ToString() : "",
                                            c.CargoCarried,
                                            c.demand > 1 ? c.demand.ToString() : "",
                                            c.stock > 0 ? c.stock.ToString() : "",
                                            c.meanPrice > 0 ? c.meanPrice.ToString() : "",
                                            c.ComparisionLR,
                                            c.ComparisionRL };

                        int rowno = dataGridViewMarketData.Rows.Add(rowobj);

                        if (c.ComparisionRightOnly && ff != null && ff.IsStyleAvailable(FontStyle.Italic))
                        {
                            for (int i = 1; i < dataGridViewMarketData.Columns.Count; i++)
                            {
                                dataGridViewMarketData.Rows[rowno].Cells[i].Style.Font = new Font(this.Font, FontStyle.Italic);
                            }
                        }

                        dataGridViewMarketData.Rows[rowno].Cells[0].ToolTipText     =
                            dataGridViewMarketData.Rows[rowno].Cells[1].ToolTipText = c.ToString();
                    }
                }

                foreach (MaterialCommodityMicroResource m in notfound)
                {
                    if (m.Count > 0)
                    {
                        object[] rowobj = { m.Details.TranslatedType,
                                            m.Details.Name,
                                            "",
                                            "",
                                            m.Count,
                                            "",
                                            "",
                                            "",
                                            "",
                                            "" };

                        int rowno = dataGridViewMarketData.Rows.Add(rowobj);
                        dataGridViewMarketData.Rows[rowno].Cells[0].ToolTipText     =
                            dataGridViewMarketData.Rows[rowno].Cells[1].ToolTipText = "Cargo only, no market data on this item".T(EDTx.UserControlMarketData_Conly);
                    }
                }

                current_displayed  = left;
                labelLocation.Text = left.System.Name + ":" + left.WhereAmI;
                string r = EDDConfig.Instance.ConvertTimeToSelectedFromUTC(left.EventTimeUTC).ToString();
                toolTip.SetToolTip(labelLocation, r);
            }
            else
            {
                toolTip.SetToolTip(labelLocation, null);
                labelLocation.Text = "No Data".T(EDTx.NoData);
            }

            dataViewScrollerPanel.ResumeLayout();

            dataGridViewMarketData.Sort(sortcol, (sortorder == SortOrder.Descending) ? ListSortDirection.Descending : ListSortDirection.Ascending);
            dataGridViewMarketData.Columns[sortcol.Index].HeaderCell.SortGlyphDirection = sortorder;

            if (commodity != null)
            {
                foreach (DataGridViewRow rw in dataGridViewMarketData.Rows)
                {
                    string v = (string)rw.Cells[1].Value;
                    if (v.Equals(commodity))            // Find the commodity, and set it to the same relative position as before.
                    {
                        dataGridViewMarketData.SetCurrentAndSelectAllCellsOnRow(rw.Index);
                        dataGridViewMarketData.SafeFirstDisplayedScrollingRowIndex(Math.Max(rw.Index - currentoffset, 0));
                        break;
                    }
                }
            }

            //System.Diagnostics.Debug.WriteLine("Stop watch" + swp.ElapsedMilliseconds);
        }
        private void buttonExtExcel_Click(object sender, EventArgs e)
        {
            Forms.ExportForm frm = new Forms.ExportForm();
            frm.Init(new string[] { "All" }, disablestartendtime: true);

            if (frm.ShowDialog(FindForm()) == DialogResult.OK)
            {
                BaseUtils.CSVWriteGrid grd = new BaseUtils.CSVWriteGrid();
                grd.SetCSVDelimiter(frm.Comma);

                var found = ReadHistory(out int prospectorsused, out int collectorsused, out int asteroidscracked, out int prospected, out int[] content);

                grd.GetPreHeader += delegate(int r)
                {
                    if (r == 0)
                    {
                        return new Object[] { "Limpets left ", limpetsleftdisplay, "Prospectors Fired", prospectorsused, "Collectors Deployed", collectorsused }
                    }
                    ;
                    else if (r == 1)
                    {
                        return(new object[0]);
                    }
                    else
                    {
                        return(null);
                    }
                };

                grd.GetSetsPad = delegate(int s, int r)
                {
                    return(r < 2 ? new object[0] : null);
                };

                {
                    grd.GetSetsHeader.Add(delegate(int s, int r)
                    {
                        if (r == 0)
                        {
                            return new object[] { "", "Ref.", "Coll.", "Pros", "Ratio%", "Avg%", "Min%", "Max%", "M.Load", "High Ct", "Med Ct", "Low Ct", "Discv" }
                        }
                        ;
                        else
                        {
                            return(null);
                        }
                    });

                    grd.GetSetsData.Add(delegate(int s, int r)
                    {
                        if (r == 0)
                        {
                            return(new object[] { "", "", "", prospected.ToString("N0"), "", "", "", "", "",
                                                  content[0].ToString("N0"),
                                                  content[1].ToString("N0"),
                                                  content[2].ToString("N0") });
                        }
                        else if (r <= found.Count)
                        {
                            MaterialsFound f = found[r - 1];
                            return(new object[] { f.friendlyname, f.amountrefined, f.amountcollected - f.amountdiscarded,
                                                  f.prospectednoasteroids > 0 ? f.prospectednoasteroids.ToString("N0") : "",
                                                  f.prospectednoasteroids > 0 ? (100.0 * (double)f.prospectednoasteroids / prospected).ToString("N1") : "",
                                                  f.prospectednoasteroids > 0 ? f.prospectedamounts.Average().ToString("N1") : "",
                                                  f.prospectednoasteroids > 0 ? f.prospectedamounts.Min().ToString("N1") : "",
                                                  f.prospectednoasteroids > 0 ? f.prospectedamounts.Max().ToString("N1") : "",
                                                  f.motherloadasteroids > 0 ? f.motherloadasteroids.ToString("N0") : "",
                                                  f.prospectednoasteroids > 0 ? f.content[0].ToString("N0") :"",
                                                  f.prospectednoasteroids > 0 ? f.content[1].ToString("N0") : "",
                                                  f.prospectednoasteroids > 0 ? f.content[2].ToString("N0") : "",
                                                  f.discovered ? "*" : "" });
                        }
                        else
                        {
                            return(null);
                        }
                    });
                }

                var prosmat = found.Where(x => x.prospectednoasteroids > 0).ToList();

                {
                    grd.GetSetsHeader.Add(delegate(int s, int r)
                    {
                        if (r == 0)
                        {
                            Object[] ret = new object[prosmat.Count + 1];
                            ret[0]       = "CDFb";

                            for (int i = 0; i < prosmat.Count; i++)
                            {
                                ret[i + 1] = prosmat[i].friendlyname;
                            }

                            return(ret);
                        }
                        else
                        {
                            return(null);
                        }
                    });

                    grd.GetSetsData.Add(delegate(int s, int r)
                    {
                        if (r < CFDbMax)
                        {
                            Object[] ret = new object[prosmat.Count + 1];
                            int percent  = r;
                            ret[0]       = percent.ToString("N0") + "%";
                            for (int m = 0; m < prosmat.Count; m++)
                            {
                                if (prosmat[m].prospectednoasteroids > 0)
                                {
                                    ret[m + 1] = ((double)prosmat[m].prospectedamounts.Count(x => x >= percent) / prosmat[m].prospectednoasteroids * 100.0).ToString("N1");
                                }
                                else
                                {
                                    ret[m + 1] = "";
                                }
                            }

                            return(ret);
                        }
                        else
                        {
                            return(null);
                        }
                    });
                }

                {
                    const int precol = 4;

                    grd.GetSetsHeader.Add(delegate(int s, int r)
                    {
                        if (r == 0)
                        {
                            Object[] ret = new object[found.Count + precol];
                            ret[0]       = "Event";
                            ret[1]       = "Time";
                            ret[2]       = "Content";
                            ret[3]       = "Motherload";

                            for (int i = 0; i < prosmat.Count; i++)
                            {
                                ret[i + precol] = prosmat[i].friendlyname;
                            }

                            return(ret);
                        }
                        else
                        {
                            return(null);
                        }
                    });

                    var proslist = curlist.Where(x => x.EntryType == JournalTypeEnum.ProspectedAsteroid).ToList();

                    grd.GetSetsData.Add(delegate(int s, int r)
                    {
                        if (r < proslist.Count)
                        {
                            var jp = proslist[r].journalEntry as JournalProspectedAsteroid;

                            Object[] ret = new object[prosmat.Count + precol];
                            ret[0]       = (r + 1).ToString("N0");
                            ret[1]       = jp.EventTimeUTC.ToStringZulu();
                            ret[2]       = jp.Content.ToString();
                            ret[3]       = MaterialCommodityMicroResourceType.GetByFDName(jp.MotherlodeMaterial)?.Name ?? jp.MotherlodeMaterial;

                            for (int m = 0; m < prosmat.Count; m++)
                            {
                                int mi = Array.FindIndex(jp.Materials, x => x.Name == prosmat[m].matnamefd2);
                                if (mi >= 0)
                                {
                                    ret[m + precol] = jp.Materials[mi].Proportion.ToString("N2");
                                }
                                else
                                {
                                    ret[m + precol] = "";
                                }
                            }
                            return(ret);
                        }
                        else
                        {
                            return(null);
                        }
                    });
                }

                grd.WriteGrid(frm.Path, frm.AutoOpen, FindForm());
            }
        }