forked from TheSuperHackers/GeneralsGameCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInGameChat.cpp
More file actions
361 lines (310 loc) · 10.7 KB
/
InGameChat.cpp
File metadata and controls
361 lines (310 loc) · 10.7 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
/*
** 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: InGameChat.cpp ///////////////////////////////////////////////////////////////////////
// Author: Matthew D. Campbell - June 2002
// Desc: GUI callbacks for the in-game chat entry
///////////////////////////////////////////////////////////////////////////////////////////////////
// INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
#include "PreRTS.h" // This must go first in EVERY cpp file in the GameEngine
#include "Common/Player.h"
#include "Common/PlayerList.h"
#include "GameClient/DisconnectMenu.h"
#include "GameClient/GameWindow.h"
#include "GameClient/Gadget.h"
#include "GameClient/GadgetTextEntry.h"
#include "GameClient/GadgetStaticText.h"
#include "GameClient/GameClient.h"
#include "GameClient/GameText.h"
#include "GameClient/GUICallbacks.h"
#include "GameClient/InGameUI.h"
#include "GameClient/LanguageFilter.h"
#include "GameLogic/GameLogic.h"
#include "GameNetwork/GameInfo.h"
#include "GameNetwork/NetworkInterface.h"
static GameWindow *chatWindow = nullptr;
static GameWindow *chatTextEntry = nullptr;
static GameWindow *chatTypeStaticText = nullptr;
static UnicodeString s_savedChat;
static InGameChatType inGameChatType;
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
void ShowInGameChat( Bool immediate )
{
if (TheGameLogic->isInReplayGame())
return;
if (TheInGameUI->isQuitMenuVisible())
return;
if (TheDisconnectMenu && TheDisconnectMenu->isScreenVisible())
return;
if (chatWindow)
{
chatWindow->winHide(FALSE);
chatWindow->winEnable(TRUE);
chatTextEntry->winHide(FALSE);
chatTextEntry->winEnable(TRUE);
GadgetTextEntrySetText( chatTextEntry, s_savedChat );
s_savedChat.clear();
}
else
{
chatWindow = TheWindowManager->winCreateFromScript( "InGameChat.wnd" );
static NameKeyType textEntryChatID = TheNameKeyGenerator->nameToKey( "InGameChat.wnd:TextEntryChat" );
chatTextEntry = TheWindowManager->winGetWindowFromId( nullptr, textEntryChatID );
GadgetTextEntrySetText( chatTextEntry, UnicodeString::TheEmptyString );
static NameKeyType chatTypeStaticTextID = TheNameKeyGenerator->nameToKey( "InGameChat.wnd:StaticTextChatType" );
chatTypeStaticText = TheWindowManager->winGetWindowFromId( nullptr, chatTypeStaticTextID );
}
TheWindowManager->winSetFocus( chatTextEntry );
SetInGameChatType( INGAME_CHAT_EVERYONE );
}
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
void ResetInGameChat()
{
if(chatWindow)
TheWindowManager->winDestroy( chatWindow );
chatWindow = nullptr;
chatTextEntry = nullptr;
chatTypeStaticText = nullptr;
s_savedChat.clear();
}
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
void HideInGameChat( Bool immediate )
{
if (chatWindow)
{
s_savedChat = GadgetTextEntryGetText( chatTextEntry );
chatWindow->winHide(TRUE);
chatWindow->winEnable(FALSE);
chatTextEntry->winHide(TRUE);
chatTextEntry->winEnable(FALSE);
TheWindowManager->winSetFocus( nullptr );
}
TheWindowManager->winSetFocus( nullptr );
}
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
void SetInGameChatType( InGameChatType chatType )
{
inGameChatType = chatType;
if (chatTypeStaticText)
{
switch (inGameChatType)
{
case INGAME_CHAT_EVERYONE:
if (ThePlayerList->getLocalPlayer()->isPlayerActive())
GadgetStaticTextSetText( chatTypeStaticText, TheGameText->fetch("Chat:Everyone") );
else
GadgetStaticTextSetText( chatTypeStaticText, TheGameText->fetch("Chat:Observers") );
break;
case INGAME_CHAT_ALLIES:
GadgetStaticTextSetText( chatTypeStaticText, TheGameText->fetch("Chat:Allies") );
break;
case INGAME_CHAT_PLAYERS:
GadgetStaticTextSetText( chatTypeStaticText, TheGameText->fetch("Chat:Players") );
break;
}
}
}
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
Bool IsInGameChatActive() {
if (chatWindow != nullptr) {
if (chatWindow->winIsHidden() == FALSE) {
return TRUE;
}
}
return FALSE;
}
// Slash commands -------------------------------------------------------------------------
extern "C" {
int getQR2HostingStatus();
}
extern int isThreadHosting;
Bool handleInGameSlashCommands(UnicodeString uText)
{
AsciiString message;
message.translate(uText);
if (message.getCharAt(0) != '/')
{
return FALSE; // not a slash command
}
AsciiString remainder = message.str() + 1;
AsciiString token;
remainder.nextToken(&token);
token.toLower();
if (token == "host")
{
UnicodeString s;
s.format(L"Hosting qr2:%d thread:%d", getQR2HostingStatus(), isThreadHosting);
TheInGameUI->message(s);
return TRUE; // was a slash command
}
return FALSE; // not a slash command
}
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
void ToggleInGameChat( Bool immediate )
{
static Bool justHid = false;
if (justHid)
{
justHid = false;
return;
}
if (TheGameLogic->isInReplayGame())
return;
if (!TheGameInfo->isMultiPlayer() && TheGlobalData->m_netMinPlayers)
return;
if (chatWindow)
{
Bool show = chatWindow->winIsHidden();
if (show)
ShowInGameChat( immediate );
else
{
if (chatTextEntry)
{
// Send what is there, clear it out, and hide the window
UnicodeString msg = GadgetTextEntryGetText( chatTextEntry );
msg.trim();
if (!msg.isEmpty() && !handleInGameSlashCommands(msg))
{
const Player *localPlayer = ThePlayerList->getLocalPlayer();
AsciiString playerName;
Int playerMask = 0;
for (Int i=0; i<MAX_SLOTS; ++i)
{
playerName.format("player%d", i);
const Player *player = ThePlayerList->findPlayerWithNameKey( TheNameKeyGenerator->nameToKey( playerName ) );
if (player && localPlayer)
{
switch (inGameChatType)
{
case INGAME_CHAT_EVERYONE:
if (!TheGameInfo->getConstSlot(i)->isMuted())
playerMask |= (1<<i);
break;
case INGAME_CHAT_ALLIES:
if ( (player->getRelationship(localPlayer->getDefaultTeam()) == ALLIES &&
localPlayer->getRelationship(player->getDefaultTeam()) == ALLIES) || player==localPlayer )
playerMask |= (1<<i);
break;
case INGAME_CHAT_PLAYERS:
if ( player == localPlayer )
playerMask |= (1<<i);
break;
}
}
}
TheLanguageFilter->filterLine(msg);
TheNetwork->sendChat(msg, playerMask);
}
GadgetTextEntrySetText( chatTextEntry, UnicodeString::TheEmptyString );
HideInGameChat( immediate );
justHid = true;
}
}
}
else
{
ShowInGameChat( immediate );
}
}
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
WindowMsgHandledType InGameChatInput( GameWindow *window, UnsignedInt msg,
WindowMsgData mData1, WindowMsgData mData2 )
{
switch( msg )
{
// --------------------------------------------------------------------------------------------
case GWM_CHAR:
{
UnsignedByte key = mData1;
// UnsignedByte state = mData2;
switch( key )
{
// ----------------------------------------------------------------------------------------
case KEY_ESC:
{
HideInGameChat();
return MSG_HANDLED;
//return MSG_IGNORED;
}
}
return MSG_HANDLED;
}
}
return MSG_IGNORED;
}
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
WindowMsgHandledType InGameChatSystem( GameWindow *window, UnsignedInt msg,
WindowMsgData mData1, WindowMsgData mData2 )
{
switch( msg )
{
//---------------------------------------------------------------------------------------------
case GGM_FOCUS_CHANGE:
{
// Bool focus = (Bool) mData1;
//if (focus)
//TheWindowManager->winSetGrabWindow( chatTextEntry );
break;
}
//---------------------------------------------------------------------------------------------
case GWM_INPUT_FOCUS:
{
// if we're givin the opportunity to take the keyboard focus we must say we want it
if( mData1 == TRUE )
*(Bool *)mData2 = TRUE;
return MSG_HANDLED;
}
//---------------------------------------------------------------------------------------------
case GEM_EDIT_DONE:
{
ToggleInGameChat();
//HideInGameChat();
break;
}
//---------------------------------------------------------------------------------------------
case GBM_SELECTED:
{
GameWindow *control = (GameWindow *)mData1;
static NameKeyType buttonClearID = TheNameKeyGenerator->nameToKey( "InGameChat.wnd:ButtonClear" );
if (control && control->winGetWindowId() == buttonClearID)
{
if (chatTextEntry)
GadgetTextEntrySetText( chatTextEntry, UnicodeString::TheEmptyString );
s_savedChat.clear();
}
break;
}
//---------------------------------------------------------------------------------------------
default:
return MSG_IGNORED;
}
return MSG_HANDLED;
}