/********************************************************************** Returns the correct name of the gfx file (with path and extension) Must be free'd when no longer used ***********************************************************************/ char *themespec_gfx_filename(const char *gfx_filename) { const char *gfx_current_fileext; const char **gfx_fileexts = gfx_fileextensions(); while((gfx_current_fileext = *gfx_fileexts++)) { char *full_name = fc_malloc(strlen(gfx_filename) + strlen(gfx_current_fileext) + 2); const char *real_full_name; sprintf(full_name,"%s.%s",gfx_filename,gfx_current_fileext); real_full_name = fileinfoname(get_data_dirs(), full_name); FC_FREE(full_name); if (real_full_name) { return fc_strdup(real_full_name); } } log_fatal("Couldn't find a supported gfx file extension for \"%s\".", gfx_filename); exit(EXIT_FAILURE); return NULL; }
/********************************************************************** Returns a static string vector of soundsets available on the system by searching all data directories for files matching SNDSPEC_SUFFIX. The list is NULL-terminated. ***********************************************************************/ const struct strvec *get_soundset_list(void) { static struct strvec *audio_list = NULL; if (NULL == audio_list) { audio_list = fileinfolist(get_data_dirs(), SNDSPEC_SUFFIX); } return audio_list; }
/************************************************************************** INTERNAL. Returns TRUE for success. **************************************************************************/ static bool audio_play_tag(const char *tag, bool repeat) { const char *soundfile; const char *fullpath = NULL; if (!tag || strcmp(tag, "-") == 0) { return FALSE; } if (tagfile) { soundfile = secfile_lookup_str(tagfile, "files.%s", tag); if (NULL == soundfile) { log_verbose("No sound file for tag %s (file %s)", tag, soundfile); } else { fullpath = fileinfoname(get_data_dirs(), soundfile); if (!fullpath) { log_error("Cannot find audio file %s", soundfile); } } } return plugins[selected_plugin].play(tag, fullpath, repeat); }
/************************************************************************** Returns the filename for the given soundset. Returns NULL if soundset couldn't be found. Caller has to free the return value. **************************************************************************/ static const char *soundspec_fullname(const char *soundset_name) { const char *soundset_default = "stdsounds"; /* Do not i18n! */ char *fname = fc_malloc(strlen(soundset_name) + strlen(SNDSPEC_SUFFIX) + 1); const char *dname; sprintf(fname, "%s%s", soundset_name, SNDSPEC_SUFFIX); dname = fileinfoname(get_data_dirs(), fname); free(fname); if (dname) { return fc_strdup(dname); } if (strcmp(soundset_name, soundset_default) == 0) { /* avoid endless recursion */ return NULL; } log_error("Couldn't find soundset \"%s\", trying \"%s\".", soundset_name, soundset_default); return soundspec_fullname(soundset_default); }
/************************************************************************** Do any necessary pre-initialization of the UI, if necessary. **************************************************************************/ void ui_init(void) { char device[20]; /* struct widget *pInit_String = NULL;*/ SDL_Surface *pBgd; Uint32 iSDL_Flags; button_behavior.counting = FALSE; button_behavior.button_down_ticks = 0; button_behavior.hold_state = MB_HOLD_SHORT; button_behavior.event = fc_calloc(1, sizeof(SDL_MouseButtonEvent)); SDL_Client_Flags = 0; iSDL_Flags = SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE; /* auto center new windows in X enviroment */ putenv((char *)"SDL_VIDEO_CENTERED=yes"); init_sdl(iSDL_Flags); log_normal(_("Using Video Output: %s"), SDL_VideoDriverName(device, sizeof(device))); /* create splash screen */ #ifdef SMALL_SCREEN { SDL_Surface *pTmpSurf = load_surf(fileinfoname(get_data_dirs(), "misc/intro.png")); pBgd = zoomSurface(pTmpSurf, DEFAULT_ZOOM, DEFAULT_ZOOM, 0); FREESURFACE(pTmpSurf); } #else /* SMALL_SCREEN */ pBgd = load_surf(fileinfoname(get_data_dirs(), "misc/intro.png")); #endif /* SMALL_SCREEN */ if (pBgd && SDL_GetVideoInfo()->wm_available) { set_video_mode(pBgd->w, pBgd->h, SDL_SWSURFACE | SDL_ANYFORMAT); #if 0 /* * call this for other than X enviroments - currently not supported. */ center_main_window_on_screen(); #endif /* 0 */ alphablit(pBgd, NULL, Main.map, NULL); putframe(Main.map, 0, 0, Main.map->w - 1, Main.map->h - 1, &(SDL_Color) { 255, 255, 255, 255 }); FREESURFACE(pBgd); SDL_WM_SetCaption(_("SDL Client for Freeciv"), _("Freeciv")); } else { #ifndef SMALL_SCREEN set_video_mode(640, 480, SDL_SWSURFACE | SDL_ANYFORMAT); #else /* SMALL_SCREEN */ set_video_mode(320, 240, SDL_SWSURFACE | SDL_ANYFORMAT); #endif /* SMALL_SCREEN */ if(pBgd) { blit_entire_src(pBgd, Main.map, (Main.map->w - pBgd->w) / 2, (Main.map->h - pBgd->h) / 2); FREESURFACE(pBgd); } else { SDL_FillRect(Main.map, NULL, SDL_MapRGB(Main.map->format, 0, 0, 128)); SDL_WM_SetCaption(_("SDL Client for Freeciv"), _("Freeciv")); } } #if 0 /* create label beackground */ pBgd = create_surf_alpha(adj_size(350), adj_size(50), SDL_SWSURFACE); SDL_FillRect(pBgd, NULL, SDL_MapRGBA(pBgd->format, 255, 255, 255, 128)); putframe(pBgd, 0, 0, pBgd->w - 1, pBgd->h - 1, SDL_MapRGB(pBgd->format, 0, 0, 0)); pInit_String = create_iconlabel(pBgd, Main.gui, create_str16_from_char(_("Initializing Client"), adj_font(20)), WF_ICON_CENTER|WF_FREE_THEME); pInit_String->string16->style |= SF_CENTER; draw_label(pInit_String, (Main.screen->w - pInit_String->size.w) / 2, (Main.screen->h - pInit_String->size.h) / 2); flush_all(); copy_chars_to_string16(pInit_String->string16, _("Waiting for the beginning of the game")); #endif /* 0 */ flush_all(); }
/********************************************************************** Finds and reads the toplevel themespec file based on given name. Sets global variables, including tile sizes and full names for intro files. ***********************************************************************/ struct theme *theme_read_toplevel(const char *theme_name) { struct section_file *file; char *fname; int i; size_t num_spec_files; const char **spec_filenames; const char *file_capstr; bool duplicates_ok; struct theme *t = theme_new(); const char *langname; const char *filename, *c; fname = themespec_fullname(theme_name); if (!fname) { log_error("Can't find theme \"%s\".", theme_name); theme_free(t); return NULL; } log_verbose("themespec file is \"%s\".", fname); if (!(file = secfile_load(fname, TRUE))) { log_error("Could not open '%s':\n%s", fname, secfile_error()); FC_FREE(fname); theme_free(t); return NULL; } if (!check_themespec_capabilities(file, "themespec", THEMESPEC_CAPSTR, fname)) { secfile_destroy(file); FC_FREE(fname); theme_free(t); return NULL; } file_capstr = secfile_lookup_str(file, "themespec.options"); duplicates_ok = has_capabilities("+duplicates_ok", file_capstr); (void) secfile_entry_by_path(file, "themespec.name"); /* currently unused */ sz_strlcpy(t->name, theme_name); t->priority = secfile_lookup_int_default(file, 0, "themespec.priority"); langname = get_langname(); if (langname) { if (strstr(langname, "zh_CN") != NULL) { c = secfile_lookup_str(file, "themespec.font_file_zh_CN"); } else if (strstr(langname, "ja") != NULL) { c = secfile_lookup_str(file, "themespec.font_file_ja"); } else if (strstr(langname, "ko") != NULL) { c = secfile_lookup_str(file, "themespec.font_file_ko"); } else { c = secfile_lookup_str(file, "themespec.font_file"); } } else { c = secfile_lookup_str(file, "themespec.font_file"); } if ((filename = fileinfoname(get_data_dirs(), c))) { t->font_filename = fc_strdup(filename); } else { log_fatal("Could not open font: %s", c); secfile_destroy(file); FC_FREE(fname); theme_free(t); return NULL; } log_debug("theme font file %s", t->font_filename); t->default_font_size = secfile_lookup_int_default(file, 10, "themespec.default_font_size"); log_debug("theme default font size %d", t->default_font_size); spec_filenames = secfile_lookup_str_vec(file, &num_spec_files, "themespec.files"); if (NULL == spec_filenames || 0 == num_spec_files) { log_error("No theme graphics files specified in \"%s\"", fname); secfile_destroy(file); FC_FREE(fname); theme_free(t); return NULL; } fc_assert(t->sprite_hash == NULL); t->sprite_hash = small_sprite_hash_new(); for (i = 0; i < num_spec_files; i++) { struct specfile *sf = fc_malloc(sizeof(*sf)); log_debug("spec file %s", spec_filenames[i]); sf->big_sprite = NULL; filename = fileinfoname(get_data_dirs(), spec_filenames[i]); if (!filename) { log_error("Can't find spec file \"%s\".", spec_filenames[i]); secfile_destroy(file); FC_FREE(fname); theme_free(t); return NULL; } sf->file_name = fc_strdup(filename); scan_specfile(t, sf, duplicates_ok); specfile_list_prepend(t->specfiles, sf); } FC_FREE(spec_filenames); t->background_system = theme_background_system_read(file); t->color_system = theme_color_system_read(file); secfile_check_unused(file); secfile_destroy(file); log_verbose("finished reading \"%s\".", fname); FC_FREE(fname); return t; }