-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNewGameForm.cs
191 lines (168 loc) · 6.32 KB
/
NewGameForm.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
using Biotronic;
using System;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
namespace ImmersiveGaming
{
public partial class NewGameForm : UserControl
{
bool checkContiguousMonitors = true;
GameInfo game = null;
public NewGameForm()
{
InitializeComponent();
UpdateSelectedMonitorColors();
}
public GameInfo Game
{
get
{
return game;
}
set
{
if (game != value)
{
game = null;
UpdateFromGame(value);
game = value;
}
}
}
private void UpdateFromGame(GameInfo value)
{
Enabled = value != null;
if (value == null)
{
return;
}
chkWindowTitle.Checked = value.title.active;
cmbWindowTitle.SelectedIndex = (int)value.title.operation;
txtWindowTitle.Text = value.title.pattern;
chkClassName.Checked = value.className.active;
cmbClassName.SelectedIndex = (int)value.className.operation;
txtClassName.Text = value.className.pattern;
chkFileName.Checked = value.file.active;
cmbFileName.SelectedIndex = (int)value.file.operation;
txtFileName.Text = value.file.pattern;
chkAot.CheckState = value.alwaysOnTop;
chkBlackout.Checked = value.blackoutUnused;
chkHideCursor.Checked = value.hideMouse;
foreach (DisplayChooser.SelectableDisplay screen in monitors.Monitors)
{
screen.Selected = false;
}
foreach (DisplayChooser.SelectableDisplay screen in value.monitors.Select(a=>monitors.ScreenFromBounds(a.Bounds)).Where(a=>a!=null))
{
screen.Selected = true;
}
}
private void UpdateToGame()
{
if (game == null)
{
return;
}
game.title = new Comparer(
chkWindowTitle.Checked, (ComparisonOperator)
cmbWindowTitle.SelectedIndex,
txtWindowTitle.Text);
game.className = new Comparer(
chkClassName.Checked, (ComparisonOperator)
cmbClassName.SelectedIndex,
txtClassName.Text);
game.file = new Comparer(
chkFileName.Checked, (ComparisonOperator)
cmbFileName.SelectedIndex,
txtFileName.Text);
game.blackoutUnused = chkBlackout.Checked;
game.hideMouse = chkHideCursor.Checked;
game.alwaysOnTop = chkAot.CheckState;
game.monitors = Screen.AllScreens.ZipFilter(monitors.Monitors.Cast<DisplayChooser.SelectableDisplay>().Select(a => a.Selected)).Select(a => new ScreenInfo(a)).ToArray();
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
chkFileName.Checked = false;
cmbWindowTitle.SelectedIndex = 0;
cmbClassName.SelectedIndex = 0;
cmbFileName.SelectedIndex = 0;
var windows = Win32Form.AllWindows.Where(a => a.Visible && !string.IsNullOrWhiteSpace(a.Text)).ToArray();
txtWindowTitle.Items.AddRange(windows.Select(a => a.Text).ToArray());
txtClassName.Items.AddRange(windows.Select(a => a.ClassName).ToArray());
}
private void CheckedChanged(object sender, EventArgs e)
{
cmbWindowTitle.Enabled = chkWindowTitle.Checked;
txtWindowTitle.Enabled = chkWindowTitle.Checked;
cmbClassName.Enabled = chkClassName.Checked;
txtClassName.Enabled = chkClassName.Checked;
cmbFileName.Enabled = chkFileName.Checked;
txtFileName.Enabled = chkFileName.Checked;
UpdateToGame();
}
private void NewGameForm_FormClosing(object sender, FormClosingEventArgs e)
{
if (checkContiguousMonitors)
{
var monitorBounds = monitors.Monitors.Cast<DisplayChooser.SelectableDisplay>().Where(a => a.Selected).Select(a => a.Bounds).ToList();
if (monitorBounds.Count == 0)
{
return;
}
if (!monitorBounds.TryUnion().HasValue)
{
e.Cancel = true;
MessageBox.Show("Selected monitors must be contiguous.");
}
}
}
private void monitors_MonitorSelectedChanged(object sender, MonitorEventArgs e)
{
UpdateSelectedMonitorColors();
UpdateToGame();
}
private void UpdateSelectedMonitorColors()
{
foreach (ImmersiveGaming.DisplayChooser.SelectableDisplay m in monitors.Monitors)
{
if (chkBlackout.Checked)
{
m.BackColor = m.Selected ? Color.Blue : Color.Black;
}
else
{
m.BackColor = m.Selected ? Color.Blue : (Color)((new ColorF(Color.Blue) + Color.White) / 2);
}
}
}
private void chkBlackout_CheckedChanged(object sender, EventArgs e)
{
UpdateSelectedMonitorColors();
UpdateToGame();
}
private void buttons_ButtonClick(object sender, Controls.DialogResultEventArgs e)
{
if (e.Result == System.Windows.Forms.DialogResult.Cancel)
{
checkContiguousMonitors = false;
}
}
private void btnCapture_Click(object sender, EventArgs e)
{
var p = MouseCaptureForm.GetMouseClickPosition();
var form = Win32Form.AllWindows.Where(a => a.Visible && a.Rect.Contains(p)).FirstOrDefault();
txtWindowTitle.Text = form.Text;
txtClassName.Text = form.ClassName;
txtFileName.Text = form.Process.MainModule.FileName;
cmbWindowTitle.SelectedIndex = 0;
cmbClassName.SelectedIndex = 0;
cmbFileName.SelectedIndex = 0;
}
private void InputChanged(object sender, EventArgs e)
{
UpdateToGame();
}
}
}