/// <summary> /// Updates the given ChokePoint's Expando. /// </summary> /// <param name="cp">The ChokePoint to update.</param> private void UpdateChokePoint(ChokePoint cp) { Expando expando = expandos[cp]; CAControls controls = (CAControls)expando.Tag; // update title image expando.TitleImage = cp.FlagImage; // update attack objective/activity level icon Image icon; if (cp.HasAO) { icon = new Bitmap(45, 18); // 21x18 + 20x18 Graphics g = Graphics.FromImage(icon); g.DrawImage(Resources.attack_objective, 0, 0, 21, 18); g.DrawImage(cp.ActivityImage, icon.Width - 20, 0, 20, 18); g.Dispose(); } else { icon = cp.ActivityImage; } expando.CustomHeaderSettings.NormalArrowUp = expando.CustomHeaderSettings.NormalArrowDown = expando.CustomHeaderSettings.NormalArrowUpHot = expando.CustomHeaderSettings.NormalArrowDownHot = icon; // capbar controls.picCapBar.Image = GenerateMiniCapBar(cp); // remember scroll position int prevFirstDisplayedIndex = controls.dgvEventList.FirstDisplayedScrollingRowIndex; if (controls.dgvEventList.Rows.Count > 0 && prevFirstDisplayedIndex >= controls.dgvEventList.Rows.Count - 5) // at bottom, preserve { prevFirstDisplayedIndex = int.MaxValue; } // clear list controls.dgvEventList.Rows.Clear(); // loop over event list (forwards or backwards) for (int i = (this.eventSortOrder == SortOrder.Ascending ? 0 : game.Events.List.Count - 1); i >= 0 && i < game.Events.List.Count; i += (this.eventSortOrder == SortOrder.Ascending ? 1 : -1)) { GameEvent gameEvent = game.Events.List[i]; if (!gameEvent.ChokePoints.Contains(cp)) { continue; // not associated with our chokepoint } if (gameEvent.Type == GameEventType.Factory) { continue; // don't include factory events here } // create & add entry w/ timestamp string entry = String.Format("{0} {1}", Misc.Timestamp(gameEvent.EventTime), gameEvent.Description); int idx = controls.dgvEventList.Rows.Add(gameEvent.Icon, entry); controls.dgvEventList.Rows[idx].Tag = gameEvent; // tooltip string tooltip = String.Format(Language.Time_MinsAgo, Misc.MinsAgoLong(gameEvent.EventTime)); int minsDiff = (int)(gameEvent.EventReceived - gameEvent.EventTime).TotalMinutes; if (minsDiff > 5) // received over 5 mins after the event occurred { tooltip += " (" + String.Format(Language.Time_ReceivedMinsAgo, Misc.MinsAgoLong(gameEvent.EventReceived)) + ")"; } controls.dgvEventList[1, idx].ToolTipText = tooltip; // if special event, make bold if (gameEvent is ChokePointCapturedGameEvent || (gameEvent is ChokePointUnderAttackGameEvent && ((ChokePointUnderAttackGameEvent)gameEvent).NewAttack)) { controls.dgvEventList[1, idx].Style.Font = new Font(controls.dgvEventList[1, idx].InheritedStyle.Font, FontStyle.Bold); } } if (expando.ExpandedHeight > EXPANDO_DEFAULT_HEIGHT) // expanded, update height { SetListExpanded(expando, true); } else // restore scroll position { if (controls.dgvEventList.Rows.Count > 0) { if (prevFirstDisplayedIndex >= 0 && prevFirstDisplayedIndex < controls.dgvEventList.Rows.Count) // valid previous value { controls.dgvEventList.FirstDisplayedScrollingRowIndex = prevFirstDisplayedIndex; } else if (prevFirstDisplayedIndex == int.MaxValue) // stay at end { controls.dgvEventList.FirstDisplayedScrollingRowIndex = controls.dgvEventList.Rows.Count - 1; } else // default: newest end { controls.dgvEventList.FirstDisplayedScrollingRowIndex = this.eventSortOrder == SortOrder.Ascending ? controls.dgvEventList.Rows.Count - 1 : 0; } } } // set enabled/disabled status if changed if (controls.dgvEventList.Rows.Count > 0) // has events { if (!expando.CanCollapse) // currently disabled, enable { expando.CustomHeaderSettings.NormalTitleColor = Color.FromArgb(224, 224, 224); expando.CustomHeaderSettings.NormalGradientEndColor = Color.FromArgb(51, 51, 51); expando.CustomHeaderSettings.NormalGradientStartColor = Color.FromArgb(51, 51, 51); expando.CanCollapse = true; expando.Collapsed = false; // animate GameStatus.ToolTip.SetToolTip(expando, null); } } else // doesn't have events { if (expando.CanCollapse) // currently enabled, disable { expando.CustomHeaderSettings.NormalTitleColor = Color.Gray; expando.CustomHeaderSettings.NormalGradientEndColor = Color.FromArgb(30, 30, 30); expando.CustomHeaderSettings.NormalGradientStartColor = Color.FromArgb(30, 30, 30); expando.Collapse(); // no animation expando.CanCollapse = false; GameStatus.ToolTip.SetToolTip(expando, String.Format(Language.CurrentAttacks_Tooltip_NoEvents, cp)); } } }
/// <summary> /// Create a new Expando control with the appropriate settings and sub-controls, based on the given ChokePoint. /// </summary> /// <param name="cp">The ChokePoint the Expando will represent.</param> /// <returns>The new Expando control</returns> private Expando CreateExpando(ChokePoint cp) { // control container CAControls controls = new CAControls(); // expando Expando expando = new Expando(); expando.Animate = true; expando.Collapse(); expando.CustomHeaderSettings.BackImageHeight = 25; expando.CustomHeaderSettings.NormalGradientEndColor = Color.FromArgb(51, 51, 51); expando.CustomHeaderSettings.NormalGradientStartColor = Color.FromArgb(51, 51, 51); expando.CustomHeaderSettings.NormalTitleColor = Color.FromArgb(224, 224, 224); expando.CustomHeaderSettings.NormalTitleHotColor = Color.White; expando.CustomHeaderSettings.TitleFont = new Font("Arial", 9F, FontStyle.Bold, GraphicsUnit.Point, 0); expando.CustomHeaderSettings.TitleGradient = true; expando.CustomHeaderSettings.TitleRadius = 0; expando.CustomSettings.NormalBackColor = Color.Black; expando.CustomSettings.NormalBorderColor = Color.Black; expando.ExpandedHeight = EXPANDO_DEFAULT_HEIGHT; expando.Text = cp.Name; // event datagridview controls.dgvEventList = new DataGridView(); controls.dgvEventList.AllowUserToAddRows = false; controls.dgvEventList.AllowUserToDeleteRows = false; controls.dgvEventList.AllowUserToResizeColumns = false; controls.dgvEventList.AllowUserToResizeRows = false; controls.dgvEventList.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells; controls.dgvEventList.BackgroundColor = Color.Black; controls.dgvEventList.BorderStyle = BorderStyle.None; controls.dgvEventList.CellBorderStyle = DataGridViewCellBorderStyle.SingleHorizontal; controls.dgvEventList.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithoutHeaderText; controls.dgvEventList.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; controls.dgvEventList.ColumnHeadersVisible = false; DataGridViewCellStyle cellStyle1 = new DataGridViewCellStyle(); cellStyle1.Alignment = DataGridViewContentAlignment.MiddleLeft; cellStyle1.BackColor = Color.Black; cellStyle1.Font = new Font("Microsoft Sans Serif", 8.25F, FontStyle.Regular, GraphicsUnit.Point, 0); cellStyle1.ForeColor = Color.FromArgb(224, 224, 224); cellStyle1.SelectionBackColor = Color.Black; cellStyle1.SelectionForeColor = Color.FromArgb(224, 224, 224); cellStyle1.WrapMode = DataGridViewTriState.False; controls.dgvEventList.DefaultCellStyle = cellStyle1; controls.dgvEventList.GridColor = Color.FromArgb(64, 64, 64); controls.dgvEventList.Location = new Point(3, 21 + 16); // 21 = header controls.dgvEventList.MultiSelect = false; controls.dgvEventList.RowHeadersVisible = false; controls.dgvEventList.ScrollBars = ScrollBars.Vertical; controls.dgvEventList.SelectionMode = DataGridViewSelectionMode.FullRowSelect; controls.dgvEventList.Size = new Size(330, 128); controls.dgvEventList.StandardTab = true; controls.dgvEventList.DataError += (sender, args) => { }; //// avoid default DataError dialog DataGridViewImageColumn imagecol = new DataGridViewImageColumn(); imagecol.AutoSizeMode = DataGridViewAutoSizeColumnMode.None; DataGridViewCellStyle cellStyle2 = new DataGridViewCellStyle(); cellStyle2.Alignment = DataGridViewContentAlignment.TopLeft; cellStyle2.Padding = new System.Windows.Forms.Padding(0, 2, 0, 0); imagecol.DefaultCellStyle = cellStyle2; imagecol.ImageLayout = DataGridViewImageCellLayout.Zoom; imagecol.ReadOnly = true; imagecol.Resizable = DataGridViewTriState.False; imagecol.Width = 20; controls.dgvEventList.Columns.Add(imagecol); DataGridViewTextBoxColumn textcol = new DataGridViewTextBoxColumn(); textcol.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; DataGridViewCellStyle cellStyle3 = new DataGridViewCellStyle(); cellStyle3.Padding = new System.Windows.Forms.Padding(0, 0, 0, 2); cellStyle3.WrapMode = DataGridViewTriState.True; textcol.DefaultCellStyle = cellStyle3; textcol.ReadOnly = true; textcol.Resizable = DataGridViewTriState.False; textcol.SortMode = DataGridViewColumnSortMode.NotSortable; controls.dgvEventList.Columns.Add(textcol); // focus on mouse enter expando.MouseEnter += delegate { BegmMisc.FocusWithoutScroll(controls.dgvEventList); }; controls.dgvEventList.MouseEnter += delegate { BegmMisc.FocusWithoutScroll(controls.dgvEventList); }; // don't draw focus rectangle controls.dgvEventList.RowPrePaint += delegate(object sender, DataGridViewRowPrePaintEventArgs e) { e.PaintParts &= ~DataGridViewPaintParts.Focus; }; // reveal other widgets on double click controls.dgvEventList.CellDoubleClick += dgvEventList_CellDoubleClick; expando.Items.Add(controls.dgvEventList); // event checkbox controls.cbShowAlerts = new CheckBox(); controls.cbShowAlerts.AutoSize = true; controls.cbShowAlerts.Text = Language.CurrentAttacks_ShowAlerts; if (Application.RenderWithVisualStyles) { controls.cbShowAlerts.Location = new Point(2, 21 + 2); } else { controls.cbShowAlerts.Location = new Point(2, 21 + 4); } if (options.Alerts.filterChokePoint == false || // not filtering, or options.Alerts.filterChokePointIDs.Contains(cp.ID)) // filtering and includes this cp { controls.cbShowAlerts.Checked = true; } controls.cbShowAlerts.Click += delegate { cbShowAlerts_Click(controls.cbShowAlerts, cp); }; expando.Controls.Add(controls.cbShowAlerts); // capbar controls.picCapBar = new PictureBox(); controls.picCapBar.Location = new Point(104, 21 + 2); controls.picCapBar.Size = new Size(130, 12); expando.Controls.Add(controls.picCapBar); // expand button controls.picExpandTown = new PictureBox(); controls.picExpandTown.Cursor = Cursors.Hand; controls.picExpandTown.Image = Resources.icon_down; if (Application.RenderWithVisualStyles) { controls.picExpandTown.Location = new Point(324, 21 + 5); } else { controls.picExpandTown.Location = new Point(324, 21 + 7); } controls.picExpandTown.SizeMode = PictureBoxSizeMode.AutoSize; controls.picExpandTown.MouseClick += delegate(object obj, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { picExpandTown_Click(expando); } }; expando.Controls.Add(controls.picExpandTown); // town status link LinkLabel link = new LinkLabel(); link.ActiveLinkColor = Color.White; link.LinkBehavior = LinkBehavior.HoverUnderline; link.LinkColor = Color.FromArgb(224, 224, 224); link.Text = Language.CurrentAttacks_TownStatus; link.TextAlign = ContentAlignment.TopRight; link.Size = new Size(90, 13); link.VisitedLinkColor = Color.FromArgb(224, 224, 224); if (Application.RenderWithVisualStyles) { link.Location = new Point(235, 21 + 1); } else { link.Location = new Point(235, 21 + 2); } link.LinkClicked += delegate { GameStatus_RevealWidget(WidgetType.TownStatus, cp); }; expando.Controls.Add(link); // store controls for future reference expando.Tag = controls; return(expando); }