Exemplo n.º 1
0
        public void SendShipInfo(ShipInformation si, MaterialCommoditiesList matcommod, int cargo, ShipInformation sicurrent, long cash, long loan,
                                 JournalProgress progress, JournalRank rank     // both may be null
                                 )
        {
            lock (LockShipInfo)               // lets not double send in different threads.
            {
                if (!si.Equals(LastShipInfo)) // if we are sending new ship info..
                {
                    System.Diagnostics.Debug.WriteLine("Update EDSM with ship info" + si.ID + " " + si.ShipType + " " + cargo);
                    CommanderUpdateShip(si.ID, si.ShipType.Alt("Unknown"), si, cargo);
                    LastShipInfo = si;
                }

                if (LastShipID != sicurrent.ID) // if we have a new current ship
                {
                    System.Diagnostics.Debug.WriteLine("Update EDSM with current ship" + sicurrent.ID);
                    CommanderSetCurrentShip(sicurrent.ID);
                    LastShipID = sicurrent.ID;
                }

                if (LastEDSMCredits != cash)    // if our cash has changed..
                {
                    System.Diagnostics.Debug.WriteLine("Update EDSM with credits" + cash);
                    SetCredits(cash, loan);
                    LastEDSMCredits = cash;
                }

                if (progress != null && rank != null && (!Object.ReferenceEquals(progress, LastProgress) || !Object.ReferenceEquals(rank, LastRank)))
                {
                    System.Diagnostics.Debug.WriteLine("Update EDSM with ranks");
                    SetRanks((int)rank.Combat, progress.Combat, (int)rank.Trade, progress.Trade, (int)rank.Explore, progress.Explore, (int)rank.CQC, progress.CQC, (int)rank.Federation, progress.Federation, (int)rank.Empire, progress.Empire);
                    LastProgress = progress;
                    LastRank     = rank;
                }

                if (matcommod != null && matcommod != LastMats)
                {
                    System.Diagnostics.Debug.WriteLine("Update EDSM with materials and cargo");
                    List <MaterialCommodities> lmats  = matcommod.Sort(false);
                    List <MaterialCommodities> lcargo = matcommod.Sort(true);
                    List <MaterialCommodities> ldata  = lmats.Where(m => m.category == MaterialCommodities.MaterialEncodedCategory).ToList();
                    lmats = lmats.Where(m => m.category != MaterialCommodities.MaterialEncodedCategory).ToList();
                    SetInventoryMaterials(lmats.Where(m => m.count > 0).ToDictionary(m => m.fdname, m => m.count));
                    SetInventoryData(ldata.Where(m => m.count > 0).ToDictionary(m => m.fdname, m => m.count));
                    SetInventoryCargo(lcargo.Where(m => m.count > 0).ToDictionary(m => m.fdname, m => m.count));
                    LastMats = matcommod;
                }
            }
        }
        private void Display(MaterialCommoditiesList mcl)
        {
            dataGridViewMC.Rows.Clear();
            textBoxItems1.Text = textBoxItems2.Text = "";

            if (mcl == null)
            {
                return;
            }

            System.Diagnostics.Trace.WriteLine(BaseUtils.AppTicks.TickCountLap(this, true) + " MC " + displaynumber + " Begin Display");

            List <MaterialCommodities> mc = mcl.Sort(!materials);

            if (mc.Count > 0)
            {
                labelNoItems.Visible = false;

                foreach (MaterialCommodities m in mc)
                {
                    object[] rowobj;

                    if (materials)
                    {
                        rowobj = new[] { m.Details.Name, m.Details.Shortname, m.Details.TranslatedCategory, m.Details.TranslatedType + " (" + (m.Details.MaterialLimit() ?? 0).ToString() + ")",
                                         m.Count.ToString() };
                    }
                    else
                    {
                        rowobj = new[] { m.Details.Name, m.Details.TranslatedType, m.Count.ToString(), m.Price.ToString("0.#") };
                    }

                    int idx = dataGridViewMC.Rows.Add(rowobj);
                    //dataGridViewMC.Rows[idx].Tag = m;
                }

                if (dataGridViewMC.SortedColumn != null && dataGridViewMC.SortOrder != SortOrder.None)
                {
                    dataGridViewMC.Sort(dataGridViewMC.SortedColumn, dataGridViewMC.SortOrder == SortOrder.Descending ? ListSortDirection.Descending : ListSortDirection.Ascending);
                }

                if (materials)
                {
                    textBoxItems1.Text = mcl.DataCount.ToStringInvariant();
                    textBoxItems2.Text = mcl.MaterialsCount.ToStringInvariant();
                }
                else
                {
                    textBoxItems1.Text = mcl.CargoCount.ToStringInvariant();
                }
            }
            else
            {
                labelNoItems.Visible = true;
            }

            System.Diagnostics.Trace.WriteLine(BaseUtils.AppTicks.TickCountLap(this) + " MC " + displaynumber + " Load Finished");
        }
        private void Display(MaterialCommoditiesList mcl)
        {
            dataGridViewMC.Rows.Clear();
            textBoxItems1.Text = textBoxItems2.Text = "";

            if (mcl == null)
            {
                return;
            }

            List <MaterialCommodities> mc = mcl.Sort(!materials);

            if (mc.Count > 0)
            {
                labelNoItems.Visible = false;

                foreach (MaterialCommodities m in mc)
                {
                    object[] rowobj;

                    if (materials)
                    {
                        rowobj = new[] { m.name, m.shortname, m.category, m.type, $"{m.count.ToString()}/{(MaterialCommodityDB.MaterialLimit(m.type)??0).ToString()}" };
                    }
                    else
                    {
                        rowobj = new[] { m.name, m.type, m.count.ToString(), m.price.ToString("0.#") };
                    }

                    int idx = dataGridViewMC.Rows.Add(rowobj);
                    //dataGridViewMC.Rows[idx].Tag = m;
                }

                if (dataGridViewMC.SortedColumn != null && dataGridViewMC.SortOrder != SortOrder.None)
                {
                    dataGridViewMC.Sort(dataGridViewMC.SortedColumn, dataGridViewMC.SortOrder == SortOrder.Descending ? ListSortDirection.Descending : ListSortDirection.Ascending);
                }

                if (materials)
                {
                    textBoxItems1.Text = mcl.DataCount.ToStringInvariant();
                    textBoxItems2.Text = mcl.MaterialsCount.ToStringInvariant();
                }
                else
                {
                    textBoxItems1.Text = mcl.CargoCount.ToStringInvariant();
                }
            }
            else
            {
                labelNoItems.Visible = true;
            }
        }
Exemplo n.º 4
0
        public override bool ExecuteAction(ActionProgramRun ap)
        {
            string res;

            if (ap.functions.ExpandString(UserData, out res) != BaseUtils.Functions.ExpandResult.Failed)
            {
                StringParser sp = new StringParser(res);

                string prefix  = (commodities) ? "C_" : "M_";
                string cmdname = sp.NextWord();

                if (cmdname != null && cmdname.Equals("PREFIX", StringComparison.InvariantCultureIgnoreCase))
                {
                    prefix = sp.NextWord();

                    if (prefix == null)
                    {
                        ap.ReportError("Missing name after Prefix in Materials/Commodity");
                        return(true);
                    }

                    cmdname = sp.NextWord();
                }

                if (cmdname != null)
                {
                    long jid;
                    if (!cmdname.InvariantParse(out jid))
                    {
                        ap.ReportError("Non integer JID in Materials/Commodity");
                        return(true);
                    }

                    int jidindex = (ap.actioncontroller as ActionController).HistoryList.EntryOrder().FindIndex(x => x.Journalid == jid);

                    if (jidindex == -1)
                    {
                        ap.ReportError("JID does not exist in Materials/Commodity");
                        return(true);
                    }

                    MaterialCommoditiesList    mcl  = (ap.actioncontroller as ActionController).HistoryList.EntryOrder()[jidindex].MaterialCommodity;
                    List <MaterialCommodities> list = mcl.Sort(commodities);

                    ap[prefix + "Count"]   = list.Count.ToString(System.Globalization.CultureInfo.InvariantCulture);
                    ap[prefix + "IndexOf"] = (ap.actioncontroller as ActionController).HistoryList.EntryOrder()[jidindex].Indexno.ToString(System.Globalization.CultureInfo.InvariantCulture);

                    for (int i = 0; i < list.Count; i++)
                    {
                        string postfix = (i + 1).ToString(System.Globalization.CultureInfo.InvariantCulture);
                        ap[prefix + "Name" + postfix]      = list[i].Details.Name;
                        ap[prefix + "Category" + postfix]  = list[i].Details.Category.ToString();
                        ap[prefix + "fdname" + postfix]    = list[i].Details.FDName;
                        ap[prefix + "type" + postfix]      = list[i].Details.Type.ToString().SplitCapsWord();
                        ap[prefix + "shortname" + postfix] = list[i].Details.Shortname;
                    }
                }
                else
                {
                    ap.ReportError("Missing JID in Materials");
                }
            }
            else
            {
                ap.ReportError(res);
            }

            return(true);
        }