/// <summary> /// Handles the Click event of the showInBrowserMenuItem control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> private void showInBrowserMenuItem_Click(object sender, EventArgs e) { ToolStripItem menuItem = sender as ToolStripItem; if (menuItem == null) { return; } PlanetaryPin pin = lvPlanetary.SelectedItems[0]?.Tag as PlanetaryPin; // showInstallationInBrowserMenuItem if (menuItem == showInstallationInBrowserMenuItem) { if (pin?.TypeID == null) { return; } Item installation = StaticItems.GetItemByID(pin.TypeID); if (installation != null) { PlanWindow.ShowPlanWindow(Character).ShowItemInBrowser(installation); } return; } // showCommodityInBrowserMenuItem if (menuItem == showCommodityInBrowserMenuItem) { if (pin?.ContentTypeID == null) { return; } Item commmodity = StaticItems.GetItemByID(pin.ContentTypeID); if (commmodity != null) { PlanWindow.ShowPlanWindow(Character).ShowItemInBrowser(commmodity); } return; } if (pin?.Colony?.PlanetTypeID == null) { return; } Item planet = StaticItems.GetItemByID(pin.Colony.PlanetTypeID); if (planet != null) { PlanWindow.ShowPlanWindow(Character).ShowItemInBrowser(planet); } }
/// <summary> /// Updates the time to completion. /// </summary> private void UpdateTimeToCompletion() { const int Pad = 4; int columnTTCIndex = m_columns.IndexOf(m_columns.FirstOrDefault(x => x.Column == PlanetaryColumn.TTC)); foreach (ListViewItem listViewItem in lvPlanetary.Items.Cast <ListViewItem>()) { PlanetaryPin pin = (PlanetaryPin)listViewItem.Tag; if (pin.State != PlanetaryPinState.Extracting) { continue; } // Update the time to completion if (columnTTCIndex != -1 && m_columns[columnTTCIndex].Visible) { if (m_columnTTCDisplayIndex == -1) { m_columnTTCDisplayIndex = lvPlanetary.Columns[columnTTCIndex].DisplayIndex; } listViewItem.SubItems[m_columnTTCDisplayIndex].Text = pin.TTC; // Using AutoResizeColumn when TTC is the first column // results to a nasty visual bug due to ListViewItem.ImageIndex placeholder if (m_columnTTCDisplayIndex == 0) { // Calculate column header text width with padding int columnHeaderWidth = TextRenderer.MeasureText(lvPlanetary.Columns[m_columnTTCDisplayIndex].Text, Font).Width + Pad * 2; // If there is an image assigned to the header, add its width with padding if (ilIcons.ImageSize.Width > 0) { columnHeaderWidth += ilIcons.ImageSize.Width + Pad; } int columnWidth = lvPlanetary.Items.Cast <ListViewItem>().Select( item => TextRenderer.MeasureText(item.SubItems[m_columnTTCDisplayIndex].Text, Font).Width).Concat( new[] { columnHeaderWidth }).Max() + Pad + 2; lvPlanetary.Columns[m_columnTTCDisplayIndex].Width = columnWidth; } else { lvPlanetary.AutoResizeColumn(m_columnTTCDisplayIndex, ColumnHeaderAutoResizeStyle.HeaderSize); } } if (pin.TTC.Length != 0) { continue; } // Pin is idle pin.State = PlanetaryPinState.Idle; UpdateContent(); } }
/// <summary> /// Handles the Opening event of the contextMenu control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="CancelEventArgs"/> instance containing the event data.</param> private void contextMenu_Opening(object sender, CancelEventArgs e) { showInBrowserMenuItem.Visible = showInBrowserMenuSeparator.Visible = lvPlanetary.SelectedItems.Count != 0; PlanetaryPin pin = lvPlanetary.SelectedItems[0]?.Tag as PlanetaryPin; showCommodityInBrowserMenuItem.Visible = pin != null && pin.ContentTypeID != 0; }
/// <summary> /// Checks the given text matches the item. /// </summary> /// <param name="x">The x.</param> /// <param name="text">The text.</param> /// <returns> /// <c>true</c> if [is text matching] [the specified x]; otherwise, <c>false</c>. /// </returns> private static bool IsTextMatching(PlanetaryPin x, string text) => string.IsNullOrEmpty(text) || x.Colony.PlanetName.ToUpperInvariant().Contains(text) || x.Colony.PlanetTypeName.ToUpperInvariant().Contains(text) || x.Colony.PlanetTypeName.ToUpperInvariant().Contains(text) || x.Colony.SolarSystem.Name.ToUpperInvariant().Contains(text) || x.Colony.SolarSystem.Constellation.Name.ToUpperInvariant().Contains(text) || x.Colony.SolarSystem.Constellation.Region.Name.ToUpperInvariant().Contains(text) || x.TypeName.ToUpperInvariant().Contains(text) || x.ContentTypeName.ToUpperInvariant().Contains(text);
/// <summary> /// Creates the list view sub items. /// </summary> /// <param name="pin">The pin.</param> /// <param name="item">The item.</param> /// <returns></returns> private ListViewItem CreateSubItems(PlanetaryPin pin, ListViewItem item) { // Add enough subitems to match the number of columns while (item.SubItems.Count < lvPlanetary.Columns.Count + 1) { item.SubItems.Add(string.Empty); } // Creates the subitems for (int i = 0; i < lvPlanetary.Columns.Count; i++) { SetColumn(pin, item.SubItems[i], (PlanetaryColumn)lvPlanetary.Columns[i].Tag); } return(item); }
/// <summary> /// Gets the color of the state. /// </summary> /// <param name="pin">The pin.</param> /// <returns></returns> private static Color GetStateColor(PlanetaryPin pin) { switch (pin.State) { case PlanetaryPinState.Extracting: return(Color.Green); case PlanetaryPinState.Producing: return(Color.Orange); case PlanetaryPinState.Idle: return(Color.DarkRed); default: return(SystemColors.GrayText); } }
/// <summary> /// Updates the listview sub-item. /// </summary> /// <param name="pin">The pin.</param> /// <param name="item">The item.</param> /// <param name="column">The column.</param> /// <exception cref="System.NotImplementedException"></exception> private static void SetColumn(PlanetaryPin pin, ListViewItem.ListViewSubItem item, PlanetaryColumn column) { switch (column) { case PlanetaryColumn.State: item.Text = pin.State != PlanetaryPinState.None ? pin.State.GetDescription() : string.Empty; item.ForeColor = GetStateColor(pin); break; case PlanetaryColumn.TTC: item.Text = pin.TTC; break; case PlanetaryColumn.TypeName: item.Text = pin.TypeName; break; case PlanetaryColumn.ContentTypeName: item.Text = pin.ContentTypeName; break; case PlanetaryColumn.InstallTime: item.Text = pin.InstallTime == DateTime.MinValue ? string.Empty : $"{pin.InstallTime.ToLocalTime()}"; break; case PlanetaryColumn.EndTime: item.Text = pin.ExpiryTime == DateTime.MinValue ? string.Empty : $"{pin.ExpiryTime.ToLocalTime()}"; break; case PlanetaryColumn.PlanetName: item.Text = pin.Colony.PlanetName; break; case PlanetaryColumn.PlanetTypeName: item.Text = pin.Colony.PlanetTypeName; break; case PlanetaryColumn.SolarSystem: item.Text = pin.Colony.SolarSystem.Name; item.ForeColor = pin.Colony.SolarSystem.SecurityLevelColor; break; case PlanetaryColumn.Location: item.Text = pin.Colony.FullLocation; break; case PlanetaryColumn.Region: item.Text = pin.Colony.SolarSystem.Constellation.Region.Name; break; case PlanetaryColumn.Quantity: item.Text = pin.ContentQuantity.ToNumericString(2); break; case PlanetaryColumn.QuantityPerCycle: item.Text = pin.QuantityPerCycle.ToNumericString(2); break; case PlanetaryColumn.CycleTime: item.Text = $"{pin.CycleTime}"; break; case PlanetaryColumn.Volume: item.Text = pin.ContentVolume.ToNumericString(2); break; case PlanetaryColumn.LinkedTo: item.Text = string.Join(", ", pin.LinkedTo.Select(x => x.TypeName).Distinct()); break; case PlanetaryColumn.RoutedTo: item.Text = string.Join(", ", pin.RoutedTo.Select(x => x.TypeName).Distinct()); break; case PlanetaryColumn.GroupName: item.Text = pin.GroupName; break; default: throw new NotImplementedException(); } }