forked from electronicarts/CnC_Generals_Zero_Hour
-
Notifications
You must be signed in to change notification settings - Fork 189
Expand file tree
/
Copy pathControlBarCallback.cpp
More file actions
609 lines (509 loc) · 19.9 KB
/
ControlBarCallback.cpp
File metadata and controls
609 lines (509 loc) · 19.9 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
/*
** 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: ControlBarCallback.cpp ///////////////////////////////////////////////////////////////////
// Author: Colin Day - October 2001
// Desc: GUI Control bar at the bottom of the screen that houses the
// the build buttons, radar etc.
///////////////////////////////////////////////////////////////////////////////////////////////////
// INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
#include "PreRTS.h" // This must go first in EVERY cpp file in the GameEngine
#include "Common/GameUtility.h"
#include "Common/NameKeyGenerator.h"
#include "Common/Player.h"
#include "Common/PlayerList.h"
#include "Common/MessageStream.h"
#include "Common/ThingFactory.h"
#include "Common/ThingTemplate.h"
#include "Common/Radar.h"
#include "GameClient/AnimateWindowManager.h"
#include "GameClient/Drawable.h"
#include "GameClient/GameWindow.h"
#include "GameClient/Gadget.h"
#include "GameClient/GadgetTextEntry.h"
#include "GameClient/GameClient.h"
#include "GameClient/GUICallbacks.h"
#include "GameClient/InGameUI.h"
#include "GameClient/ControlBar.h"
#include "GameClient/GameWindowManager.h"
#include "GameClient/LanguageFilter.h"
#include "GameClient/CommandXlat.h"
#include "GameLogic/GameLogic.h"
#include "GameLogic/ScriptEngine.h"
//external declarations of the Gadgets the callbacks can use
WindowLayout *popupCommunicatorLayout = nullptr;
//-------------------------------------------------------------------------------------------------
/** Input procedure for the left HUD */
//-------------------------------------------------------------------------------------------------
WindowMsgHandledType LeftHUDInput( GameWindow *window, UnsignedInt msg,
WindowMsgData mData1, WindowMsgData mData2 )
{
//
// if the player doesn't have a radar, or the radar is hidden, and the radar is not being
// forced to on, we just eat input over the radar window
//
if( !rts::localPlayerHasRadar() )
return MSG_HANDLED;
// If the middle mouse button is depressed, then just let the message fall all the
// way back to the usual middle mouse button processing.
// jkmcd
if( TheMouse->getMouseStatus()->middleState == MBS_Down )
return MSG_IGNORED;
switch( msg )
{
/** @todo
This is wrong. The radar should be in the message stream, and eat all messages and propagate them
as a new message with the coords converted to world coords and the message flagged as being from
the radar. This would let all of the normal processing occur, and allow individual commands to easily
reject being used on the radar.
*/
// ------------------------------------------------------------------------
case GWM_NONE:
case GWM_MOUSE_ENTERING:
case GWM_MOUSE_LEAVING:
{
//
// consider changing the mouse cursor if we are not in the process of firing
// targeted "superweapons" which we can use the radar itself to fire
//
Bool targeting = FALSE;
const CommandButton *command = TheInGameUI->getGUICommand();
if( command
&& (command->getCommandType() == GUI_COMMAND_SPECIAL_POWER || command->getCommandType() == GUI_COMMAND_SPECIAL_POWER_FROM_SHORTCUT)
&& BitIsSet( command->getOptions(), NEED_TARGET_POS ) )
targeting = TRUE;
if( targeting == FALSE )
{
const DrawableList *drawableList = TheInGameUI->getAllSelectedLocalDrawables();
Mouse::MouseCursor cur = Mouse::ARROW;
if (!(drawableList->empty() || msg == GWM_MOUSE_LEAVING))
{
if (command && command->getCommandType() == GUI_COMMAND_ATTACK_MOVE)
{
cur = Mouse::ATTACKMOVETO;
}
else
{
cur = Mouse::MOVETO;
}
}
// Groovy
TheMouse->setCursor(cur);
}
return MSG_HANDLED;
}
// --------------------------------------------------------------------------------------------
case GWM_MOUSE_POS:
{
// get mouse position
ICoord2D mouse;
mouse.x = mData1 & 0xFFFF;
mouse.y = mData1 >> 16;
// get window screen position
ICoord2D screenPos;
window->winGetScreenPosition( &screenPos.x, &screenPos.y );
// set mouse position to be relative to this window
mouse.x -= screenPos.x;
mouse.y -= screenPos.y;
// is the mouse in the radar window
ICoord2D radar;
if( TheRadar->localPixelToRadar( &mouse, &radar ) )
{
/*
//
// this is an example piece of code to find the object under the pixel position
// of the radar ... should we in the future wish to allow commands to be executed
// on objects through the radar. note tho that this is extremely hard to do because
// the pixels on the radar are very small and it's hard to do accurate targeting
//
Object *obj = TheRadar->objectUnderRadarPixel( &mouse );
UnicodeString msg;
if( obj )
msg.format( L"Object under mouse on radar '%S'(%d)",
obj->getTemplate()->getName().str(), obj->getID() );
else
msg.format( L"Mouse (%d,%d) in Radar window L(%d,%d)", mouse.x, mouse.y, radar.x, radar.y );
TheInGameUI->message( msg );
*/
// keep the cursor for any context commands
const CommandButton *command = TheInGameUI->getGUICommand();
if( command
&& (command->getCommandType() == GUI_COMMAND_SPECIAL_POWER || command->getCommandType() == GUI_COMMAND_SPECIAL_POWER_FROM_SHORTCUT)
&& BitIsSet( command->getOptions(), NEED_TARGET_POS ) )
{
Int index = TheMouse->getCursorIndex( command->getCursorName() );
if( index != Mouse::INVALID_MOUSE_CURSOR )
TheMouse->setCursor( (Mouse::MouseCursor)index );
else
TheMouse->setCursor( Mouse::CROSS );
}
else
{
// Else we are not super targeting, so we have to try to refresh the move cursor.
// We can't just do this on Enter and Exit, because hotkeys allow state to change
// while we are in the radar.
const DrawableList *drawableList = TheInGameUI->getAllSelectedLocalDrawables();
Mouse::MouseCursor cur = Mouse::ARROW;
if (!(drawableList->empty() || msg == GWM_MOUSE_LEAVING))
{
if (command && command->getCommandType() == GUI_COMMAND_ATTACK_MOVE)
{
cur = Mouse::ATTACKMOVETO;
}
else
{
cur = Mouse::MOVETO;
}
}
// Groovy
TheMouse->setCursor(cur);
}
}
break;
}
// ------------------------------------------------------------------------
case GWM_RIGHT_UP:// Here to eat
case GWM_LEFT_UP:// Here to eat
break;
case GWM_RIGHT_DOWN:
case GWM_LEFT_DOWN:
{
ICoord2D mouse;
ICoord2D radar;
ICoord2D size;
ICoord2D screenPos;
Coord3D world;
// get window size
window->winGetSize( &size.x, &size.y );
// get mouse position
mouse.x = mData1 & 0xFFFF;
mouse.y = mData1 >> 16;
// get window screen position
window->winGetScreenPosition( &screenPos.x, &screenPos.y );
// set mouse position to be relative to this window
mouse.x -= screenPos.x;
mouse.y -= screenPos.y;
//
// translate mouse position to radar position ... we know that the mouse
// location given to us here is relative to the HUD window, which is
// completely drawn with the radar ... so it's just a translation from
// our window size we're drawing into to the radar cell size
//
if( TheRadar->localPixelToRadar( &mouse, &radar ) &&
TheRadar->radarToWorld( &radar, &world ) )
{
// No drawables, or a right click automatically means its a look at.
// Having drawables and being in attack move mode means that we should attack move.
// Having drawables and not being in attack move mode means that we should move.
const DrawableList *drawableList = TheInGameUI->getAllSelectedLocalDrawables(); // locally-owned only
// see if the user wants to move the tactical view
if ( drawableList->empty()
|| (! TheGlobalData->m_useAlternateMouse && msg == GWM_RIGHT_DOWN)
|| (TheGlobalData->m_useAlternateMouse && msg == GWM_LEFT_DOWN) )
{
TheTacticalView->userLookAt( &world );
break;
}
// evaluate any special powers that can be executed from the radar
const CommandButton *command = TheInGameUI->getGUICommand();
if( command
&& (command->getCommandType() == GUI_COMMAND_SPECIAL_POWER || command->getCommandType() == GUI_COMMAND_SPECIAL_POWER_FROM_SHORTCUT)
&& BitIsSet( command->getOptions(), NEED_TARGET_POS )
)
{
// do the command
TheGameClient->evaluateContextCommand( nullptr, &world, CommandTranslator::DO_COMMAND );
}
else if( command && command->getCommandType() == GUI_COMMAND_ATTACK_MOVE)
{
// Attack move has changed from a modifier to a command, so it moves up here.
GameMessage *msg = TheMessageStream->appendMessage( GameMessage::MSG_DO_ATTACKMOVETO );
msg->appendLocationArgument( world );
// Play the unit voice response
pickAndPlayUnitVoiceResponse(TheInGameUI->getAllSelectedDrawables(), GameMessage::MSG_DO_ATTACKMOVETO);
}
else
{
GameMessage *newMsg = nullptr;
// Do the superweapon stuff here, before issuing these other messages
// GS Leaving commented out to show that isInAttackMoveToMode is NEVER SET. It's a command now, not a modifier.
// if (TheInGameUI->isInAttackMoveToMode())
// {
// newMsg = TheMessageStream->appendMessage(GameMessage::MSG_DO_ATTACKMOVETO);
// newMsg->appendLocationArgument(world);
// // Play the unit voice response
// pickAndPlayUnitVoiceResponse(drawableList, GameMessage::MSG_DO_ATTACKMOVETO);
// break;
// }
newMsg = TheMessageStream->appendMessage(GameMessage::MSG_DO_MOVETO);
newMsg->appendLocationArgument(world);
// Play the unit voice response
pickAndPlayUnitVoiceResponse(drawableList, GameMessage::MSG_DO_MOVETO);
}
}
break;
}
// ------------------------------------------------------------------------
default:
return MSG_IGNORED;
}
TheInGameUI->clearAttackMoveToMode();
return MSG_HANDLED;
}
//-------------------------------------------------------------------------------------------------
/** Input procedure for the control bar */
//-------------------------------------------------------------------------------------------------
WindowMsgHandledType ControlBarInput( GameWindow *window, UnsignedInt msg,
WindowMsgData mData1, WindowMsgData mData2 )
{
return MSG_IGNORED;
}
void ToggleQuitMenu();
//-------------------------------------------------------------------------------------------------
/** System callback for the control bar parent */
//-------------------------------------------------------------------------------------------------
WindowMsgHandledType ControlBarSystem( GameWindow *window, UnsignedInt msg,
WindowMsgData mData1, WindowMsgData mData2 )
{
static NameKeyType buttonCommunicator = NAMEKEY_INVALID;
if(TheScriptEngine && TheScriptEngine->isGameEnding())
return MSG_IGNORED;
switch( msg )
{
// --------------------------------------------------------------------------------------------
case GWM_CREATE:
{
// get ids for our children controls
buttonCommunicator = TheNameKeyGenerator->nameToKey( "ControlBar.wnd:PopupCommunicator" );
break;
}
//---------------------------------------------------------------------------------------------
case GBM_MOUSE_ENTERING:
case GBM_MOUSE_LEAVING:
{
GameWindow *control = (GameWindow *)mData1;
TheControlBar->processContextSensitiveButtonTransition( control, (GadgetGameMessage)msg);
break;
}
//---------------------------------------------------------------------------------------------
case GBM_SELECTED:
case GBM_SELECTED_RIGHT:
{
GameWindow *control = (GameWindow *)mData1;
static NameKeyType beaconPlacementButtonID = NAMEKEY("ControlBar.wnd:ButtonPlaceBeacon");
static NameKeyType beaconDeleteButtonID = NAMEKEY("ControlBar.wnd:ButtonDeleteBeacon");
static NameKeyType beaconClearTextButtonID = NAMEKEY("ControlBar.wnd:ButtonClearBeaconText");
static NameKeyType beaconGeneralButtonID = NAMEKEY("ControlBar.wnd:ButtonGeneral");
// static NameKeyType buttonSmallID = NAMEKEY("ControlBar.wnd:ButtonSmall");
// static NameKeyType buttonMediumID = NAMEKEY("ControlBar.wnd:ButtonMedium");
static NameKeyType buttonLargeID = NAMEKEY("ControlBar.wnd:ButtonLarge");
static NameKeyType buttonOptions = NAMEKEY("ControlBar.wnd:ButtonOptions");
static NameKeyType buttonIdleWorker = NAMEKEY("ControlBar.wnd:ButtonIdleWorker");
Int controlID = control->winGetWindowId();
if( controlID == buttonCommunicator )
{
ToggleDiplomacy(FALSE);
}
else if( controlID == beaconPlacementButtonID && TheGameLogic->isInMultiplayerGame() &&
ThePlayerList->getLocalPlayer()->isPlayerActive())
{
const CommandButton *commandButton = TheControlBar->findCommandButton( "Command_PlaceBeacon" );
TheInGameUI->setGUICommand( commandButton );
}
else if( controlID == beaconDeleteButtonID && TheGameLogic->isInMultiplayerGame() )
{
TheMessageStream->appendMessage( GameMessage::MSG_REMOVE_BEACON );
}
else if( controlID == beaconClearTextButtonID && TheGameLogic->isInMultiplayerGame() )
{
static NameKeyType textID = NAMEKEY("ControlBar.wnd:EditBeaconText");
GameWindow *win = TheWindowManager->winGetWindowFromId(nullptr, textID);
if (win)
{
GadgetTextEntrySetText( win, UnicodeString::TheEmptyString );
}
}
else if( controlID == beaconGeneralButtonID)
{
HideQuitMenu();
TheControlBar->togglePurchaseScience();
}
//else if( controlID == buttonSmallID)
// {
// TheControlBar->switchControlBarStage( CONTROL_BAR_STAGE_LOW );
// }
// else if( controlID == buttonMediumID)
// {
// TheControlBar->switchControlBarStage( CONTROL_BAR_STAGE_SQUISHED );
// }
else if( controlID == buttonLargeID)
{
TheControlBar->toggleControlBarStage();
}
else if( controlID == buttonOptions)
{
ToggleQuitMenu();
}
else if( controlID == buttonIdleWorker)
{
HideQuitMenu();
TheInGameUI->selectNextIdleWorker();
}
else
{
//
// all buttons from all the context sensitive user interface windows are part of the
// control bar, send the button processing that way
//
TheControlBar->processContextSensitiveButtonClick( control, (GadgetGameMessage)msg );
}
break;
}
//---------------------------------------------------------------------------------------------
case GEM_EDIT_DONE:
{
GameWindow *control = (GameWindow *)mData1;
Int controlID = control->winGetWindowId();
static NameKeyType textID = NAMEKEY("ControlBar.wnd:EditBeaconText");
if (controlID == textID)
{
// set beacon text
if (TheInGameUI->getSelectCount() == 1)
{
GameMessage *msg = TheMessageStream->appendMessage( GameMessage::MSG_SET_BEACON_TEXT );
UnicodeString newText = GadgetTextEntryGetText( control );
TheLanguageFilter->filterLine(newText);
const WideChar * c = newText.str();
while ( c && *c )
{
msg->appendWideCharArgument( *c++ );
}
msg->appendWideCharArgument( L'\0' ); // trailing null terminator
}
}
break;
}
//---------------------------------------------------------------------------------------------
default:
return MSG_IGNORED;
}
return MSG_HANDLED;
}
extern void showReplayControls();
extern void hideReplayControls();
extern void toggleReplayControls();
//-------------------------------------------------------------------------------------------------
/** Force the control bar to be shown */
//-------------------------------------------------------------------------------------------------
void ShowControlBar( Bool immediate )
{
if (!TheWindowManager || !TheControlBar)
return;
showReplayControls();
TheControlBar->showSpecialPowerShortcut();
Int id = (Int)TheNameKeyGenerator->nameToKey("ControlBar.wnd:ControlBarParent");
GameWindow *window = TheWindowManager->winGetWindowFromId(nullptr, id);
if (window)
{
TheControlBar->switchControlBarStage(CONTROL_BAR_STAGE_DEFAULT);
TheControlBar->setScaledViewportHeight();
if (TheControlBar->m_animateWindowManager && !immediate)
{
TheControlBar->m_animateWindowManager->reset();
//TheControlBar->m_animateWindowManager->registerGameWindow(window, WIN_ANIMATION_SLIDE_BOTTOM_TIMED, TRUE, 1000, 0);
TheControlBar->m_animateWindowManager->registerGameWindow(window, WIN_ANIMATION_SLIDE_BOTTOM, TRUE, 500, 0);
TheControlBar->animateSpecialPowerShortcut(TRUE);
}
window->winHide(FALSE);
}
// We want to get everything recalced since this is a major state change.
TheControlBar->markUIDirty();
}
//-------------------------------------------------------------------------------------------------
/** Force the control bar to be hidden */
//-------------------------------------------------------------------------------------------------
void HideControlBar( Bool immediate )
{
if (!TheWindowManager || !TheControlBar)
return;
hideReplayControls();
TheControlBar->hideSpecialPowerShortcut();
Int id = (Int)TheNameKeyGenerator->nameToKey("ControlBar.wnd:ControlBarParent");
GameWindow *window = TheWindowManager->winGetWindowFromId(nullptr, id);
if (window)
{
#ifdef SLIDE_LETTERBOX
TheControlBar->setScaledViewportHeight();
#else
TheControlBar->setFullViewportHeight();
#endif
if (immediate)
{
window->winHide(TRUE);
}
}
if (TheControlBar->m_animateWindowManager && !immediate)
{
TheControlBar->m_animateWindowManager->reverseAnimateWindow();
TheControlBar->animateSpecialPowerShortcut(FALSE);
}
//Always get rid of the purchase science screen!
TheControlBar->hidePurchaseScience();
}
//-------------------------------------------------------------------------------------------------
/** Toggle the control bar on or off */
//-------------------------------------------------------------------------------------------------
void ToggleControlBar( Bool immediate )
{
if (!TheWindowManager || !TheControlBar)
return;
toggleReplayControls();
Int id = (Int)TheNameKeyGenerator->nameToKey("ControlBar.wnd:ControlBarParent");
GameWindow *window = TheWindowManager->winGetWindowFromId(nullptr, id);
if (window)
{
if (window->winIsHidden())
{
TheControlBar->showSpecialPowerShortcut();
//now hidden, we're making it visible again so shrink viewport under the window
TheControlBar->setScaledViewportHeight();
window->winHide(FALSE);
TheControlBar->switchControlBarStage(CONTROL_BAR_STAGE_DEFAULT);
if (TheControlBar->m_animateWindowManager && !immediate)
{
TheControlBar->m_animateWindowManager->reset();
//TheControlBar->m_animateWindowManager->registerGameWindow(window, WIN_ANIMATION_SLIDE_BOTTOM_TIMED, FALSE, 500, 0);
TheControlBar->m_animateWindowManager->registerGameWindow(window, WIN_ANIMATION_SLIDE_BOTTOM, TRUE, 500, 0);
TheControlBar->animateSpecialPowerShortcut(TRUE);
}
}
else
{
TheControlBar->hideSpecialPowerShortcut();
TheControlBar->setFullViewportHeight();
window->winHide(TRUE);
}
}
}
//-------------------------------------------------------------------------------------------------
/** Resize the control bar */
//-------------------------------------------------------------------------------------------------