forked from 1dot13/source
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MPJoinScreen.cpp
797 lines (645 loc) · 23.5 KB
/
MPJoinScreen.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
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
#include "Types.h"
#include "MPJoinScreen.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 "cursors.h"
#include "Text.h"
#include "Text Input.h"
#include "Soldier Profile.h"
#include "gameloop.h"
#include "connect.h"
#include "network.h" // for client name
#include "saveloadscreen.h"
#include "game init.h"
#include <vfs/Core/vfs.h>
#include <vfs/Core/vfs_init.h>
#include <vfs/Tools/vfs_property_container.h>
#include <vfs/Core/vfs_os_functions.h>
#include "Random.h"
////////////////////////////////////////////
//
// Global Defines
//
///////////////////////////////////////////
#define MPJ_TITLE_FONT FONT14ARIAL//FONT16ARIAL
#define MPJ_TITLE_COLOR FONT_MCOLOR_WHITE
#define MPJ_LABEL_TEXT_FONT FONT12ARIAL//FONT16ARIAL
#define MPJ_LABEL_TEXT_COLOR FONT_MCOLOR_WHITE
//buttons
#define MPJ_CANCEL_X iScreenWidthOffset + ((320 - 115) / 2)
#define MPJ_BTN_HOST_X iScreenWidthOffset + 265
#define MPJ_BTN_HOST_Y iScreenHeightOffset + 435
#define MPJ_BTN_JOIN_X iScreenWidthOffset + 425
#define MPJ_BTN_JOIN_Y iScreenHeightOffset + 435
//textboxes
#define MPJ_TXT_HANDLE_X iScreenWidthOffset + 100
#define MPJ_TXT_HANDLE_Y iScreenHeightOffset + 100
#define MPJ_TXT_HANDLE_WIDTH 120
#define MPJ_TXT_HANDLE_HEIGHT 17
#define MPJ_TXT_IP_X iScreenWidthOffset + 100
#define MPJ_TXT_IP_Y iScreenHeightOffset + 400
#define MPJ_TXT_IP_WIDTH 100
#define MPJ_TXT_IP_HEIGHT 17
#define MPJ_TXT_PORT_X MPJ_TXT_IP_X + MPJ_TXT_IP_WIDTH + 40
#define MPJ_TXT_PORT_Y iScreenHeightOffset + 400
#define MPJ_TXT_PORT_WIDTH 40
#define MPJ_TXT_PORT_HEIGHT 17
//main title
#define MPJ_MAIN_TITLE_X 0
#define MPJ_MAIN_TITLE_Y iScreenHeightOffset + 10
#define MPJ_MAIN_TITLE_WIDTH SCREEN_WIDTH
//labels
#define MPJ_LABEL_HANDLE_X MPJ_TXT_HANDLE_X - 80
#define MPJ_LABEL_HANDLE_Y MPJ_TXT_HANDLE_Y + 3
#define MPJ_LABEL_HANDLE_WIDTH 80
#define MPJ_LABEL_HANDLE_HEIGHT 17
#define MPJ_LABEL_IP_X MPJ_TXT_IP_X - 80
#define MPJ_LABEL_IP_Y MPJ_TXT_IP_Y + 3
#define MPJ_LABEL_IP_WIDTH 80
#define MPJ_LABEL_IP_HEIGHT 17
#define MPJ_LABEL_PORT_X MPJ_TXT_PORT_X - 30
#define MPJ_LABEL_PORT_Y MPJ_TXT_PORT_Y + 3
#define MPJ_LABEL_PORT_WIDTH 80
#define MPJ_LABEL_PORT_HEIGHT 17
////////////////////////////////////////////
//
// Global Variables
//
///////////////////////////////////////////
BOOLEAN gfMPJScreenEntry = TRUE;
BOOLEAN gfMPJScreenExit = FALSE;
BOOLEAN gfReRenderMPJScreen=TRUE;
BOOLEAN gfMPJButtonsAllocated = FALSE;
//enum for different states of screen
enum
{
MPJ_NOTHING,
MPJ_CANCEL,
MPJ_EXIT,
MPJ_HOST,
MPJ_JOIN
};
UINT8 gubMPJScreenHandler=MPJ_NOTHING; // State changer for HandleMPJScreen()
UINT32 gubMPJExitScreen = MP_JOIN_SCREEN; // The screen that is in control next iteration of the game_loop
UINT32 guiMPJMainBackGroundImage;
// Wide-char strings that will hold the variables until they are transferred to the CHAR ascii fields
CHAR16 gzPlayerHandleField[ 10+1 ] = {0} ;
CHAR16 gzServerIPField[ 15+1 ] = {0} ;
CHAR16 gzServerPortField[ 5+1 ] = {0} ;
// client sets this when joining
extern CHAR16 gzFileTransferDirectory[100];
void CUniqueServerId::uniqueRandomString(vfs::String& str)
{
std::vector<wchar_t> _rand(30,0);
int pos = 0;
for(int block = 0; block < 5; ++block)
{
for(int i=0; i<5; ++i)
{
int r = Random(36);
if(r < 10)
{
r += L'0';
}
else
{
r += L'A' - 10;
}
_rand[pos++] = r;
}
_rand[pos++] = L'-';
}
str.r_wcs().assign(&_rand[0],29);
}
vfs::String const& CUniqueServerId::getServerId(vfs::Path dir, vfs::PropertyContainer* props)
{
if(!props)
{
return _id;
}
vfs::String key = L"\"" + dir.c_wcs() + L"\"";
vfs::String id = props->getStringProperty(JA2MP_INI_SERVER_SECTION,key);
if(id.empty())
{
uniqueRandomString(id);
}
_id = id;
props->setStringProperty(JA2MP_INI_SERVER_SECTION,key,_id);
return _id;
}
CUniqueServerId s_ServerId;
////////////////////////////////////////////
//
// Screen Controls
//
///////////////////////////////////////////
// Join Button
void BtnMPJoinCallback(GUI_BUTTON *btn,INT32 reason);
UINT32 guiMPJoinButton;
INT32 giMPJoinBtnImage;
// Host Button
void BtnMPJHostCallback(GUI_BUTTON *btn,INT32 reason);
UINT32 guiMPJHostButton;
INT32 giMPJHostBtnImage;
// Cancel Button
void BtnMPJCancelCallback(GUI_BUTTON *btn,INT32 reason);
UINT32 guiMPJCancelButton;
INT32 giMPJCancelBtnImage;
// Message Box handle
INT8 giMPJMessageBox = -1;
////////////////////////////////////////////
//
// Local Function Prototypes
//
///////////////////////////////////////////
extern void ClearMainMenu();
BOOLEAN EnterMPJScreen();
BOOLEAN ExitMPJScreen();
void HandleMPJScreen();
BOOLEAN RenderMPJScreen();
void GetMPJScreenUserInput();
bool ValidateJoinSettings(bool bSkipServerAddress);
BOOLEAN DoMPJMessageBox( UINT8 ubStyle, const STR16 zString, UINT32 uiExitScreen, UINT16 usFlags, MSGBOX_CALLBACK ReturnCallback );
void DoneFadeOutForExitMPJScreen( void );
void DoneFadeInForExitMPJScreen( void );
void MpIniExists()
{
if(!getVFS()->fileExists(JA2MP_INI_FILENAME))
{
SGP_THROW_IFFALSE(getVFS()->createNewFile(JA2MP_INI_FILENAME),L"could not create file : Ja2_mp.ini");
vfs::tWritableFile* file = getVFS()->getWriteFile(JA2MP_INI_FILENAME);
if(file)
{
file->openWrite(true);
file->close();
}
}
}
UINT32 MPJoinScreenInit( void )
{
// WANNE - MP: Read the values from Profiles/UserProfile/ja2_mp.ini
MpIniExists();
vfs::PropertyContainer props;
props.initFromIniFile( JA2MP_INI_FILENAME);
props.getStringProperty( JA2MP_INI_INITIAL_SECTION, JA2MP_SERVER_IP, gzServerIPField, 16, "127.0.0.1");
props.getStringProperty( JA2MP_INI_INITIAL_SECTION, JA2MP_SERVER_PORT, gzServerPortField, 6, "60005");
props.getStringProperty( JA2MP_INI_INITIAL_SECTION, JA2MP_CLIENT_NAME, gzPlayerHandleField, 12, L"Player Name");
return( 1 );
}
void SaveJoinSettings(bool ReSaving)
{
if (!ReSaving)
{
Get16BitStringFromField( 0, gzPlayerHandleField, 12 ); // these indexes are based on the order created
Get16BitStringFromField( 1, gzServerIPField, 16 );
Get16BitStringFromField( 2, gzServerPortField, 6 );
}
MpIniExists();
vfs::PropertyContainer props;
props.initFromIniFile(JA2MP_INI_FILENAME);
props.setStringProperty(JA2MP_INI_INITIAL_SECTION,JA2MP_SERVER_IP, gzServerIPField);
props.setStringProperty(JA2MP_INI_INITIAL_SECTION,JA2MP_SERVER_PORT, gzServerPortField);
props.setStringProperty(JA2MP_INI_INITIAL_SECTION,JA2MP_CLIENT_NAME, gzPlayerHandleField);
s_ServerId.getServerId(vfs::Path(gzFileTransferDirectory), &props);
props.writeToIniFile(JA2MP_INI_FILENAME,false);
}
bool ValidateJoinSettings(bool bSkipServerAddress, bool bSkipSyncDir)
{
// Check a Player name is entered
Get16BitStringFromField( 0, gzPlayerHandleField, 12 ); // these indexes are based on the order created
if (wcscmp(gzPlayerHandleField,L"")<=0)
{
DoMPJMessageBox( MSG_BOX_BASIC_STYLE, gzMPJScreenText[MPJ_HANDLE_INVALID], MP_JOIN_SCREEN, MSG_BOX_FLAG_OK, NULL );
return false;
}
if (!bSkipServerAddress)
{
// Verify the IP Address
Get16BitStringFromField( 1, gzServerIPField, 16 );
// loop through octets and check
int numOctets = 0;
wchar_t* tok;
tok = wcstok(gzServerIPField,L".");
while (tok != NULL)
{
numOctets++;
INT32 oct = _wtoi(tok);
// check for invalid conversion, ie alpha chars
// wtoi returns 0 if it cant convert, but we need this value
// therefore if tok <> 0 then it was a bad convert.
if (oct == 0 && wcscmp(tok,L"0") != 0)
{
// force error
numOctets=0;
break;
}
if (oct < 0 || oct > 255) // allow 255
{
// bad octet, error
numOctets=0;
break;
}
// get next octet
tok = wcstok(NULL,L".");
}
if (numOctets != 4)
{
// not a valid ip address
DoMPJMessageBox( MSG_BOX_BASIC_STYLE, gzMPJScreenText[MPJ_SERVERIP_INVALID], MP_JOIN_SCREEN, MSG_BOX_FLAG_OK, NULL );
return false;
}
// Verify the Server Port
Get16BitStringFromField( 2, gzServerPortField, 6 );
INT32 svrPort = _wtoi(gzServerPortField);
if (svrPort < 1 || svrPort > 65535)
{
DoMPJMessageBox( MSG_BOX_BASIC_STYLE, gzMPJScreenText[MPJ_SERVERPORT_INVALID], MP_JOIN_SCREEN, MSG_BOX_FLAG_OK, NULL );
return false;
}
}
if (!bSkipSyncDir)
{
if(vfs::OS::createRealDirectory(vfs::Path(L"Multiplayer")))
{
vfs::OS::createRealDirectory(vfs::Path(L"Multiplayer/Servers"));
}
}
return true;
}
UINT32 MPJoinScreenHandle( void )
{
StartFrameBufferRender();
if( gfMPJScreenEntry )
{
EnterMPJScreen();
gfMPJScreenEntry = FALSE;
gfMPJScreenExit = FALSE;
InvalidateRegion( 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT );
}
GetMPJScreenUserInput();
HandleMPJScreen();
// render buttons marked dirty
MarkButtonsDirty( );
RenderButtons( );
// render text boxes
RenderAllTextFields(); // textbox system call
ExecuteBaseDirtyRectQueue();
EndFrameBufferRender();
// handle fades in and out
if ( HandleFadeOutCallback( ) )
{
ClearMainMenu();
return( gubMPJExitScreen );
}
if ( HandleBeginFadeOut( gubMPJExitScreen ) )
{
return( gubMPJExitScreen );
}
if ( HandleFadeInCallback( ) )
{
// Re-render the scene!
RenderMPJScreen();
}
if ( HandleBeginFadeIn( gubMPJExitScreen ) )
{
}
if( gfMPJScreenExit )
{
ExitMPJScreen();
}
return( gubMPJExitScreen );
}
UINT32 MPJoinScreenShutdown( void )
{
return( 1 );
}
BOOLEAN EnterMPJScreen()
{
VOBJECT_DESC VObjectDesc;
if( gfMPJButtonsAllocated )
return( TRUE );
SetCurrentCursorFromDatabase( CURSOR_NORMAL );
// load the Main trade screen backgroiund image
ColorFillVideoSurfaceArea( FRAME_BUFFER, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, Get16BPPColor( FROMRGB( 0, 0, 0 ) ) );
VObjectDesc.fCreateFlags=VOBJECT_CREATE_FROMFILE;
if (iResolution >= _640x480 && iResolution < _800x600)
FilenameForBPP("INTERFACE\\OptionsScreenBackGround.sti", VObjectDesc.ImageFile);
else if (iResolution < _1024x768)
FilenameForBPP("INTERFACE\\OptionsScreenBackGround_800x600.sti", VObjectDesc.ImageFile);
else
FilenameForBPP("INTERFACE\\OptionsScreenBackGround_1024x768.sti", VObjectDesc.ImageFile);
CHECKF(AddVideoObject(&VObjectDesc, &guiMPJMainBackGroundImage ));
//Join button
giMPJoinBtnImage = LoadButtonImage("INTERFACE\\PreferencesButtons.sti", -1,0,-1,2,-1 );
guiMPJoinButton = CreateIconAndTextButton( giMPJoinBtnImage, gzMPJScreenText[MPJ_JOIN_TEXT], OPT_BUTTON_FONT,
OPT_BUTTON_ON_COLOR, DEFAULT_SHADOW,
OPT_BUTTON_OFF_COLOR, DEFAULT_SHADOW,
TEXT_CJUSTIFIED,
MPJ_BTN_JOIN_X, MPJ_BTN_JOIN_Y, BUTTON_TOGGLE, MSYS_PRIORITY_HIGH,
DEFAULT_MOVE_CALLBACK, BtnMPJoinCallback);
SpecifyButtonSoundScheme( guiMPJoinButton, BUTTON_SOUND_SCHEME_BIGSWITCH3 );
SpecifyDisabledButtonStyle( guiMPJoinButton, DISABLED_STYLE_NONE );
//Host button
giMPJHostBtnImage = UseLoadedButtonImage( giMPJoinBtnImage, -1,1,-1,3,-1 );
guiMPJHostButton = CreateIconAndTextButton( giMPJHostBtnImage, gzMPJScreenText[MPJ_HOST_TEXT], OPT_BUTTON_FONT,
OPT_BUTTON_ON_COLOR, DEFAULT_SHADOW,
OPT_BUTTON_OFF_COLOR, DEFAULT_SHADOW,
TEXT_CJUSTIFIED,
MPJ_BTN_HOST_X, MPJ_BTN_HOST_Y, BUTTON_TOGGLE, MSYS_PRIORITY_HIGH,
DEFAULT_MOVE_CALLBACK, BtnMPJHostCallback);
SpecifyButtonSoundScheme( guiMPJHostButton, BUTTON_SOUND_SCHEME_BIGSWITCH3 );
SpecifyDisabledButtonStyle( guiMPJHostButton, DISABLED_STYLE_NONE );
//Cancel button
giMPJCancelBtnImage = UseLoadedButtonImage( giMPJoinBtnImage, -1,1,-1,3,-1 );
guiMPJCancelButton = CreateIconAndTextButton( giMPJCancelBtnImage, gzMPJScreenText[MPJ_CANCEL_TEXT], OPT_BUTTON_FONT,
OPT_BUTTON_ON_COLOR, DEFAULT_SHADOW,
OPT_BUTTON_OFF_COLOR, DEFAULT_SHADOW,
TEXT_CJUSTIFIED,
MPJ_CANCEL_X, MPJ_BTN_JOIN_Y, BUTTON_TOGGLE, MSYS_PRIORITY_HIGH,
DEFAULT_MOVE_CALLBACK, BtnMPJCancelCallback );
SpecifyButtonSoundScheme( guiMPJCancelButton, BUTTON_SOUND_SCHEME_BIGSWITCH3 );
// Initialise Text Boxes
InitTextInputMode(); // API call to initialise text input mode for this screen
// does not mean we are inputting text right away
// Player Name field
SetTextInputCursor( CUROSR_IBEAM_WHITE );
SetTextInputFont( (UINT16) FONT12ARIALFIXEDWIDTH ); //FONT12ARIAL //FONT12ARIALFIXEDWIDTH
Set16BPPTextFieldColor( Get16BPPColor(FROMRGB( 0, 0, 0) ) );
SetBevelColors( Get16BPPColor(FROMRGB(136, 138, 135)), Get16BPPColor(FROMRGB(24, 61, 81)) );
SetTextInputRegularColors( FONT_WHITE, 2 );
SetTextInputHilitedColors( 2, FONT_WHITE, FONT_WHITE );
SetCursorColor( Get16BPPColor(FROMRGB(255, 255, 255) ) );
//AddUserInputField( NULL ); // API Call that sets a special input-handling routine and method for the TAB key
//Add Player Name textbox
AddTextInputField( MPJ_TXT_HANDLE_X,
MPJ_TXT_HANDLE_Y,
MPJ_TXT_HANDLE_WIDTH,
MPJ_TXT_HANDLE_HEIGHT,
MSYS_PRIORITY_HIGH+2,
gzPlayerHandleField,
11,
INPUTTYPE_ASCII );//23
//Add Server IP textbox
AddTextInputField( MPJ_TXT_IP_X,
MPJ_TXT_IP_Y,
MPJ_TXT_IP_WIDTH,
MPJ_TXT_IP_HEIGHT,
MSYS_PRIORITY_HIGH+2,
gzServerIPField,
15,
INPUTTYPE_ASCII );//23
//Add Server Port textbox
AddTextInputField( MPJ_TXT_PORT_X,
MPJ_TXT_PORT_Y,
MPJ_TXT_PORT_WIDTH,
MPJ_TXT_PORT_HEIGHT,
MSYS_PRIORITY_HIGH+2,
gzServerPortField,
5,
INPUTTYPE_ASCII );//23
SetActiveField( 0 ); // Playername textbox has focus
//Reset the exit screen - screen the main game loop will call next iteration
gubMPJExitScreen = MP_JOIN_SCREEN;
//REnder the screen once so we can blt ot to ths save buffer
RenderMPJScreen();
BlitBufferToBuffer(guiRENDERBUFFER, guiSAVEBUFFER, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT );
gfMPJButtonsAllocated = TRUE;
return( TRUE );
}
BOOLEAN ExitMPJScreen()
{
if( !gfMPJButtonsAllocated )
return( TRUE );
//Delete the main options screen background
DeleteVideoObjectFromIndex( guiMPJMainBackGroundImage );
RemoveButton( guiMPJoinButton );
RemoveButton( guiMPJHostButton );
RemoveButton( guiMPJCancelButton );
UnloadButtonImage( giMPJCancelBtnImage );
UnloadButtonImage( giMPJHostBtnImage );
UnloadButtonImage( giMPJoinBtnImage );
// exit text input mode in this screen and clean up text boxes
KillAllTextInputModes();
SetTextInputCursor( CURSOR_IBEAM );
gfMPJButtonsAllocated = FALSE;
//If we are starting the game stop playing the music
// <TODO> review this, i think MPJ_EXIT is the proceed mode...
//if( gubMPJScreenHandler == MPJ_EXIT )
// SetMusicMode( MUSIC_NONE );
gfMPJScreenExit = FALSE;
gfMPJScreenEntry = TRUE;
return( TRUE );
}
void HandleMPJScreen()
{
if( gubMPJScreenHandler != MPJ_NOTHING )
{
switch( gubMPJScreenHandler )
{
case MPJ_CANCEL:
gubMPJExitScreen = MAINMENU_SCREEN;
gfMPJScreenExit = TRUE;
break;
case MPJ_HOST:
gubMPJExitScreen = MP_HOST_SCREEN;
gfMPJScreenExit = TRUE;
break;
case MPJ_JOIN:
{
//if we are already fading out, get out of here
if( gFadeOutDoneCallback != DoneFadeOutForExitMPJScreen )
{
//Disable the ok button
DisableButton( guiMPJoinButton );
DisableButton( guiMPJHostButton );
gFadeOutDoneCallback = DoneFadeOutForExitMPJScreen;
FadeOutNextFrame( );
}
break;
}
}
gubMPJScreenHandler = MPJ_NOTHING;
}
if( gfReRenderMPJScreen )
{
RenderMPJScreen();
gfReRenderMPJScreen = FALSE;
}
}
void DrawHelpText()
{
int x = MPJ_LABEL_HANDLE_X;
int y = iScreenHeightOffset + 60;
int width = 640 - (2 * 50);
int lineSpacing = 12;
// Visit IRC
DrawTextToScreen( gzMPJHelpText[ 0 ], x, y, width, FONT10ARIAL, MPJ_TITLE_COLOR, FONT_MCOLOR_BLACK, FALSE, CENTER_JUSTIFIED );
y+= lineSpacing;
DrawTextToScreen( gzMPJHelpText[ 1 ], x, y, width, FONT10ARIAL, MPJ_TITLE_COLOR, FONT_MCOLOR_BLACK, FALSE, CENTER_JUSTIFIED );
// Host
y += 150;
y+= lineSpacing;
DrawTextToScreen( gzMPJHelpText[ 2 ], x, y, width, FONT12ARIAL, MPJ_TITLE_COLOR, FONT_MCOLOR_BLACK, FALSE, LEFT_JUSTIFIED );
y+= lineSpacing + 5;
DrawTextToScreen( gzMPJHelpText[ 3 ], x, y, width, FONT10ARIAL, MPJ_TITLE_COLOR, FONT_MCOLOR_BLACK, FALSE, LEFT_JUSTIFIED );
y+= lineSpacing;
DrawTextToScreen( gzMPJHelpText[ 4 ], x, y, width, FONT10ARIAL, MPJ_TITLE_COLOR, FONT_MCOLOR_BLACK, FALSE, LEFT_JUSTIFIED );
y+= lineSpacing;
DrawTextToScreen( gzMPJHelpText[ 5 ], x, y, width, FONT10ARIAL, MPJ_TITLE_COLOR, FONT_MCOLOR_BLACK, FALSE, LEFT_JUSTIFIED );
y+= lineSpacing;
DrawTextToScreen( gzMPJHelpText[ 6 ], x, y, width, FONT10ARIAL, MPJ_TITLE_COLOR, FONT_MCOLOR_BLACK, FALSE, LEFT_JUSTIFIED );
// Join
y += 20;
y += lineSpacing;
DrawTextToScreen( gzMPJHelpText[ 7 ], x, y, width, FONT12ARIAL, MPJ_TITLE_COLOR, FONT_MCOLOR_BLACK, FALSE, LEFT_JUSTIFIED );
y += lineSpacing + 5;
DrawTextToScreen( gzMPJHelpText[ 8 ], x, y, width, FONT10ARIAL, MPJ_TITLE_COLOR, FONT_MCOLOR_BLACK, FALSE, LEFT_JUSTIFIED );
y += lineSpacing;
DrawTextToScreen( gzMPJHelpText[ 9 ], x, y, width, FONT10ARIAL, MPJ_TITLE_COLOR, FONT_MCOLOR_BLACK, FALSE, LEFT_JUSTIFIED );
y += lineSpacing;
DrawTextToScreen( gzMPJHelpText[ 10 ], x, y, width, FONT10ARIAL, MPJ_TITLE_COLOR, FONT_MCOLOR_BLACK, FALSE, LEFT_JUSTIFIED );
}
BOOLEAN RenderMPJScreen()
{
HVOBJECT hPixHandle;
//Get the main background screen graphic and blt it
GetVideoObject(&hPixHandle, guiMPJMainBackGroundImage );
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 );
//Display the title
DrawTextToScreen( gzMPJScreenText[ MPJ_TITLE_TEXT ], MPJ_MAIN_TITLE_X, MPJ_MAIN_TITLE_Y, MPJ_MAIN_TITLE_WIDTH, MPJ_TITLE_FONT, MPJ_TITLE_COLOR, FONT_MCOLOR_BLACK, FALSE, CENTER_JUSTIFIED );
DrawHelpText();
// Player name text label
DisplayWrappedString( MPJ_LABEL_HANDLE_X, MPJ_LABEL_HANDLE_Y, MPJ_LABEL_HANDLE_WIDTH, 2, MPJ_LABEL_TEXT_FONT, MPJ_LABEL_TEXT_COLOR, gzMPJScreenText[ MPJ_HANDLE_TEXT ], FONT_MCOLOR_BLACK, FALSE, LEFT_JUSTIFIED );
// Server IP text label
DisplayWrappedString( MPJ_LABEL_IP_X, MPJ_LABEL_IP_Y, MPJ_LABEL_IP_WIDTH, 2, MPJ_LABEL_TEXT_FONT, MPJ_LABEL_TEXT_COLOR, gzMPJScreenText[ MPJ_SERVERIP_TEXT ], FONT_MCOLOR_BLACK, FALSE, LEFT_JUSTIFIED );
// Server Port text label
DisplayWrappedString( MPJ_LABEL_PORT_X, MPJ_LABEL_PORT_Y, MPJ_LABEL_PORT_WIDTH, 2, MPJ_LABEL_TEXT_FONT, MPJ_LABEL_TEXT_COLOR, gzMPJScreenText[ MPJ_SERVERPORT_TEXT ], FONT_MCOLOR_BLACK, FALSE, LEFT_JUSTIFIED );
return( TRUE );
}
void GetMPJScreenUserInput()
{
InputAtom Event;
while (DequeueSpecificEvent(&Event, KEY_DOWN|KEY_UP|KEY_REPEAT))
{
// check if this event is swallowed by text input, otherwise process key
if( !HandleTextInput( &Event ) && Event.usEvent == KEY_DOWN )
{
switch( Event.usParam )
{
case ESC:
//Exit out of the screen
gubMPJScreenHandler = MPJ_CANCEL;
break;
case ENTER:
if (ValidateJoinSettings(false, false))
{
SaveJoinSettings(false);
gubMPJScreenHandler = MPJ_JOIN;
// force client to use "MULTIPLAYER/SERVERS" path
memset(gzFileTransferDirectory,0,100*sizeof(CHAR16));
wcscpy(gzFileTransferDirectory,L"multiplayer/servers");
}
break;
}
}
}
}
// CALLBACKS
void BtnMPJoinCallback(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 );
if (ValidateJoinSettings(false, false))
{
SaveJoinSettings(false);
gubMPJScreenHandler = MPJ_JOIN;
// force client to use "MULTIPLAYER/SERVERS" path
memset(gzFileTransferDirectory,0,100*sizeof(CHAR16));
wcscpy(gzFileTransferDirectory,L"multiplayer/servers");
}
InvalidateRegion(btn->Area.RegionTopLeftX, btn->Area.RegionTopLeftY, btn->Area.RegionBottomRightX, btn->Area.RegionBottomRightY);
}
}
void BtnMPJHostCallback(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 );
if (ValidateJoinSettings(true, false))
{
SaveJoinSettings(false);
gubMPJScreenHandler = MPJ_HOST;
}
InvalidateRegion(btn->Area.RegionTopLeftX, btn->Area.RegionTopLeftY, btn->Area.RegionBottomRightX, btn->Area.RegionBottomRightY);
}
}
void BtnMPJCancelCallback(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 );
gubMPJScreenHandler = MPJ_CANCEL;
InvalidateRegion(btn->Area.RegionTopLeftX, btn->Area.RegionTopLeftY, btn->Area.RegionBottomRightX, btn->Area.RegionBottomRightY);
}
}
BOOLEAN DoMPJMessageBox( UINT8 ubStyle, const STR16 zString, UINT32 uiExitScreen, UINT16 usFlags, MSGBOX_CALLBACK ReturnCallback )
{
SGPRect CenteringRect= {0 + xResOffset, 0, SCREEN_WIDTH - xResOffset, SCREEN_HEIGHT };
// do message box and return
giMPJMessageBox = DoMessageBox( ubStyle, zString, uiExitScreen, ( UINT16 ) ( usFlags| MSG_BOX_FLAG_USE_CENTERING_RECT ), ReturnCallback, &CenteringRect );
// send back return state
return( ( giMPJMessageBox != -1 ) );
}
void DoneFadeOutForExitMPJScreen( void )
{
// As we bypassed the GIO screen, set up some game options for multiplayer here
is_networked = true;
is_host = false; // we want to be a client, not we ARE a client yet (is_client)
auto_retry = true;
giNumTries = 5;
// set up and initialise a new game on the client
InitNewGame(false);
SetPendingNewScreen( MP_CONNECT_SCREEN );
if (is_networked)
gGameOptions.fTurnTimeLimit = TRUE;
else
gGameOptions.fTurnTimeLimit = FALSE;
// Bobby Rays - why would we want anything less than the best
gGameOptions.ubBobbyRayQuality = BR_AWESOME;
gGameOptions.ubBobbyRayQuantity = BR_AWESOME;
gubMPJExitScreen = MP_CONNECT_SCREEN;
ExitMPJScreen(); // cleanup please, if we called a fadeout then we didnt do it above
SetCurrentCursorFromDatabase( VIDEO_NO_CURSOR );
}
void DoneFadeInForExitMPJScreen( void )
{
SetCurrentCursorFromDatabase( VIDEO_NO_CURSOR );
}