Skip to content

Commit 35b9880

Browse files
committed
Move classes to separate files, remove Util folder.
1 parent 64a1142 commit 35b9880

File tree

13 files changed

+900
-964
lines changed

13 files changed

+900
-964
lines changed

src/Form1.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,10 @@ public void SetSquadName(int index, string name)
167167

168168
public void SetUpdateNotice(string text, string url = "")
169169
{
170-
updateNoticeLinkLabel.Text = text;
171-
updateNoticeLinkLabel.LinkArea = string.IsNullOrWhiteSpace(url) ? new LinkArea(0, 0) : new LinkArea(0, updateNoticeLinkLabel.Text.Length);
172-
updateNoticeLinkLabel.Tag = url;
173-
updateNoticeLinkLabel.LinkVisited = false;
170+
SetControlProperty(updateNoticeLinkLabel, "Text", text);
171+
SetControlProperty(updateNoticeLinkLabel, "LinkArea", string.IsNullOrWhiteSpace(url) ? new LinkArea(0, 0) : new LinkArea(0, updateNoticeLinkLabel.Text.Length));
172+
SetControlProperty(updateNoticeLinkLabel, "Tag", url);
173+
SetControlProperty(updateNoticeLinkLabel, "LinkVisited", false);
174174
}
175175

176176
public void ShowHideConsole(bool showConsole)
@@ -187,7 +187,7 @@ public void ShowHideConsole(bool showConsole)
187187
int tableRow = mainTableLayoutPanel.GetRow(consoleLogTextBox);
188188
consoleLogTextBox.Visible = showConsole;
189189
mainTableLayoutPanel.RowStyles[tableRow].Height = showConsole ? consoleHeight : 0;
190-
Size = new Size(Size.Width, Size.Height + (showConsole ? consoleHeight : consoleHeight * -1));
190+
Size = new System.Drawing.Size(Size.Width, Size.Height + (showConsole ? consoleHeight : consoleHeight * -1));
191191
}
192192

193193
public void ShowHideSortButtons(int squadmates)
@@ -201,10 +201,10 @@ public void ShowHideSortButtons(int squadmates)
201201
private static void SwapSquad(int indexA, int indexB)
202202
{
203203
var max = indexA > indexB ? indexA : indexB;
204-
if (Program.fortniters.Count < max + 1) { return; }
205-
var temp = Program.fortniters[indexA];
206-
Program.fortniters[indexA] = Program.fortniters[indexB];
207-
Program.fortniters[indexB] = temp;
204+
if (Program.CurrentSquad.Count < max + 1) { return; }
205+
var temp = Program.CurrentSquad[indexA];
206+
Program.CurrentSquad[indexA] = Program.CurrentSquad[indexB];
207+
Program.CurrentSquad[indexB] = temp;
208208
Program.UpdateFormElements();
209209
}
210210

@@ -259,7 +259,7 @@ private void showConsoleCheckBox_CheckedChanged(object sender, EventArgs e)
259259
var visible = ((CheckBox)sender).Checked;
260260

261261
mainTableLayoutPanel.RowStyles[1].Height = (visible ? consoleHeight : 0);
262-
Size = new Size(Size.Width, Size.Height + (visible ? consoleHeight : consoleHeight * -1));
262+
Size = new System.Drawing.Size(Size.Width, Size.Height + (visible ? consoleHeight : consoleHeight * -1));
263263
}
264264

265265
private void squadmate1DownButton_Click(object sender, EventArgs e)
@@ -286,11 +286,11 @@ private void updateNoticeLinkLabel_LinkClicked(object sender, LinkLabelLinkClick
286286
System.Diagnostics.Process.Start(label.Tag.ToString());
287287
}
288288

289-
private Fortniter FortniterAtUiIndex(int uiIndex)
289+
private FortnitePlayer FortniterAtUiIndex(int uiIndex)
290290
{
291291
if (uiIndex == 0)
292292
{
293-
return Program.localPlayer;
293+
return Program.LocalPlayer;
294294
}
295295

296296
Label control = null;
@@ -308,7 +308,7 @@ private Fortniter FortniterAtUiIndex(int uiIndex)
308308
default:
309309
throw new Exception("Invalid index given to CopyName");
310310
}
311-
var fortniter = Program.fortniters.FirstOrDefault(x => x.Name == control.Text);
311+
var fortniter = Program.CurrentSquad.FirstOrDefault(x => x.Name == control.Text);
312312
return fortniter;
313313
}
314314

src/FortniteOverlay.csproj

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,19 +106,22 @@
106106
<Compile Include="Form1.Designer.cs">
107107
<DependentUpon>Form1.cs</DependentUpon>
108108
</Compile>
109+
<Compile Include="FortnitePlayer.cs" />
110+
<Compile Include="ImageProcessing.cs" />
109111
<Compile Include="OverlayForm.cs">
110112
<SubType>Form</SubType>
111113
</Compile>
112114
<Compile Include="OverlayForm.Designer.cs">
113115
<DependentUpon>OverlayForm.cs</DependentUpon>
114116
</Compile>
117+
<Compile Include="PixelPositions.cs" />
115118
<Compile Include="Program.cs" />
116119
<Compile Include="Properties\AssemblyInfo.cs" />
117-
<Compile Include="Util\LogParser.cs" />
118-
<Compile Include="Util\ProcMon.cs" />
119-
<Compile Include="Util\ImageUtil.cs" />
120-
<Compile Include="Util\LogReader.cs" />
121-
<Compile Include="Util\MiscUtil.cs" />
120+
<Compile Include="LogParser.cs" />
121+
<Compile Include="ProcMon.cs" />
122+
<Compile Include="ImageUtil.cs" />
123+
<Compile Include="LogReader.cs" />
124+
<Compile Include="MiscUtil.cs" />
122125
<EmbeddedResource Include="ConfigForm.resx">
123126
<DependentUpon>ConfigForm.cs</DependentUpon>
124127
</EmbeddedResource>
@@ -168,5 +171,6 @@
168171
<Install>false</Install>
169172
</BootstrapperPackage>
170173
</ItemGroup>
174+
<ItemGroup />
171175
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
172176
</Project>

src/FortnitePlayer.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
using System.Drawing;
3+
4+
namespace FortniteOverlay
5+
{
6+
internal class FortnitePlayer
7+
{
8+
public string Name { get; set; }
9+
public string UserId { get; set; }
10+
public ReadyState State { get; set; }
11+
public int Index { get; set; } = -1;
12+
public Bitmap GearImage { get; set; }
13+
public DateTime GearModified { get; set; }
14+
public bool IsFaded { get; set; } = false;
15+
16+
public string UserIdTruncated => UserId.Substring(0, 5) + "..." + UserId.Substring(UserId.Length - 5, 5);
17+
18+
public enum ReadyState
19+
{
20+
NotReady,
21+
Ready,
22+
SittingOut,
23+
}
24+
}
25+
}

src/ImageProcessing.cs

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
using System.Drawing;
2+
using FortniteOverlay.Properties;
3+
4+
namespace FortniteOverlay
5+
{
6+
internal class ImageProcessing
7+
{
8+
public static bool IsPlaying(Bitmap screenshot, PixelPositions positions)
9+
{
10+
if (screenshot == null) { return false; }
11+
var pix = screenshot.GetPixel(positions.ShieldIcon.X, positions.ShieldIcon.Y);
12+
if (pix.R < 190 || pix.G < 190 || pix.B < 190)
13+
{
14+
// debug: Shield indicator not detected (vals: {pix.R},{pix.G},{pix.B})
15+
return false;
16+
}
17+
18+
return true;
19+
}
20+
21+
public static bool IsSpectating(Bitmap screenshot, PixelPositions positions)
22+
{
23+
if (screenshot == null) { return false; };
24+
25+
var pix = screenshot.GetPixel(positions.SpectatingText[0].X, positions.SpectatingText[0].Y);
26+
if (pix.R < 255 || pix.G < 255 || pix.B < 255)
27+
{
28+
return false;
29+
}
30+
31+
pix = screenshot.GetPixel(positions.SpectatingText[1].X, positions.SpectatingText[1].Y);
32+
if (pix.R < 255 || pix.G < 255 || pix.B < 255)
33+
{
34+
return false;
35+
}
36+
37+
// debug: Detected spectating text.
38+
return true;
39+
}
40+
41+
public static Bitmap MarkStaleImage(Bitmap bmp)
42+
{
43+
using (Graphics g = Graphics.FromImage(bmp))
44+
{
45+
int width = bmp.Width;
46+
int height = bmp.Height;
47+
48+
Image outdated = Resources.outdated;
49+
50+
Rectangle rect = new Rectangle(0, 0, width, height);
51+
using (Brush darken = new SolidBrush(Color.FromArgb(96, Color.Black)))
52+
{
53+
g.FillRectangle(darken, rect);
54+
}
55+
56+
var smallestSide = (height < width) ? height : width;
57+
var leftEdge = (width / 2) - (smallestSide / 2);
58+
var topEdge = (height / 2) - (smallestSide / 2);
59+
60+
g.DrawImage(outdated, new Rectangle(leftEdge + (int)(smallestSide * 0.05),
61+
topEdge + (int)(smallestSide * 0.05),
62+
smallestSide - (int)(smallestSide * 0.10),
63+
smallestSide - (int)(smallestSide * 0.10)));
64+
}
65+
return bmp;
66+
}
67+
68+
public static Bitmap CropGear(Bitmap bmp, PixelPositions positions)
69+
{
70+
int slotSelected = -1;
71+
for (int i = 0; i < positions.Slots.Length; i++)
72+
{
73+
var pix = bmp.GetPixel(positions.Slots[i].X, positions.Slots[i].Y);
74+
75+
if (pix.R < 255 || pix.G < 255 || pix.B < 255)
76+
{
77+
// FIXME: wtf is this checking for?
78+
if (pix.R != 127 || pix.G != 127 || pix.B != 127)
79+
{
80+
continue;
81+
}
82+
}
83+
84+
slotSelected = i;
85+
break;
86+
}
87+
88+
// debug: Selected slot: {slotSelected}
89+
90+
Bitmap cropped = new Bitmap(positions.SlotSize.Width * 5, positions.SlotSize.Height);
91+
using (Graphics g = Graphics.FromImage(cropped))
92+
{
93+
for (int i = 0; i < positions.Slots.Length; i++)
94+
{
95+
var ofs = (slotSelected == i) ? positions.SelectedSlotOffset : 0;
96+
g.DrawImage(bmp,
97+
new Rectangle(i * positions.SlotSize.Width, 0, positions.SlotSize.Width, positions.SlotSize.Height),
98+
new Rectangle(positions.Slots[i].X, positions.Slots[i].Y + ofs, positions.SlotSize.Width, positions.SlotSize.Height),
99+
GraphicsUnit.Pixel);
100+
}
101+
102+
// keys (defunct)
103+
//g.DrawImage(bmp,
104+
// new Rectangle(positions.SlotSize.Width * 5, 0, positions.SlotSize.Width, positions.SlotSize.Height),
105+
// new Rectangle(positions.Keys.X, positions.Keys.Y, positions.SlotSize.Width, positions.SlotSize.Height),
106+
// GraphicsUnit.Pixel);
107+
}
108+
109+
return cropped;
110+
}
111+
112+
public static void RenderDebugMarkers(ref Bitmap blankScreenshot, PixelPositions positions)
113+
{
114+
Pen pen = new Pen(Color.Red, 1);
115+
116+
using (Graphics g = Graphics.FromImage(blankScreenshot))
117+
{
118+
for (int i = 0; i < positions.Slots.Length; i++)
119+
{
120+
g.DrawRectangle(pen, new Rectangle(positions.Slots[i].X - 1, positions.Slots[i].Y - 1, positions.SlotSize.Width + 1, positions.SlotSize.Height + 1));
121+
}
122+
123+
// keys are defunct
124+
//g.DrawRectangle(pen, new Rectangle(positions.Keys.X - 1, positions.Keys.Y - 1, positions.SlotSize.Width + 1, positions.SlotSize.Height + 1));
125+
126+
g.DrawEllipse(pen, positions.ShieldIcon.X - 1, positions.ShieldIcon.Y - 1, 2, 2);
127+
128+
g.DrawEllipse(pen, positions.SpectatingText[0].X - 1, positions.SpectatingText[0].Y - 1, 2, 2);
129+
g.DrawEllipse(pen, positions.SpectatingText[1].X - 1, positions.SpectatingText[1].Y - 1, 2, 2);
130+
}
131+
}
132+
}
133+
}

src/ImageUtil.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using FortniteOverlay.Properties;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Drawing;
5+
using System.Linq;
6+
using System.Windows.Forms;
7+
8+
namespace FortniteOverlay.Util
9+
{
10+
internal class ImageUtil
11+
{
12+
public static void TakeScreenshot(ref Bitmap startingBitmap, Rectangle bounds)
13+
{
14+
if (bounds.Width <= 0 || bounds.Height <= 0)
15+
{
16+
bounds = Screen.GetBounds(Point.Empty);
17+
}
18+
if (startingBitmap == null || startingBitmap.Width != bounds.Width || startingBitmap.Height != bounds.Height)
19+
{
20+
startingBitmap = new Bitmap(bounds.Width, bounds.Height);
21+
}
22+
23+
using (Graphics g = Graphics.FromImage(startingBitmap))
24+
{
25+
g.CopyFromScreen(bounds.X, bounds.Y, 0, 0, bounds.Size);
26+
}
27+
}
28+
}
29+
}
Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@ private static class FortniteLogActions
6969
{
7070
string name = match.Groups["DisplayName"].ToString();
7171
string userId = match.Groups["UserId"].ToString();
72-
Fortniter self = new Fortniter()
72+
FortnitePlayer self = new FortnitePlayer()
7373
{
7474
Name = name,
7575
UserId = userId,
7676
};
77-
Program.localPlayer = self;
77+
Program.LocalPlayer = self;
7878
},
7979
};
8080

@@ -85,17 +85,17 @@ private static class FortniteLogActions
8585
string name = match.Groups["DisplayName"].ToString();
8686
string userId = match.Groups["UserId"].ToString();
8787

88-
if (Program.localPlayer.Name == name) { return; }
89-
if (Program.fortniters.Any(x => x.Name == name)) { return; }
88+
if (Program.LocalPlayer.Name == name) { return; }
89+
if (Program.CurrentSquad.Any(x => x.Name == name)) { return; }
9090

91-
Fortniter newJoin = new Fortniter()
91+
FortnitePlayer newJoin = new FortnitePlayer()
9292
{
9393
Name = name,
9494
UserId = userId,
9595
};
96-
newJoin.Index = Array.IndexOf(Program.order, newJoin.UserIdTruncated);
97-
Program.fortniters.Add(newJoin);
98-
Program.fortniters.Sort(MiscUtil.SortFortniters);
96+
newJoin.Index = Program.UserIdOrder.IndexOf(newJoin.UserIdTruncated);
97+
Program.CurrentSquad.Add(newJoin);
98+
Program.CurrentSquad.Sort(MiscUtil.SortFortniters);
9999
},
100100
};
101101

@@ -104,8 +104,8 @@ private static class FortniteLogActions
104104
Action = (match) =>
105105
{
106106
string name = match.Groups["DisplayName"].ToString();
107-
var leaver = Program.fortniters.Find(x => x.Name == name);
108-
if (leaver != null) { Program.fortniters.Remove(leaver); };
107+
var leaver = Program.CurrentSquad.Find(x => x.Name == name);
108+
if (leaver != null) { Program.CurrentSquad.Remove(leaver); };
109109
},
110110
};
111111

@@ -114,24 +114,24 @@ private static class FortniteLogActions
114114
Action = (match) =>
115115
{
116116
string userId = match.Groups["UserId"].ToString();
117-
if (userId == Program.localPlayer.UserId)
117+
if (userId == Program.LocalPlayer.UserId)
118118
{
119119
return;
120120
}
121121

122122
string state = match.Groups["State"].ToString();
123-
var user = Program.fortniters.Find(x => x.UserIdTruncated == userId) ?? throw new Exception("Unable to find player with ID: " + userId);
123+
var user = Program.CurrentSquad.Find(x => x.UserIdTruncated == userId) ?? throw new Exception("Unable to find player with ID: " + userId);
124124

125125
switch(state)
126126
{
127127
case "Ready":
128-
user.State = Fortniter.ReadyState.Ready;
128+
user.State = FortnitePlayer.ReadyState.Ready;
129129
break;
130130
case "Not Ready":
131-
user.State = Fortniter.ReadyState.NotReady;
131+
user.State = FortnitePlayer.ReadyState.NotReady;
132132
break;
133133
case "Sitting Out":
134-
user.State = Fortniter.ReadyState.SittingOut;
134+
user.State = FortnitePlayer.ReadyState.SittingOut;
135135
break;
136136
}
137137
},
@@ -156,7 +156,7 @@ private static class FortniteLogActions
156156
{
157157
string userid = match.Groups["UserId"].ToString();
158158

159-
foreach (var fortniter in Program.fortniters)
159+
foreach (var fortniter in Program.CurrentSquad)
160160
{
161161
if (fortniter.UserId.IndexOf("...") == -1)
162162
{

0 commit comments

Comments
 (0)