1 /*
2  * Copyright (C) Volition, Inc. 1999.  All rights reserved.
3  *
4  * All source code herein is the property of Volition, Inc. You may not sell
5  * or otherwise commercially exploit the source or things you created based on the
6  * source.
7  *
8 */
9 
10 
11 
12 #include "gamesequence/gamesequence.h"
13 #include "graphics/2d.h"
14 #include "menuui/snazzyui.h"
15 #include "menuui/trainingmenu.h"
16 
17 
18 
19 // global to this file
20 static int trainingMenuBitmap;
21 static int trainingMenuMask;
22 static bitmap* trainingMenuMaskPtr;
23 static ubyte* mask_data;
24 static int Training_mask_w, Training_mask_h;
25 static MENU_REGION region[TRAINING_MENU_MAX_CHOICES];
26 static int num_training;
27 
28 static int training_menu_inited=0;
29 
training_menu_init()30 void training_menu_init()
31 {
32 	char background_img_filename[MAX_FILENAME_LEN];
33 	char background_mask_filename[MAX_FILENAME_LEN];
34 
35 	snazzy_menu_init();
36 
37 	read_menu_tbl(NOX("TRAINING MENU"), background_img_filename, background_mask_filename, region, &num_training);
38 
39 	// load in the background bitmap (filenames are hard-coded temporarily)
40 	trainingMenuBitmap = bm_load(background_img_filename);
41 	if (trainingMenuBitmap < 0) {
42 		Error(LOCATION,"Could not load in %s!",background_img_filename);
43 	}
44 
45 	trainingMenuMask = bm_load(background_mask_filename);
46 	Training_mask_w = -1;
47 	Training_mask_h = -1;
48 
49 	if (trainingMenuMask < 0) {
50 		Error(LOCATION,"Could not load in %s!",background_mask_filename);
51 	}
52 	else {
53 		// get a pointer to bitmap by using bm_lock()
54 		trainingMenuMaskPtr = bm_lock(trainingMenuMask, 8, BMP_AABITMAP | BMP_MASK_BITMAP);
55 		mask_data = (ubyte*)trainingMenuMaskPtr->data;
56 		bm_get_info(trainingMenuMask, &Training_mask_w, &Training_mask_h);
57 	}
58 }
59 
training_menu_close()60 void training_menu_close()
61 {
62 	if (training_menu_inited) {
63 		// done with the bitmap, so unlock it
64 		bm_unlock(trainingMenuMask);
65 
66 		// unload the bitmaps
67 		bm_release(trainingMenuBitmap);
68 		bm_release(trainingMenuMask);
69 
70 		training_menu_inited = 0;
71 		snazzy_menu_close();
72 	}
73 }
74 
training_menu_do_frame(float)75 void training_menu_do_frame(float  /*frametime*/)
76 {
77 	int training_menu_choice;
78 
79 	if (!training_menu_inited) {
80 		training_menu_init();
81 		training_menu_inited=1;
82 	}
83 
84 	gr_reset_clip();
85 	gr_set_color(0,0,0);
86 	GR_MAYBE_CLEAR_RES(trainingMenuBitmap);
87 	// set the background
88 	if(trainingMenuBitmap != -1){
89 		gr_set_bitmap(trainingMenuBitmap);
90 		gr_bitmap(0,0,GR_RESIZE_MENU);
91 	}
92 
93 	int snazzy_action = -1;
94 	training_menu_choice = snazzy_menu_do(mask_data, Training_mask_w, Training_mask_h, num_training, region, &snazzy_action);
95 	if ( snazzy_action != SNAZZY_CLICKED ){
96 		training_menu_choice = -1;
97 	}
98 
99 	switch (training_menu_choice) {
100 
101 		case TRAINING_MENU_TRAINING_MISSIONS_MASK:
102 			break;
103 		case TRAINING_MENU_REPLAY_MISSIONS_MASK:
104 			// TODO: load the mission and start the briefing
105 			break;
106 		case TRAINING_MENU_RETURN_MASK:
107 		case ESC_PRESSED:
108 			gameseq_post_event(GS_EVENT_MAIN_MENU);
109 			break;
110 		case -1:
111 			// nothing selected
112 			break;
113 		default:
114 			Error(LOCATION, "Unknown option %d in training menu screen", training_menu_choice );
115 			break;
116 
117 	} // end switch
118 
119 	gr_flip();
120 }
121