forked from Agorath/ChummerGenSR4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ContactControl.cs
431 lines (388 loc) · 13.1 KB
/
ContactControl.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
using System;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
// ConnectionRatingChanged Event Handler.
public delegate void ConnectionRatingChangedHandler(Object sender);
// GroupRatingChanged Event Handler.
public delegate void ConnectionGroupRatingChangedHandler(Object sender);
// LoyaltyRatingChanged Event Handler.
public delegate void LoyaltyRatingChangedHandler(Object sender);
// DeleteContact Event Handler.
public delegate void DeleteContactHandler(Object sender);
// FileNameChanged Event Handler.
public delegate void FileNameChangedHandler(Object sender);
namespace Chummer
{
public partial class ContactControl : UserControl
{
private Contact _objContact;
// Events.
public event ConnectionRatingChangedHandler ConnectionRatingChanged;
public event ConnectionGroupRatingChangedHandler ConnectionGroupRatingChanged;
public event LoyaltyRatingChangedHandler LoyaltyRatingChanged;
public event DeleteContactHandler DeleteContact;
public event FileNameChangedHandler FileNameChanged;
#region Control Events
public ContactControl()
{
InitializeComponent();
LanguageManager.Instance.Load(GlobalOptions.Instance.Language, this);
}
private void ContactControl_Load(object sender, EventArgs e)
{
this.Width = cmdDelete.Left + cmdDelete.Width;
tipTooltip.SetToolTip(cmdGroup, LanguageManager.Instance.GetString("Title_SelectContactConnection"));
}
private void nudConnection_ValueChanged(object sender, EventArgs e)
{
// Raise the ConnectionGroupRatingChanged Event when the NumericUpDown's Value changes.
// The entire ContactControl is passed as an argument so the handling event can evaluate its contents.
_objContact.Connection = Convert.ToInt32(nudConnection.Value);
ConnectionRatingChanged(this);
}
private void nudLoyalty_ValueChanged(object sender, EventArgs e)
{
// Raise the LoyaltyRatingChanged Event when the NumericUpDown's Value changes.
// The entire ContactControl is passed as an argument so the handling event can evaluate its contents.
_objContact.Loyalty = Convert.ToInt32(nudLoyalty.Value);
LoyaltyRatingChanged(this);
}
private void cmdDelete_Click(object sender, EventArgs e)
{
// Raise the DeleteContact Event when the user has confirmed their desire to delete the Contact.
// The entire ContactControl is passed as an argument so the handling event can evaluate its contents.
DeleteContact(this);
}
private void txtContactName_TextChanged(object sender, EventArgs e)
{
_objContact.Name = txtContactName.Text;
}
private void imgLink_Click(object sender, EventArgs e)
{
// Determine which options should be shown based on the FileName value.
if (_objContact.FileName != "")
{
tsAttachCharacter.Visible = false;
tsContactOpen.Visible = true;
tsRemoveCharacter.Visible = true;
}
else
{
tsAttachCharacter.Visible = true;
tsContactOpen.Visible = false;
tsRemoveCharacter.Visible = false;
}
cmsContact.Show(imgLink, imgLink.Left - 490, imgLink.Top);
}
private void tsContactOpen_Click(object sender, EventArgs e)
{
bool blnError = false;
bool blnUseRelative = false;
// Make sure the file still exists before attempting to load it.
if (!File.Exists(_objContact.FileName))
{
// If the file doesn't exist, use the relative path if one is available.
if (_objContact.RelativeFileName == "")
blnError = true;
else
{
MessageBox.Show(Path.GetFullPath(_objContact.RelativeFileName));
if (!File.Exists(Path.GetFullPath(_objContact.RelativeFileName)))
blnError = true;
else
blnUseRelative = true;
}
if (blnError)
{
MessageBox.Show(LanguageManager.Instance.GetString("Message_FileNotFound").Replace("{0}", _objContact.FileName), LanguageManager.Instance.GetString("MessageTitle_FileNotFound"), MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
if (!blnUseRelative)
GlobalOptions.Instance.MainForm.LoadCharacter(_objContact.FileName, false);
else
{
string strFile = Path.GetFullPath(_objContact.RelativeFileName);
GlobalOptions.Instance.MainForm.LoadCharacter(strFile, false);
}
}
private void tsAttachCharacter_Click(object sender, EventArgs e)
{
// Prompt the user to select a save file to associate with this Contact.
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "Chummer Files (*.chum)|*.chum|All Files (*.*)|*.*";
if (openFileDialog.ShowDialog(this) == DialogResult.OK)
{
_objContact.FileName = openFileDialog.FileName;
if (_objContact.EntityType == ContactType.Enemy)
tipTooltip.SetToolTip(imgLink, LanguageManager.Instance.GetString("Tip_Enemy_OpenFile"));
else
tipTooltip.SetToolTip(imgLink, LanguageManager.Instance.GetString("Tip_Contact_OpenFile"));
// Set the relative path.
Uri uriApplication = new Uri(@Application.StartupPath);
Uri uriFile = new Uri(@_objContact.FileName);
Uri uriRelative = uriApplication.MakeRelativeUri(uriFile);
_objContact.RelativeFileName = "../" + uriRelative.ToString();
FileNameChanged(this);
}
}
private void tsRemoveCharacter_Click(object sender, EventArgs e)
{
// Remove the file association from the Contact.
if (MessageBox.Show(LanguageManager.Instance.GetString("Message_RemoveCharacterAssociation"), LanguageManager.Instance.GetString("MessageTitle_RemoveCharacterAssociation"), MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
_objContact.FileName = "";
_objContact.RelativeFileName = "";
if (_objContact.EntityType == ContactType.Enemy)
tipTooltip.SetToolTip(imgLink, LanguageManager.Instance.GetString("Tip_Enemy_LinkFile"));
else
tipTooltip.SetToolTip(imgLink, LanguageManager.Instance.GetString("Tip_Contact_LinkFile"));
FileNameChanged(this);
}
}
private void cmdGroup_Click(object sender, EventArgs e)
{
frmSelectContactConnection frmPickContactConnection = new frmSelectContactConnection();
frmPickContactConnection.Membership = _objContact.Membership;
frmPickContactConnection.AreaOfInfluence = _objContact.AreaOfInfluence;
frmPickContactConnection.MagicalResources = _objContact.MagicalResources;
frmPickContactConnection.MatrixResources = _objContact.MatrixResources;
frmPickContactConnection.GroupName = _objContact.GroupName;
frmPickContactConnection.Colour = _objContact.Colour;
frmPickContactConnection.Free = _objContact.Free;
frmPickContactConnection.ShowDialog(this);
if (frmPickContactConnection.DialogResult == DialogResult.Cancel)
return;
// Update the Connection Modifier values.
_objContact.Membership = frmPickContactConnection.Membership;
_objContact.AreaOfInfluence = frmPickContactConnection.AreaOfInfluence;
_objContact.MagicalResources = frmPickContactConnection.MagicalResources;
_objContact.MatrixResources = frmPickContactConnection.MatrixResources;
_objContact.GroupName = frmPickContactConnection.GroupName;
_objContact.Colour = frmPickContactConnection.Colour;
_objContact.Free = frmPickContactConnection.Free;
lblGroup.Text = (_objContact.Membership + _objContact.AreaOfInfluence + _objContact.MagicalResources + _objContact.MatrixResources).ToString();
if (_objContact.Colour.Name != "White" && _objContact.Colour.Name != "Black")
this.BackColor = _objContact.Colour;
else
this.BackColor = SystemColors.Control;
ConnectionGroupRatingChanged(this);
}
private void imgNotes_Click(object sender, EventArgs e)
{
frmNotes frmContactNotes = new frmNotes();
frmContactNotes.Notes = _objContact.Notes;
frmContactNotes.ShowDialog(this);
if (frmContactNotes.DialogResult == DialogResult.OK)
_objContact.Notes = frmContactNotes.Notes;
string strTooltip = "";
if (_objContact.EntityType == ContactType.Enemy)
strTooltip = LanguageManager.Instance.GetString("Tip_Enemy_EditNotes");
else
strTooltip = LanguageManager.Instance.GetString("Tip_Contact_EditNotes");
if (_objContact.Notes != string.Empty)
strTooltip += "\n\n" + _objContact.Notes;
tipTooltip.SetToolTip(imgNotes, strTooltip);
}
private void cmsContact_Opening(object sender, CancelEventArgs e)
{
foreach (ToolStripItem objItem in ((ContextMenuStrip)sender).Items)
{
if (objItem.Tag != null)
{
objItem.Text = LanguageManager.Instance.GetString(objItem.Tag.ToString());
}
}
}
#endregion
#region Properties
/// <summary>
/// Contact object this is linked to.
/// </summary>
public Contact ContactObject
{
get
{
return _objContact;
}
set
{
_objContact = value;
}
}
/// <summary>
/// Contact name.
/// </summary>
public string ContactName
{
get
{
return _objContact.Name;
}
set
{
txtContactName.Text = value;
_objContact.Name = value;
}
}
/// <summary>
/// Indicates if this is a Contact or Enemy.
/// </summary>
public ContactType EntityType
{
get
{
return _objContact.EntityType;
}
set
{
_objContact.EntityType = value;
if (value == ContactType.Enemy)
{
lblLoyalty.Text = LanguageManager.Instance.GetString("Label_Enemy_Incidence");
lblGroup.Text = (_objContact.Membership + _objContact.AreaOfInfluence + _objContact.MagicalResources + _objContact.MatrixResources).ToString();
if (_objContact.FileName != "")
tipTooltip.SetToolTip(imgLink, LanguageManager.Instance.GetString("Tip_Enemy_OpenLinkedEnemy"));
else
tipTooltip.SetToolTip(imgLink, LanguageManager.Instance.GetString("Tip_Enemy_LinkEnemy"));
string strTooltip = LanguageManager.Instance.GetString("Tip_Enemy_EditNotes");
if (_objContact.Notes != string.Empty)
strTooltip += "\n\n" + _objContact.Notes;
tipTooltip.SetToolTip(imgNotes, strTooltip);
nudConnection.Minimum = 1;
}
else
{
lblLoyalty.Text = LanguageManager.Instance.GetString("Label_Contact_Loyalty");
lblGroup.Text = (_objContact.Membership + _objContact.AreaOfInfluence + _objContact.MagicalResources + _objContact.MatrixResources).ToString();
if (_objContact.FileName != "")
tipTooltip.SetToolTip(imgLink, LanguageManager.Instance.GetString("Tip_Contact_OpenLinkedContact"));
else
tipTooltip.SetToolTip(imgLink, LanguageManager.Instance.GetString("Tip_Contact_LinkContact"));
string strTooltip = LanguageManager.Instance.GetString("Tip_Contact_EditNotes");
if (_objContact.Notes != string.Empty)
strTooltip += "\n\n" + _objContact.Notes;
tipTooltip.SetToolTip(imgNotes, strTooltip);
nudConnection.Minimum = 0;
}
}
}
/// <summary>
/// Connection Rating.
/// </summary>
public int ConnectionRating
{
get
{
return _objContact.Connection;
}
set
{
nudConnection.Value = value;
_objContact.Connection = value;
}
}
/// <summary>
/// Group Rating.
/// </summary>
public int GroupRating
{
get
{
return _objContact.Group;
}
set
{
lblGroup.Text = value.ToString();
}
}
/// <summary>
/// Connection Modifier: Membership.
/// </summary>
public int MembershipRating
{
get
{
return _objContact.Membership;
}
set
{
_objContact.Membership = value;
}
}
/// <summary>
/// Connection Modifier: Area of Influence.
/// </summary>
public int AreaOfInfluenceRating
{
get
{
return _objContact.AreaOfInfluence;
}
set
{
_objContact.AreaOfInfluence = value;
}
}
/// <summary>
/// Connection Modifier: Magical Resources.
/// </summary>
public int MagicalResourcesRating
{
get
{
return _objContact.MagicalResources;
}
set
{
_objContact.MagicalResources = value;
}
}
/// <summary>
/// Connection Modifier: Matrix Resources.
/// </summary>
public int MatrixResourcesRating
{
get
{
return _objContact.MatrixResources;
}
set
{
_objContact.MatrixResources = value;
}
}
/// <summary>
/// Loyalty Rating.
/// </summary>
public int LoyaltyRating
{
get
{
return _objContact.Loyalty;
}
set
{
nudLoyalty.Value = value;
_objContact.Loyalty = value;
}
}
/// <summary>
/// Whether or not this is a free Contact.
/// </summary>
public bool Free
{
get
{
return _objContact.Free;
}
set
{
_objContact.Free = value;
}
}
#endregion
}
}