forked from electronicarts/CnC_Generals_Zero_Hour
-
Notifications
You must be signed in to change notification settings - Fork 202
Expand file tree
/
Copy pathControlBar.cpp
More file actions
3800 lines (3181 loc) · 126 KB
/
ControlBar.cpp
File metadata and controls
3800 lines (3181 loc) · 126 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
/*
** Command & Conquer Generals(tm)
** Copyright 2025 Electronic Arts Inc.
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
////////////////////////////////////////////////////////////////////////////////
// //
// (c) 2001-2003 Electronic Arts Inc. //
// //
////////////////////////////////////////////////////////////////////////////////
// FILE: ControlBar.cpp ///////////////////////////////////////////////////////////////////////////
// Author: Colin Day, March 2002
// Desc: Context sensitive command interface
///////////////////////////////////////////////////////////////////////////////////////////////////
// USER INCLUDES //////////////////////////////////////////////////////////////////////////////////
#include "PreRTS.h" // This must go first in EVERY cpp file in the GameEngine
#define DEFINE_GUI_COMMAND_NAMES
#define DEFINE_COMMAND_OPTION_NAMES
#define DEFINE_WEAPONSLOTTYPE_NAMES
#define DEFINE_RADIUSCURSOR_NAMES
#include "Common/ActionManager.h"
#include "Common/GameType.h"
#include "Common/MultiplayerSettings.h"
#include "Common/NameKeyGenerator.h"
#include "Common/Override.h"
#include "Common/PlayerTemplate.h"
#include "Common/Player.h"
#include "Common/PlayerList.h"
#include "Common/ProductionPrerequisite.h"
#include "Common/SpecialPower.h"
#include "Common/ThingTemplate.h"
#include "Common/ThingFactory.h"
#include "Common/Upgrade.h"
#include "Common/Recorder.h"
#include "GameLogic/GameLogic.h"
#include "GameLogic/Object.h"
#include "GameLogic/Module/ProductionUpdate.h"
#include "GameLogic/Module/OCLUpdate.h"
#include "GameLogic/Module/ContainModule.h"
#include "GameLogic/Module/SpecialPowerModule.h"
#include "GameLogic/Module/StealthUpdate.h"
#include "GameLogic/Module/RebuildHoleBehavior.h"
#include "GameLogic/ScriptEngine.h"
#include "GameClient/AnimateWindowManager.h"
#include "GameClient/ControlBar.h"
#include "GameClient/ControlBarScheme.h"
#include "GameClient/Drawable.h"
#include "GameClient/Display.h"
#include "GameClient/DisplayStringManager.h"
#include "GameClient/GameClient.h"
#include "GameClient/GameWindowManager.h"
#include "GameClient/GameText.h"
#include "GameClient/GadgetPushButton.h"
#include "GameClient/GadgetProgressBar.h"
#include "GameClient/GadgetStaticText.h"
#include "GameClient/GadgetTextEntry.h"
#include "GameClient/InGameUI.h"
#include "GameClient/WindowVideoManager.h"
#include "GameClient/ControlBarResizer.h"
#include "GameClient/GadgetListBox.h"
#include "GameClient/HotKey.h"
#include "GameClient/GameWindowTransitions.h"
#include "GameClient/GUICallbacks.h"
#include "GameNetwork/GameInfo.h"
// PUBLIC /////////////////////////////////////////////////////////////////////////////////////////
ControlBar *TheControlBar = nullptr;
const Image* ControlBar::m_rankVeteranIcon = nullptr;
const Image* ControlBar::m_rankEliteIcon = nullptr;
const Image* ControlBar::m_rankHeroicIcon = nullptr;
///////////////////////////////////////////////////////////////////////////////////////////////////
// CommandButton //////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
const FieldParse CommandButton::s_commandButtonFieldParseTable[] =
{
{ "Command", CommandButton::parseCommand, nullptr, offsetof( CommandButton, m_command ) },
{ "Options", INI::parseBitString32, TheCommandOptionNames, offsetof( CommandButton, m_options ) },
{ "Object", INI::parseThingTemplate, nullptr, offsetof( CommandButton, m_thingTemplate ) },
{ "Upgrade", INI::parseUpgradeTemplate, nullptr, offsetof( CommandButton, m_upgradeTemplate ) },
{ "WeaponSlot", INI::parseLookupList, TheWeaponSlotTypeNamesLookupList, offsetof( CommandButton, m_weaponSlot ) },
{ "MaxShotsToFire", INI::parseInt, nullptr, offsetof( CommandButton, m_maxShotsToFire ) },
{ "Science", INI::parseScienceVector, nullptr, offsetof( CommandButton, m_science ) },
{ "SpecialPower", INI::parseSpecialPowerTemplate, nullptr, offsetof( CommandButton, m_specialPower ) },
{ "TextLabel", INI::parseAsciiString, nullptr, offsetof( CommandButton, m_textLabel ) },
{ "DescriptLabel", INI::parseAsciiString, nullptr, offsetof( CommandButton, m_descriptionLabel ) },
{ "PurchasedLabel", INI::parseAsciiString, nullptr, offsetof( CommandButton, m_purchasedLabel ) },
{ "ConflictingLabel", INI::parseAsciiString, nullptr, offsetof( CommandButton, m_conflictingLabel ) },
{ "ButtonImage", INI::parseAsciiString, nullptr, offsetof( CommandButton, m_buttonImageName ) },
{ "CursorName", INI::parseAsciiString, nullptr, offsetof( CommandButton, m_cursorName ) },
{ "InvalidCursorName", INI::parseAsciiString, nullptr, offsetof( CommandButton, m_invalidCursorName ) },
{ "ButtonBorderType", INI::parseLookupList, CommandButtonMappedBorderTypeNames, offsetof( CommandButton, m_commandButtonBorder ) },
{ "RadiusCursorType", INI::parseIndexList, TheRadiusCursorNames, offsetof( CommandButton, m_radiusCursor ) },
{ "UnitSpecificSound", INI::parseAudioEventRTS, nullptr, offsetof( CommandButton, m_unitSpecificSound ) },
{ nullptr, nullptr, nullptr, 0 }
};
static void commandButtonTooltip(GameWindow *window,
WinInstanceData *instData,
UnsignedInt mouse)
{
TheControlBar->showBuildTooltipLayout(window);
}
/// mark the UI as dirty so the context of everything is re-evaluated
void ControlBar::markUIDirty()
{
m_UIDirty = TRUE;
#if defined(RTS_DEBUG)
UnsignedInt now = TheGameLogic->getFrame();
if( now == m_lastFrameMarkedDirty )
{
//Do nothing.
}
else if( now == m_lastFrameMarkedDirty + 1 )
{
m_consecutiveDirtyFrames++;
}
else
{
m_consecutiveDirtyFrames = 1;
}
m_lastFrameMarkedDirty = now;
if( m_consecutiveDirtyFrames > 20 )
{
DEBUG_CRASH( ("Serious flaw in interface system! Either new code or INI has caused the interface to be marked dirty every frame. This problem actually causes the interface to completely lockup not allowing you to click normal game buttons.") );
}
#endif
}
Player* ControlBar::getCurrentlyViewedPlayer()
{
if (isObserverControlBarOn())
return getObserverLookAtPlayer();
return ThePlayerList->getLocalPlayer();
}
Relationship ControlBar::getCurrentlyViewedPlayerRelationship(const Team* team)
{
if (Player* player = getCurrentlyViewedPlayer())
return player->getRelationship(team);
return NEUTRAL;
}
void ControlBar::populatePurchaseScience( Player* player )
{
// TheInGameUI->deselectAllDrawables();
const CommandSet *commandSet1;
const CommandSet *commandSet3;
const CommandSet *commandSet8;
Int i;
if(TheScriptEngine->isGameEnding())
return;
// get command set
if(!player ||!player->getPlayerTemplate() || player->getPlayerTemplate()->getPurchaseScienceCommandSetRank1().isEmpty() ||
player->getPlayerTemplate()->getPurchaseScienceCommandSetRank3().isEmpty() ||
player->getPlayerTemplate()->getPurchaseScienceCommandSetRank8().isEmpty())
return;
commandSet1 = findCommandSet(player->getPlayerTemplate()->getPurchaseScienceCommandSetRank1()); // TEMP WILL CHANGE TO PROPER WAY ONCE WORKING
commandSet3 = findCommandSet(player->getPlayerTemplate()->getPurchaseScienceCommandSetRank3()); // TEMP WILL CHANGE TO PROPER WAY ONCE WORKING
commandSet8 = findCommandSet(player->getPlayerTemplate()->getPurchaseScienceCommandSetRank8()); // TEMP WILL CHANGE TO PROPER WAY ONCE WORKING
for( i = 0; i < MAX_PURCHASE_SCIENCE_RANK_1; i++ )
if (m_sciencePurchaseWindowsRank1[i] != nullptr)
m_sciencePurchaseWindowsRank1[i]->winHide(TRUE);
for( i = 0; i < MAX_PURCHASE_SCIENCE_RANK_3; i++ )
if (m_sciencePurchaseWindowsRank3[i] != nullptr)
m_sciencePurchaseWindowsRank3[i]->winHide(TRUE);
for( i = 0; i < MAX_PURCHASE_SCIENCE_RANK_8; i++ )
if (m_sciencePurchaseWindowsRank8[i] != nullptr)
m_sciencePurchaseWindowsRank8[i]->winHide(TRUE);
// if no command set match is found hide all the buttons
if( commandSet1 == nullptr ||
commandSet3 == nullptr ||
commandSet8 == nullptr )
return;
// populate the button with commands defined
const CommandButton *commandButton;
for( i = 0; i < MAX_PURCHASE_SCIENCE_RANK_1; i++ )
{
if (m_sciencePurchaseWindowsRank1[i] == nullptr)
continue;
// get command button
commandButton = commandSet1->getCommandButton(i);
// if button is not present, just hide the window
if( commandButton == nullptr || BitIsSet( commandButton->getOptions(), SCRIPT_ONLY ) )
{
// hide window on interface
m_sciencePurchaseWindowsRank1[ i ]->winHide( TRUE );
}
else
{
// make sure the window is not hidden
m_sciencePurchaseWindowsRank1[ i ]->winHide( FALSE );
// Disable by default
m_sciencePurchaseWindowsRank1[ i ]->winEnable( FALSE );
// populate the visible button with data from the command button
setControlCommand( m_sciencePurchaseWindowsRank1[ i ], commandButton );
if (!commandButton->getScienceVec().empty())
{
ScienceType st = commandButton->getScienceVec()[ 0 ];
if( player->isScienceDisabled( st ) )
{
//A script has deemed this science disabled.
m_sciencePurchaseWindowsRank1[ i ]->winEnable( FALSE );
}
else if( player->isScienceHidden( st ) )
{
//A script has deemed this science unavailable, thus hidden
m_sciencePurchaseWindowsRank1[ i ]->winHide( TRUE );
}
else
{
//Handle normal game logic cases!
if(!player->hasScience(st) && TheScienceStore->playerHasPrereqsForScience(player, st) && TheScienceStore->getSciencePurchaseCost(st) <= player->getSciencePurchasePoints())
{
m_sciencePurchaseWindowsRank1[ i ]->winEnable( TRUE );
}
if(player->hasScience(st))
{
m_sciencePurchaseWindowsRank1[ i ]->winSetStatus(WIN_STATUS_ALWAYS_COLOR);
}
else
{
m_sciencePurchaseWindowsRank1[ i ]->winClearStatus(WIN_STATUS_ALWAYS_COLOR);
}
if(!TheScienceStore->playerHasRootPrereqsForScience(player, st))
m_sciencePurchaseWindowsRank1[ i ]->winHide(TRUE);
}
}
}
}
for( i = 0; i < MAX_PURCHASE_SCIENCE_RANK_3; i++ )
{
if (m_sciencePurchaseWindowsRank3[i] == nullptr)
continue;
// get command button
commandButton = commandSet3->getCommandButton(i);
// if button is not present, just hide the window
if( commandButton == nullptr || BitIsSet( commandButton->getOptions(), SCRIPT_ONLY ) )
{
// hide window on interface
m_sciencePurchaseWindowsRank3[ i ]->winHide( TRUE );
}
else
{
// make sure the window is not hidden
m_sciencePurchaseWindowsRank3[ i ]->winHide( FALSE );
// Disable by default
m_sciencePurchaseWindowsRank3[ i ]->winEnable( FALSE );
// populate the visible button with data from the command button
setControlCommand( m_sciencePurchaseWindowsRank3[ i ], commandButton );
ScienceType st = SCIENCE_INVALID;
ScienceVec sv = commandButton->getScienceVec();
if (! sv.empty())
{
st = sv[ 0 ];
}
if( player->isScienceDisabled( st ) )
{
//A script has deemed this science disabled.
m_sciencePurchaseWindowsRank3[ i ]->winEnable( FALSE );
}
else if( player->isScienceHidden( st ) )
{
//A script has deemed this science unavailable, thus hidden
m_sciencePurchaseWindowsRank3[ i ]->winHide( TRUE );
}
else
{
//Handle normal game logic cases!
if(!player->hasScience(st) && TheScienceStore->playerHasPrereqsForScience(player, st) && TheScienceStore->getSciencePurchaseCost(st) <= player->getSciencePurchasePoints())
{
m_sciencePurchaseWindowsRank3[ i ]->winEnable( TRUE );
}
if(player->hasScience(st))
{
m_sciencePurchaseWindowsRank3[ i ]->winSetStatus(WIN_STATUS_ALWAYS_COLOR);
}
else
{
m_sciencePurchaseWindowsRank3[ i ]->winClearStatus(WIN_STATUS_ALWAYS_COLOR);
}
if(!TheScienceStore->playerHasRootPrereqsForScience(player, st))
m_sciencePurchaseWindowsRank3[ i ]->winHide(TRUE);
}
}
}
for( i = 0; i < MAX_PURCHASE_SCIENCE_RANK_8; i++ )
{
if (m_sciencePurchaseWindowsRank8[i] == nullptr)
continue;
// get command button
commandButton = commandSet8->getCommandButton(i);
// if button is not present, just hide the window
if( commandButton == nullptr || BitIsSet( commandButton->getOptions(), SCRIPT_ONLY ) )
{
// hide window on interface
m_sciencePurchaseWindowsRank8[ i ]->winHide( TRUE );
}
else
{
// make sure the window is not hidden
m_sciencePurchaseWindowsRank8[ i ]->winHide( FALSE );
// Disable by default
m_sciencePurchaseWindowsRank8[ i ]->winEnable( FALSE );
// populate the visible button with data from the command button
setControlCommand( m_sciencePurchaseWindowsRank8[ i ], commandButton );
ScienceType st = SCIENCE_INVALID;
st = commandButton->getScienceVec()[ 0 ];
if( player->isScienceDisabled( st ) )
{
//A script has deemed this science disabled.
m_sciencePurchaseWindowsRank8[ i ]->winEnable( FALSE );
}
else if( player->isScienceHidden( st ) )
{
//A script has deemed this science unavailable, thus hidden
m_sciencePurchaseWindowsRank8[ i ]->winHide( TRUE );
}
else
{
//Handle normal game logic cases!
if(!player->hasScience(st) && TheScienceStore->playerHasPrereqsForScience(player, st) && TheScienceStore->getSciencePurchaseCost(st) <= player->getSciencePurchasePoints())
{
m_sciencePurchaseWindowsRank8[ i ]->winEnable( TRUE );
}
if(player->hasScience(st))
{
m_sciencePurchaseWindowsRank8[ i ]->winSetStatus(WIN_STATUS_ALWAYS_COLOR);
}
else
{
m_sciencePurchaseWindowsRank8[ i ]->winClearStatus(WIN_STATUS_ALWAYS_COLOR);
}
if(!TheScienceStore->playerHasRootPrereqsForScience(player, st))
m_sciencePurchaseWindowsRank8[ i ]->winHide(TRUE);
}
}
}
GameWindow *win = nullptr;
UnicodeString tempUS;
win = TheWindowManager->winGetWindowFromId( m_contextParent[ CP_PURCHASE_SCIENCE ], TheNameKeyGenerator->nameToKey( "GeneralsExpPoints.wnd:StaticTextRankPointsAvailable" ) );
if(win)
{
tempUS.format(L"%d", player->getSciencePurchasePoints());
GadgetStaticTextSetText(win, tempUS);
}
#if RTS_GENERALS
win = TheWindowManager->winGetWindowFromId( m_contextParent[ CP_PURCHASE_SCIENCE ], TheNameKeyGenerator->nameToKey( "GeneralsExpPoints.wnd:StaticTextLevel" ) );
if(win)
{
tempUS.format(TheGameText->fetch("SCIENCE:Rank"), player->getRankLevel());
GadgetStaticTextSetText(win, tempUS);
}
#else
// redundant to StaticTextTitle in the Zero Hour context
#endif
win = TheWindowManager->winGetWindowFromId( m_contextParent[ CP_PURCHASE_SCIENCE ], TheNameKeyGenerator->nameToKey( "GeneralsExpPoints.wnd:ProgressBarExperience" ) );
if(win)
{
Int progress;
progress = ((player->getSkillPoints() - player->getSkillPointsLevelDown()) * 100) /(player->getSkillPointsLevelUp() - player->getSkillPointsLevelDown());
GadgetProgressBarSetProgress(win, progress);
}
win = TheWindowManager->winGetWindowFromId( m_contextParent[ CP_PURCHASE_SCIENCE ], TheNameKeyGenerator->nameToKey( "GeneralsExpPoints.wnd:StaticTextTitle" ) );
if(win)
{
AsciiString tempAs;
tempAs.format("SCIENCE:Rank%d", player->getRankLevel());
GadgetStaticTextSetText(win, TheGameText->fetch(tempAs));
}
//
// to avoid a one frame delay where windows may become enabled/disabled, run the update
// at once to get it all in the correct state immediately
//
updateContextPurchaseScience();
/*
// get the side select buttons
GameWindow* win = m_contextParent[ CP_PURCHASE_SCIENCE ];
Color color = GameMakeColor(255, 255, 255, 255);
/// @todo srj -- evil hack testing code. do not imitate.
ScienceVec purchasable, potential;
TheScienceStore->getPurchasableSciences(player, purchasable, potential);
GadgetListBoxReset(win);
for (ScienceVec::const_iterator it = purchasable.begin(); it != purchasable.end(); ++it)
{
ScienceType st = *it;
UnicodeString u;
u.translate(TheScienceStore->getInternalNameForScience(st));
GadgetListBoxAddEntryText(win, u, color, -1, -1);
}
for (ScienceVec::const_iterator it2 = potential.begin(); it2 != potential.end(); ++it2)
{
ScienceType st = *it2;
AsciiString foo = "(Not Yet)";
foo.concat(TheScienceStore->getInternalNameForScience(st));
UnicodeString u;
u.translate(foo);
GadgetListBoxAddEntryText(win, u, color, -1, -1);
}
GadgetListBoxAddEntryText(win, L"Cancel", color, -1, -1);*/
}
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
void ControlBar::updateContextPurchaseScience()
{
GameWindow *win =nullptr;
Player *player = ThePlayerList->getLocalPlayer();
win = TheWindowManager->winGetWindowFromId( m_contextParent[ CP_PURCHASE_SCIENCE ], TheNameKeyGenerator->nameToKey( "GeneralsExpPoints.wnd:ProgressBarExperience" ) );
if(win)
{
Int progress;
progress = ((player->getSkillPoints() - player->getSkillPointsLevelDown()) * 100) /(player->getSkillPointsLevelUp() - player->getSkillPointsLevelDown());
GadgetProgressBarSetProgress(win, progress);
}
// win = TheWindowManager->winGetWindowFromId( m_contextParent[ CP_PURCHASE_SCIENCE ], TheNameKeyGenerator->nameToKey( "ControlBar.wnd:TextEntryGeneralName" ) );
// if(win)
// {
// UnicodeString temp = GadgetTextEntryGetText(win);
// if(temp.compare(player->getGeneralName()) != 0)
// player->setGeneralName(temp);
// }
/*
/// @todo srj -- evil hack testing code. do not imitate.
Object *obj = m_currentSelectedDrawable->getObject();
if( obj == nullptr )
return;
// sanity
if( obj->isKindOf( KINDOF_COMMANDCENTER ) == FALSE )
switchToContext( CB_CONTEXT_NONE, nullptr );
GameWindow* win = m_contextParent[ CP_PURCHASE_SCIENCE ];
Int selected;
GadgetListBoxGetSelected( win, &selected );
if( selected != -1 )
{
UnicodeString usci = GadgetListBoxGetText( win, selected, 0 );
AsciiString sci;
sci.translate(usci);
ScienceType st = usci.getCharAt(0) == '(' ? SCIENCE_INVALID : TheScienceStore->getScienceFromInternalName(sci);
if (st != SCIENCE_INVALID)
{
GameMessage *msg = TheMessageStream->appendMessage( GameMessage::MSG_PURCHASE_SCIENCE );
msg->appendIntegerArgument( st );
}
switchToContext( CB_CONTEXT_NONE, nullptr );
}
*/
}
//-------------------------------------------------------------------------------------------------
/** parse command definition */
//-------------------------------------------------------------------------------------------------
void CommandButton::parseCommand( INI* ini, void *instance, void *store, const void *userData )
{
const char *token = ini->getNextToken();
Int i;
for( i = 0; TheGuiCommandNames[ i ]; i++ )
{
if( stricmp( TheGuiCommandNames[ i ], token ) == 0 )
{
GUICommandType *command = (GUICommandType *)store;
*command = (GUICommandType)i;
return;
}
}
// if we're here the command was not found
throw INI_INVALID_DATA;
}
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
CommandButton::CommandButton()
{
m_command = GUI_COMMAND_NONE;
m_thingTemplate = nullptr;
m_upgradeTemplate = nullptr;
m_weaponSlot = PRIMARY_WEAPON;
m_maxShotsToFire = 0x7fffffff; // huge number
m_science.clear();
m_specialPower = nullptr;
m_buttonImage = nullptr;
//Code renderer handles these states now.
//m_disabledImage = nullptr;
//m_hiliteImage = nullptr;
//m_pushedImage = nullptr;
m_flashCount = 0;
m_conflictingLabel.clear();
m_cursorName.clear();
m_descriptionLabel.clear();
m_invalidCursorName.clear();
m_name.clear();
m_options = 0;
m_purchasedLabel.clear();
m_textLabel.clear();
m_window = nullptr;
m_commandButtonBorder = COMMAND_BUTTON_BORDER_NONE;
//m_prev = nullptr;
m_next = nullptr;
m_radiusCursor = RADIUSCURSOR_NONE;
}
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
CommandButton::~CommandButton()
{
}
//-------------------------------------------------------------------------------------------------
Bool CommandButton::isValidRelationshipTarget(Relationship r) const
{
UnsignedInt mask = 0;
if (r == ENEMIES) mask |= NEED_TARGET_ENEMY_OBJECT;
else if (r == ALLIES) mask |= NEED_TARGET_ALLY_OBJECT;
else if (r == NEUTRAL) mask |= NEED_TARGET_NEUTRAL_OBJECT;
return (m_options & mask) != 0;
}
//-------------------------------------------------------------------------------------------------
Bool CommandButton::isValidObjectTarget(const Player* sourcePlayer, const Object* targetObj) const
{
if (!sourcePlayer || !targetObj)
return false;
Relationship r = sourcePlayer->getRelationship(targetObj->getTeam());
return isValidRelationshipTarget(r);
}
//-------------------------------------------------------------------------------------------------
Bool CommandButton::isValidObjectTarget(const Object* sourceObj, const Object* targetObj) const
{
if (!sourceObj || !targetObj)
return false;
Relationship r = sourceObj->getRelationship(targetObj);
return isValidRelationshipTarget(r);
}
//-------------------------------------------------------------------------------------------------
Bool CommandButton::isValidToUseOn(const Object *sourceObj, const Object *targetObj, const Coord3D *targetLocation, CommandSourceType commandSource) const
{
if (m_upgradeTemplate) {
// @todo: Make a const version of pui. We're not altering the production queue, so this const-cast
// is okay.
ProductionUpdateInterface *pui = const_cast<Object*>(sourceObj)->getProductionUpdateInterface();
if (pui) {
const ProductionEntry *pe = pui->firstProduction();
while (pe) {
if (pe->getProductionUpgrade() != nullptr)
return false;
pe = pui->nextProduction(pe);
}
return sourceObj->affectedByUpgrade(m_upgradeTemplate) && !sourceObj->hasUpgrade(m_upgradeTemplate);
}
// No ProductionUpdateInterface means we can't do this.
return false;
}
if( BitIsSet( m_options, COMMAND_OPTION_NEED_OBJECT_TARGET ) && !targetObj )
{
return false;
}
Coord3D pos;
if( targetLocation )
{
pos.set( targetLocation );
}
if( BitIsSet( m_options, NEED_TARGET_POS ) && !targetLocation )
{
if( targetObj )
{
pos.set( targetObj->getPosition() );
}
else
{
return false;
}
}
if( BitIsSet( m_options, COMMAND_OPTION_NEED_OBJECT_TARGET ) )
{
return TheActionManager->canDoSpecialPowerAtObject( sourceObj, targetObj, commandSource, m_specialPower, m_options, false );
}
if( BitIsSet( m_options, NEED_TARGET_POS ) )
{
return TheActionManager->canDoSpecialPowerAtLocation( sourceObj, &pos, commandSource, m_specialPower, nullptr, m_options, false );
}
return TheActionManager->canDoSpecialPower( sourceObj, m_specialPower, commandSource, m_options, false );
}
//-------------------------------------------------------------------------------------------------
Bool CommandButton::isReady(const Object *sourceObj) const
{
SpecialPowerModuleInterface *mod = sourceObj->getSpecialPowerModule( m_specialPower );
if( mod && mod->getPercentReady() == 1.0f )
return true;
if (m_upgradeTemplate && sourceObj->affectedByUpgrade(m_upgradeTemplate) && !sourceObj->hasUpgrade(m_upgradeTemplate))
return true;
return false;
}
//-------------------------------------------------------------------------------------------------
Bool CommandButton::isValidObjectTarget(const Drawable* source, const Drawable* target) const
{
return isValidObjectTarget(source ? source->getObject() : nullptr, target ? target->getObject() : nullptr);
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// CommandSet /////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
//-------------------------------------------------------------------------------------------------
/** These are the fields you can define in a command set, they correspond to physical
* buttons in the GUI */
//-------------------------------------------------------------------------------------------------
const FieldParse CommandSet::m_commandSetFieldParseTable[] =
{
{ "1", CommandSet::parseCommandButton, (void *)nullptr, offsetof( CommandSet, m_command ) },
{ "2", CommandSet::parseCommandButton, (void *)1, offsetof( CommandSet, m_command ) },
{ "3", CommandSet::parseCommandButton, (void *)2, offsetof( CommandSet, m_command ) },
{ "4", CommandSet::parseCommandButton, (void *)3, offsetof( CommandSet, m_command ) },
{ "5", CommandSet::parseCommandButton, (void *)4, offsetof( CommandSet, m_command ) },
{ "6", CommandSet::parseCommandButton, (void *)5, offsetof( CommandSet, m_command ) },
{ "7", CommandSet::parseCommandButton, (void *)6, offsetof( CommandSet, m_command ) },
{ "8", CommandSet::parseCommandButton, (void *)7, offsetof( CommandSet, m_command ) },
{ "9", CommandSet::parseCommandButton, (void *)8, offsetof( CommandSet, m_command ) },
{ "10", CommandSet::parseCommandButton, (void *)9, offsetof( CommandSet, m_command ) },
{ "11", CommandSet::parseCommandButton, (void *)10, offsetof( CommandSet, m_command ) },
{ "12", CommandSet::parseCommandButton, (void *)11, offsetof( CommandSet, m_command ) },
{ "13", CommandSet::parseCommandButton, (void *)12, offsetof( CommandSet, m_command ) },
{ "14", CommandSet::parseCommandButton, (void *)13, offsetof( CommandSet, m_command ) },
{ "15", CommandSet::parseCommandButton, (void *)14, offsetof( CommandSet, m_command ) },
{ "16", CommandSet::parseCommandButton, (void *)15, offsetof( CommandSet, m_command ) },
{ "17", CommandSet::parseCommandButton, (void *)16, offsetof( CommandSet, m_command ) },
{ "18", CommandSet::parseCommandButton, (void *)17, offsetof( CommandSet, m_command ) },
{ nullptr, nullptr, nullptr, 0 }
};
//-------------------------------------------------------------------------------------------------
Bool CommandButton::isContextCommand() const
{
return BitIsSet( m_options, CONTEXTMODE_COMMAND );
}
//-------------------------------------------------------------------------------------------------
// bleah. shouldn't be const, but is. sue me. (srj)
void CommandButton::copyImagesFrom( const CommandButton *button, Bool markUIDirtyIfChanged ) const
{
if( m_buttonImage != button->getButtonImage() )
{
m_buttonImage = button->getButtonImage();
//Code renderer handles these states now.
//m_disabledImage = button->getDisabledImage();
//m_hiliteImage = button->getHiliteImage();
//m_pushedImage = button->getPushedImage();
if( markUIDirtyIfChanged )
{
TheControlBar->markUIDirty();
}
}
}
//-------------------------------------------------------------------------------------------------
// bleah. shouldn't be const, but is. sue me. (Kris) -snork!
void CommandButton::copyButtonTextFrom( const CommandButton *button, Bool shortcutButton, Bool markUIDirtyIfChanged ) const
{
//This function was added to change the strings when you upgrade from a DaisyCutter to a MOAB. All other special
//powers are the same.
Bool change = FALSE;
if( shortcutButton )
{
//Not the best code, but conflicting label means shortcut label (most won't have any string specified).
if( button->getConflictingLabel().isNotEmpty() && m_textLabel.compare( button->getConflictingLabel() ) )
{
m_textLabel = button->getConflictingLabel();
change = TRUE;
}
}
else
{
//Copy the text from the purchase science button if it exists (most won't).
if( button->getTextLabel().isNotEmpty() && m_textLabel.compare( button->getTextLabel() ) )
{
m_textLabel = button->getTextLabel();
change = TRUE;
}
}
if( button->getDescriptionLabel().isNotEmpty() && m_descriptionLabel.compare( button->getDescriptionLabel() ) )
{
m_descriptionLabel = button->getDescriptionLabel();
change = TRUE;
}
if( markUIDirtyIfChanged && change )
{
TheControlBar->markUIDirty();
}
}
//-------------------------------------------------------------------------------------------------
/** Parse a single command button definition */
//-------------------------------------------------------------------------------------------------
void CommandSet::parseCommandButton( INI* ini, void *instance, void *store, const void *userData )
{
const char *token = ini->getNextToken();
// get find the command button from this name
const CommandButton *commandButton = TheControlBar->findCommandButton( AsciiString( token ) );
if( commandButton == nullptr )
{
DEBUG_CRASH(( "[LINE: %d - FILE: '%s'] Unknown command '%s' found in command set",
ini->getLineNum(), ini->getFilename().str(), token ));
throw INI_INVALID_DATA;
}
// get the index to store the command at, and the command array itself
const CommandButton **buttonArray = (const CommandButton **)store;
Int buttonIndex = (Int)userData;
// sanity
DEBUG_ASSERTCRASH( buttonIndex < MAX_COMMANDS_PER_SET, ("parseCommandButton: button index '%d' out of range",
buttonIndex) );
// save it
buttonArray[ buttonIndex ] = commandButton;
}
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
CommandSet::CommandSet(const AsciiString& name) :
m_name(name),
m_next(nullptr)
{
for( Int i = 0; i < MAX_COMMANDS_PER_SET; i++ )
m_command[ i ] = nullptr;
}
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
const CommandButton* CommandSet::getCommandButton(Int i) const
{
const CommandButton* button;
// Check for TheGameLogic == null, cause it is in Worldbuilder, and wb gets command bar info. jba.
if (TheGameLogic && TheGameLogic->findControlBarOverride(m_name, i, button))
return button;
return m_command[i];
}
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
void CommandSet::friend_addToList(CommandSet** listHead)
{
m_next = *listHead;
*listHead = this;
}
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
CommandSet::~CommandSet()
{
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// ControlBar /////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
ControlBar::ControlBar()
{
Int i;
m_commandButtons = nullptr;
m_commandSets = nullptr;
m_controlBarSchemeManager = nullptr;
m_isObserverCommandBar = FALSE;
m_observerLookAtPlayer = nullptr;
m_observedPlayer = nullptr;
m_buildToolTipLayout = nullptr;
m_showBuildToolTipLayout = FALSE;
m_animateDownWin1Pos.x = m_animateDownWin1Pos.y = 0;
m_animateDownWin1Size.x = m_animateDownWin1Size.y = 0;
m_animateDownWin2Pos.x = m_animateDownWin2Pos.y = 0;
m_animateDownWin2Size.x = m_animateDownWin2Size.y = 0;
m_animateDownWindow = nullptr;
m_animTime = 0;
for( i = 0; i < MAX_COMMANDS_PER_SET; i++)
{
m_commonCommands[i] = nullptr;
}
m_currContext = CB_CONTEXT_NONE;
m_defaultControlBarPosition.x = m_defaultControlBarPosition.y = 0;
m_genStarFlash = FALSE;
m_genStarOff = nullptr;
m_genStarOn = nullptr;
m_UIDirty = FALSE;
// m_controlBarResizer = nullptr;
m_buildUpClockColor = GameMakeColor(0,0,0,100);
m_commandBarBorderColor = GameMakeColor(0,0,0,100);
for( i = 0; i < NUM_CONTEXT_PARENTS; i++ )
m_contextParent[ i ] = nullptr;
for( i = 0; i < MAX_COMMANDS_PER_SET; i++ )
{
m_commandWindows[ i ] = nullptr;
// removed from multiplayer branch
//m_commandMarkers[ i ] = nullptr;
}
for( i = 0; i < MAX_PURCHASE_SCIENCE_RANK_1; i++ )
m_sciencePurchaseWindowsRank1[i] = nullptr;
for( i = 0; i < MAX_PURCHASE_SCIENCE_RANK_3; i++ )
m_sciencePurchaseWindowsRank3[i] = nullptr;
for( i = 0; i < MAX_PURCHASE_SCIENCE_RANK_8; i++ )
m_sciencePurchaseWindowsRank8[i] = nullptr;
for( i = 0; i < MAX_SPECIAL_POWER_SHORTCUTS; i++ )
{
m_specialPowerShortcutButtons[i] = nullptr;
m_specialPowerShortcutButtonParents[i] = nullptr;
}
m_specialPowerShortcutParent = nullptr;
m_specialPowerLayout = nullptr;
m_scienceLayout = nullptr;
m_rightHUDWindow = nullptr;
m_rightHUDCameoWindow = nullptr;
for( i = 0; i < MAX_RIGHT_HUD_UPGRADE_CAMEOS; i++ )
m_rightHUDUpgradeCameos[i];
m_rightHUDUnitSelectParent = nullptr;
m_communicatorButton = nullptr;
m_currentSelectedDrawable = nullptr;
m_currContext = CB_CONTEXT_NONE;
m_rallyPointDrawableID = INVALID_DRAWABLE_ID;
m_displayedConstructPercent = -1.0f;
m_displayedOCLTimerSeconds = 0;
m_displayedQueueCount = 0;
resetBuildQueueData();
resetContainData();
m_lastRecordedInventoryCount = 0;
m_videoManager = nullptr;
m_animateWindowManager = nullptr;
m_generalsScreenAnimate = nullptr;
m_animateWindowManagerForGenShortcuts = nullptr;
m_flash = FALSE;
m_toggleButtonUpIn = nullptr;
m_toggleButtonUpOn = nullptr;
m_toggleButtonUpPushed = nullptr;
m_toggleButtonDownIn = nullptr;
m_toggleButtonDownOn = nullptr;
m_toggleButtonDownPushed = nullptr;
m_generalButtonEnable = nullptr;
m_generalButtonHighlight = nullptr;
m_genArrow = nullptr;
m_sideSelectAnimateDown = FALSE;
updateCommandBarBorderColors(GAME_COLOR_UNDEFINED,GAME_COLOR_UNDEFINED,GAME_COLOR_UNDEFINED,GAME_COLOR_UNDEFINED);
m_radarAttackGlowOn = FALSE;
m_remainingRadarAttackGlowFrames = 0;
m_radarAttackGlowWindow = nullptr;
#if defined(RTS_DEBUG)
m_lastFrameMarkedDirty = 0;
m_consecutiveDirtyFrames = 0;
#endif
}
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
ControlBar::~ControlBar()
{
if(m_scienceLayout)
{
m_scienceLayout->destroyWindows();
deleteInstance(m_scienceLayout);
m_scienceLayout = nullptr;
}
m_genArrow = nullptr;
delete m_videoManager;
m_videoManager = nullptr;
delete m_animateWindowManagerForGenShortcuts;
m_animateWindowManagerForGenShortcuts = nullptr;