Skip to content

Commit

Permalink
v1.3 - bugfixes and improvments
Browse files Browse the repository at this point in the history
  • Loading branch information
Azim committed Jan 17, 2021
1 parent 9e8fafc commit 38c7834
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 88 deletions.
78 changes: 38 additions & 40 deletions WavesInfo/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

82 changes: 47 additions & 35 deletions WavesInfo/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<int, int> spawnToColumn = new Dictionary<int, int>
Expand Down Expand Up @@ -143,6 +143,7 @@ private void button2_Click(object sender, EventArgs e)
imageWindowCB.Enabled = true;
nextWaveCB.Enabled = true;
refreshCB.Enabled = true;
respawnTimerCB.Enabled = true;
}
}

Expand Down Expand Up @@ -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
{
Expand All @@ -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
{
Expand All @@ -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);
}


Expand All @@ -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();
}
}

Expand Down
39 changes: 34 additions & 5 deletions WavesInfo/ImageDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand All @@ -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;
}
Expand Down
Loading

0 comments on commit 38c7834

Please sign in to comment.