From 448918713d66e3a85cf7b24fa5f4fd7900222793 Mon Sep 17 00:00:00 2001 From: Deantwo Date: Sun, 22 Jun 2014 14:37:44 +0200 Subject: [PATCH] Character Filter - Made a simple character filter dropdown box - Minor change to hopefully make scanning mails a little faster --- HObj.cs | 10 +++++++ Main.Designer.cs | 16 +++++++++++ Main.cs | 71 +++++++++++++++++++++++++++++++++++++++++------- Main.resx | 22 +++++++-------- 4 files changed, 98 insertions(+), 21 deletions(-) diff --git a/HObj.cs b/HObj.cs index 75df5fc..f582a02 100644 --- a/HObj.cs +++ b/HObj.cs @@ -40,12 +40,22 @@ public byte AttentionCode get { return _attentionCode; } } + protected List _owners = new List(); + public List Onwers + { + get { return _owners; } + } + public virtual void Update(HMail mail) { _name = mail.From; // Incase sender changed name. _lastUpdated = mail.DateTime; _attentionCode = 0x00; // 0b00000000 + string tempOwner = HHelper.ToID(mail.RecipientID); + if (!_owners.Contains(tempOwner)) + _owners.Add(tempOwner); // Wish I could get the name of the empire instead!!! + // Full body test, mostly used for debuging. _body = mail.Body; } diff --git a/Main.Designer.cs b/Main.Designer.cs index 8572c50..a240730 100644 --- a/Main.Designer.cs +++ b/Main.Designer.cs @@ -78,6 +78,7 @@ private void InitializeComponent() this.ColumnOfficerDate = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.tbxOfficer = new System.Windows.Forms.TextBox(); this.toolTip1 = new System.Windows.Forms.ToolTip(this.components); + this.cmbCharFilter = new System.Windows.Forms.ComboBox(); this.statusStrip1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.splitContainerShip)).BeginInit(); this.splitContainerShip.Panel1.SuspendLayout(); @@ -649,11 +650,25 @@ private void InitializeComponent() this.tbxOfficer.TabIndex = 0; this.tbxOfficer.WordWrap = false; // + // cmbCharFilter + // + this.cmbCharFilter.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.cmbCharFilter.Enabled = false; + this.cmbCharFilter.FormattingEnabled = true; + this.cmbCharFilter.Items.AddRange(new object[] { + "Show all"}); + this.cmbCharFilter.Location = new System.Drawing.Point(93, 14); + this.cmbCharFilter.Name = "cmbCharFilter"; + this.cmbCharFilter.Size = new System.Drawing.Size(121, 21); + this.cmbCharFilter.TabIndex = 3; + this.cmbCharFilter.SelectedIndexChanged += new System.EventHandler(this.cmbCharFilter_SelectedIndexChanged); + // // Main // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(790, 508); + this.Controls.Add(this.cmbCharFilter); this.Controls.Add(this.tabControlMain); this.Controls.Add(this.statusStrip1); this.Controls.Add(this.button1); @@ -746,6 +761,7 @@ private void InitializeComponent() private System.Windows.Forms.ToolTip toolTip1; private System.Windows.Forms.SplitContainer splitContainerCityStatistics; private System.Windows.Forms.Panel pCityStatisticsMorale; + private System.Windows.Forms.ComboBox cmbCharFilter; } } diff --git a/Main.cs b/Main.cs index e8cc120..ef79a52 100644 --- a/Main.cs +++ b/Main.cs @@ -17,6 +17,8 @@ public partial class Main : Form List hShipList = new List(); List hOfficerList = new List(); + List charIdList = new List(); + Image imageCity; Image imageShip; Image imageOfficer; @@ -36,7 +38,8 @@ public Main() imageShip = HazeronAdviser.Properties.Resources.GovSpacecraft; imageOfficer = HazeronAdviser.Properties.Resources.Officer; dgvCity.Columns["ColumnCityAbandonment"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight; - dgvCity.Columns["ColumnCityAbandonment"].DefaultCellStyle.Font = new Font("Lucida Console", 9); + dgvCity.Columns["ColumnCityAbandonment"].DefaultCellStyle.Font = new Font("Lucida Console", 9); + cmbCharFilter.SelectedIndex = 0; } private void button1_Click(object sender, EventArgs e) @@ -51,6 +54,10 @@ private void button1_Click(object sender, EventArgs e) return; } string[] fileList = Directory.GetFiles(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Shores of Hazeron", "Mail")); // %USERPROFILE%\Shores of Hazeron\Mail + cmbCharFilter.Enabled = false; + cmbCharFilter.Items.Clear(); + cmbCharFilter.Items.Add("Show all"); + cmbCharFilter.SelectedIndex = 0; toolStripProgressBar1.Value = 0; toolStripProgressBar1.Maximum = fileList.Length; toolStripProgressBar1.Visible = true; @@ -66,6 +73,7 @@ private void button1_Click(object sender, EventArgs e) tbxCity.Clear(); tbxShip.Clear(); tbxOfficer.Clear(); + #region Scan HMails foreach (string file in fileList) { if (HMail.IsUni4(file)) // Check if signature is 0x2110 before trying to read it. @@ -74,30 +82,33 @@ private void button1_Click(object sender, EventArgs e) try { #endif - if (HMail.IsCityReport(file)) + HMail mail = new HMail(file); + if (HMail.IsCityReport(mail)) { - HCity temp = new HCity(new HMail(file)); + HCity temp = new HCity(mail); if (hCityList.Any(city => city.ID == temp.ID)) - hCityList[hCityList.FindIndex(city => city.ID == temp.ID)].Update(new HMail(file)); + hCityList[hCityList.FindIndex(city => city.ID == temp.ID)].Update(mail); else hCityList.Add(temp); } - else if (HMail.IsShipLog(file)) + else if (HMail.IsShipLog(mail)) { - HShip temp = new HShip(new HMail(file)); + HShip temp = new HShip(mail); if (hShipList.Any(ship => ship.ID == temp.ID)) - hShipList[hShipList.FindIndex(ship => ship.ID == temp.ID)].Update(new HMail(file)); + hShipList[hShipList.FindIndex(ship => ship.ID == temp.ID)].Update(mail); else hShipList.Add(temp); } - else if (HMail.IsOfficerTenFour(file)) + else if (HMail.IsOfficerTenFour(mail)) { - HOfficer temp = new HOfficer(new HMail(file)); + HOfficer temp = new HOfficer(mail); if (hOfficerList.Any(officer => officer.ID == temp.ID)) - hOfficerList[hOfficerList.FindIndex(ship => ship.ID == temp.ID)].Update(new HMail(file)); + hOfficerList[hOfficerList.FindIndex(ship => ship.ID == temp.ID)].Update(mail); else hOfficerList.Add(temp); } + if (!charIdList.Contains(HHelper.ToID(mail.RecipientID))) + charIdList.Add(HHelper.ToID(mail.RecipientID)); toolStripProgressBar1.Increment(1); #if RELEASE } @@ -113,6 +124,7 @@ private void button1_Click(object sender, EventArgs e) #endif } } + #endregion toolStripProgressBar2.Value = 0; toolStripProgressBar2.Maximum = hCityList.Count + hShipList.Count + hOfficerList.Count; toolStripProgressBar2.Visible = true; @@ -230,8 +242,14 @@ private void button1_Click(object sender, EventArgs e) toolStripProgressBar2.Increment(1); } #endregion + foreach (string charId in charIdList) + cmbCharFilter.Items.Add(charId); + cmbCharFilter.Enabled = true; toolStripProgressBar1.Visible = false; toolStripProgressBar2.Visible = false; + dgvCity.ClearSelection(); + dgvShip.ClearSelection(); + dgvOfficer.ClearSelection(); toolStripStatusLabel1.Text = "Done!"; } @@ -263,6 +281,39 @@ private void dgvOfficer_SelectionChanged(object sender, EventArgs e) } #endregion + private void cmbCharFilter_SelectedIndexChanged(object sender, EventArgs e) + { + if (cmbCharFilter.Enabled) + { + if (cmbCharFilter.SelectedIndex == 0) + { + foreach (DataGridViewRow row in dgvCity.Rows) + row.Visible = true; + foreach (DataGridViewRow row in dgvShip.Rows) + row.Visible = true; + foreach (DataGridViewRow row in dgvOfficer.Rows) + row.Visible = true; + } + else + { + foreach (DataGridViewRow row in dgvCity.Rows) + row.Visible = hCityList[(int)row.Cells["ColumnCityIndex"].Value].Onwers.Contains(charIdList[cmbCharFilter.SelectedIndex - 1]); + foreach (DataGridViewRow row in dgvShip.Rows) + row.Visible = hShipList[(int)row.Cells["ColumnShipIndex"].Value].Onwers.Contains(charIdList[cmbCharFilter.SelectedIndex - 1]); + foreach (DataGridViewRow row in dgvOfficer.Rows) + row.Visible = hOfficerList[(int)row.Cells["ColumnOfficerIndex"].Value].Onwers.Contains(charIdList[cmbCharFilter.SelectedIndex - 1]); + } + dgvCity.ClearSelection(); + dgvShip.ClearSelection(); + dgvOfficer.ClearSelection(); + tbxCity.Clear(); + tbxShip.Clear(); + tbxOfficer.Clear(); + pCityStatisticsPop.Refresh(); + pCityStatisticsMorale.Refresh(); + } + } + #region Statistics Graphics private void pCityStatistics_Paint(object sender, PaintEventArgs e) // gCityStatisticsPop { diff --git a/Main.resx b/Main.resx index ff65e60..8af79b5 100644 --- a/Main.resx +++ b/Main.resx @@ -189,17 +189,6 @@ True - - 133, 17 - - - Yellow - Loyal Citizens (often hidden under Population) -Orange - Disloyal Citizens (often hidden under Population) -Light Green - Population (often hidden under Homes) -Green - Homes -Blue - Jobs -Red - Population Limit for the city's resource zone - True @@ -227,6 +216,17 @@ Red - Population Limit for the city's resource zone True + + 133, 17 + + + Yellow - Loyal Citizens (often hidden under Population) +Orange - Disloyal Citizens (often hidden under Population) +Light Green - Population (often hidden under Homes) +Green - Homes +Blue - Jobs +Red - Population Limit for the city's resource zone + True