Example #1
0
        public override void Init()
        {
            dataGridViewEngineering.MakeDoubleBuffered();
            extCheckBoxWordWrap.Checked = EliteDangerousCore.DB.UserDatabase.Instance.GetSettingBool(DbWordWrap, false);
            UpdateWordWrap();
            extCheckBoxWordWrap.Click += extCheckBoxWordWrap_Click;

            Order = EliteDangerousCore.DB.UserDatabase.Instance.GetSettingString(DbOSave, "").RestoreArrayFromString(0, Recipes.EngineeringRecipes.Count);
            if (Order.Max() >= Recipes.EngineeringRecipes.Count || Order.Min() < 0 || Order.Distinct().Count() != Recipes.EngineeringRecipes.Count) // if not distinct..
            {
                for (int i = 0; i < Order.Length; i++)                                                                                              // reset
                {
                    Order[i] = i;
                }
            }

            Wanted = EliteDangerousCore.DB.UserDatabase.Instance.GetSettingString(DbWSave, "").RestoreArrayFromString(0, Recipes.EngineeringRecipes.Count);

            List <string> engineers = Recipes.EngineeringRecipes.SelectMany(r => r.engineers).Distinct().ToList();

            engineers.Sort();
            efs          = new RecipeFilterSelector(engineers);
            efs.Changed += FilterChanged;

            lfs          = new RecipeFilterSelector(levels);
            lfs.Changed += FilterChanged;

            List <string> modules = Recipes.EngineeringRecipes.SelectMany(r => r.modules).Distinct().ToList();

            modules.Sort();
            mfs          = new RecipeFilterSelector(modules);
            mfs.Changed += FilterChanged;

            var upgrades = Recipes.EngineeringRecipes.Select(r => r.Name).Distinct().ToList();

            upgrades.Sort();
            ufs          = new RecipeFilterSelector(upgrades);
            ufs.Changed += FilterChanged;

            List <string> matLongNames = Recipes.EngineeringRecipes.SelectMany(r => r.Ingredients).Select(x => x.Name).Distinct().ToList();

            matfs          = new RecipeFilterSelector(matLongNames);
            matfs.Changed += FilterChanged;

            for (int i = 0; i < Recipes.EngineeringRecipes.Count; i++)         // pre-fill array.. preventing the crash on cell edit when you
            {
                int rno = Order[i];
                Recipes.EngineeringRecipe r = Recipes.EngineeringRecipes[rno];

                int             rown = dataGridViewEngineering.Rows.Add();
                DataGridViewRow row  = dataGridViewEngineering.Rows[rown];
                row.Cells[UpgradeCol.Index].Value   = r.Name; // debug rno + ":" + r.name;
                row.Cells[ModuleCol.Index].Value    = r.modulesstring;
                row.Cells[LevelCol.Index].Value     = r.level;
                row.Cells[EngineersCol.Index].Value = r.engineersstring;
                row.Tag     = rno;
                row.Visible = false;
            }

            isHistoric = EliteDangerousCore.DB.UserDatabase.Instance.GetSettingBool(DbHistoricMatsSave, false);

            discoveryform.OnNewEntry      += Discoveryform_OnNewEntry;
            discoveryform.OnHistoryChange += Discoveryform_OnHistoryChange;

            BaseUtils.Translator.Instance.Translate(this);
            BaseUtils.Translator.Instance.Translate(toolTip, this);
        }
        public override void Init()
        {
            dataGridViewEngineering.MakeDoubleBuffered();
            dataGridViewEngineering.DefaultCellStyle.WrapMode = DataGridViewTriState.False;

            Order = SQLiteDBClass.GetSettingString(DbOSave, "").RestoreArrayFromString(0, Recipes.EngineeringRecipes.Count);
            if (Order.Max() >= Recipes.EngineeringRecipes.Count || Order.Min() < 0 || Order.Distinct().Count() != Recipes.EngineeringRecipes.Count) // if not distinct..
            {
                for (int i = 0; i < Order.Length; i++)                                                                                              // reset
                {
                    Order[i] = i;
                }
            }

            Wanted = SQLiteDBClass.GetSettingString(DbWSave, "").RestoreArrayFromString(0, Recipes.EngineeringRecipes.Count);

            List <string> engineers = Recipes.EngineeringRecipes.SelectMany(r => r.engineers).Distinct().ToList();

            engineers.Sort();
            efs          = new RecipeFilterSelector(engineers);
            efs.Changed += FilterChanged;

            lfs          = new RecipeFilterSelector(levels);
            lfs.Changed += FilterChanged;

            List <string> modules = Recipes.EngineeringRecipes.SelectMany(r => r.modules).Distinct().ToList();

            modules.Sort();
            mfs          = new RecipeFilterSelector(modules);
            mfs.Changed += FilterChanged;

            var upgrades = Recipes.EngineeringRecipes.Select(r => r.name).Distinct().ToList();

            upgrades.Sort();
            ufs          = new RecipeFilterSelector(upgrades);
            ufs.Changed += FilterChanged;

            List <string> matShortNames = Recipes.EngineeringRecipes.SelectMany(r => r.ingredients).Distinct().ToList();

            matLookUp = matShortNames.ToDictionary(sn => MaterialCommodityData.GetByShortName(sn).Name, sn => sn);
            List <string> matLongNames = matLookUp.Keys.ToList();

            matLongNames.Sort();
            matfs          = new RecipeFilterSelector(matLongNames);
            matfs.Changed += FilterChanged;

            for (int i = 0; i < Recipes.EngineeringRecipes.Count; i++)         // pre-fill array.. preventing the crash on cell edit when you
            {
                int rno = Order[i];
                Recipes.EngineeringRecipe r = Recipes.EngineeringRecipes[rno];

                int             rown = dataGridViewEngineering.Rows.Add();
                DataGridViewRow row  = dataGridViewEngineering.Rows[rown];
                row.Cells[UpgradeCol.Index].Value      = r.name; // debug rno + ":" + r.name;
                row.Cells[ModuleCol.Index].Value       = r.modulesstring;
                row.Cells[LevelCol.Index].Value        = r.level;
                row.Cells[RecipeCol.Index].Value       = r.ingredientsstring;
                row.Cells[RecipeCol.Index].ToolTipText = r.ingredientsstringlong;
                row.Cells[EngineersCol.Index].Value    = r.engineersstring;
                row.Tag     = rno;
                row.Visible = false;
            }

            isHistoric = SQLiteDBClass.GetSettingBool(DbHistoricMatsSave, false);

            discoveryform.OnNewEntry += Discoveryform_OnNewEntry;

            BaseUtils.Translator.Instance.Translate(this);
            BaseUtils.Translator.Instance.Translate(toolTip, this);
        }
        public void Init(string name, string starsystem, string planet, string basename, ItemData.EngineeringInfo ei,
                         string wantedsettings, string colsetting)
        {
            this.Name    = name;
            EngineerInfo = ei;

            ExtendedControls.Theme.Current?.ApplyStd(this);
            var enumlist = new Enum[] { EDTx.UserControlEngineering_UpgradeCol, EDTx.UserControlEngineering_ModuleCol, EDTx.UserControlEngineering_LevelCol,
                                        EDTx.UserControlEngineering_MaxCol, EDTx.UserControlEngineering_WantedCol, EDTx.UserControlEngineering_CraftedCol,
                                        EDTx.UserControlEngineering_NotesCol, EDTx.UserControlEngineering_RecipeCol, EDTx.UserControlEngineering_EngineersCol, };

            BaseUtils.Translator.Instance.TranslateControls(this, enumlist, null, "UserControlEngineering");    // share IDs with Engineering panel./

            dataGridViewEngineering.LoadColumnSettings(colsetting, (a) => EliteDangerousCore.DB.UserDatabase.Instance.GetSettingInt(a, int.MinValue),
                                                       (b) => EliteDangerousCore.DB.UserDatabase.Instance.GetSettingDouble(b, double.MinValue));

            labelEngineerName.Text       = name;
            labelEngineerStatus.Text     = "";
            engineerImage.Image          = BaseUtils.Icons.IconSet.GetIcon("Engineers." + name);
            labelEngineerStarSystem.Text = starsystem;
            labelPlanet.Text             = planet;
            labelBaseName.Text           = basename;
            labelEngineerDistance.Text   = "";
            labelCrafts.Text             = "";

            if (name == "Weapon" || name == "Suit")        // these are not currently recorded in EngineerList
            {
                CraftedCol.HeaderText = "-";
            }

            dataGridViewEngineering.MakeDoubleBuffered();

            dataViewScrollerPanel.Suspend();

            for (int i = 0; i < Recipes.EngineeringRecipes.Count; i++)
            {
                if (Recipes.EngineeringRecipes[i].engineers.Contains(name))
                {
                    Recipes.EngineeringRecipe r = Recipes.EngineeringRecipes[i];

                    var row = dataGridViewEngineering.Rows[dataGridViewEngineering.Rows.Add()];
                    row.Tag = r;
                    row.Cells[UpgradeCol.Index].Value      = r.Name;
                    row.Cells[ModuleCol.Index].Value       = r.modulesstring;
                    row.Cells[LevelCol.Index].Value        = r.level;
                    row.Cells[EngineersCol.Index].Tag      = r.engineers;   // keep list in tag
                    row.Cells[EngineersCol.Index].Value    = string.Join(Environment.NewLine, r.engineers);
                    row.Cells[RecipeCol.Index].ToolTipText = r.IngredientsStringLong;
                }
            }

            WantedPerRecipe = wantedsettings.RestoreArrayFromString(0, RecipesCount);

            for (int i = 0; i < RecipesCount; i++)
            {
                dataGridViewEngineering.Rows[i].Cells[WantedCol.Index].Value = WantedPerRecipe[i].ToString();
            }

            dataViewScrollerPanel.Resume();

            //System.Diagnostics.Debug.WriteLine($"Engineer {name} Recipes {dataGridViewEngineering.RowCount}");

            delaytime.Tick += Delaytime_Tick;
        }
        public override void Init()
        {
            dataGridViewEngineering.MakeDoubleBuffered();
            extCheckBoxWordWrap.Checked = GetSetting(dbWordWrap, false);
            UpdateWordWrap();
            extCheckBoxWordWrap.Click += extCheckBoxWordWrap_Click;

            RowToRecipe = GetSetting(dbOSave, "").RestoreArrayFromString(0, Recipes.EngineeringRecipes.Count);
            if (RowToRecipe.Max() >= Recipes.EngineeringRecipes.Count || RowToRecipe.Min() < 0 || RowToRecipe.Distinct().Count() != Recipes.EngineeringRecipes.Count) // if not distinct..
            {
                for (int i = 0; i < RowToRecipe.Length; i++)                                                                                                          // reset
                {
                    RowToRecipe[i] = i;
                }
            }

            WantedPerRecipe = GetSetting(dbWSave, "").RestoreArrayFromString(0, Recipes.EngineeringRecipes.Count);

            List <string> engineers = Recipes.EngineeringRecipes.SelectMany(r => r.engineers).Distinct().ToList();

            engineers.Sort();
            efs = new RecipeFilterSelector(engineers);
            efs.SaveSettings += (newvalue, e) => { PutSetting(dbEngFilterSave, newvalue); Display(); };

            lfs = new RecipeFilterSelector(levels);
            lfs.SaveSettings += (newvalue, e) => { PutSetting(dbLevelFilterSave, newvalue); Display(); };

            List <string> modules = Recipes.EngineeringRecipes.SelectMany(r => r.modules).Distinct().ToList();

            modules.Sort();
            mfs = new RecipeFilterSelector(modules);
            mfs.SaveSettings += (newvalue, e) => { PutSetting(dbModFilterSave, newvalue); Display(); };

            var upgrades = Recipes.EngineeringRecipes.Select(r => r.Name).Distinct().ToList();

            upgrades.Sort();
            ufs = new RecipeFilterSelector(upgrades);
            ufs.SaveSettings += (newvalue, e) => { PutSetting(dbUpgradeFilterSave, newvalue); Display(); };

            List <string> matLongNames = Recipes.EngineeringRecipes.SelectMany(r => r.Ingredients).Select(x => x.Name).Distinct().ToList();

            matfs = new RecipeFilterSelector(matLongNames);
            matfs.SaveSettings += (newvalue, e) => { PutSetting(dbMaterialFilterSave, newvalue); Display(); };

            for (int rowno = 0; rowno < Recipes.EngineeringRecipes.Count; rowno++)         // pre-fill array.. preventing the crash on cell edit when you
            {
                int recipeno = RowToRecipe[rowno];
                Recipes.EngineeringRecipe r = Recipes.EngineeringRecipes[recipeno];

                int             rown = dataGridViewEngineering.Rows.Add();
                DataGridViewRow row  = dataGridViewEngineering.Rows[rown];
                row.Cells[UpgradeCol.Index].Value   = r.Name; // debug rno + ":" + r.name;
                row.Cells[ModuleCol.Index].Value    = r.modulesstring;
                row.Cells[LevelCol.Index].Value     = r.level;
                row.Cells[EngineersCol.Index].Value = r.engineersstring;
                row.Tag     = recipeno;
                row.Visible = false;
            }

            isHistoric = GetSetting(dbHistoricMatsSave, false);

            discoveryform.OnNewEntry      += Discoveryform_OnNewEntry;
            discoveryform.OnHistoryChange += Discoveryform_OnHistoryChange;

            BaseUtils.Translator.Instance.Translate(this);
            BaseUtils.Translator.Instance.Translate(toolTip, this);
        }
        // mcllist may be null, cursystem may be null as may crafts

        public void UpdateStatus(string status, ISystem cursystem, List <MaterialCommodityMicroResource> mcllist, List <HistoryEntry> crafts)
        {
            labelEngineerStatus.Text = status;
            string dist = "";

            if (cursystem != null && EngineerInfo != null)
            {
                var d = cursystem.Distance(EngineerInfo.X, EngineerInfo.Y, EngineerInfo.Z);
                dist = d.ToString("0.#") + " ly";
            }

            labelEngineerDistance.Text = dist;

            if (mcllist != null)                                           // may be null
            {
                var totals = MaterialCommoditiesRecipe.TotalList(mcllist); // start with totals present

                dataViewScrollerPanel.Suspend();
                dataGridViewEngineering.SuspendLayout();

                var wwmode = dataGridViewEngineering.DefaultCellStyle.WrapMode;
                dataGridViewEngineering.DefaultCellStyle.WrapMode = DataGridViewTriState.False;     // seems to make it a tad faster

                foreach (DataGridViewRow row in dataGridViewEngineering.Rows)
                {
                    row.Visible = true;     // if we hide stuff, we just make it invisible, we do not remove it

                    Recipes.EngineeringRecipe r = row.Tag as Recipes.EngineeringRecipe;

                    string tooltip    = "";
                    int    craftcount = 0;

                    foreach (var c in crafts.EmptyIfNull())     // all crafts
                    {
                        var cb = c.journalEntry as EliteDangerousCore.JournalEvents.JournalEngineerCraftBase;
                        if (cb != null)     // if an craft base type, check name and level
                        {
                            if (cb.Engineering.BlueprintName.Equals(r.fdname, StringComparison.InvariantCultureIgnoreCase) && cb.Engineering.Level == r.LevelInt)
                            {
                                tooltip = tooltip.AppendPrePad(c.EventTimeUTC.ToString() + " " + (c.ShipInformation?.Name ?? "?") + " " + (cb.Engineering.ExperimentalEffect_Localised ?? ""), Environment.NewLine);
                                craftcount++;
                            }
                        }
                        else if (c.EntryType == JournalTypeEnum.TechnologyBroker)       // if tech broker, check name
                        {
                            var tb = c.journalEntry as EliteDangerousCore.JournalEvents.JournalTechnologyBroker;
                            //string unl = string.Join(",", tb.ItemsUnlocked.Select(x=>x.Name));  System.Diagnostics.Debug.WriteLine($"{unl} {r.fdname}");
                            if (tb.ItemsUnlocked != null && Array.FindIndex(tb.ItemsUnlocked, x => x.Name.Equals(r.fdname, StringComparison.InvariantCultureIgnoreCase)) >= 0)
                            {
                                tooltip = tooltip.AppendPrePad(c.EventTimeUTC.ToString() + " " + (tb.BrokerType ?? "") + " " + string.Join(",", tb.ItemsUnlocked.Select(x => x.Name_Localised)));
                                craftcount++;
                            }
                        }
                    }

                    row.Cells[CraftedCol.Index].ToolTipText = tooltip;

                    var res = MaterialCommoditiesRecipe.HowManyLeft(mcllist, totals, r, WantedPerRecipe[row.Index], reducetotals: false);    // recipes not chained not in order

                    row.Cells[MaxCol.Index].Value         = res.Item1.ToString();
                    row.Cells[CraftedCol.Index].Value     = CraftedCol.HeaderText == "-" ? "" : craftcount.ToString();
                    row.Cells[PercentageCol.Index].Value  = res.Item5.ToString("N0");
                    row.Cells[NotesCol.Index].Value       = res.Item3;
                    row.Cells[NotesCol.Index].ToolTipText = res.Item4;
                    row.Cells[RecipeCol.Index].Value      = r.IngredientsStringvsCurrent(mcllist);
                    row.DefaultCellStyle.BackColor        = (res.Item5 >= 100.0) ? ExtendedControls.Theme.Current.GridHighlightBack : ExtendedControls.Theme.Current.GridCellBack;
                }

                dataGridViewEngineering.DefaultCellStyle.WrapMode = wwmode;
                dataGridViewEngineering.ResumeLayout();
                dataViewScrollerPanel.Resume();
            }

            labelCrafts.Text = crafts != null ? (crafts.Count + " crafts") : "";
        }