forked from 1dot13/source
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FeaturesScreen.cpp
1619 lines (1335 loc) · 50.7 KB
/
FeaturesScreen.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 "Types.h"
#include "FeaturesScreen.h"
#include "Video.h"
#include "Font Control.h"
#include "Game Clock.h"
#include "Text Input.h"
#include "WordWrap.h"
#include "SaveLoadScreen.h"
#include "Render Dirty.h"
#include "WordWrap.h"
#include "WCheck.h"
#include "Utilities.h"
#include "Debug.h"
#include "Sound Control.h"
#include "Ambient Control.h"
#include "Worlddat.h"
#include "Worlddef.h"
#include "GameSettings.h"
#include "Game Init.h"
#include "English.h"
#include "Overhead.h"
#include "Gap.h"
#include "Cursors.h"
#include "SysUtil.h"
#include "Exit Grids.h"
#include "Text.h"
#include "Interface Control.h"
#include "Message.h"
#include "Language Defines.h"
#include "Multi Language Graphic Utils.h"
#include "Map Information.h"
#include "Sys Globals.h"
#include "insurance.h"
#include "connect.h"
#include "WorldMan.h"
#include "Init.h"
#include "Game Events.h"
extern UINT32 guiDoneButton; // symbol already declared globally in AimArchives.cpp (jonathanl)
namespace FeaturesScreen
{
// this enum must be kept in sync with z113FeaturesScreenText
enum Text
{
FST_TITLE,
FST_DESCRIPTION,
FST_HOVER_FOR_MORE_INFO,
};
/////////////////////////////////
//
// Global Variables
//
/////////////////////////////////
UINT32 guiFeaturesBackGroundImage;
UINT32 guiFeaturesAddOnImages;
BOOLEAN gfFeaturesScreenEntry = TRUE;
BOOLEAN gfFeaturesScreenExit = FALSE;
BOOLEAN gfRedrawFeaturesScreen = TRUE;
BOOLEAN gfEnteredFromMapScreen = FALSE; // entered from options screen or new game screen
UINT32 guiFeaturesScreen = FEATURES_SCREEN;
UINT32 guiPreviousScreen = FEATURES_SCREEN;
BOOLEAN gfExitFeaturesDueToMessageBox = FALSE;
BOOLEAN gfExitFeaturesAfterMessageBox = FALSE;
INT32 giFeaturesMessageBox = -1; // Options pop up messages index value
INT8 gbHighLightedOptionText = -1;
// Goto save game Button
void BtnOptGotoSaveGameCallback(GUI_BUTTON* btn, INT32 reason);
UINT32 guiOptGotoSaveGameBtn;
INT32 giOptionsButtonImages;
// Goto load game button
void BtnOptGotoLoadGameCallback(GUI_BUTTON* btn, INT32 reason);
UINT32 guiOptGotoLoadGameBtn;
INT32 giGotoLoadBtnImage;
// QuitButton
void BtnOptQuitCallback(GUI_BUTTON* btn, INT32 reason);
UINT32 guiQuitButton;
INT32 giQuitBtnImage;
// Options Button
void BtnOptionsCallback(GUI_BUTTON* btn, INT32 reason);
UINT32 guiOptionsButton;
INT32 giOptionsBtnImage;
// arynn : need more option screen toggles : Add in button that allow for options column paging
// Options Screen globals
INT16 OptionsList_Column_Offset = 0; // the first column's -or- "half page" start
INT16 Current_First_Option_Index; // index of the first (single) option in the first column, used in lookup option vs togglebox
INT16 Max_Number_Of_Pages = 0; // dynamic column counter per build/mode type
void Establish_Features_Screen_Rules(void); // define the display rules
void Build_Features_List_Reinterpretation(void); // interpret rules and build a set of which options are used for use in options screen
void Create_Toggle_Buttons(void); // these two are blcok removals from functions, an isolation of toggle create/destroy
void Destroy_Toggle_Buttons(void);
// Next Button
void BtnOptNextCallback(GUI_BUTTON* btn, INT32 reason);
UINT32 guiOptNextButton;
INT32 giOptNextBtnImage;
// Prev Button
void BtnOptPrevCallback(GUI_BUTTON* btn, INT32 reason);
UINT32 guiOptPrevButton;
INT32 giOptPrevBtnImage;
// Done Button
void BtnDoneCallback(GUI_BUTTON* btn, INT32 reason);
INT32 giDoneBtnImage;
//checkbox to toggle tracking mode on or off
UINT32 guiFeaturesToggles[MAX_NUMBER_OF_OPTION_TOGGLES]; //array of ButtonID, index's for button list
BOOL Buttons_Exist_State = 0;
void BtnOptionsTogglesCallback(GUI_BUTTON* btn, INT32 reason);
//Mouse regions for the name of the option
MOUSE_REGION gSelectedOptionTextRegion[MAX_NUMBER_OF_OPTION_TOGGLES];
void SelectedOptionTextRegionCallBack(MOUSE_REGION* pRegion, INT32 iReason);
void SelectedOptionTextRegionMovementCallBack(MOUSE_REGION* pRegion, INT32 reason);
//Mouse regions for the area around the toggle boxs
MOUSE_REGION gSelectedToggleBoxAreaRegion;
void SelectedToggleBoxAreaRegionMovementCallBack(MOUSE_REGION* pRegion, INT32 reason);
//toggle box correspondence to option tracker
//1 define the render rules,
//2 recast real options into new array under constraints of rules,
//3 then using a pager system, create a subset that will fit on screen
int toggle_box_feature_rules[NUM_FEATURE_FLAGS]; // index = game option value = render state
int toggle_box_gGameSettings_recast[NUM_FEATURE_FLAGS + OPT_FIRST_COLUMN_TOGGLE_CUT_OFF];
// index = reinterpreted positions value = game_option or state
//" + OPT_FIRST_COLUMN_TOGGLE_CUT_OFF " to account for potential empty togglebox positions up to next whole column
int toggle_box_array[MAX_NUMBER_OF_OPTION_TOGGLES]; // index = option position on screen value = game_option or state
/////////////////////////////////
//
// Function ProtoTypes
//
/////////////////////////////////
BOOLEAN EnterScreen();
void RenderScreen();
void ExitScreen();
void HandleScreen();
void GetUserInput();
void SetToggleBoxes();
void SetExitScreen(UINT32 uiExitScreen);
void NextPage();
void PreviousPage();
void ConfirmQuitToMainMenuMessageBoxCallBack(UINT8 bExitValue);
void HandleOptionToggle(UINT8 Button_UserData_0, UINT8 Button_UserData_1, BOOLEAN fState, BOOLEAN fDown, BOOLEAN fPlaySound);
void HandleHighLightedText(BOOLEAN fHighLight);
void DrawLeftPanel();
/////////////////////////////////
//
// Code
//
/////////////////////////////////
UINT32 Init()
{
//Set so next time we come in, we can set up
gfFeaturesScreenEntry = TRUE;
//init rules and paging extent
Establish_Features_Screen_Rules();
Build_Features_List_Reinterpretation(); //need to calc paging max before next/prev button creation
return(TRUE);
}
UINT32 Handle()
{
StartFrameBufferRender();
if (gfFeaturesScreenEntry)
{
EnterScreen();
gfFeaturesScreenEntry = FALSE;
gfFeaturesScreenExit = FALSE;
gfRedrawFeaturesScreen = TRUE;
RenderScreen();
//Blit the background to the save buffer
BlitBufferToBuffer(guiRENDERBUFFER, guiSAVEBUFFER, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
InvalidateRegion(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
}
RestoreBackgroundRects();
GetUserInput();
RenderScreen();
HandleScreen();
if (gfRedrawFeaturesScreen)
{
RenderButtons();
gfRedrawFeaturesScreen = FALSE;
}
// render buttons marked dirty
MarkButtonsDirty();
RenderButtons();
// ATE: Put here to save RECTS before any fast help being drawn...
SaveBackgroundRects();
RenderButtonsFastHelp();
ExecuteBaseDirtyRectQueue();
EndFrameBufferRender();
if (gfFeaturesScreenExit)
{
ExitScreen();
gfFeaturesScreenExit = FALSE;
gfFeaturesScreenEntry = TRUE;
UnPauseGame();
}
return(guiFeaturesScreen);
}
UINT32 Shutdown()
{
return(TRUE);
}
void Establish_Features_Screen_Rules(void)
{
UINT16 counter;
// ary-05/05/2009 : note : pre-emptive definition of "game options render state". Show/Hide/etc options on option screen.
// : note : enum of states possible :
// : note : state -2 = is a state defined later, after rules build-up, and denotes the unused spots that exceed the final page.
// : note : state -1 = used in toggle_box_array, after rules build-up. and denotes the unused spots that are within last page.
// : note : state 0 = skip this option, consider it to be non-existant.. do not render..
// : note : state 1 = normal, default
// : note : state 2 = text only, no box, no option to toggle, a "header/divider" type rendering
//Re-init toggle_box_feature_rules[]
for (counter = 0; counter < NUM_FEATURE_FLAGS; counter++)
{
//this loop will re-initialize toggle_box_feature_rules[counter1] to "display as normally" state
toggle_box_feature_rules[counter] = 1;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
////// begining of features content rules ////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////
}
void Build_Features_List_Reinterpretation(void)
{
// This function fills out a recast of gGameSettings.fOptions[],
// it differs by constraint foun in Establish_Features_Screen_Rules()
INT16 counter1, counter2, index_of_last_valid_option;
for (counter1 = 0; counter1 < (NUM_FEATURE_FLAGS + OPT_FIRST_COLUMN_TOGGLE_CUT_OFF); counter1++)
{
toggle_box_gGameSettings_recast[counter1] = -2;
}
index_of_last_valid_option = 0; //track where inside the recast we ran out of actual options,
//we then pad the rest with -1's
//also, this is the basis for column counting
// ary-05/05/2009 : counter1 represents the position inside toggle_box_gGameSettings_recast[], we dont skip these until there are no more options
// : counter2 represents the position inside gGameSettings.fOptions[], skip invalids until valid or NUM_FEATURE_FLAGS
counter2 = 0; // init prior to the loop
for (counter1 = 0; counter1 < NUM_FEATURE_FLAGS; counter1++)
{
for (; counter2 < NUM_FEATURE_FLAGS; )
{
if (toggle_box_feature_rules[counter2]) // might be change to bit_vect, or some other mechanic, but for only 0 is not rendered
{
toggle_box_gGameSettings_recast[counter1] = counter2;
index_of_last_valid_option = counter1;
counter2++;
break;
}
counter2++;
}
}
// pick up final tail of toggle box up to the next whole column
if ((index_of_last_valid_option + 1) % OPT_FIRST_COLUMN_TOGGLE_CUT_OFF)
{
Max_Number_Of_Pages = ((index_of_last_valid_option + 1) / OPT_FIRST_COLUMN_TOGGLE_CUT_OFF) + 1;
for (counter1 = (index_of_last_valid_option + 1);
counter1 < (Max_Number_Of_Pages * OPT_FIRST_COLUMN_TOGGLE_CUT_OFF);
counter1++)
{
toggle_box_gGameSettings_recast[counter1] = -1;
}
}
else
{
Max_Number_Of_Pages = ((index_of_last_valid_option + 1) / OPT_FIRST_COLUMN_TOGGLE_CUT_OFF);
// no tail to fill out, index_of_last_valid_option is the last option up to a whole column
}
}
void Create_Toggle_Buttons(void)
{
UINT16 counter1;
UINT16 usPosY = 0, usBoxPosX, usTextPosX;
UINT16 usTextWidth, usTextHeight;
//
// Toggle Boxes
//
// Build up a set of options toggles for render and callbacks. and remember set for deletion of set.
//
// main events:
// fill toggle_box_feature_rules[] (content rules), and global state after conditions have been setup
// fill toggle_box_array[], with options based on content rule, or global rules
// show check_box images and text, create mouse regions, based on toggle_box_array[]
// see Destroy_Toggle_Buttons() for handling of deletion (this is all setup to prevent deletion of uncreated regions)
/////////////////////////////////////////////////////////////////////////////////////////////////////////
Establish_Features_Screen_Rules();
Build_Features_List_Reinterpretation(); // based on rules, build a options_screen version of gGameSetting[], and derive max_pages
// at this point we have an array that describes how the toggle boxes will be handled
// only thing left now is to describe the array of toggle_boxes that is currently about to be displayed on screen
// this should be easy enough, just offset into toggle_box_gGameSettings_recast, and direct copy into toggle_box_array
Current_First_Option_Index = OptionsList_Column_Offset * OPT_FIRST_COLUMN_TOGGLE_CUT_OFF;
for (counter1 = 0; counter1 < MAX_NUMBER_OF_OPTION_TOGGLES; counter1++)
{
//counter1 represents index within toggle_box_array, we have to handle each one
toggle_box_array[counter1] = toggle_box_gGameSettings_recast[counter1 + Current_First_Option_Index];
}
// at this point toggle_box_array has been built properly to content rules.
// now it is time to create/render/keep track of the toggle box options
usTextHeight = GetFontHeight(OPT_MAIN_FONT);
for (counter1 = 0; counter1 < MAX_NUMBER_OF_OPTION_TOGGLES; counter1++)
{
// skip creating toggle box for cases : no option , option supression
if (toggle_box_array[counter1] < 0) // skip every thing for -1
{
continue;
}
if (toggle_box_feature_rules[toggle_box_array[counter1]] == 2) //skip creating the toggle box | mouse regions
{ // this case isnt creating toggle box, but is still using positions on the list, so adjust the graphics cursor
// init or re-init base points of where graphics/text/regions are going to be placed
if (counter1 % OPT_FIRST_COLUMN_TOGGLE_CUT_OFF == 0)
{
//reset the vertical position
usPosY = OPT_TOGGLE_BOX_FIRST_COLUMN_START_Y;
}
//skip over vertical portion
usPosY += OPT_GAP_BETWEEN_TOGGLE_BOXES;
//init/reset horizontal
if (counter1 < OPT_FIRST_COLUMN_TOGGLE_CUT_OFF)
{
usBoxPosX = OPT_TOGGLE_BOX_FIRST_COLUMN_X;
usTextPosX = OPT_TOGGLE_BOX_FIRST_COL_TEXT_X;
}
else
{
usBoxPosX = OPT_TOGGLE_BOX_SECOND_COLUMN_X;
usTextPosX = OPT_TOGGLE_BOX_SECOND_TEXT_X;
}
continue;
}
// init or re-init base points of where graphics/text/regions are going to be placed
if (counter1 % OPT_FIRST_COLUMN_TOGGLE_CUT_OFF == 0)
{
//reset the vertical position
usPosY = OPT_TOGGLE_BOX_FIRST_COLUMN_START_Y;
}
if (counter1 < OPT_FIRST_COLUMN_TOGGLE_CUT_OFF)
{
usBoxPosX = OPT_TOGGLE_BOX_FIRST_COLUMN_X;
usTextPosX = OPT_TOGGLE_BOX_FIRST_COL_TEXT_X;
}
else
{
usBoxPosX = OPT_TOGGLE_BOX_SECOND_COLUMN_X;
usTextPosX = OPT_TOGGLE_BOX_SECOND_TEXT_X;
}
// here is the point when the graphical toggle is drawn and associated with a mouse region
//Check box ID stored to guiFeaturesToggles[] by toggle option
guiFeaturesToggles[counter1] = CreateCheckBoxButton(usBoxPosX, usPosY,
"INTERFACE\\OptionsCheckBoxes_12x12.sti",
MSYS_PRIORITY_HIGH + 10,
BtnOptionsTogglesCallback);
//set the toggle box's UserData[0] to the toggle_box index (which toggle box it is)
//set the toggle box's UserData[1] to the option's index (which option the toggle box represents)
MSYS_SetBtnUserData(guiFeaturesToggles[counter1], 0, counter1);
MSYS_SetBtnUserData(guiFeaturesToggles[counter1], 1, toggle_box_array[counter1]);
usTextWidth = StringPixLength(z113FeaturesToggleText[toggle_box_array[counter1]], OPT_MAIN_FONT);
if (usTextWidth > OPT_TOGGLE_BOX_TEXT_WIDTH)
{
//Get how many lines will be used to display the string, without displaying the string
UINT8 ubNumLines = (UINT8)(DisplayWrappedString(0, 0, OPT_TOGGLE_BOX_TEXT_WIDTH, 2, OPT_MAIN_FONT, OPT_HIGHLIGHT_COLOR,
z113FeaturesToggleText[toggle_box_array[counter1]], FONT_MCOLOR_BLACK, TRUE,
LEFT_JUSTIFIED | DONT_DISPLAY_TEXT) / GetFontHeight(OPT_MAIN_FONT));
usTextWidth = OPT_TOGGLE_BOX_TEXT_WIDTH;
//Create mouse regions for the option toggle text
MSYS_DefineRegion(&gSelectedOptionTextRegion[counter1], usBoxPosX + 13, usPosY,
(usTextPosX + usTextWidth), (UINT16)(usPosY + usTextHeight * ubNumLines), MSYS_PRIORITY_HIGH,
CURSOR_NORMAL, SelectedOptionTextRegionMovementCallBack, SelectedOptionTextRegionCallBack);
MSYS_AddRegion(&gSelectedOptionTextRegion[counter1]);
//set the text's region's UserData[0] to the toggle_box index (which toggle box it is)
//set the text's region's UserData[1] to the option's index (which option the toggle box represents)
MSYS_SetRegionUserData(&gSelectedOptionTextRegion[counter1], 0, counter1);
MSYS_SetRegionUserData(&gSelectedOptionTextRegion[counter1], 1, toggle_box_array[counter1]);
}
else
{
//Create mouse regions for the option toggle text
MSYS_DefineRegion(&gSelectedOptionTextRegion[counter1], usBoxPosX + 13, usPosY,
(usTextPosX + usTextWidth), (UINT16)(usPosY + usTextHeight), MSYS_PRIORITY_HIGH,
CURSOR_NORMAL, SelectedOptionTextRegionMovementCallBack, SelectedOptionTextRegionCallBack);
MSYS_AddRegion(&gSelectedOptionTextRegion[counter1]);
//set the text's region's UserData[0] to the toggle_box index (which toggle box it is)
//set the text's region's UserData[1] to the option's index (which option the toggle box represents)
MSYS_SetRegionUserData(&gSelectedOptionTextRegion[counter1], 0, counter1);
MSYS_SetRegionUserData(&gSelectedOptionTextRegion[counter1], 1, toggle_box_array[counter1]);
}
SetRegionFastHelpText(&gSelectedOptionTextRegion[counter1], z113FeaturesHelpText[toggle_box_array[counter1]]);
SetButtonFastHelpText(guiFeaturesToggles[counter1], z113FeaturesHelpText[toggle_box_array[counter1]]);
usPosY += OPT_GAP_BETWEEN_TOGGLE_BOXES;
}
Buttons_Exist_State = 1; // ok check boxes now exist, its safe to allow text highlights
}
void Destroy_Toggle_Buttons(void)
{
UINT8 counter1;
Buttons_Exist_State = 0; // set this to off, prevents HandleScreen() from causing a CTD when tring to
// higlight text for non-existing checkboxes
//Remove the toggle buttons
for (counter1 = 0; counter1 < MAX_NUMBER_OF_OPTION_TOGGLES; counter1++)
{
if (toggle_box_array[counter1] == -1)
{
// dont delete non existing buttons
continue;
}
if (toggle_box_feature_rules[toggle_box_array[counter1]] == 2)
{
// dont delete non existing buttons
continue;
}
RemoveButton(guiFeaturesToggles[counter1]);
MSYS_RemoveRegion(&gSelectedOptionTextRegion[counter1]);
}
}
BOOLEAN EnterScreen()
{
VOBJECT_DESC VObjectDesc;
//if we are coming from mapscreen
if (guiTacticalInterfaceFlags & INTERFACE_MAPSCREEN)
{
guiTacticalInterfaceFlags &= ~INTERFACE_MAPSCREEN;
gfEnteredFromMapScreen = TRUE;
}
// Stop ambients...
StopAmbients();
guiFeaturesScreen = FEATURES_SCREEN;
if (gfExitFeaturesDueToMessageBox)
{
gfRedrawFeaturesScreen = TRUE;
gfExitFeaturesDueToMessageBox = FALSE;
return(TRUE);
}
gfExitFeaturesDueToMessageBox = FALSE;
// load the options screen background graphic and add it
VObjectDesc.fCreateFlags = VOBJECT_CREATE_FROMFILE;
FilenameForBPP("INTERFACE\\OptionScreenBase.sti", VObjectDesc.ImageFile);
CHECKF(AddVideoObject(&VObjectDesc, &guiFeaturesBackGroundImage));
// load button, title graphic and add it
VObjectDesc.fCreateFlags = VOBJECT_CREATE_FROMFILE;
GetMLGFilename(VObjectDesc.ImageFile, MLG_OPTIONHEADER);
CHECKF(AddVideoObject(&VObjectDesc, &guiFeaturesAddOnImages));
//Save game button
giOptionsButtonImages = LoadButtonImage("INTERFACE\\OptionScreenAddons2.sti", -1, 2, -1, 3, -1);
guiOptGotoSaveGameBtn = CreateIconAndTextButton(giOptionsButtonImages, zOptionsText[OPT_SAVE_GAME], OPT_BUTTON_FONT2,
OPT_BUTTON_ON_COLOR, DEFAULT_SHADOW,
OPT_BUTTON_OFF_COLOR, DEFAULT_SHADOW,
TEXT_CJUSTIFIED,
OPT_SAVE_BTN_X, OPT_SAVE_BTN_Y, BUTTON_TOGGLE, MSYS_PRIORITY_HIGH,
DEFAULT_MOVE_CALLBACK, BtnOptGotoSaveGameCallback);
SpecifyDisabledButtonStyle(guiOptGotoSaveGameBtn, DISABLED_STYLE_HATCHED);
if (guiPreviousScreen == MAINMENU_SCREEN || !CanGameBeSaved() || guiPreviousScreen == GAME_INIT_OPTIONS_SCREEN)
{
DisableButton(guiOptGotoSaveGameBtn);
}
//Load game button
giGotoLoadBtnImage = UseLoadedButtonImage(giOptionsButtonImages, -1, 2, -1, 3, -1);
guiOptGotoLoadGameBtn = CreateIconAndTextButton(giGotoLoadBtnImage, zOptionsText[OPT_LOAD_GAME], OPT_BUTTON_FONT2,
OPT_BUTTON_ON_COLOR, DEFAULT_SHADOW,
OPT_BUTTON_OFF_COLOR, DEFAULT_SHADOW,
TEXT_CJUSTIFIED,
OPT_LOAD_BTN_X, OPT_LOAD_BTN_Y, BUTTON_TOGGLE, MSYS_PRIORITY_HIGH,
DEFAULT_MOVE_CALLBACK, BtnOptGotoLoadGameCallback);
//Quit to main menu button
giQuitBtnImage = UseLoadedButtonImage(giOptionsButtonImages, -1, 2, -1, 3, -1);
guiQuitButton = CreateIconAndTextButton(giQuitBtnImage, zOptionsText[OPT_MAIN_MENU], OPT_BUTTON_FONT2,
OPT_BUTTON_ON_COLOR, DEFAULT_SHADOW,
OPT_BUTTON_OFF_COLOR, DEFAULT_SHADOW,
TEXT_CJUSTIFIED,
OPT_QUIT_BTN_X, OPT_QUIT_BTN_Y, BUTTON_TOGGLE, MSYS_PRIORITY_HIGH,
DEFAULT_MOVE_CALLBACK, BtnOptQuitCallback);
SpecifyDisabledButtonStyle(guiQuitButton, DISABLED_STYLE_HATCHED);
// Options Button
giOptionsBtnImage = UseLoadedButtonImage(giOptionsButtonImages, -1, 2, -1, 3, -1);
guiOptionsButton = CreateIconAndTextButton(giOptionsBtnImage, zOptionsText[OPT_OPTIONS], OPT_BUTTON_FONT2,
OPT_BUTTON_ON_COLOR, DEFAULT_SHADOW,
OPT_BUTTON_OFF_COLOR, DEFAULT_SHADOW,
TEXT_CJUSTIFIED,
OPT_SWAP_BTN_X, OPT_SWAP_BTN_Y, BUTTON_TOGGLE, MSYS_PRIORITY_HIGH,
DEFAULT_MOVE_CALLBACK, BtnOptionsCallback);
// ary-05/05/2009 : need more option screen toggles : Add in buttons that allow for options column paging
// Previous Column of options
giOptPrevBtnImage = UseLoadedButtonImage(giOptionsButtonImages, -1, 2, -1, 3, -1);
guiOptPrevButton = CreateIconAndTextButton(giOptPrevBtnImage, zOptionsText[OPT_PREV], OPT_BUTTON_FONT2,
OPT_BUTTON_ON_COLOR, DEFAULT_SHADOW,
OPT_BUTTON_OFF_COLOR, DEFAULT_SHADOW,
TEXT_CJUSTIFIED,
OPT_PREV_BTN_X, OPT_PREV_BTN_Y, BUTTON_TOGGLE, MSYS_PRIORITY_HIGH,
DEFAULT_MOVE_CALLBACK, BtnOptPrevCallback);
SpecifyDisabledButtonStyle(guiOptPrevButton, DISABLED_STYLE_HATCHED);
if (OptionsList_Column_Offset == 0)
{
DisableButton(guiOptPrevButton);
}
// Next Column of options
giOptNextBtnImage = UseLoadedButtonImage(giOptionsButtonImages, -1, 2, -1, 3, -1);
guiOptNextButton = CreateIconAndTextButton(giOptNextBtnImage, zOptionsText[OPT_NEXT], OPT_BUTTON_FONT2,
OPT_BUTTON_ON_COLOR, DEFAULT_SHADOW,
OPT_BUTTON_OFF_COLOR, DEFAULT_SHADOW,
TEXT_CJUSTIFIED,
OPT_NEXT_BTN_X, OPT_NEXT_BTN_Y, BUTTON_TOGGLE, MSYS_PRIORITY_HIGH,
DEFAULT_MOVE_CALLBACK, BtnOptNextCallback);
SpecifyDisabledButtonStyle(guiOptNextButton, DISABLED_STYLE_HATCHED);
if (OptionsList_Column_Offset >= (Max_Number_Of_Pages - 2))// ary-05/05/2009 : "Max_Number_Of_Pages-2" becaues each "page" = 2 "columns"
{
DisableButton(guiOptNextButton);
}
//Done button
giDoneBtnImage = UseLoadedButtonImage(giOptionsButtonImages, -1, 2, -1, 3, -1);
guiDoneButton = CreateIconAndTextButton(giDoneBtnImage, zOptionsText[OPT_DONE], OPT_BUTTON_FONT2,
OPT_BUTTON_ON_COLOR, DEFAULT_SHADOW,
OPT_BUTTON_OFF_COLOR, DEFAULT_SHADOW,
TEXT_CJUSTIFIED,
OPT_DONE_BTN_X, OPT_DONE_BTN_Y, BUTTON_TOGGLE, MSYS_PRIORITY_HIGH,
DEFAULT_MOVE_CALLBACK, BtnDoneCallback);
Create_Toggle_Buttons(); // ary-05/05/2009 : moved block out of func
//Create a mouse region so when the user leaves a togglebox text region we can detect it then unselect the region
MSYS_DefineRegion(&gSelectedToggleBoxAreaRegion, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, MSYS_PRIORITY_NORMAL,
CURSOR_NORMAL, SelectedToggleBoxAreaRegionMovementCallBack, MSYS_NO_CALLBACK);
MSYS_AddRegion(&gSelectedToggleBoxAreaRegion);
//Remove the mouse region over the clock
RemoveMouseRegionForPauseOfClock();
//Draw the screen
gfRedrawFeaturesScreen = TRUE;
//Set the screen toggle boxes
SetToggleBoxes();
DisableScrollMessages();
//reset
gbHighLightedOptionText = -1;
return(TRUE);
}
void ExitScreen()
{
if (gfExitFeaturesDueToMessageBox)
{
gfFeaturesScreenExit = FALSE;
if (!gfExitFeaturesAfterMessageBox)
return;
gfExitFeaturesAfterMessageBox = FALSE;
gfExitFeaturesDueToMessageBox = FALSE;
}
//The save the current settings to disk
SaveFeatureFlags();
if (guiFeaturesScreen == GAME_SCREEN)
{
EnterTacticalScreen();
}
if (guiFeaturesScreen == SAVE_LOAD_SCREEN && guiPreviousScreen == MAINMENU_SCREEN)
{
giMAXIMUM_NUMBER_OF_PLAYER_SLOTS = CODE_MAXIMUM_NUMBER_OF_PLAYER_SLOTS;
InitDependingGameStyleOptions();
}
RemoveButton(guiOptGotoSaveGameBtn);
RemoveButton(guiOptGotoLoadGameBtn);
RemoveButton(guiQuitButton);
RemoveButton(guiOptionsButton);
RemoveButton(guiOptNextButton);// ary-05/05/2009 : more option screen toggles
RemoveButton(guiOptPrevButton);
RemoveButton(guiDoneButton);
UnloadButtonImage(giOptionsButtonImages);
UnloadButtonImage(giGotoLoadBtnImage);
UnloadButtonImage(giQuitBtnImage);
UnloadButtonImage(giOptionsBtnImage);
UnloadButtonImage(giOptNextBtnImage);// ary-05/05/2009 : more option screen toggles
UnloadButtonImage(giOptPrevBtnImage);
UnloadButtonImage(giDoneBtnImage);
DeleteVideoObjectFromIndex(guiFeaturesBackGroundImage);
DeleteVideoObjectFromIndex(guiFeaturesAddOnImages);
Destroy_Toggle_Buttons(); // ary-05/05/2009 : moved block out of func
MSYS_RemoveRegion(&gSelectedToggleBoxAreaRegion);
//if we are coming from mapscreen
if (gfEnteredFromMapScreen)
{
gfEnteredFromMapScreen = FALSE;
guiTacticalInterfaceFlags |= INTERFACE_MAPSCREEN;
}
}
void HandleScreen()
{
HandleHighLightedText(TRUE);
}
void RenderScreen()
{
HVOBJECT hPixHandle;
UINT16 usPosY = 0, usPosX;
UINT16 usWidth = 0;
UINT8 count;
CHAR16 sPage[60];
//Get and display the background image
if (GetVideoObject(&hPixHandle, guiFeaturesBackGroundImage))
BltVideoObject(FRAME_BUFFER, hPixHandle, 0, iScreenWidthOffset, iScreenHeightOffset, VO_BLT_SRCTRANSPARENCY, NULL);
//Get and display the titla image
if (GetVideoObject(&hPixHandle, guiFeaturesAddOnImages))
{
BltVideoObject(FRAME_BUFFER, hPixHandle, 0, iScreenWidthOffset, iScreenHeightOffset, VO_BLT_SRCTRANSPARENCY, NULL);
BltVideoObject(FRAME_BUFFER, hPixHandle, 1, iScreenWidthOffset, iScreenHeightOffset + 434, VO_BLT_SRCTRANSPARENCY, NULL);
}
DrawLeftPanel();
//
// Text for the toggle boxes
//
//Display the First column of toggles
for (count = 0; count < MAX_NUMBER_OF_OPTION_TOGGLES; count++)
{
if (toggle_box_array[count] == -1)
{
break;
}// no text for non existing buttons
//setup base points of where graphics/text/regions are going to be placed
if (count % OPT_FIRST_COLUMN_TOGGLE_CUT_OFF == 0)
{
//reset the vertical position
usPosY = OPT_TOGGLE_BOX_FIRST_COLUMN_START_Y + OPT_TOGGLE_TEXT_OFFSET_Y;
}
if (count < OPT_FIRST_COLUMN_TOGGLE_CUT_OFF)
{
usPosX = OPT_TOGGLE_BOX_FIRST_COL_TEXT_X;
}
else
{
usPosX = OPT_TOGGLE_BOX_SECOND_TEXT_X;
}
usWidth = StringPixLength(z113FeaturesToggleText[toggle_box_array[count]], OPT_MAIN_FONT);
// set the colour of the toggle box text
UINT8 fontColor = (count == 0 && OptionsList_Column_Offset == 0) || gGameSettings.fFeatures[FF_FEATURES_SCREEN] ?
OPT_MAIN_COLOR : FONT_GRAY7;
//if the string is going to wrap, move the string up a bit
if (usWidth > OPT_TOGGLE_BOX_TEXT_WIDTH)
DisplayWrappedString(usPosX, usPosY, OPT_TOGGLE_BOX_TEXT_WIDTH, 2, OPT_MAIN_FONT, fontColor,
z113FeaturesToggleText[toggle_box_array[count]], FONT_MCOLOR_BLACK, FALSE, LEFT_JUSTIFIED);
else
DrawTextToScreen(z113FeaturesToggleText[toggle_box_array[count]], usPosX, usPosY, 0,
OPT_MAIN_FONT, fontColor, FONT_MCOLOR_BLACK, FALSE, LEFT_JUSTIFIED);
usPosY += OPT_GAP_BETWEEN_TOGGLE_BOXES;
}
//Display the option page numbers
swprintf(sPage, L"%d / %d", OptionsList_Column_Offset + 1, max(1, Max_Number_Of_Pages - 1));
DisplayWrappedString(OPT_PAGE_X, OPT_PAGE_Y, OPT_SLIDER_TEXT_WIDTH, 2, OPT_BUTTON_FONT2, OPT_MAIN_COLOR,
sPage, FONT_MCOLOR_BLACK, FALSE, RIGHT_JUSTIFIED);
//Set the screen toggle boxes
SetToggleBoxes();
InvalidateRegion(OPTIONS__TOP_LEFT_X, OPTIONS__TOP_LEFT_Y, OPTIONS__BOTTOM_RIGHT_X, OPTIONS__BOTTOM_RIGHT_Y);
}
void GetUserInput()
{
InputAtom Event;
POINT MousePos;
GetCursorPos(&MousePos);
ScreenToClient(ghWindow, &MousePos); // In window coords!
while (DequeueSpecificEvent(&Event, KEY_DOWN | KEY_UP | KEY_REPEAT))
{
if (!HandleTextInput(&Event) && Event.usEvent == KEY_DOWN)
{
switch (Event.usParam)
{
case 'q':
case 'Q':
//Confirm the Exit to the main menu screen
DoMessageBox(MSG_BOX_BASIC_STYLE, zOptionsText[OPT_RETURN_TO_MAIN], FEATURES_SCREEN, MSG_BOX_FLAG_YESNO,
ConfirmQuitToMainMenuMessageBoxCallBack);
break;
case ESC:
SetExitScreen(guiPreviousScreen);
break;
//Enter the save game screen
case 's':
case 'S':
//if the save game button isnt disabled
if (ButtonList[guiOptGotoSaveGameBtn]->uiFlags & BUTTON_ENABLED)
{
SetExitScreen(SAVE_LOAD_SCREEN);
gfSaveGame = TRUE;
}
break;
//Enter the Load game screen
case 'l':
case 'L':
SetExitScreen(SAVE_LOAD_SCREEN);
gfSaveGame = FALSE;
break;
// toggle between features and options screen
case TAB:
SetExitScreen(OPTIONS_SCREEN);
break;
// page left
case 'a':
case 'A':
case LEFTARROW:
PreviousPage();
break;
// page right
case 'd':
case 'D':
case RIGHTARROW:
NextPage();
break;
#ifdef JA2TESTVERSION
case 'r':
gfRedrawFeaturesScreen = TRUE;
break;
case 'i':
InvalidateRegion(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
break;
//Test keys
case 'y':
{
static UINT32 uiTest2 = NO_SAMPLE;
if (!SoundIsPlaying(uiTest2))
uiTest2 = PlayJA2SampleFromFile("Sounds\\RAID Dive.wav", RATE_11025, HIGHVOLUME, 1, MIDDLEPAN);
}
break;
case 't':
{
/*
{
CHAR8 zCdromRootDrive[512];
HWFILE hFile;
if( !GetCdromLocationFromIniFile( zCdromRootDrive ) )
return;
//Check if a file exists on the cdrom
sprintf( zCdromRootDrive, "%sData\\NPC_Speech.slf", zCdromRootDrive );
// if( FileExistsNoDB( zCdromRootDrive ) )
hFile = FileOpen( zCdromRootDrive, FILE_ACCESS_READ | FILE_OPEN_EXISTING, FALSE );
if( hFile != 0 )
{
FileClose( hFile );
sprintf( zCdromRootDrive, "%sData\\NPC_Speech.slf", zCdromRootDrive );
}
else
{
sprintf( zCdromRootDrive, "%sData\\NPC_Speech.slf", zCdromRootDrive );
}
uiLastTimeToCheckCDromDrive = GetJA2Clock();
}
*/
}
break;
case 'z':
SetErrorMode(SEM_FAILCRITICALERRORS);
break;
//case 'q':
// ShouldMercSayPrecedentToRepeatOneSelf( 11, 99 );
//break;
#endif
}
}
}
// mousewheel input
if (OptionsList_Column_Offset > 0)
{
BOOL act = FALSE;
// check general screen mouseregion
if (gSelectedToggleBoxAreaRegion.WheelState > 0)
{
act = TRUE;
}
// check toggle box mouseregions
for (int i = 0; i < MAX_NUMBER_OF_OPTION_TOGGLES; ++i)
{
if (act) break;
if (gSelectedOptionTextRegion[i].WheelState > 0)
{
act = TRUE;
}
}
if (act) PreviousPage();
}
if (OptionsList_Column_Offset < Max_Number_Of_Pages-2)
{
BOOL act = FALSE;
// check general screen mouseregion
if (gSelectedToggleBoxAreaRegion.WheelState < 0)
{
act = TRUE;
}
// check toggle box mouseregions
for (int i = 0; i < MAX_NUMBER_OF_OPTION_TOGGLES; ++i)
{
if (act) break;
if (gSelectedOptionTextRegion[i].WheelState < 0)
{
act = TRUE;
}
}
if (act) NextPage();
}
}
void NextPage()
{
ExitScreen();
OptionsList_Column_Offset++;
if (OptionsList_Column_Offset >= Max_Number_Of_Pages - 1) // ary-05/05/2009 : Max_Number_Of_Pages
OptionsList_Column_Offset = (Max_Number_Of_Pages - 2);
Init();
}
void PreviousPage()
{
ExitScreen();
OptionsList_Column_Offset--;
if(OptionsList_Column_Offset < 0)
OptionsList_Column_Offset = 0;
Init();
}
void SetExitScreen(UINT32 uiExitScreen)
{
OptionsList_Column_Offset = 0; // reset the pager till next visit
guiFeaturesScreen = uiExitScreen;
gfFeaturesScreenExit = TRUE;
}
void BtnOptGotoSaveGameCallback(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);
SetExitScreen(SAVE_LOAD_SCREEN);
gfSaveGame = TRUE;
InvalidateRegion(btn->Area.RegionTopLeftX, btn->Area.RegionTopLeftY, btn->Area.RegionBottomRightX, btn->Area.RegionBottomRightY);
}
if (reason & MSYS_CALLBACK_REASON_LOST_MOUSE)
{