This repository was archived by the owner on Aug 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.cs
More file actions
913 lines (701 loc) · 21.9 KB
/
client.cs
File metadata and controls
913 lines (701 loc) · 21.9 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
//Drop Down Search
//By Zeblote (1163)
//Download Support_Updater
///////////////////////////////////////////////////////////////////////////
if(!$Pref::DDS::DisableUpdater
&& !$SupportUpdaterMigration
&& !isFile("Add-Ons/Support_Updater.zip"))
{
exec("./tcpclient.cs");
exec("./updater.cs");
}
//Preferences
///////////////////////////////////////////////////////////////////////////
//Drop down lists added here will not be affected
$DDS::BlockCtrl["ServerSettingsGui_MaxPlayers"] = true;
//Whether we show results that contain the filter in the middle instead of the start
$DDS::ShowExtendedResults = true;
//Whether rows starting with the filter text are always first
$DDS::SeperateExtendedResults = true;
//Whether rows starting with the filter text are colored
$DDS::ColorBasicResults = false;
//Whether rows not starting with the filter text are colored
$DDS::ColorExtendedResults = true;
//Space to keep between the selected row and the scroll border
$DDS::SelectionPadding = 120;
//GuiPopUpMenuCtrl hooks
///////////////////////////////////////////////////////////////////////////
//Fix missing function errors
if(!isFunction(GuiPopUpMenuCtrl, onWake))
eval("function GuiPopUpMenuCtrl::onWake(){}");
if(!isFunction(GuiPopUpMenuCtrl, onRemove))
eval("function GuiPopUpMenuCtrl::onRemove(){}");
if(!isFunction(GuiTextListCtrl, onAdd))
eval("function GuiTextListCtrl::onAdd(){}");
//Packaged functions
package DropDownSearch
{
//New drop down list was created, initialize dds list
function GuiPopUpMenuCtrl::onWake(%this)
{
parent::onWake(%this);
%this.ddsInit();
}
//Drop down list was deleted, delete dds list
function GuiPopUpMenuCtrl::onRemove(%this)
{
%this.ddsDestroy();
parent::onRemove(%this);
}
//A line was added to the drop down list, refresh dds list
function GuiPopUpMenuCtrl::add(%this, %name, %id, %scheme)
{
parent::add(%this, %name, %id, %scheme);
%this.ddsUpdateRequired = true;
}
//A line was added to the drop down list, refresh dds list
function GuiPopUpMenuCtrl::addFront(%this, %name, %id, %scheme)
{
parent::addFront(%this, %name, %id, %scheme);
%this.ddsUpdateRequired = true;
}
//The drop down list was sorted, refresh dds list
function GuiPopUpMenuCtrl::sort(%this)
{
parent::sort(%this);
%this.ddsUpdateRequired = true;
}
//The drop down list was cleared, refresh dds list
function GuiPopUpMenuCtrl::clear(%this)
{
parent::clear(%this);
%this.ddsUpdateRequired = true;
}
//Force open the drop down list, open dds list instead
function GuiPopUpMenuCtrl::forceOnAction(%this)
{
if(%this.ddsOverride)
%this.ddsOpenMenu();
else
parent::forceOnAction(%this);
}
//Force close the drop down list, close dds list instead
function GuiPopUpMenuCtrl::forceClose(%this)
{
if(%this.ddsOverride)
%this.ddsCloseMenu();
else
parent::forceClose(%this);
}
//Internal text list was created (hack to get rows from drop down)
function GuiTextListCtrl::onAdd(%this)
{
parent::onAdd(%this);
$DDS::LastTextList = %this;
}
};
//Creating a dds control
///////////////////////////////////////////////////////////////////////////
//Creates gui profiles required for the dds list
function GuiPopUpMenuCtrl::ddsCreateProfiles(%this)
{
%profile = (strLen(%this.profile) ? %this.profile : GuiPopUpMenuProfile);
%name = %profile.getName();
%profile = %profile.getId();
%profile.setName("DDS_TempProfileName");
//Get mean between font and background color for highlighting
%fontCol = getColorF(%profile.fontColor);
%fillCol = getColorF(%profile.fillColor);
%textCol = getColorI(vectoradd(%fontCol, vectorscale(vectorsub(%fillCol, %fontCol), 0.45)) SPC 1);
%backCol = getColorI(vectoradd(%fontCol, vectorscale(vectorsub(%fillCol, %fontCol), 0.75)) SPC 1);
//Text profile for tab completion hint
if(!$DDS::TextProfile[%name])
{
%p = new GuiControlProfile("DDS_TextProfile_" @ %name : DDS_TempProfileName)
{
justify = left;
fontColor = %textCol;
textOffset = "0 0";
};
$DDS::TextProfile[%name] = %p;
}
//Text profile for search input
if(!$DDS::InputProfile[%name])
{
%p = new GuiControlProfile("DDS_InputProfile_" @ %name : DDS_TempProfileName)
{
justify = left;
canKeyFocus = true;
textOffset = "0 0";
border = false;
opague = false;
fillColor = "0 0 0 0";
};
$DDS::InputProfile[%name] = %p;
}
//Text profile for dds list
if(!$DDS::ListProfile[%name])
{
%p = new GuiControlProfile("DDS_ListProfile_" @ %name : DDS_TempProfileName){
fillColorHL = %backCol;
fontColorHL = %fontCol;
fontColors[2] = %fontCol;
fontColors[3] = %textCol;
mouseOverSelected = true;
};
$DDS::ListProfile[%name] = %p;
}
%profile.setName(%name);
}
//Creates better popup menu to replace original
function GuiPopUpMenuCtrl::ddsInit(%this)
{
//Already has a dds list, do nothing
if(isObject(%this.ddsButton))
return;
//In blocked list, do nothing
if($DDS::BlockCtrl[%this.getName()])
return;
//Create dds profiles
%this.ddsCreateProfiles();
//Create dds button
%this.ddsButton = new GuiMouseEventCtrl(DDS_ButtonCtrl)
{
position = "0 0";
extent = %this.getExtent();
ddsControl = %this;
horizSizing = "width";
vertSizing = "height";
};
//Add button to this control (can't use own .add method, it's broken?)
GuiControl::add(%this, %this.ddsButton);
//Have to copy the list before we can open this
%this.ddsUpdateRequired = true;
//Force opening this list should open the dds list instead
%this.ddsOverride = true;
}
//Deletes dds controls
function GuiPopUpMenuCtrl::ddsDestroy(%this)
{
//Doesn't have a dds list, do nothing
if(!isObject(%this.ddsButton))
return;
%this.ddsCloseMenu();
%this.ddsOverride = false;
%this.ddsButton.delete();
}
//Opening a dds list
///////////////////////////////////////////////////////////////////////////
//Clicked popup, open menu
function DDS_ButtonCtrl::onMouseDown(%this)
{
%this.ddsControl.ddsOpenMenu();
}
//Copy the rows from the drop down list to a buffer
function GuiPopUpMenuCtrl::ddsUpdateRows(%this)
{
//If the list is empty, don't do anything
if(%this.size() == 0)
{
%this.ddsRowCount = 0;
return;
}
//%cnt = %this.size();
//for(%i = 0; %i < %cnt; %i++)
//{
// %this.ddsRow[%i] = %this.getRowText(%i);
// %this.ddsRowId[%i] = %this.getRowId(%i);
// %this.ddsRowNum[%this.ddsRowId[%i]] = %i;
//}
//Can't copy the rows from the drop down list directly,
//so open the list and get them from the internal one...
//Make sure we use the id, or this will fail
%this = %this.getId();
//Prepare control to ensure it does NOT call any callbacks
%var = %this.variable;
%cmd = %this.command;
%alt = %this.altCommand;
%this.variable = "";
%this.command = "";
%this.altCommand = "";
%name = %this.getName();
%this.setName("DDS_Temp");
//Open the list
%this.ddsOverride = false;
%this.forceOnAction();
//List opened, package should have set this var
%list = $DDS::LastTextList;
if(isObject(%list) && %list.rowCount() == %this.size())
{
%cnt = %list.rowCount();
//Copy lines reversed, in case an id is used for multiple rows
for(%i = %cnt - 1; %i >= 0; %i--)
{
%this.ddsRow[%i] = %list.getRowText(%i);
%this.ddsRowId[%i] = %list.getRowId(%i);
%this.ddsRowNum[%this.ddsRowId[%i]] = %i;
}
%this.ddsRowCount = %cnt;
}
else
{
error("Failed to copy lines from drop down list " @ %this @ ", the internal list was not created!");
%this.ddsRowCount = 0;
}
//Close list and restore callbacks
%this.forceClose();
%this.ddsOverride = true;
%this.setName(%name);
%this.variable = %var;
%this.command = %cmd;
%this.altCommand = %alt;
}
//Get total width of all lines
function GuiPopUpMenuCtrl::ddsCalcListWidth(%this)
{
//Create control to find width
%profile = (strLen(%this.profile) ? %this.profile : GuiPopUpMenuProfile);
//Enable auto resize
%orig = %profile.autoSizeWidth;
%profile.autoSizeWidth = true;
%ctrl = new GuiTextCtrl(){profile = %profile;};
//Find max width of all lines
%width = 0;
for(%i = 0; %i < %this.ddsRowCount; %i++)
{
%ctrl.setText(%this.ddsRow[%i]);
//Save width of every line for later
%w = getWord(%ctrl.getExtent(), 0) + 8;
%this.ddsRowWidth[%i] = %w;
if(%w > %width)
%width = %w;
}
%ctrl.delete();
%profile.autoSizeWidth = %orig;
return %width;
}
//Open the dds list
function GuiPopUpMenuCtrl::ddsOpenMenu(%this)
{
//Control is disabled - do nothing
if(%this.enabled $= "0")
return;
//Menu already open - do nothing
if(isObject(%this.ddsDialog))
return;
//Make sure we have the latest row list
if(%this.ddsUpdateRequired)
%this.ddsUpdateRows();
//Some things that we will need often
%thisPos = %this.getScreenPosition();
%thisExt = %this.getExtent();
%canvasExt = Canvas.getExtent();
%profile = (strLen(%this.profile) ? %this.profile : GuiPopUpMenuProfile);
//Create the background ctrl
%this.ddsDialog = new GuiMouseEventCtrl(DDS_BackgroundCtrl)
{
position = "0 0";
extent = %canvasExt;
ddsControl = %this;
};
//Create the search field background
%searchBorder = new GuiSwatchCtrl()
{
position = %thisPos;
extent = vectorSub(%thisExt, "0 1");
color = %profile.borderColor;
};
%searchFill = new GuiSwatchCtrl()
{
position = "1 1";
extent = vectorSub(%thisExt, "2 1");
color = %profile.fillColor;
};
%searchBorder.add(%searchFill);
%this.ddsDialog.add(%searchBorder);
//Create the search field
%searchText = new GuiTextCtrl()
{
profile = $DDS::TextProfile[%profile.getName()];
position = "5 1";
extent = vectorSub(%thisExt, "5 1");
text = "Search...";
};
%searchInput = new GuiTextEditCtrl(DDS_InputCtrl)
{
profile = $DDS::InputProfile[%profile.getName()];
position = "2 1";
extent = vectorSub(%thisExt, "2 1");
tabComplete = true;
command = %this @ ".ddsUpdateFilter($ThisControl.getValue());";
altCommand = "$ThisControl.onTabComplete();";
escapeCommand = %this @ ".ddsCloseMenu();";
ddsControl = %this;
};
%searchBorder.add(%searchText);
%searchBorder.add(%searchInput);
%this.ddsSearchText = %searchText;
//Calculate scroll rect
%listWidth = %this.ddsCalcListWidth();
%startY = getWord(%thisPos, 1) + getWord(%thisExt, 1) - 1;
%listHeight = %this.ddsRowCount * (%profile.fontSize + 2);
%canvasHeight = getWord(%canvasExt, 1);
if(%startY + %listHeight + 12 > %canvasHeight)
{
//List doesn't fit below completely...
%listHeight = %canvasHeight - %startY - 12;
%listWidth += 16;
%this.ddsScrollBar = true;
}
else
%this.ddsScrollBar = false;
//List not wide enough
if(getWord(%thisExt, 0) > %listWidth)
%listWidth = getWord(%thisExt, 0);
//No entries
if(!%this.ddsRowCount)
%listHeight = 4;
//Create scroll
%scroll = new GuiScrollCtrl()
{
profile = %profile;
position = getWord(%thisPos, 0) SPC %startY;
extent = %listWidth SPC %listHeight + 2;
hScrollBar = "alwaysOff";
vScrollBar = "dynamic";
};
%this.ddsDialog.add(%scroll);
%this.ddsScroll = %scroll;
//Create text list
%list = new GuiTextListCtrl(DDS_ListCtrl)
{
profile = $DDS::ListProfile[%profile.getName()];
position = "1 1";
extent = %listWidth SPC 0;
command = %this @ ".ddsLineSelected();";
};
%scroll.add(%list);
%this.ddsList = %list;
//Add lines to list (no filter when opening list)
for(%i = 0; %i < %this.ddsRowCount; %i++)
%list.addRow(%i, %this.ddsRow[%i]);
//Fix list not extending to the far right (?????)
%list.resize(1, 1, 0, 0);
//Push background dialog
Canvas.pushDialog(%this.ddsDialog, 99);
//Highlight the currently selected row
%this.ddsSelectedRow = %this.ddsRowNum[%this.getSelected()];
if(%this.ddsSelectedRow == -1)
%this.ddsSelectedRow = 0;
%list.selectLineNoCallback(%this.ddsSelectedRow);
%this.ddsFilter = "";
//Focus on search field
%searchInput.makeFirstResponder(true);
%searchInput.setCursorPos(0);
//Create the actionmap for directional buttons
//Seems like we can't detect pressing up/down on their own... sad
%this.ddsActionMap = new ActionMap();
%this.ddsActionMap.bindCmd("keyboard", "shift up", %this @ ".ddsStartMoveUp();", %this @ ".ddsStopMove();");
%this.ddsActionMap.bindCmd("keyboard", "ctrl up", %this @ ".ddsStartMoveUp();", %this @ ".ddsStopMove();");
%this.ddsActionMap.bindCmd("keyboard", "alt up", %this @ ".ddsStartMoveUp();", %this @ ".ddsStopMove();");
%this.ddsActionMap.bindCmd("keyboard", "shift down", %this @ ".ddsStartMoveDown();", %this @ ".ddsStopMove();");
%this.ddsActionMap.bindCmd("keyboard", "ctrl down", %this @ ".ddsStartMoveDown();", %this @ ".ddsStopMove();");
%this.ddsActionMap.bindCmd("keyboard", "alt down", %this @ ".ddsStartMoveDown();", %this @ ".ddsStopMove();");
%this.ddsActionMap.bind("mouse0", "zaxis", "ddsHandleScrolling");
%this.ddsActionMap.push();
$DDS::CurrentMenu = %this;
}
//Selecting and filtering lines
///////////////////////////////////////////////////////////////////////////
//Select a line in the list, without passing it to the original
function DDS_ListCtrl::selectLineNoCallback(%this, %id)
{
%str = %this.command;
%this.command = "";
%this.setSelectedById(%id);
%this.makeSelectedVisible();
%this.command = %str;
}
//Move the control so the selected line is visible
function DDS_ListCtrl::makeSelectedVisible(%this)
{
%scrollHeight = getWord(%this.getGroup().getExtent(), 1);
%listHeight = getWord(%this.getExtent(), 1);
%currPos = getWord(%this.getPosition(), 1);
//Do nothing if the list doesn't have a scroll bar
if(%listHeight < %scrollHeight)
return;
//Find center of the currently selected row
%rowNum = %this.getRowNumById(%this.getSelectedId());
%rowPosition = 1 + %rowNum * (%this.profile.fontSize + 2) + %this.profile.fontSize / 2;
%distanceUp = %rowPosition + %currPos;
%distanceDown = (%scrollHeight - %currPos) - %rowPosition;
//Adjust list to have 120px above and below the line
if(%distanceUp < $DDS::SelectionPadding)
%currPos += $DDS::SelectionPadding - %distanceUp;
if(%distanceDown < $DDS::SelectionPadding)
%currPos -= $DDS::SelectionPadding - %distanceDown;
//Move list
%this.resize(1, %currPos, getWord(%this.getExtent(), 0), %listHeight);
}
//Update the scroll rect to fit new lines
function GuiPopUpMenuCtrl::ddsUpdateScrollRect(%this)
{
%scrollPos = %this.ddsScroll.getPosition();
%listPos = %this.ddsList.getPosition();
%listExt = %this.ddsList.getExtent();
%minWidth = getWord(%this.getExtent(), 0);
%lineCount = %this.ddsList.rowCount();
%listWidth = 0;
//Find width of all currently visible lines
for(%i = 0; %i < %lineCount; %i++)
{
%w = %this.ddsRowWidth[%this.ddsList.getRowId(%i)];
if(%w > %listWidth)
%listWidth = %w;
}
//Find height of lines
%listHeight = %lineCount * (%this.ddsList.profile.fontSize + 2);
%start = getWord(%scrollPos, 1);
%canvasHeight = getWord(Canvas.getExtent(), 1);
//List doesn't fit below completely...
if(%start + %listHeight + 12 > %canvasHeight)
{
%listHeight = %canvasHeight - %start - 12;
%listWidth += 16;
%this.ddsScrollBar = true;
}
else
%this.ddsScrollBar = false;
//List not wide enough
if(%minWidth > %listWidth)
%listWidth = %minWidth;
//No entries
if(!%lineCount)
%listHeight = 4;
//Update scroll rect
%this.ddsScroll.resize(getWord(%scrollPos, 0), getWord(%scrollPos, 1), %listWidth, %listHeight + 2);
//Fix list not updating correctly (?????)
%this.ddsScroll.remove(%this.ddsList);
%this.ddsScroll.add(%this.ddsList);
}
//Update line filter
function GuiPopUpMenuCtrl::ddsUpdateFilter(%this, %filter)
{
//Filter unchanged - do nothing
if(%filter $= %this.ddsFilter)
return;
//Clear list
%this.ddsList.clear();
%this.ddsFilter = %filter;
%filterLen = strLen(%filter);
if(!%filterLen)
{
//Add all lines to list (no markup)
for(%i = 0; %i < %this.ddsRowCount; %i++)
%this.ddsList.addRow(%i, %this.ddsRow[%i]);
//Select current line
%this.ddsSelectedRow = %this.ddsRowNum[%this.getSelected()];
}
else
{
//Add all lines matching the filter
for(%i = 0; %i < %this.ddsRowCount; %i++)
{
%curRow = %this.ddsRow[%i];
%filterPos = strPos(strLwr(%curRow), strLwr(%filter));
//Check whether the line should be added
if(%filterPos == 0)
{
//Line starts with filter. Always add this one
if($DDS::ColorBasicResults)
{
//Line should be colored (highlights filter)
%curRow = "\c3" @ getSubStr(%curRow, 0, %filterPos)
@ "\c2" @ getSubStr(%curRow, %filterPos, %filterLen)
@ "\c3" @ getSubStr(%curRow, %filterPos + %filterLen, 255);
}
}
else if(%filterPos > 0 && $DDS::ShowExtendedResults && !$DDS::SeperateExtendedResults)
{
//Line contains filter, extended results are enabled and not seperated
if($DDS::ColorExtendedResults)
{
//Line should be colored (highlights filter)
%curRow = "\c3" @ getSubStr(%curRow, 0, %filterPos)
@ "\c2" @ getSubStr(%curRow, %filterPos, %filterLen)
@ "\c3" @ getSubStr(%curRow, %filterPos + %filterLen, 255);
}
}
else
//Line doesn't contain filter or shouldn't be shown, ignore
continue;
//Add line to list
%this.ddsList.addRow(%i, %curRow);
}
//If extended results are enabled and seperated, search again for them
if($DDS::ShowExtendedResults && $DDS::SeperateExtendedResults)
{
for(%i = 0; %i < %this.ddsRowCount; %i++)
{
%curRow = %this.ddsRow[%i];
%filterPos = strPos(strLwr(%curRow), strLwr(%filter));
//Check whether the line should be added
if(%filterPos > 0)
{
//Extended results don't start with filter
if($DDS::ColorExtendedResults)
{
//Line should be colored (highlights filter)
%curRow = "\c3" @ getSubStr(%curRow, 0, %filterPos)
@ "\c2" @ getSubStr(%curRow, %filterPos, %filterLen)
@ "\c3" @ getSubStr(%curRow, %filterPos + %filterLen, 255);
}
}
else
//Line is not an extended result, ignore
continue;
//Add line to list
%this.ddsList.addRow(%i, %curRow);
}
}
//If the previously selected line was removed, select the first one
if(%this.ddsList.getRowNumById(%this.ddsSelectedRow) == -1)
%this.ddsSelectedRow = %this.ddsList.getRowId(0);
}
%this.ddsUpdateTabHint();
%this.ddsUpdateScrollRect();
%this.ddsList.selectLineNoCallback(%this.ddsSelectedRow);
}
//Update the tab completion hint
function GuiPopUpMenuCtrl::ddsUpdateTabHint(%this)
{
%len = strLen(%this.ddsFilter);
if(%len)
{
%text = %this.ddsRow[%this.ddsSelectedRow];
if(getSubStr(%text, 0, %len) $= %this.ddsFilter)
%this.ddsSearchText.setText(%this.ddsFilter @ getSubStr(%text, %len, 255));
else
%this.ddsSearchText.setText("");
}
else
%this.ddsSearchText.setText("Search...");
}
//Tab complete list
function DDS_InputCtrl::onTabComplete(%this)
{
%this.ddsControl.ddsList.setSelectedById(%this.ddsControl.ddsSelectedRow);
}
//Selected a line - pass to original control
function GuiPopUpMenuCtrl::ddsLineSelected(%this)
{
%row = %this.ddsList.getSelectedId();
%this.ddsCloseMenu();
//We can't directly select a row number, but we can open the list, select, close it
%this.ddsOverride = false;
%this.forceOnAction();
$DDS::LastTextList.setSelectedRow(%row);
%this.forceClose();
%this.ddsOverride = true;
}
//Moving the selected line
///////////////////////////////////////////////////////////////////////////
//Start moving the selected line up
function GuiPopupMenuCtrl::ddsStartMoveUp(%this)
{
%this.ddsMoveSelection(-1);
cancel(%this.ddsMoveSchedule);
%this.ddsMoveSchedule = %this.schedule(200, ddsRepeatMove, -1);
}
//Start moving the selected line down
function GuiPopupMenuCtrl::ddsStartMoveDown(%this)
{
%this.ddsMoveSelection(1);
cancel(%this.ddsMoveSchedule);
%this.ddsMoveSchedule = %this.schedule(200, ddsRepeatMove, 1);
}
//Repeat moving the selected line
function GuiPopupMenuCtrl::ddsRepeatMove(%this, %dir)
{
%this.ddsMoveSelection(%dir);
cancel(%this.ddsMoveSchedule);
%this.ddsMoveSchedule = %this.schedule(50, ddsRepeatMove, %dir);
}
//Stop moving the selected line
function GuiPopupMenuCtrl::ddsStopMove(%this)
{
cancel(%this.ddsMoveSchedule);
}
//Handle moving the selected line
function GuiPopupMenuCtrl::ddsMoveSelection(%this, %dir)
{
%curRow = %this.ddsList.getRowNumById(%this.ddsSelectedRow);
%newRow = %curRow + %dir;
if(%newRow < 0 || %newRow > %this.ddsList.rowCount() - 1)
return;
%this.ddsSelectedRow = %this.ddsList.getRowId(%newRow);
%this.ddsList.selectLineNoCallback(%this.ddsSelectedRow);
%this.ddsUpdateTabHint();
}
//Handle scrolling the selected line with mouse
function ddsHandleScrolling(%val, %a, %b)
{
if(isObject($DDS::CurrentMenu))
{
$DDS::CurrentMenu.ddsStopMove();
//If we have a scroll bar, don't scroll the list while mouse is inside it
if($DDS::CurrentMenu.ddsScrollBar)
{
%scrollExt = $DDS::CurrentMenu.ddsScroll.getExtent();
%scrollPos = $DDS::CurrentMenu.ddsScroll.getScreenPosition();
%scrollX = getWord(%scrollPos, 0);
%scrollY = getWord(%scrollPos, 1);
%curPos = Canvas.getCursorPos();
%curX = getWord(%curPos, 0);
%curY = getWord(%curPos, 1);
if(%curX > %scrollX
&& %curX < %scrollX + getWord(%scrollExt, 0)
&& %curY > %scrollY
&& %curY < %scrollY + getWord(%scrollExt, 1))
return;
}
if(%val > 1)
$DDS::CurrentMenu.ddsMoveSelection(-1);
else
$DDS::CurrentMenu.ddsMoveSelection(1);
}
}
//Closing a dds list
///////////////////////////////////////////////////////////////////////////
//Clicked popup background, close menu
function DDS_BackgroundCtrl::onMouseDown(%this)
{
%this.ddsControl.ddsCloseMenu();
}
//Closes the popup menu
function GuiPopUpMenuCtrl::ddsCloseMenu(%this)
{
//Menu not open - do nothing
if(!isObject(%this.ddsDialog))
return;
Canvas.popDialog(%this.ddsDialog);
%this.ddsDialog.delete();
%this.ddsActionMap.pop();
%this.ddsActionMap.delete();
$DDS::CurrentMenu = 0;
}
//Initialization
///////////////////////////////////////////////////////////////////////////
//Recursively initialize all drop down lists created before loading this script
function SimGroup::ddsInitChildren(%this)
{
if(%this.getClassName() $= "GuiPopUpMenuCtrl")
%this.ddsInit();
for(%i = %this.getCount() - 1; %i >= 0; %i--)
%this.getObject(%i).ddsInitChildren();
}
//Activate package
activatePackage(DropDownSearch);
//Init all existing controls
//GuiGroup.ddsInitChildren();