forked from 1dot13/source
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MPConnectScreen.cpp
551 lines (427 loc) · 14.2 KB
/
MPConnectScreen.cpp
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
#include "Types.h"
#include "MPConnectScreen.h"
#include "GameSettings.h"
#include "Utilities.h"
#include "wCheck.h"
#include "Font Control.h"
#include "WordWrap.h"
#include "Render Dirty.h"
#include "Input.h"
#include "Options Screen.h"
#include "English.h"
#include "Sysutil.h"
#include "Fade Screen.h"
#include "Cursor Control.h"
#include "Music Control.h"
#include "cursors.h"
#include "Text.h"
#include "Text Input.h"
#include "Soldier Profile.h"
#include "Animated ProgressBar.h"
#include "mainmenuscreen.h"
#include "gameloop.h"
#include "Game Init.h"
#include "connect.h"
#include "network.h" // for client name
#include "message.h"
#include "init.h"
#include "xml.h"
////////////////////////////////////////////
//
// Global Defines
//
///////////////////////////////////////////
#define MPC_TITLE_FONT FONT14ARIAL//FONT16ARIAL
#define MPC_TITLE_COLOR FONT_MCOLOR_WHITE
#define MPC_SUBHEADING_FONT FONT12ARIAL//FONT16ARIAL
#define MPC_SUBHEADING_COLOR FONT_MCOLOR_WHITE
//buttons
#define MPC_BTN_CANCEL_X iScreenWidthOffset + ((320 - 115) / 2)
#define MPC_BTN_CANCEL_Y iScreenHeightOffset + SCREEN_HEIGHT - 50
//main title
#define MPC_MAIN_TITLE_X 0
#define MPC_MAIN_TITLE_Y iScreenHeightOffset + 10
#define MPC_MAIN_TITLE_WIDTH SCREEN_WIDTH
//subtitle
#define MPC_SUBHEADING_X 0
#define MPC_SUBHEADING_Y MPC_MAIN_TITLE_Y + 30
#define MPC_SUBHEADING_WIDTH SCREEN_WIDTH
//help
#define MPC_HELP_X 0
#define MPC_HELP_Y MPC_SUBHEADING_Y + 30
#define MPC_HELP_WIDTH SCREEN_WIDTH
////////////////////////////////////////////
//
// Global Variables
//
///////////////////////////////////////////
BOOLEAN gfMPCScreenEntry = TRUE;
BOOLEAN gfMPCScreenExit = FALSE;
BOOLEAN gfReRenderMPCScreen=TRUE;
BOOLEAN gfMPCButtonsAllocated = FALSE;
BOOLEAN gfMPConnectScreenCanContinue = FALSE;
//enum for different states of screen
enum
{
MPC_NOTHING,
MPC_CANCEL,
MPC_CONTINUE,
};
UINT8 gubMPCScreenHandler=MPC_NOTHING; // State changer for HandleMPCNScreen()
UINT32 gubMPCExitScreen = MP_CONNECT_SCREEN; // The screen that is in control next iteration of the game_loop
UINT8 loadscreenID = 0;
////////////////////////////////////////////
//
// Screen Controls
//
///////////////////////////////////////////
// Cancel Button
void BtnMPCCancelCallback(GUI_BUTTON *btn,INT32 reason);
UINT32 guiMPCCancelButton;
INT32 giMPCCancelBtnImage;
UINT32 guiMPCMainBackGroundImage;
// Message Box handle
INT8 giMPCMessageBox = -1;
// connect screen message
CHAR16 gszConnectHeadingMsg[512];
CHAR16 gszConnectSubMsg[512];
////////////////////////////////////////////
//
// Local Function Prototypes
//
///////////////////////////////////////////
extern void ClearMainMenu();
BOOLEAN EnterMPCScreen();
BOOLEAN ExitMPCScreen();
void HandleMPCScreen();
BOOLEAN RenderMPCScreen();
void GetMPCScreenUserInput();
void DoneFadeOutForExitMPCScreen( void );
void DoneFadeInForExitMPCScreen( void );
void CheckForContinue();
UINT32 MPConnectScreenInit( void )
{
return (1);
}
UINT32 MPConnectScreenHandle( void )
{
StartFrameBufferRender();
RestoreBackgroundRects( );
if( gfMPCScreenEntry )
{
// PauseGame();
EnterMPCScreen();
gfMPCScreenEntry = FALSE;
gfMPCScreenExit = FALSE;
InvalidateRegion( 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT );
}
// add scrolling string log
ScrollString( );
GetMPCScreenUserInput();
// connect to the server
NetworkAutoStart();
// Check if we need to leave this screen
CheckForContinue();
HandleMPCScreen();
// draw chat texts
ExecuteVideoOverlays( );
SaveBackgroundRects();
//InvalidateScreen();
ExecuteBaseDirtyRectQueue();
EndFrameBufferRender();
// handle fades in and out
if ( HandleFadeOutCallback( ) )
{
ClearMainMenu();
return( gubMPCExitScreen );
}
if ( HandleBeginFadeOut( gubMPCExitScreen ) )
{
return( gubMPCExitScreen );
}
if ( HandleFadeInCallback( ) )
{
// Re-render the scene!
RenderMPCScreen();
}
if ( HandleBeginFadeIn( gubMPCExitScreen ) )
{
}
if( gfMPCScreenExit ) // we are exiting this screen
{
ExitMPCScreen(); // perform destruction
}
return( gubMPCExitScreen );
} // end MPScoreScreenHandle()
UINT32 MPConnectScreenShutdown( void )
{
return( 1 );
}
BOOLEAN EnterMPCScreen()
{
// make sure only chat messages show up on connect screen
ClearTacticalMessageQueue( );
SetTacticalMessageFilter( MSG_CHAT );
gfMPConnectScreenCanContinue = FALSE;
VOBJECT_DESC VObjectDesc;
if( gfMPCButtonsAllocated )
return( TRUE );
SetCurrentCursorFromDatabase( CURSOR_NORMAL );
// load the Main trade screen backgroiund image
VObjectDesc.fCreateFlags=VOBJECT_CREATE_FROMFILE;
if (iResolution >= _640x480 && iResolution < _800x600)
FilenameForBPP("INTERFACE\\MPConnect.sti",VObjectDesc.ImageFile);
else if (iResolution < _1024x768)
FilenameForBPP("INTERFACE\\MPConnect_800x600.sti",VObjectDesc.ImageFile);
else
FilenameForBPP("INTERFACE\\MPConnect_1024x768.sti", VObjectDesc.ImageFile);
CHECKF(AddVideoObject(&VObjectDesc, &guiMPCMainBackGroundImage ));
CreateLoadingScreenProgressBar(TRUE);
// default to red connecting color
SetProgressBarColor(0,150,0,0);
SetRelativeStartAndEndPercentage(0,0,100,L"");
//Cancel button
/*giMPCCancelBtnImage = LoadButtonImage("INTERFACE\\PreferencesButtons.sti", -1,0,-1,2,-1 );
guiMPCCancelButton = CreateIconAndTextButton( giMPCCancelBtnImage, gzMPCScreenText[MPC_CANCEL_TEXT], OPT_BUTTON_FONT,
OPT_BUTTON_ON_COLOR, DEFAULT_SHADOW,
OPT_BUTTON_OFF_COLOR, DEFAULT_SHADOW,
TEXT_CJUSTIFIED,
MPC_BTN_CANCEL_X, MPC_BTN_CANCEL_Y, BUTTON_TOGGLE, MSYS_PRIORITY_HIGH,
DEFAULT_MOVE_CALLBACK, BtnMPCCancelCallback);
SpecifyButtonSoundScheme( guiMPCCancelButton, BUTTON_SOUND_SCHEME_BIGSWITCH3 );
SpecifyDisabledButtonStyle( guiMPCCancelButton, DISABLED_STYLE_NONE );*/
//Reset the exit screen - screen the main game loop will call next iteration
gubMPCExitScreen = MP_CONNECT_SCREEN;
//REnder the screen once so we can blt ot to ths save buffer
RenderMPCScreen();
BlitBufferToBuffer(guiRENDERBUFFER, guiSAVEBUFFER, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT );
gfMPCButtonsAllocated = TRUE;
return( TRUE );
} // End of EnterMPSScreen()
BOOLEAN ExitMPCScreen()
{
RemoveTacticalMessageFilter();
if( !gfMPCButtonsAllocated )
return( TRUE );
//Delete the main options screen background
DeleteVideoObjectFromIndex( guiMPCMainBackGroundImage );
RemoveProgressBar(0);
//RemoveButton( guiMPCCancelButton );
//UnloadButtonImage( giMPCCancelBtnImage );
// exit text input mode in this screen and clean up text boxes
//KillAllTextInputModes();
SetTextInputCursor( CURSOR_IBEAM );
gfMPCButtonsAllocated = FALSE;
//If we are starting the game stop playing the music
if( gubMPCScreenHandler == MPC_CONTINUE )
SetMusicMode( MUSIC_NONE );
gfMPCScreenExit = FALSE;
gfMPCScreenEntry = TRUE;
return( TRUE );
} // End of ExitMPJScreen()
void HandleMPCScreen()
{
if( gubMPCScreenHandler != MPC_NOTHING )
{
switch( gubMPCScreenHandler )
{
case MPC_CANCEL:
gubMPCExitScreen = MP_JOIN_SCREEN;
gfMPCScreenExit = TRUE;
// disconnect the client
client_disconnect();
break;
case MPC_CONTINUE:
{
//if we are already fading out, get out of here
if( gFadeOutDoneCallback != DoneFadeOutForExitMPCScreen )
{
//Disable the ok button
DisableButton( guiMPCCancelButton );
gFadeOutDoneCallback = DoneFadeOutForExitMPCScreen;
FadeOutNextFrame( );
}
break;
}
}
gubMPCScreenHandler = MPC_NOTHING;
}
if( gfReRenderMPCScreen )
{
RenderMPCScreen();
gfReRenderMPCScreen = FALSE;
}
} // end of HandleMPCScreen
BOOLEAN RenderMPCScreen()
{
HVOBJECT hPixHandle;
//Get the main background screen graphic and blt it
GetVideoObject(&hPixHandle, guiMPCMainBackGroundImage );
BltVideoObject(FRAME_BUFFER, hPixHandle, 0,(SCREEN_WIDTH - xResSize)/2,(SCREEN_HEIGHT - yResSize)/2, VO_BLT_SRCTRANSPARENCY,NULL);
//Shade the background
//ShadowVideoSurfaceRect( FRAME_BUFFER, iScreenWidthOffset, iScreenHeightOffset, iScreenWidthOffset + 640, iScreenHeightOffset + 480 );
UINT8 iProgress = 0;
if (is_connecting)
{
iProgress = (UINT8)(100 * (float)((MAX_CONNECT_RETRIES-(float)giNumTries)/MAX_CONNECT_RETRIES));
SetProgressBarColor(0,150,0,0);
SetConnectScreenHeadingW(gzMPCScreenText[ MPC_CONNECTING_TEXT ]);
}
else if (is_connected)
{
if (!recieved_settings && !recieved_transfer_settings)
{
//Display the title
SetConnectScreenHeadingW( gzMPCScreenText[ MPC_GETSETTINGS_TEXT ]);
}
else
{
if (serverSyncClientsDirectory==1)
{
SetConnectScreenHeadingW( gzMPCScreenText[ MPC_DOWNLOADING_TEXT ]);
SetProgressBarColor(0,0,0,150);
iProgress = client_progress[CLIENT_NUM-1];
}
else
{
SetConnectScreenHeadingW( gzMPCScreenText[ MPC_READY_TEXT ] );
}
}
}
//Display the title
DrawTextToScreen( gszConnectHeadingMsg, MPC_MAIN_TITLE_X, MPC_MAIN_TITLE_Y, MPC_MAIN_TITLE_WIDTH, MPC_TITLE_FONT, MPC_TITLE_COLOR, FONT_MCOLOR_BLACK, FALSE, CENTER_JUSTIFIED );
InvalidateRegion(MPC_MAIN_TITLE_X,MPC_MAIN_TITLE_Y,MPC_MAIN_TITLE_WIDTH,MPC_MAIN_TITLE_Y+20);
//Display the subheading
DrawTextToScreen( gszConnectSubMsg, MPC_SUBHEADING_X, MPC_SUBHEADING_Y, MPC_SUBHEADING_WIDTH, MPC_SUBHEADING_FONT, MPC_SUBHEADING_COLOR, FONT_MCOLOR_BLACK, FALSE, CENTER_JUSTIFIED );
InvalidateRegion(MPC_SUBHEADING_X,MPC_SUBHEADING_Y,MPC_MAIN_TITLE_WIDTH,MPC_SUBHEADING_Y+20);
//Display the help text
DrawTextToScreen( (is_connected && recieved_settings ? gzMPCScreenText[ MPC_HELP1_TEXT ] : gzMPCScreenText[MPC_HELP2_TEXT] ), MPC_HELP_X, MPC_HELP_Y, MPC_HELP_WIDTH, MPC_SUBHEADING_FONT, MPC_SUBHEADING_COLOR, FONT_MCOLOR_BLACK, FALSE, CENTER_JUSTIFIED );
InvalidateRegion(MPC_HELP_X,MPC_HELP_Y,MPC_HELP_WIDTH,MPC_HELP_Y+20);
SetProgressBarRenderBuffer(0,FRAME_BUFFER);
RenderProgressBar(0,iProgress);
return( TRUE );
} // end of RenderMPCScreen()
void GetMPCScreenUserInput()
{
InputAtom Event;
// POINT MousePos;
// GetCursorPos(&MousePos);
while (DequeueSpecificEvent(&Event, KEY_DOWN|KEY_UP|KEY_REPEAT))
{
// check if this event is swallowed by text input, otherwise process key
if( Event.usEvent == KEY_DOWN )
{
switch( Event.usParam )
{
case ESC:
//Exit out of the screen
gubMPCScreenHandler = MPC_CANCEL;
break;
case 'y':
if (is_connected && recieved_settings)
OpenChatMsgBox();
break;
}
}
}
} // end of GetMPCScreenUserInput()
void DoneFadeOutForExitMPCScreen( void )
{
// ------------------------------------------
// Now Initialize the client again with all the files from the "_MULTIPLAYER" profile!!!
LoadExternalGameplayData(TABLEDATA_DIRECTORY, true);
LoadAllExternalText();
InitDependingGameStyleOptions();
InitNewGame(false);
// Overwrite some client settings with values from the server (cash, ...)
reapplySETTINGS();
// ------------------------------------------
gubMPCExitScreen = MAP_SCREEN;
ExitMPCScreen(); // cleanup please, if we called a fadeout then we didnt do it above
SetCurrentCursorFromDatabase( VIDEO_NO_CURSOR );
}
void DoneFadeInForExitMPCScreen( void )
{
SetCurrentCursorFromDatabase( VIDEO_NO_CURSOR );
}
void BtnMPCCancelCallback(GUI_BUTTON *btn,INT32 reason)
{
if(reason & MSYS_CALLBACK_REASON_LBUTTON_DWN )
{
btn->uiFlags |= BUTTON_CLICKED_ON;
InvalidateRegion(btn->Area.RegionTopLeftX, btn->Area.RegionTopLeftY, btn->Area.RegionBottomRightX, btn->Area.RegionBottomRightY);
}
if(reason & MSYS_CALLBACK_REASON_LBUTTON_UP )
{
btn->uiFlags &= (~BUTTON_CLICKED_ON );
gubMPCScreenHandler = MPC_CANCEL;
InvalidateRegion(btn->Area.RegionTopLeftX, btn->Area.RegionTopLeftY, btn->Area.RegionBottomRightX, btn->Area.RegionBottomRightY);
}
}
void SetConnectScreenHeadingW( STR16 cmsg )
{
wcscpy(gszConnectHeadingMsg,cmsg);
gfReRenderMPCScreen=TRUE;
}
void SetConnectScreenHeadingA( const char* cmsg )
{
CHAR16 converted[512];
MultiByteToWideChar( CP_UTF8, 0, cmsg, -1, (LPWSTR)converted, 512);
SetConnectScreenHeadingW( converted );
}
void SetConnectScreenSubMessageW( STR16 cmsg )
{
wcscpy(gszConnectSubMsg,cmsg);
gfReRenderMPCScreen=TRUE;
}
void SetConnectScreenSubMessageA( const char* cmsg )
{
CHAR16 converted[512];
MultiByteToWideChar( CP_UTF8, 0, cmsg, -1, (LPWSTR)converted, 512);
SetConnectScreenSubMessageW( converted );
}
void CheckForContinue()
{
if (is_connected && is_client && recieved_settings)
{
if (serverSyncClientsDirectory == 1)
{
if (fClientReceivedAllFiles)
gubMPCScreenHandler = MPC_CONTINUE;
}
else
{
gubMPCScreenHandler = MPC_CONTINUE;
}
}
}
#include <vfs/Core/vfs_os_functions.h>
#include <vfs/Core/vfs_profile.h>
#include <vfs/Core/vfs.h>
#include <vfs/Core/vfs_init.h>
#include <memory>
void ja2::mp::InitializeMultiplayerProfile(vfs::Path const& profileRoot)
{
// does the profile root directory actually exist
if(!vfs::OS::checkRealDirectory(profileRoot))
{
// OK, directory did not exist, probably a new profile
SGP_THROW_IFFALSE( vfs::OS::createRealDirectory(profileRoot),
_BS(L"Could not create directory : ") << profileRoot << _BS::wget );
}
// create and initialize a new Multiplayer profile
std::unique_ptr<vfs::CVirtualProfile> pProf( new vfs::CVirtualProfile("_MULTIPLAYER",profileRoot,true) );
if(!vfs_init::initWriteProfile(*pProf))
{
SGP_THROW(_BS(L"Could not initialize client profile") << profileRoot << _BS::wget);
}
vfs::CProfileStack *PS = getVFS()->getProfileStack();
// remove old Multiplayer profile (if it exists)
vfs::CVirtualProfile *pOldProf = PS->getProfile("_MULTIPLAYER");
if( pOldProf && (pOldProf == PS->topProfile()) )
{
SGP_THROW_IFFALSE(PS->popProfile(), L"Could not remove old \"_MULTIPLAYER\" profile");
}
// add new profile
PS->pushProfile(pProf.release());
}