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