-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuEditorLoader.pas
More file actions
703 lines (607 loc) · 22.1 KB
/
uEditorLoader.pas
File metadata and controls
703 lines (607 loc) · 22.1 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
unit uEditorLoader;
interface
uses
WinAPI.Windows, System.SysUtils, System.StrUtils, System.Classes, System.Math, uEditor.Consts;
procedure EdInitServer(hWndMain: HWND; hWndCallback: HWND); stdcall; external 'Editor.dll' name '_EdInitServer@8';
procedure EdExitServer; stdcall; external 'Editor.dll' name '_EdExitServer@0';
procedure EdExec(const Cmd: PAnsiChar); stdcall; external 'Editor.dll' name '_EdExec@4';
procedure EdSetProp(const Topic, Item, Value: PAnsiChar); stdcall; external 'Editor.dll' name '_EdSetProp@12';
function EdGetProp(const Topic, Item: PAnsiChar): PAnsiChar; stdcall; external 'Editor.dll' name '_EdGetProp@8';
// Äëÿ óäîáñòâà
procedure ServerCmd(command: string); // îòïðàâèòü êîìàíäó
function ServerGetProp(const Topic, Item: string): string; // ïîëó÷èòü ÷òî-òî
procedure ServerSetProp(const Topic, Item, Value: string); // Topic = Îáúåêò, Item = Ïîëå, Value = çíà÷åíèå?
// Utilities
function ExtractCommaString(var S: string): string;
function ExtractString(var S: string): string;
function NumSelectedActors(): Integer;
function NumSelectedPolys(): Integer;
function SelectedIsMover(): Boolean;
function SelectedIsBrush(): Boolean;
function SelectedIsChildOf(className: string): Boolean;
function GetSelectedClass(): string;
function GetPackagesList(): TArray<string>;
function Get_GIsRequestingExit(): Integer;
function DynamicFindClass(const SearchText: string): string;
function DynamicFindClassInChildren(const ParentClass: string; const SearchText: string): string;
// Êîíâåðòåð, äþéìû
function UUToInches(UU: Double): Double;
function InchesToUU(Inches: Double): Double;
function UUToFeet(UU: Double): Double;
function FeetToUU(Feet: Double): Double;
// ñàíòèìåòðû, ìåòðû
function UUToCm(UU: Double): Double;
function CmToUU(Cm: Double): Double;
function UUToMeters(UU: Double): Double;
function MetersToUU(Meters: Double): Double;
// óãëû
function UUToDegrees(UU: Integer): Double;
function DegreesToUU(Degrees: Double): Integer;
function UUToRadians(UU: Integer): Double;
function RadiansToUU(Radians: Double): Integer;
// Texture skewing
function GenerateVertTexSkew(VertRise, VertRun, VertScale: Double; bVertNegate: Boolean): string;
function GenerateHorzTexSkew(HorzRise, HorzRun, HorzScale: Double; bHorzNegate: Boolean): string;
function GenerateHVTexSkew(HorzRise, HorzRun, HorzScale: Double; bHorzNegate: Boolean;
VertRise, VertRun, VertScale: Double; bVertNegate: Boolean): string;
//
function GetTextureSize(const TexName: string): string;
function ExtractField(const fieldName, text: string): string;
function GetActorEvent(const TextToProcess: string): string;
function GetActorTag(const TextToProcess: string): string;
function GetActorName(const TextToProcess: string): string;
function GetActorAttachTag(const TextToProcess: string): string;
function GetActorBindName(const TextToProcess: string): string;
function GetActorBarkBindName(const TextToProcess: string): string;
procedure ServerSetCurrentClass(const NewClass: string);
procedure SetGridSize(const NewValue: Integer);
procedure SetRotGridSize(const NewValue: Integer);
procedure SetMoverKeyFrame(const NewKey: Integer);
procedure SelectActorsOfClass(const NewClass: string);
procedure RotateTexture(Angle: Double); // Øêîëüíàÿ ðîìàíòèêà
procedure ScaleTexture(ScaleUU, ScaleVV: Double; bRelative: Boolean);
// New commands from Hanflings's EditorPatch
procedure SelectOfSubClass(const NewClass: string); // Works like the SELECT OFCLASS command, but includes subclasses as well.
procedure SelectOfTag(const NewTag: string); // Selects all Actors with Tag=<tag>.
procedure SelectOfEvent(const NewEvent: string); // Selects all Actors with Event=<event>.
procedure SelectOfAttachTag(const NewTag: string); // Selects all Actors with AttachTag=<attachtag>.
procedure SelectOfBindName(const NewBindName: string); // Selects all Actors with Bindname=<bindname>
procedure SelectOfBarkBindName(const NewBarkBindName: string); // Selects all Actors with BarkBindname=<barkbindname>
// Remove fonts from lists
procedure RemoveFilteredItems(List: TStrings; const FilterArray: array of string);
implementation
procedure ServerCmd(command: string);
var
Cmd: AnsiString;
begin
Cmd := AnsiString(command); // Ïðåîáðàçóåì ñòðîêó â AnsiString
EdExec(PAnsiChar(Cmd));
end;
function ServerGetProp(const Topic, Item: string): string;
var
AnsiTopic, AnsiItem: AnsiString;
AnsiResult: PAnsiChar;
begin
AnsiTopic := AnsiString(Topic);
AnsiItem := AnsiString(Item);
// Ïðåîáðàçóåì êîìàíäó â AnsiString
AnsiResult := EdGetProp(PAnsiChar(AnsiTopic), PAnsiChar(AnsiItem));
Result := string(AnsiResult);
end;
procedure ServerSetProp(const Topic, Item, Value: string);
var
AnsiTopic, AnsiItem, AnsiValue: AnsiString;
begin
AnsiTopic := AnsiString(Topic);
AnsiItem := AnsiString(Item);
AnsiValue := AnsiString(Value);
EdSetProp(PAnsiChar(AnsiTopic), PAnsiChar(AnsiItem), PAnsiChar(AnsiValue));
end;
function ExtractCommaString(var S: string): string;
begin
S := Trim(S); // Óáèðàåì ïðîáåëû ïî êðàÿì
var i := Pos(',', S); // Èùåì ïåðâóþ çàïÿòóþ
if i <> 0 then
begin
Result := Copy(S, 1, i - 1); // Èçâëåêàåì ýëåìåíò äî çàïÿòîé
Delete(S, 1, i); // Óäàëÿåì èçâëå÷åííûé ýëåìåíò è çàïÿòóþ èç èñõîäíîé ñòðîêè
end
else
begin
Result := S; // Åñëè çàïÿòàÿ íå íàéäåíà, âîçâðàùàåì âñþ ñòðîêó
S := ''; // Î÷èùàåì èñõîäíóþ ñòðîêó
end;
end;
function ExtractString(var S: string): string;
var
i, j: Integer;
begin
S := Trim(S);
i := Pos(' ', S);
j := Pos(#9, S);
if (i = 0) or ((j <> 0) and (j < i)) then
i := j;
if i <> 0 then
begin
Result := Copy(S, 1, i - 1);
S := Copy(S, i + 1, Length(S));
end
else
begin
Result := S;
S := '';
end;
end;
function NumSelectedActors(): Integer;
begin
Result := StrToIntDef(ServerGetProp('Actor', 'NumSelected'),0);
end;
function NumSelectedPolys(): Integer;
begin
Result := StrToInt(ServerGetProp('Polys', 'NumSelected'));
end;
function SelectedIsMover(): Boolean;
begin
Result := StrToInt(ServerGetProp('Actor', 'IsKindOf CLASS=MOVER')) <> 0;
end;
function SelectedIsBrush(): Boolean;
begin
Result := StrToInt(ServerGetProp('Actor', 'IsKindOf CLASS=BRUSH')) <> 0;
end;
function SelectedIsChildOf(className: string): Boolean;
begin
Result := StrToInt(ServerGetProp('Actor', 'IsKindOf CLASS=' + className)) <> 0;
end;
function GetSelectedClass(): string;
begin
Result := ServerGetProp('Actor', 'ClassSelected');
end;
function GetPackagesList(): TArray<string>;
var
List: string;
Package: string;
Packages: TArray<string>;
bShouldAdd: Boolean;
begin
// Why not EditPackages..?
List := ServerGetProp('OBJ', 'PACKAGES CLASS=Class');
// Çàïóñêàåì öèêë, ïîêà â ñòðîêå List åñòü ýëåìåíòû
while List <> '' do
begin
// Èçâëåêàåì ïåðâûé ýëåìåíò èç ñòðîêè
Package := ExtractCommaString(List);
// Ïðîâåðÿåì, åñëè ýòîò ïàêåò íàõîäèòñÿ â ñïèñêå FilterPackages
bShouldAdd := True;
for var i := Low(uEditor.Consts.EditorPatchFileNames) to High(uEditor.Consts.FilterPackages) do
begin
if SameText(Package, uEditor.Consts.FilterPackages[i]) then
begin
bShouldAdd := False;
Break;
end;
end;
// Åñëè ïàêåò íå â ñïèñêå FilterPackages, äîáàâëÿåì åãî â ìàññèâ
if bShouldAdd then
Packages := Packages + [Package];
end;
// Âîçâðàùàåì ìàññèâ ïàêåòîâ
Result := Packages;
end;
function Get_GIsRequestingExit(): Integer;
var
hCoreDll: HMODULE;
GIsRequestingExitPtr: PInteger;
begin
Result := -1; // Default result value to indicate failure
// Load the DLL
hCoreDll := LoadLibrary('Core.dll');
if hCoreDll = 0 then
begin
MessageBox(0, 'Failed to load Core.dll', 'Core.dll', MB_OK + MB_ICONSTOP + MB_DEFBUTTON2 + MB_TOPMOST);
Exit;
end;
try
// Get the address of the GIsRequestingExit variable
GIsRequestingExitPtr := GetProcAddress(hCoreDll, '?GIsRequestingExit@@3HA');
if GIsRequestingExitPtr = nil then
begin
MessageBox(0, 'Failed to locate GIsRequestingExit in ', 'Core.dll', MB_OK + MB_ICONSTOP + MB_DEFBUTTON2 + MB_TOPMOST);
Exit;
end;
// Read the value of GIsRequestingExit
Result := GIsRequestingExitPtr^;
finally
// Free the library
FreeLibrary(hCoreDll);
end;
end;
function DynamicFindClass(const SearchText: string): string;
var
StartFrom: string;
Lines: TStringList;
i: Integer;
CurrentLine, ClassName: string;
begin
Result := 'Not Found'; // Íà÷àëüíîå çíà÷åíèå
// Çàïðàøèâàåì äî÷åðíèå êëàññû äëÿ 'Actor'
StartFrom := ServerGetProp('Class', 'Query Parent=Actor');
Lines := TStringList.Create();
try
Lines.Text := StartFrom;
for i := 0 to Lines.Count - 1 do
begin
CurrentLine := Trim(Lines[i]);
// Èçâëåêàåì èìÿ êëàññà äî ñèìâîëà '|'
ClassName := Copy(CurrentLine, 1, Pos('|', CurrentLine) - 1);
// Óáèðàåì ñèìâîë * åñëè îí ïðèñóòñòâóåò
if ClassName[1] = '*' then
Delete(ClassName, 1, 1);
// Ñðàâíåíèå ñ èñêîìûì òåêñòîì
if SameText(ClassName, SearchText) then
begin
Result := ClassName;
Exit;
end;
// Åñëè ó êëàññà åñòü äî÷åðíèå ýëåìåíòû (îáîçíà÷åíèå |C)
if EndsText('|C', CurrentLine) then
begin
// Ðåêóðñèâíûé âûçîâ ôóíêöèè äëÿ ïîèñêà â äî÷åðíèõ óçëàõ
Result := DynamicFindClassInChildren(ClassName, SearchText);
if Result <> 'Not Found' then
Exit;
end;
end;
finally
Lines.Free();
end;
end;
function DynamicFindClassInChildren(const ParentClass: string; const SearchText: string): string;
var
StartFrom: string;
Lines: TStringList;
i: Integer;
CurrentLine, ClassName: string;
begin
Result := 'Not Found'; // Íà÷àëüíîå çíà÷åíèå
// Çàïðàøèâàåì äî÷åðíèå êëàññû äëÿ ParentClass
StartFrom := ServerGetProp('Class', Format('Query Parent=%s', [ParentClass]));
Lines := TStringList.Create;
try
Lines.Text := StartFrom;
for i := 0 to Lines.Count - 1 do
begin
CurrentLine := Trim(Lines[i]);
// Èçâëåêàåì èìÿ êëàññà äî ñèìâîëà '|'
ClassName := Copy(CurrentLine, 1, Pos('|', CurrentLine) - 1);
// Óáèðàåì ñèìâîë * åñëè îí ïðèñóòñòâóåò
if ClassName[1] = '*' then
Delete(ClassName, 1, 1);
// Ñðàâíåíèå ñ èñêîìûì òåêñòîì
if SameText(ClassName, SearchText) then
begin
Result := ClassName;
Exit;
end;
// Åñëè ó êëàññà åñòü äî÷åðíèå ýëåìåíòû (îáîçíà÷åíèå |C)
if EndsText('|C', CurrentLine) then
begin
// Ðåêóðñèâíûé âûçîâ ôóíêöèè äëÿ ïîèñêà â äî÷åðíèõ óçëàõ
Result := DynamicFindClassInChildren(ClassName, SearchText);
if Result <> 'Not Found' then
Exit;
end;
end;
finally
Lines.Free();
end;
end;
function UUToInches(UU: Double): Double;
begin
Result := UU * 0.75;
end;
function InchesToUU(Inches: Double): Double;
begin
Result := Inches / 0.75;
end;
function UUToFeet(UU: Double): Double;
begin
Result := UU / 16;
end;
function FeetToUU(Feet: Double): Double;
begin
Result := Feet * 16;
end;
// ñàíòèìåòðû, ìåòðû
function UUToCm(UU: Double): Double;
begin
Result := UU * 1.9046875; // 1 UU = 1.9046875 ñì
end;
function CmToUU(Cm: Double): Double;
begin
Result := Cm / 1.9046875; // 1 UU = 1.9046875 ñì
end;
function UUToMeters(UU: Double): Double;
begin
Result := UUToCm(UU) / 100;
end;
function MetersToUU(Meters: Double): Double;
begin
Result := CmToUU(Meters * 100);
end;
// óãëû
function UUToDegrees(UU: Integer): Double;
begin
Result := (UU / 65536) * 360;
end;
function DegreesToUU(Degrees: Double): Integer;
begin
Result := Round((Degrees / 360) * 65536);
end;
function UUToRadians(UU: Integer): Double;
begin
Result := (UU / 65536) * 2 * Pi;
end;
function RadiansToUU(Radians: Double): Integer;
begin
Result := Round((Radians / (2 * Pi)) * 65536);
end;
function GenerateVertTexSkew(VertRise, VertRun, VertScale: Double; bVertNegate: Boolean): string;
var
VV, VU: Double;
FormatSettings: TFormatSettings;
begin
FormatSettings := TFormatSettings.Create();
FormatSettings.DecimalSeparator := '.';
if VertRise = 0 then
begin
VV := 1.0 / VertScale;
VU := 0.0; // When VertRise is zero, VU should be zero
end
else
begin
VV := 1.0 / VertScale;
VU := -1.0 / (VertScale * VertRun / VertRise);
if bVertNegate = True then
VU := -VU;
end;
Result := Format('POLY TEXSCALE VV=%.6f VU=%.6f', [VV, VU], FormatSettings);
end;
function GenerateHorzTexSkew(HorzRise, HorzRun, HorzScale: Double; bHorzNegate: Boolean): string;
var
UU, UV: Double;
FormatSettings: TFormatSettings;
begin
FormatSettings := TFormatSettings.Create();
FormatSettings.DecimalSeparator := '.';
// Ïðîâåðêà íà HorzRun = 0
if HorzRun = 0 then
begin
UU := 1.0 / HorzScale;
UV := 0;
end
else
begin
UU := 1.0 / HorzScale;
UV := -1.0 / (HorzScale * HorzRise / HorzRun);
if bHorzNegate = True then
UV:= -UV;
end;
Result := Format('POLY TEXSCALE UU=%.6f UV=%.6f', [UU, UV], FormatSettings);
end;
function GenerateHVTexSkew(HorzRise, HorzRun, HorzScale: Double; bHorzNegate: Boolean;
VertRise, VertRun, VertScale: Double; bVertNegate: Boolean): string;
var
UU, UV, VV, VU: Double;
FormatSettings: TFormatSettings;
begin
FormatSettings := TFormatSettings.Create();
FormatSettings.DecimalSeparator := '.';
// Calculate Horizontal (UU, UV) skew
if HorzRun = 0 then
begin
UU := 1.0 / HorzScale;
UV := 0.0; // When HorzRun is zero, UV should be zero
end
else
begin
UU := 1.0 / HorzScale;
UV := -1.0 / (HorzScale * HorzRise / HorzRun);
if bHorzNegate then
UV := -UV;
end;
// Calculate Vertical (VV, VU) skew
if VertRise = 0 then
begin
VV := 1.0 / VertScale;
VU := 0.0; // When VertRise is zero, VU should be zero
end
else
begin
VV := 1.0 / VertScale;
VU := -1.0 / (VertScale * VertRun / VertRise);
if bVertNegate then
VU := -VU;
end;
// Combine results
Result := Format('POLY TEXSCALE UU=%.6f UV=%.6f VV=%.6f VU=%.6f', [UU, UV, VV, VU], FormatSettings);
end;
function GetTextureSize(const TexName: string): string;
begin
Result := ServerGetProp('Texture', 'SIZE TEXTURE=' + Trim(TexName));
end;
function ExtractField(const fieldName, text: string): string;
var
posStart, posEnd: Integer;
searchPattern: string;
begin
Result := '';
searchPattern := fieldName + '='; // Ôîðìèðóåì òî÷íûé øàáëîí ïîèñêà
posStart := Pos(searchPattern, text);
if posStart > 0 then
begin
posStart := posStart + Length(searchPattern); // Ñìåùàåìñÿ ïîñëå '='
// Ïðîâåðÿåì, íà÷èíàåòñÿ ëè çíà÷åíèå ñ êàâû÷åê
if (text[posStart] = '"') then
begin
Inc(posStart); // Ïðîïóñê íà÷àëüíîé êàâû÷êè
posEnd := PosEx('"', text, posStart);
if posEnd > 0 then
Result := Copy(text, posStart, posEnd - posStart);
end
else
begin
posEnd := PosEx(#13#10, text, posStart); // Ïîèñê êîíöà ñòðîêè
if posEnd = 0 then
posEnd := Length(text) + 1;
Result := Trim(Copy(text, posStart, posEnd - posStart));
end;
end;
end;
function GetActorEvent(const TextToProcess: string): string;
begin
Result := ExtractField('Event', TextToProcess);
end;
function GetActorTag(const TextToProcess: string): string;
begin
Result := ExtractField('Tag', TextToProcess);
end;
function GetActorName(const TextToProcess: string): string;
begin
Result := ExtractField('Name', TextToProcess);
end;
function GetActorAttachTag(const TextToProcess: string): string;
begin
Result := ExtractField('AttachTag', TextToProcess);
end;
function GetActorBindName(const TextToProcess: string): string;
begin
Result := ExtractField('BindName', TextToProcess);
end;
function GetActorBarkBindName(const TextToProcess: string): string;
begin
Result := ExtractField('BarkBindName', TextToProcess);
end;
procedure ServerSetCurrentClass(const NewClass: string);
begin
var CheckSuccess := DynamicFindClass(NewClass);
if UpperCase(CheckSuccess) = UpperCase(NewClass) then
ServerCmd('SETCURRENTCLASS CLASS=' + Trim(NewClass))
else
MessageBox(0, PChar(NewClass +': '+ CheckSuccess), 'Class not found', MB_OK + MB_ICONINFORMATION + MB_TOPMOST);
end;
procedure SetGridSize(const NewValue: Integer);
begin
ServerCmd(Format('MAP GRID X=%d Y=%d Z=%d', [NewValue, NewValue, NewValue]));
end;
procedure SetRotGridSize(const NewValue: Integer);
var
FormatSettings: TFormatSettings;
begin
FormatSettings := TFormatSettings.Create();
FormatSettings.DecimalSeparator := '.';
var msdos_sys:= NewValue / 256;
ServerCmd(Format('MAP ROTGRID PITCH=%.6f YAW=%.6f ROLL=%.6f', [msdos_sys, msdos_sys, msdos_sys], FormatSettings));
ServerCmd('MAP ROTGRID=ON');
end;
procedure SetMoverKeyFrame(const NewKey: Integer);
begin
ServerCmd(Format('ACTOR KEYFRAME NUM=%d', [NewKey]));
end;
procedure SelectActorsOfClass(const NewClass: string);
begin
ServerCmd(Format('ACTOR SELECT OFCLASS CLASS=%s', [NewClass]));
end;
procedure RotateTexture(Angle: Double);
var
AngleInRadians, cosTheta, sinTheta: Double;
Command: string;
FormatSettings: TFormatSettings;
begin
// Óñòàíàâëèâàåì íàñòðîéêè ôîðìàòà äëÿ ÷èñåë, ÷òîáû èñïîëüçîâàòü òî÷êó êàê äåñÿòè÷íûé ðàçäåëèòåëü
FormatSettings := TFormatSettings.Create;
FormatSettings.DecimalSeparator := '.';
// Ïåðåâîä óãëà â ðàäèàíû
AngleInRadians := DegToRad(Angle);
// Âû÷èñëÿåì êîñèíóñ è ñèíóñ óãëà
cosTheta := Cos(AngleInRadians);
sinTheta := Sin(AngleInRadians);
// Ôîðìèðóåì êîìàíäó äëÿ îòïðàâêè íà ñåðâåð
Command := 'POLY TEXMULT UU=' + FormatFloat('.###############', cosTheta, FormatSettings) +
' VV=' + FormatFloat('.###############', cosTheta, FormatSettings) +
' UV=' + FormatFloat('.###############', sinTheta, FormatSettings) +
' VU=' + FormatFloat('.###############', -sinTheta, FormatSettings);
// Îòïðàâêà êîìàíäû íà ñåðâåð
ServerCmd(Command);
end;
procedure ScaleTexture(ScaleUU, ScaleVV: Double; bRelative: Boolean);
var
Command: string;
UU, VV: Double;
FormatSettings: TFormatSettings;
begin
// Ïðîâåðêà ìàñøòàáà íà êîððåêòíîñòü (íå ðàâåí íóëþ)
if (ScaleUU = 0) or (ScaleVV = 0) then
begin
MessageBox(0,'Error: Scale cannot be zero!', 'ScaleTexture()',MB_OK + MB_ICONSTOP + MB_TOPMOST);
Exit;
end;
// Óñòàíàâëèâàåì íàñòðîéêè ôîðìàòà äëÿ ÷èñåë, ÷òîáû èñïîëüçîâàòü òî÷êó êàê äåñÿòè÷íûé ðàçäåëèòåëü
FormatSettings := TFormatSettings.Create;
FormatSettings.DecimalSeparator := '.';
// Âû÷èñëåíèå çíà÷åíèé UU è VV
UU := 1 / ScaleUU;
VV := 1 / ScaleVV;
// Ôîðìèðóåì êîìàíäó â çàâèñèìîñòè îò çíà÷åíèÿ bRelative
if bRelative = True then
Command := 'POLY TEXSCALE RELATIVE UU=' + FormatFloat('.#####', UU, FormatSettings) +
' VV=' + FormatFloat('.#####', VV, FormatSettings)
else
Command := 'POLY TEXSCALE UU=' + FormatFloat('.#####', UU, FormatSettings) +
' VV=' + FormatFloat('.#####', VV, FormatSettings);
ServerCmd(Command);
end;
procedure SelectOfSubClass(const NewClass: string); // Works like the SELECT OFCLASS command, but includes subclasses as well.
begin
ServerCmd(Format('ACTOR SELECT OFSUBCLASS CLASS=%s', [NewClass]));
end;
procedure SelectOfTag(const NewTag: string); // Selects all Actors with Tag=<tag>.
begin
ServerCmd(Format('ACTOR SELECT OFTAG TAG=%s', [NewTag]));
end;
procedure SelectOfEvent(const NewEvent: string); // Selects all Actors with Event=<event>.
begin
ServerCmd(Format('ACTOR SELECT OFEVENT EVENT=%s', [NewEvent]));
end;
procedure SelectOfAttachTag(const NewTag: string); // Selects all Actors with AttachTag=<attachtag>.
begin
ServerCmd(Format('ACTOR SELECT OFATTACHTAG ATTACHTAG=%s', [NewTag]));
end;
procedure SelectOfBindName(const NewBindName: string); // Selects all Actors with Bindname=<bindname>
begin
ServerCmd(Format('ACTOR SELECT OFBINDNAME BINDNAME=%s', [NewBindName]));
end;
procedure SelectOfBarkBindName(const NewBarkBindName: string); // Selects all Actors with BarkBindname=<barkbindname>
begin
ServerCmd(Format('ACTOR SELECT OFBARKBINDNAME BARKBINDNAME=%s', [NewBarkBindName]));
end;
procedure RemoveFilteredItems(List: TStrings; const FilterArray: array of string);
var
i, j: Integer;
begin
i := List.Count - 1;
// Ïðîõîäèì ïî ýëåìåíòàì ñïèñêà ñ êîíöà
while i >= 0 do
begin
// Ïðîâåðÿåì, ñîäåðæèòñÿ ëè ýëåìåíò â ìàññèâå FilterArray
for j := Low(FilterArray) to High(FilterArray) do
begin
if UpperCase(List[i]) = UpperCase(FilterArray[j]) then
begin
List.Delete(i); // Óäàëÿåì ýëåìåíò
Break; // Ïðåðûâàåì öèêë, òàê êàê ýëåìåíò óæå óäàëåí
end;
end;
Dec(i);
end;
end;
end.