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