Beispiel #1
0
        /// <summary>
        /// Occurs when we downloaded a loadouts feed from Battleclinic
        /// </summary>
        /// <param name="feed"></param>
        /// <param name="errorMessage"></param>
        /// <returns></returns>
        private void OnLoadoutFeedDownloaded(SerializableLoadoutFeed feed, string errorMessage)
        {
            if (this.IsDisposed)
            {
                return;
            }

            // Restore the default cursor instead of the waiting one
            Cursor.Current    = Cursors.Default;
            m_selectedLoadout = null;
            btnLoad.Enabled   = false;
            btnPlan.Enabled   = false;

            // Was there an error ?
            if (!String.IsNullOrEmpty(errorMessage))
            {
                lblShip.Text = "There was a problem connecting to Battleclinic, it may be down for maintainance.\r\n" + errorMessage;
                return;
            }

            // Are there no feeds ?
            if (feed.Race == null || feed.Race.Loadouts.Length == 0)
            {
                lblShip.Text = "There are no loadouts for " + m_ship.Name + ", why not submit one to Battleclinic?";
                return;
            }

            // Add the listview items for every loadout
            lvLoadouts.Items.Clear();
            foreach (SerializableLoadout loadout in feed.Race.Loadouts)
            {
                ListViewItem lvi = new ListViewItem(loadout.LoadoutName);
                lvi.Text = loadout.LoadoutName;
                lvi.SubItems.Add(loadout.Author);
                lvi.SubItems.Add(loadout.rating.ToString());
                lvi.SubItems.Add(loadout.SubmissionDateString);
                lvi.Tag = loadout;
                lvLoadouts.Items.Add(lvi);
            }

            // Update the header
            lblShip.Text = "Found " + lvLoadouts.Items.Count.ToString() + " loadouts";

            // Update the listview's comparer and sort
            lvLoadouts.Sort();

            // Enable the "load" button
            btnLoad.Enabled = true;
        }
Beispiel #2
0
            public int Compare(object x, object y)
            {
                int          compareResult = 0;
                ListViewItem a             = (ListViewItem)x;
                ListViewItem b             = (ListViewItem)y;

                if (m_sortOrder == SortOrder.Descending)
                {
                    ListViewItem tmp = b;
                    b = a;
                    a = tmp;
                }

                SerializableLoadout sla = a.Tag as SerializableLoadout;
                SerializableLoadout slb = b.Tag as SerializableLoadout;

                switch (m_sortColumn)
                {
                case 0:     // sort by name
                    compareResult = String.Compare(a.Text, b.Text);
                    break;

                case 1:     // Author
                    compareResult = String.Compare(a.SubItems[1].Text, b.SubItems[1].Text);
                    break;

                case 2:      // Rating
                    if (sla.rating < slb.rating)
                    {
                        compareResult = -1;
                    }
                    else if (sla.rating > slb.rating)
                    {
                        compareResult = 1;
                    }
                    else
                    {
                        compareResult = 0;
                    }
                    break;

                case 3:      // Date
                    compareResult = sla.SubmissionDate.CompareTo(slb.SubmissionDate);
                    break;
                }

                return(compareResult);
            }
        /// <summary>
        /// Downloads the given loadout
        /// </summary>
        /// <param name="loadout"></param>
        private void DownloadLoadout(SerializableLoadout loadout)
        {
            // See the cursor to wait
            Cursor.Current = Cursors.WaitCursor;

            // Retrieve the selected loadout
            m_selectedLoadout = loadout;

            // Set the headings
            lblLoadoutName.Text = m_selectedLoadout.LoadoutName;
            lblAuthor.Text      = m_selectedLoadout.Author;
            lblSubmitDate.Text  = m_selectedLoadout.SubmissionDate.ToString();

            // Download the loadout details
            string url = String.Format(CultureConstants.DefaultCulture, NetworkConstants.BattleclinicLoadoutDetails, m_selectedLoadout.LoadoutId.ToString());

            Util.DownloadXMLAsync <SerializableLoadoutFeed>(url, null, OnLoadoutDownloaded);
        }
Beispiel #4
0
 /// <summary>
 /// When the user clicks cancel, we quit
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnCancel_Click(object sender, EventArgs e)
 {
     m_selectedLoadout = null;
     this.DialogResult = DialogResult.Cancel;
     this.Close();
 }