Example #1
0
        void DrawBaryTree(Graphics g, ExtPictureBox.ImageElement e)
        {
            using (Pen p = new Pen(Color.FromArgb(255, 170, 170, 170), 2)) // gray
            {
                var tojoin = e.Tag as List <BaryPointInfo>;

                for (int i = 0; i < tojoin.Count; i++)
                {
                    var cur = tojoin[i];
                    g.DrawLine(p, cur.point, cur.toppos);           // always draw the sub from the centre to the top pos

                    if (i > 0)                                      // if we have a previous
                    {
                        var prev = tojoin[i - 1];

                        if (cur.toppos.Y == prev.toppos.Y || e.Location.Width == 1) //.Width records if horizontal line, ie.moons.  If on same level, or horz
                        {
                            g.DrawLine(p, prev.toppos, cur.toppos);                 // draw from prev top to our top
                        }
                        else
                        {                                   // here, for vert (planets) the entries are not side by side, so we draw nice lines out
                            g.DrawLine(p, prev.toppos, new Point(prev.toppos.X + planetsize.Width * 2, prev.toppos.Y));
                            g.DrawLine(p, cur.toppos, new Point(cur.toppos.X - planetsize.Width, cur.toppos.Y));
                        }
                    }
                }
            }
        }
Example #2
0
        public bool DrawScanText(bool attop, Color textcolour, Color backcolour)
        {
            Size maxscansize = new Size(10000, 10000);            // set arbitary large.. not important for this.

            if (scantext != null)
            {
                if (attop)
                {
                    if (Config(Configuration.showScanLeft))
                    {
                        ExtPictureBox.ImageElement scanimg = pictureBox.AddTextAutoSize(new Point(4, 0), maxscansize, scantext, displayfont, textcolour, backcolour, 1.0F, "SCAN");
                        scanpostextoffset = new Point(4 + scanimg.Image.Width + 4, 0);
                        RequestTemporaryMinimumSize(new Size(scanimg.Image.Width + 8, scanimg.Image.Height + 4));
                    }
                    else if (Config(Configuration.showScanAbove))
                    {
                        ExtPictureBox.ImageElement scanimg = pictureBox.AddTextAutoSize(new Point(4, 0), maxscansize, scantext, displayfont, textcolour, backcolour, 1.0F, "SCAN");
                        scanpostextoffset = new Point(0, scanimg.Image.Height + 4);
                        RequestTemporaryResizeExpand(new Size(0, scanimg.Image.Height + 4));
                    }
                    else if (Config(Configuration.showScanOnTop))
                    {
                        ExtPictureBox.ImageElement scanimg = pictureBox.AddTextAutoSize(new Point(4, 0), maxscansize, scantext, displayfont, textcolour, backcolour, 1.0F, "SCAN");
#if false
                        using (Graphics gr = Graphics.FromImage(scanimg.img))
                        {
                            using (Pen p1 = new Pen(Color.Red, 1.0F))
                            {
                                for (int i = 0; i < 1000; i += 50)
                                {
                                    gr.DrawLine(p1, new Point(0, i), new Point(100, i));
                                }
                            }
                        }
#endif
                        RequestTemporaryResize(new Size(scanimg.Image.Width + 8, scanimg.Image.Height + 4));         // match exactly to use minimum space
                        return(true);
                    }
                }
                else // bottom chance
                {
                    if (Config(Configuration.showScanRight))
                    {
                        Size s = pictureBox.DisplaySize();
                        ExtPictureBox.ImageElement scanimg = pictureBox.AddTextAutoSize(new Point(s.Width + 4, 0), maxscansize, scantext, displayfont, textcolour, backcolour, 1.0F, "SCAN");
                        RequestTemporaryMinimumSize(new Size(s.Width + 4 + scanimg.Image.Width + 8, scanimg.Image.Height + 4));
                    }
                    else if (Config(Configuration.showScanBelow))
                    {
                        Size s = pictureBox.DisplaySize();
                        ExtPictureBox.ImageElement scanimg = pictureBox.AddTextAutoSize(new Point(4, s.Height + 4), maxscansize, scantext, displayfont, textcolour, backcolour, 1.0F, "SCAN");
                        RequestTemporaryResizeExpand(new Size(0, scanimg.Image.Height + 4));
                    }
                }
            }

            return(false);
        }
 private void ClickElement(object sender, MouseEventArgs e, ExtPictureBox.ImageElement i, object tag)
 {
     if (i != null && tag is string)
     {
         ShowInfo((string)tag, i.Location.Location.X < panelStars.Width / 2);
     }
     else
     {
         HideInfo();
     }
 }
Example #4
0
        private void DrawBodyInfo()
        {
            //System.Diagnostics.Debug.WriteLine($"Organics {displaynumber} Draw {lasthe?.System.Name} {lasthe?.System.HasCoordinate}");

            pictureBox.ClearImageList();

            if (lasthe != null && lasthe.Status.HasBodyID && lasthe.Status.BodyType == "Planet")
            {
                StarScan.SystemNode data = discoveryform.history.StarScan.FindSystemSynchronous(lasthe.System, false);

                if (data != null && data.NodesByID.TryGetValue(lasthe.Status.BodyID.Value, out StarScan.ScanNode node))
                {
                    var picelements = new List <ExtPictureBox.ImageElement>();       // accumulate picture elements in here

                    Font dfont = displayfont ?? this.Font;

                    // System.Diagnostics.Debug.WriteLine($"Organics {displaynumber} Go for draw on {lasthe.WhereAmI} {lasthe.BodyType}");

                    int          vpos = 0;
                    StringFormat frmt = new StringFormat(extCheckBoxWordWrap.Checked ? 0 : StringFormatFlags.NoWrap);
                    frmt.Alignment = StringAlignment.Near;
                    var textcolour = IsTransparent ? ExtendedControls.Theme.Current.SPanelColor : ExtendedControls.Theme.Current.LabelColor;
                    var backcolour = IsTransparent ? Color.Transparent : this.BackColor;

                    //System.Diagnostics.Debug.WriteLine($"Pbox size {pictureBox.Size}");
                    string l = string.Format("At {0}, {1}, Radius {2}, {3} G, {4}", node.FullName, node.ScanData?.PlanetTypeText ?? "Unknown", node.ScanData?.RadiusText() ?? "Unknown",
                                             node.ScanData?.nSurfaceGravityG?.ToString("N1") ?? "Unknown", node.ScanData?.Atmosphere);

                    string s = node.Organics != null?JournalScanOrganic.OrganicList(node.Organics) : "No organic scanned";

                    var i = new ExtPictureBox.ImageElement();
                    i.TextAutoSize(new Point(3, vpos),
                                   new Size(Math.Max(pictureBox.Width - 6, 24), 10000),
                                   l.AppendPrePad(s, Environment.NewLine),
                                   dfont,
                                   textcolour,
                                   backcolour,
                                   1.0F,
                                   frmt: frmt);;

                    extPictureBoxScroll.Height = i.Location.Bottom + 8;
                    picelements.Add(i);
                    frmt.Dispose();

                    pictureBox.AddRange(picelements);
                    extPictureBoxScroll.Render();
                    Refresh();
                }
            }
        }
Example #5
0
        void CreateMaterialImage(List <ExtPictureBox.ImageElement> pc, Point matpos, Size matsize, string text, string mattag, string mattip, Color matcolour, Color textcolour)
        {
            System.Drawing.Imaging.ColorMap colormap = new System.Drawing.Imaging.ColorMap();
            colormap.OldColor = Color.White;    // this is the marker colour to replace
            colormap.NewColor = matcolour;

            Bitmap mat = BaseUtils.BitMapHelpers.ReplaceColourInBitmap((Bitmap)Icons.Controls.Scan_Bodies_Material, new System.Drawing.Imaging.ColorMap[] { colormap });

            BaseUtils.BitMapHelpers.DrawTextCentreIntoBitmap(ref mat, text, stdfont, textcolour);

            ExtPictureBox.ImageElement ie = new ExtPictureBox.ImageElement(
                new Rectangle(matpos.X, matpos.Y, matsize.Width, matsize.Height), mat, mattag, mattip);

            pc.Add(ie);
        }
Example #6
0
        Point CreateImageLabel(List <ExtPictureBox.ImageElement> c, Image i, Point postopright, Size size, string label,
                               string ttext, int labelhoff, bool fromEDSM, bool imgowned = true)
        {
            //System.Diagnostics.Debug.WriteLine("    " + label + " " + postopright + " size " + size + " hoff " + labelhoff + " laby " + (postopright.Y + size.Height + labelhoff));

            ExtPictureBox.ImageElement ie = new ExtPictureBox.ImageElement(new Rectangle(postopright.X, postopright.Y, size.Width, size.Height), i, ttext, ttext, imgowned);

            Point max = new Point(postopright.X + size.Width, postopright.Y + size.Height);

            if (label != null)
            {
                Font font = stdfont;
                if (fromEDSM)
                {
                    font = stdfontUnderline;
                }

                Point labposcenthorz = new Point(postopright.X + size.Width / 2, postopright.Y + size.Height + labelhoff);

                ExtPictureBox.ImageElement lab = new ExtPictureBox.ImageElement();
                Size maxsize = new Size(300, 30);

                //System.Diagnostics.Debug.WriteLine("Write Label " + label + " " + EDDTheme.Instance.LabelColor + " " + this.BackColor);

                lab.TextCentreAutosize(labposcenthorz, maxsize, label, font, EDDTheme.Instance.LabelColor, this.BackColor);

                if (lab.pos.X < postopright.X)
                {
                    int offset = postopright.X - lab.pos.X;
                    ie.Translate(offset, 0);
                    lab.Translate(offset, 0);
                }

                c.Add(lab);

                max = new Point(Math.Max(lab.pos.X + lab.pos.Width, max.X), lab.pos.Y + lab.pos.Height);
            }

            c.Add(ie);

            //System.Diagnostics.Debug.WriteLine(" ... to " + label + " " + max + " size " + (new Size(max.X-postopright.X,max.Y-postopright.Y)));
            return(max);
        }
Example #7
0
        // plot at leftmiddle the image of size, return bot left accounting for label
        // label can be null. returns ximagecentre of image

        Point CreateImageAndLabel(List <ExtPictureBox.ImageElement> c, Image i, Point leftmiddle, Size size, out Rectangle imageloc,
                                  string[] labels, string ttext, bool imgowned = true)
        {
            //System.Diagnostics.Debug.WriteLine("    " + label + " " + postopright + " size " + size + " hoff " + labelhoff + " laby " + (postopright.Y + size.Height + labelhoff));

            ExtPictureBox.ImageElement ie = new ExtPictureBox.ImageElement(new Rectangle(leftmiddle.X, leftmiddle.Y - size.Height / 2, size.Width, size.Height), i, ttext, ttext, imgowned);

            Point max = new Point(leftmiddle.X + size.Width, leftmiddle.Y + size.Height / 2);

            var labelie = new List <ExtPictureBox.ImageElement>();
            int laboff  = 0;
            int vpos    = leftmiddle.Y + size.Height / 2;

            foreach (string label in labels)
            {
                if (label.HasChars())
                {
                    Font f      = stdfont;
                    int  labcut = 0;
                    if (label[0] == '_')
                    {
                        f      = stdfontUnderline;
                        labcut = 1;
                    }

                    Point labposcenthorz = new Point(leftmiddle.X + size.Width / 2, vpos);

                    ExtPictureBox.ImageElement labie = new ExtPictureBox.ImageElement();
                    Color backcolor = this.BackColor;       // override for debug

                    using (var frmt = new StringFormat()
                    {
                        Alignment = StringAlignment.Center
                    })
                    {
                        labie.TextCentreAutosize(labposcenthorz, new Size(0, 1000), label.Substring(labcut), f, EDDTheme.Instance.LabelColor, backcolor, frmt: frmt);
                    }

                    labelie.Add(labie);

                    if (labie.Location.X < leftmiddle.X)
                    {
                        laboff = Math.Max(laboff, leftmiddle.X - labie.Location.X);
                    }
                    vpos += labie.Location.Height;
                }
            }


            foreach (var l in labelie)
            {
                l.Translate(laboff, 0);
                c.Add(l);
                max = new Point(Math.Max(max.X, l.Location.Right), Math.Max(max.Y, l.Location.Bottom));
                //System.Diagnostics.Debug.WriteLine("Label " + l.Location);
            }

            ie.Translate(laboff, 0);
            max = new Point(Math.Max(max.X, ie.Location.Right), Math.Max(max.Y, ie.Location.Bottom));
            c.Add(ie);

            imageloc = ie.Location;     // used to be ximagecentre = ie.Location.X+ie.Location.Width/2

            //System.Diagnostics.Debug.WriteLine(".. Max " + max);

            return(max);
        }
Example #8
0
        // curmats may be null
        Point CreateMaterialNodes(List <ExtPictureBox.ImageElement> pc, JournalScan sn, MaterialCommoditiesList curmats, HistoryList hl, Point matpos, Size matsize)
        {
            Point startpos  = matpos;
            Point maximum   = matpos;
            int   noperline = 0;

            string matclicktext = sn.DisplayMaterials(2, curmats, hl.GetLast?.MaterialCommodity);

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

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

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

                if (mc != null)
                {
                    abv   = mc.Shortname;
                    fillc = mc.Colour;

                    if (HideFullMaterials)                 // check full
                    {
                        int?limit = mc.MaterialLimit();
                        MaterialCommodities matnow = curmats?.Find(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)Icons.Controls.Scan_Bodies_Material, new System.Drawing.Imaging.ColorMap[] { colormap });

                BaseUtils.BitMapHelpers.DrawTextCentreIntoBitmap(ref mat, abv, stdfont, Color.Black);

                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);
        }
        // draw scannode (may be null),
        // curmats may be null
        public void DrawSystem(StarScan.SystemNode scannode, MaterialCommoditiesList curmats, HistoryList hl, string opttext = null, string[] filter = null)
        {
            HideInfo();

            imagebox.ClearImageList();  // does not clear the image, render will do that

            if (scannode != null)
            {
                Point leftmiddle = new Point(leftmargin, topmargin + StarSize.Height * nodeheightratio / 2 / noderatiodivider);  // half down (h/2 * ratio)

                if (opttext != null)
                {
                    ExtPictureBox.ImageElement lab = new ExtPictureBox.ImageElement();
                    lab.TextAutosize(new Point(leftmargin, 0), new Size(500, 30), opttext, largerfont, EDDTheme.Instance.LabelColor, this.BackColor);
                    imagebox.Add(lab);
                    leftmiddle.Y += lab.Image.Height + 8;
                }

                DisplayAreaUsed = leftmiddle;
                List <ExtPictureBox.ImageElement> starcontrols = new List <ExtPictureBox.ImageElement>();

                bool displaybelts = filter == null || (filter.Contains("belt") || filter.Contains("All"));

                Point maxitemspos = new Point(0, 0);

                foreach (StarScan.ScanNode starnode in scannode.starnodes.Values)         // always has scan nodes
                {
                    if (filter != null && starnode.IsBodyInFilter(filter, true) == false) // if filter active, but no body or children in filter
                    {
                        // System.Diagnostics.Debug.WriteLine("SDUC Rejected " + starnode.fullname);
                        continue;
                    }

                    // Draw star

                    Point maxstarpos = DrawNode(starcontrols, starnode, curmats, hl,
                                                (starnode.type == StarScan.ScanNodeType.barycentre) ? Icons.Controls.Scan_Bodies_Barycentre : JournalScan.GetStarImageNotScanned(),
                                                leftmiddle, false, out int unusedstarcentre, StarSize, DrawLevel.TopLevelStar); // the last part nerfs the label down to the right position

                    maxitemspos = new Point(Math.Max(maxitemspos.X, maxstarpos.X), Math.Max(maxitemspos.Y, maxstarpos.Y));

                    if (starnode.children != null)
                    {
                        leftmiddle = new Point(maxitemspos.X + starfirstplanetspacerx, leftmiddle.Y);
                        Point firstcolumn = leftmiddle;

                        Queue <StarScan.ScanNode> belts;
                        if (starnode.ScanData != null && (!starnode.ScanData.IsEDSMBody || CheckEDSM))                                        // have scandata on star, and its not edsm or allowed edsm
                        {
                            belts = new Queue <StarScan.ScanNode>(starnode.children.Values.Where(s => s.type == StarScan.ScanNodeType.belt)); // find belts in children of star
                        }
                        else
                        {
                            belts = new Queue <StarScan.ScanNode>(); // empty array
                        }

                        StarScan.ScanNode lastbelt = belts.Count != 0 ? belts.Dequeue() : null;

                        double habzonestartls = starnode.ScanData?.HabitableZoneInner ?? 0;
                        double habzoneendls   = starnode.ScanData?.HabitableZoneOuter ?? 0;

                        // process body and stars only

                        List <StarScan.ScanNode> planetsinorder = starnode.children.Values.Where(s => s.type == StarScan.ScanNodeType.body || s.type == StarScan.ScanNodeType.star).ToList();
                        var planetcentres = new Dictionary <StarScan.ScanNode, Point>();

                        for (int pn = 0; pn < planetsinorder.Count; pn++)
                        {
                            StarScan.ScanNode planetnode = planetsinorder[pn];

                            if (filter != null && planetnode.IsBodyInFilter(filter, true) == false)       // if filter active, but no body or children in filter
                            {
                                //System.Diagnostics.Debug.WriteLine("SDUC Rejected " + planetnode.fullname);
                                continue;
                            }

                            //System.Diagnostics.Debug.WriteLine("Draw " + planetnode.ownname + ":" + planetnode.type);

                            // if belt is before this, display belts here

                            while (displaybelts && lastbelt != null && planetnode.ScanData != null && (lastbelt.BeltData == null || planetnode.ScanData.IsOrbitingBaryCentre || lastbelt.BeltData.OuterRad < planetnode.ScanData.nSemiMajorAxis))
                            {
                                // if too far across, go back to star
                                if (leftmiddle.X + planetsize.Width > panelStars.Width - panelStars.ScrollBarWidth)               // if too far across..
                                {
                                    leftmiddle = new Point(firstcolumn.X, maxitemspos.Y + planetspacery + planetsize.Height / 2); // move to left at maxy+space+h/2
                                }

                                string appendlabel = "";

                                if (lastbelt.BeltData != null)
                                {
                                    appendlabel = appendlabel.AppendPrePad($"{lastbelt.BeltData.OuterRad / JournalScan.oneLS_m:N1}ls", Environment.NewLine);
                                }

                                appendlabel = appendlabel.AppendPrePad("" + lastbelt.ScanData?.BodyID, Environment.NewLine);

                                Point maxbeltpos = DrawNode(starcontrols, lastbelt, curmats, hl, Icons.Controls.Scan_Bodies_Belt, leftmiddle, false, out int unusedbeltcentre, beltsize, DrawLevel.PlanetLevel, appendlabeltext: appendlabel);

                                leftmiddle = new Point(maxbeltpos.X + planetspacerx, leftmiddle.Y);
                                lastbelt   = belts.Count != 0 ? belts.Dequeue() : null;

                                maxitemspos = new Point(Math.Max(maxitemspos.X, maxbeltpos.X), Math.Max(maxitemspos.Y, maxbeltpos.Y));
                            }

                            //System.Diagnostics.Debug.WriteLine("Planet Node " + planetnode.ownname + " has scans " + nonedsmscans);

                            if (planetnode.DoesNodeHaveNonEDSMScansBelow() || CheckEDSM)
                            {
                                List <ExtPictureBox.ImageElement> pc = new List <ExtPictureBox.ImageElement>();

                                bool habzone = false;

                                if (ShowHabZone && planetnode.ScanData != null && !planetnode.ScanData.IsOrbitingBaryCentre && planetnode.ScanData.nSemiMajorAxis.HasValue)
                                {
                                    double dist = planetnode.ScanData.nSemiMajorAxis.Value / JournalScan.oneLS_m;  // m , converted to LS
                                    habzone = dist >= habzonestartls && dist <= habzoneendls;
                                }

                                Point maxplanetpos = CreatePlanetTree(pc, planetnode, curmats, hl, leftmiddle, filter, habzone, out int centreplanet);

                                Point pcnt = new Point(centreplanet, leftmiddle.Y);

                                if (maxplanetpos.X > panelStars.Width - panelStars.ScrollBarWidth) // uh oh too wide..
                                {
                                    int xoff = firstcolumn.X - leftmiddle.X;                       // shift to firstcolumn.x, maxitemspos.Y+planetspacer
                                    int yoff = (maxitemspos.Y + planetspacery) - (leftmiddle.Y - planetsize.Height / 2);

                                    RepositionTree(pc, xoff, yoff);                                              // shift co-ords of all you've drawn - this will include any bary points drawn in moons

                                    pcnt.X += xoff; pcnt.Y += yoff;                                              // need to account for planet centre

                                    maxplanetpos = new Point(maxplanetpos.X + xoff, maxplanetpos.Y + yoff);      // remove the shift from maxpos

                                    leftmiddle = new Point(maxplanetpos.X + planetspacerx, leftmiddle.Y + yoff); // and set the curpos to maxpos.x + spacer, remove the shift from curpos.y
                                }
                                else
                                {
                                    leftmiddle = new Point(maxplanetpos.X + planetspacerx, leftmiddle.Y);     // shift current pos right, plus a spacer
                                }
                                maxitemspos = new Point(Math.Max(maxitemspos.X, maxplanetpos.X), Math.Max(maxitemspos.Y, maxplanetpos.Y));

                                starcontrols.AddRange(pc.ToArray());

                                planetcentres[planetnode] = pcnt;
                            }
                        }

                        // do any futher belts after all planets

                        while (displaybelts && lastbelt != null)
                        {
                            if (leftmiddle.X + planetsize.Width > panelStars.Width - panelStars.ScrollBarWidth)               // if too far across..
                            {
                                leftmiddle = new Point(firstcolumn.X, maxitemspos.Y + planetspacery + planetsize.Height / 2); // move to left at maxy+space+h/2
                            }

                            string appendlabel = "";

                            if (lastbelt.BeltData != null)
                            {
                                appendlabel = appendlabel.AppendPrePad($"{lastbelt.BeltData.OuterRad / JournalScan.oneLS_m:N1}ls", Environment.NewLine);
                            }

                            appendlabel = appendlabel.AppendPrePad("" + lastbelt.ScanData?.BodyID, Environment.NewLine);

                            Point maxbeltpos = DrawNode(starcontrols, lastbelt, curmats, hl, Icons.Controls.Scan_Bodies_Belt, leftmiddle, false, out int unusedbelt2centre, beltsize, DrawLevel.PlanetLevel, appendlabeltext: appendlabel);

                            leftmiddle = new Point(maxbeltpos.X + planetspacerx, leftmiddle.Y);
                            lastbelt   = belts.Count != 0 ? belts.Dequeue() : null;

                            maxitemspos = new Point(Math.Max(maxitemspos.X, maxbeltpos.X), Math.Max(maxitemspos.Y, maxbeltpos.Y));
                        }

                        maxitemspos = leftmiddle = new Point(leftmargin, maxitemspos.Y + starplanetgroupspacery + StarSize.Height / 2);     // move back to left margin and move down to next position of star, allowing gap

                        // make a tree of the planets with their barycentres from the Parents information
                        var barynodes = StarScan.ScanNode.PopulateBarycentres(planetsinorder);  // children always made, barynode tree

                        StarScan.ScanNode.DumpTree(barynodes, "TOP", 0);

                        List <ExtPictureBox.ImageElement> pcb = new List <ExtPictureBox.ImageElement>();

                        foreach (var k in barynodes.children)                                                       // for all barynodes.. display
                        {
                            DisplayBarynode(k.Value, 0, planetcentres, planetsinorder, pcb, planetsize.Height / 2); // done after the reposition so true positions set up.
                        }

                        starcontrols.InsertRange(0, pcb); // insert at start so drawn under
                    }
                    else
                    {               // no planets, so just move across and plot another one
                        leftmiddle = new Point(maxitemspos.X + starfirstplanetspacerx, leftmiddle.Y);

                        if (leftmiddle.X + StarSize.Width > panelStars.Width - panelStars.ScrollBarWidth)                                   // if too far across..
                        {
                            maxitemspos = leftmiddle = new Point(leftmargin, maxitemspos.Y + starplanetgroupspacery + StarSize.Height / 2); // move to left at maxy+space+h/2
                        }
                    }

                    DisplayAreaUsed = new Point(Math.Max(DisplayAreaUsed.X, maxitemspos.X), Math.Max(DisplayAreaUsed.Y, maxitemspos.Y));
                }

                imagebox.AddRange(starcontrols);
            }

            imagebox.Render();      // replaces image..
        }
Example #10
0
        const int baryspacingmargin = baryspacing * 4;      // up to 4 bary lines..

        Tuple <Point, int, int> DisplayBarynode(StarScan.ScanNode sn, int level, Dictionary <StarScan.ScanNode, Point> nodecentres, List <StarScan.ScanNode> nodes, List <ExtPictureBox.ImageElement> pc, int imagesize, bool horz = false)
        {
            if (sn.children == null)
            {
                return(new Tuple <Point, int, int>(Point.Empty, level, 0));
            }

            var tojoin = new List <BaryPointInfo>();

            int orderpos = 0;   // this records the last planet order pos for use to pass back up the tree - helps in ordering

            foreach (var c in sn.children)
            {
                if (c.Value.type == StarScan.ScanNodeType.barycentre)       // if a barycentre, draw it
                {
                    var x = DisplayBarynode(c.Value, level + 1, nodecentres, nodes, pc, imagesize, horz);
                    //System.Diagnostics.Debug.WriteLine("                        ".Substring(0, level * 3) + level + " Draw bary " + c.Value.fullname + " " + x.Item1 + " " + level);
                    if (horz)
                    {
                        tojoin.Add(new BaryPointInfo()
                        {
                            point = x.Item1, toppos = x.Item1, orderpos = x.Item3
                        });                                                                                        // make a join point for a barynode
                    }
                    else
                    {
                        tojoin.Add(new BaryPointInfo()
                        {
                            point = x.Item1, toppos = x.Item1, orderpos = x.Item3
                        });                                                                                        // make a join point for a barynode. Leave the toppos for later
                    }
                }
                else
                {
                    // Note if EDSM draw is turned off, but it was in the data from another source, we would not have drawn it so we need to check that by
                    // seeing if the node has a nodecentre. No nodecentre, did not draw

                    if (nodecentres.ContainsKey(c.Value))
                    {
                        orderpos = nodes.IndexOf(c.Value);
                        //System.Diagnostics.Debug.WriteLine("                        ".Substring(0, level * 3) + level + " Draw Body " + c.Value.fullname + " " + orderpos + " " + nodecentres[c.Value]);
                        if (horz)
                        {
                            tojoin.Add(new BaryPointInfo()
                            {
                                point = nodecentres[c.Value], toppos = new Point(nodecentres[c.Value].X - imagesize / 2, nodecentres[c.Value].Y), orderpos = orderpos
                            });
                        }
                        else
                        {
                            tojoin.Add(new BaryPointInfo()
                            {
                                point = nodecentres[c.Value], toppos = new Point(nodecentres[c.Value].X, nodecentres[c.Value].Y - 10 * imagesize / 8), orderpos = orderpos
                            });
                        }
                    }
                }
            }

            if (tojoin.Count > 1)                                                                                      // we need two or more to make a barynode line
            {
                tojoin.Sort(delegate(BaryPointInfo l, BaryPointInfo r) { return(l.orderpos.CompareTo(r.orderpos)); }); // make sure in order

                if (horz)
                {
                    foreach (var c in tojoin)                                                                                              // find min y of cohort (same line) and set estimate pos to it
                    {
                        int minx = tojoin.Where(x => Math.Abs(x.toppos.X - c.toppos.X) < baryspacingmargin).Select(x => x.toppos.X).Min(); // find minx in cohort
                        c.est = minx - baryspacing;                                                                                        // don't change toppos, we need it for other estimations. hold in another var
                    }

                    foreach (var c in tojoin)
                    {
                        c.toppos = new Point(c.est, c.toppos.Y);    // apply calculated pos to toppos to align all barycentres to it
                    }
                }
                else
                {
                    foreach (var c in tojoin)                                                                                              // find min y of cohort (same line) and set estimate pos to it
                    {
                        int miny = tojoin.Where(y => Math.Abs(y.toppos.Y - c.toppos.Y) < baryspacingmargin).Select(x => x.toppos.Y).Min(); // find miny in cohort
                        c.est = miny - baryspacing;                                                                                        // don't change toppos, we need it for other estimations. hold in another var
                    }

                    foreach (var c in tojoin)
                    {
                        c.toppos = new Point(c.toppos.X, c.est);    // apply calculated pos to toppos to align all barycentres to it
                    }
                }

                ExtPictureBox.ImageElement ie = new ExtPictureBox.ImageElement();
                ie.OwnerDraw(DrawBaryTree, new Rectangle(0, 0, horz ? 1 : 0, 0), tojoin); // use Width, which does not get affected by repositiontree, to record if horz
                pc.Insert(0, ie);                                                         // insert first so drawn under

                //System.Diagnostics.Debug.Write("                        ".Substring(0, level * 3) + level + " Join co-ords");
                //for (int i = 0; i < tojoin.Count; i++) System.Diagnostics.Debug.Write(" " + tojoin[i].point + ":" + tojoin[i].toppos);

                Point pi;       // calculate and return the barycentre position
                if (horz)
                {
                    if (tojoin.Average(x => x.toppos.X) == tojoin[0].toppos.X)      // if all on same line
                    {
                        pi = new Point(tojoin[0].toppos.X, (int)tojoin.Select(y => y.point.Y).Average());
                        //System.Diagnostics.Debug.Write(" same xline");
                    }
                    else
                    {
                        pi = new Point(tojoin[0].toppos.X, tojoin[0].toppos.Y + imagesize);
                        //System.Diagnostics.Debug.Write(" not same xline");
                    }
                }
                else
                {
                    if (tojoin.Average(x => x.toppos.Y) == tojoin[0].toppos.Y)      // if all on same line
                    {
                        pi = new Point((int)tojoin.Select(x => x.point.X).Average(), tojoin[0].toppos.Y);
                        //System.Diagnostics.Debug.Write(" same yline");
                    }
                    else
                    {
                        pi = new Point(tojoin[0].point.X + imagesize, tojoin[0].toppos.Y); // objects are not on same line, so we set the barypoint off to side a bit of the first
                        //System.Diagnostics.Debug.Write(" not same yline");
                    }
                }

                //System.Diagnostics.Debug.WriteLine(" Pass back " + pi);
                //System.Diagnostics.Debug.WriteLine("");
                return(new Tuple <Point, int, int>(pi, level, orderpos));
            }
            else
            {
                return(new Tuple <Point, int, int>(Point.Empty, level, 0));
            }
        }
        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 <MaterialCommodities> mcl = last_he.MaterialCommodity.Sort(false);

                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();

                string techBrokers = EliteDangerousCore.DB.UserDatabase.Instance.GetSettingString(DBTechBrokerFilterSave, "None");
                if (techBrokers != "None")
                {
                    List <string> techBrokerList = techBrokers.Split(';').ToList <string>();
                    foreach (Recipes.Recipe r in Recipes.TechBrokerUnlocks)
                    {
                        if (techBrokers == "All" || techBrokerList.Contains(r.Name))
                        {
                            totalWanted.Add(new Tuple <Recipes.Recipe, int>(r, 1));
                        }
                    }
                }

                string specialeffects = EliteDangerousCore.DB.UserDatabase.Instance.GetSettingString(DBSpecialEffectsFilterSave, "None");
                if (specialeffects != "None")
                {
                    List <string> seList = specialeffects.Split(';').ToList <string>();
                    foreach (Recipes.Recipe r in Recipes.SpecialEffects)
                    {
                        if (specialeffects == "All" || specialeffects.Contains(r.Name))
                        {
                            totalWanted.Add(new Tuple <Recipes.Recipe, int>(r, 1));
                        }
                    }
                }

                var shoppinglist = MaterialCommoditiesRecipe.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 = await discoveryform.history.starscan.FindSystemAsync(last_he.System, useEDSMForSystemAvailability);
                }

                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)
                        {
                            if (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 == MaterialCommodityData.ItemType.VeryCommon && totalReq > VeryCommonCap) ||
                            (c.Item1.Details.Type == MaterialCommodityData.ItemType.Common && totalReq > CommonCap) ||
                            (c.Item1.Details.Type == MaterialCommodityData.ItemType.Standard && totalReq > StandardCap) ||
                            (c.Item1.Details.Type == MaterialCommodityData.ItemType.Rare && totalReq > RareCap) ||
                            (c.Item1.Details.Type == MaterialCommodityData.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;
                        MaterialCommodityData 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.Panel1MinSize = displayList.Image.Width + 8;       // panel left has minimum width to accomodate the text
                }
                catch (Exception e)
                {
                    System.Diagnostics.Debug.WriteLine("Swallowed 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;
            buttonTechBroker.Visible       = buttonSpecialEffects.Visible = !IsTransparent;
        }
Example #12
0
        // draw scannode (may be null),
        // curmats may be null
        public void DrawSystem(StarScan.SystemNode scannode, MaterialCommoditiesList curmats, HistoryList hl, string opttext = null, string[] filter = null)
        {
            HideInfo();

            imagebox.ClearImageList();  // does not clear the image, render will do that

            if (scannode != null)
            {
                Point curpos = new Point(leftmargin, topmargin);

                if (opttext != null)
                {
                    ExtPictureBox.ImageElement lab = new ExtPictureBox.ImageElement();
                    lab.TextAutosize(curpos, new Size(500, 30), opttext, largerfont, EDDTheme.Instance.LabelColor, this.BackColor);
                    imagebox.Add(lab);
                    curpos.Y += lab.img.Height + 8;
                }

                DisplayAreaUsed = curpos;
                List <ExtPictureBox.ImageElement> starcontrols = new List <ExtPictureBox.ImageElement>();

                bool displaybelts = filter == null || (filter.Contains("belt") || filter.Contains("All"));

                //for( int i = 0; i < 1000; i +=100)  CreateStarPlanet(starcontrols, EDDiscovery.Properties.Resources.ImageStarDiscWhite, new Point(i, 0), new Size(24, 24), i.ToString(), "");

                //foreach( var sn in scannode.Bodies )
                //{
                //    System.Diagnostics.Debug.Write("Node " + sn.type + " " + sn.fullname);
                //    if ( sn.ScanData != null )
                //    {
                //        System.Diagnostics.Debug.Write("  " + sn.ScanData.IsStar + " P:" + sn.ScanData.PlanetTypeID + " S:" + sn.ScanData.StarTypeID + " EDSM:" + sn.ScanData.IsEDSMBody);
                //    }
                //    System.Diagnostics.Debug.WriteLine("");
                //}

                foreach (StarScan.ScanNode starnode in scannode.starnodes.Values)         // always has scan nodes
                {
                    if (filter != null && starnode.IsBodyInFilter(filter, true) == false) // if filter active, but no body or children in filter
                    {
                        System.Diagnostics.Debug.WriteLine("SDUC Rejected " + starnode.fullname);
                        continue;
                    }

                    // Draw star

                    int   offset     = 0;
                    Point maxstarpos = DrawNode(starcontrols, starnode, curmats, hl,
                                                (starnode.type == StarScan.ScanNodeType.barycentre) ? Icons.Controls.Scan_Bodies_Barycentre : JournalScan.GetStarImageNotScanned(),
                                                curpos, StarSize, ref offset, false, (planetsize.Height * 6 / 4 - StarSize.Height) / 2, true); // the last part nerfs the label down to the right position

                    Point maxitemspos = maxstarpos;

                    curpos    = new Point(maxitemspos.X + starfirstplanetspacerx, curpos.Y); // move to the right
                    curpos.Y += StarSize.Height / 2 - planetsize.Height * 3 / 4;             // slide down for planet vs star difference in size

                    Point firstcolumn = curpos;

                    if (starnode.children != null)
                    {
                        Queue <StarScan.ScanNode> belts = null;
                        if (starnode.ScanData != null && (!starnode.ScanData.IsEDSMBody || CheckEDSM))
                        {
                            belts = new Queue <StarScan.ScanNode>(starnode.children.Values.Where(s => s.type == StarScan.ScanNodeType.belt));
                        }
                        else
                        {
                            belts = new Queue <StarScan.ScanNode>();
                        }

                        StarScan.ScanNode lastbelt = belts.Count != 0 ? belts.Dequeue() : null;

                        // process body and stars only

                        foreach (StarScan.ScanNode planetnode in starnode.children.Values.Where(s => s.type == StarScan.ScanNodeType.body || s.type == StarScan.ScanNodeType.star))
                        {
                            if (filter != null && planetnode.IsBodyInFilter(filter, true) == false)       // if filter active, but no body or children in filter
                            {
                                System.Diagnostics.Debug.WriteLine("SDUC Rejected " + planetnode.fullname);
                                continue;
                            }

                            //System.Diagnostics.Debug.WriteLine("Draw " + planetnode.ownname + ":" + planetnode.type);

                            // if belt is before this, display belts here

                            while (displaybelts && lastbelt != null && planetnode.ScanData != null && (lastbelt.BeltData == null || lastbelt.BeltData.OuterRad < planetnode.ScanData.nSemiMajorAxis))
                            {
                                //System.Diagnostics.Debug.WriteLine("Draw a belt " + lastbelt.ownname);

                                // if too far across, go back to star
                                if (curpos.X + planetsize.Width > panelStars.Width - panelStars.ScrollBarWidth)
                                {
                                    curpos = new Point(firstcolumn.X, maxitemspos.Y + planetsize.Height + planetspacery);
                                }

                                Point used = DrawNode(starcontrols, lastbelt, curmats, hl, Icons.Controls.Scan_Bodies_Belt,
                                                      new Point(curpos.X + (planetsize.Width - beltsize.Width) / 2, curpos.Y), beltsize, ref offset, false);

                                curpos   = new Point(used.X, curpos.Y);
                                lastbelt = belts.Count != 0 ? belts.Dequeue() : null;
                            }

                            bool nonedsmscans = planetnode.DoesNodeHaveNonEDSMScansBelow();     // is there any scans here, either at this node or below?

                            //System.Diagnostics.Debug.WriteLine("Planet Node " + planetnode.ownname + " has scans " + nonedsmscans);

                            if (nonedsmscans || CheckEDSM)
                            {
                                List <ExtPictureBox.ImageElement> pc = new List <ExtPictureBox.ImageElement>();

                                Point maxpos = CreatePlanetTree(pc, planetnode, curmats, hl, curpos, filter);

                                //System.Diagnostics.Debug.WriteLine("Planet " + planetnode.ownname + " " + curpos + " " + maxpos + " max " + (panelStars.Width - panelStars.ScrollBarWidth));

                                if (maxpos.X > panelStars.Width - panelStars.ScrollBarWidth)    // uh oh too wide..
                                {
                                    int xoffset = firstcolumn.X - curpos.X;                     // shift to firstcolumn.x, maxitemspos.Y+planetspacer
                                    int yoffset = (maxitemspos.Y + planetspacery) - curpos.Y;

                                    RepositionTree(pc, xoffset, yoffset);                             // shift co-ords of all you've drawn

                                    maxpos = new Point(maxpos.X + xoffset, maxpos.Y + yoffset);       // remove the shift from maxpos
                                    curpos = new Point(maxpos.X + planetspacerx, curpos.Y + yoffset); // and set the curpos to maxpos.x + spacer, remove the shift from curpos.y
                                }
                                else
                                {
                                    curpos = new Point(maxpos.X + planetspacerx, curpos.Y);     // shift current pos right, plus a spacer
                                }
                                maxitemspos = new Point(Math.Max(maxitemspos.X, maxpos.X), Math.Max(maxitemspos.Y, maxpos.Y));

                                starcontrols.AddRange(pc.ToArray());
                            }
                        }

                        // do any futher belts after all planets

                        while (displaybelts && lastbelt != null)
                        {
                            if (curpos.X + planetsize.Width > panelStars.Width - panelStars.ScrollBarWidth)
                            {
                                curpos = new Point(firstcolumn.X, maxitemspos.Y + planetsize.Height);
                            }

                            Point used = DrawNode(starcontrols, lastbelt, curmats, hl, Icons.Controls.Scan_Bodies_Belt,
                                                  new Point(curpos.X + (planetsize.Width - beltsize.Width) / 2, curpos.Y), beltsize, ref offset, false);

                            curpos   = new Point(used.X, curpos.Y);
                            lastbelt = belts.Count != 0 ? belts.Dequeue() : null;
                        }
                    }

                    DisplayAreaUsed = new Point(Math.Max(DisplayAreaUsed.X, maxitemspos.X), Math.Max(DisplayAreaUsed.Y, maxitemspos.Y));

                    curpos = new Point(leftmargin, maxitemspos.Y + starplanetgroupspacery);     // move back to left margin and move down to next position of star, allowing gap
                }

                imagebox.AddRange(starcontrols);
            }

            imagebox.Render();      // replaces image..
        }
Example #13
0
        public void DrawSystem(StarScan.SystemNode last_sn, MaterialCommoditiesList curmats, HistoryList hl, string opttext = null)    // draw showing_system (may be null), showing_matcomds (may be null)
        {
            HideInfo();

            imagebox.ClearImageList();  // does not clear the image, render will do that

            if (last_sn != null)
            {
                Point curpos = new Point(leftmargin, topmargin);

                if (opttext != null)
                {
                    ExtPictureBox.ImageElement lab = new ExtPictureBox.ImageElement();
                    lab.TextAutosize(curpos, new Size(500, 30), opttext, largerfont, EDDTheme.Instance.LabelColor, this.BackColor);
                    imagebox.Add(lab);
                    curpos.Y += lab.img.Height + 8;
                }

                DisplayAreaUsed = curpos;
                List <ExtPictureBox.ImageElement> starcontrols = new List <ExtPictureBox.ImageElement>();

                //for( int i = 0; i < 1000; i +=100)  CreateStarPlanet(starcontrols, EDDiscovery.Properties.Resources.ImageStarDiscWhite, new Point(i, 0), new Size(24, 24), i.ToString(), "");

                foreach (StarScan.ScanNode starnode in last_sn.starnodes.Values)        // always has scan nodes
                {
                    //System.Diagnostics.Debug.WriteLine("Draw " + starnode.type);
                    int   offset     = 0;
                    Point maxstarpos = DrawNode(starcontrols, starnode, curmats, hl,
                                                (starnode.type == StarScan.ScanNodeType.barycentre) ? Icons.Controls.Scan_Bodies_Barycentre : JournalScan.GetStarImageNotScanned(),
                                                curpos, StarSize, ref offset, false, (planetsize.Height * 6 / 4 - StarSize.Height) / 2, true); // the last part nerfs the label down to the right position

                    Point maxitemspos = maxstarpos;

                    curpos    = new Point(maxitemspos.X + itemsepar.Width, curpos.Y); // move to the right
                    curpos.Y += StarSize.Height / 2 - planetsize.Height * 3 / 4;      // slide down for planet vs star difference in size

                    Point firstcolumn = curpos;

                    if (starnode.children != null)
                    {
                        Queue <StarScan.ScanNode> belts = null;
                        if (starnode.ScanData != null && (!starnode.ScanData.IsEDSMBody || CheckEDSM))
                        {
                            belts = new Queue <StarScan.ScanNode>(starnode.children.Values.Where(s => s.type == StarScan.ScanNodeType.belt));
                        }
                        else
                        {
                            belts = new Queue <StarScan.ScanNode>();
                        }

                        StarScan.ScanNode lastbelt = belts.Count != 0 ? belts.Dequeue() : null;

                        foreach (StarScan.ScanNode planetnode in starnode.children.Values.Where(s => s.type == StarScan.ScanNodeType.body || s.type == StarScan.ScanNodeType.star))
                        {
                            // System.Diagnostics.Debug.WriteLine("Draw " + planetnode.type);

                            while (lastbelt != null && planetnode.ScanData != null && (lastbelt.BeltData == null || lastbelt.BeltData.OuterRad < planetnode.ScanData.nSemiMajorAxis))
                            {
                                if (curpos.X + planetsize.Width > panelStars.Width - panelStars.ScrollBarWidth)
                                {
                                    curpos = new Point(firstcolumn.X, maxitemspos.Y + planetsize.Height);
                                }

                                DrawNode(starcontrols, lastbelt, curmats, hl, Icons.Controls.Scan_Bodies_Belt,
                                         new Point(curpos.X + (planetsize.Width - beltsize.Width) / 2, curpos.Y), beltsize, ref offset, false);

                                curpos   = new Point(curpos.X + planetsize.Width, curpos.Y);
                                lastbelt = belts.Count != 0 ? belts.Dequeue() : null;
                            }

                            bool nonedsmscans = planetnode.DoesNodeHaveNonEDSMScansBelow();     // is there any scans here, either at this node or below?

                            //System.Diagnostics.Debug.WriteLine("Planet Node " + planetnode.ownname + " has scans " + nonedsmscans);

                            if (nonedsmscans || CheckEDSM)
                            {
                                List <ExtPictureBox.ImageElement> pc = new List <ExtPictureBox.ImageElement>();

                                Point maxpos = CreatePlanetTree(pc, planetnode, curmats, hl, curpos);

                                //System.Diagnostics.Debug.WriteLine("Planet " + planetnode.ownname + " " + curpos + " " + maxpos + " max " + (panelStars.Width - panelStars.ScrollBarWidth));

                                if (maxpos.X > panelStars.Width - panelStars.ScrollBarWidth)          // uh oh too wide..
                                {
                                    int xoffset = firstcolumn.X - curpos.X;
                                    int yoffset = maxitemspos.Y - curpos.Y;

                                    RepositionTree(pc, xoffset, yoffset);        // shift co-ords of all you've drawn

                                    maxpos = new Point(maxpos.X + xoffset, maxpos.Y + yoffset);
                                    curpos = new Point(maxpos.X, curpos.Y + yoffset);
                                }
                                else
                                {
                                    curpos = new Point(maxpos.X, curpos.Y);
                                }

                                maxitemspos = new Point(Math.Max(maxitemspos.X, maxpos.X), Math.Max(maxitemspos.Y, maxpos.Y));

                                starcontrols.AddRange(pc.ToArray());
                            }
                        }

                        while (lastbelt != null)
                        {
                            if (curpos.X + planetsize.Width > panelStars.Width - panelStars.ScrollBarWidth)
                            {
                                curpos = new Point(firstcolumn.X, maxitemspos.Y + planetsize.Height);
                            }

                            DrawNode(starcontrols, lastbelt, curmats, hl, Icons.Controls.Scan_Bodies_Belt,
                                     new Point(curpos.X + (planetsize.Width - beltsize.Width) / 2, curpos.Y), beltsize, ref offset, false);

                            curpos   = new Point(curpos.X + planetsize.Width, curpos.Y);
                            lastbelt = belts.Count != 0 ? belts.Dequeue() : null;
                        }
                    }

                    DisplayAreaUsed = new Point(Math.Max(DisplayAreaUsed.X, maxitemspos.X), Math.Max(DisplayAreaUsed.Y, maxitemspos.Y));
                    curpos          = new Point(leftmargin, maxitemspos.Y + itemsepar.Height);
                }

                imagebox.AddRange(starcontrols);
            }

            imagebox.Render();      // replaces image..
        }
        // 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);
        }