-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPlayerEditForm.cs
1015 lines (929 loc) · 38 KB
/
PlayerEditForm.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
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;
namespace NFL2K5Tool
{
public partial class PlayerEditForm : Form
{
private string[] mKeyParts;
private bool mInitializing = true;
/// <summary>
/// Constructor.
/// </summary>
public PlayerEditForm()
{
InitializeComponent();
mGenericFacePictureBox.Parent = null;
// issues setting these in the designer; too lazy to set the attributes on the controls to get it to work.
Position.Text = "Position";
Position.RepresentedValue = typeof(Positions);
Position.BorderStyle = BorderStyle.None;
}
private void UpdateGenericFacePictureBox()
{
// Get photo, Skin, Face;
// mGenericFacePictureBox.Visible = photo == NOPhoto;
// mGenericFacePictureBox.Image = GetGenericFace(skin, face);
StringSelectionControl pc = FindControl(mAppearanceTab, "Photo") as StringSelectionControl;
StringSelectionControl sc = FindControl(mAppearanceTab, "Skin") as StringSelectionControl;
StringSelectionControl fc = FindControl(mAppearanceTab, "Face") as StringSelectionControl;
/*if (pc != null && pc.Value == "NoPhoto")
{
mGenericFacePictureBox.Visible = true;
if (pc != null && sc != null && fc != null)
{
string fileName = ".\\PlayerData\\GenericFaces\\" + sc.Value.Replace("kin", "") + fc.Value.Replace("ace", "") + ".jpg";
mGenericFacePictureBox.ImageLocation = fileName;
}
if(mGenericFacePictureBox.Parent == null)
mGenericFacePictureBox.Parent = mAppearanceTab;
}
else
{
mGenericFacePictureBox.Visible = false;
}*/
mGenericFacePictureBox.ImageLocation = null;
if ( fc.Value.Length > 1)
{
mGenericFacePictureBox.Visible = true;
try
{
Face f = (Face)Enum.Parse(typeof(Face), fc.Value);
Skin s = (Skin)Enum.Parse(typeof(Skin), sc.Value);
FaceData data = GetFace(s, f);
if (data != null)
{
string path = String.Format(
"PlayerData\\PlayerModelFaces\\Generic\\{0:x8}.jpg",
data.faceModelTexture);
mGenericFacePictureBox.ImageLocation = path;
if (mGenericFacePictureBox.Parent == null)
mGenericFacePictureBox.Parent = mAppearanceTab;
}
}
catch { }
}
}
/// <summary>
/// the colleges.
/// </summary>
public string[] Colleges { get; set; }
/// <summary>
/// PBP names
/// </summary>
public Dictionary<string, string> ReversePBPs { get; set; }
/// <summary>
/// Photo names
/// </summary>
public Dictionary<string,string> ReversePhotos { get; set; }
/// <summary>
/// PBP names
/// </summary>
public Dictionary<string, string> PBPs { get; set; }
/// <summary>
/// Photo names
/// </summary>
public Dictionary<string, string> Photos { get; set; }
private string mData = "";
/// <summary>
/// The text corresponding to all the text in the main GUI.
/// </summary>
public string Data
{
get { return mData; }
set
{
mData = value;
SetupTeams();
SetupGui();
}
}
private string mKeyString = "";
private const string mSkillsString = "Speed,Agility,Strength,Jumping,Coverage,PassRush,RunCoverage,PassBlocking,RunBlocking,Catch,RunRoute,BreakTackle,HoldOntoBall,PowerRunStyle,PassAccuracy,PassArmStrength,PassReadCoverage,Tackle,KickPower,KickAccuracy,Stamina,Durability,Leadership,Scramble,Composure,Consistency,Aggressiveness,";
private const string mAppearanceString = "JerseyNumber,College,DOB,PBP,Photo,YearsPro,Hand,Weight,Height,BodyType,Skin,Face,Dreads,Helmet,FaceMask,Visor,EyeBlack,MouthPiece,LeftGlove,RightGlove,LeftWrist,RightWrist,LeftElbow,RightElbow,Sleeves,LeftShoe,RightShoe,NeckRoll,Turtleneck,";
/// <summary>
/// Returns true when a new key is set, false if it's the same key
/// </summary>
private bool SetupKey()
{
bool retVal = false;
Regex keyReg = new Regex("[\\s]*[#|Key=](Position,fname,lname,.*)", RegexOptions.IgnoreCase);
Match m = keyReg.Match(Data);
if (m != Match.Empty )
{
if (mKeyString != m.Groups[1].Value)
{
mKeyString = m.Groups[1].Value;
mKeyParts = mKeyString.Split(new char[] { ',' });
retVal = true;
}
}
else
{
throw new InvalidOperationException("Please make sure the key '#Position,fname,lname...' is present at the top of the text box. (Did you list content yet?)");
}
return retVal;
}
/// <summary>
/// Initializes the Form.
/// Call this after Colleges, Photos & PBPs have been set.
/// </summary>
private void SetupGui()
{
if (SetupKey())
{
ClearControls(mSkillsTab);
ClearControls(mAppearanceTab);
foreach (string attr in mKeyParts)
{
if (attr.Length > 0 && mSkillsString.IndexOf(attr + ",") > -1)
{
AddSkill(attr);
}
}
foreach (string attr in mKeyParts)
{
if (attr.Length > 0 && mAppearanceString.IndexOf(attr + ",") > -1)
{
AddAppearance(attr);
}
}
if (mSkillsTab.Controls.Count == 0 && mAppearanceTab.Controls.Count > 0)
{
tabControl1.SelectedIndex = 1;
}
}
}
List<FaceData> mGenericFaces = null;
private FaceData GetFace(Skin s, Face f)
{
if( mGenericFaces == null )
mGenericFaces = FaceData.GetGenericFaces();
foreach (FaceData data in mGenericFaces)
{
if (data.skin == s && data.face == f)
return data;
}
return null;
}
/// <summary>
/// Clears and disposed of the child controls on parentControl.
/// </summary>
private void ClearControls(Control parentControl)
{
Control c = null;
IntAttrControl iac = null;
StringSelectionControl ssc = null;
for (int i = parentControl.Controls.Count - 1; i > -1; i--)
{
c = parentControl.Controls[i];
parentControl.Controls.Remove(c);
ssc = c as StringSelectionControl;
iac = c as IntAttrControl;
if( ssc != null)
ssc.ValueChanged -= new EventHandler(ValueChanged);
else if( iac != null)
iac.ValueChanged -= new EventHandler(ValueChanged);
c.Dispose();
}
}
private void AddSkill(string skill)
{
Control c = null;
if (skill == "PowerRunStyle")
{
StringSelectionControl ssc = new StringSelectionControl();
ssc.RepresentedValue = typeof(PowerRunStyle);
ssc.Name = ssc.Text = skill;
ssc.ValueChanged += new EventHandler(ValueChanged);
c = ssc;
}
else
{
IntAttrControl iac = new IntAttrControl();
iac.Name = iac.Text = skill;
iac.ValueChanged += new EventHandler(ValueChanged);
c = iac;
}
int row = mSkillsTab.Controls.Count / 5;
int col = mSkillsTab.Controls.Count % 5;
c.Location = new Point(col * c.Width, row * c.Height);
mSkillsTab.Controls.Add(c);
}
private void AddAppearance(string appearance)
{
Control c = null;
IntAttrControl intAttrCtrl = null;
StringSelectionControl ctrl = null;
if( "Weight,DOB,YearsPro,JerseyNumber,".IndexOf(appearance+",") > -1)
{
switch( appearance)
{
case "JerseyNumber":
intAttrCtrl = new IntAttrControl();
intAttrCtrl.Name = intAttrCtrl.Text = appearance;
intAttrCtrl.Max = 99;
intAttrCtrl.ValueChanged += new EventHandler(jersey_ValueChanged);
break;
case "YearsPro":
intAttrCtrl = new IntAttrControl();
intAttrCtrl.Name = intAttrCtrl.Text = appearance;
intAttrCtrl.Max = 99;
break;
case "Weight":
intAttrCtrl = new IntAttrControl();
intAttrCtrl.Name = intAttrCtrl.Text = appearance;
intAttrCtrl.Min = 150;
intAttrCtrl.Max = intAttrCtrl.Min + 255;
intAttrCtrl.ValueChanged += new EventHandler(weight_ValueChanged);
break;
case "DOB":
DateValueControl dvc = new DateValueControl();
dvc.Name = dvc.Text = appearance;
dvc.ValueChanged += new EventHandler(ValueChanged);
c = dvc;
break;
}
}
else if( "Hand,BodyType,Skin,Face,MouthPiece,EyeBlack,Dreads,Helmet,Sleeves,Visor,Turtleneck,Height,College,PBP,".IndexOf(appearance+",") > -1) {
ctrl = new StringSelectionControl();
ctrl.Name = ctrl.Text = appearance;
switch (appearance)
{
case "Hand": ctrl.RepresentedValue = typeof(Hand); break;
case "BodyType":
ctrl.RepresentedValue = typeof(Body);
ctrl.ValueChanged += new EventHandler(bodyType_ValueChanged);
break;
case "Skin":
ctrl.RepresentedValue = typeof(Skin);
ctrl.ValueChanged += new EventHandler(skin_ValueChanged);
break;
case "Face":
ctrl.RepresentedValue = typeof(Face);
ctrl.ValueChanged += new EventHandler(face_ValueChanged);
break;
case "MouthPiece":
case "EyeBlack":
case "Dreads": ctrl.RepresentedValue = typeof(YesNo); break;
case "Helmet": ctrl.RepresentedValue = typeof(Helmet); break;
case "Sleeves": ctrl.RepresentedValue = typeof(Sleeves); break;
case "Visor": ctrl.RepresentedValue = typeof(Visor); break;
case "Turtleneck": ctrl.RepresentedValue = typeof(Turtleneck); break;
case "Height": //5'6"-7'0"
ctrl.SetItems(new string[] {
"5'6\"", "5'7\"", "5'8\"", "5'9\"", "5'10\"", "5'11\"",
"6'0\"", "6'1\"", "6'2\"", "6'3\"", "6'4\"", "6'5\"",
"6'6\"", "6'7\"", "6'8\"", "6'9\"", "6'10\"", "6'11\"",
"7'0\"" });
ctrl.ValueChanged += new EventHandler(height_ValueChanged);
break;
case "College":
ctrl.DropDownStyle = ComboBoxStyle.DropDown;
ctrl.SetItems(Colleges);
break;
case "PBP":
string[] values = new string[this.ReversePBPs.Count];
this.ReversePBPs.Values.CopyTo(values, 0);
ctrl.SetItems(values);
ctrl.DropDownStyle = ComboBoxStyle.DropDown;
break;
}
}
else
{
ctrl = new PictureChooser();
ctrl.Name = ctrl.Text = appearance;
ctrl.ValueChanged += new EventHandler(PictureChooser_ValueChanged);
switch(appearance)
{
// need to special case the setting of these items.
case "FaceMask": ctrl.RepresentedValue = typeof(FaceMask); break;
case "LeftElbow":
case "RightElbow": ctrl.RepresentedValue = typeof(Elbow); break;
case "LeftGlove":
case "RightGlove": ctrl.RepresentedValue = typeof(Glove); break;
case "LeftWrist":
case "RightWrist": ctrl.RepresentedValue = typeof(Wrist); break;
case "LeftShoe":
case "RightShoe": ctrl.RepresentedValue = typeof(Shoe); break;
case "NeckRoll": ctrl.RepresentedValue = typeof(NeckRoll); break;
case "Photo":
ctrl.DropDownStyle = ComboBoxStyle.DropDown;
ctrl.ValueChanged += new EventHandler(PictureChooser_ValueChanged);
string[] vals = new string[this.ReversePhotos.Count];
this.ReversePhotos.Values.CopyTo(vals, 0);
ctrl.SetItems(vals);
break;
}
}
if (intAttrCtrl != null)
{
intAttrCtrl.ValueChanged += new EventHandler(ValueChanged);
c = intAttrCtrl;
}
else if (ctrl != null)
{
ctrl.ValueChanged += new EventHandler(ValueChanged);
c = ctrl;
}
if (c != null)
{
int row = mAppearanceTab.Controls.Count / 5;
int col = mAppearanceTab.Controls.Count % 5;
c.Location = new Point(col * c.Width, row * c.Height);
mAppearanceTab.Controls.Add(c);
}
}
void jersey_ValueChanged(object sender, EventArgs e)
{
IntAttrControl ctrl = sender as IntAttrControl;
mJerseyNumberLabel.Text = "#"+ctrl.Value;
}
void bodyType_ValueChanged(object sender, EventArgs e)
{
StringSelectionControl ctrl = sender as StringSelectionControl;
mBodyTypeLabel.Text = "Body Type:" + ctrl.Value;
}
void face_ValueChanged(object sender, EventArgs e)
{
UpdateGenericFacePictureBox();
}
void skin_ValueChanged(object sender, EventArgs e)
{
StringSelectionControl ctrl = sender as StringSelectionControl;
mSkinColorLabel.Text = ctrl.Value;
Color backColor = Color.Black;
Color foreColor = Color.White;
switch (mSkinColorLabel.Text)
{
case "Skin1":// white guys
case "Skin9":
case "Skin17":
backColor = Color.FromArgb(242, 212, 202);
foreColor = Color.Black;
break;
case "Skin2": // mixed White&black(light) guys, Samoans
case "Skin18": // mixed White&black(light) guys, Samoans, Latino, White,
backColor = Color.FromArgb(200, 140, 132);
break;
case "Skin3": // inconsistently assigned
backColor = Color.FromArgb(142, 92, 79);
break;
case "Skin4":
backColor = Color.FromArgb(123,75, 65);
break;
case "Skin5":
backColor = Color.FromArgb(101,61 ,53 );
break;
case "Skin6":
backColor = Color.FromArgb(78,47 ,42 );
break;
//case "Skin7": No one has these
// c = Color.FromArgb(, , );
// break;
//case "Skin8":
// c = Color.FromArgb(, , );
// break;
//case "Skin15":
// c = Color.FromArgb(, , );
// break;
//case "Skin16":
// c = Color.FromArgb(, , );
// break;
case "Skin10":
backColor = Color.FromArgb(163,106 ,95 );
break;
case "Skin11":
backColor = Color.FromArgb(198,141 ,130 );
break;
case "Skin12":
backColor = Color.FromArgb(101,61 ,53 );
break;
case "Skin13":
backColor = Color.FromArgb(123,75 ,65 );
break;
case "Skin14":
backColor = Color.FromArgb(100,62 ,49 );
break;
case "Skin19":
backColor = Color.FromArgb(101,61 ,53 );
break;
case "Skin20":
backColor = Color.FromArgb(102,62 ,53 );
break;
case "Skin21": // pretty dark skin tone
backColor = Color.FromArgb(90,55 ,48 );
break;
case "Skin22": // generally the darkest skin tone
backColor = Color.FromArgb(72, 45,38 );
break;
}
mSkinColorLabel.BackColor = backColor;
mSkinColorLabel.ForeColor = foreColor;
UpdateGenericFacePictureBox();
}
void height_ValueChanged(object sender, EventArgs e)
{
StringSelectionControl ctrl = sender as StringSelectionControl;
mHeightLabel.Text = ctrl.Value;
}
void weight_ValueChanged(object sender, EventArgs e)
{
IntAttrControl ctrl = sender as IntAttrControl;
mWeightLabel.Text = ctrl.Value + " lbs";
}
void PictureChooser_ValueChanged(object sender, EventArgs e)
{
string path = "";
PictureChooser chooser = sender as PictureChooser;
if (chooser == null) return;
switch (chooser.Name)
{
case "Photo":
string dude = DataMap.PhotoMap[chooser.Value];
path = String.Format("PlayerData\\PlayerPhotos\\{0}.jpg", dude);
string noPhoto = "PlayerData\\PlayerPhotos\\0004.jpg";
if (System.IO.File.Exists(path))
chooser.PictureBox.ImageLocation = path;
else if (System.IO.File.Exists(noPhoto))
chooser.PictureBox.ImageLocation = noPhoto;
mFacePictureBox.ImageLocation = chooser.PictureBox.ImageLocation;
UpdateGenericFacePictureBox();
break;
case "FaceMask":
path = String.Format("PlayerData\\EquipmentImages\\{0}.jpg", chooser.Value);
if (System.IO.File.Exists(path))
chooser.PictureBox.ImageLocation = path;
else
chooser.PictureBox.ImageLocation = null;
mFaceMaskPictureBox.ImageLocation = chooser.PictureBox.ImageLocation;
break;
case "RightShoe":
case "LeftShoe":
path = String.Format("PlayerData\\EquipmentImages\\{0}.jpg", chooser.Value);
if (System.IO.File.Exists(path))
chooser.PictureBox.ImageLocation = path;
else
chooser.PictureBox.ImageLocation = null;
break;
// elbow == incomplete
case "RightElbow":
case "LeftElbow":
case "RightWrist":
case "LeftWrist":
case "NeckRoll":
case "LeftGlove":
case "RightGlove":
path = String.Format("PlayerData\\EquipmentImages\\{0}{1}.jpg",chooser.RepresentedValue.Name, chooser.Value);
if (System.IO.File.Exists(path))
chooser.PictureBox.ImageLocation = path;
else
chooser.PictureBox.ImageLocation = null;
break;
}
}
/// <summary>
/// Get and set the current team.
/// </summary>
public string CurrentTeam
{
get { return this.m_TeamsComboBox.SelectedItem.ToString(); }
set
{
int index = m_TeamsComboBox.Items.IndexOf(value);
if (index > -1)
{
m_TeamsComboBox.SelectedIndex = index;
string[] players = GetTeamPlayers(value);
if (players != null)
mPlayerIndexUpDown.Maximum = players.Length;
else
mPlayerIndexUpDown.Maximum = 0;
}
}
}
private int mSelectionStart = 0;
/// <summary>
/// The position in the text that the user clicked.
/// (We use this to figure out the player we're editing)
/// </summary>
public int SelectionStart
{
get { return mSelectionStart; }
set
{
if (mSelectionStart != value)
{
int oldVal = mSelectionStart;
mSelectionStart = value;
OnSelectionStartChanged(oldVal, mSelectionStart);
}
}
}
private void OnSelectionStartChanged(int oldVal, int newValue)
{
string playerLine = InputParser.GetLine(newValue, Data);
string team = InputParser.GetTeam(newValue, Data);
int index = m_TeamsComboBox.Items.IndexOf(team);
if (index > -1)
{
m_TeamsComboBox.SelectedIndex = index;
}
string[] players = GetTeamPlayers(team);
if (players != null)
{
for (int i = 0; i < players.Length; i++)
{
if (players[i].StartsWith(playerLine))
{
mPlayerIndexUpDown.Value = i;
break;
}
}
SetCurrentPlayer();
mInitializing = false; // keep it here, initialization failed
this.mPlayerIndexUpDown.Maximum = players.Length - 1;
UpdateGenericFacePictureBox();
}
}
private void SetupTeams()
{
Regex teamRegex = new Regex("TEAM\\s*=\\s*([a-z0-9]+)", RegexOptions.IgnoreCase);
MatchCollection mc = teamRegex.Matches(Data);
m_TeamsComboBox.Items.Clear();
m_TeamsComboBox.BeginUpdate();
foreach (Match m in mc)
{
string team = m.Groups[1].Value;
m_TeamsComboBox.Items.Add(team);
}
m_TeamsComboBox.EndUpdate();
if (m_TeamsComboBox.Items.Count > 0)
{
m_TeamsComboBox.SelectedItem = m_TeamsComboBox.Items[0];
}
}
/// <summary>
/// Replaces the current player with the values specified.
/// </summary>
private void ReplacePlayer()
{
string oldPlayer = GetPlayerString(m_TeamsComboBox.SelectedItem.ToString(),
(int)mPlayerIndexUpDown.Value);
if (oldPlayer == null)
return;
string newPlayer = GetPlayerString_UI();
string team = m_TeamsComboBox.Items[m_TeamsComboBox.SelectedIndex].ToString();
ReplacePlayer(team, oldPlayer, newPlayer);
}
private void ReplacePlayer(string team, string oldPlayer, string newPlayer)
{
int nextTeamIndex = -1;
int currentTeamIndex = -1;
string nextTeam = null;
Regex findTeamRegex = new Regex("TEAM\\s*=\\s*" + team, RegexOptions.IgnoreCase);
Match m = findTeamRegex.Match(Data);
if (!m.Success)
return;
currentTeamIndex = m.Groups[1].Index;
int test = m_TeamsComboBox.Items.IndexOf(team);
if (test != m_TeamsComboBox.Items.Count - 1)
{
nextTeam = string.Format("TEAM\\s*=\\s*{0}", m_TeamsComboBox.Items[test + 1]);
Regex nextTeamRegex = new Regex(nextTeam);
Match nt = nextTeamRegex.Match(Data);
if (nt.Success)
nextTeamIndex = nt.Index;
}
if (nextTeamIndex < 0)
nextTeamIndex = Data.Length;
int playerIndex = Data.IndexOf(oldPlayer, currentTeamIndex);
if (playerIndex > -1)
{
int endLine = Data.IndexOf('\n', playerIndex);
string start = Data.Substring(0, playerIndex);
string last = Data.Substring(endLine);
StringBuilder tmp = new StringBuilder(Data.Length + 200);
tmp.Append(start);
tmp.Append(newPlayer);
tmp.Append(last);
mData = tmp.ToString();
}
else
{
StaticUtils.AddError( string.Concat(
"An error occured looking up player ", oldPlayer,
"\nPlease verify that this player's attributes are correct."));
}
}
/// <summary>
/// Updates the GUI with the current player.
/// </summary>
private void SetCurrentPlayer()
{
if (m_TeamsComboBox.SelectedItem != null)
{
string team = m_TeamsComboBox.SelectedItem.ToString();
int index = (int)mPlayerIndexUpDown.Value;
string playerData = GetPlayerString(team, index);
if (playerData != null)
SetPlayerData(playerData);
}
}
/// <summary>
/// Updates the GUI with the player 'line' passed.
/// </summary>
public void SetPlayerData(string playerLine)
{
List<string> playerParts = InputParser.ParsePlayerLine(playerLine);
for (int i = 0; i < playerParts.Count; i++)
SetControlValue(mKeyParts[i], playerParts[i]);
}
private void SetControlValue(string controlName, string val)
{
if (!SetControlValue(mSkillsTab, controlName, val))
if (!SetControlValue(mAppearanceTab, controlName, val))
SetControlValue(this, controlName, val);
}
private bool SetControlValue(Control parentControl, string controlName, string val)
{
foreach (Control c in parentControl.Controls)
{
if (c.Name == controlName)
{
IntAttrControl iac = c as IntAttrControl;
StringSelectionControl ssc = c as StringSelectionControl;
DateValueControl dvc = c as DateValueControl;
if (iac != null)
{
iac.Value = Int32.Parse(val);
return true;
}
else if (dvc != null)
{
dvc.Value = val;
return true;
}
else if (ssc != null)
{
if (controlName == "PBP")
{
if (ReversePBPs.ContainsKey(val))
{
ssc.Value = ReversePBPs[val];
return true;
}
}
else if (controlName == "Photo")
{
if (ReversePhotos.ContainsKey(val))
ssc.Value = ReversePhotos[val];
else
ssc.Value = "NoPhoto";
return true;
}
else if (controlName == "College")
{
if (val[0] == '"')
val = val.Replace("\"", "");
ssc.Value = val;
return true;
}
else
{
ssc.Value = val;
return true;
}
}
else
{
c.Text = val;
return true;
}
}
}
return false;
}
/// <summary>
/// returns null when control is not found, control value otherwise
/// </summary>
private string GetControlValue(string controlName)
{
string retVal = "";
if ((retVal = GetControlValue(mSkillsTab, controlName)) == null )
if((retVal = GetControlValue(mAppearanceTab, controlName)) == null)
retVal = GetControlValue(this, controlName);
return retVal;
}
/// <summary>
/// returns null when control is not found, control value otherwise
/// </summary>
private string GetControlValue(Control parentControl, string controlName)
{
Control c = FindControl(parentControl, controlName);
if (c != null)
{
TextBox tb = c as TextBox;
IntAttrControl iac = c as IntAttrControl;
StringSelectionControl ssc = c as StringSelectionControl;
DateValueControl dvc = c as DateValueControl;
if (iac != null)
return iac.Value.ToString();
else if (dvc != null)
return dvc.Value;
else if (ssc != null)
{
if (controlName == "PBP" && PBPs.ContainsKey(ssc.Value))
{
return PBPs[ssc.Value];
}
else if (controlName == "Photo" && Photos.ContainsKey(ssc.Value))
{
return Photos[ssc.Value];
}
else if (controlName == "College" && ssc.Value.IndexOf(',') > -1)
return string.Concat("\"", ssc.Value, "\"");
return ssc.Value;
}
else if (tb != null)
return tb.Text;
}
return null;
}
private Control FindControl(Control parentControl, string controlName)
{
foreach (Control c in parentControl.Controls)
if (c.Name == controlName)
return c;
return null;
}
/// <summary>
/// Gets a player 'line' from Data from 'team' playing 'position'.
/// </summary>
/// <param name="team">The team</param>
/// <param name="playerIndex">the player index on the team</param>
/// <returns>the player line </returns>
private string GetPlayerString(string team, int playerIndex)
{
string[] players = GetTeamPlayers(team);
if (players != null && playerIndex < players.Length)
return players[playerIndex];
return null;
}
private string[] GetTeamPlayers(string team)
{
Regex findTeamRegex = new Regex("TEAM\\s*=\\s*" + team, RegexOptions.IgnoreCase);
Regex nextTeam = new Regex("TEAM\\s*=\\s*", RegexOptions.IgnoreCase);
Regex player = new Regex("(K,.+)|(QB,.+)|(P,.+)|(WR,.+)|(CB,.+)|(FS,.+)|(SS,.+)|(RB,.+)|(FB,.+)|(TE,.+)|(OLB,.+)|(ILB,.+)|(C,.+)|(G,.+)|(T,.+)|(DT,.+)|(DE,.+)");
Match m = findTeamRegex.Match(Data);
Match m2;
string chunk = "";
if (m != Match.Empty)
{
m2 = nextTeam.Match(Data, m.Index + m.Length);
int end = Data.Length;
if (m2 != Match.Empty)
end = m2.Index;
chunk = Data.Substring(m.Index, end - m.Index);
MatchCollection mc = player.Matches(chunk);
if (mc.Count > 0)
{
string[] retVal = new string[mc.Count];
for (int i = 0; i < retVal.Length; i++)
retVal[i] = mc[i].Value;
return retVal;
}
}
return null;
}
/// <summary>
/// Returns the text representation of what the GUI is presenting.
/// </summary>
public string GetPlayerString_UI()
{
StringBuilder sb = new StringBuilder(300);
string a = "";
for (int i = 0; i < mKeyParts.Length; i++)
{
a = GetControlValue(mKeyParts[i]);
if (!String.IsNullOrEmpty(a))
{
sb.Append(a);
sb.Append(",");
}
}
return sb.ToString();
}
private void mPreviousButton_Click(object sender, EventArgs e)
{
if (mPlayerIndexUpDown.Value > 0)
mPlayerIndexUpDown.Value--;
else if (m_TeamsComboBox.SelectedIndex > 0)
m_TeamsComboBox.SelectedIndex--;
SetCurrentPlayer();
}
private void mNextButton_Click(object sender, EventArgs e)
{
string[] players = GetTeamPlayers(m_TeamsComboBox.SelectedItem.ToString());
if (mPlayerIndexUpDown.Value < players.Length-1)
mPlayerIndexUpDown.Value++;
else if (m_TeamsComboBox.SelectedIndex < m_TeamsComboBox.Items.Count-1)
m_TeamsComboBox.SelectedIndex++;
else
m_TeamsComboBox.SelectedIndex = 0;
SetCurrentPlayer();
}
private void m_TeamsComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
SetMaxPlayerIndex();
}
private void SetMaxPlayerIndex()
{
if (!mInitializing)
{
string[] players = GetTeamPlayers(m_TeamsComboBox.SelectedItem.ToString());
if (players != null)
{
mPlayerIndexUpDown.Value = 0;
mPlayerIndexUpDown.Maximum = players.Length - 1;
SetCurrentPlayer();
}
}
}
private void mPlayerIndexUpDown_ValueChanged(object sender, EventArgs e)
{
mInitializing = true;
SetCurrentPlayer();
mInitializing = false;
}
private void mOkButton_Click(object sender, EventArgs e)
{
ReplacePlayer();
}
private void ValueChanged(object sender, System.EventArgs e)
{
if (!mInitializing)
{
ReplacePlayer();
}
}
private void button1_Click(object sender, EventArgs e)
{
string newPlayer = GetPlayerString_UI();
MessageBox.Show(newPlayer);
}
private void mSkinColorLabel_Click(object sender, EventArgs e)
{
tabControl1.SelectedIndex = 1;
Control c = FindControl(mAppearanceTab, "Skin");
if (c != null) c.Focus();
}
private void mHeightLabel_Click(object sender, EventArgs e)
{
tabControl1.SelectedIndex = 1;
Control c = FindControl(mAppearanceTab, "Height");
if (c != null) c.Focus();
}
private void mWeightLabel_Click(object sender, EventArgs e)
{
tabControl1.SelectedIndex = 1;
Control c = FindControl(mAppearanceTab, "Weight");
if (c != null) c.Focus();
}
private void mBodyTypeLabel_Click(object sender, EventArgs e)
{
tabControl1.SelectedIndex = 1;
Control c = FindControl(mAppearanceTab, "BodyType");
if (c != null) c.Focus();
}
static FaceForm sFaceForm = null;
private void mFacePictureBox_Click(object sender, EventArgs e)
{
if( sFaceForm == null)
sFaceForm = new FaceForm();
if (sFaceForm.ShowDialog(this) == DialogResult.OK)
{
SetControlValue("Photo", sFaceForm.SelectedFace);
}
//form.Dispose();
}
private void copyPlayerNameToolStripMenuItem_Click(object sender, EventArgs e)