-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChatPageControl.cs
More file actions
978 lines (833 loc) · 24.2 KB
/
ChatPageControl.cs
File metadata and controls
978 lines (833 loc) · 24.2 KB
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
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
using System.Windows.Forms;
namespace nwn2_Chatter
{
/// <summary>
/// This <c>Control</c> appears as a <c>TabPage</c> in
/// <c><see cref="Chatter">Chatter's</see></c> <c>TabControl</c>. It
/// contains all the data about a loaded SoundSetFile and is responsible for
/// displaying and editing that data.
/// </summary>
sealed class ChatPageControl
: Control
{
#region Fields (static)
/// <summary>
/// The fixed count of cols in this <c>ChatPageControl</c>.
/// </summary>
const int COLCOUNT = 4;
/// <summary>
/// The fixed width of the first col (voices).
/// </summary>
const int COLWIDTH0 = 150;
/// <summary>
/// The fixed width of the second col (resrefs).
/// </summary>
const int COLWIDTH1 = 230;
/// <summary>
/// The fixed width of the third col (strrefs). The fourth col extends
/// to the right edge of the table (Dialog.Tlk text).
/// </summary>
const int COLWIDTH2 = 85;
/// <summary>
/// text indent in each cell
/// </summary>
const int INDENT = 4;
/// <summary>
/// The fixed height of rows.
/// </summary>
const int ROWHEIGHT = 20;
/// <summary>
/// Tracks the last directory for
/// <list type="bullet">
/// <item><c><see cref="click_it_browse()">click_it_browse()</see></c></item>
/// <item><c><see cref="click_it_play()">click_it_play()</see></c></item>
/// </list>
/// </summary>
/// <remarks>The path is written to "config.cfg" when Chatter closes.</remarks>
internal static string _lastbrowsedirectory;
#endregion Fields (static)
#region Fields
readonly Chatter _f;
/// <summary>
/// The path-file-extension of the file that's been loaded into this
/// <c>ChatPageControl</c>.
/// </summary>
internal string _pfe;
/// <summary>
/// The SoundSetFile specification of the data loaded in this
/// <c>ChatPageControl</c>.
/// </summary>
/// <seealso cref="Chatter.Output"><c>Chatter.Output</c></seealso>
internal SsfFormat _ver;
/// <summary>
/// <c>true</c> if the data loaded in this <c>ChatPageControl</c> has
/// an extended voice-set.
/// </summary>
/// <seealso cref="Chatter.Extended"><c>Chatter.Extended</c></seealso>
internal bool _extended;
/// <summary>
/// The array of resrefs that have been loaded into this
/// <c>ChatPageControl</c>.
/// </summary>
internal string[] _resrefs;
/// <summary>
/// The array of strrefs that have been loaded into this
/// <c>ChatPageControl</c>.
/// </summary>
internal uint[] _strrefs;
/// <summary>
/// The count of rows/voice-entries in this <c>ChatPageControl</c>.
/// </summary>
int _rcount;
/// <summary>
/// The vertical fckin scrollbar. Get a grip ...
/// </summary>
readonly VScrollBar _scroller = new VScrollBar();
/// <summary>
/// Since a .NET scrollbar's <c>Maximum</c> value is not its maximum
/// value calculate and store what it really is.
/// </summary>
int _vertical;
/// <summary>
/// This will be set <c>true</c> if a SoundSetFile fails to load.
/// </summary>
internal bool _fail;
/// <summary>
/// <c>true</c> if this <c>ChatPageControl</c> was created from a zipped
/// file in the nwn2/data folder.
/// </summary>
internal bool _datazipfile;
/// <summary>
///
/// </summary>
/// <remarks><c>Dispose()</c> the <c>resref_slotter</c> when this
/// <c>ChatPageControl</c> gets disposed.</remarks>
internal ContextMenuStrip _slotter;
int _r;
bool _isresref, _isstrref;
#endregion Fields
#region Properties
bool _changed;
internal bool Changed
{
get { return _changed; }
set
{
_changed = value;
_f.SetTitle();
}
}
#endregion Properties
#region cTor
/// <summary>
/// cTor.
/// </summary>
/// <param name="f"></param>
/// <param name="pfe">path-file-extension to load a SoundSetFile or
/// "ssf10" to create a new ver 1.0 SoundSetFile or "ssf11" to create a
/// new ver 1.1 SoundSetFile</param>
/// <param name="bytes"></param>
internal ChatPageControl(Chatter f, string pfe, byte[] bytes = null)
{
_f = f;
_pfe = pfe;
DoubleBuffered = true;
Margin = new Padding(0);
Dock = DockStyle.Fill;
BackColor = SystemColors.ControlDark;
_scroller.Dock = DockStyle.Right;
_scroller.LargeChange = ROWHEIGHT;
_scroller.ValueChanged += valuechanged_scroller;
Controls.Add(_scroller);
CreateSlotter();
if (_pfe == "ssf10")
{
Changed = true;
_ver = SsfFormat.ssf10;
_extended = false;
_rcount = 49;
}
else if (_pfe == "ssf11")
{
Changed = true;
_ver = SsfFormat.ssf11;
_extended = true;
_rcount = 51;
}
if (Changed)
{
_resrefs = new string[_rcount];
_strrefs = new uint [_rcount];
for (int i = 0; i != _rcount; ++i)
{
_resrefs[i] = String.Empty;
_strrefs[i] = UInt32.MaxValue;
}
}
else
{
string ver = null;
if (bytes != null)
{
Changed = _datazipfile = true;
_rcount = SoundsetFileService.ReadSoundsetFile(bytes, ref _resrefs, ref _strrefs, ref ver);
}
else
_rcount = SoundsetFileService.ReadSoundsetFile(_pfe, ref _resrefs, ref _strrefs, ref ver);
if (_rcount != -1)
{
if (ver == SoundsetFileService.Ver10) _ver = SsfFormat.ssf10;
else if (ver == SoundsetFileService.Ver11) _ver = SsfFormat.ssf11;
_extended = (_rcount > 49);
}
else
_fail = true;
}
}
#endregion cTor
#region Handlers (override)
/// <summary>
/// Since if an <c>OpenFileDialog</c> pops up under the mousecursor in a
/// <c>MouseDown</c> event the dialog will fire a <c>MouseUp</c> event
/// and open its contextmenu ... the <c>MouseUp</c> event needs to be
/// used to invoke the <c>OpenFileDialog</c>. That prevents a
/// contextmenu from showing in the dialog's <c>MouseUp</c> - or
/// <c>MouseClick</c> or whatever it is. But then there's the problem
/// that user can click down and move the cursor before releasing it for
/// the <c>MouseUp</c> event ... so the
/// <c><see cref="OnMouseDown()">OnMouseDown()</see></c> will track what
/// slot was clicked down on, and that slot shall be checked against
/// when <c><see cref="OnMouseUp()">OnMouseUp()</see></c> fires.
/// </summary>
/// <param name="e"></param>
/// <remarks>An <c>OpenFileDialog</c> no longer opens on rightclick but
/// keep the above mechanic.</remarks>
protected override void OnMouseDown(MouseEventArgs e)
{
_r = -1; _isresref = _isstrref = false;
if ((ModifierKeys & Keys.Alt) == Keys.None
&& (e.Button == MouseButtons.Left || e.Button == MouseButtons.Right)
&& e.X > COLWIDTH0 && e.X < COLWIDTH0 + COLWIDTH1 + COLWIDTH2)
// && !Chatter.BypassClicks
{
int r = (e.Y + _scroller.Value) / ROWHEIGHT;
if (e.X < COLWIDTH0 + COLWIDTH1) // is Resref ->
{
if (r < _resrefs.Length)
_r = r; _isresref = true;
}
else if ((ModifierKeys & Keys.Shift) == Keys.None) // is Strref ->
{
if (r < _strrefs.Length)
_r = r; _isstrref = true;
}
}
}
/// <summary>
/// Overrides the <c>MouseUp</c> handler.
/// </summary>
/// <param name="e"></param>
protected override void OnMouseUp(MouseEventArgs e)
{
Select();
if ((ModifierKeys & Keys.Alt) == Keys.None
&& (e.Y + _scroller.Value) / ROWHEIGHT == _r)
{
if (_isresref && e.X > COLWIDTH0 && e.X < COLWIDTH0 + COLWIDTH1)
{
if (_r < _resrefs.Length)
{
switch (e.Button)
{
case MouseButtons.Left:
if (ModifierKeys == Keys.Control) // input resref ->
{
click_it_input(null, EventArgs.Empty);
}
else if (ModifierKeys == Keys.Shift) // browse for file ->
{
click_it_browse(null, EventArgs.Empty);
}
else if ((ModifierKeys & (Keys.Control | Keys.Shift)) == (Keys.Control | Keys.Shift)) // browse /Data zipfile ->
{
click_it_browsedatazip(null, EventArgs.Empty);
}
break;
case MouseButtons.Right:
if ((ModifierKeys & Keys.Shift) == Keys.None)
{
if (ModifierKeys == Keys.Control) // browse and Play file ->
{
click_it_play(null, EventArgs.Empty);
}
else // context ->
{
ShowSlotter();
}
}
break;
}
}
}
else if ((ModifierKeys & Keys.Shift) == Keys.None
&& _isstrref && e.X > COLWIDTH0 + COLWIDTH1 && e.X < COLWIDTH0 + COLWIDTH1 + COLWIDTH2)
{
if (_r < _strrefs.Length)
{
switch (e.Button)
{
case MouseButtons.Left: // input strref ->
if (ModifierKeys == Keys.Control)
click_it_input(null, EventArgs.Empty);
// TODO: browse Dialog.Tlk
break;
case MouseButtons.Right: // context ->
if ((ModifierKeys & Keys.Control) == Keys.None)
ShowSlotter();
// TODO: browse Dialog.Tlk
break;
}
}
}
}
}
/// <summary>
/// Overrides the <c>MouseWheel</c> handler. Scrolls the table.
/// </summary>
/// <param name="e"></param>
protected override void OnMouseWheel(MouseEventArgs e)
{
if (e.Delta > 0)
{
if (_scroller.Value - ROWHEIGHT < 0)
_scroller.Value = 0;
else
_scroller.Value -= ROWHEIGHT;
}
else if (e.Delta < 0)
{
if (_scroller.Value + ROWHEIGHT > _vertical)
_scroller.Value = _vertical;
else
_scroller.Value += ROWHEIGHT;
}
}
/// <summary>
/// Overrides the <c>Paint</c> handler. Draws the table.
/// </summary>
/// <param name="e"></param>
protected override void OnPaint(PaintEventArgs e)
{
e.Graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
int r,c, r_start = _scroller.Value / ROWHEIGHT;
// fill backgrounds ->
var rect = new Rectangle(0,0, Width, ROWHEIGHT);
Brush brush;
for (r = r_start; r != _rcount; ++r)
{
if ((rect.Y = ROWHEIGHT * r - _scroller.Value) > Bottom)
break;
brush = (r % 2 == 0) ? Brushes.AliceBlue : Brushes.BlanchedAlmond;
e.Graphics.FillRectangle(brush, rect);
}
// draw text ->
for (r = r_start; r != _rcount; ++r)
{
if ((rect.Y = ROWHEIGHT * r - _scroller.Value) > Bottom)
break;
string text = null;
for (c = 0; c != COLCOUNT; ++c)
{
switch (c)
{
case 0:
text = Chatter.Voices[r]; // WARNING: 'Voices' has only 51 entries. But in theory '_rcount' can be greater than 50.
rect.X = INDENT;
rect.Width = COLWIDTH0;
break;
case 1:
text = _resrefs[r];
rect.X = COLWIDTH0 + INDENT;
rect.Width = COLWIDTH1 - INDENT;
break;
case 2:
{
uint strref = _strrefs[r];
if (strref == UInt32.MaxValue) text = String.Empty;
else text = strref.ToString();
rect.X = COLWIDTH0 + COLWIDTH1 + INDENT;
rect.Width = COLWIDTH2 - INDENT;
break;
}
case 3:
{
uint strref = _strrefs[r];
int id;
if (strref == UInt32.MaxValue) id = -1;
else id = (int)strref;
if (id != -1 && TalkReader.DictDialo.ContainsKey(id)) //TalkReader.DictDialo.Count != 0
text = TalkReader.DictDialo[id];
else
text = String.Empty;
rect.X = COLWIDTH0 + COLWIDTH1 + COLWIDTH2 + INDENT;
rect.Width = Width - COLWIDTH0 - COLWIDTH1 - COLWIDTH2 - INDENT;
break;
}
}
if (text.Length != 0)
{
TextRenderer.DrawText(e.Graphics,
text,
Font,
rect,
SystemColors.ControlText,
flags);
}
}
}
// draw horizontal lines ->
int y;
for (r = r_start + 1; r != _rcount + 1; ++r)
{
if ((y = ROWHEIGHT * r - _scroller.Value) > Bottom)
break;
e.Graphics.DrawLine(SystemPens.ControlDark,
0, y,
Width, y);
}
// draw vertical lines ->
e.Graphics.DrawLine(SystemPens.ControlDark, COLWIDTH0, 0, COLWIDTH0, Height);
e.Graphics.DrawLine(SystemPens.ControlDark, COLWIDTH0 + COLWIDTH1, 0, COLWIDTH0 + COLWIDTH1, Height);
e.Graphics.DrawLine(SystemPens.ControlDark, COLWIDTH0 + COLWIDTH1 + COLWIDTH2, 0, COLWIDTH0 + COLWIDTH1 + COLWIDTH2, Height);
}
/// <summary>
/// Flags used when drawing texts.
/// </summary>
const TextFormatFlags flags = TextFormatFlags.NoPrefix
| TextFormatFlags.NoPadding
| TextFormatFlags.Left
| TextFormatFlags.VerticalCenter
| TextFormatFlags.SingleLine
| TextFormatFlags.NoClipping;
protected override void OnResize(EventArgs e)
{
InitScroll();
base.OnResize(e);
}
#endregion Handlers (override)
#region Handlers
/// <summary>
/// Scrolls the table vertically.
/// </summary>
/// <param name="sender"><c><see cref="_scroller"></see></c></param>
/// <param name="e"></param>
void valuechanged_scroller(object sender, EventArgs e)
{
Select(); // <- focus the table when the bar is moved by mousedrag (bar has to move > 0px)
Invalidate();
}
#endregion Handlers
#region Methods
/// <summary>
/// Initializes <c><see cref="_vertical"/></c> and
/// <c><see cref="_scroller"/>.Maximum</c> value based on the height of
/// the table.
/// </summary>
/// <returns>the value of <c><see cref="_vertical"/></c></returns>
internal void InitScroll()
{
int height = ROWHEIGHT * _rcount;
// NOTE: Do not set Maximum until after deciding whether or not
// real Maximum < 0. 'Cause it borks everything up. bingo.
int vertical = height - Height + (ROWHEIGHT - 1);
if (vertical < ROWHEIGHT)
{
_vertical = (_scroller.Maximum = 0);
}
else
{
_vertical = ((_scroller.Maximum = vertical) - (ROWHEIGHT - 1));
// handle .NET OnResize anomaly ->
// keep the bottom of the table snuggled against the bottom
// of the visible area when resize enlarges the area
if (height < Height + _scroller.Value)
_scroller.Value = _vertical;
}
}
/// <summary>
/// Updates this <c>ChatPageControl</c> if the
/// <c><see cref="_extended"/></c> flag changes.
/// </summary>
internal void ChangedExtended()
{
if (_extended) _rcount = 51;
else _rcount = 49;
var resrefs = new string[_rcount];
for (int i = 0; i != _rcount; ++i)
{
if (i < _resrefs.Length) resrefs[i] = _resrefs[i];
else resrefs[i] = String.Empty;
}
_resrefs = resrefs;
var strrefs = new uint[_rcount];
for (int i = 0; i != _rcount; ++i)
{
if (i < _strrefs.Length) strrefs[i] = _strrefs[i];
else strrefs[i] = UInt32.MaxValue;
}
_strrefs = strrefs;
InitScroll();
Refresh();
}
#endregion Methods
#region Context
ToolStripMenuItem it_input;
ToolStripMenuItem it_cut;
ToolStripMenuItem it_copy;
ToolStripMenuItem it_paste;
ToolStripMenuItem it_delete;
ToolStripMenuItem it_browse;
ToolStripMenuItem it_browsedatazip;
ToolStripMenuItem it_play;
/// <summary>
/// Creates a <c>ContextMenuStrip</c> for this <c>ChatPageControl</c>.
/// </summary>
void CreateSlotter()
{
_slotter = new ContextMenuStrip();
_slotter.Font = new Font("Comic Sans MS", 8F);
_slotter.ShowImageMargin = false;
it_input = new ToolStripMenuItem();
it_input.ShortcutKeyDisplayString = "[Ctrl]+LMB";
it_input.Click += click_it_input;
var sep0 = new ToolStripSeparator();
it_cut = new ToolStripMenuItem();
it_cut.Text = "cut";
it_cut.Click += click_it_cut;
it_copy = new ToolStripMenuItem();
it_copy.Text = "copy";
it_copy.Click += click_it_copy;
it_paste = new ToolStripMenuItem();
it_paste.Text = "paste";
it_paste.Click += click_it_paste;
it_delete = new ToolStripMenuItem();
it_delete.Text = "delete";
it_delete.Click += click_it_delete;
var sep1 = new ToolStripSeparator();
it_browse = new ToolStripMenuItem();
it_browse.Text = "browse for file ...";
it_browse.ShortcutKeyDisplayString = "[Shift]+LMB";
it_browse.Click += click_it_browse;
it_browsedatazip = new ToolStripMenuItem();
it_browsedatazip.Text = "browse /Data zips ...";
it_browsedatazip.ShortcutKeyDisplayString = "[Ctrl+Shift]+LMB";
it_browsedatazip.Click += click_it_browsedatazip;
var sep2 = new ToolStripSeparator();
it_play = new ToolStripMenuItem();
it_play.Text = "Play file ...";
it_play.ShortcutKeyDisplayString = "[Ctrl]+RMB";
it_play.Click += click_it_play;
_slotter.Items.AddRange(new ToolStripItem[]
{
it_input,
sep0,
it_cut,
it_copy,
it_paste,
it_delete,
sep1,
it_browse,
it_browsedatazip,
sep2,
it_play
});
}
/// <summary>
/// Shows the rightclick context slotter.
/// </summary>
void ShowSlotter()
{
if (_isresref)
{
it_input.Text = "input text";
it_cut .Enabled =
it_copy .Enabled =
it_delete.Enabled = _resrefs[_r].Length != 0;
string clip = ClipboardService.GetText();
it_paste .Enabled = !String.IsNullOrEmpty(clip) && Inputbox.islegal(clip);
it_browse .Enabled =
it_browsedatazip.Enabled =
it_play .Enabled = true;
}
else // _isstrref
{
it_input.Text = "input integer";
it_cut .Enabled =
it_copy .Enabled =
it_delete .Enabled = _strrefs[_r] != UInt32.MaxValue;
string clip = ClipboardService.GetText(); uint result;
it_paste .Enabled = !String.IsNullOrEmpty(clip)
&& UInt32.TryParse(clip, out result)
&& result < 0x02000000;
it_browse .Enabled =
it_browsedatazip.Enabled =
it_play .Enabled = false;
}
_slotter.Show(this, PointToClient(Cursor.Position));
}
/// <summary>
///
/// </summary>
/// <param name="sender">
/// <list type="bullet">
/// <item><c><see cref="it_input"/></c></item>
/// <item><c>null</c> - <c><see cref="OnMouseUp()">OnMouseUp()</see></c></item>
/// </list></param>
/// <param name="e"></param>
void click_it_input(object sender, EventArgs e)
{
if (_isresref)
{
using (var ip = new Inputbox(_resrefs[_r], true))
{
if (ip.ShowDialog(this) == DialogResult.OK
&& ip._result != _resrefs[_r])
{
_resrefs[_r] = ip._result;
Changed = true;
Invalidate();
}
}
}
else // _isstrref
{
string strref;
if (_strrefs[_r] == UInt32.MaxValue)
strref = String.Empty;
else
strref = _strrefs[_r].ToString();
using (var ip = new Inputbox(strref, false))
{
if (ip.ShowDialog(this) == DialogResult.OK
&& ip._result != _strrefs[_r].ToString())
{
_strrefs[_r] = UInt32.Parse(ip._result);
Changed = true;
Invalidate();
}
}
}
}
/// <summary>
///
/// </summary>
/// <param name="sender"><c><see cref="it_cut"/></c></param>
/// <param name="e"></param>
void click_it_cut(object sender, EventArgs e)
{
if (_isresref)
{
ClipboardService.SetText(_resrefs[_r]);
_resrefs[_r] = String.Empty;
}
else // isstrref
{
ClipboardService.SetText(_strrefs[_r].ToString());
_strrefs[_r] = UInt32.MaxValue;
}
Changed = true;
Invalidate();
}
/// <summary>
///
/// </summary>
/// <param name="sender"><c><see cref="it_copy"/></c></param>
/// <param name="e"></param>
void click_it_copy(object sender, EventArgs e)
{
if (_isresref)
{
ClipboardService.SetText(_resrefs[_r]);
}
else // isstrref
{
ClipboardService.SetText(_strrefs[_r].ToString());
}
}
/// <summary>
///
/// </summary>
/// <param name="sender"><c><see cref="it_paste"/></c></param>
/// <param name="e"></param>
void click_it_paste(object sender, EventArgs e)
{
if (_isresref)
{
string clip = ClipboardService.GetText();
if (!String.IsNullOrEmpty(clip)) // safety perhaps.
{
_resrefs[_r] = clip;
Changed = true;
Invalidate();
}
}
else // isstrref
{
string clip = ClipboardService.GetText();
if (!String.IsNullOrEmpty(clip)) // safety perhaps.
{
_strrefs[_r] = UInt32.Parse(clip);
Changed = true;
Invalidate();
}
}
}
/// <summary>
///
/// </summary>
/// <param name="sender"><c><see cref="it_delete"/></c></param>
/// <param name="e"></param>
void click_it_delete(object sender, EventArgs e)
{
if (_isresref)
{
_resrefs[_r] = String.Empty;
}
else // isstrref
{
_strrefs[_r] = UInt32.MaxValue;
}
Changed = true;
Invalidate();
}
/// <summary>
///
/// </summary>
/// <param name="sender">
/// <list type="bullet">
/// <item><c><see cref="it_browse"/></c></item>
/// <item><c>null</c> - <c><see cref="OnMouseUp()">OnMouseUp()</see></c></item>
/// </list></param>
/// <param name="e"></param>
void click_it_browse(object sender, EventArgs e)
{
using (var ofd = new OpenFileDialog())
{
ofd.AutoUpgradeEnabled = false;
ofd.Title = "Select " + Chatter.Voices[_r] + " resref";
ofd.Filter = Chatter.FileFilter_WAV;
ofd.RestoreDirectory = true; // do not track this as last location
string dir;
if (Directory.Exists(_lastbrowsedirectory))
dir = _lastbrowsedirectory;
else
dir = Chatter.GetCurrentDirectory();
ofd.FileName = Path.Combine(dir, _resrefs[_r] + ".WAV");
if (ofd.ShowDialog() == DialogResult.OK)
{
_lastbrowsedirectory = Path.GetDirectoryName(ofd.FileName);
string label = Path.GetFileNameWithoutExtension(ofd.FileName);
if (label != _resrefs[_r])
{
_resrefs[_r] = Path.GetFileNameWithoutExtension(label);
Changed = true;
Invalidate();
}
}
}
}
/// <summary>
///
/// </summary>
/// <param name="sender">
/// <list type="bullet">
/// <item><c><see cref="it_browsedatazip"/></c></item>
/// <item><c>null</c> - <c><see cref="OnMouseUp()">OnMouseUp()</see></c></item>
/// </list></param>
/// <param name="e"></param>
void click_it_browsedatazip(object sender, EventArgs e)
{
using (var ofd = new OpenFileDialog())
{
ofd.AutoUpgradeEnabled = false;
ofd.Title = "Open nwn2 /Data zip for " + Chatter.Voices[_r];
ofd.Filter = Chatter.FileFilter_ZIP;
ofd.RestoreDirectory = true; // do not track this as last location
string dir;
if (Directory.Exists(Chatter._lastdatadirectory))
dir = Chatter._lastdatadirectory;
else
{
string dirT = Chatter.GetDatazipDirectory();
if (dirT != null)
dir = dirT;
else
dir = Chatter.GetCurrentDirectory();
}
ofd.FileName = Path.Combine(dir, "*.ZIP");
if (ofd.ShowDialog() == DialogResult.OK)
{
Chatter._lastdatadirectory = Path.GetDirectoryName(ofd.FileName);
string label = String.Empty;
using (var dzld = new DatazipListDialog(ofd.FileName, _r))
{
if (dzld.ShowDialog(this) == DialogResult.OK)
{
label = Path.GetFileNameWithoutExtension(dzld.GetSelectedFile());
if (label != _resrefs[_r])
{
_resrefs[_r] = label;
Changed = true;
Invalidate();
}
}
}
}
}
}
/// <summary>
///
/// </summary>
/// <param name="sender">
/// <list type="bullet">
/// <item><c><see cref="it_play"/></c></item>
/// <item><c>null</c> - <c><see cref="OnMouseUp()">OnMouseUp()</see></c></item>
/// </list></param>
/// <param name="e"></param>
void click_it_play(object sender, EventArgs e)
{
using (var ofd = new OpenFileDialog())
{
ofd.AutoUpgradeEnabled = false;
ofd.Title = "Play a voice file";
ofd.Filter = Chatter.FileFilter_WBM;
ofd.RestoreDirectory = true; // do not track this as last location
string dir;
if (Directory.Exists(_lastbrowsedirectory))
dir = _lastbrowsedirectory;
else
dir = Chatter.GetCurrentDirectory();
ofd.FileName = Path.Combine(dir, _resrefs[_r] + ".WAV");
if (ofd.ShowDialog() == DialogResult.OK)
{
_lastbrowsedirectory = Path.GetDirectoryName(ofd.FileName);
string audiofile = AudioConverter.DecodeVoiceFile(ofd.FileName); // this/these file/s will be deleted when Chatter closes
if (audiofile != null)
{
using (var fs = new FileStream(audiofile, FileMode.Open, FileAccess.Read, FileShare.Read))
using (var player = new System.Media.SoundPlayer(fs))
{
player.SoundLocation = audiofile;
player.Play();
}
}
}
}
}
#endregion Context
}
}