1 /***************************************************************************
2 theme.c - description
3 -------------------
4 begin : Fri Feb 15 2002
5 copyright : (C) 2001 by Michael Speck
6 email : kulkanie@gmx.net
7 ***************************************************************************/
8
9 /***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18 #include <sys/types.h>
19 #include <unistd.h>
20 #include <sys/stat.h>
21 #include <dirent.h>
22
23 #include "lbreakout.h"
24 #include "config.h"
25 #include "theme.h"
26
27 extern SDL_Surface *stk_display;
28 extern Config config;
29 extern int ball_w, ball_h;
30 extern int shot_w, shot_h;
31 extern int paddle_cw;
32 /* theme name list */
33 char **theme_names = 0;
34 int theme_count = 0;
35 /* current theme name */
36 char theme_name[32] = "Default";
37
38 /*
39 ====================================================================
40 Themeable gfx and sounds.
41 ====================================================================
42 */
43 SDL_Surface *exp_pic = 0;
44 SDL_Surface *exp_dark_pic = 0;
45 StkFont *font = 0;
46 StkFont *chat_font_normal = 0;
47 StkFont *chat_font_error = 0;
48 StkFont *chat_font_name = 0;
49 #ifdef AUDIO_ENABLED
50 StkSound *wav_click = 0;
51 StkSound *wav_damn = 0, *wav_dammit = 0, *wav_wontgiveup = 0, *wav_excellent = 0, *wav_verygood = 0;
52 #endif
53 SDL_Surface *brick_pic = 0;
54 SDL_Surface *brick_shadow = 0;
55 #ifdef AUDIO_ENABLED
56 StkSound *wav_boom = 0;
57 #endif
58 SDL_Surface *paddle_pic = 0;
59 SDL_Surface *paddle_shadow = 0;
60 SDL_Surface *weapon_pic = 0;
61 SDL_Surface *weapon_shadow = 0;
62 SDL_Surface *ammo_pic = 0;
63 #ifdef AUDIO_ENABLED
64 StkSound *wav_expand = 0, *wav_shrink = 0, *wav_frozen = 0;
65 #endif
66 SDL_Surface *ball_pic = 0; /* ball pictures */
67 SDL_Surface *ball_shadow = 0;
68 #ifdef AUDIO_ENABLED
69 StkSound *wav_reflect_brick = 0;
70 StkSound *wav_reflect_paddle = 0;
71 StkSound *wav_attach = 0;
72 #endif
73 SDL_Surface *shot_pic = 0;
74 SDL_Surface *shot_shadow = 0;
75 #ifdef AUDIO_ENABLED
76 StkSound *wav_shot = 0;
77 #endif
78 SDL_Surface *extra_pic = 0; /* graphics */
79 SDL_Surface *extra_shadow = 0;
80 SDL_Surface *wall_pic = 0;
81 #ifdef AUDIO_ENABLED
82 StkSound *wav_score = 0, *wav_metal = 0, *wav_std = 0, *wav_wall = 0, *wav_joker = 0;
83 StkSound *wav_goldshower = 0;
84 StkSound *wav_speedup = 0, *wav_speeddown = 0;
85 StkSound *wav_chaos = 0, *wav_darkness = 0, *wav_ghost = 0;
86 StkSound *wav_timeadd = 0, *wav_expl_ball = 0, *wav_weak_ball = 0;
87 StkSound *wav_bonus_magnet = 0, *wav_malus_magnet = 0, *wav_disable = 0;
88 #endif
89 SDL_Surface *shine_pic = 0;
90 SDL_Surface *frame_left = 0, *frame_top = 0, *frame_right = 0;
91 SDL_Surface *frame_left_shadow = 0, *frame_top_shadow = 0, *frame_right_shadow = 0;
92 SDL_Surface *frame_mp_left = 0, *frame_mp_right = 0; /* multiplayer variants */
93 SDL_Surface *frame_mp_left_shadow = 0, *frame_mp_right_shadow = 0;
94 SDL_Surface *lamps = 0; /* life lamps */
95 StkFont *display_font;
96 StkFont *display_highlight_font;
97 #ifdef AUDIO_ENABLED
98 StkSound *wav_life_up = 0, *wav_life_down = 0;
99 #endif
100 SDL_Surface **bkgnds = 0;
101 int bkgnd_count = 0;
102 SDL_Surface *nuke_bkgnd = 0; /* special background for nuke mode */
103 /* chatroom */
104 SDL_Surface *cr_up = 0, *cr_down = 0, *cr_track = 0, *cr_wallpaper = 0;
105 /* frame box */
106 SDL_Surface *fr_hori = 0, *fr_vert = 0, *fr_luc = 0, *fr_llc = 0, *fr_ruc = 0, *fr_rlc = 0;
107 /* menu manager */
108 StkFont *mfont = 0, *mhfont = 0, *mcfont = 0; /* font, highlight font, caption font */
109 SDL_Surface *mbkgnd = 0; /* menu background */
110 #ifdef AUDIO_ENABLED
111 StkSound *wav_menu_click = 0;
112 StkSound *wav_menu_motion = 0;
113 #endif
114 /* charts */
115 StkFont *cfont = 0, *chfont = 0, *ccfont = 0; /* normal, highlight and caption font */
116 /* warp icon (indicates you can now go to next level) */
117 SDL_Surface *warp_pic = 0;
118
119 /*
120 ====================================================================
121 Locals
122 ====================================================================
123 */
124
125 /*
126 ====================================================================
127 Build the theme directory from passed name. The resources are then
128 loaded from this directory and the full file name is saved to
129 theme_path.
130 ====================================================================
131 */
132 static char theme_dir[512];
133 static char theme_path[512];
theme_set_dir(char * name)134 void theme_set_dir( char *name )
135 {
136 if ( name[0] == '~' )
137 snprintf( theme_dir, sizeof(theme_dir)-1, "%s/%s/lbreakout2-themes/%s",
138 (getenv( "HOME" )?getenv( "HOME" ):"."), CONFIG_DIR_NAME, name + 1 );
139 else {
140 if ( STRCMP( SRC_DIR, "." ) ) {
141 getcwd( theme_dir, 511 );
142 strcat( theme_dir, "/gfx/" );
143 strcat( theme_dir, name );
144 }
145 else
146 snprintf( theme_dir, sizeof(theme_dir)-1, "%s/gfx/%s", SRC_DIR, name );
147 }
148 }
149
150 /*
151 ====================================================================
152 Load a picture or sound from theme directory or (if not found)
153 from original source directory.
154 ====================================================================
155 */
theme_load_surf(char * name)156 SDL_Surface* theme_load_surf( char *name )
157 {
158 struct stat filestat;
159 SDL_Surface *surf = 0;
160 sprintf( theme_path, "%s/%s", theme_dir, name );
161 if ( stat( theme_path, &filestat ) == -1 ||
162 ( surf = stk_surface_load( SDL_SWSURFACE | SDL_NONFATAL, theme_path ) ) == 0 )
163 surf = stk_surface_load( SDL_SWSURFACE, name );
164 return surf;
165 }
166 #ifdef AUDIO_ENABLED
theme_load_sound(char * name)167 StkSound* theme_load_sound( char *name )
168 {
169 struct stat filestat;
170 StkSound *sound = 0;
171 sprintf( theme_path, "%s/%s", theme_dir, name );
172 if ( stat( theme_path, &filestat ) == -1 ||
173 ( sound = stk_sound_load( -1, theme_path ) ) == 0 )
174 sound = stk_sound_load( -1, name );
175 return sound;
176 }
177 #endif
theme_load_font_fixed(char * name,int start,int len,int width)178 StkFont* theme_load_font_fixed( char *name, int start, int len, int width )
179 {
180 struct stat filestat;
181 StkFont *font = 0;
182 sprintf( theme_path, "%s/%s", theme_dir, name );
183 if ( stat( theme_path, &filestat ) == -1 ||
184 ( font = stk_font_load( SDL_SWSURFACE | SDL_NONFATAL, theme_path ) ) == 0 )
185 font = stk_font_load( SDL_SWSURFACE, name );
186 if ( font )
187 SDL_SetColorKey( font->surface, SDL_SRCCOLORKEY,
188 stk_surface_get_pixel( font->surface, 0,0 ) );
189 return font;
190 }
191
192 /*
193 ====================================================================
194 The frame is a bit complex to be done.
195 ====================================================================
196 */
theme_load_frame()197 void theme_load_frame()
198 {
199 Uint32 ckey;
200
201 /* load resources */
202 frame_left = theme_load_surf( "fr_left.png" );
203 frame_top = theme_load_surf( "fr_top.png" );
204 frame_right = theme_load_surf( "fr_right.png" );
205 /* get colorkey */
206 ckey = stk_surface_get_pixel( frame_right, frame_right->w - 1, 0 );
207 SDL_SetColorKey( frame_left, SDL_SRCCOLORKEY, ckey );
208 SDL_SetColorKey( frame_top, SDL_SRCCOLORKEY, ckey );
209 SDL_SetColorKey( frame_right, SDL_SRCCOLORKEY, ckey );
210 /* build shadows */
211 frame_left_shadow = create_shadow( frame_left, 0, 0, frame_left->w, frame_left->h );
212 frame_top_shadow = create_shadow( frame_top, 0, 0, frame_top->w, frame_top->h );
213 frame_right_shadow = create_shadow( frame_right, 0, 0, frame_right->w, frame_right->h );
214
215 /* build the columns for multiplayer */
216 frame_mp_left = theme_load_surf( "fr_mp_left.png" );
217 frame_mp_right = theme_load_surf( "fr_mp_right.png" );
218 SDL_SetColorKey( frame_mp_left, SDL_SRCCOLORKEY, ckey );
219 SDL_SetColorKey( frame_mp_right, SDL_SRCCOLORKEY, ckey );
220 frame_mp_left_shadow = create_shadow( frame_mp_left, 0, 0, frame_mp_left->w, frame_mp_left->h );
221 frame_mp_right_shadow = create_shadow( frame_mp_right, 0, 0, frame_mp_right->w, frame_mp_right->h );
222
223 /* load other resources */
224 lamps = theme_load_surf( "life.png" );
225 display_font = theme_load_font_fixed( "f_frame.png", 32, 96, 8 );
226 display_font->align = STK_FONT_ALIGN_RIGHT | STK_FONT_ALIGN_CENTER_Y;
227 display_highlight_font = theme_load_font_fixed( "f_small_white.png", 32, 96, 8 );
228 display_highlight_font->align = STK_FONT_ALIGN_RIGHT | STK_FONT_ALIGN_CENTER_Y;
229
230 /* waves */
231 #ifdef AUDIO_ENABLED
232 wav_life_up = theme_load_sound( "gainlife.wav" );
233 wav_life_down = theme_load_sound( "looselife.wav" );
234 #endif
235 }
236
237 /*
238 ====================================================================
239 Load backgrounds. If no background was found use the original
240 backgrounds. Else count the number of new backgrounds and use these.
241 ====================================================================
242 */
theme_load_bkgnds()243 void theme_load_bkgnds()
244 {
245 int i;
246 struct stat filestat;
247 sprintf( theme_path, "%s/back0.png", theme_dir );
248 if ( stat( theme_path, &filestat ) == -1 ) {
249 /* use original backs */
250 bkgnds = calloc( ORIG_BACK_COUNT, sizeof( SDL_Surface* ) );
251 for ( i = 0; i < ORIG_BACK_COUNT; i++ ) {
252 sprintf( theme_path, "back%i.png", i );
253 bkgnds[i] = stk_surface_load( SDL_SWSURFACE, theme_path );
254 }
255 bkgnd_count = ORIG_BACK_COUNT;
256 }
257 else {
258 /* use new backs */
259 bkgnd_count = -1;
260 do {
261 bkgnd_count++;
262 sprintf( theme_path, "%s/back%i.png", theme_dir, bkgnd_count );
263 } while ( stat( theme_path, &filestat ) == 0 );
264 bkgnds = calloc( bkgnd_count, sizeof( SDL_Surface* ) );
265 /* load backs */
266 for ( i = 0; i < bkgnd_count; i++ ) {
267 sprintf( theme_path, "%s/back%i.png", theme_dir, i );
268 bkgnds[i] = stk_surface_load( SDL_SWSURFACE, theme_path );
269 }
270 }
271
272 for ( i = 0; i < bkgnd_count; i++ )
273 SDL_SetColorKey( bkgnds[i], 0, 0x0 );
274 }
275
276 /*
277 ====================================================================
278 Publics
279 ====================================================================
280 */
281
282 /*
283 ====================================================================
284 Get/delete names of all themes found in themes directory.
285 ====================================================================
286 */
theme_get_list()287 void theme_get_list()
288 {
289 int i;
290 int default_theme_count = 4;
291 char *default_theme_names[] = {
292 "AbsoluteB",
293 "Oz",
294 "Moiree",
295 "Classic"
296 };
297 char name[64];
298 char dir[256];
299 DIR *hdir = 0;
300 struct dirent *entry = 0;
301 struct stat estat;
302 List *list = 0;
303 /* auxilary list */
304 list = list_create( LIST_NO_AUTO_DELETE, LIST_NO_CALLBACK );
305 /* install theme directory */
306 snprintf( dir, sizeof(dir) - 1, "%s/gfx", SRC_DIR );
307 if ( ( hdir = opendir( dir ) ) != 0 ) {
308 while ( ( entry = readdir( hdir ) ) ) {
309 if ( entry->d_name[0] == '.' )
310 continue;
311 /* full path */
312 sprintf( theme_path, "%s/%s", dir, entry->d_name );
313 stat( theme_path, &estat );
314 if ( S_ISDIR( estat.st_mode ) ) {
315 /* ignore entry if it is a default theme */
316 for ( i = 0; i < default_theme_count; i++ )
317 if ( STRCMP( default_theme_names[i], entry->d_name ) ) {
318 i = -1;
319 break;
320 }
321 if ( i == -1 ) continue;
322 /* store it otherwise */
323 sprintf( name, "%s", entry->d_name );
324 list_add( list, strdup( name ) );
325 }
326 }
327 closedir( hdir );
328 }
329 /* home theme directory */
330 snprintf( dir, sizeof(dir)-1, "%s/%s/lbreakout2-themes", (getenv( "HOME" )?getenv( "HOME" ):"."), CONFIG_DIR_NAME );
331 if ( ( hdir = opendir( dir ) ) != 0 ) {
332 while ( ( entry = readdir( hdir ) ) ) {
333 if ( entry->d_name[0] == '.' )
334 continue;
335 /* full path */
336 sprintf( theme_path, "%s/%s", dir, entry->d_name );
337 stat( theme_path, &estat );
338 if ( S_ISDIR( estat.st_mode ) ) {
339 sprintf( name, "~%s", entry->d_name );
340 list_add( list, strdup( name ) );
341 }
342 }
343 closedir( hdir );
344 }
345 /* create static list. the default themes are the
346 first four entries in the order at the
347 beginning of this function. */
348 theme_count = list->count + default_theme_count;
349 theme_names = calloc( theme_count, sizeof( char* ) );
350 for ( i = 0; i < default_theme_count; i++ )
351 theme_names[i] = strdup( default_theme_names[i] );
352 for ( i = 0; i < list->count; i++ ) {
353 theme_names[i + default_theme_count] = list_get( list, i );
354 }
355 list_delete( list );
356 /* if config's theme count is not equal reset the theme_id to 0 */
357 if ( theme_count != config.theme_count ) {
358 config.theme_count = theme_count;
359 config.theme_id = 0;
360 }
361 }
theme_delete_list()362 void theme_delete_list()
363 {
364 int i;
365 if ( theme_names ) {
366 for ( i = 0; i < theme_count; i++ )
367 if ( theme_names[i] ) free( theme_names[i] );
368 free( theme_names );
369 theme_names = 0;
370 }
371 }
372
373 /*
374 ====================================================================
375 Load theme by name or delete current theme (is done by load too
376 so it might be used to change a theme as well.)
377 ====================================================================
378 */
theme_load(char * name)379 void theme_load( char *name )
380 {
381 SDL_Surface *surf;
382 struct stat filestat;
383 char aux[128];
384 int i;
385 printf( "Loading theme '%s'\n", name );
386 /* clear resources */
387 theme_delete();
388 /* set theme directory */
389 theme_set_dir( name );
390 /* load resources */
391 /* explosions */
392 exp_pic = theme_load_surf( "explosions.png" );
393 exp_dark_pic = theme_load_surf( "explosions_dark.png" );
394 /* main game font */
395 font = theme_load_font_fixed( "f_game.png", 32, 96, 10 );
396 font->align = STK_FONT_ALIGN_CENTER_X | STK_FONT_ALIGN_CENTER_Y;
397 /* normal chat font (messages by server) */
398 chat_font_normal = theme_load_font_fixed( "f_small_yellow.png", 32, 96, 8 );
399 /* error font (messages by server) */
400 chat_font_error = theme_load_font_fixed( "f_small_red.png", 32, 96, 8 );
401 /* username font (also for server) */
402 chat_font_name = theme_load_font_fixed( "f_small_white.png", 32, 96, 8 );
403 /* main game sounds */
404 #ifdef AUDIO_ENABLED
405 wav_click = theme_load_sound( "click.wav" );
406 wav_damn = theme_load_sound( "damn.wav" );
407 wav_dammit = theme_load_sound( "dammit.wav" );
408 wav_wontgiveup = theme_load_sound( "wontgiveup.wav" );
409 wav_excellent = theme_load_sound( "excellent.wav" );
410 wav_verygood = theme_load_sound( "verygood.wav" );
411 #endif
412 /* brick pics and shadow template */
413 brick_pic = theme_load_surf( "bricks.png" );
414 /* default color key is: BLACK but you may specify a special
415 key by adding a column of one pixel width at the end of the file */
416 if ( brick_pic->w & 1 )
417 SDL_SetColorKey( brick_pic, SDL_SRCCOLORKEY, stk_surface_get_pixel( brick_pic, brick_pic->w - 1, 0 ) );
418 brick_shadow = create_shadow( brick_pic, 0, 0, brick_pic->w, brick_pic->h );
419 /* brick destruction sound */
420 #ifdef AUDIO_ENABLED
421 wav_boom = theme_load_sound( "exp.wav" );
422 #endif
423 /* paddle and weapon */
424 paddle_pic = theme_load_surf( "paddle.png" );
425 SDL_SetColorKey( paddle_pic, SDL_SRCCOLORKEY,
426 stk_surface_get_pixel( paddle_pic, 0, 0 ) );
427 if ( paddle_pic->w < 6 * paddle_cw ) {
428 /* no top paddle specified so duplicate first one */
429 surf = stk_surface_create( SDL_SWSURFACE, paddle_pic->w*2, paddle_pic->h );
430 SDL_SetColorKey( surf, SDL_SRCCOLORKEY, paddle_pic->format->colorkey );
431 SDL_FillRect( surf, 0, paddle_pic->format->colorkey );
432 stk_surface_blit( paddle_pic, 0,0,-1,-1, surf, 0,0 );
433 stk_surface_blit( paddle_pic, 0,0,-1,-1, surf, paddle_pic->w,0 );
434 stk_surface_free( &paddle_pic ); paddle_pic = surf;
435 }
436 weapon_pic = theme_load_surf( "weapon.png" );
437 paddle_shadow = create_shadow( paddle_pic, 0, 0, paddle_pic->w, paddle_pic->h );
438 weapon_shadow = create_shadow( weapon_pic, 0, 0, weapon_pic->w, weapon_pic->h );
439 ammo_pic = theme_load_surf( "ammo.png" );
440 SDL_SetColorKey( ammo_pic, SDL_SRCCOLORKEY, 0x0 );
441 /* paddle sounds */
442 #ifdef AUDIO_ENABLED
443 wav_expand = theme_load_sound( "expand.wav" );
444 wav_shrink = theme_load_sound( "shrink.wav" );
445 wav_frozen = theme_load_sound( "freeze.wav" );
446 #endif
447 /* ball gfx */
448 ball_pic = theme_load_surf( "ball.png" );
449 SDL_SetColorKey( ball_pic, SDL_SRCCOLORKEY, stk_surface_get_pixel( ball_pic, 0, 0 ) );
450 ball_shadow = create_shadow( ball_pic, 0, 0, ball_w, ball_h );
451 /* ball sounds */
452 #ifdef AUDIO_ENABLED
453 wav_reflect_brick = theme_load_sound( "reflect_brick.wav" );
454 wav_reflect_paddle = theme_load_sound( "reflect_paddle.wav" );
455 wav_attach = theme_load_sound( "attach.wav" );
456 #endif
457 /* shot gfx */
458 shot_pic = theme_load_surf( "shot.png" );
459 shot_shadow = create_shadow( shot_pic, 0, 0, shot_w, shot_h );
460 #ifdef AUDIO_ENABLED
461 wav_shot = theme_load_sound( "shot.wav" );
462 #endif
463 /* extra pic */
464 extra_pic = theme_load_surf( "extras.png" );
465 SDL_SetColorKey( extra_pic, 0, 0 );
466 /* default color key is: disabled but you may specify a special
467 key by adding a column of one pixel width at the end of the file */
468 if ( extra_pic->w & 1 )
469 SDL_SetColorKey( extra_pic, SDL_SRCCOLORKEY, stk_surface_get_pixel( extra_pic, extra_pic->w - 1, 0 ) );
470 extra_shadow = create_shadow( extra_pic, 0, 0, extra_pic->w, extra_pic->h );
471 /* extra sounds */
472 #ifdef AUDIO_ENABLED
473 wav_score = theme_load_sound( "score.wav" );
474 wav_metal = theme_load_sound( "metal.wav" );
475 wav_speedup = theme_load_sound( "speedup.wav" );
476 wav_speeddown = theme_load_sound( "speeddown.wav" );
477 wav_std = theme_load_sound( "standard.wav" );
478 wav_wall = theme_load_sound( "wall.wav" );
479 wav_joker = theme_load_sound( "joker.wav" );
480 wav_goldshower = theme_load_sound( "goldshower.wav" );
481 wav_chaos = theme_load_sound( "chaos.wav" );
482 wav_darkness = theme_load_sound( "darkness.wav" );
483 wav_ghost = theme_load_sound( "ghost.wav" );
484 wav_timeadd = theme_load_sound( "timeadd.wav" );
485 wav_expl_ball = theme_load_sound( "expl_ball.wav" );
486 wav_weak_ball = theme_load_sound( "weak_ball.wav" );
487 wav_bonus_magnet = theme_load_sound( "bonus_magnet.wav" );
488 wav_malus_magnet = theme_load_sound( "malus_magnet.wav" );
489 wav_disable = theme_load_sound( "disable.wav" );
490 #endif
491 /* shine pic */
492 shine_pic = theme_load_surf( "shine.png" );
493 /* chatroom */
494 cr_up = theme_load_surf( "scroll_up.png" );
495 cr_down = theme_load_surf( "scroll_down.png" );
496 cr_track = theme_load_surf( "scroll_track.png" );
497 cr_wallpaper = theme_load_surf( "cr_back.png" );
498 SDL_SetColorKey( cr_wallpaper, 0,0 );
499 /* frame box */
500 fr_hori = theme_load_surf( "fr_hori.png" );
501 fr_vert = theme_load_surf( "fr_vert.png" );
502 fr_luc = theme_load_surf( "fr_luc.png" );
503 fr_llc = theme_load_surf( "fr_llc.png" );
504 fr_ruc = theme_load_surf( "fr_ruc.png" );
505 fr_rlc = theme_load_surf( "fr_rlc.png" );
506 /* frame */
507 theme_load_frame();
508 /* wall */
509 sprintf( theme_path, "%s/floor.png", theme_dir );
510 if ( stat( theme_path, &filestat ) == -1 ) {
511 /* build default floor */
512 wall_pic = stk_surface_create(
513 SDL_SWSURFACE, stk_display->w - 2 * BRICK_WIDTH,
514 BRICK_HEIGHT );
515 /* bricks must have been loaded at this point! */
516 for ( i = 0; i < MAP_WIDTH - 2; i++ )
517 stk_surface_blit( brick_pic, 0, 0,
518 BRICK_WIDTH, BRICK_HEIGHT,
519 wall_pic, i * BRICK_WIDTH, 0 );
520 }
521 else {
522 /* load floor */
523 wall_pic = theme_load_surf( "floor.png" );
524 }
525 /* backgrounds */
526 theme_load_bkgnds();
527 /* build nuke bkgnd */
528 nuke_bkgnd = stk_surface_create( SDL_SWSURFACE,
529 stk_display->w, stk_display->h );
530 surf = stk_surface_load( SDL_SWSURFACE, "nukeback.png" );
531 stk_surface_apply_wallpaper( nuke_bkgnd, 0,0,-1,-1,
532 surf, 128 );
533 stk_surface_free( &surf );
534 stk_surface_gray( nuke_bkgnd, 0,0,-1,-1, 0 );
535 /* manager */
536 mbkgnd = theme_load_surf( "menuback.png" );
537 SDL_SetColorKey( mbkgnd, 0, 0 );
538 mfont = theme_load_font_fixed( "f_small_yellow.png", 32, 96, 8 );
539 mhfont = theme_load_font_fixed( "f_white.png", 32, 96, 10 );
540 mcfont = theme_load_font_fixed( "f_yellow.png", 32, 96, 10 );
541 #ifdef AUDIO_ENABLED
542 wav_menu_click = theme_load_sound( "menu_click.wav" );
543 wav_menu_motion = theme_load_sound( "menu_motion.wav" );
544 #endif
545 /* add version to background */
546 mfont->align = STK_FONT_ALIGN_RIGHT | STK_FONT_ALIGN_BOTTOM;
547 sprintf( aux, "v%s", VERSION );
548 stk_font_write( mfont, mbkgnd, mbkgnd->w - 4, stk_display->h - 4 - mfont->height, STK_OPAQUE, aux );
549 stk_font_write( mfont, mbkgnd, mbkgnd->w - 4, stk_display->h - 4, STK_OPAQUE, "http://lgames.sf.net" );
550 /* charts */
551 /* load resources */
552 cfont = theme_load_font_fixed( "f_small_yellow.png", 32, 96, 8 );
553 chfont = theme_load_font_fixed( "f_small_white.png", 32, 96, 8 );
554 ccfont = theme_load_font_fixed( "f_yellow.png", 32, 96, 10 );
555 /* warp picture */
556 warp_pic = theme_load_surf( "warp.png" );
557 }
theme_delete()558 void theme_delete()
559 {
560 int i;
561 stk_surface_free( &exp_pic );
562 stk_surface_free( &exp_dark_pic );
563 stk_font_free( &font );
564 stk_font_free( &chat_font_normal );
565 stk_font_free( &chat_font_error );
566 stk_font_free( &chat_font_name );
567 #ifdef AUDIO_ENABLED
568 stk_sound_free( &wav_click );
569 stk_sound_free( &wav_damn );
570 stk_sound_free( &wav_dammit );
571 stk_sound_free( &wav_wontgiveup );
572 stk_sound_free( &wav_excellent );
573 stk_sound_free( &wav_verygood );
574 #endif
575 stk_surface_free( &brick_pic );
576 stk_surface_free( &brick_shadow );
577 #ifdef AUDIO_ENABLED
578 stk_sound_free( &wav_boom );
579 #endif
580 stk_surface_free( &paddle_pic );
581 stk_surface_free( &weapon_pic );
582 stk_surface_free( &ammo_pic );
583 stk_surface_free( &paddle_shadow );
584 stk_surface_free( &weapon_shadow );
585 #ifdef AUDIO_ENABLED
586 stk_sound_free( &wav_expand );
587 stk_sound_free( &wav_shrink );
588 stk_sound_free( &wav_frozen );
589 #endif
590 stk_surface_free( &ball_pic );
591 stk_surface_free( &ball_shadow );
592 #ifdef AUDIO_ENABLED
593 stk_sound_free( &wav_reflect_paddle );
594 stk_sound_free( &wav_reflect_brick );
595 stk_sound_free( &wav_attach );
596 #endif
597 stk_surface_free( &shot_pic );
598 stk_surface_free( &shot_shadow );
599 #ifdef AUDIO_ENABLED
600 stk_sound_free( &wav_shot );
601 #endif
602 stk_surface_free( &extra_pic );
603 stk_surface_free( &extra_shadow );
604 stk_surface_free( &wall_pic );
605 #ifdef AUDIO_ENABLED
606 stk_sound_free( &wav_score );
607 stk_sound_free( &wav_metal );
608 stk_sound_free( &wav_speedup );
609 stk_sound_free( &wav_speeddown );
610 stk_sound_free( &wav_std );
611 stk_sound_free( &wav_wall );
612 stk_sound_free( &wav_joker );
613 stk_sound_free( &wav_goldshower );
614 stk_sound_free( &wav_chaos );
615 stk_sound_free( &wav_darkness );
616 stk_sound_free( &wav_ghost );
617 stk_sound_free( &wav_timeadd );
618 stk_sound_free( &wav_expl_ball );
619 stk_sound_free( &wav_weak_ball );
620 stk_sound_free( &wav_bonus_magnet );
621 stk_sound_free( &wav_malus_magnet );
622 stk_sound_free( &wav_disable );
623 #endif
624 stk_surface_free( &shine_pic );
625 stk_surface_free( &frame_left );
626 stk_surface_free( &frame_right );
627 stk_surface_free( &frame_top );
628 stk_surface_free( &frame_left_shadow );
629 stk_surface_free( &frame_right_shadow );
630 stk_surface_free( &frame_top_shadow );
631 stk_surface_free( &lamps );
632 stk_font_free( &display_font );
633 stk_font_free( &display_highlight_font );
634 #ifdef AUDIO_ENABLED
635 stk_sound_free( &wav_life_up );
636 stk_sound_free( &wav_life_down );
637 #endif
638 if ( bkgnds ) {
639 for ( i = 0; i < bkgnd_count; i++ )
640 stk_surface_free( &bkgnds[i] );
641 free( bkgnds );
642 bkgnds = 0;
643 bkgnd_count = 0;
644 }
645 stk_surface_free( &nuke_bkgnd );
646 /* chatroom */
647 stk_surface_free( &cr_up );
648 stk_surface_free( &cr_down );
649 stk_surface_free( &cr_track );
650 stk_surface_free( &cr_wallpaper );
651 /* frame box */
652 stk_surface_free( &fr_vert );
653 stk_surface_free( &fr_hori );
654 stk_surface_free( &fr_luc );
655 stk_surface_free( &fr_llc );
656 stk_surface_free( &fr_ruc );
657 stk_surface_free( &fr_rlc );
658 /* manager */
659 stk_surface_free( &mbkgnd );
660 stk_font_free( &mfont );
661 stk_font_free( &mhfont );
662 stk_font_free( &mcfont );
663 #ifdef AUDIO_ENABLED
664 stk_sound_free( &wav_menu_click );
665 stk_sound_free( &wav_menu_motion );
666 #endif
667 /* charts */
668 stk_font_free( &cfont );
669 stk_font_free( &chfont );
670 stk_font_free( &ccfont );
671 /* warp picture */
672 stk_surface_free( &warp_pic );
673 }
674
675 /*
676 ====================================================================
677 Check if there is a file ABOUT in the theme directory and return
678 it's contents up to limit characters.
679 If this file isn't found 'NO INFO' is set.
680 ====================================================================
681 */
theme_get_info(char * theme_name,char * text,int limit)682 void theme_get_info( char *theme_name, char *text, int limit )
683 {
684 FILE *file = 0;
685 int i, count;
686 theme_set_dir( theme_name );
687 sprintf( theme_path, "%s/ABOUT", theme_dir );
688 if ( ( file = fopen( theme_path, "rb" ) ) ) {
689 count = fread( text, 1, limit, file );
690 fclose( file );
691 text[(count>=0)?count:0] = 0;
692 for ( i = 0; i < strlen( text ); i++ )
693 if ( text[i] == 10 )
694 text[i] = '#';
695 /* remove empty lines */
696 for ( i = strlen( text ) - 1; i >= 0; i++ )
697 if ( text[i] == '#' && i > 0 && text[i-1] == '#' )
698 text[i] = 0;
699 else
700 break;
701 }
702 else
703 strcpy_lt( text, _("NO INFO AVAILABLE"), limit );
704 }
705