This repository was archived by the owner on Dec 18, 2017. It is now read-only.
forked from vans163/civ6_qui
-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathunitpanel.lua
More file actions
3752 lines (3253 loc) · 155 KB
/
unitpanel.lua
File metadata and controls
3752 lines (3253 loc) · 155 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
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-- ===========================================================================
-- Unit Panel Screen
-- ===========================================================================
include( "InstanceManager" );
include( "SupportFunctions" );
include( "Colors" );
include( "CombatInfo" );
include( "PopupDialogSupport" );
include( "Civ6Common" );
include( "EspionageSupport" );
-- ===========================================================================
-- CONSTANTS
-- ===========================================================================
local ANIMATION_SPEED :number = 2;
local SECONDARY_ACTIONS_ART_PADDING :number = -4;
local MAX_BEFORE_TRUNC_STAT_NAME :number = 170;
-- ===========================================================================
-- MEMBERS / VARIABLES
-- ===========================================================================
hstructure DisabledByTutorial
kLockedHashes : table; -- Action hashes that the tutorial says shouldn't be enabled.
end
local m_standardActionsIM :table = InstanceManager:new( "UnitActionInstance", "UnitActionButton", Controls.StandardActionsStack );
local m_secondaryActionsIM :table = InstanceManager:new( "UnitActionInstance", "UnitActionButton", Controls.SecondaryActionsStack );
local m_groupArtIM :table = InstanceManager:new( "GroupArtInstance", "Top", Controls.PrimaryArtStack );
local m_buildActionsIM :table = InstanceManager:new( "BuildActionsColumnInstance", "Top", Controls.BuildActionsStack );
local m_earnedPromotionIM :table = InstanceManager:new( "EarnedPromotionInstance", "Top", Controls.EarnedPromotionsStack);
local m_PromotionListInstanceMgr:table = InstanceManager:new( "PromotionSelectionInstance", "PromotionSelection", Controls.PromotionList );
local m_subjectModifierIM :table = InstanceManager:new( "ModifierInstance", "ModifierContainer", Controls.SubjectModifierStack );
local m_targetModifierIM :table = InstanceManager:new( "ModifierInstance", "ModifierContainer", Controls.TargetModifierStack );
local m_interceptorModifierIM :table = InstanceManager:new( "ModifierInstance", "ModifierContainer", Controls.InterceptorModifierStack );
local m_antiAirModifierIM :table = InstanceManager:new( "ModifierInstance", "ModifierContainer", Controls.AntiAirModifierStack );
local m_subjectStatStackIM :table = InstanceManager:new( "StatInstance", "StatGrid", Controls.SubjectStatStack );
local m_targetStatStackIM :table = InstanceManager:new( "TargetStatInstance", "StatGrid", Controls.TargetStatStack );
local m_combatResults :table = nil;
local m_currentIconGroup :table = nil; -- Tracks the current icon group as they are built.
local m_isOkayToProcess :boolean= true;
local m_selectedPlayerId :number = -1;
local m_primaryColor :number = 0xdeadbeef;
local m_secondaryColor :number = 0xbaadf00d;
local m_UnitId :number = -1;
local m_numIconsInCurrentIconGroup :number = 0;
local m_bestValidImprovement :number = -1;
local m_kHotkeyActions :table = {};
local m_kHotkeyCV1 :table = {};
local m_kHotkeyCV2 :table = {};
local m_kSoundCV1 :table = {};
local m_kTutorialDisabled :table = {}; -- key = Unit Type, value = lockedHashes
local m_kTutorialAllDisabled :table = {}; -- hashes of actions disabled for all units
local m_attackerUnit = nil;
local m_locX = nil;
local m_locY = nil;
local INVALID_PLOT_ID :number = -1;
local m_plotId :number = INVALID_PLOT_ID;
local m_kPopupDialog :table;
local m_targetData :table;
local m_subjectData :table;
-- Defines the number of modifiers displayed per page in the combat preview
local m_maxModifiersPerPage :number = 5;
-- Defines the minimum unit panel size and resize padding used when resizing unit panel to fit action buttons
local m_minUnitPanelWidth :number = 340;
local m_resizeUnitPanelPadding :number = 18;
local pSpyInfo = GameInfo.Units["UNIT_SPY"];
local m_AttackHotkeyId = Input.GetActionId("Attack");
local m_DeleteHotkeyId = Input.GetActionId("DeleteUnit");
--CQUI Members
local CQUI_ImprovementTutorial = true;
local CQUI_AutoExpandUnitActions = false;
function CQUI_OnSettingsUpdate()
CQUI_AutoExpandUnitActions = GameConfiguration.GetValue("CQUI_AutoExpandUnitActions");
CQUI_ImprovementTutorial = GameConfiguration.GetValue("CQUI_ImprovementTutorial");
OnRefresh();
end
-- ===========================================================================
-- FUNCTIONS
-- ===========================================================================
function InitSubjectData()
m_subjectData =
{
Name = "",
Moves = 0,
InFormation = 0,
FormationMoves = 0,
FormationMaxMoves = 0,
MaxMoves = 0,
Combat = 0,
Damage = 0,
MaxDamage = 0,
PotentialDamage = 0,
WallDamage = 0,
MaxWallDamage = 0,
PotentialWallDamage = 0,
RangedCombat = 0,
BombardCombat = 0,
AntiAirCombat = 0,
Range = 0,
Owner = 0,
BuildCharges = 0,
SpreadCharges = 0,
GreatPersonActionCharges = 0,
GreatPersonPassiveName = "",
GreatPersonPassiveText = "",
ReligiousStrength = 0,
HasMovedIntoZOC = 0,
MilitaryFormation = 0,
UnitType = -1,
UnitID = 0,
UnitExperience = 0,
MaxExperience = 0,
UnitLevel = 0,
CurrentPromotions = {},
Actions = {},
IsSpy = false,
SpyOperation = -1,
SpyTargetOwnerID = -1,
SpyTargetCityName = "",
SpyRemainingTurns = 0,
SpyTotalTurns = 0,
StatData = nil,
IsTradeUnit = false,
TradeRouteName = "",
TradeRouteIcon = "",
TradeLandRange = 0,
TradeSeaRange = 0,
IsSettler = false;
};
end
function InitTargetData()
m_targetData =
{
Name = "",
Combat = 0,
RangedCombat = 0,
BombardCombat = 0,
ReligiousCombat = 0,
Range = 0,
Damage = 0,
MaxDamage = 0,
PotentialDamage = 0,
WallDamage = 0,
MaxWallDamage = 0,
PotentialWallDamage = 0,
BuildCharges = 0,
SpreadCharges = 0,
ReligiousStrength = 0,
GreatPersonActionCharges = 0,
Moves = 0,
MaxMoves = 0,
InterceptorName = "",
InterceptorCombat = 0,
InterceptorDamage = 0,
InterceptorMaxDamage = 0,
InterceptorPotentialDamage = 0,
AntiAirName = "",
AntiAirCombat = 0,
StatData = nil;
UnitType = -1,
UnitID = 0,
};
end
-- ===========================================================================
-- An action icon which will shows up immediately above the unit panel
-- ===========================================================================
function AddActionButton( instance:table, action:table )
instance.UnitActionIcon:SetIcon(action.IconId);
instance.UnitActionButton:SetDisabled( action.Disabled );
instance.UnitActionButton:SetAlpha( (action.Disabled and 0.7) or 1 );
instance.UnitActionButton:SetToolTipString( action.helpString );
instance.UnitActionButton:RegisterCallback( Mouse.eLClick,
function(void1,void2)
if action.Sound ~= nil and action.Sound ~= "" then
UI.PlaySound(action.Sound);
end
action.CallbackFunc(void1,void2);
end
);
instance.UnitActionButton:SetVoid1( action.CallbackVoid1 );
instance.UnitActionButton:SetVoid2( action.CallbackVoid2 );
instance.UnitActionButton:SetTag( action.userTag );
instance.UnitActionButton:RegisterCallback( Mouse.eMouseEnter, function() UI.PlaySound("Main_Menu_Mouse_Over"); end);
-- Track # of icons added for whatever is the current group
m_numIconsInCurrentIconGroup = m_numIconsInCurrentIconGroup + 1;
end
-- ===========================================================================
function GetHashFromType( actionType:string )
local hash:number = 0;
if GameInfo.UnitCommands[actionType] ~= nil then
hash = GameInfo.UnitCommands[actionType].Hash;
elseif GameInfo.UnitOperations[actionType] ~= nil then
hash = GameInfo.UnitOperations[actionType].Hash;
end
return hash;
end
-- ===========================================================================
-- RETURNS true if tutorial is disabling this action.
-- ===========================================================================
function IsDisabledByTutorial( unitType:string, actionHash:number )
-- Any type of unit
for i,action in ipairs( m_kTutorialAllDisabled ) do
hash = GetHashFromType(action);
if actionHash == hash and hash ~= 0 then
return true;
end
end
-- Specific to a unit
if m_kTutorialDisabled[unitType] ~= nil then
-- In mode where all are enabled except for specific list
for i,hash in ipairs( m_kTutorialDisabled[unitType].kLockedHashes ) do
if actionHash == hash then
return true;
end
end
end
return false;
end
-- ===========================================================================
-- Add an action for the UI to display.
-- actionsTable Table holding actions via categories
-- action A command or operation
-- disabled Is the action disabled (tutorial may disable even if enabled)
-- toolTipString What the action does
-- actionHash The hash of the action.
-- ===========================================================================
function AddActionToTable( actionsTable:table, action:table, disabled:boolean, toolTipString:string, actionHash:number, callbackFunc:ifunction, callbackVoid1, callbackVoid2, overrideIcon:string)
local actionsCategoryTable:table;
if ( actionsTable[action.CategoryInUI] ~= nil ) then
actionsCategoryTable = actionsTable[action.CategoryInUI];
else
UI.DataError("Operation is in unsupported action category '" .. tostring(action.CategoryInUI) .. "'.");
actionsCategoryTable = actionsTable["SPECIFIC"];
end
-- Wrap every callback function with a call that guarantees the interface
-- mode is reset. It prevents issues such as selecting range attack and
-- then instead of attacking, choosing another action, which would leave
-- up the range attack lens layer.
local wrappedCallback:ifunction =
function(void1,void2)
if UI.GetInterfaceMode() ~= InterfaceModeTypes.SELECTION then
print("Unit panel forcing interface mode back to selection before performing operation/action"); --Debug
UI.SetInterfaceMode( InterfaceModeTypes.SELECTION );
end
callbackFunc(void1,void2);
end;
table.insert( actionsCategoryTable, {
IconId = (overrideIcon and overrideIcon) or action.Icon,
Disabled = disabled,
helpString = toolTipString,
userTag = actionHash,
CallbackFunc = wrappedCallback,
CallbackVoid1 = callbackVoid1,
CallbackVoid2 = callbackVoid2,
IsBestImprovement = action.IsBestImprovement,
Sound = action.Sound
});
-- Hotkey support
if (action.HotkeyId~=nil) and disabled==false then
local actionId = Input.GetActionId( action.HotkeyId );
if actionId ~= nil then
m_kHotkeyActions[actionId] = callbackFunc;
m_kHotkeyCV1[actionId] = callbackVoid1;
m_kHotkeyCV2[actionId] = callbackVoid2;
m_kSoundCV1[actionId] = action.Sound;
else
UI.DataError("Cannot set hotkey on Unitpanel for action with icon '"..action.IconId.."' because engine doesn't have actionId of '"..action.HotkeyId.."'.");
end
end
end
-- ===========================================================================
-- Refresh unit actions
-- Returns a table of unit actions.
-- ===========================================================================
function GetUnitActionsTable( pUnit )
-- Build action table; holds sub-tables of commands & operations based on UI categories set in DB.
-- Also defines order actions show in panel.
local actionsTable = {
ATTACK = {},
BUILD = {},
GAMEMODIFY = {},
MOVE = {},
OFFENSIVESPY = {},
INPLACE = {},
SECONDARY = {},
SPECIFIC = {},
displayOrder = {
primaryArea = {"ATTACK","OFFENSIVESPY","SPECIFIC","MOVE","INPLACE","GAMEMODIFY"}, -- How they appear in the UI
secondaryArea = {"SECONDARY"}
}
};
m_bestValidImprovement = -1;
if pUnit == nil then
UI.DataError("NIL unit when attempting to get action table.");
return;
end
local unitType :string = GameInfo.Units[pUnit:GetUnitType()].UnitType;
for commandRow in GameInfo.UnitCommands() do
if ( commandRow.VisibleInUI ) then
local actionHash :number = commandRow.Hash;
local isDisabled :boolean = IsDisabledByTutorial(unitType, actionHash );
if (actionHash == UnitCommandTypes.ENTER_FORMATION) then
--Check if there are any units in the same tile that this unit can create a formation with
--Call CanStartCommand asking for results
local bCanStart, tResults = UnitManager.CanStartCommand( pUnit, actionHash, nil, true);
if (bCanStart and tResults) then
if (tResults[UnitCommandResults.UNITS] ~= nil and #tResults[UnitCommandResults.UNITS] ~= 0) then
local tUnits = tResults[UnitCommandResults.UNITS];
for i, unit in ipairs(tUnits) do
local pUnitInstance = Players[unit.player]:GetUnits():FindID(unit.id);
if (pUnitInstance ~= nil) then
local toolTipString :string = Locale.Lookup(commandRow.Description, GameInfo.Units[pUnitInstance:GetUnitType()].Name);
local callback :ifunction = function() OnUnitActionClicked_EnterFormation(pUnitInstance) end
AddActionToTable( actionsTable, commandRow, isDisabled, toolTipString, actionHash, callback );
end
end
end
end
elseif (actionHash == UnitCommandTypes.PROMOTE) then
--Call CanStartCommand asking for a list of possible promotions for that unit
local bCanStart, tResults = UnitManager.CanStartCommand( pUnit, actionHash, true, true);
if (bCanStart and tResults) then
if (tResults[UnitCommandResults.PROMOTIONS] ~= nil and #tResults[UnitCommandResults.PROMOTIONS] ~= 0) then
local tPromotions = tResults[UnitCommandResults.PROMOTIONS];
local toolTipString = Locale.Lookup(commandRow.Description);
local callback = function() ShowPromotionsList(tPromotions); end
AddActionToTable( actionsTable, commandRow, isDisabled, toolTipString, actionHash, callback );
end
end
elseif (actionHash == UnitCommandTypes.NAME_UNIT) then
local bCanStart = UnitManager.CanStartCommand( pUnit, UnitCommandTypes.NAME_UNIT, true);
if (bCanStart) then
local toolTipString = Locale.Lookup(commandRow.Description);
AddActionToTable( actionsTable, commandRow, isDisabled, toolTipString, actionHash, OnNameUnit );
end
elseif (actionHash == UnitCommandTypes.DELETE) then
local bCanStart = UnitManager.CanStartCommand( pUnit, UnitCommandTypes.DELETE, true);
if (bCanStart) then
local toolTipString = Locale.Lookup(commandRow.Description);
AddActionToTable( actionsTable, commandRow, isDisabled, toolTipString, actionHash, OnPromptToDeleteUnit );
end
elseif (actionHash == UnitCommandTypes.CANCEL and GameInfo.Units[unitType].Spy) then
-- Route the cancel action for spies to the espionage popup for cancelling a mission
local bCanStart = UnitManager.CanStartCommand( pUnit, actionHash, true);
if (bCanStart) then
local bCanStartNow, tResults = UnitManager.CanStartCommand( pUnit, actionHash, false, true);
AddActionToTable( actionsTable, commandRow, isDisabled, Locale.Lookup("LOC_UNITPANEL_ESPIONAGE_CANCEL_MISSION"), actionHash, OnUnitActionClicked_CancelSpyMission, UnitCommandTypes.TYPE, actionHash );
end
else
if (actionHash == UnitCommandTypes.AIRLIFT) then
local foo = true;
end
-- The UI check of an operation is a loose check where it only fails if the unit could never do the command.
local bCanStart = UnitManager.CanStartCommand( pUnit, actionHash, true);
if (bCanStart) then
-- Check again if the operation can occur, this time for real.
local bCanStartNow, tResults = UnitManager.CanStartCommand( pUnit, actionHash, false, true);
local bDisabled = not bCanStartNow;
local toolTipString:string;
if (actionHash == UnitCommandTypes.UPGRADE) then
-- if it's a unit upgrade action, add the unit it will upgrade to in the tooltip as well as the upgrade cost
if (tResults ~= nil) then
if (tResults[UnitCommandResults.UNIT_TYPE] ~= nil) then
local upgradeUnitName = GameInfo.Units[tResults[UnitCommandResults.UNIT_TYPE]].Name;
toolTipString = Locale.Lookup(upgradeUnitName);
local upgradeCost = pUnit:GetUpgradeCost();
if (upgradeCost ~= nil) then
toolTipString = toolTipString .. ": " .. upgradeCost .. " " .. Locale.Lookup("LOC_TOP_PANEL_GOLD");
end
toolTipString = Locale.Lookup("LOC_UNITOPERATION_UPGRADE_INFO", upgradeUnitName, upgradeCost);
end
end
elseif (actionHash == UnitCommandTypes.FORM_CORPS) then
if (GameInfo.Units[unitType].Domain == "DOMAIN_SEA") then
toolTipString = Locale.Lookup("LOC_UNITCOMMAND_FORM_FLEET_DESCRIPTION");
else
toolTipString = Locale.Lookup(commandRow.Description);
end
elseif (actionHash == UnitCommandTypes.FORM_ARMY) then
if (GameInfo.Units[unitType].Domain == "DOMAIN_SEA") then
toolTipString = Locale.Lookup("LOC_UNITCOMMAND_FORM_ARMADA_DESCRIPTION");
else
toolTipString = Locale.Lookup(commandRow.Description);
end
else
toolTipString = Locale.Lookup(commandRow.Description);
end
if (tResults ~= nil) then
if (tResults[UnitOperationResults.ACTION_NAME] ~= nil and tResults[UnitOperationResults.ACTION_NAME] ~= "") then
toolTipString = Locale.Lookup(tResults[UnitOperationResults.ACTION_NAME]);
end
if (tResults[UnitOperationResults.ADDITIONAL_DESCRIPTION] ~= nil) then
for i,v in ipairs(tResults[UnitOperationResults.ADDITIONAL_DESCRIPTION]) do
toolTipString = toolTipString .. "[NEWLINE]" .. Locale.Lookup(v);
end
end
-- Are there any failure reasons?
if ( bDisabled ) then
if (tResults[UnitOperationResults.FAILURE_REASONS] ~= nil) then
-- Add the reason(s) to the tool tip
for i,v in ipairs(tResults[UnitOperationResults.FAILURE_REASONS]) do
toolTipString = toolTipString .. "[NEWLINE]" .. "[COLOR:Red]" .. Locale.Lookup(v) .. "[ENDCOLOR]";
end
end
end
end
isDisabled = bDisabled or isDisabled; -- Mix in tutorial disabledness
AddActionToTable( actionsTable, commandRow, isDisabled, toolTipString, actionHash, OnUnitActionClicked, UnitCommandTypes.TYPE, actionHash );
end
end
end
end
-- Loop over the UnitOperations (like commands but may take 1 to N turns to complete)
-- Only show the operations if the unit has moves left.
local isHasMovesLeft = pUnit:GetMovesRemaining() > 0;
if isHasMovesLeft then
for operationRow in GameInfo.UnitOperations() do
local actionHash :number = operationRow.Hash;
local isDisabled :boolean= IsDisabledByTutorial( unitType, actionHash );
local instance;
-- if unit can build an improvement, show all the buildable improvements for that tile
if (actionHash == UnitOperationTypes.BUILD_IMPROVEMENT) then
local tParameters = {};
tParameters[UnitOperationTypes.PARAM_X] = pUnit:GetX();
tParameters[UnitOperationTypes.PARAM_Y] = pUnit:GetY();
--Call CanStartOperation asking for results
local bCanStart, tResults = UnitManager.CanStartOperation( pUnit, UnitOperationTypes.BUILD_IMPROVEMENT, nil, tParameters, true);
if (bCanStart and tResults ~= nil) then
if (tResults[UnitOperationResults.IMPROVEMENTS] ~= nil and #tResults[UnitOperationResults.IMPROVEMENTS] ~= 0) then
m_bestValidImprovement = tResults[UnitOperationResults.BEST_IMPROVEMENT];
local tImprovements = tResults[UnitOperationResults.IMPROVEMENTS];
for i, eImprovement in ipairs(tImprovements) do
tParameters[UnitOperationTypes.PARAM_IMPROVEMENT_TYPE] = eImprovement;
local improvement = GameInfo.Improvements[eImprovement];
bCanStart, tResults = UnitManager.CanStartOperation(pUnit, actionHash, nil, tParameters, true);
local isDisabled = not bCanStart;
local toolTipString = Locale.Lookup(operationRow.Description) .. ": " .. Locale.Lookup(improvement.Name);
if tResults ~= nil then
if (tResults[UnitOperationResults.ADDITIONAL_DESCRIPTION] ~= nil) then
for i,v in ipairs(tResults[UnitOperationResults.ADDITIONAL_DESCRIPTION]) do
toolTipString = toolTipString .. "[NEWLINE]" .. Locale.Lookup(v);
end
end
-- Are there any failure reasons?
if isDisabled then
if (tResults[UnitOperationResults.FAILURE_REASONS] ~= nil) then
-- Add the reason(s) to the tool tip
for i,v in ipairs(tResults[UnitOperationResults.FAILURE_REASONS]) do
toolTipString = toolTipString .. "[NEWLINE]" .. "[COLOR:Red]" .. Locale.Lookup(v) .. "[ENDCOLOR]";
end
end
end
end
-- If this improvement is the same enum as what the game marked as "the best" for this plot, set this flag for the UI to use.
if ( m_bestValidImprovement ~= -1 and m_bestValidImprovement == eImprovement ) then
improvement["IsBestImprovement"] = true;
else
improvement["IsBestImprovement"] = false;
end
improvement["CategoryInUI"] = "BUILD"; -- TODO: Force improvement to be a type of "BUILD", this can be removed if CategoryInUI is added to "Improvements" in the database schema. ??TRON
AddActionToTable( actionsTable, improvement, isDisabled, toolTipString, actionHash, OnUnitActionClicked_BuildImprovement, improvement.Hash );
end
end
end
elseif (actionHash == UnitOperationTypes.MOVE_TO) then
local bCanStart :boolean= UnitManager.CanStartOperation( pUnit, UnitOperationTypes.MOVE_TO, nil, false, false); -- No exclusion test, no results
if (bCanStart) then
local toolTipString :string = Locale.Lookup(operationRow.Description);
AddActionToTable( actionsTable, operationRow, isDisabled, toolTipString, actionHash, OnUnitActionClicked_MoveTo );
end
elseif (operationRow.CategoryInUI == "OFFENSIVESPY") then
local bCanStart :boolean= UnitManager.CanStartOperation( pUnit, actionHash, nil, false, false); -- No exclusion test, no result
if (bCanStart) then
---- We only want a single offensive spy action which opens the EspionageChooser side panel
if actionsTable[operationRow.CategoryInUI] ~= nil and table.count(actionsTable[operationRow.CategoryInUI]) == 0 then
local toolTipString :string = Locale.Lookup("LOC_UNITPANEL_ESPIONAGE_CHOOSE_MISSION");
AddActionToTable( actionsTable, operationRow, isDisabled, toolTipString, actionHash, OnUnitActionClicked, UnitOperationTypes.TYPE, actionHash, "ICON_UNITOPERATION_SPY_MISSIONCHOOSER");
end
end
elseif (actionHash == UnitOperationTypes.SPY_COUNTERSPY) then
local bCanStart, tResults = UnitManager.CanStartOperation( pUnit, actionHash, nil, true );
if (bCanStart) then
local toolTipString = Locale.Lookup(operationRow.Description);
AddActionToTable( actionsTable, operationRow, isDisabled, toolTipString, actionHash, OnUnitActionClicked, UnitOperationTypes.TYPE, actionHash, "ICON_UNITOPERATION_SPY_COUNTERSPY_ACTION");
end
elseif (actionHash == UnitOperationTypes.FOUND_CITY) then
local bCanStart :boolean= UnitManager.CanStartOperation( pUnit, UnitOperationTypes.FOUND_CITY, nil, false, false); -- No exclusion test, no results
if (bCanStart) then
local toolTipString :string = Locale.Lookup(operationRow.Description);
AddActionToTable( actionsTable, operationRow, isDisabled, toolTipString, actionHash, OnUnitActionClicked_FoundCity );
end
elseif (actionHash == UnitOperationTypes.WMD_STRIKE) then
-- if unit can deploy a WMD, create a unit action for each type
-- first check if the unit is capable of deploying a WMD
local bCanStart = UnitManager.CanStartOperation( pUnit, UnitOperationTypes.WMD_STRIKE, nil, true);
if (bCanStart) then
for entry in GameInfo.WMDs() do
local tParameters = {};
tParameters[UnitOperationTypes.PARAM_WMD_TYPE] = entry.Index;
bCanStart, tResults = UnitManager.CanStartOperation(pUnit, actionHash, nil, tParameters, true);
local isWMDTypeDisabled:boolean = (not bCanStart) or isDisabled;
local toolTipString :string = Locale.Lookup(operationRow.Description);
local wmd = entry.Index;
toolTipString = toolTipString .. "[NEWLINE]" .. Locale.Lookup(entry.Name);
local callBack = function() OnUnitActionClicked_WMDStrike(wmd); end
-- Are there any failure reasons?
if ( not bCanStart ) then
if tResults ~= nil and (tResults[UnitOperationResults.FAILURE_REASONS] ~= nil) then
-- Add the reason(s) to the tool tip
for i,v in ipairs(tResults[UnitOperationResults.FAILURE_REASONS]) do
toolTipString = toolTipString .. "[NEWLINE]" .. "[COLOR:Red]" .. Locale.Lookup(v) .. "[ENDCOLOR]";
end
end
end
AddActionToTable( actionsTable, operationRow, isWMDTypeDisabled, toolTipString, actionHash, callBack );
end
end
else
-- Is this operation visible in the UI?
-- The UI check of an operation is a loose check where it only fails if the unit could never do the operation.
if ( operationRow.VisibleInUI ) then
local bCanStart, tResults = UnitManager.CanStartOperation( pUnit, actionHash, nil, true );
if (bCanStart) then
-- Check again if the operation can occur, this time for real.
bCanStart, tResults = UnitManager.CanStartOperation(pUnit, actionHash, nil, false, true);
local bDisabled = not bCanStart;
local toolTipString = Locale.Lookup(operationRow.Description);
if (tResults ~= nil) then
if (tResults[UnitOperationResults.ACTION_NAME] ~= nil and tResults[UnitOperationResults.ACTION_NAME] ~= "") then
toolTipString = Locale.Lookup(tResults[UnitOperationResults.ACTION_NAME]);
end
if (tResults[UnitOperationResults.FEATURE_TYPE] ~= nil) then
local featureName = GameInfo.Features[tResults[UnitOperationResults.FEATURE_TYPE]].Name;
toolTipString = toolTipString .. ": " .. Locale.Lookup(featureName);
end
if (tResults[UnitOperationResults.ADDITIONAL_DESCRIPTION] ~= nil) then
for i,v in ipairs(tResults[UnitOperationResults.ADDITIONAL_DESCRIPTION]) do
toolTipString = toolTipString .. "[NEWLINE]" .. Locale.Lookup(v);
end
end
-- Are there any failure reasons?
if ( bDisabled ) then
if (tResults[UnitOperationResults.FAILURE_REASONS] ~= nil) then
-- Add the reason(s) to the tool tip
for i,v in ipairs(tResults[UnitOperationResults.FAILURE_REASONS]) do
toolTipString = toolTipString .. "[NEWLINE]" .. "[COLOR:Red]" .. Locale.Lookup(v) .. "[ENDCOLOR]";
end
end
end
end
isDisabled = bDisabled or isDisabled;
AddActionToTable( actionsTable, operationRow, isDisabled, toolTipString, actionHash, OnUnitActionClicked, UnitOperationTypes.TYPE, actionHash );
end
end
end
end
end
return actionsTable;
end
-- ===========================================================================
function StartIconGroup()
if m_currentIconGroup ~= nil then
UI.DataError("Starting an icon group but a prior one wasn't completed!");
end
m_currentIconGroup = m_groupArtIM:GetInstance();
m_numIconsInCurrentIconGroup = 0;
end
-- ===========================================================================
function EndIconGroup()
if m_currentIconGroup == nil then
UI.DataError("Attempt to end an icon group, but their are no icons!");
return;
end
local instance :table = m_standardActionsIM:GetInstance();
local width :number = instance.UnitActionButton:GetSizeX();
m_standardActionsIM:ReleaseInstance( instance );
m_currentIconGroup.Top:SetSizeX( width * m_numIconsInCurrentIconGroup );
m_currentIconGroup = nil;
Controls.PrimaryArtStack:CalculateSize();
Controls.PrimaryArtStack:ReprocessAnchoring();
end
-- ===========================================================================
function GetPercentFromDamage( damage:number, maxDamage:number )
if damage > maxDamage then
damage = maxDamage;
end
return (damage / maxDamage);
end
-- ===========================================================================
-- Set the health meter
-- ===========================================================================
function RealizeHealthMeter( control:table, percent:number, controlShadow:table, shadowPercent:number )
if ( percent > 0.7 ) then
control:SetColor( COLORS.METER_HP_GOOD );
controlShadow:SetColor( COLORS.METER_HP_GOOD_SHADOW );
elseif ( percent > 0.4 ) then
control:SetColor( COLORS.METER_HP_OK );
controlShadow:SetColor( COLORS.METER_HP_OK_SHADOW );
else
control:SetColor( COLORS.METER_HP_BAD );
controlShadow:SetColor( COLORS.METER_HP_BAD_SHADOW );
end
-- Meter control is half circle, so add enough to start at half point and condence % into the half area
percent = (percent * 0.5) + 0.5;
shadowPercent = (shadowPercent * 0.5) + 0.5;
control:SetPercent( percent );
controlShadow:SetPercent( shadowPercent );
end
-- ===========================================================================
-- View(data)
-- Update the layout based on the view model
-- ===========================================================================
function View(data)
-- TODO: Explore what (if anything) could be done with prior values so Reset can be utilized instead of destory; this would gain LUA side pooling
m_buildActionsIM:DestroyInstances();
m_standardActionsIM:ResetInstances();
m_secondaryActionsIM:ResetInstances();
m_groupArtIM:ResetInstances();
m_buildActionsIM:ResetInstances();
---=======[ ACTIONS ]=======---
HidePromotionPanel();
-- Reset UnitPanelBaseContainer to minium size
Controls.UnitPanelBaseContainer:SetSizeX(m_minUnitPanelWidth);
-- First fill the primary area
if (table.count(data.Actions) > 0) then
for _,categoryName in ipairs(data.Actions.displayOrder.primaryArea) do
local categoryTable = data.Actions[categoryName];
if (categoryTable == nil ) then
local allNames :string = "";
for _,catName in ipairs(data.Actions) do allNames = allNames .. "'" .. catName .. "' "; end
print("ERROR: Unit panel's primary actions sort reference '"..categoryName.."' but no table of that name. Tables in actionsTable: " .. allNames);
Controls.ForceAnAssertDueToAboveCondition();
else
StartIconGroup();
for _,action in ipairs(categoryTable) do
local instance:table = m_standardActionsIM:GetInstance();
AddActionButton( instance, action );
end
EndIconGroup();
end
end
-- Next fill in secondardy actions area
local numSecondaryItems:number = 0;
for _,categoryName in ipairs(data.Actions.displayOrder.secondaryArea) do
local categoryTable = data.Actions[categoryName];
if (categoryTable == nil ) then
local allNames :string = "";
for _,catName in ipairs(data.Actions) do allNames = allNames .. "'" .. catName .. "' "; end
print("ERROR: Unit panel's secondary actions sort reference '"..categoryName.."' but no table of that name. Tables in actionsTable: " .. allNames);
Controls.ForceAnAssertDueToAboveCondition();
else
for _,action in ipairs(categoryTable) do
local instance:table = m_secondaryActionsIM:GetInstance();
AddActionButton( instance, action );
numSecondaryItems = numSecondaryItems + 1;
end
end
end
Controls.ExpandSecondaryActionGrid:SetHide( numSecondaryItems <=0 );
end
-- Build panel options (if any)
if ( data.Actions["BUILD"] ~= nil and #data.Actions["BUILD"] > 0 ) then
Controls.BuildActionsPanel:SetHide(false);
local bestBuildAction :table = nil;
-- Create columns (each able to hold x3 icons) and fill them top to bottom
local numBuildCommands = table.count(data.Actions["BUILD"]);
for i=1,numBuildCommands,3 do
local buildColumnInstance = m_buildActionsIM:GetInstance();
for iRow=1,3,1 do
if ( (i+iRow)-1 <= numBuildCommands ) then
local slotName = "Row"..tostring(iRow);
local action = data.Actions["BUILD"][(i+iRow)-1];
local instance = {};
ContextPtr:BuildInstanceForControl( "BuildActionInstance", instance, buildColumnInstance[slotName]);
instance.UnitActionIcon:SetTexture( IconManager:FindIconAtlas(action.IconId) );
instance.UnitActionButton:SetDisabled( action.Disabled );
instance.UnitActionButton:SetAlpha( (action.Disabled and 0.4) or 1 );
instance.UnitActionButton:SetToolTipString( action.helpString );
instance.UnitActionButton:RegisterCallback( Mouse.eLClick, action.CallbackFunc );
instance.UnitActionButton:SetVoid1( action.CallbackVoid1 );
instance.UnitActionButton:SetVoid2( action.CallbackVoid2 );
-- PLACEHOLDER, currently sets first non-disabled build command; change to best build command.
if ( action.IsBestImprovement ~= nil and action.IsBestImprovement == true ) then
bestBuildAction = action;
end
end
end
end
local BUILD_PANEL_ART_PADDING_X = 24;
local BUILD_PANEL_ART_PADDING_Y = 20;
Controls.BuildActionsStack:CalculateSize();
Controls.BuildActionsStack:ReprocessAnchoring();
local buildStackWidth :number = Controls.BuildActionsStack:GetSizeX();
local buildStackHeight :number = Controls.BuildActionsStack:GetSizeY();
Controls.BuildActionsPanel:SetSizeX( buildStackWidth + BUILD_PANEL_ART_PADDING_X);
Controls.RecommendedActionButton:ReprocessAnchoring();
Controls.RecommendedActionIcon:ReprocessAnchoring();
Controls.RecommendedActionFrame:SetHide( bestBuildAction == nil );
if ( bestBuildAction ~= nil and CQUI_ImprovementTutorial) then
Controls.RecommendedActionButton:SetHide(false);
Controls.BuildActionsPanel:SetSizeY( buildStackHeight + 20 + BUILD_PANEL_ART_PADDING_Y);
Controls.BuildActionsStack:SetOffsetY(26);
Controls.RecommendedActionIcon:SetTexture( IconManager:FindIconAtlas(bestBuildAction.IconId) );
Controls.RecommendedActionButton:SetDisabled( bestBuildAction.Disabled );
Controls.RecommendedActionIcon:SetAlpha( (bestBuildAction.Disabled and 0.4) or 1 );
local tooltipString:string = Locale.Lookup("LOC_HUD_UNIT_PANEL_RECOMMENDED") .. ":[NEWLINE]" .. bestBuildAction.helpString;
Controls.RecommendedActionButton:SetToolTipString( tooltipString );
Controls.RecommendedActionButton:RegisterCallback( Mouse.eLClick, bestBuildAction.CallbackFunc );
Controls.RecommendedActionButton:SetVoid1( bestBuildAction.CallbackVoid1 );
Controls.RecommendedActionButton:SetVoid2( bestBuildAction.CallbackVoid2 );
else
Controls.RecommendedActionButton:SetHide(true);
Controls.BuildActionsPanel:SetSizeY( buildStackHeight + BUILD_PANEL_ART_PADDING_Y);
Controls.BuildActionsStack:SetOffsetY(0);
end
else
Controls.BuildActionsPanel:SetHide(true);
end
Controls.StandardActionsStack:CalculateSize();
Controls.StandardActionsStack:ReprocessAnchoring();
Controls.SecondaryActionsStack:CalculateSize();
Controls.SecondaryActionsStack:ReprocessAnchoring();
ResizeUnitPanelToFitActionButtons();
---=======[ STATS ]=======---
ShowSubjectUnitStats(ReadTargetData());
TradeUnitView(data);
EspionageView(data);
-- Unit Name
local unitName = Locale.Lookup(data.Name);
-- Add suffix
if data.UnitType ~= -1 then
if (GameInfo.Units[data.UnitType].Domain == "DOMAIN_SEA") then
if (data.MilitaryFormation == MilitaryFormationTypes.CORPS_FORMATION) then
unitName = unitName .. " " .. Locale.Lookup("LOC_HUD_UNIT_PANEL_FLEET_SUFFIX");
elseif (data.MilitaryFormation == MilitaryFormationTypes.ARMY_FORMATION) then
unitName = unitName .. " " .. Locale.Lookup("LOC_HUD_UNIT_PANEL_ARMADA_SUFFIX");
end
else
if (data.MilitaryFormation == MilitaryFormationTypes.CORPS_FORMATION) then
unitName = unitName .. " " .. Locale.Lookup("LOC_HUD_UNIT_PANEL_CORPS_SUFFIX");
elseif (data.MilitaryFormation == MilitaryFormationTypes.ARMY_FORMATION) then
unitName = unitName .. " " .. Locale.Lookup("LOC_HUD_UNIT_PANEL_ARMY_SUFFIX");
end
end
end
Controls.UnitName:SetText( Locale.ToUpper( unitName ));
Controls.CombatPreviewUnitName:SetText( Locale.ToUpper( unitName ));
-- Portrait Icons
if(data.IconName ~= nil) then
Controls.UnitIcon:SetIcon(data.IconName);
end
if(data.CivIconName ~= nil) then
local darkerBackColor = DarkenLightenColor(m_primaryColor,(-85),238);
local brighterBackColor = DarkenLightenColor(m_primaryColor,90,255);
Controls.CircleBacking:SetColor(m_primaryColor);
Controls.CircleLighter:SetColor(brighterBackColor);
Controls.CircleDarker:SetColor(darkerBackColor);
Controls.CivIcon:SetColor(m_secondaryColor);
Controls.CivIcon:SetIcon(data.CivIconName);
Controls.CityIconArea:SetHide(false);
Controls.UnitIcon:SetHide(true);
else
Controls.CityIconArea:SetHide(true);
Controls.UnitIcon:SetHide(false);
end
-- Damage meters ---
if (data.MaxWallDamage > 0) then
local healthPercent :number = 1 - GetPercentFromDamage( data.Damage + data.PotentialDamage, data.MaxDamage );
local healthShadowPercent :number = 1 - GetPercentFromDamage( data.Damage, data.MaxDamage );
RealizeHealthMeter( Controls.CityHealthMeter, healthPercent, Controls.CityHealthMeterShadow, healthShadowPercent );
local wallsPercent :number = 1 - GetPercentFromDamage(data.WallDamage + data.PotentialWallDamage, data.MaxWallDamage);
local wallsShadowPercent :number = 1 - GetPercentFromDamage( data.WallDamage, data.MaxWallDamage );
local wallRealizedPercent = (wallsPercent * 0.5) + 0.5;
Controls.WallHealthMeter:SetPercent( wallRealizedPercent )
local wallShadowRealizedPercent = (wallsShadowPercent * 0.5) + 0.5;
Controls.WallHealthMeterShadow:SetPercent( wallShadowRealizedPercent )
Controls.UnitHealthMeter:SetHide(true);
Controls.CityHealthMeters:SetHide(false);
if(wallsPercent == 0) then
Controls.CityWallHealthMeters:SetHide(true);
else
Controls.CityWallHealthMeters:SetHide(false);
end
-- Update health tooltip
local tooltip:string = "";
if data.UnitType ~= -1 then
tooltip = Locale.Lookup(data.UnitTypeName);
end
tooltip = tooltip .. "[NEWLINE]" .. Locale.Lookup("LOC_HUD_UNIT_PANEL_HEALTH_TOOLTIP", data.MaxDamage - data.Damage, data.MaxDamage);
if (data.MaxWallDamage > 0) then
tooltip = tooltip .. "[NEWLINE]" .. Locale.Lookup("LOC_HUD_UNIT_PANEL_WALL_HEALTH_TOOLTIP", data.MaxWallDamage - data.WallDamage, data.MaxWallDamage);
end
Controls.CityHealthMeter:SetToolTipString(tooltip);
else
local percent :number = 1 - GetPercentFromDamage( data.Damage, data.MaxDamage );
RealizeHealthMeter( Controls.UnitHealthMeter, percent, Controls.UnitHealthMeterShadow, percent );
Controls.UnitHealthMeter:SetHide(false);
Controls.CityHealthMeters:SetHide(true);
-- Update health tooltip
local tooltip:string = Locale.Lookup(data.UnitTypeName);
tooltip = tooltip .. "[NEWLINE]" .. Locale.Lookup("LOC_HUD_UNIT_PANEL_HEALTH_TOOLTIP", data.MaxDamage - data.Damage, data.MaxDamage);
Controls.UnitHealthMeter:SetToolTipString(tooltip);
end
-- Populate Earned Promotions UI
if (not UILens.IsLensActive("Religion") and data.Combat > 0) then
Controls.XPArea:SetHide(false);
Controls.XPBar:SetPercent( data.UnitExperience / data.MaxExperience );
Controls.XPArea:SetToolTipString( Locale.Lookup("LOC_HUD_UNIT_PANEL_XP_TT", data.UnitExperience, data.MaxExperience, data.UnitLevel+1 ) );
else
Controls.XPArea:SetHide(true);
end
Controls.PromotionBanner:SetColor( m_primaryColor );
m_earnedPromotionIM:ResetInstances();
if (table.count(data.CurrentPromotions) > 0) then
for i, promotion in ipairs(data.CurrentPromotions) do
local promotionInst = m_earnedPromotionIM:GetInstance();
if (data.CurrentPromotions[i] ~= nil) then
local descriptionStr = Locale.Lookup(data.CurrentPromotions[i].Name);
descriptionStr = descriptionStr .. "[NEWLINE]" .. Locale.Lookup(data.CurrentPromotions[i].Desc);
promotionInst.Top:SetToolTipString(descriptionStr);
end
end
Controls.PromotionBanner:SetHide(false);
else
Controls.PromotionBanner:SetHide(true);
end
-- Great Person Passive Ability Info
if data.GreatPersonPassiveText ~= "" then
Controls.GreatPersonPassiveGrid:SetHide(false);
Controls.GreatPersonPassiveGrid:SetToolTipString(Locale.Lookup("LOC_HUD_UNIT_PANEL_GREAT_PERSON_PASSIVE_ABILITY_TOOLTIP", data.GreatPersonPassiveName, data.GreatPersonPassiveText));
else
Controls.GreatPersonPassiveGrid:SetHide(true);
end
-- Settler Water Availability Info
if data.IsSettler then
Controls.SettlementWaterContainer:SetHide(false);
else
Controls.SettlementWaterContainer:SetHide(true);
end
ContextPtr:SetHide(false);
-- Hide combat preview unless we have valid combat results
if m_combatResults == nil then
OnShowCombat(false);
end
-- Turn off any animation previously occuring on meter, otherwise it will animate up each time a new unit is selected.
Controls.UnitHealthMeter:SetAnimationSpeed( -1 );
end
-- ===========================================================================
function ViewTarget(data)
-- Unit Name
local targetName = data.Name;
-- Add suffix
if (data.UnitType ~= -1) then
if (GameInfo.Units[data.UnitType].Domain == "DOMAIN_SEA") then
if (data.MilitaryFormation == MilitaryFormationTypes.CORPS_FORMATION) then
targetName = targetName .. " " .. Locale.Lookup("LOC_HUD_UNIT_PANEL_FLEET_SUFFIX");
elseif (data.MilitaryFormation == MilitaryFormationTypes.ARMY_FORMATION) then
targetName = targetName .. " " .. Locale.Lookup("LOC_HUD_UNIT_PANEL_ARMADA_SUFFIX");
end
else
if (data.MilitaryFormation == MilitaryFormationTypes.CORPS_FORMATION) then
targetName = targetName .. " " .. Locale.Lookup("LOC_HUD_UNIT_PANEL_CORPS_SUFFIX");
elseif (data.MilitaryFormation == MilitaryFormationTypes.ARMY_FORMATION) then
targetName = targetName .. " " .. Locale.Lookup("LOC_HUD_UNIT_PANEL_ARMY_SUFFIX");
end
end
end
Controls.TargetUnitName:SetText( Locale.ToUpper( targetName ));
---=======[ STATS ]=======---