]> icculus.org git repositories - taylor/freespace2.git/blob - src/menuui/trainingmenu.cpp
Initial revision
[taylor/freespace2.git] / src / menuui / trainingmenu.cpp
1 /*
2  * $Logfile: /Freespace2/code/MenuUI/TrainingMenu.cpp $
3  * $Revision$
4  * $Date$
5  * $Author$
6  *
7  * C module that contains functions to drive the Training user interface
8  *
9  * $Log$
10  * Revision 1.1  2002/05/03 03:28:09  root
11  * Initial revision
12  *
13  * 
14  * 6     7/16/99 1:49p Dave
15  * 8 bit aabitmaps. yay.
16  * 
17  * 5     1/30/99 5:08p Dave
18  * More new hi-res stuff.Support for nice D3D textures.
19  * 
20  * 4     12/18/98 1:13a Dave
21  * Rough 1024x768 support for Direct3D. Proper detection and usage through
22  * the launcher.
23  * 
24  * 3     11/30/98 1:07p Dave
25  * 16 bit conversion, first run.
26  * 
27  * 2     10/07/98 10:53a Dave
28  * Initial checkin.
29  * 
30  * 1     10/07/98 10:49a Dave
31  * 
32  * 22    2/23/98 6:55p Lawrance
33  * Rip out obsolete code.
34  * 
35  * 21    2/22/98 4:17p John
36  * More string externalization classification... 190 left to go!
37  * 
38  * 20    12/06/97 1:11a Lawrance
39  * make a general interface for help overlays
40  * 
41  * 19    12/05/97 2:39p Lawrance
42  * added some different sounds to main hall, add support for looping
43  * ambient sounds
44  * 
45  * 18    11/19/97 8:36p Dave
46  * Removed references to MainMenu.h
47  * 
48  * 17    9/03/97 4:32p John
49  * changed bmpman to only accept ani and pcx's.  made passing .pcx or .ani
50  * to bm_load functions not needed.   Made bmpman keep track of palettes
51  * for bitmaps not mapped into game palettes.
52  * 
53  * 16    8/31/97 6:38p Lawrance
54  * pass in frametime to do_frame loop
55  * 
56  * 15    6/12/97 2:50a Lawrance
57  * bm_unlock() now passed bitmap number, not pointer
58  * 
59  * 14    5/12/97 12:27p John
60  * Restructured Graphics Library to add support for multiple renderers.
61  * 
62  * 13    2/25/97 11:11a Lawrance
63  * adding more functionality needed for ship selection screen
64  * 
65  * 12    12/10/96 4:18p Lawrance
66  * added snazzy_menu_close() call and integrated with existing menus
67  * 
68  * 11    11/29/96 11:47a Lawrance
69  * removed out-dated comments
70  * 
71  * 10    11/21/96 7:14p Lawrance
72  * converted menu code to use a file (menu.tbl) to get the data for the
73  * menu
74  * 
75  * 9     11/20/96 12:33p Lawrance
76  * fixed problem when index for adding regions was not being initalized to
77  * 0 in the menu init() function
78  * 
79  * 8     11/19/96 5:20p Lawrance
80  * fixed state problem that came up as a result of menu code re-work
81  * 
82  * 7     11/15/96 12:09p John
83  * Added new UI code.  Made mouse not return Enter when you click it.
84  * Changed the doSnazzyUI function and names to be snazzy_menu_xxx.   
85  * 
86  * 6     11/13/96 5:08p Lawrance
87  * fixed up close functions to only free stuff if it was actually
88  * allocated  duh
89  * 
90  * 5     11/13/96 4:02p Lawrance
91  * complete over-haul of the menu system and the states associated with
92  * them
93  * 
94  * 4     11/13/96 8:32a Lawrance
95  * streamlined menu code
96  * 
97  * 3     11/08/96 4:57p Lawrance
98  * integrated playing previous mission code with latest goal code
99  * 
100  * 2     11/05/96 1:54p Lawrance
101  * 
102  * 1     11/05/96 1:11p Lawrance
103  * files for different game menus
104  *
105  * $NoKeywords: $
106  *
107 */
108
109 #include "gamesequence.h"
110 #include "trainingmenu.h"
111 #include "2d.h"
112 #include "snazzyui.h"
113 #include "managepilot.h"
114 #include "missionload.h"
115 #include "key.h"
116 #include "bmpman.h"
117 #include "mainhallmenu.h"
118
119 // global to this file
120 static int trainingMenuBitmap;
121 static int trainingMenuMask;
122 static bitmap* trainingMenuMaskPtr;
123 static ubyte* mask_data;
124 static int Training_mask_w, Training_mask_h;
125 static MENU_REGION region[TRAINING_MENU_MAX_CHOICES];
126 static int num_training;
127
128 static int training_menu_inited=0;
129
130 void training_menu_init()
131 {
132         char background_img_filename[MAX_FILENAME_LEN];
133         char background_mask_filename[MAX_FILENAME_LEN];        
134
135         snazzy_menu_init();
136
137         read_menu_tbl(NOX("TRAINING MENU"), background_img_filename, background_mask_filename, region, &num_training);
138
139         // load in the background bitmap (filenames are hard-coded temporarily)
140         trainingMenuBitmap = bm_load(background_img_filename);
141         if (trainingMenuBitmap < 0) {
142                 Error(LOCATION,"Could not load in %s!",background_img_filename);
143         }
144
145         trainingMenuMask = bm_load(background_mask_filename);
146         Training_mask_w = -1;
147         Training_mask_h = -1;
148
149         if (trainingMenuMask < 0) {
150                 Error(LOCATION,"Could not load in %s!",background_mask_filename);
151         }
152         else {
153                 // get a pointer to bitmap by using bm_lock()
154                 trainingMenuMaskPtr = bm_lock(trainingMenuMask, 8, BMP_AABITMAP);
155                 mask_data = (ubyte*)trainingMenuMaskPtr->data;          
156                 bm_get_info(trainingMenuMask, &Training_mask_w, &Training_mask_h);
157         }
158 }
159
160 void training_menu_close()
161 {
162         if (training_menu_inited) {
163                 // done with the bitmap, so unlock it
164                 bm_unlock(trainingMenuMask);
165
166                 // unload the bitmaps
167                 bm_unload(trainingMenuBitmap);
168                 bm_unload(trainingMenuMask);
169
170                 training_menu_inited = 0;
171                 snazzy_menu_close();
172         }
173 }
174
175 void training_menu_do_frame(float frametime)
176 {
177         int training_menu_choice;       
178
179         if (!training_menu_inited) {
180                 training_menu_init();
181                 training_menu_inited=1;
182         }
183
184         gr_reset_clip();
185         gr_set_color(0,0,0);
186         GR_MAYBE_CLEAR_RES(trainingMenuBitmap); 
187         // set the background
188         if(trainingMenuBitmap != -1){
189                 gr_set_bitmap(trainingMenuBitmap);
190                 gr_bitmap(0,0);
191         }
192
193         int snazzy_action = -1;
194         training_menu_choice = snazzy_menu_do(mask_data, Training_mask_w, Training_mask_h, num_training, region, &snazzy_action);
195         if ( snazzy_action != SNAZZY_CLICKED ){
196                 training_menu_choice = -1;
197         }
198
199         switch (training_menu_choice) {
200
201                 case TRAINING_MENU_TRAINING_MISSIONS_MASK:
202                         break;
203                 case TRAINING_MENU_REPLAY_MISSIONS_MASK:
204                         // TODO: load the mission and start the briefing
205                         break;
206                 case TRAINING_MENU_RETURN_MASK:
207                 case ESC_PRESSED:
208                         gameseq_post_event(GS_EVENT_MAIN_MENU);
209                         break;
210                 case -1:
211                         // nothing selected
212                         break;
213                 default:
214                         Error(LOCATION, "Unknown option %d in training menu screen", training_menu_choice );
215                         break;
216
217         } // end switch
218
219         gr_flip();
220 }
221