-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathBaseConflict.EntityComponents.Client.GUI.pas
3272 lines (2889 loc) · 106 KB
/
BaseConflict.EntityComponents.Client.GUI.pas
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
unit BaseConflict.EntityComponents.Client.GUI;
interface
uses
Generics.Collections,
System.SysUtils,
System.RegularExpressions,
System.Math,
Engine.Log,
Engine.Input,
Engine.Core,
Engine.Core.Types,
Engine.Vertex,
Engine.GUI,
Engine.GFXApi,
Engine.GFXApi.Types,
Engine.Script,
Engine.Helferlein,
Engine.Helferlein.DataStructures,
Engine.Helferlein.Windows,
Engine.Terrain,
Engine.Math,
Engine.Math.Collision2D,
Engine.Math.Collision3D,
BaseConflict.Map,
BaseConflict.Game,
BaseConflict.Classes.Gamestates.GUI,
BaseConflict.Classes.Shared,
BaseConflict.Constants,
BaseConflict.Constants.Cards,
BaseConflict.Constants.Client,
BaseConflict.Types.Shared,
BaseConflict.Types.Target,
BaseConflict.Globals,
BaseConflict.Globals.Client,
BaseConflict.Entity,
BaseConflict.EntityComponents.Shared,
BaseConflict.EntityComponents.Shared.Wela,
BaseConflict.EntityComponents.Client,
BaseConflict.Settings.Client;
type
{$RTTI INHERIT}
/// <summary> Handles a commanderability like build, spell. Handles the related GUI. </summary>
TAbilitybuttonComponent = class(TEntityComponent)
protected
FSpell : TCommanderSpellData;
FMultiMode : TArray<byte>;
function GetDataEntity() : TEntity;
procedure DeRegisterButton; virtual;
procedure RegisterButton; virtual;
procedure GenerateSpellData;
published
[XEvent(eiRegisterInGui, epLast, etTrigger)]
/// <summary> Registers this ability in the gui. </summary>
function OnRegisterInGUI() : boolean;
[XEvent(eiDeregisterInGui, epLast, etTrigger)]
/// <summary> Deregister this ability in the gui. </summary>
function OnClearGUI() : boolean;
public
function IsMultiMode(ModeGroups : TArray<byte>) : TAbilitybuttonComponent;
destructor Destroy; override;
end;
/// <summary> Specify the ability as a generic commander ability. </summary>
TCommanderAbilityButtonComponent = class(TAbilitybuttonComponent)
protected
FHUDCommanderAbility : THUDCommanderAbility;
FUID : string;
procedure RegisterButton; override;
procedure DeRegisterButton; override;
public
function UID(const UID : string) : TCommanderAbilityButtonComponent;
end;
/// <summary> Specify the ability as buildability. </summary>
TDeckCardButtonComponent = class(TAbilitybuttonComponent)
protected
FHUDDeckSlot : THUDDeckSlot;
FSlot : integer;
FCardInfo : TCardInfo;
FCooldownGroup : SetComponentGroup;
procedure RegisterButton; override;
procedure DeRegisterButton; override;
published
[XEvent(eiIdle, epMiddle, etTrigger, esGlobal)]
/// <summary> Shows tooltip for buildabilities after a short delay. </summary>
function OnIdle() : boolean;
public
function Slot(Slot : integer) : TDeckCardButtonComponent;
function CardInfo(CardInfo : TCardInfo) : TDeckCardButtonComponent;
function SetCooldownGroup(Group : TArray<byte>) : TDeckCardButtonComponent;
end;
{$RTTI INHERIT}
/// <summary> Displays a unit ability. </summary>
TTooltipUnitAbilityComponent = class(TEntityComponent)
protected
FIsCardDescription : boolean;
FAbilityname : string;
FKeywords : TList<string>;
FVariables : TObjectList<TTranslationVariable>;
published
[XEvent(eiBuildAbilityList, epLower, etTrigger)]
function OnBuildAbilityList(AbilityIDList, KeywordIDList, CardDescriptionRaw : RParam) : boolean;
public
constructor Create(Owner : TEntity; const AbilityName : string); reintroduce;
constructor CreateGrouped(Owner : TEntity; Group : TArray<byte>; const AbilityName : string); reintroduce;
function Keyword(const Keyword : string) : TTooltipUnitAbilityComponent;
function IsCardDescription() : TTooltipUnitAbilityComponent;
function PassInteger(const Key : string; Value : integer) : TTooltipUnitAbilityComponent; overload;
function PassInteger(const Key : string; Value : integer; const SpanClass : string) : TTooltipUnitAbilityComponent; overload;
function PassSingleAsInteger(const Key : string; Value : single) : TTooltipUnitAbilityComponent; overload;
function PassSingleAsInteger(const Key : string; Value : single; const SpanClass : string) : TTooltipUnitAbilityComponent; overload;
function PassPercentage(const Key : string; Value : integer) : TTooltipUnitAbilityComponent; overload;
function PassPercentage(const Key : string; Value : integer; const SpanClass : string) : TTooltipUnitAbilityComponent; overload;
function PassSingle(const Key : string; IntegralPart, FractionalPart : integer) : TTooltipUnitAbilityComponent; overload;
function PassSingle(const Key : string; IntegralPart, FractionalPart : integer; const SpanClass : string) : TTooltipUnitAbilityComponent; overload;
function PassString(const Key : string; const Value : string) : TTooltipUnitAbilityComponent; overload;
function PassString(const Key : string; const Value : string; const SpanClass : string) : TTooltipUnitAbilityComponent; overload;
destructor Destroy; override;
end;
{$RTTI INHERIT}
/// <summary> Shows a ping on the minimap. </summary>
TMinimapPingComponent = class(TEntityComponent)
protected const
PING_DURATION = 4000;
protected
FIconPath : string;
FSize : single;
published
[XEvent(eiFire, epLast, etTrigger)]
function OnFire(Targets : RParam) : boolean;
public
function Size(Size : single) : TMinimapPingComponent;
function Texture(const IconPath : string) : TMinimapPingComponent;
end;
{$RTTI INHERIT}
/// <summary> Displays a healthbar and other data above the entity. </summary>
TEntityDisplayWrapperComponent = class(TEntityComponent)
protected
FWrapper : TGUIStackPanel;
FOffset : RVector3;
procedure UpdatePosition;
published
[XEvent(eiAfterCreate, epLast, etTrigger)]
/// <summary> Init the position. </summary>
function OnAfterDeserialization() : boolean;
[XEvent(eiIdle, epLow, etTrigger, esGlobal)]
/// <summary> Update position of the Resource display. </summary>
function OnIdle() : boolean;
[XEvent(eiGetEntityResourceWrapper, epFirst, etRead)]
/// <summary> Returns the wrapper. </summary>
function OnGetEntityResourceWrapper() : RParam;
public
constructor CreateGrouped(Owner : TEntity; Group : TArray<byte>); override;
function SetOffset(YOffset : single) : TEntityDisplayWrapperComponent;
destructor Destroy; override;
end;
{$RTTI INHERIT}
/// <summary> Displays icons above the entity. </summary>
TEntityDisplayComponent = class abstract(TEntityComponent)
protected
FRegisteredInWrapper : boolean;
FDirty : boolean;
FOrderValue : integer;
FSizeYOverride : single;
procedure SetDirty;
function GetDefaultSize : RVector2; virtual;
function GetSize : RVector2;
function IsVisible : boolean; virtual;
procedure ComputeVisibility; virtual;
procedure Init; virtual;
procedure Update; virtual;
procedure Idle; virtual;
/// <summary> Component is applied all generic changes. </summary>
procedure PostProcessComponent(Component : TGUIComponent);
/// <summary> Component will be inserted into resource stack. Will be postprocessed before insert. </summary>
procedure InsertIntoWrapper(Component : TGUIComponent; Wrapper : TGUIStackPanel = nil);
published
[XEvent(eiAfterCreate, epLast, etTrigger)]
/// <summary> Create the Resourcebar. </summary>
function OnAfterDeserialization() : boolean;
[XEvent(eiIdle, epLow, etTrigger, esGlobal)]
/// <summary> Compute visibility. </summary>
function OnIdle() : boolean;
public
constructor Create(Owner : TEntity); override;
/// <summary> Determines an order value, where this display is placed relative to other stack elements. Default 0. </summary>
function OrderValue(OrderValue : integer) : TEntityDisplayComponent;
function SizeY(SizeY : single) : TEntityDisplayComponent;
end;
{$RTTI INHERIT}
/// <summary> Displays all icons above the entity. </summary>
TStateDisplayStackComponent = class(TEntityDisplayComponent)
protected
FStack : TGUIStackPanel;
function GetDefaultSize : RVector2; override;
procedure ComputeVisibility; override;
procedure Init; override;
procedure InitWrapper;
published
[XEvent(eiGetEntityStateWrapper, epFirst, etRead)]
/// <summary> Returns the wrapper. </summary>
function OnGetEntityStateWrapper() : RParam;
public
destructor Destroy; override;
end;
{$RTTI INHERIT}
/// <summary> Displays a particula icon above the entity. </summary>
TStateDisplayComponent = class(TEntityDisplayComponent)
protected
FReverseWelaIsReadyCheck : boolean;
FWelaIsReadyGroup : SetComponentGroup;
FTexturePath : string;
FIcon : TGUIComponent;
procedure Init; override;
procedure InitIcon;
procedure ComputeVisibility; override;
function IsVisible : boolean; override;
public
function CheckWelaIsReadyInGroup(const TargetGroup : TArray<byte>) : TStateDisplayComponent;
function ReverseWelaIsReadyCheck : TStateDisplayComponent;
function Texture(const TexturePath : string) : TStateDisplayComponent;
destructor Destroy; override;
end;
{$RTTI INHERIT}
/// <summary> Displays a progress bar above the entity. </summary>
TResourceDisplayComponent = class abstract(TEntityDisplayComponent)
protected
FHideIfEmpty, FHideIfFull : boolean;
FResourceType : EnumResource;
FTeamOverride : integer;
function ObservedResourceTypes : SetResource; virtual;
function TeamID : integer;
function IsVisible : boolean; override;
function IsEmpty : boolean; virtual;
function IsFull : boolean; virtual;
procedure ResourceChanged(Value : RParam); virtual;
procedure ResourceCapChanged(Value : RParam); virtual;
published
[XEvent(eiResourceBalance, epLast, etWrite)]
/// <summary> Update the healthbar. </summary>
function OnSetResource(ID, Value : RParam) : boolean;
[XEvent(eiResourceCap, epLast, etWrite)]
/// <summary> Update the healthbar. </summary>
function OnSetResourceCap(ID, Value : RParam) : boolean;
public
constructor Create(Owner : TEntity); override;
function ShowResource(ResourceType : integer) : TResourceDisplayComponent;
function ShowAsTeam(TeamID : integer) : TResourceDisplayComponent;
function HideIfEmpty : TResourceDisplayComponent;
function HideIfFull : TResourceDisplayComponent;
end;
{$RTTI INHERIT}
/// <summary> Displays a progress bar above the entity. </summary>
TResourceDisplayBarComponent = class abstract(TResourceDisplayComponent)
protected
FResourceBar : TGUIComponent;
FGradientTopOverride, FGradientBottomOverride : RColor;
procedure InitBar;
function GetDefaultBackgroundColor : RColor; virtual;
function GetBackgroundColor : RColor;
function GetColorGradient : RTuple<RColor, RColor>; overload;
function GetColorGradient(Resource : EnumResource) : RTuple<RColor, RColor>; overload;
function GetColorTop : RColor; overload;
function GetColorTop(Resource : EnumResource) : RColor; overload;
function GetColorBottom : RColor; overload;
function GetColorBottom(Resource : EnumResource) : RColor; overload;
procedure ComputeVisibility; override;
function IsVisible : boolean; override;
procedure Init; override;
public
function GradientTop(GradientTop : cardinal) : TResourceDisplayBarComponent;
function GradientBottom(GradientBottom : cardinal) : TResourceDisplayBarComponent;
destructor Destroy; override;
end;
{$RTTI INHERIT}
/// <summary> Displays a progress bar above the entity. </summary>
TResourceDisplayProgressBarComponent = class(TResourceDisplayBarComponent)
protected
FResourceFill : TGUIComponent;
procedure InitFillbar; virtual;
function GetCurrent : single;
function GetMax : single;
function GetProgress : single; virtual;
function IsEmpty : boolean; override;
function IsFull : boolean; override;
procedure Update; override;
procedure UpdateColors;
procedure Init; override;
end;
{$RTTI INHERIT}
/// <summary> Displays a progress bar above the entity. </summary>
TResourceDisplayHealthComponent = class(TResourceDisplayProgressBarComponent)
protected
FOverhealBar : TGUIComponent;
procedure InitFillbar; override;
function GetDefaultSize : RVector2; override;
function ObservedResourceTypes : SetResource; override;
function GetProgress : single; override;
function GetCurrentOverheal : single;
function GetMaxOverheal : single;
function IsVisible : boolean; override;
procedure Update; override;
published
[XEvent(eiChangeCommander, epLast, etTrigger, esGlobal)]
/// <summary> Refreshes the commanderswitch. </summary>
function OnChangeCommander(Index : RParam) : boolean;
[XEvent(eiClientOption, epLast, etTrigger, esGlobal)]
/// <summary> React to option changes. </summary>
function OnClientOption(ChangedOption : RParam) : boolean;
public
constructor Create(Owner : TEntity); override;
end;
{$RTTI INHERIT}
/// <summary> Displays a progress bar build by small chunks above the entity. </summary>
TResourceDisplayIntegerProgressBarComponent = class(TResourceDisplayBarComponent)
strict private
type
EnumAnimationState = (asShown, asIn, asOut, asHidden);
public const
MAX_CHUNKS_PER_ROW = 31;
MAX_ROWS = 2;
MAX_CHUNKS = MAX_ROWS * MAX_CHUNKS_PER_ROW;
protected
FFixedCap, FVisibleChunks : integer;
FNoCap : boolean;
procedure AddChunkToBar;
function GetDefaultBackgroundColor : RColor; override;
function GetCurrent : integer;
function GetMax : integer;
function IsEmpty : boolean; override;
function IsFull : boolean; override;
function AmountToInt(Amount : RParam) : integer;
procedure Init; override;
procedure RecomputeChunk(Index : integer);
procedure ResourceChanged(Value : RParam); override;
procedure ResourceCapChanged(Value : RParam); override;
procedure UpdateBar;
procedure Idle; override;
public
function NoCap : TResourceDisplayIntegerProgressBarComponent;
function FixedCap(NewCap : integer) : TResourceDisplayIntegerProgressBarComponent;
end;
{$RTTI INHERIT}
/// <summary> Prints the resource to the console. </summary>
TResourceDisplayConsoleComponent = class(TResourceDisplayComponent)
published
[XEvent(eiIdle, epLow, etTrigger, esGlobal)]
/// <summary> Compute visibility. </summary>
function OnIdle() : boolean;
end;
{$RTTI INHERIT}
/// <summary> Shows a circle to visualize a range. </summary>
TRangeIndicatorComponent = class(TEntityComponent)
protected
FColor : RColor;
FPermanent : boolean;
procedure Idle; virtual;
published
[XEvent(eiColorAdjustment, epLast, etTrigger)]
/// <summary> Changes the color of the circle. </summary>
function OnColorAdjustment(ColorAdjustment : RParam; absH, absS, absV : RParam) : boolean;
[XEvent(eiIdle, epLower, etTrigger, esGlobal)]
/// <summary> Draws the circle. </summary>
function OnIdle() : boolean;
[XEvent(eiDeploy, epLast, etTrigger)]
/// <summary> Removes this after real creation of the entity. </summary>
function OnDeploy() : boolean;
public
constructor CreateGrouped(Owner : TEntity; Group : TArray<byte>); override;
function IsPermanent : TRangeIndicatorComponent;
end;
{$RTTI INHERIT}
/// <summary> Shows a texture circle to visualize a range. Default with additive blending. </summary>
TTextureRangeIndicatorComponent = class(TRangeIndicatorComponent)
protected
FTexture, FInvalidTexture : TTexture;
FQuad : TVertexWorldspaceQuad;
FCircle : TVertexWorldspaceCircle;
FUseWeaponrange, FShowTeamColor, FDrawOnShowSpawnZone, FIsCone, FHideInCaptureMode : boolean;
FShownDynamicZones : SetDynamicZone;
FSize, FOpacity : single;
FConeDirection, FOffset : RVector2;
function GetSize : single;
procedure Idle; override;
published
[XEvent(eiDrawSpawnZone, epLower, etRead, esGlobal)]
/// <summary> Enumerates Zones. </summary>
function OnEnumerateSpawnZone(Zone, Previous : RParam) : RParam;
public
constructor Create(Owner : TEntity); override;
constructor CreateGrouped(Owner : TEntity; Group : TArray<byte>); override;
function SetAdditiveBlend : TTextureRangeIndicatorComponent;
function ShowWeaponRange : TTextureRangeIndicatorComponent;
function Size(Size : single) : TTextureRangeIndicatorComponent;
function Opacity(Opacity : single) : TTextureRangeIndicatorComponent;
/// <summary> Alters the used texture, uses 'SpelltargetGround.png' as default. </summary>
function SetTexture(TextureName : string) : TTextureRangeIndicatorComponent;
function DrawCircle(Thickness : single) : TTextureRangeIndicatorComponent;
/// <summary> Only with DrawCircle. </summary>
function Slice(SliceFrom, SliceTo : single) : TTextureRangeIndicatorComponent;
function ShowTeamColor : TTextureRangeIndicatorComponent;
function DrawOnShowSpawnZone(Zones : TArray<byte>) : TTextureRangeIndicatorComponent;
function HideInCaptureMode : TTextureRangeIndicatorComponent;
function Cone(DirectionX, DirectionZ : single) : TTextureRangeIndicatorComponent;
function Offset(OffsetX, OffsetZ : single) : TTextureRangeIndicatorComponent;
destructor Destroy; override;
end;
{$RTTI INHERIT}
/// <summary> Highlight all entities in range and valid to wela. </summary>
TRangeIndicatorHighlightEntitiesComponent = class(TRangeIndicatorComponent)
protected
FValidGroup, FInvalidGroup : SetComponentGroup;
/// <summary> Highlights entities. </summary>
procedure Idle; override;
public
function Valid(Group : TArray<byte>) : TRangeIndicatorHighlightEntitiesComponent;
function Invalid(Group : TArray<byte>) : TRangeIndicatorHighlightEntitiesComponent;
end;
{$RTTI INHERIT}
/// <summary> Metaclass for all spelltargetvisualizer. </summary>
TSpelltargetVisualizerComponent = class(TEntityComponent)
protected
/// <summary> Called every frame. </summary>
procedure Visualize(Data : TCommanderSpellData); virtual; abstract;
procedure Hide; virtual; abstract;
published
[XEvent(eiSpellVisualization, epMiddle, etTrigger)]
/// <summary> Updates the abilitypreview. </summary>
function OnVisualize(Data : RParam) : boolean;
[XEvent(eiSpellVisualizationHide, epMiddle, etTrigger)]
/// <summary> Updates the abilitypreview. </summary>
function OnHideVisualization() : boolean;
end;
{$RTTI INHERIT}
/// <summary> Shows a texture circle to visualize a cooldown. Default with additive blending. </summary>
TIndicatorCooldownCircleComponent = class(TSpelltargetVisualizerComponent)
protected
FTexture : TTexture;
FCircle : TVertexWorldspaceCircle;
FOffset : RVector3;
FOpacity, FRadius : single;
FScaleWith : EnumEventIdentifier;
FSpelltargetVisualizer, FInvertDirection, FInvert, FUseScaleWith : boolean;
FShowGameEvent : string;
FGameEventDuration : integer;
FShowResource : EnumResource;
FTeamOverride : integer;
FColorOverride : RColor;
FTargetPosition : RVector3;
FTargetTeam : integer;
FTargetCollisionRadius : single;
function Progress : single;
procedure Idle; virtual;
procedure Render; virtual;
procedure Visualize(Data : TCommanderSpellData); override;
procedure Hide; override;
published
[XEvent(eiIdle, epLower, etTrigger, esGlobal)]
/// <summary> Draws the circle. </summary>
function OnIdle() : boolean;
public
constructor Create(Owner : TEntity); override;
constructor CreateGrouped(Owner : TEntity; Group : TArray<byte>); override;
function SpelltargetVisualizer : TIndicatorCooldownCircleComponent;
function SetLinearBlend : TIndicatorCooldownCircleComponent;
function SetThickness(Thickness : single) : TIndicatorCooldownCircleComponent;
function SetRadius(Radius : single) : TIndicatorCooldownCircleComponent;
function ScaleWith(Event : EnumEventIdentifier) : TIndicatorCooldownCircleComponent;
function SetTexture(TextureName : string) : TIndicatorCooldownCircleComponent;
function Opacity(s : single) : TIndicatorCooldownCircleComponent;
function Offset(X, Y, Z : single) : TIndicatorCooldownCircleComponent;
function InvertDirection : TIndicatorCooldownCircleComponent;
function Invert : TIndicatorCooldownCircleComponent;
function ShowsResource(Resource : EnumResource) : TIndicatorCooldownCircleComponent;
function ShowsGameEvent(const GameEvent : string; Duration : integer) : TIndicatorCooldownCircleComponent;
function ShowAsTeam(TeamID : integer) : TIndicatorCooldownCircleComponent;
function Color(ForcedColor : cardinal) : TIndicatorCooldownCircleComponent;
destructor Destroy; override;
end;
{$RTTI INHERIT}
/// <summary> Shows a dashed texture circle to visualize a integer resource. Default with additive blending. </summary>
TIndicatorResourceCircleComponent = class(TIndicatorCooldownCircleComponent)
protected
FFixedCap : integer;
FPadding : single;
FChunks : TObjectList<TVertexWorldspaceCircle>;
procedure Idle; override;
procedure Render; override;
public
constructor CreateGrouped(Owner : TEntity; Group : TArray<byte>); override;
function Padding(Angle : single) : TIndicatorResourceCircleComponent;
function FixedCap(FixedCap : integer) : TIndicatorResourceCircleComponent;
destructor Destroy; override;
end;
{$RTTI INHERIT}
/// <summary> For each target the the texture is placed beneath it. </summary>
TSpelltargetVisualizerShowTextureComponent = class(TSpelltargetVisualizerComponent)
protected
type
TTargetInfo = class
Texture, Invalidtexture : TTexture;
Size, Opacity : single;
Additive : boolean;
constructor Create;
destructor Destroy; override;
end;
var
FQuads : TObjectList<TVertexWorldspaceQuad>;
/// <summary> Sets the textures (Valid, Invalid Target) for each targetindex. If not specified defaults to 0. </summary>
FInfo : TObjectDictionary<integer, TTargetInfo>;
FDefaultInfo : TTargetInfo;
FNoValidChecks : boolean;
function GetInfo(Index : integer) : TTargetInfo;
function GetOrCreateInfo(Index : integer) : TTargetInfo;
procedure Visualize(Data : TCommanderSpellData); override;
procedure Hide; override;
public
constructor CreateGrouped(Owner : TEntity; Group : TArray<byte>); override;
function SetTexture(TexturePath : string; ForIndex : integer = 0) : TSpelltargetVisualizerShowTextureComponent;
function SetSize(Size : single; ForIndex : integer = 0) : TSpelltargetVisualizerShowTextureComponent;
function Opacity(Opacity : single; ForIndex : integer = 0) : TSpelltargetVisualizerShowTextureComponent;
function Additive(ForIndex : integer = 0) : TSpelltargetVisualizerShowTextureComponent;
function NoValidChecks : TSpelltargetVisualizerShowTextureComponent;
destructor Destroy; override;
end;
{$RTTI INHERIT}
/// <summary> Shows a text on the targets. </summary>
TIndicatorShowTextComponent = class(TSpelltargetVisualizerComponent)
private
const
DEFAULT_OFFSET_FROM_CURSOR : RIntVector2 = (X : 25; Y : - 10);
protected
FShownResource : EnumResource;
FResourceGroup : SetComponentGroup;
FResourceFromCommander, FNoCap, FResourceGroupOfSpell, FClamps, FUseFixedCap : boolean;
FFixedCap : integer;
FText : TVertexFont;
FCursorOffset : RIntVector2;
FColor, FColorAtCap : RColor;
FClamp : RIntVector2;
FSpelltargetVisualizer : boolean;
FTargetPosition : RVector3;
procedure Visualize(Data : TCommanderSpellData); override;
procedure Hide; override;
procedure Idle; virtual;
procedure Render; virtual;
published
[XEvent(eiIdle, epLower, etTrigger, esGlobal)]
function OnIdle() : boolean;
public
constructor CreateGrouped(Owner : TEntity; Group : TArray<byte>); override;
function ShowResource(Resource : EnumResource) : TIndicatorShowTextComponent;
function ResourceGroup(Group : TArray<byte>) : TIndicatorShowTextComponent;
function ResourceFromCommander : TIndicatorShowTextComponent;
function Clamp(Minimum, Maximum : integer) : TIndicatorShowTextComponent;
function Color(Color : cardinal) : TIndicatorShowTextComponent;
function ColorAtCap(Color : cardinal) : TIndicatorShowTextComponent;
function FixedCap(Value : integer) : TIndicatorShowTextComponent;
function NoCap : TIndicatorShowTextComponent;
function SpelltargetVisualizer : TIndicatorShowTextComponent;
function ResourceGroupOfSpell : TIndicatorShowTextComponent;
function CursorOffset(X, Y : integer) : TIndicatorShowTextComponent;
destructor Destroy; override;
end;
{$RTTI INHERIT}
/// <summary> For each target the eiWelaUnitPattern is meta created and placed there. </summary>
TSpelltargetVisualizerShowPatternComponent = class(TSpelltargetVisualizerComponent)
protected
FForIndex : integer;
FPattern : TArray<TEntity>;
procedure Visualize(Data : TCommanderSpellData); override;
procedure Hide; override;
public
constructor CreateGrouped(Owner : TEntity; Group : TArray<byte>); override;
function ShowForIndex(Index : integer) : TSpelltargetVisualizerShowPatternComponent;
destructor Destroy; override;
end;
{$RTTI INHERIT}
/// <summary> Places a line between the first to targets. If fewer targets are passed, nothing will be showed. </summary>
TSpelltargetVisualizerLineBetweenTargetsComponent = class(TSpelltargetVisualizerComponent)
protected
FLine : TVertexLine;
FTexture, FInvalidTexture : TTexture;
FRatio : single;
procedure Visualize(Data : TCommanderSpellData); override;
procedure Hide; override;
public
constructor CreateGrouped(Owner : TEntity; Group : TArray<byte>); override;
function Width(Width : single) : TSpelltargetVisualizerLineBetweenTargetsComponent;
function Additive : TSpelltargetVisualizerLineBetweenTargetsComponent;
function Texture(const TexturePath : string) : TSpelltargetVisualizerLineBetweenTargetsComponent;
destructor Destroy; override;
end;
{$RTTI INHERIT}
/// <summary> A selected entity gets this component. </summary>
TSelectedEntityComponent = class(TEntityComponent)
protected
SendUnselect : boolean;
FTexture, FRangeTexture : TTexture;
FQuad, FRangeQuad : TVertexWorldspaceQuad;
published
[XEvent(eiSelectEntity, epLower, etTrigger, esGlobal)]
/// <summary> Kills this component. </summary>
function OnSelectEntity(Entity : RParam) : boolean;
[XEvent(eiIdle, epLow, etTrigger, esGlobal)]
/// <summary> Renders a circle around the selected entity. </summary>
function OnIdle : boolean;
[XEvent(eiUnitProperties, epMiddle, etRead)]
/// <summary> Tags the unit with certain properties. </summary>
function OnUnitProperies(Previous : RParam) : RParam;
public
constructor Create(Owner : TEntity); reintroduce;
destructor Destroy; override;
end;
{$RTTI INHERIT}
/// <summary> Visualizes the target gridpoints in red or green, if it's blocked or not. </summary>
TWelaTargetConstraintGridVisualizedComponent = class(TWelaTargetConstraintGridComponent)
protected
function CheckGridNode(TargetBuildZone : TBuildZone; WorldCoord : RVector2) : boolean; override;
public
constructor CreateGrouped(Owner : TEntity; Group : TArray<byte>); override;
end;
{$RTTI INHERIT}
TShowOnMinimapComponent = class(TEntityComponent)
protected
FIconSize : single;
FIconPath : string;
published
[XEvent(eiAfterCreate, epLast, etTrigger)]
/// <summary> Register at minimap. </summary>
function OnAfterCreate() : boolean;
public
constructor Create(Owner : TEntity); reintroduce;
function SetIconSize(Size : single) : TShowOnMinimapComponent;
destructor Destroy(); override;
end;
implementation
{ TTooltipUnitAbilityComponent }
constructor TTooltipUnitAbilityComponent.Create(Owner : TEntity; const AbilityName : string);
begin
CreateGrouped(Owner, nil, AbilityName);
end;
constructor TTooltipUnitAbilityComponent.CreateGrouped(Owner : TEntity; Group : TArray<byte>; const AbilityName : string);
begin
inherited CreateGrouped(Owner, Group);
FAbilityname := AbilityName;
FKeywords := TList<string>.Create;
FVariables := TObjectList<TTranslationVariable>.Create;
end;
destructor TTooltipUnitAbilityComponent.Destroy;
begin
FKeywords.Free;
FVariables.Free;
inherited;
end;
function TTooltipUnitAbilityComponent.IsCardDescription : TTooltipUnitAbilityComponent;
begin
Result := self;
FIsCardDescription := True;
end;
function TTooltipUnitAbilityComponent.Keyword(const Keyword : string) : TTooltipUnitAbilityComponent;
begin
Result := self;
FKeywords.Add(Keyword);
end;
function TTooltipUnitAbilityComponent.OnBuildAbilityList(AbilityIDList, KeywordIDList, CardDescriptionRaw : RParam) : boolean;
var
List : TList<RAbilityDescription>;
KeyWordList : TList<string>;
Keyword : string;
CardDescription : TCardDescription;
begin
Result := True;
// add ability
if not FIsCardDescription then
begin
List := AbilityIDList.AsType<TList<RAbilityDescription>>;
if assigned(List) and (self.FAbilityname <> '') then
List.Add(RAbilityDescription.Create(self.FAbilityname.ToLowerInvariant, FVariables));
end;
// add keywords avoiding duplicates
KeyWordList := KeywordIDList.AsType<TList<string>>;
if assigned(KeyWordList) then
begin
for Keyword in FKeywords do
begin
if not KeyWordList.Contains(Keyword.ToLowerInvariant) then
KeyWordList.Add(Keyword.ToLowerInvariant);
end;
end;
// add card description
if FIsCardDescription then
begin
CardDescription := CardDescriptionRaw.AsType<TCardDescription>;
if assigned(CardDescription) then
CardDescription.Fill(self.FAbilityname.ToLowerInvariant, FVariables);
end;
end;
function TTooltipUnitAbilityComponent.PassInteger(const Key : string; Value : integer) : TTooltipUnitAbilityComponent;
begin
Result := PassInteger(Key, Value, '');
end;
function TTooltipUnitAbilityComponent.PassInteger(const Key : string; Value : integer; const SpanClass : string) : TTooltipUnitAbilityComponent;
begin
Result := self;
FVariables.Add(TTranslationIntegerVariable.Create(Key, SpanClass, Value, 0, False));
end;
function TTooltipUnitAbilityComponent.PassPercentage(const Key : string; Value : integer) : TTooltipUnitAbilityComponent;
begin
Result := PassPercentage(Key, Value, '');
end;
function TTooltipUnitAbilityComponent.PassSingle(const Key : string; IntegralPart, FractionalPart : integer) : TTooltipUnitAbilityComponent;
begin
Result := PassSingle(Key, IntegralPart, FractionalPart, '');
end;
function TTooltipUnitAbilityComponent.PassSingleAsInteger(const Key : string; Value : single; const SpanClass : string) : TTooltipUnitAbilityComponent;
begin
Result := self;
FVariables.Add(TTranslationIntegerVariable.Create(Key, SpanClass, round(Value), 0, False));
end;
function TTooltipUnitAbilityComponent.PassString(const Key, Value : string) : TTooltipUnitAbilityComponent;
begin
Result := PassString(Key, Value, '');
end;
function TTooltipUnitAbilityComponent.PassPercentage(const Key : string; Value : integer; const SpanClass : string) : TTooltipUnitAbilityComponent;
begin
Result := self;
FVariables.Add(TTranslationIntegerVariable.Create(Key, SpanClass, Value, 0, True));
end;
function TTooltipUnitAbilityComponent.PassSingle(const Key : string; IntegralPart, FractionalPart : integer; const SpanClass : string) : TTooltipUnitAbilityComponent;
begin
Result := self;
FVariables.Add(TTranslationIntegerVariable.Create(Key, SpanClass, IntegralPart, FractionalPart, False));
end;
function TTooltipUnitAbilityComponent.PassSingleAsInteger(const Key : string; Value : single) : TTooltipUnitAbilityComponent;
begin
Result := PassSingleAsInteger(Key, Value, '');
end;
function TTooltipUnitAbilityComponent.PassString(const Key, Value, SpanClass : string) : TTooltipUnitAbilityComponent;
begin
Result := self;
FVariables.Add(TTranslationStringVariable.Create(Key, SpanClass, Value));
end;
{ TAbilitybuttonComponent }
procedure TAbilitybuttonComponent.DeRegisterButton;
begin
FreeAndNil(FSpell);
end;
function TAbilitybuttonComponent.IsMultiMode(ModeGroups : TArray<byte>) : TAbilitybuttonComponent;
begin
Result := self;
FMultiMode := ModeGroups;
end;
destructor TAbilitybuttonComponent.Destroy;
begin
DeRegisterButton;
inherited;
end;
procedure TAbilitybuttonComponent.GenerateSpellData;
var
MetaInf : TEntity;
TargetType : EnumCommanderAbilityTargetType;
TargetCount : integer;
Targets : TArray<RCommanderAbilityTarget>;
Range : single;
begin
MetaInf := GetDataEntity;
TargetType := ctNone;
TargetCount := 0;
if assigned(MetaInf) then
begin
TargetType := MetaInf.Eventbus.Read(eiAbilityTargetType, []).AsEnumType<EnumCommanderAbilityTargetType>;
TargetCount := MetaInf.Eventbus.Read(eiAbilityTargetCount, []).AsInteger;
end;
if not assigned(MetaInf) or (TargetType = ctNone) then
begin
TargetType := Eventbus.Read(eiAbilityTargetType, [], ComponentGroup).AsEnumType<EnumCommanderAbilityTargetType>;
TargetCount := Eventbus.Read(eiAbilityTargetCount, [], ComponentGroup).AsInteger;
end;
TargetCount := Max(1, TargetCount);
Range := Eventbus.Read(eiAbilityTargetRange, [], ComponentGroup).AsSingle;
Targets := HArray.Generate<RCommanderAbilityTarget>(TargetCount, RCommanderAbilityTarget.CreateUnset(TargetType));
FSpell := TCommanderSpellData.Create(GlobalEventbus, FOwner.ID, ComponentGroup, Targets, Range);
end;
function TAbilitybuttonComponent.OnClearGUI : boolean;
begin
Result := True;
DeRegisterButton;
end;
procedure TAbilitybuttonComponent.RegisterButton;
begin
GenerateSpellData;
end;
function TAbilitybuttonComponent.GetDataEntity() : TEntity;
var
Pattern : string;
begin
Pattern := Eventbus.Read(eiWelaUnitPattern, [], ComponentGroup).AsString;
if Pattern = '' then Result := nil
else Result := EntityDataCache.GetEntity(Pattern, CardLeague, CardLevel);
end;
function TAbilitybuttonComponent.OnRegisterInGUI() : boolean;
begin
Result := True;
RegisterButton;
end;
{ TDeckCardButtonComponent }
function TDeckCardButtonComponent.OnIdle : boolean;
var
CooldownProgress, CooldownSeconds : single;
CurrentCharges, MaxCharges : integer;
IsReady : boolean;
begin
Result := True;
if assigned(FHUDDeckSlot) then
begin
IsReady := Eventbus.Read(eiIsReady, [], ComponentGroup).AsBoolean;
if FHUDDeckSlot.IsReady <> IsReady then
FHUDDeckSlot.IsReady := IsReady;
// Display charges
CurrentCharges := Owner.Balance(reCharge, ComponentGroup).AsInteger;
if FHUDDeckSlot.CurrentCharges <> CurrentCharges then
FHUDDeckSlot.CurrentCharges := CurrentCharges;
MaxCharges := Owner.Cap(reCharge, ComponentGroup).AsInteger;
if FHUDDeckSlot.MaxCharges <> MaxCharges then
FHUDDeckSlot.MaxCharges := MaxCharges;
// update cooldown if not reached cap
if CurrentCharges < MaxCharges then
begin
CooldownProgress := HMath.Saturate(Eventbus.Read(eiCooldownProgress, [], FCooldownGroup).AsSingle);
if FHUDDeckSlot.ChargeProgress <> CooldownProgress then
FHUDDeckSlot.ChargeProgress := CooldownProgress;
CooldownSeconds := Eventbus.Read(eiCooldown, [], FCooldownGroup).AsInteger * (1 - CooldownProgress) / 1000;
if FHUDDeckSlot.CooldownSeconds <> CooldownSeconds then
FHUDDeckSlot.CooldownSeconds := CooldownSeconds;
end;
end;
end;
procedure TDeckCardButtonComponent.RegisterButton;
begin
inherited;
assert(assigned(FCardInfo), Format('TDeckCardButtonComponent.RegisterButton: Empty card info for build button in slot %d!', [FSlot]));
if assigned(FCardInfo) then
begin
FSpell.IsSpawner := FCardInfo.IsSpawner;
FSpell.IsDrop := not FCardInfo.IsSpawner and not FCardInfo.IsSpell;
FSpell.IsSpell := FCardInfo.IsSpell;
FSpell.IsEpic := FCardInfo.IsEpic;
FSpell.MultiModes := FMultiMode;
if assigned(HUD) then
begin
FHUDDeckSlot := HUD.RegisterDeckSlot(FCardInfo, FSlot, FSpell);
// deckslot takes the ownership
FSpell := nil;
end;
end;
end;
function TDeckCardButtonComponent.SetCooldownGroup(Group : TArray<byte>) : TDeckCardButtonComponent;
begin
Result := self;
FCooldownGroup := ByteArrayToComponentGroup(Group);
end;
function TDeckCardButtonComponent.CardInfo(CardInfo : TCardInfo) : TDeckCardButtonComponent;
begin
Result := self;
FCardInfo := CardInfo;
end;
function TDeckCardButtonComponent.Slot(Slot : integer) : TDeckCardButtonComponent;
begin
Result := self;
FSlot := Slot;
end;
procedure TDeckCardButtonComponent.DeRegisterButton;
begin
inherited;
if assigned(HUD) then
HUD.DeregisterDeckSlot(FHUDDeckSlot);
FHUDDeckSlot := nil;
end;
{ TWelaTargetConstraintGridVisualizedComponent }
function TWelaTargetConstraintGridVisualizedComponent.CheckGridNode(TargetBuildZone : TBuildZone; WorldCoord : RVector2) : boolean;
var
Color : RColor;
begin
Result := inherited CheckGridNode(TargetBuildZone, WorldCoord);
Color := HGeneric.TertOp(Result, RColor.CGREEN, RColor.CRED);
TargetBuildZone.RenderGridNode(TargetBuildZone.PositionToCoord(WorldCoord), Color);
end;
constructor TWelaTargetConstraintGridVisualizedComponent.CreateGrouped(Owner : TEntity; Group : TArray<byte>);
begin
inherited CreateGrouped(Owner, Group);
CheckAllFields := True;
end;
{ TRangeIndicatorComponent }
constructor TRangeIndicatorComponent.CreateGrouped(Owner : TEntity; Group : TArray<byte>);
begin
inherited CreateGrouped(Owner, Group);
FColor := RColor.CBLACK;