static public JToken setCommanderInventoryItem(MaterialCommoditiesList list, string name, DateTime dt)
        {
            var item = list.FindFDName(name);

            if (item != null)
            {
                if (item.Details.IsCommodity)
                {
                    return(setCommanderInventoryCargoItem(item.Details.FDName, item.Count, null, dt));
                }
                else
                {
                    return(setCommanderInventoryMaterialsItem(item.Details.FDName, item.Count, dt));
                }
            }
            else
            {
                System.Diagnostics.Debug.WriteLine("Can't find " + name + " in mat db");
                return(null);
            }
        }
        }                                   // found from MCL

        public void UpdateMaterials(MaterialCommoditiesList mc)
        {
            mc.Change(Category, Name, -Count, 0);
            Total = mc.FindFDName(Name)?.Count ?? 0;
        }
Beispiel #3
0
        private void DisplayTradeSelection(MaterialCommodityData highlight = null)  // last_he and current_mcl can be null
        {
            int sel = extComboBoxTraderType.SelectedIndex;

            var mcl = new List <Tuple <MaterialCommodityData.MaterialGroupType, MaterialCommodityData[]> >();                                                  // list of groups vs data
            Dictionary <MaterialCommodityData.MaterialGroupType, string> mattxgroupnames = new Dictionary <MaterialCommodityData.MaterialGroupType, string>(); // translated names of groups

            foreach (var t in Enum.GetValues(typeof(MaterialCommodityData.MaterialGroupType)))                                                                 // relies on MCD being in order
            {
                var  matgroup = (MaterialCommodityData.MaterialGroupType)t;
                bool ok       = (sel == 0 && matgroup >= MaterialCommodityData.MaterialGroupType.RawCategory1 && matgroup <= MaterialCommodityData.MaterialGroupType.RawCategory7);
                ok |= (sel == 1 && matgroup >= MaterialCommodityData.MaterialGroupType.EncodedEmissionData && matgroup <= MaterialCommodityData.MaterialGroupType.EncodedFirmware);
                ok |= (sel == 2 && matgroup >= MaterialCommodityData.MaterialGroupType.ManufacturedChemical);
                if (ok)
                {
                    var list = MaterialCommodityData.Get(x => x.MaterialGroup == matgroup);
                    mcl.Add(new Tuple <MaterialCommodityData.MaterialGroupType, MaterialCommodityData[]>(matgroup, list));
                    mattxgroupnames[matgroup] = list[0].TranslatedMaterialGroup;
                }
            }

            Font titlefont = EDDTheme.Instance.GetFont;
            Font badgefont = EDDTheme.Instance.GetScaledFont(16f / 12f, max: 21);

            const int hbadgemargin = 20;
            const int vbadgemargin = 12;

            extPictureTrades.ClearImageList();

            int vpos    = 0;
            int maxhpos = 0;

            foreach (var t in mcl)
            {
                int hpos     = 0;
                int nextvpos = vpos;
                int lvl      = 1;

                extPictureTrades.AddOwnerDraw((g, ie) =>
                {
                    int tlen;
                    using (Brush b = new SolidBrush(orange))
                    {
                        string s = mattxgroupnames[t.Item1];
                        s        = s.Substring(s.IndexOf(" ") + 1);
                        tlen     = (int)(g.MeasureString(s, titlefont).Width + 2);
                        g.DrawString(s, titlefont, b, new Point(ie.Location.Left, ie.Location.Top));
                    }

                    using (Pen p = new Pen(orange))
                    {
                        g.DrawLine(p, new Point(tlen, ie.Location.Top + titlefont.Height / 2), new Point(maxhpos, ie.Location.Top + titlefont.Height / 2));
                    }
                }, new Rectangle(0, vpos, 2000, 24), t.Item1.ToString());

                vpos += titlefont.Height + 6;

                string backname = "encodedbackground";
                if (t.Item1.ToString().Contains("Manu"))
                {
                    backname = "manubackground";
                }
                else if (t.Item1.ToString().Contains("Raw"))
                {
                    backname = "rawbackground";
                }

                Bitmap background = BaseUtils.Icons.IconSet.GetIcon("Controls.MaterialTrader." + backname) as Bitmap;

                foreach (var mat in t.Item2)
                {
                    int    offer = 0, receive = 0;
                    string name = mat.Name;

                    int mattotal = last_mcl == null ? int.MinValue : last_mcl.FindFDName(mat.FDName)?.Count ?? 0; // find mcl in material list if there, and its count

                    if (mattotal >= 0)                                                                            // if we have an he, adjust the totals by the trades
                    {
                        foreach (var trade in trades)
                        {
                            if (trade.fromelement.FDName == mat.FDName)
                            {
                                mattotal -= trade.offer;                              // may go negative if over offered
                            }
                            if (trade.element.FDName == mat.FDName)
                            {
                                mattotal += trade.receive;
                            }
                        }
                    }

                    Color wash = Color.Transparent;

                    if (highlight?.FDName == mat.FDName)
                    {
                        wash = Color.FromArgb(80, 0, 75, 0);
                    }

                    if (selected != null)
                    {
                        bool difflevel = selected.type != t.Item1;

                        if (lvl < selected.level)
                        {
                            offer   = (int)Math.Pow(6, (selected.level - lvl) + (difflevel ? 1 : 0));
                            receive = 1;
                        }
                        else if (lvl > selected.level)
                        {
                            offer   = difflevel ? 6 : 1;
                            receive = (int)Math.Pow(3, (lvl - selected.level));
                            while (offer % 3 == 0)
                            {
                                offer   /= 3;
                                receive /= 3;
                            }
                        }
                        else if (selected.type == t.Item1)
                        {
                            name = "Cancel";
                            wash = Color.FromArgb(80, 0, 32, 0);
                        }
                        else
                        {
                            offer   = 6;
                            receive = 1;
                        }

                        if (offer > mattotal)
                        {
                            wash = Color.FromArgb(80, 128, 0, 0);
                        }
                    }

                    Bitmap bmp = DrawBadge(background, badgefont, offer, receive, lvl, name, mattotal, wash);

                    var ie = extPictureTrades.AddImage(new Rectangle(hpos, vpos, background.Width, background.Height), bmp, imgowned: true);
                    ie.Tag = new ElementTrade {
                        type = t.Item1, element = mat, level = lvl, offer = offer, receive = receive
                    };

                    maxhpos  = Math.Max(maxhpos, hpos + bmp.Width);
                    hpos    += bmp.Width + hbadgemargin;
                    nextvpos = Math.Max(nextvpos, vpos + bmp.Height + vbadgemargin);
                    lvl++;
                }

                vpos = nextvpos;
            }

            extPictureTrades.Render();
        }
        }                                   // found from MCL

        public void UpdateCommodities(MaterialCommoditiesList mc)
        {
            mc.Change(MaterialCommodityData.CatType.Commodity, Type, 1, 0);
            Total = mc.FindFDName(Type)?.Count ?? 0;
        }
        private void Display()  // last_he and current_mcl can be null
        {
            int sel = extComboBoxTraderType.SelectedIndex;

            mcl = new List <Tuple <MaterialCommodityData.MaterialGroupType, MaterialCommodityData[]> >();

            foreach (var t in Enum.GetValues(typeof(MaterialCommodityData.MaterialGroupType)))
            {
                var  e  = (MaterialCommodityData.MaterialGroupType)t;
                bool ok = (sel == 0 && e >= MaterialCommodityData.MaterialGroupType.RawCategory1 && e <= MaterialCommodityData.MaterialGroupType.RawCategory7);
                ok |= (sel == 1 && e >= MaterialCommodityData.MaterialGroupType.EncodedEmissionData && e <= MaterialCommodityData.MaterialGroupType.EncodedFirmware);
                ok |= (sel == 2 && e >= MaterialCommodityData.MaterialGroupType.ManufacturedChemical);
                if (ok)
                {
                    var list = MaterialCommodityData.GetMaterialGroup(x => x.MaterialGroup == e);
                    mcl.Add(new Tuple <MaterialCommodityData.MaterialGroupType, MaterialCommodityData[]>(e, list));
                }
            }

            const int badgemargin = 20;

            extPictureTrades.ClearImageList();

            int vpos = 0;

            foreach (var t in mcl)
            {
                int hpos     = 0;
                int nextvpos = vpos;
                int lvl      = 1;

                foreach (var b in t.Item2)
                {
                    Bitmap background = EDDiscovery.Icons.IconSet.GetIcon("Controls.MaterialTrader.encodedbackground") as Bitmap;

                    int    offer = 0, receive = 0, mattotal = 0;
                    string name = b.Name;

                    var mc = current_mcl?.FindFDName(b.FDName) ?? (last_he?.MaterialCommodity.FindFDName(b.FDName));    // if locked to mcl, use that, else use last he mcl

                    mattotal = mc?.Count ?? -1;

                    Color wash = Color.Transparent;

                    if (selected != null)
                    {
                        bool difflevel = selected.type != t.Item1;

                        if (lvl < selected.level)
                        {
                            offer   = (int)Math.Pow(6, (selected.level - lvl) + (difflevel ? 1 : 0));
                            receive = 1;
                        }
                        else if (lvl > selected.level)
                        {
                            offer   = difflevel ? 6 : 1;
                            receive = (int)Math.Pow(3, (lvl - selected.level));
                            while (offer % 3 == 0)
                            {
                                offer   /= 3;
                                receive /= 3;
                            }
                        }
                        else if (selected.type == t.Item1)
                        {
                            name = "Cancel";
                            wash = Color.FromArgb(80, 0, 32, 0);
                        }
                        else
                        {
                            offer   = 6;
                            receive = 1;
                        }

                        if (offer > mattotal)
                        {
                            wash = Color.FromArgb(80, 128, 0, 0);
                        }
                    }

                    Bitmap bmp = DrawBadge(background, offer, receive, lvl, name, mattotal, wash);

                    var ie = extPictureTrades.AddImage(new Rectangle(hpos, vpos, background.Width, background.Height), bmp, imgowned: true);
                    ie.tag = new ElementTag {
                        type = t.Item1, element = b, level = lvl, offer = offer, receive = receive
                    };

                    hpos    += bmp.Width + badgemargin;
                    nextvpos = Math.Max(nextvpos, vpos + bmp.Height + badgemargin);
                    lvl++;
                }

                vpos = nextvpos;
            }

            extPictureTrades.Render();
        }