]> icculus.org git repositories - taylor/freespace2.git/blob - src/menuui/mainhalltemp.cpp
added copyright header
[taylor/freespace2.git] / src / menuui / mainhalltemp.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/MainHallTemp.cpp $
11  * $Revision$
12  * $Date$
13  * $Author$
14  *
15  * Header file for main-hall menu code
16  *
17  * $Log$
18  * Revision 1.2  2002/06/09 04:41:22  relnev
19  * added copyright header
20  *
21  * Revision 1.1.1.1  2002/05/03 03:28:09  root
22  * Initial import.
23  *
24  * 
25  * 3     6/04/99 9:52a Dave
26  * Fixed some rendering problems.
27  * 
28  * 2     6/03/99 10:15p Dave
29  * Put in temporary main hall screen.
30  * 
31  * $NoKeywords: $
32  *
33  */
34
35 #include "mainhallmenu.h"
36 #include "mainhalltemp.h"
37 #include "2d.h"
38 #include "ui.h"
39 #include "key.h"
40 #include "bmpman.h"
41 #include "gamesnd.h"
42 #include "gamesequence.h"
43 #include "missionparse.h"
44 #include "missioncampaign.h"
45 #include "player.h"
46 #include "freespace.h"
47
48 // ------------------------------------------------------------------------------------------------------------------------
49 // TEMP MAIN HALL DEFINES/VARS
50 //
51
52 #define MHT_NUM_BUTTONS 6
53
54 char *Mht_bitmap_fname[GR_NUM_RESOLUTIONS] = {
55         "mht_background",                               // GR_640
56         "2_mht_background"                      // GR_1024
57 };
58
59 char *Mht_bitmap_mask_fname[GR_NUM_RESOLUTIONS] = {
60         "mht_mask",                     // GR_640
61         "2_mht_mask"            // GR_1024
62 };
63
64 // button defs
65 #define MHT_READY_ROOM                          0
66 #define MHT_CAMPAIGN_ROOM                       1
67 #define MHT_OPTIONS                                     2
68 #define MHT_TECH_ROOM                           3
69 #define MHT_BARRACKS                                    4
70 #define MHT_EXIT                                                5
71
72 UI_WINDOW Mht_window;                                                                                                   // the window object for the join screen
73 int Mht_bitmap;                                                                                                                 // the background bitmap
74
75 ui_button_info Mht_buttons[GR_NUM_RESOLUTIONS][MHT_NUM_BUTTONS] = {
76         { // GR_640
77                 ui_button_info( "MHT_00",       15,     194,    -1,     -1,     2 ),                                            // ready room
78                 ui_button_info( "MHT_01",       15,     222,    -1,     -1,     5 ),                                            // campaigns            
79                 ui_button_info( "MHT_02",       14,     251,    -1,     -1,     4 ),                                            // options
80                 ui_button_info( "MHT_03",       14,     280,    -1,     -1,     3 ),                                            // tech room
81                 ui_button_info( "MHT_04",       14,     309,    -1,     -1,     1 ),                                            // barracks
82                 ui_button_info( "MHT_05",       16,     339,    -1,     -1,     0 ),                                            // exit
83         },              
84         { // GR_1024
85                 ui_button_info( "2_MHT_00",     25,     312,    -1,     -1,     2 ),                                            // ready room
86                 ui_button_info( "2_MHT_01",     25,     357,    -1,     -1,     5 ),                                            // campaigns            
87                 ui_button_info( "2_MHT_02",     24,     403,    -1,     -1,     4 ),                                            // options
88                 ui_button_info( "2_MHT_03",     24,     450,    -1,     -1,     3 ),                                            // tech room
89                 ui_button_info( "2_MHT_04",     25,     497,    -1,     -1,     1 ),                                            // barracks
90                 ui_button_info( "2_MHT_05",     27,     544,    -1,     -1,     0 ),                                            // exit
91         }
92 };
93
94
95 // ------------------------------------------------------------------------------------------------------------------------
96 // TEMP MAIN HALL FUNCTIONS
97 //
98
99 void mht_check_buttons();
100 void mht_button_pressed(int n);
101 void mht_exit_game();
102
103 void mht_init()
104 {       
105         int idx;
106
107         // create the interface window
108         Mht_window.create(0, 0, gr_screen.max_w,gr_screen.max_h, 0);
109         Mht_window.set_mask_bmap(Mht_bitmap_mask_fname[gr_screen.res]);
110
111         // load the background bitmap
112         Mht_bitmap = bm_load(Mht_bitmap_fname[gr_screen.res]);
113         if(Mht_bitmap < 0){
114                 // we failed to load the bitmap - this is very bad
115                 Int3();
116         }
117         
118         // create the interface buttons
119         for(idx=0; idx<MHT_NUM_BUTTONS; idx++){
120                 // create the object
121                 Mht_buttons[gr_screen.res][idx].button.create(&Mht_window, "", Mht_buttons[gr_screen.res][idx].x, Mht_buttons[gr_screen.res][idx].y, 1, 1, 0, 1);
122
123                 // set the sound to play when highlighted
124                 Mht_buttons[gr_screen.res][idx].button.set_highlight_action(common_play_highlight_sound);
125
126                 // set the ani for the button
127                 Mht_buttons[gr_screen.res][idx].button.set_bmaps(Mht_buttons[gr_screen.res][idx].filename);
128
129                 // set the hotspot
130                 Mht_buttons[gr_screen.res][idx].button.link_hotspot(Mht_buttons[gr_screen.res][idx].hotspot);
131         }                       
132
133         // remove any multiplayer flags from the game mode
134         Game_mode &= ~(GM_MULTIPLAYER);
135
136         // initialize the music
137         main_hall_start_music();
138
139         // set the game_mode based on the type of player
140         Assert( Player != NULL );
141         if ( Player->flags & PLAYER_FLAGS_IS_MULTI ){
142                 Game_mode = GM_MULTIPLAYER;
143         } else {
144                 Game_mode = GM_NORMAL;
145         }
146 }
147
148 void mht_do()
149 {       
150         int k = Mht_window.process();
151
152         // need to ensure ambient is playing, since it may be stopped by a playing movie
153         main_hall_start_ambient();
154
155         // process any keypresses
156         switch(k){
157         case KEY_ESC :          
158                 mht_exit_game();
159                 break;
160
161         case KEY_B:
162                 gameseq_post_event( GS_EVENT_BARRACKS_MENU );
163                 break;  
164
165         case KEY_G:
166                 if(Player->flags & PLAYER_FLAGS_IS_MULTI){
167                         break;
168                 }
169
170                 if (Num_recent_missions > 0)    {
171                         strncpy( Game_current_mission_filename, Recent_missions[0], MAX_FILENAME_LEN );
172                 } else {
173                         mission_load_up_campaign();
174                         strncpy( Game_current_mission_filename, Campaign.missions[0].name, MAX_FILENAME_LEN );
175                 }
176
177                 Campaign.current_mission = -1;
178                 gameseq_post_event(GS_EVENT_START_GAME_QUICK);
179                 break;
180
181         case KEY_L:
182                 gameseq_post_event( GS_EVENT_LOAD_MISSION_MENU );
183                 break;
184
185         case KEY_F2:
186                 gameseq_post_event(GS_EVENT_OPTIONS_MENU);
187                 break;
188
189         case KEY_M:
190                 if (Player->flags & PLAYER_FLAGS_IS_MULTI){
191                         main_hall_do_multi_ready();
192                 }
193                 break;
194         }       
195
196         // process button presses
197         mht_check_buttons();
198
199         // draw the background, etc
200         gr_reset_clip();
201         GR_MAYBE_CLEAR_RES(Mht_bitmap);
202         if(Mht_bitmap != -1){           
203                 gr_set_bitmap(Mht_bitmap);
204                 gr_bitmap(0,0);
205         }
206         Mht_window.draw();      
207         
208         // flip the buffer
209         gr_flip();      
210 }
211
212 void mht_close()
213 {
214         // unload any bitmaps
215         if(!bm_unload(Mht_bitmap)){
216                 nprintf(("General","WARNING : could not unload background bitmap %s\n", Mht_bitmap_fname[gr_screen.res]));
217         }       
218         
219         // destroy the UI_WINDOW
220         Mht_window.destroy();
221 }
222
223 void mht_check_buttons()
224 {
225         int idx;
226         for(idx=0; idx<MHT_NUM_BUTTONS; idx++){
227                 // we only really need to check for one button pressed at a time, so we can break after 
228                 // finding one.
229                 if(Mht_buttons[gr_screen.res][idx].button.pressed()){
230                         mht_button_pressed(idx);
231                         break;
232                 }
233         }
234 }
235
236 void mht_button_pressed(int n)
237 {
238         switch(n){              
239         case MHT_READY_ROOM:
240                 if (Player->flags & PLAYER_FLAGS_IS_MULTI){
241                         main_hall_do_multi_ready();
242                 } else {                        
243                         gameseq_post_event(GS_EVENT_NEW_CAMPAIGN);                      
244
245                         gamesnd_play_iface(SND_USER_SELECT);
246                 }
247                 break;
248
249         case MHT_CAMPAIGN_ROOM:
250                 gameseq_post_event(GS_EVENT_CAMPAIGN_ROOM);                     
251                 gamesnd_play_iface(SND_USER_SELECT);
252                 break;
253                 
254         case MHT_OPTIONS:
255                 gameseq_post_event(GS_EVENT_OPTIONS_MENU);
256                 gamesnd_play_iface(SND_USER_SELECT);
257                 break;
258
259         case MHT_TECH_ROOM:
260                 gameseq_post_event( GS_EVENT_TECH_MENU );
261                 gamesnd_play_iface(SND_USER_SELECT);
262                 break;
263         
264         case MHT_BARRACKS:
265                 gameseq_post_event( GS_EVENT_BARRACKS_MENU );
266                 gamesnd_play_iface(SND_USER_SELECT);
267                 break;
268
269         case MHT_EXIT:
270                 mht_exit_game();
271                 gamesnd_play_iface(SND_USER_SELECT);
272                 break;
273         }                                                       
274 }
275
276 void mht_exit_game()
277 {
278         // stop music first
279         main_hall_stop_music();
280         main_hall_stop_ambient();
281         gameseq_post_event(GS_EVENT_QUIT_GAME);
282 }
283