forked from TheSuperHackers/GeneralsGameCode
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathControlBarCommand.cpp
More file actions
1549 lines (1288 loc) · 51.8 KB
/
ControlBarCommand.cpp
File metadata and controls
1549 lines (1288 loc) · 51.8 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 Zero Hour(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: ControlBarCommand.cpp ////////////////////////////////////////////////////////////////////
// Author: Colin Day, March 2002
// Desc: Methods specific to the control bar unit commands
///////////////////////////////////////////////////////////////////////////////////////////////////
// USER INCLUDES //////////////////////////////////////////////////////////////////////////////////
#include "PreRTS.h" // This must go first in EVERY cpp file in the GameEngine
#include "Common/NameKeyGenerator.h"
#include "Common/ThingTemplate.h"
#include "Common/ThingFactory.h"
#include "Common/Player.h"
#include "Common/PlayerList.h"
#include "Common/PlayerTemplate.h"
#include "Common/SpecialPower.h"
#include "Common/Upgrade.h"
#include "Common/BuildAssistant.h"
#include "GameLogic/GameLogic.h"
#include "GameLogic/Module/BattlePlanUpdate.h"
#include "GameLogic/Module/DozerAIUpdate.h"
#include "GameLogic/Module/JetAIUpdate.h"
#include "GameLogic/Module/OverchargeBehavior.h"
#include "GameLogic/Module/ProductionUpdate.h"
#include "GameLogic/Module/SpecialPowerModule.h"
#include "GameLogic/Module/TransportContain.h"
#include "GameLogic/Module/MobNexusContain.h"
#include "GameLogic/Module/SpecialAbilityUpdate.h"
#include "GameLogic/Module/VeterancyGainCreate.h"
#include "GameLogic/Module/HackInternetAIUpdate.h"
#include "GameLogic/Weapon.h"
#include "GameClient/InGameUI.h"
#include "GameClient/Drawable.h"
#include "GameClient/ControlBar.h"
#include "GameClient/GameWindow.h"
#include "GameClient/GameWindowManager.h"
#include "GameClient/GadgetPushButton.h"
// PRIVATE DATA ///////////////////////////////////////////////////////////////////////////////////
static GameWindow *commandWindows[ MAX_COMMANDS_PER_SET ];
Bool commandWindowsInitialized = FALSE;
static Color BuildClockColor = GameMakeColor(0,0,0,100);
// STATIC DATA STORAGE ////////////////////////////////////////////////////////////////////////////
ControlBar::ContainEntry ControlBar::m_containData[ MAX_COMMANDS_PER_SET ];
//-------------------------------------------------------------------------------------------------
/** Note, this iterate callback assumes that the inventory exit buttons appear in a
* continuous order in the layout of the command set */
//-------------------------------------------------------------------------------------------------
struct PopulateInvButtonData
{
Int currIndex; ///< index that represents the control we're talking about
Int maxIndex; ///< this is the last valid control we can use
GameWindow **controls; ///< the controls
Object *transport; ///< the transport
};
//-------------------------------------------------------------------------------------------------
/** Used for the callback iterator on transport contents to do the actual GUI fill */
//-------------------------------------------------------------------------------------------------
void ControlBar::populateInvDataCallback( Object *obj, void *userData )
{
PopulateInvButtonData *data = (PopulateInvButtonData *)userData;
//
// if we're beyond the max the GUI can support, design needs to change the parameters
// of the transport object to carry less things
//
if( data->currIndex > data->maxIndex )
{
DEBUG_ASSERTCRASH( 0, ("There is not enough GUI slots to hold the # of items inside a '%s'",
data->transport->getTemplate()->getName().str()) );
return;
}
// get the window control that we're going to put our smiling faces in
GameWindow *control = data->controls[ data->currIndex ];
DEBUG_ASSERTCRASH( control, ("populateInvDataCallback: Control not found") );
// assign our control and object id to the transport data
m_containData[ data->currIndex ].control = control;
m_containData[ data->currIndex ].objectID = obj->getID();
data->currIndex++;
// fill out the control enabled, hilite, and pushed images
const Image *image;
image = obj->getTemplate()->getButtonImage();
GadgetButtonSetEnabledImage( control, image );
//No longer used
//image = TheMappedImageCollection->findImageByName( obj->getTemplate()->getInventoryImageName( INV_IMAGE_HILITE ) );
//GadgetButtonSetHiliteImage( control, image );
//image = TheMappedImageCollection->findImageByName( obj->getTemplate()->getInventoryImageName( INV_IMAGE_PUSHED ) );
//GadgetButtonSetHiliteSelectedImage( control, image );
//Show the contained object's veterancy symbol!
image = calculateVeterancyOverlayForObject( obj );
GadgetButtonDrawOverlayImage( control, image );
// enable the control
control->winEnable( TRUE );
}
//-------------------------------------------------------------------------------------------------
/** Transports have an extra special manipulation of the user interface. They get to look
* at the available command set, and any of the commands that are TransportExit commands *AND*
* there is actually an object to represent that slot contained in the transport, the
* inventory picture of the contained object will be displayed in the window control for
* that TransportExit command. Also, transports will HIDE any TransportExit controls found
* in the command set that represent slots that *DO NOT EXIST* for the transport (that is,
* the transport can only hold 4 things, but the GUI has buttons for 8 things). For slots
* that are empty but present in the transport the UI will show a disabled button to show
* the user that there is an open "slot" */
//-------------------------------------------------------------------------------------------------
void ControlBar::doTransportInventoryUI( Object *transport, const CommandSet *commandSet )
{
/// @todo srj -- remove hard-coding here, please
//static const CommandButton *exitCommand = findCommandButton( "Command_TransportExit" );
// sanity
if( transport == NULL || commandSet == NULL )
return;
// get the transport contain module
ContainModuleInterface *contain = transport->getContain();
// sanity
if( contain == NULL )
return;
// how many slots do we have inside the transport
Int transportMax = contain->getContainMax();
//
// first, hide any windows in 'm_commandWindows' that correspond to TransportExit commands
// within the 'commandSet' that are overflow slots (the ui could be showing more inventory
// exit button slots than there are slots in the transport)
//
// The extra slots bit means that a tank that takes up three slots will make two transport
// buttons disappear off the end to show he takes up more room.
transportMax = transportMax - contain->getExtraSlotsInUse();
Int firstInventoryIndex = -1;
Int lastInventoryIndex = -1;
Int inventoryCommandCount = 0;
const CommandButton *commandButton;
for( Int i = 0; i < MAX_COMMANDS_PER_SET; i++ )
{
// our implementation doesn't necessarily make use of the max possible command buttons
if (! m_commandWindows[ i ]) continue;
// get command button
commandButton = commandSet->getCommandButton(i);
// is this an inventory exit command
if( commandButton && commandButton->getCommandType() == GUI_COMMAND_EXIT_CONTAINER )
{
// record the index of the control for the first inventory exit command we found
if( firstInventoryIndex == -1 )
firstInventoryIndex = i;
//
// since we're assuming all inventory exit commands appear in a continuous order,
// we need to also need to keep track of what is the last valid inventory commadn index
//
lastInventoryIndex = i;
// increment our count of available inventory exit commands found for the set
inventoryCommandCount++;
// show the window, but disable by default unless something is actually loaded in there
m_commandWindows[ i ]->winHide( FALSE );
m_commandWindows[ i ]->winEnable( FALSE );
//Clear any potential veterancy rank, or else we'll see it when it's empty!
GadgetButtonDrawOverlayImage( m_commandWindows[ i ], NULL );
//Unmanned vehicles don't have any commands available -- in fact they are hidden!
if( transport->isDisabledByType( DISABLED_UNMANNED ) )
{
m_commandWindows[ i ]->winHide( TRUE );
}
// is this where we set the cameos disabled when container is subdued?
// if we've counted more UI spots than the transport can hold, hide this command window
if( inventoryCommandCount > transportMax )
m_commandWindows[ i ]->winHide( TRUE );
//
// set the inventory exit command into the window (even if it's one of the hidden ones
// it's OK cause we'll never see it to click it
//
setControlCommand( m_commandWindows[ i ], commandButton );
}
}
// After Every change to the m_commandWIndows, we need to show fill in the missing blanks with the images
// removed from multiplayer branch
//showCommandMarkers();
//
// now, iterate the contained items of the transport and for each one we find we will
// populate a user interface button with its inventory picture and store the inventory
// data inside the control bar so we can respond to the button when its clicked
//
if( lastInventoryIndex >= 0 ) // just for sanity
{
PopulateInvButtonData data;
data.controls = m_commandWindows;
data.currIndex = firstInventoryIndex;
data.maxIndex = lastInventoryIndex;
data.transport = transport;
contain->iterateContained( populateInvDataCallback, &data, FALSE );
}
//
// save the last recorded inventory count so we know when we have to redo the gui when
// something exits or enters
//
m_lastRecordedInventoryCount = contain->getContainCount();
}
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
void ControlBar::populateCommand( Object *obj )
{
const CommandSet *commandSet;
Int i;
Player *player = obj->getControllingPlayer();
// reset contain data
resetContainData();
// reset the build queue data
resetBuildQueueData();
// get command set
commandSet = TheControlBar->findCommandSet( obj->getCommandSetString() );
// if no command set match is found hide all the buttons
if( commandSet == NULL )
{
// hide all the buttons
for( i = 0; i < MAX_COMMANDS_PER_SET; i++ )
if (m_commandWindows[ i ])
{
m_commandWindows[ i ]->winHide( TRUE );
}
// nothing left to do
return;
}
// transports do extra special things with the user interface buttons
if( obj->getContain() && obj->getContain()->isDisplayedOnControlBar() )
doTransportInventoryUI( obj, commandSet );
// populate the button with commands defined
const CommandButton *commandButton;
for( i = 0; i < MAX_COMMANDS_PER_SET; i++ )
{
// our implementation doesn't necessarily make use of the max possible command buttons
if (! m_commandWindows[ i ]) continue;
// get command button
commandButton = commandSet->getCommandButton(i);
// if button is not present, just hide the window
if( commandButton == NULL )
{
// hide window on interface
m_commandWindows[ i ]->winHide( TRUE );
}
else
{
//Script only command -- don't show it in the UI.
if( BitIsSet( commandButton->getOptions(), SCRIPT_ONLY ) )
{
m_commandWindows[ i ]->winHide( TRUE );
continue;
}
//
// inventory exit commands were a special case already taken care above ... we needed
// to iterage through the containment for transport objects and fill out any available
// inventory exit buttons on the UI
//
if( commandButton->getCommandType() != GUI_COMMAND_EXIT_CONTAINER )
{
// make sure the window is not hidden
m_commandWindows[ i ]->winHide( FALSE );
// enable by default
m_commandWindows[ i ]->winEnable( TRUE );
// populate the visible button with data from the command button
setControlCommand( m_commandWindows[ i ], commandButton );
//
// commands that require sciences we don't have are hidden so they never show up
// cause we can never pick "another" general technology throughout the game
//
if( BitIsSet( commandButton->getOptions(), NEED_SPECIAL_POWER_SCIENCE ) )
{
const SpecialPowerTemplate *power = commandButton->getSpecialPowerTemplate();
if( power && power->getRequiredScience() != SCIENCE_INVALID )
{
if( commandButton->getCommandType() != GUI_COMMAND_PURCHASE_SCIENCE &&
commandButton->getCommandType() != GUI_COMMAND_PLAYER_UPGRADE &&
commandButton->getCommandType() != GUI_COMMAND_OBJECT_UPGRADE )
{
if( player->hasScience( power->getRequiredScience() ) == FALSE )
{
//Hide the power
m_commandWindows[ i ]->winHide( TRUE );
}
else
{
//The player does have the special power! Now determine if the images require
//enhancement based on upgraded versions. This is determined by the command
//button specifying a vector of sciences in the command button.
Int bestIndex = -1;
ScienceType science;
for( size_t scienceIndex = 0; scienceIndex < commandButton->getScienceVec().size(); ++scienceIndex )
{
science = commandButton->getScienceVec()[ scienceIndex ];
//Keep going until we reach the end or don't have the required science!
if( player->hasScience( science ) )
{
bestIndex = scienceIndex;
}
else
{
break;
}
}
if( bestIndex != -1 )
{
//Now get the best sciencetype.
science = commandButton->getScienceVec()[ bestIndex ];
const CommandSet *commandSet1;
const CommandSet *commandSet3;
const CommandSet *commandSet8;
Int i;
// get command set
if( !player || !player->getPlayerTemplate()
|| player->getPlayerTemplate()->getPurchaseScienceCommandSetRank1().isEmpty()
|| player->getPlayerTemplate()->getPurchaseScienceCommandSetRank3().isEmpty()
|| player->getPlayerTemplate()->getPurchaseScienceCommandSetRank8().isEmpty() )
{
continue;
}
commandSet1 = TheControlBar->findCommandSet( player->getPlayerTemplate()->getPurchaseScienceCommandSetRank1() );
commandSet3 = TheControlBar->findCommandSet( player->getPlayerTemplate()->getPurchaseScienceCommandSetRank3() );
commandSet8 = TheControlBar->findCommandSet( player->getPlayerTemplate()->getPurchaseScienceCommandSetRank8() );
if( !commandSet1 || !commandSet3 || !commandSet8 )
{
continue;
}
Bool found = FALSE;
for( i = 0; !found && i < MAX_PURCHASE_SCIENCE_RANK_1; i++ )
{
const CommandButton *command = commandSet1->getCommandButton( i );
if( command && command->getCommandType() == GUI_COMMAND_PURCHASE_SCIENCE )
{
//All purchase sciences specify a single science.
if( command->getScienceVec().empty() )
{
DEBUG_CRASH( ("Commandbutton %s is a purchase science button without any science! Please add it.", command->getName().str() ) );
}
else if( command->getScienceVec()[0] == science )
{
commandButton->copyImagesFrom( command, TRUE );
commandButton->copyButtonTextFrom( command, FALSE, TRUE );
found = TRUE;
break;
}
}
}
for( i = 0; !found && i < MAX_PURCHASE_SCIENCE_RANK_3; i++ )
{
const CommandButton *command = commandSet3->getCommandButton( i );
if( command && command->getCommandType() == GUI_COMMAND_PURCHASE_SCIENCE )
{
//All purchase sciences specify a single science.
if( command->getScienceVec().empty() )
{
DEBUG_CRASH( ("Commandbutton %s is a purchase science button without any science! Please add it.", command->getName().str() ) );
}
else if( command->getScienceVec()[0] == science )
{
commandButton->copyImagesFrom( command, TRUE );
commandButton->copyButtonTextFrom( command, FALSE, TRUE );
found = TRUE;
break;
}
}
}
for( i = 0; !found && i < MAX_PURCHASE_SCIENCE_RANK_8; i++ )
{
const CommandButton *command = commandSet8->getCommandButton( i );
if( command && command->getCommandType() == GUI_COMMAND_PURCHASE_SCIENCE )
{
//All purchase sciences specify a single science.
if( command->getScienceVec().empty() )
{
DEBUG_CRASH( ("Commandbutton %s is a purchase science button without any science! Please add it.", command->getName().str() ) );
}
else if( command->getScienceVec()[0] == science )
{
commandButton->copyImagesFrom( command, TRUE );
commandButton->copyButtonTextFrom( command, FALSE, TRUE );
found = TRUE;
break;
}
}
}
}
}
}
}
}
}
}
}
// After Every change to the m_commandWIndows, we need to show fill in the missing blanks with the images
// removed from multiplayer branch
//showCommandMarkers();
//
// for objects that have a production exit interface, we may have a rally point set.
// if we do, we want to show that rally point in the world
//
ExitInterface *exit = obj->getObjectExitInterface();
if( exit )
{
//
// if a rally point is set, show the rally point, if we don't have it set hide any rally
// point we might have visible
//
showRallyPoint( exit->getRallyPoint() );
}
//
// 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
//
updateContextCommand();
}
//-------------------------------------------------------------------------------------------------
/** reset transport data */
//-------------------------------------------------------------------------------------------------
void ControlBar::resetContainData( void )
{
Int i;
for( i = 0; i < MAX_COMMANDS_PER_SET; i++ )
{
m_containData[ i ].control = NULL;
m_containData[ i ].objectID = INVALID_ID;
}
}
//-------------------------------------------------------------------------------------------------
/** reset the build queue data we use to die queue entires to control */
//-------------------------------------------------------------------------------------------------
void ControlBar::resetBuildQueueData( void )
{
Int i;
for( i = 0; i < MAX_BUILD_QUEUE_BUTTONS; i++ )
{
m_queueData[ i ].control = NULL;
m_queueData[ i ].type = PRODUCTION_INVALID;
m_queueData[ i ].productionID = PRODUCTIONID_INVALID;
m_queueData[ i ].upgradeToResearch = NULL;
}
}
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
void ControlBar::populateBuildQueue( Object *producer )
{
/// @todo srj -- remove hard-coding here, please
static const CommandButton *cancelUnitCommand = findCommandButton( "Command_CancelUnitCreate" );
/// @todo srj -- remove hard-coding here, please
static const CommandButton *cancelUpgradeCommand = findCommandButton( "Command_CancelUpgradeCreate" );
static NameKeyType buildQueueIDs[ MAX_BUILD_QUEUE_BUTTONS ];
static Bool idsInitialized = FALSE;
Int i;
// reset the build queue data
resetBuildQueueData();
// get name key ids for the build queue buttons
if( idsInitialized == FALSE )
{
AsciiString buttonName;
for( i = 0; i < MAX_BUILD_QUEUE_BUTTONS; i++ )
{
buttonName.format( "ControlBar.wnd:ButtonQueue%02d", i + 1 );
buildQueueIDs[ i ] = TheNameKeyGenerator->nameToKey( buttonName );
}
idsInitialized = TRUE;
}
// get window pointers to all the buttons for the build queue
for( i = 0; i < MAX_BUILD_QUEUE_BUTTONS; i++ )
{
// get window commented out cause I believe we already set this. We'll see in a few minutes
m_queueData[ i ].control = TheWindowManager->winGetWindowFromId( m_contextParent[ CP_BUILD_QUEUE ],
buildQueueIDs[ i ] );
// disable window by default
m_queueData[ i ].control->winEnable( FALSE );
//Clear the status because this button doesn't use it -- and if it's set, it'll
//become invisible meaning the image that was there will be showed.
m_queueData[ i ].control->winClearStatus( WIN_STATUS_USE_OVERLAY_STATES );
// set the text of the window to nothing by default
GadgetButtonSetText( m_queueData[ i ].control, L"" );
//Clear any potential veterancy rank, or else we'll see it when it's empty!
GadgetButtonDrawOverlayImage( m_queueData[ i ].control, NULL );
}
// step through each object being built and set the image data for the buttons
ProductionUpdateInterface *pu = producer->getProductionUpdateInterface();
if( pu == NULL )
return; // sanity
const ProductionEntry *production;
Int windowIndex = 0;
const Image *image;
for( production = pu->firstProduction();
production;
production = pu->nextProduction( production ) )
{
// don't go above how many queue windows we have
if( windowIndex >= MAX_BUILD_QUEUE_BUTTONS )
break; // exit for
// set the command into the queue button
if( production->getProductionType() == PRODUCTION_UNIT )
{
// set the control command
setControlCommand( m_queueData[ windowIndex ].control, cancelUnitCommand );
m_queueData[ windowIndex ].type = PRODUCTION_UNIT;
m_queueData[ windowIndex ].productionID = production->getProductionID();
// set the images
m_queueData[ windowIndex ].control->winEnable( TRUE );
m_queueData[ windowIndex ].control->winSetStatus( WIN_STATUS_USE_OVERLAY_STATES );
image = production->getProductionObject()->getButtonImage();
GadgetButtonSetEnabledImage( m_queueData[ windowIndex ].control, image );
//No longer used.
//image = TheMappedImageCollection->findImageByName( production->getProductionObject()->getInventoryImageName( INV_IMAGE_HILITE ) );
//GadgetButtonSetHiliteSelectedImage( m_queueData[ windowIndex ].control, image );
//image = TheMappedImageCollection->findImageByName( production->getProductionObject()->getInventoryImageName( INV_IMAGE_PUSHED ) );
//GadgetButtonSetHiliteImage( m_queueData[ windowIndex ].control, image );
//Show the veterancy rank of the object being constructed in the queue
const Image *image = calculateVeterancyOverlayForThing( production->getProductionObject() );
GadgetButtonDrawOverlayImage( m_queueData[ windowIndex ].control, image );
//
// note we're not setting a disabled image into the queue button ... when there is
// nothing in the queue we set the button to disabled, we want to leave the disabled
// queue button graphic we already have in place
//
// image = TheMappedImageCollection->findImageByName( production->getProductionObject()->getInventoryImageName( INV_IMAGE_DISABLED ) );
// GadgetButtonSetDisabledImage( m_queueData[ windowIndex ].control, image );
}
else
{
const UpgradeTemplate *ut = production->getProductionUpgrade();
// set the control command
setControlCommand( m_queueData[ windowIndex ].control, cancelUpgradeCommand );
m_queueData[ windowIndex ].type = PRODUCTION_UPGRADE;
m_queueData[ windowIndex ].upgradeToResearch = production->getProductionUpgrade();
// set the images
m_queueData[ windowIndex ].control->winEnable( TRUE );
m_queueData[ windowIndex ].control->winSetStatus( WIN_STATUS_USE_OVERLAY_STATES );
image = ut->getButtonImage();
GadgetButtonSetEnabledImage( m_queueData[ windowIndex ].control, image );
//No longer used
//image = TheMappedImageCollection->findImageByName( ut->getQueueImageName( UpgradeTemplate::UPGRADE_HILITE ) );
//GadgetButtonSetHiliteSelectedImage( m_queueData[ windowIndex ].control, image );
//image = TheMappedImageCollection->findImageByName( ut->getQueueImageName( UpgradeTemplate::UPGRADE_PUSHED ) );
//GadgetButtonSetHiliteImage( m_queueData[ windowIndex ].control, image );
//
// note we're not setting a disabled image into the queue button ... when there is
// nothing in the queue we set the button to disabled, we want to leave the disabled
// queue button graphic we already have in place
//
// image = TheMappedImageCollection->findImageByName( ut->getQueueImageName( UpgradeTemplate::UPGRADE_DISABLED ) );
// GadgetButtonSetDisabledImage( m_queueData[ windowIndex ].control, image );
}
// we have filled up this window now
windowIndex++;
}
//
// save the count of things being produced in the build queue, when it changes we will
// repopulate the queue to visually show the change
//
m_displayedQueueCount = pu->getProductionCount();
}
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
void ControlBar::updateContextCommand( void )
{
Object *obj = NULL;
Int i;
// get object
if( m_currentSelectedDrawable )
obj = m_currentSelectedDrawable->getObject();
//
// the contents of objects are ususally showed on the UI, when those contents change
// we always to update the UI
//
ContainModuleInterface *contain = obj ? obj->getContain() : NULL;
if( contain && contain->getContainMax() > 0 &&
m_lastRecordedInventoryCount != contain->getContainCount() )
{
// record this ast the last known number
m_lastRecordedInventoryCount = contain->getContainCount();
// re-evaluate the UI because something has changed
evaluateContextUI();
}
// get production update for those objects that have one
ProductionUpdateInterface *pu = obj ? obj->getProductionUpdateInterface() : NULL;
//
// when we have a production update, we show the build queue when there is actually
// something in the queue, otherwise we show the selection portrait for the object ... so if
// the queue is visible we need to check to see if we should hide it and show the portrait,
// and if the queue is hidden, we need to check and see if it should become shown
//
if( m_contextParent[ CP_BUILD_QUEUE ]->winIsHidden() == TRUE )
{
if( pu && pu->firstProduction() != NULL )
{
// don't show the portrait image
setPortraitByObject( NULL );
// show the build queue
m_contextParent[ CP_BUILD_QUEUE ]->winHide( FALSE );
populateBuildQueue( obj );
}
}
else
{
if( pu && pu->firstProduction() == NULL )
{
// hide the build queue
m_contextParent[ CP_BUILD_QUEUE ]->winHide( TRUE );
// show the portrait image
setPortraitByObject( obj );
}
}
// update a visible production queue
if( m_contextParent[ CP_BUILD_QUEUE ]->winIsHidden() == FALSE )
{
// when the build queue is enabled, the selected portrait cannot be shown
setPortraitByObject( NULL );
//
// when showing a production queue, when the production count changes of the producer
// object (the thing we have selected for the control bar) we will repopulate the
// windows to visually show the new production linup
//
if( pu )
{
// update the whole queue as necessary
if( pu->getProductionCount() != m_displayedQueueCount )
populateBuildQueue( obj );
//
// update the build percentage on the first thing (the thing that's being built)
// in the queue
//
const ProductionEntry *produce = pu->firstProduction();
if( produce )
{
static NameKeyType winID = TheNameKeyGenerator->nameToKey( "ControlBar.wnd:ButtonQueue01" );
GameWindow *win = TheWindowManager->winGetWindowFromId( m_contextParent[ CP_BUILD_QUEUE ], winID );
DEBUG_ASSERTCRASH( win, ("updateContextCommand: Unable to find first build queue button") );
// UnicodeString text;
//
// text.format( L"%.0f%%", produce->getPercentComplete() );
// GadgetButtonSetText( win, text );
GadgetButtonDrawInverseClock(win,produce->getPercentComplete(), m_buildUpClockColor);
}
}
}
// evaluate each command on whether or not it should be enabled
for( i = 0; i < MAX_COMMANDS_PER_SET; i++ )
{
GameWindow *win;
const CommandButton *command;
// our implementation doesn't necessarily make use of the max possible command buttons
if (! m_commandWindows[ i ]) continue;
// get the window
win = m_commandWindows[ i ];
// only consider commands for windows that are actually shown
//`tbd: fix the bug here, that is that if we don't change the unit, we won't attempt to show
// these.
if( win->winIsHidden() == TRUE )
continue;
// get the command from the control
command = (const CommandButton *)GadgetButtonGetData(win);
//command = (const CommandButton *)win->winGetUserData();
if( command == NULL )
continue;
// LORENZEN COMMENTED THIS OUT 8/11
// Reason: ExitCameos can be greyed out when the container object gets subdued
// // ignore transport/structure inventory commands, they are handled elsewhere
// if( command->getCommandType() == GUI_COMMAND_EXIT_CONTAINER )
// {
// win->winSetStatus( WIN_STATUS_ALWAYS_COLOR ); //Don't let these buttons render in grayscale ever!
// continue;
// }
// else
{
win->winClearStatus( WIN_STATUS_NOT_READY );
win->winClearStatus( WIN_STATUS_ALWAYS_COLOR );
}
// is the command available
CommandAvailability availability = getCommandAvailability( command, obj, win );
// enable/disable the window control
switch( availability )
{
case COMMAND_HIDDEN:
win->winHide( TRUE );
break;
case COMMAND_RESTRICTED:
win->winEnable( FALSE );
break;
case COMMAND_NOT_READY:
win->winEnable( FALSE );
win->winSetStatus( WIN_STATUS_NOT_READY );
break;
case COMMAND_CANT_AFFORD:
win->winEnable( FALSE );
win->winSetStatus( WIN_STATUS_ALWAYS_COLOR );
break;
default:
win->winEnable( TRUE );
break;
}
//Determine by the production type of this button, whether or not the created object
//will have a veterancy rank
if( command->getCommandType() != GUI_COMMAND_EXIT_CONTAINER )
{
//Already handled for contained members -- see ControlBar::populateButtonProc()
const Image *image = calculateVeterancyOverlayForThing( command->getThingTemplate() );
GadgetButtonDrawOverlayImage( win, image );
}
//
// for check-like commands we will keep the push button "pushed" or "unpushed" depending
// on the current running status of the command
//
if( BitIsSet( command->getOptions(), CHECK_LIKE ))
{
// sanity, check like commands should have windows that are check like as well
DEBUG_ASSERTCRASH( BitIsSet( win->winGetStatus(), WIN_STATUS_CHECK_LIKE ),
("updateContextCommand: Error, gadget window for command '%s' is not check-like!",
command->getName().str()) );
if( availability == COMMAND_ACTIVE )
GadgetCheckLikeButtonSetVisualCheck( win, TRUE );
else
GadgetCheckLikeButtonSetVisualCheck( win, FALSE );
}
}
// After Every change to the m_commandWIndows, we need to show fill in the missing blanks with the images
// removed from multiplayer branch
//showCommandMarkers();
// // if we have a build tooltip layout, update it with the new data.
// repopulateBuildTooltipLayout();
}
//-------------------------------------------------------------------------------------------------
const Image* ControlBar::calculateVeterancyOverlayForThing( const ThingTemplate *thingTemplate )
{
VeterancyLevel level = LEVEL_REGULAR;
if( !thingTemplate )
{
return NULL;
}
Player *player = ThePlayerList->getLocalPlayer();
if( !player )
{
return NULL;
}
//See if the thingTemplate has a VeterancyGainCreate
//This is HORROR CODE and needs to be optimized!
const VeterancyGainCreateModuleData *data = NULL;
AsciiString modName;
const ModuleInfo& mi = thingTemplate->getBehaviorModuleInfo();
for( Int modIdx = 0; modIdx < mi.getCount(); ++modIdx )
{
modName = mi.getNthName(modIdx);
if( !modName.compare( "VeterancyGainCreate" ) )
{
data = (const VeterancyGainCreateModuleData*)mi.getNthData( modIdx );
//It does, so see if the player has that upgrade
if( data )
{
//If no science is specified, he gets it automatically (or check the science).
if( data->m_scienceRequired == SCIENCE_INVALID || player->hasScience( data->m_scienceRequired ) )
{
//We do! So now check to see what the veterancy level would be.
if( data->m_startingLevel > level )
{
level = data->m_startingLevel;
}
}
}
}
}
//Return the appropriate image (including NULL if no veterancy levels)
switch( level )
{
case LEVEL_VETERAN:
return m_rankVeteranIcon;
case LEVEL_ELITE:
return m_rankEliteIcon;
case LEVEL_HEROIC:
return m_rankHeroicIcon;
}
return NULL;
}
//-------------------------------------------------------------------------------------------------
const Image* ControlBar::calculateVeterancyOverlayForObject( const Object *obj )
{
if( !obj )
{
return NULL;
}
VeterancyLevel level = obj->getVeterancyLevel();
//Return the appropriate image (including NULL if no veterancy levels)
switch( level )
{
case LEVEL_VETERAN:
return m_rankVeteranIcon;
case LEVEL_ELITE:
return m_rankEliteIcon;
case LEVEL_HEROIC:
return m_rankHeroicIcon;
}
return NULL;
}
//-------------------------------------------------------------------------------------------------
static Int getRappellerCount(Object* obj)
{
Int num = 0;
const ContainedItemsList* items = obj->getContain() ? obj->getContain()->getContainedItemsList() : NULL;
if (items)
{
for (ContainedItemsList::const_iterator it = items->begin(); it != items->end(); ++it )
{
if ((*it)->isKindOf(KINDOF_CAN_RAPPEL))
{
++num;
}
}