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