forked from 1dot13/source
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MPChatScreen.cpp
1604 lines (1240 loc) · 45.2 KB
/
MPChatScreen.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
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
#include "sgp.h"
#include "screenids.h"
#include "Timer Control.h"
#include "fade screen.h"
#include "sysutil.h"
#include "vobject_blitters.h"
#include "MercTextBox.h"
#include "cursors.h"
#include "font control.h"
#include "Map Screen Interface.h"
#include "renderworld.h"
#include "gameloop.h"
#include "english.h"
#include "GameSettings.h"
#include "cursor control.h"
#include "laptop.h"
#include "text.h"
#include "Text Input.h"
#include "overhead map.h"
#include "MPChatScreen.h"
#include "WordWrap.h"
#include "message.h"
#include "utilities.h"
#include "connect.h"
#define CHATBOX_WIDTH 310 // 350 is the max size, the PrepareMercPopupBox will add the X_MARGIN to both sides
#define CHATBOX_Y_MARGIN_NOLOG 25
#define CHATBOX_Y_MARGIN_LOG 80
#define CHATBOX_Y_MARGIN_BOTTOM 80
#define CHATBOX_X_MARGIN 30 // pad box width 20 either side of text pixel length, but i use half of this value for control margins
#define CHATBOX_LOG_WIDTH 300
#define CHATBOX_LOG_HEIGHT 80
#define CHATBOX_LOG_TXTBORDER 4 // offset till text renderable area on all sides
#define CHATBOX_SCROLL_WIDTH 17
#define CHATBOX_SCROLL_HEIGHT 80
#define CHATBOX_SCROLL_GAPX 5
#define CHATBOX_BUTTON_WIDTH 61
#define CHATBOX_BUTTON_HEIGHT 20
#define CHATBOX_BUTTON_X_SEP 15
#define CHATBOX_SMALL_BUTTON_WIDTH 31
#define CHATBOX_SMALL_BUTTON_X_SEP 8
#define CHATBOX_TOGGLE_WIDTH 120
#define CHATBOX_TOGGLE_HEIGHT 12
#define CHATBOX_Y_GAP 10
#define CHATBOX_SLIDER_GAP 5
#define CHATBOX_INPUT_HEIGHT 20
#define CHATBOX_FONT_COLOR 73
#define CHATBOX_FONT_TITLE FONT14ARIAL
#define CHATBOX_FONT_TOGGLE FONT10ARIAL
// old mouse x and y positions
extern SGPPoint pOldMousePosition;
SGPRect ChatBoxRestrictedCursorRegion;
// if the cursor was locked to a region
extern BOOLEAN fCursorLockedToArea;
BOOLEAN gfInChatBox = FALSE;
//extern BOOLEAN fMapExitDueToMessageBox;
extern BOOLEAN fInMapMode;
extern BOOLEAN gfOverheadMapDirty;
//OJW - 20090208
CHAR16 gszChatBoxInputString[255];
BOOLEAN gbChatSendToAll = true;
void OKChatBoxCallback(GUI_BUTTON *btn, INT32 reason );
void CancelChatBoxCallback(GUI_BUTTON *btn, INT32 reason );
void ChatBoxClickCallback( MOUSE_REGION * pRegion, INT32 iReason );
UINT32 ExitChatBox( INT8 ubExitCode );
UINT16 GetChatBoxButtonWidth( INT32 iButtonImage );
extern SGPRect gOldCursorLimitRectangle;
MESSAGE_BOX_STRUCT gChatBox;
BOOLEAN gfNewChatBox = FALSE;
extern BOOLEAN gfStartedFromGameScreen;
extern BOOLEAN gfStartedFromMapScreen;
BOOLEAN fRestoreBackgroundForChatBox = FALSE;
extern BOOLEAN gfDontOverRideSaveBuffer; //this variable can be unset if ur in a non gamescreen and DONT want the msg box to use the save buffer
extern void HandleTacticalUILoseCursorFromOtherScreen( );
extern STR16 pUpdatePanelButtons[];
#define NUM_CHAT_TOGGLES 2
INT32 guiChatToggles[ NUM_CHAT_TOGGLES ];
void BtnChatTogglesCallback(GUI_BUTTON *btn,INT32 reason);
void RestoreChatToggleBackGrounds();
bool gIncludeChatLog = false;
SGPRect gChatTextBoxRegion;
// OPTIONAL CHAT MESSAGE LOG SETUP
SGPRect gChatMessageLogRegion;
UINT32 guiCHATLOGIMG; // Images for chat message log
// button enums
enum{
CHAT_SCROLL_MESSAGE_UP =0,
CHAT_SCROLL_MESSAGE_DOWN,
};
UINT32 guiChatSliderBar;
UINT16 CHATLOG_SCROLL_AREA_START_Y; //(SCREEN_HEIGHT - 90) //390
UINT16 CHATLOG_SCROLL_AREA_END_Y; //(SCREEN_HEIGHT - 32) //448
UINT16 CHATLOG_SCROLL_AREA_HEIGHT; //( CHATLOG_SCROLL_AREA_END_Y - CHATLOG_SCROLL_AREA_START_Y + 1 )
// CHRISL: Use these if we want scroll bar based on left edge of screen
UINT16 CHATLOG_SCROLL_AREA_START_X; //330
UINT16 CHATLOG_SCROLL_AREA_END_X; //344
UINT16 CHATLOG_SCROLL_AREA_WIDTH; //( CHATLOG_SCROLL_AREA_END_X - CHATLOG_SCROLL_AREA_START_X + 1 )
#define CHATLOG_BTN_SCROLL_TIME 100
#define CHAT_SLIDER_HEIGHT 11
#define CHAT_SLIDER_WIDTH 11
#define MAX_CHATLOG_MESSAGES 8
UINT16 CHAT_SLIDER_BAR_RANGE;
// buttons
UINT32 guiChatLogScrollButtons[ 2 ];
// buttons images
UINT32 guiChatLogScrollButtonsImage[ 2 ];
// mouse regions
MOUSE_REGION gChatLogScrollBarRegion;
void LoadChatLogSliderBar( void );
void DeleteChatLogSliderBar( void );
void DisplayChatLogScrollBarSlider( );
void CreateChatLogMessageScrollBarRegion( void );
void DeleteChatLogMessageScrollRegion( void );
void ChatScreenMsgScrollDown( UINT8 ubLinesDown );
void ChatScreenMsgScrollUp( UINT8 ubLinesUp );
void ChangeCurrentChatScreenMessageIndex( UINT8 ubNewMessageIndex );
void MoveToEndOfChatScreenMessageList( void );
void BtnMessageDownChatLogCallback( GUI_BUTTON *btn,INT32 reason );
void BtnMessageUpChatLogCallback( GUI_BUTTON *btn,INT32 reason );
void ChatScreenMessageScrollBarCallBack(MOUSE_REGION * pRegion, INT32 iReason );
void EnableDisableChatLogScrollButtonsAndRegions( void );
// the local logical message index
UINT8 gubFirstChatLogMessageIndex = 0;
// Chat Log Messages List
UINT8 gubStartOfChatLogMessageList = 0; // Front of the Message Queue
UINT8 gubEndOfChatLogMessageList = 0; // End of the Message Queue
UINT8 gubCurrentChatLogMessageString = 0; // // index of the current string we are looking at
static ScrollStringStPtr gChatLogMessageList[ 256 ]; // The message Queue
void InitChatMessageList( void );
void FreeChatMessageList( void );
void DisplayStringsInChatLogMessageList( void );
void AddStringToChatLogMessageList( STR16 pString, UINT16 usColor, UINT32 uiFont, BOOLEAN fStartOfNewString, UINT8 ubPriority );
UINT8 GetRangeOfChatLogMessages( void );
void ClearWrappedStringsCHAT( WRAPPED_STRING *pStringWrapperHead );
#define CHAT_LINE_WIDTH 292
#define CHAT_MESSAGE_FONT TINYFONT1
INT32 DoChatBox( bool bIncludeChatLog, const STR16 zString, UINT32 uiExitScreen, MSGBOX_CALLBACK ReturnCallback, SGPRect *pCenteringRect )
{
VSURFACE_DESC vs_desc;
UINT16 usTextBoxWidth;
UINT16 usTextBoxHeight;
UINT16 usYMargin;
SGPRect aRect;
UINT32 uiDestPitchBYTES, uiSrcPitchBYTES;
UINT8 *pDestBuf, *pSrcBuf;
INT16 sButtonX, sButtonY;
UINT8 ubMercBoxBackground = BASIC_MERC_POPUP_BACKGROUND, ubMercBoxBorder = BASIC_MERC_POPUP_BORDER;
UINT8 ubFontColor, ubFontShadowColor;
UINT16 usCursor;
INT32 iId = -1;
// clear the ouput string
memset(gszChatBoxInputString,0,sizeof(CHAR16)*255);
gIncludeChatLog = bIncludeChatLog;
GetMousePos( &pOldMousePosition );
if (bIncludeChatLog)
usYMargin = CHATBOX_Y_MARGIN_LOG;
else
usYMargin = CHATBOX_Y_MARGIN_NOLOG;
//this variable can be unset if ur in a non gamescreen and DONT want the msg box to use the save buffer
gfDontOverRideSaveBuffer = TRUE;
SetCurrentCursorFromDatabase( CURSOR_NORMAL );
if( gChatBox.BackRegion.uiFlags & MSYS_REGION_EXISTS )
{
return( 0 );
}
// set style
ubMercBoxBackground = DIALOG_MERC_POPUP_BACKGROUND;
ubMercBoxBorder = DIALOG_MERC_POPUP_BORDER;
// Add button images
gChatBox.iButtonImages = LoadButtonImage( "INTERFACE\\popupbuttons.sti", -1,0,-1,1,-1 );
ubFontColor = CHATBOX_FONT_COLOR;
ubFontShadowColor = DEFAULT_SHADOW;
usCursor = CURSOR_NORMAL;
// Use default!
aRect.iTop = 0;
aRect.iLeft = 0;
aRect.iBottom = SCREEN_HEIGHT;
aRect.iRight = SCREEN_WIDTH;
// Set some values!
//gChatBox.usFlags = usFlags;
gChatBox.uiExitScreen = uiExitScreen;
gChatBox.ExitCallback = ReturnCallback;
gChatBox.fRenderBox = TRUE;
gChatBox.bHandled = 0;
// Init message box
if (bIncludeChatLog)
// we need a string just long enough to give 1 line, but max length of the box, we render the chatlog over this string so well never see it. DONT DELETE ANY SPACES
gChatBox.iBoxId = PrepareMercPopupBox( iId, ubMercBoxBackground, ubMercBoxBorder, L"A string that will be hidden, ", CHATBOX_WIDTH, CHATBOX_X_MARGIN, usYMargin, CHATBOX_Y_MARGIN_BOTTOM, &usTextBoxWidth, &usTextBoxHeight );
else
gChatBox.iBoxId = PrepareMercPopupBox( iId, ubMercBoxBackground, ubMercBoxBorder, zString, CHATBOX_WIDTH, CHATBOX_X_MARGIN, usYMargin, CHATBOX_Y_MARGIN_BOTTOM, &usTextBoxWidth, &usTextBoxHeight );
if( gChatBox.iBoxId == -1 )
{
#ifdef JA2BETAVERSION
AssertMsg( 0, "Failed in DoMessageBox(). Probable reason is because the string was too large to fit in max message box size." );
#endif
return 0;
}
// Save height,width
gChatBox.usWidth = usTextBoxWidth;
gChatBox.usHeight = usTextBoxHeight;
// Determine position ( centered in rect )
gChatBox.sX = (INT16)( ( ( ( aRect.iRight - aRect.iLeft ) - usTextBoxWidth ) / 2 ) + aRect.iLeft );
gChatBox.sY = (INT16)( ( ( ( aRect.iBottom - aRect.iTop ) - usTextBoxHeight ) / 2 ) + aRect.iTop );
if ( guiCurrentScreen == GAME_SCREEN )
{
gfStartedFromGameScreen = TRUE;
}
if ( (fInMapMode == TRUE ) )
{
// fMapExitDueToMessageBox = TRUE;
gfStartedFromMapScreen = TRUE;
fMapPanelDirty = TRUE;
}
// Set pending screen
SetPendingNewScreen( MP_CHAT_SCREEN);
// Init save buffer
vs_desc.fCreateFlags = VSURFACE_CREATE_DEFAULT | VSURFACE_SYSTEM_MEM_USAGE;
vs_desc.usWidth = usTextBoxWidth;
vs_desc.usHeight = usTextBoxHeight;
vs_desc.ubBitDepth = 16;
if( AddVideoSurface( &vs_desc, &gChatBox.uiSaveBuffer) == FALSE )
{
return( - 1 );
}
//Save what we have under here...
pDestBuf = LockVideoSurface( gChatBox.uiSaveBuffer, &uiDestPitchBYTES);
pSrcBuf = LockVideoSurface( FRAME_BUFFER, &uiSrcPitchBYTES);
Blt16BPPTo16BPP((UINT16 *)pDestBuf, uiDestPitchBYTES,
(UINT16 *)pSrcBuf, uiSrcPitchBYTES,
0 , 0,
gChatBox.sX , gChatBox.sY,
usTextBoxWidth, usTextBoxHeight );
UnLockVideoSurface( gChatBox.uiSaveBuffer );
UnLockVideoSurface( FRAME_BUFFER );
// Create top-level mouse region
MSYS_DefineRegion( &(gChatBox.BackRegion), 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, MSYS_PRIORITY_HIGHEST,
usCursor, MSYS_NO_CALLBACK, ChatBoxClickCallback );
// Add region
MSYS_AddRegion(&(gChatBox.BackRegion) );
// findout if cursor locked, if so, store old params and store, restore when done
if( IsCursorRestricted() )
{
fCursorLockedToArea = TRUE;
GetRestrictedClipCursor( &ChatBoxRestrictedCursorRegion );
FreeMouseCursor( FALSE );
}
// vars for positioning controls on the chatbox
int usPosX = 0;
int usPosY = gChatBox.sY + GetFontHeight(CHATBOX_FONT_TITLE) + CHATBOX_Y_GAP + 5;
if (bIncludeChatLog)
{
// CREATE BUTTONS AND IMAGES FOR CHATLOG
VOBJECT_DESC VObjectDesc;
// will create buttons for interface bottom
VObjectDesc.fCreateFlags=VOBJECT_CREATE_FROMFILE;
FilenameForBPP( "INTERFACE\\mpchatbox.sti", VObjectDesc.ImageFile );
if( !AddVideoObject( &VObjectDesc, &guiCHATLOGIMG ) )
Assert( false );
gChatMessageLogRegion.iTop = usPosY;
gChatMessageLogRegion.iLeft = gChatBox.sX + (CHATBOX_X_MARGIN / 2);
gChatMessageLogRegion.iBottom = usPosY + CHATBOX_LOG_HEIGHT;
gChatMessageLogRegion.iRight = gChatMessageLogRegion.iLeft + CHATBOX_LOG_WIDTH;
// SETUP SCROLLING AREA BOUNDS
CHATLOG_SCROLL_AREA_START_Y = gChatMessageLogRegion.iTop+20;
CHATLOG_SCROLL_AREA_END_Y = gChatMessageLogRegion.iBottom-20;
CHATLOG_SCROLL_AREA_HEIGHT = ( CHATLOG_SCROLL_AREA_END_Y - CHATLOG_SCROLL_AREA_START_Y + 1 );
CHATLOG_SCROLL_AREA_START_X = gChatMessageLogRegion.iRight + CHATBOX_SLIDER_GAP + 1;
CHATLOG_SCROLL_AREA_END_X = gChatMessageLogRegion.iRight + CHATBOX_SLIDER_GAP + 1 + CHAT_SLIDER_WIDTH;
CHATLOG_SCROLL_AREA_WIDTH = ( CHATLOG_SCROLL_AREA_END_X - CHATLOG_SCROLL_AREA_START_X + 1 );
CHAT_SLIDER_BAR_RANGE = ( CHATLOG_SCROLL_AREA_HEIGHT - CHAT_SLIDER_HEIGHT );
LoadChatLogSliderBar();
// Load Scroll button images
guiChatLogScrollButtonsImage[ CHAT_SCROLL_MESSAGE_UP ]= LoadButtonImage( "INTERFACE\\map_screen_bottom_arrows.sti" ,11,4,-1,6,-1 );
guiChatLogScrollButtonsImage[ CHAT_SCROLL_MESSAGE_DOWN ]= LoadButtonImage( "INTERFACE\\map_screen_bottom_arrows.sti" ,12,5,-1,7,-1 );
// Create buttons
guiChatLogScrollButtons[ CHAT_SCROLL_MESSAGE_UP ] = QuickCreateButton( guiChatLogScrollButtonsImage[ CHAT_SCROLL_MESSAGE_UP ], gChatMessageLogRegion.iRight + CHATBOX_SLIDER_GAP + 2 , gChatMessageLogRegion.iTop + 1 ,
BUTTON_TOGGLE, MSYS_PRIORITY_HIGHEST,
(GUI_CALLBACK)BtnGenericMouseMoveButtonCallback, (GUI_CALLBACK)BtnMessageUpChatLogCallback);
guiChatLogScrollButtons[ CHAT_SCROLL_MESSAGE_DOWN ] = QuickCreateButton( guiChatLogScrollButtonsImage[ CHAT_SCROLL_MESSAGE_DOWN ], gChatMessageLogRegion.iRight + CHATBOX_SLIDER_GAP + 2, gChatMessageLogRegion.iBottom - 16,
BUTTON_TOGGLE, MSYS_PRIORITY_HIGHEST,
(GUI_CALLBACK)BtnGenericMouseMoveButtonCallback, (GUI_CALLBACK)BtnMessageDownChatLogCallback);
usPosY = gChatBox.sY + CHATBOX_Y_MARGIN_LOG + (CHATBOX_Y_GAP * 2) + GetFontHeight(FONT12ARIAL) + 5;
// END CREATE CHATLOG
}
else
usPosY = gChatBox.sY + CHATBOX_Y_MARGIN_NOLOG + (CHATBOX_Y_GAP * 2) + GetFontHeight(FONT12ARIAL);
// get the middle of the box
UINT16 middleBox = ( usTextBoxWidth / 2 );
// CREATE SEND TO ALLIES / ALL TOGGLES
// send to all
int toggleWidth = 32 + StringPixLength( gzMPChatToggleText[ 0 ], CHATBOX_FONT_TOGGLE );
usPosX = gChatBox.sX + ((middleBox - toggleWidth)/2);
guiChatToggles[ 0 ] = CreateCheckBoxButton( usPosX, usPosY,
"INTERFACE\\OptionsCheckBoxes_12x12.sti", MSYS_PRIORITY_HIGHEST,
BtnChatTogglesCallback );
MSYS_SetBtnUserData( guiChatToggles[ 0 ], 0, 0 );
// send to allies
toggleWidth = 32 + StringPixLength( gzMPChatToggleText[ 1 ], CHATBOX_FONT_TOGGLE );
usPosX = gChatBox.sX + middleBox + ((middleBox - toggleWidth)/2);
guiChatToggles[ 1 ] = CreateCheckBoxButton( usPosX, usPosY,
"INTERFACE\\OptionsCheckBoxes_12x12.sti", MSYS_PRIORITY_HIGHEST,
BtnChatTogglesCallback );
MSYS_SetBtnUserData( guiChatToggles[ 1 ], 0, 1 );
usPosY += CHATBOX_TOGGLE_HEIGHT + CHATBOX_Y_GAP;
// SET DEFAULT FLAGGED
if (gbChatSendToAll)
ButtonList[ guiChatToggles[ 0 ] ]->uiFlags |= BUTTON_CLICKED_ON;
else
ButtonList[ guiChatToggles[ 1 ] ]->uiFlags |= BUTTON_CLICKED_ON;
// END CREATE TOGGLES
// CREATE TEXT INPUT BOX
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) ) );
usPosX = gChatBox.sX + (CHATBOX_X_MARGIN / 2);
//Add Player Name textbox
AddTextInputField( usPosX ,
usPosY ,
usTextBoxWidth - CHATBOX_X_MARGIN,
20,
MSYS_PRIORITY_HIGH+2,
gszChatBoxInputString,
255,
INPUTTYPE_ASCII );//23
gChatTextBoxRegion.iTop = usPosY;
gChatTextBoxRegion.iLeft = usPosX;
gChatTextBoxRegion.iBottom = usPosY+20;
gChatTextBoxRegion.iRight = usPosX+usTextBoxWidth - CHATBOX_X_MARGIN;
// exit text input mode in this screen and clean up text boxes
SetActiveField( 0 );
usPosY += CHATBOX_INPUT_HEIGHT + CHATBOX_Y_GAP;
// END CREATE TEXT INPUT BOX
// CREATE OK AND CANCEL BUTTONS
// get the button width
UINT16 btnWidth = GetChatBoxButtonWidth( gChatBox.iButtonImages );
// Create OK Button
sButtonX = middleBox + ((middleBox - btnWidth)/2);
sButtonY = usTextBoxHeight - CHATBOX_BUTTON_HEIGHT - 10;
gChatBox.uiOKButton = CreateIconAndTextButton( gChatBox.iButtonImages, pMessageStrings[ MSG_OK ], FONT12ARIAL,
CHATBOX_FONT_COLOR, ubFontShadowColor,
CHATBOX_FONT_COLOR, ubFontShadowColor,
TEXT_CJUSTIFIED,
(INT16)(gChatBox.sX + sButtonX ), (INT16)(gChatBox.sY + sButtonY ), BUTTON_TOGGLE ,MSYS_PRIORITY_HIGHEST,
DEFAULT_MOVE_CALLBACK, (GUI_CALLBACK)OKChatBoxCallback );
SetButtonCursor(gChatBox.uiOKButton, usCursor);
ForceButtonUnDirty( gChatBox.uiOKButton );
// move the mouse over the ok button
if( gGameSettings.fOptions[ TOPTION_DONT_MOVE_MOUSE ] == FALSE )
{
SimulateMouseMovement( ( gChatBox.sX + sButtonX + 27 ), ( gChatBox.sY + sButtonY + 10) );
}
// Create Cancel Button
sButtonX = ((middleBox - btnWidth)/2);
sButtonY = usTextBoxHeight - CHATBOX_BUTTON_HEIGHT - 10;
gChatBox.uiNOButton = CreateIconAndTextButton( gChatBox.iButtonImages, pMessageStrings[ MSG_CANCEL ], FONT10ARIAL,
CHATBOX_FONT_COLOR, ubFontShadowColor,
CHATBOX_FONT_COLOR, ubFontShadowColor,
TEXT_CJUSTIFIED,
(INT16)(gChatBox.sX + sButtonX ), (INT16)(gChatBox.sY + sButtonY ), BUTTON_TOGGLE ,MSYS_PRIORITY_HIGHEST,
DEFAULT_MOVE_CALLBACK, (GUI_CALLBACK)CancelChatBoxCallback );
SetButtonCursor(gChatBox.uiNOButton, usCursor);
ForceButtonUnDirty( gChatBox.uiNOButton );
// END CREATE BUTTONS
#if 0
gChatBox.fWasPaused = GamePaused();
if (!gChatBox.fWasPaused)
{
InterruptTime();
PauseGame();
LockPauseState( 1 );
// Pause timers as well....
PauseTime( TRUE );
}
#endif
// Save mouse restriction region...
GetRestrictedClipCursor( &gOldCursorLimitRectangle );
FreeMouseCursor( FALSE );
gfNewChatBox = TRUE;
gfInChatBox = TRUE;
return( iId );
}
UINT32 ExitChatBox( INT8 ubExitCode )
{
UINT32 uiDestPitchBYTES, uiSrcPitchBYTES;
UINT8 *pDestBuf, *pSrcBuf;
SGPPoint pPosition;
// Delete popup!
RemoveMercPopupBoxFromIndex( gChatBox.iBoxId );
gChatBox.iBoxId = -1;
// OJW - 20090208 - Add text input box type
// exit text input mode in this screen and clean up text boxes
KillAllTextInputModes();
RemoveButton( gChatBox.uiOKButton );
RemoveButton( gChatBox.uiNOButton );
// Delete button images
UnloadButtonImage( gChatBox.iButtonImages );
//Remove the toggle buttons
for(int cnt=0; cnt<NUM_CHAT_TOGGLES; cnt++)
{
RemoveButton( guiChatToggles[ cnt ] );
}
// delete graphics and scrolling buttons / slider
if (gIncludeChatLog)
{
RemoveButton( guiChatLogScrollButtons[ 0 ] );
RemoveButton( guiChatLogScrollButtons[ 1 ] );
UnloadButtonImage( guiChatLogScrollButtonsImage[ 0 ] );
UnloadButtonImage( guiChatLogScrollButtonsImage[ 1 ] );
DeleteVideoObjectFromIndex( guiCHATLOGIMG );
DeleteChatLogSliderBar();
}
#if 0
if (!gChatBox.fWasPaused)
{
// Unpause game....
UnLockPauseState();
UnPauseGame();
// UnPause timers as well....
PauseTime( FALSE );
}
#endif
// Restore mouse restriction region...
RestrictMouseCursor( &gOldCursorLimitRectangle );
gfInChatBox = FALSE;
// Call done callback!
if ( gChatBox.ExitCallback != NULL )
{
(*(gChatBox.ExitCallback))( ubExitCode );
}
//if ur in a non gamescreen and DONT want the msg box to use the save buffer, unset gfDontOverRideSaveBuffer in ur callback
if( ( ( gChatBox.uiExitScreen != GAME_SCREEN ) || ( fRestoreBackgroundForMessageBox == TRUE ) ) && gfDontOverRideSaveBuffer )
{
// restore what we have under here...
pSrcBuf = LockVideoSurface( gChatBox.uiSaveBuffer, &uiSrcPitchBYTES);
pDestBuf = LockVideoSurface( FRAME_BUFFER, &uiDestPitchBYTES);
Blt16BPPTo16BPP((UINT16 *)pDestBuf, uiDestPitchBYTES,
(UINT16 *)pSrcBuf, uiSrcPitchBYTES,
gChatBox.sX , gChatBox.sY,
0, 0,
gChatBox.usWidth, gChatBox.usHeight );
UnLockVideoSurface( gChatBox.uiSaveBuffer );
UnLockVideoSurface( FRAME_BUFFER );
InvalidateRegion( gChatBox.sX, gChatBox.sY, (INT16)( gChatBox.sX + gChatBox.usWidth ), (INT16)( gChatBox.sY + gChatBox.usHeight ) );
}
fRestoreBackgroundForMessageBox = FALSE;
gfDontOverRideSaveBuffer = TRUE;
if( fCursorLockedToArea == TRUE )
{
GetMousePos( &pPosition );
if( ( pPosition.iX > ChatBoxRestrictedCursorRegion.iRight ) || ( pPosition.iX > ChatBoxRestrictedCursorRegion.iLeft ) && ( pPosition.iY < ChatBoxRestrictedCursorRegion.iTop ) && ( pPosition.iY > ChatBoxRestrictedCursorRegion.iBottom ) )
{
SimulateMouseMovement( pOldMousePosition.iX , pOldMousePosition.iY );
}
fCursorLockedToArea = FALSE;
RestrictMouseCursor( &ChatBoxRestrictedCursorRegion );
}
// Remove region
MSYS_RemoveRegion(&(gChatBox.BackRegion) );
// Remove save buffer!
DeleteVideoSurfaceFromIndex( gChatBox.uiSaveBuffer );
switch( gChatBox.uiExitScreen )
{
case GAME_SCREEN:
if ( InOverheadMap( ) )
{
gfOverheadMapDirty = TRUE;
}
else
{
SetRenderFlags( RENDER_FLAG_FULL );
}
break;
case MAP_SCREEN:
fMapPanelDirty = TRUE;
break;
}
if ( gfFadeInitialized )
{
SetPendingNewScreen(FADE_SCREEN);
return( FADE_SCREEN );
}
return( gChatBox.uiExitScreen );
}
UINT32 MPChatScreenInit( )
{
InitChatMessageList();
return( TRUE );
}
UINT32 MPChatScreenHandle( )
{
InputAtom InputEvent;
if ( gfNewChatBox )
{
// If in game screen....
if ( ( gfStartedFromGameScreen )||( gfStartedFromMapScreen ) )
{
//UINT32 uiDestPitchBYTES, uiSrcPitchBYTES;
//UINT8 *pDestBuf, *pSrcBuf;
if( gfStartedFromGameScreen )
{
HandleTacticalUILoseCursorFromOtherScreen( );
}
else
{
HandleMAPUILoseCursorFromOtherScreen( );
}
gfStartedFromGameScreen = FALSE;
gfStartedFromMapScreen = FALSE;
}
gfNewChatBox = FALSE;
return( MP_CHAT_SCREEN );
}
UnmarkButtonsDirty( );
// Render the box!
if ( gChatBox.fRenderBox )
{
// Render the Background ( this includes the text string)
RenderMercPopUpBoxFromIndex( gChatBox.iBoxId, gChatBox.sX, gChatBox.sY, FRAME_BUFFER );
UINT16 usWidth = StringPixLength( gzMPChatboxText[0], CHATBOX_FONT_TITLE );
int usPosY = 0;
int usPosX = 0;
usPosY = gChatBox.sY + 10;
usPosX = gChatBox.sX + ((gChatBox.usWidth - usWidth) / 2);
DrawTextToScreen( gzMPChatboxText[0], usPosX, usPosY, usWidth, CHATBOX_FONT_TITLE, CHATBOX_FONT_COLOR, DEFAULT_SHADOW, FALSE, CENTER_JUSTIFIED | TEXT_SHADOWED );
// Render the toggle button strings
for(UINT8 cnt=0; cnt<NUM_CHAT_TOGGLES; cnt++)
{
GUI_BUTTON* btn = ButtonList[ guiChatToggles[ cnt ] ];
usPosX = btn->XLoc + 12 + 10;
usPosY = btn->YLoc;
usWidth = StringPixLength( gzMPChatToggleText[ cnt ], CHATBOX_FONT_TOGGLE );
DrawTextToScreen( gzMPChatToggleText[ cnt ], usPosX, usPosY, usWidth, CHATBOX_FONT_TOGGLE, CHATBOX_FONT_COLOR, FONT_MCOLOR_BLACK, FALSE, LEFT_JUSTIFIED );
}
if (gIncludeChatLog)
{
// draw chatbox
HVOBJECT hHandle;
// get and blt panel
GetVideoObject(&hHandle, guiCHATLOGIMG );
BltVideoObject( FRAME_BUFFER , hHandle, 0, gChatMessageLogRegion.iLeft, gChatMessageLogRegion.iTop, VO_BLT_SRCTRANSPARENCY,NULL );
BltVideoObject( FRAME_BUFFER , hHandle, 1, gChatMessageLogRegion.iRight+CHATBOX_SLIDER_GAP, gChatMessageLogRegion.iTop, VO_BLT_SRCTRANSPARENCY,NULL );
// draw slider
DisplayChatLogScrollBarSlider( );
// draw chat log text
DisplayStringsInChatLogMessageList();
}
}
MarkButtonsDirty();
EnableDisableChatLogScrollButtonsAndRegions();
// Render buttons
RenderButtons( );
// render text boxes
//SaveFontSettings();
SetFontDestBuffer( FRAME_BUFFER, gChatTextBoxRegion.iLeft , gChatTextBoxRegion.iTop , gChatTextBoxRegion.iRight , gChatTextBoxRegion.iBottom, FALSE );
RenderAllTextFields(); // textbox system call
SetFontDestBuffer( FRAME_BUFFER, 0 , 0 , SCREEN_WIDTH , SCREEN_HEIGHT , FALSE );
//RestoreFontSettings();
EndFrameBufferRender( );
// carter, need key shortcuts for clearing up message boxes
// Check for esc
bool bHandled;
while (DequeueSpecificEvent(&InputEvent, KEY_DOWN|KEY_UP|KEY_REPEAT))
{
bHandled = false;
if(InputEvent.usEvent == KEY_DOWN )
{
if( ( InputEvent.usParam == ESC ) )
{
// Exit messagebox
gChatBox.bHandled = MSG_BOX_RETURN_NO;
memset(gszChatBoxInputString,0,sizeof(CHAR16)*255);
bHandled = true;
}
if( InputEvent.usParam == ENTER )
{
// retrieve the string from the text box
Get16BitStringFromField( 0, gszChatBoxInputString, 255 ); // these indexes are based on the order created
// Exit messagebox
gChatBox.bHandled = MSG_BOX_RETURN_OK;
bHandled = true;
}
// OJW - 20090403 - add better key control
UINT8 ubDesiredMessageIndex;
UINT8 ubNumMessages;
ubNumMessages = GetRangeOfChatLogMessages();
if ( ubNumMessages > MAX_CHATLOG_MESSAGES )
{
if (InputEvent.usParam == PGUP)
{
//move up a page
ChatScreenMsgScrollUp( MAX_CHATLOG_MESSAGES );
bHandled = true;
}
if (InputEvent.usParam == PGDN)
{
// move down a page
ChatScreenMsgScrollDown( MAX_CHATLOG_MESSAGES );
bHandled = true;
}
if (InputEvent.usParam == HOME)
{
// move to the beginning
ChangeCurrentChatScreenMessageIndex( 0 );
bHandled = true;
}
if (InputEvent.usParam == END)
{
// move to end
ubDesiredMessageIndex = ubNumMessages - MAX_CHATLOG_MESSAGES;
ChangeCurrentChatScreenMessageIndex( ubDesiredMessageIndex );
bHandled = true;
}
}
}
// send to text box
if (!bHandled)
HandleTextInput( &InputEvent );
}
if ( gChatBox.bHandled )
{
SetRenderFlags( RENDER_FLAG_FULL );
return( ExitChatBox( gChatBox.bHandled ) );
}
return( MP_CHAT_SCREEN );
}
UINT32 MPChatScreenShutdown( )
{
FreeChatMessageList();
return( FALSE );
}
UINT16 GetChatBoxButtonWidth( INT32 iButtonImage )
{
return( GetWidthOfButtonPic( (UINT16)iButtonImage, ButtonPictures[iButtonImage].OnNormal ) );
}
void CancelChatBoxCallback(GUI_BUTTON *btn, INT32 reason )
{
static BOOLEAN fLButtonDown = FALSE;
if(reason & MSYS_CALLBACK_REASON_LBUTTON_DWN )
{
btn->uiFlags |= BUTTON_CLICKED_ON;
fLButtonDown = TRUE;
}
else if( ( reason & MSYS_CALLBACK_REASON_LBUTTON_UP ) && fLButtonDown )
{
btn->uiFlags &= (~BUTTON_CLICKED_ON );
// OK, exit
gChatBox.bHandled = MSG_BOX_RETURN_NO;
// clear the ouput string
memset(gszChatBoxInputString,0,sizeof(CHAR16)*255);
}
else if ( reason & MSYS_CALLBACK_REASON_LOST_MOUSE )
{
fLButtonDown = FALSE;
}
}
void OKChatBoxCallback(GUI_BUTTON *btn, INT32 reason )
{
static BOOLEAN fLButtonDown = FALSE;
if(reason & MSYS_CALLBACK_REASON_LBUTTON_DWN )
{
btn->uiFlags |= BUTTON_CLICKED_ON;
fLButtonDown = TRUE;
}
else if( ( reason & MSYS_CALLBACK_REASON_LBUTTON_UP ) && fLButtonDown )
{
btn->uiFlags &= (~BUTTON_CLICKED_ON );
// OK, exit
gChatBox.bHandled = MSG_BOX_RETURN_OK;
// retrieve the string from the text box
Get16BitStringFromField( 0, gszChatBoxInputString, 255 ); // these indexes are based on the order created
}
else if ( reason & MSYS_CALLBACK_REASON_LOST_MOUSE )
{
fLButtonDown = FALSE;
}
}
void BtnChatTogglesCallback( GUI_BUTTON *btn, INT32 reason )
{
UINT8 ubButton = (UINT8)MSYS_GetBtnUserData( btn, 0 );
if (ubButton == 1 && cGameType != MP_TYPE_TEAMDEATMATCH)
return;
if( reason & MSYS_CALLBACK_REASON_LBUTTON_UP )
{
if( btn->uiFlags & BUTTON_CLICKED_ON )
{
// disable all buttons in grp
UINT8 cnt;
for( cnt=0; cnt<NUM_CHAT_TOGGLES; cnt++)
{
ButtonList[ guiChatToggles[ cnt ] ]->uiFlags &= ~BUTTON_CLICKED_ON;
}
// reselect the current button
btn->uiFlags |= BUTTON_CLICKED_ON;
gbChatSendToAll = ubButton == 0; // 0 is send to all
}
else
{
// check if any other buttons are checked
UINT8 cnt;
BOOLEAN fAnyChecked=FALSE;
for( cnt=0; cnt<NUM_CHAT_TOGGLES; cnt++)
{
if( ButtonList[ guiChatToggles[ cnt ] ]->uiFlags & BUTTON_CLICKED_ON )
{
fAnyChecked = TRUE;
}
}
//if none are checked, re check this one
if( !fAnyChecked )
btn->uiFlags |= BUTTON_CLICKED_ON;
}
}
}
void RestoreChatToggleBackGrounds()
{
UINT8 cnt;
//Redraw toggle buttons
for( cnt=0; cnt<NUM_CHAT_TOGGLES; cnt++)
{
GUI_BUTTON* btn = ButtonList[ guiChatToggles[ cnt ] ];
InvalidateRegion(btn->Area.RegionTopLeftX, btn->Area.RegionTopLeftY, btn->Area.RegionBottomRightX, btn->Area.RegionBottomRightY);
}
}
void ChatBoxClickCallback( MOUSE_REGION * pRegion, INT32 iReason )
{
}
// SCROLLING FOR CHAT LOG
void BtnMessageDownChatLogCallback( GUI_BUTTON *btn,INT32 reason )
{
static INT32 iLastRepeatScrollTime = 0;
if( reason & MSYS_CALLBACK_REASON_LBUTTON_DWN )
{
// redraw region
if( btn->uiFlags & MSYS_HAS_BACKRECT )
{
gChatBox.fRenderBox = TRUE;
}
btn->uiFlags|=(BUTTON_CLICKED_ON);
iLastRepeatScrollTime = 0;
}
else if(reason & MSYS_CALLBACK_REASON_LBUTTON_UP )
{
if (btn->uiFlags & BUTTON_CLICKED_ON)
{
btn->uiFlags&=~(BUTTON_CLICKED_ON);
// redraw region
if( btn->uiFlags & MSYS_HAS_BACKRECT )
{
gChatBox.fRenderBox = TRUE;
}
// down a line
ChatScreenMsgScrollDown( 1 );
}
}
else if( reason & MSYS_CALLBACK_REASON_LBUTTON_REPEAT )
{
if( GetJA2Clock() - iLastRepeatScrollTime >= CHATLOG_BTN_SCROLL_TIME )
{
// down a line
ChatScreenMsgScrollDown( 1 );
iLastRepeatScrollTime = GetJA2Clock( );
}
}
else if( reason & MSYS_CALLBACK_REASON_RBUTTON_DWN )
{
// redraw region
if( btn->uiFlags & MSYS_HAS_BACKRECT )
{
gChatBox.fRenderBox = TRUE;
}
btn->uiFlags|=(BUTTON_CLICKED_ON);