From 38c7834c292782e1f6d85c7e10495fae85709e3a Mon Sep 17 00:00:00 2001 From: Azim-D3Tm Date: Mon, 18 Jan 2021 00:31:12 +0300 Subject: [PATCH] v1.3 - bugfixes and improvments --- WavesInfo/Form1.Designer.cs | 78 +++++++++++++++++------------------ WavesInfo/Form1.cs | 82 +++++++++++++++++++++---------------- WavesInfo/ImageDrawer.cs | 39 +++++++++++++++--- WavesInfo/LogParser.cs | 12 ++---- WavesInfo/Player.cs | 2 + 5 files changed, 125 insertions(+), 88 deletions(-) diff --git a/WavesInfo/Form1.Designer.cs b/WavesInfo/Form1.Designer.cs index 760275e..bef82ea 100644 --- a/WavesInfo/Form1.Designer.cs +++ b/WavesInfo/Form1.Designer.cs @@ -35,8 +35,6 @@ private void InitializeComponent() this.label2 = new System.Windows.Forms.Label(); this.button2 = new System.Windows.Forms.Button(); this.label3 = new System.Windows.Forms.Label(); - this.imageFileCB = new System.Windows.Forms.CheckBox(); - this.textFileCB = new System.Windows.Forms.CheckBox(); this.imageWindowCB = new System.Windows.Forms.CheckBox(); this.refreshCB = new System.Windows.Forms.CheckBox(); this.noteLabel = new System.Windows.Forms.Label(); @@ -69,6 +67,8 @@ private void InitializeComponent() this.player0status = new System.Windows.Forms.Label(); this.player0label = new System.Windows.Forms.Label(); this.timeDiff = new System.Windows.Forms.Label(); + this.drawHalfsCB = new System.Windows.Forms.CheckBox(); + this.respawnTimerCB = new System.Windows.Forms.CheckBox(); this.tableLayoutPanel1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox8)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox7)).BeginInit(); @@ -133,38 +133,12 @@ private void InitializeComponent() this.label3.TabIndex = 5; this.label3.Text = "Log file not selected"; // - // imageFileCB - // - this.imageFileCB.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.imageFileCB.AutoSize = true; - this.imageFileCB.Enabled = false; - this.imageFileCB.Location = new System.Drawing.Point(12, 621); - this.imageFileCB.Name = "imageFileCB"; - this.imageFileCB.Size = new System.Drawing.Size(157, 17); - this.imageFileCB.TabIndex = 6; - this.imageFileCB.Text = "Image file (not implemented)"; - this.imageFileCB.UseVisualStyleBackColor = true; - this.imageFileCB.CheckedChanged += new System.EventHandler(this.imageFileCB_CheckedChanged); - // - // textFileCB - // - this.textFileCB.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.textFileCB.AutoSize = true; - this.textFileCB.Enabled = false; - this.textFileCB.Location = new System.Drawing.Point(12, 598); - this.textFileCB.Name = "textFileCB"; - this.textFileCB.Size = new System.Drawing.Size(149, 17); - this.textFileCB.TabIndex = 7; - this.textFileCB.Text = "Text file (not implemented)"; - this.textFileCB.UseVisualStyleBackColor = true; - this.textFileCB.CheckedChanged += new System.EventHandler(this.textFileCB_CheckedChanged); - // // imageWindowCB // this.imageWindowCB.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.imageWindowCB.AutoSize = true; this.imageWindowCB.Enabled = false; - this.imageWindowCB.Location = new System.Drawing.Point(12, 575); + this.imageWindowCB.Location = new System.Drawing.Point(12, 621); this.imageWindowCB.Name = "imageWindowCB"; this.imageWindowCB.Size = new System.Drawing.Size(94, 17); this.imageWindowCB.TabIndex = 8; @@ -177,7 +151,7 @@ private void InitializeComponent() this.refreshCB.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.refreshCB.AutoSize = true; this.refreshCB.Enabled = false; - this.refreshCB.Location = new System.Drawing.Point(12, 528); + this.refreshCB.Location = new System.Drawing.Point(12, 574); this.refreshCB.Name = "refreshCB"; this.refreshCB.Size = new System.Drawing.Size(113, 17); this.refreshCB.TabIndex = 9; @@ -414,7 +388,7 @@ private void InitializeComponent() // this.topmostCB.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.topmostCB.AutoSize = true; - this.topmostCB.Location = new System.Drawing.Point(12, 505); + this.topmostCB.Location = new System.Drawing.Point(12, 551); this.topmostCB.Name = "topmostCB"; this.topmostCB.Size = new System.Drawing.Size(80, 17); this.topmostCB.TabIndex = 26; @@ -425,7 +399,7 @@ private void InitializeComponent() // label11 // this.label11.AutoSize = true; - this.label11.Location = new System.Drawing.Point(212, 529); + this.label11.Location = new System.Drawing.Point(212, 575); this.label11.Name = "label11"; this.label11.Size = new System.Drawing.Size(204, 39); this.label11.TabIndex = 27; @@ -436,7 +410,7 @@ private void InitializeComponent() this.nextWaveCB.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.nextWaveCB.AutoSize = true; this.nextWaveCB.Enabled = false; - this.nextWaveCB.Location = new System.Drawing.Point(12, 551); + this.nextWaveCB.Location = new System.Drawing.Point(12, 597); this.nextWaveCB.Name = "nextWaveCB"; this.nextWaveCB.Size = new System.Drawing.Size(152, 17); this.nextWaveCB.TabIndex = 28; @@ -458,7 +432,7 @@ private void InitializeComponent() this.tableLayoutPanel2.Controls.Add(this.player1status, 1, 1); this.tableLayoutPanel2.Controls.Add(this.player0status, 1, 0); this.tableLayoutPanel2.Controls.Add(this.player0label, 0, 0); - this.tableLayoutPanel2.Location = new System.Drawing.Point(185, 360); + this.tableLayoutPanel2.Location = new System.Drawing.Point(186, 360); this.tableLayoutPanel2.Name = "tableLayoutPanel2"; this.tableLayoutPanel2.RowCount = 5; this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 30F)); @@ -544,16 +518,42 @@ private void InitializeComponent() // timeDiff // this.timeDiff.AutoSize = true; - this.timeDiff.Location = new System.Drawing.Point(188, 337); + this.timeDiff.Location = new System.Drawing.Point(189, 337); this.timeDiff.Name = "timeDiff"; this.timeDiff.Size = new System.Drawing.Size(0, 13); this.timeDiff.TabIndex = 8; // + // drawHalfsCB + // + this.drawHalfsCB.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.drawHalfsCB.AutoSize = true; + this.drawHalfsCB.Location = new System.Drawing.Point(12, 528); + this.drawHalfsCB.Name = "drawHalfsCB"; + this.drawHalfsCB.Size = new System.Drawing.Size(98, 17); + this.drawHalfsCB.TabIndex = 30; + this.drawHalfsCB.Text = "Draw only halfs"; + this.drawHalfsCB.UseVisualStyleBackColor = true; + // + // respawnTimerCB + // + this.respawnTimerCB.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.respawnTimerCB.AutoSize = true; + this.respawnTimerCB.Enabled = false; + this.respawnTimerCB.Location = new System.Drawing.Point(12, 505); + this.respawnTimerCB.Name = "respawnTimerCB"; + this.respawnTimerCB.Size = new System.Drawing.Size(123, 17); + this.respawnTimerCB.TabIndex = 31; + this.respawnTimerCB.Text = "Player respawn timer"; + this.respawnTimerCB.UseVisualStyleBackColor = true; + this.respawnTimerCB.CheckedChanged += new System.EventHandler(this.respawnTimerCB_CheckedChanged); + // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(758, 708); + this.Controls.Add(this.respawnTimerCB); + this.Controls.Add(this.drawHalfsCB); this.Controls.Add(this.timeDiff); this.Controls.Add(this.tableLayoutPanel2); this.Controls.Add(this.nextWaveCB); @@ -563,8 +563,6 @@ private void InitializeComponent() this.Controls.Add(this.noteLabel); this.Controls.Add(this.refreshCB); this.Controls.Add(this.imageWindowCB); - this.Controls.Add(this.textFileCB); - this.Controls.Add(this.imageFileCB); this.Controls.Add(this.label3); this.Controls.Add(this.button2); this.Controls.Add(this.label2); @@ -572,7 +570,7 @@ private void InitializeComponent() this.Controls.Add(this.pictureBox1); this.Controls.Add(this.label1); this.Name = "Form1"; - this.Text = "Waves Info v1.2"; + this.Text = "Waves Info v1.3"; this.Load += new System.EventHandler(this.Form1_Load); this.tableLayoutPanel1.ResumeLayout(false); this.tableLayoutPanel1.PerformLayout(); @@ -599,8 +597,6 @@ private void InitializeComponent() private System.Windows.Forms.Label label2; private System.Windows.Forms.Button button2; private System.Windows.Forms.Label label3; - private System.Windows.Forms.CheckBox imageFileCB; - private System.Windows.Forms.CheckBox textFileCB; private System.Windows.Forms.CheckBox imageWindowCB; private System.Windows.Forms.CheckBox refreshCB; private System.Windows.Forms.Label noteLabel; @@ -632,6 +628,8 @@ private void InitializeComponent() private System.Windows.Forms.Label player3label; private System.Windows.Forms.Label player0label; private System.Windows.Forms.Label timeDiff; + private System.Windows.Forms.CheckBox drawHalfsCB; + private System.Windows.Forms.CheckBox respawnTimerCB; } } diff --git a/WavesInfo/Form1.cs b/WavesInfo/Form1.cs index 5f7d082..1683bac 100644 --- a/WavesInfo/Form1.cs +++ b/WavesInfo/Form1.cs @@ -19,7 +19,7 @@ public partial class Form1 : Form { private LogParser parser; - private CancellationTokenSource cts; + private CancellationTokenSource cts1,cts2; private ImageForm imageFormCurrent, imageFormNext; private Label[] names, statuses; private readonly Dictionary spawnToColumn = new Dictionary @@ -143,6 +143,7 @@ private void button2_Click(object sender, EventArgs e) imageWindowCB.Enabled = true; nextWaveCB.Enabled = true; refreshCB.Enabled = true; + respawnTimerCB.Enabled = true; } } @@ -178,7 +179,8 @@ private void nextWaveCB_CheckedChanged(object sender, EventArgs e) { imageFormNext = new ImageForm(nextWaveCB); imageFormNext.Show(); - if(parser.inBrawl) imageFormNext.updateImage(ImageDrawer.createImage(new Bitmap(Resources.map_small), waves[parser.wave])); + int index = parser.wave + (drawHalfsCB.Checked ? 1 : 0); + if (parser.inBrawl) imageFormNext.updateImage(ImageDrawer.createImage(Resources.map_small, waves[index], waves[index + 1], drawHalfsCB.Checked)); } else { @@ -198,47 +200,43 @@ private void refresh() private void refreshDeaths() { - if (!parser.inBrawl) - { - for(int i = 0; i < 4; i++) - { - names[i].Text = "Player " + i; - statuses[i].Text = "no info"; - } - } - else - { - string[] newstatuses = new string[4]; - for(int i = 0; i < 4; i++)//checks + names[0].Invoke(new Action(() => {//apply them + if (!parser.inBrawl) { - var respawns = parser.players[i].died.AddSeconds(30); - if(respawns < DateTime.Now) - { - newstatuses[i] = "Alive"; - } - else + for (int i = 0; i < 4; i++) { - newstatuses[i] = "" + Convert.ToInt32((respawns - DateTime.Now).TotalSeconds); + names[i].Text = "Player " + i; + statuses[i].Text = "no info"; } - } - names[0].Invoke(new Action(() => {//apply them - for (int i = 0; i < 4; i++) + else + { + string[] newstatuses = new string[4]; + for (int i = 0; i < 4; i++)//checks { + if (!parser.players.ContainsKey(i)) continue; + var respawns = parser.players[i].died.AddSeconds(30); + if (respawns < DateTime.Now) + { + statuses[i].Text = "Alive"; + } + else + { + statuses[i].Text = "" + Convert.ToInt32((respawns - DateTime.Now).TotalSeconds); + } names[i].Text = parser.players[i].Name; - statuses[i].Text = newstatuses[i]; } - })); - } + } + })); } private void updateImage() { if (parser.inBrawl) { - Bitmap image = new Bitmap(Resources.map_small); pictureBox1.Image.Dispose(); - pictureBox1.Image = ImageDrawer.createImage(image, waves[parser.wave - (parser.convoy?0:1)]); + int index = parser.wave - (parser.convoy ? 0 : 1); + pictureBox1.Image = ImageDrawer.createImage(Resources.map_small, waves[index], waves[index + 1], drawHalfsCB.Checked); } else { @@ -251,7 +249,8 @@ private void updateImage() } if (nextWaveCB.Checked && imageFormNext != null) { - imageFormNext.updateImage(parser.inBrawl ? ImageDrawer.createImage(new Bitmap(Resources.map_small), waves[parser.wave]) : pictureBox1.Image); + int index = parser.wave + (drawHalfsCB.Checked ? 1 : 0); + imageFormNext.updateImage(parser.inBrawl ? ImageDrawer.createImage(Resources.map_small, waves[index], waves[index + 1], drawHalfsCB.Checked) : pictureBox1.Image); } @@ -276,18 +275,31 @@ private void updateText() } } + private void respawnTimerCB_CheckedChanged(object sender, EventArgs e) + { + if (respawnTimerCB.Checked) + { + cts2 = new CancellationTokenSource(); + parser.runRepeatingTaskMillis(refreshDeaths, 500, cts2.Token); + } + else + { + if (cts2 == null) return; + cts2.Cancel(); + } + } + private void refreshCB_CheckedChanged(object sender, EventArgs e) { if (refreshCB.Checked) { - cts = new CancellationTokenSource(); - parser.runRepeatingTask(refresh, 2, cts.Token); - parser.runRepeatingTaskMillis(refreshDeaths, 500, cts.Token); + cts1 = new CancellationTokenSource(); + parser.runRepeatingTask(refresh, 2, cts1.Token); } else { - if (cts == null) return; - cts.Cancel(); + if (cts1 == null) return; + cts1.Cancel(); } } diff --git a/WavesInfo/ImageDrawer.cs b/WavesInfo/ImageDrawer.cs index cf0d012..3f43007 100644 --- a/WavesInfo/ImageDrawer.cs +++ b/WavesInfo/ImageDrawer.cs @@ -44,11 +44,41 @@ public class ImageDrawer private static readonly Pen red = new Pen(Color.Red, 3), orange = new Pen(Color.Orange, 3); - public static Bitmap createImage(Bitmap image, Wave wave) + public static Bitmap createImage(Bitmap image, Wave wave, Wave next, bool halfs) { - using(Graphics g = Graphics.FromImage(image)) + if (!halfs) { - foreach(int s in wave.spawns.Keys) + return drawSingle(new Bitmap(image), wave, true); + } + else + { + bool h1 = ((wave.Number - 1) % 10) < 5; + bool h2 = ((next.Number - 1) % 10) < 5; + Bitmap result = new Bitmap(image.Width, image.Height); + Bitmap top = drawSingle(new Bitmap(image), wave, false); + Bitmap bottom = drawSingle(new Bitmap(image), next, false); + using (Graphics g = Graphics.FromImage(result)) + { + Rectangle topr = h1 ? new Rectangle(0, 0, image.Width, image.Height / 2) : new Rectangle(0, image.Height / 2, image.Width, image.Height); + g.DrawImage(top, 0, 0, topr, GraphicsUnit.Pixel); + + Rectangle bottomr = h2 ? new Rectangle(0, 0, image.Width, image.Height / 2) : new Rectangle(0, image.Height / 2, image.Width, image.Height); + g.DrawImage(bottom, 0, image.Height / 2, bottomr, GraphicsUnit.Pixel); + + g.DrawLine(orange, new Point(0, image.Height / 2), new Point(image.Width, image.Height / 2)); + g.DrawString("" + wave.Number, new Font(SystemFonts.DefaultFont.FontFamily, 18, FontStyle.Bold), Brushes.Lime, 2, 2); + g.DrawString("" + next.Number, new Font(SystemFonts.DefaultFont.FontFamily, 18, FontStyle.Bold), Brushes.Lime, 2, 2 + (image.Height / 2)); + + } + return result; + } + } + + private static Bitmap drawSingle(Bitmap image, Wave wave, bool draw) + { + using (Graphics g = Graphics.FromImage(image)) + { + foreach (int s in wave.spawns.Keys) { SpawnInfo spawn = doors[s]; drawIcons(g, spawn, wave.spawns[s]); @@ -61,10 +91,9 @@ public static Bitmap createImage(Bitmap image, Wave wave) { g.DrawLine(red, new Point(spawn.x1, spawn.y1), new Point(spawn.x2, spawn.y2)); } - g.DrawString("" + wave.Number, new Font(SystemFonts.DefaultFont.FontFamily, 18, FontStyle.Bold), Brushes.Lime, 0, 0); + if (draw) g.DrawString("" + wave.Number, new Font(SystemFonts.DefaultFont.FontFamily, 18, FontStyle.Bold), Brushes.Lime, 2, 2); } - } return image; } diff --git a/WavesInfo/LogParser.cs b/WavesInfo/LogParser.cs index 3a3514b..4d11dca 100644 --- a/WavesInfo/LogParser.cs +++ b/WavesInfo/LogParser.cs @@ -94,7 +94,7 @@ private void parse(string row) Debug.WriteLine("started some level, not in brawl anymore"); return; } - if (players.Keys.Count < 4 && inBrawl) + if (inBrawl) { if(data.StartsWith("Spawn player")) { @@ -105,15 +105,12 @@ private void parse(string row) players[number] = player; return; } - } - else if(inBrawl) - { - for(int i = 0; i < 4; i++) + foreach(var player in players.Values) { - if(data.StartsWith("Kill. Victim: " + players[i].Name+" ")) + if(data.StartsWith("Kill. Victim: " + player.Name+" ")) { DateTime deathTime = DateTime.Parse(time); - players[i].died = deathTime; + player.died = deathTime; } } } @@ -176,7 +173,6 @@ public void runRepeatingTask(Action action, int seconds, CancellationToken token } }, token); } - public void runRepeatingTaskMillis(Action action, int millis, CancellationToken token) { if (action == null) diff --git a/WavesInfo/Player.cs b/WavesInfo/Player.cs index e8c600d..87df850 100644 --- a/WavesInfo/Player.cs +++ b/WavesInfo/Player.cs @@ -8,6 +8,8 @@ namespace WavesOverlay { public class Player { + + public int Number { get; set; } public string Name { get; set; } public string NameWithBrackets { get; set; } public DateTime died { get; set; } = DateTime.Now.AddMinutes(-2);