-
Notifications
You must be signed in to change notification settings - Fork 13
/
Form1.cs
384 lines (359 loc) · 13.7 KB
/
Form1.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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using Newtonsoft.Json;
namespace LeagueSandbox_LAN_Server_Launcher
{
public partial class Form1 : Form
{
private bool maximized = false;
public static List<Form2> red = new List<Form2>();
public static List<Form2> blue = new List<Form2>();
public static int redPlayerCount = 0;
public static int bluePlayerCount = 0;
public static int playerCount = 0;
public static int playerId = 0;
public static List<int> idList = new List<int>();
public static List<int[]> redMapping = new List<int[]>();
public static List<int[]> blueMapping = new List<int[]>();
public static bool testingMode = false;
private int progressValue = 100;
private bool debug = true;
private string contentPath;
private int scanDepth = 10;
private bool cheatsEnabled = false;
private bool manacostsEnabled = true;
private bool cooldownsEnabled = true;
private bool minionSpawnsEnabled = true;
public Form1()
{
InitializeComponent();
// Content Path Scan, CPS
string gDirectory = "";
for (int i = 1; i < scanDepth + 1; i++)
{
string directory = "";
for (int j = 1; j < i + 1; j++)
{
directory += "../";
}
if (Directory.Exists(directory + "Contents/"))
{
contentPath = directory + "Contents/";
textBox1.Text = directory + "Contents/";
gDirectory = directory;
break;
}
if (Directory.Exists(gDirectory)) break;
}
}
private void button4_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void setProgess(int value)
{
float maximumWidth = panel6.Width/100;
if ((maximumWidth * 100 - value * maximumWidth) >= 0)
{
progress.Width = Convert.ToInt32(maximumWidth * (100 - value));
button3.Width = Convert.ToInt32(value * maximumWidth);
button3.TextAlign = ContentAlignment.MiddleCenter;
progressValue = value;
}
this.Invalidate();
}
bool launchDisabled = false;
private void button3_Click(object sender, EventArgs e)
{
if (!launchDisabled)
{
launchDisabled = true;
setProgess(30);
button3.Text = "构建玩家...";
Game game = prepareBuild();
string buffer = buildJson(game);
Console.WriteLine(buffer);
setProgess(85);
button3.Text = "写入Json...";
try
{
File.WriteAllText("Settings\\GameInfo.json", buffer);
}
catch (Exception ex)
{
MessageBox.Show("无法找到目录:\n" + ex.Message, "错误 - 无法找到目录", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
setProgess(95);
button3.Text = "启动服务器...";
try
{
Process.Start("GameServerConsole.exe");
}
catch (Exception ex)
{
MessageBox.Show("无法启动服务器:\n" + ex.Message, "错误 - 无法启动服务器", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
setProgess(100);
button3.Text = "启动服务器!";
launchDisabled = false;
}
}
private void button5_Click(object sender, EventArgs e)
{
maximizeTrigger();
}
private void button6_Click(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Minimized;
}
Point LeftDown;
private void panel3_MouseDown(object sender, MouseEventArgs e)
{
LeftDown.X = e.X;
LeftDown.Y = e.Y;
}
private void panel3_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
Point p = MousePosition;
p.Offset(-LeftDown.X, -LeftDown.Y);
Location = p;
}
if (maximized & e.Button == MouseButtons.Left)
{
button5.Text = "口";
this.WindowState = FormWindowState.Normal;
maximized = !maximized;
setProgess(progressValue);
}
}
private void label1_MouseDown(object sender, MouseEventArgs e)
{
LeftDown.X = e.X;
LeftDown.Y = e.Y;
}
private void label1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
Point p = MousePosition;
p.Offset(-LeftDown.X, -LeftDown.Y);
Location = p;
}
if (maximized & e.Button == MouseButtons.Left)
{
button5.Text = "口";
this.WindowState = FormWindowState.Normal;
maximized = !maximized;
setProgess(progressValue);
}
}
private void panel3_MouseDoubleClick(object sender, MouseEventArgs e)
{
maximizeTrigger();
}
private void label1_MouseDoubleClick(object sender, MouseEventArgs e)
{
maximizeTrigger();
}
private void button1_Click(object sender, EventArgs e)
{
// Add before use
playerCount++;
redPlayerCount++;
if (redPlayerCount < 6)
{
playerId++;
// Used to link listboxes to tabpage indexes
int[] mapping = { redPlayerCount - 1, playerCount };
redMapping.Add(mapping);
listBox1.Items.Add("Player" + Convert.ToString(playerId));
// New player instance
Form2 form = new Form2(playerId, "Player" + Convert.ToString(playerId), "RED", tabControl1, listBox1, redMapping[redMapping.Count-1]);
// New tabpage to hold the instance
TabPage neu = new TabPage();
// Instance initilization
neu.BackColor = Color.Maroon;
form.Dock = DockStyle.Fill;
form.TopLevel = false;
form.WindowState = FormWindowState.Maximized;
// Add to the UI Display
red.Add(form);
neu.Controls.Add(red[redPlayerCount - 1]);
tabControl1.TabPages.Add(neu);
red[redPlayerCount - 1].Show();
tabControl1.SelectedIndex = playerCount;
idList.Add(playerId);
listBox1.SelectedIndex = redPlayerCount - 1;
}
else
{
playerCount--;
redPlayerCount--;
}
}
private void button2_Click(object sender, EventArgs e)
{
playerCount++;
bluePlayerCount++;
if (bluePlayerCount < 6)
{
playerId++;
int[] mapping = { bluePlayerCount - 1, playerCount };
blueMapping.Add(mapping);
listBox2.Items.Add("Player" + Convert.ToString(playerId));
Form2 form = new Form2(playerId, "Player" + Convert.ToString(playerId), "BLUE", tabControl1, listBox2, blueMapping[blueMapping.Count-1]);
TabPage neu = new TabPage();
neu.BackColor = Color.MidnightBlue;
form.Dock = DockStyle.Fill;
form.TopLevel = false;
form.WindowState = FormWindowState.Maximized;
blue.Add(form);
neu.Controls.Add(blue[bluePlayerCount - 1]);
tabControl1.TabPages.Add(neu);
blue[bluePlayerCount - 1].Show();
tabControl1.SelectedIndex = playerCount;
idList.Add(playerId);
listBox2.SelectedIndex = bluePlayerCount - 1;
}
else
{
playerCount--;
bluePlayerCount--;
}
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
foreach (int[] mapping in redMapping)
{
if (listBox1.SelectedIndex == mapping[0])
{
if (!(listBox2.SelectedIndex < 0))
listBox2.SelectedIndex = -1;
tabControl1.SelectedIndex = mapping[1];
}
}
}
private void listBox2_SelectedIndexChanged(object sender, EventArgs e)
{
foreach (int[] mapping in blueMapping)
{
if (listBox2.SelectedIndex == mapping[0])
{
if (!(listBox1.SelectedIndex < 0))
listBox1.SelectedIndex = -1;
tabControl1.SelectedIndex = mapping[1];
}
}
}
private void maximizeTrigger()
{
if (maximized)
{
button5.Text = "口";
this.WindowState = FormWindowState.Normal;
maximized = !maximized;
}
else
{
button5.Text = "▽";
this.WindowState = FormWindowState.Maximized;
maximized = !maximized;
}
setProgess(progressValue);
}
private void Form1_Load(object sender, EventArgs e)
{
if (debug) return;
if (!File.Exists("GameServerConsole.exe") || !Directory.Exists("Settings\\"))
{
MessageBox.Show("未找到服务器文件,请将本程序至于GameServerConsole.exe同级目录!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
Application.Exit();
}
}
private Game prepareBuild()
{
List<Player> players = new List<Player>();
for (int i = 0; i < redPlayerCount; i++)
{
/* public int playerId;
public string rank;
public string name;
public string champion;
public string team;
public string summoner1;
public string summoner2;
*/
Form2 builder = tabControl1.TabPages[redMapping[i][1]].Controls[0] as Form2;
players.Add(builder.buildPlayer());
}
for (int i = 0; i < bluePlayerCount; i++)
{
Form2 builder = tabControl1.TabPages[blueMapping[i][1]].Controls[0] as Form2;
players.Add(builder.buildPlayer());
}
setProgess(50);
button3.Text = "建立数据结构...";
return new Game(players, manacostsEnabled, cooldownsEnabled, cheatsEnabled, minionSpawnsEnabled, contentPath);
}
private string buildJson(Game game)
{
setProgess(75);
button3.Text = "构建Json...";
return JsonConvert.SerializeObject(game, Formatting.Indented);
}
private void button8_Click(object sender, EventArgs e)
{
tabControl1.SelectedIndex = 0;
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
if (Directory.Exists(textBox1.Text))
{
contentPath = textBox1.Text;
textBox1.ForeColor = Color.WhiteSmoke;
}
else textBox1.ForeColor = Color.Red;
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
cheatsEnabled = checkBox1.Checked;
}
private void checkBox2_CheckedChanged(object sender, EventArgs e)
{
manacostsEnabled = checkBox2.Checked;
}
private void checkBox3_CheckedChanged(object sender, EventArgs e)
{
cooldownsEnabled = checkBox3.Checked;
}
private void checkBox4_CheckedChanged(object sender, EventArgs e)
{
minionSpawnsEnabled = checkBox4.Checked;
}
private void checkBox5_CheckedChanged(object sender, EventArgs e)
{
label7.Visible = checkBox5.Checked;
checkBox5.ForeColor =
!checkBox5.Checked ?
Color.PaleGreen :
Color.OrangeRed ;
testingMode = checkBox5.Checked;
for (int i = 0; i < redPlayerCount; i++)
{
Form2 cache = tabControl1.TabPages[redMapping[i][1]].Controls[0] as Form2;
cache.updateTestMode();
}
for (int i = 0; i < bluePlayerCount; i++)
{
Form2 cache = tabControl1.TabPages[blueMapping[i][1]].Controls[0] as Form2;
cache.updateTestMode();
}
}
}
}