Freeciv-3.1
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "capability.h"
#include "fcintl.h"
#include "log.h"
#include "registry.h"
#include "string_vector.h"
#include "game.h"
#include "citydlg_common.h"
#include "client_main.h"
#include "dialogs.h"
#include "gui_tilespec.h"
#include "mapview.h"
#include "sprite.h"
#include "themespec.h"
#include "speclist.h"
#include "spechash.h"
Go to the source code of this file.
Data Structures | |
struct | specfile |
struct | small_sprite |
struct | theme |
Functions | |
const char * | theme_get_name (const struct theme *t) |
const char * | theme_font_filename (const struct theme *t) |
int | theme_default_font_size (const struct theme *t) |
static struct theme * | theme_new (void) |
const char ** | get_theme_list (void) |
static char * | themespec_fullname (const char *theme_name) |
static bool | check_themespec_capabilities (struct section_file *file, const char *which, const char *us_capstr, const char *filename) |
static void | theme_free_toplevel (struct theme *t) |
void | theme_free (struct theme *ftheme) |
void | themespec_try_read (const char *theme_name) |
void | themespec_reread (const char *new_theme_name) |
static struct sprite * | load_gfx_file (const char *gfx_filename) |
static void | theme_ensure_big_sprite (struct specfile *sf) |
static void | scan_specfile (struct theme *t, struct specfile *sf, bool duplicates_ok) |
char * | themespec_gfx_filename (const char *gfx_filename) |
struct theme * | theme_read_toplevel (const char *theme_name) |
static struct sprite * | theme_load_sprite (struct theme *t, const char *tag_name) |
static void | theme_unload_sprite (struct theme *t, const char *tag_name) |
static void | theme_lookup_sprite_tags (struct theme *t) |
static void | theme_finish_loading_sprites (struct theme *t) |
void | theme_load_sprites (struct theme *t) |
struct sprite * | theme_lookup_sprite_tag_alt (struct theme *t, enum log_level level, const char *tag, const char *alt, const char *what, const char *name) |
static void | theme_unload_all_sprites (struct theme *t) |
void | theme_free_sprites (struct theme *t) |
struct theme_background_system * | theme_get_background_system (const struct theme *t) |
struct theme_color_system * | theme_get_color_system (const struct theme *t) |
Variables | |
struct theme * | active_theme = NULL |
#define ADD_SPRITE | ( | s, | |
draw_fog, | |||
x_offset, | |||
y_offset | |||
) |
Definition at line 1039 of file themespec.c.
#define ADD_SPRITE_FULL | ( | s | ) | ADD_SPRITE(s, TRUE, FULL_TILE_X_OFFSET, FULL_TILE_Y_OFFSET) |
Definition at line 1047 of file themespec.c.
#define ADD_SPRITE_SIMPLE | ( | s | ) | ADD_SPRITE(s, TRUE, 0, 0) |
Definition at line 1046 of file themespec.c.
#define FULL_TILE_X_OFFSET ((t->normal_tile_width - t->full_tile_width) / 2) |
Definition at line 1036 of file themespec.c.
#define FULL_TILE_Y_OFFSET (t->normal_tile_height - t->full_tile_height) |
Definition at line 1037 of file themespec.c.
#define SET_SPRITE | ( | field, | |
tag | |||
) |
Definition at line 927 of file themespec.c.
#define SET_SPRITE_ALT | ( | field, | |
tag, | |||
alt | |||
) |
Definition at line 935 of file themespec.c.
#define SET_SPRITE_ALT_OPT | ( | field, | |
tag, | |||
alt | |||
) |
Definition at line 950 of file themespec.c.
#define SET_SPRITE_OPT | ( | field, | |
tag | |||
) | t->sprites.field = theme_load_sprite(t, tag) |
Definition at line 947 of file themespec.c.
Definition at line 128 of file themespec.c.
#define small_sprite_hash_iterate_end HASH_ITERATE_END |
Definition at line 131 of file themespec.c.
#define small_sprite_list_iterate | ( | list, | |
pitem | |||
) | TYPED_LIST_ITERATE(struct small_sprite, list, pitem) |
Definition at line 116 of file themespec.c.
#define small_sprite_list_iterate_end LIST_ITERATE_END |
Definition at line 118 of file themespec.c.
#define SPEC_SDL2_CAPSTR "+Freeciv-3.1-sdl2-spec" |
Definition at line 62 of file themespec.c.
#define specfile_list_iterate | ( | list, | |
pitem | |||
) | TYPED_LIST_ITERATE(struct specfile, list, pitem) |
Definition at line 87 of file themespec.c.
#define specfile_list_iterate_end LIST_ITERATE_END |
Definition at line 89 of file themespec.c.
#define SPECHASH_IDATA_TYPE struct small_sprite * |
Definition at line 122 of file themespec.c.
#define SPECHASH_IKEY_COMP genhash_str_comp_func |
Definition at line 124 of file themespec.c.
#define SPECHASH_IKEY_COPY genhash_str_copy_func |
Definition at line 125 of file themespec.c.
#define SPECHASH_IKEY_FREE genhash_str_free_func |
Definition at line 126 of file themespec.c.
#define SPECHASH_IKEY_TYPE char * |
Definition at line 121 of file themespec.c.
#define SPECHASH_IKEY_VAL genhash_str_val_func |
Definition at line 123 of file themespec.c.
#define SPECHASH_TAG small_sprite |
Definition at line 120 of file themespec.c.
#define SPECLIST_TAG specfile |
Definition at line 83 of file themespec.c.
#define SPECLIST_TAG small_sprite |
Definition at line 83 of file themespec.c.
#define SPECLIST_TYPE struct specfile |
Definition at line 84 of file themespec.c.
#define SPECLIST_TYPE struct small_sprite |
Definition at line 84 of file themespec.c.
#define THEMESPEC_SDL2_CAPSTR "+Freeciv-2.6-sdl2-themespec duplicates_ok" |
Definition at line 50 of file themespec.c.
#define THEMESPEC_SUFFIX ".themespec" |
Definition at line 69 of file themespec.c.
|
static |
Checks options in filename match what we require and support. Die if not. 'which' should be "themespec" or "spec".
Definition at line 256 of file themespec.c.
Referenced by scan_specfile(), theme_ensure_big_sprite(), and theme_read_toplevel().
const char ** get_theme_list | ( | void | ) |
Returns a static list of themes available on the system by searching all data directories for files matching THEMESPEC_SUFFIX. The list is NULL-terminated.
Definition at line 200 of file themespec.c.
|
static |
Loads the given graphics file (found in the data path) into a newly allocated sprite.
Definition at line 451 of file themespec.c.
Referenced by theme_ensure_big_sprite(), and theme_load_sprite().
Scan all sprites declared in the given specfile. This means that the positions of the sprites in the big_sprite are saved in the small_sprite structs.
Definition at line 525 of file themespec.c.
Referenced by theme_read_toplevel().
int theme_default_font_size | ( | const struct theme * | t | ) |
Return theme's default font size.
Definition at line 177 of file themespec.c.
Referenced by default_font_size().
|
static |
Ensure that the big sprite of the given spec file is loaded.
Definition at line 480 of file themespec.c.
Referenced by theme_load_sprite().
|
static |
Frees any internal buffers which are created by theme_load_sprite. Should be called after the last (for a given period of time) theme_load_sprite call. This saves a fair amount of memory, but it will take extra time the next time we start loading sprites again.
Definition at line 976 of file themespec.c.
Referenced by theme_load_sprites().
const char * theme_font_filename | ( | const struct theme * | t | ) |
Return the path within the data directories where the font file can be found. (It is left up to the GUI code to load and unload this file.)
Definition at line 169 of file themespec.c.
Referenced by load_font().
void theme_free | ( | struct theme * | ftheme | ) |
Free resources allocated for the theme.
Definition at line 316 of file themespec.c.
Referenced by get_theme_list(), gui_load_theme(), theme_read_toplevel(), themespec_try_read(), and ui_main().
void theme_free_sprites | ( | struct theme * | t | ) |
Free all sprites for the theme.
Definition at line 1067 of file themespec.c.
Referenced by theme_free(), and themespec_reread().
|
static |
Frees the themespec toplevel data, in preparation for re-reading it.
See themespec_read_toplevel().
Definition at line 294 of file themespec.c.
Referenced by theme_free(), and themespec_reread().
struct theme_background_system * theme_get_background_system | ( | const struct theme * | t | ) |
Return the theme's background system.
Definition at line 1116 of file themespec.c.
Referenced by theme_get_background().
struct theme_color_system * theme_get_color_system | ( | const struct theme * | t | ) |
Return the theme's color system.
Definition at line 1124 of file themespec.c.
Referenced by theme_get_color().
const char * theme_get_name | ( | const struct theme * | t | ) |
Return the name of the given theme.
Definition at line 160 of file themespec.c.
Loads the sprite. If the sprite is already loaded a reference counter is increased. Can return NULL if the sprite couldn't be loaded.
Definition at line 857 of file themespec.c.
Referenced by theme_lookup_sprite_tag_alt().
void theme_load_sprites | ( | struct theme * | t | ) |
Load the tiles; requires themespec_read_toplevel() called previously. Leads to tile_sprites being allocated and filled with pointers to sprites. Also sets up and populates sprite_hash, and calls func to initialize 'sprites' structure.
Definition at line 992 of file themespec.c.
Referenced by gui_load_theme(), and themespec_reread().
struct sprite * theme_lookup_sprite_tag_alt | ( | struct theme * | t, |
enum log_level | level, | ||
const char * | tag, | ||
const char * | alt, | ||
const char * | what, | ||
const char * | name | ||
) |
Lookup sprite to match tag, or else to match alt if don't find, or else return NULL, and emit log message.
Definition at line 1002 of file themespec.c.
Referenced by tilespec_setup_city_gfx().
|
static |
Initialize 'sprites' structure based on hardwired tags which the client always requires.
Definition at line 960 of file themespec.c.
Referenced by theme_load_sprites().
|
static |
struct theme * theme_read_toplevel | ( | const char * | theme_name | ) |
Finds and reads the toplevel themespec file based on given name. Sets global variables, including tile sizes and full names for intro files.
Definition at line 716 of file themespec.c.
Referenced by get_theme_list(), themespec_reread(), and themespec_try_read().
|
static |
Unload all sprites from theme sprite hash (the hash itself is left intact).
Definition at line 1053 of file themespec.c.
Referenced by theme_free_sprites().
|
static |
Unloads the sprite. Decrease the reference counter. If the last reference is removed the sprite is freed.
Definition at line 906 of file themespec.c.
Referenced by theme_unload_all_sprites().
|
static |
Gets full filename for themespec file, based on input name. Returned data is allocated, and freed by user as required. Input name may be null, in which case uses default. Falls back to default if can't find specified name; dies if can't find default.
Definition at line 233 of file themespec.c.
Referenced by theme_read_toplevel().
char * themespec_gfx_filename | ( | const char * | gfx_filename | ) |
Returns the correct name of the gfx file (with path and extension) Must be free'd when no longer used
Definition at line 685 of file themespec.c.
Referenced by theme_background_system_read().
void themespec_reread | ( | const char * | new_theme_name | ) |
Read a new themespec in from scratch.
Unlike the initial reading code, which reads pieces one at a time, this gets rid of the old data and reads in the new all at once. If the new theme fails to load the old theme may be reloaded; otherwise the client will exit. If a NULL name is given the current theme will be reread.
It will also call the necessary functions to redraw the graphics.
Definition at line 372 of file themespec.c.
void themespec_try_read | ( | const char * | theme_name | ) |
Read a new themespec in when first starting the game.
Call this function with the (guessed) name of the theme, when starting the client.
Definition at line 333 of file themespec.c.
Referenced by gui_load_theme().
struct theme* active_theme = NULL |
Definition at line 154 of file themespec.c.
Referenced by arrange_widgets(), draw_intro_gfx(), economy_report_dialog_popup(), get_theme_color(), gui_load_theme(), load_font(), meswin_dialog_popup(), popup_change_research_dialog(), popup_change_research_goal_dialog(), popup_city_cma_dialog(), popup_conn_list_dialog(), popup_connection_dialog(), popup_government_dialog(), popup_impr_info(), popup_join_game_dialog(), popup_load_game_dialog(), popup_new_user_passwd_dialog(), popup_newcity_dialog(), popup_races_dialog(), popup_tech_info(), popup_unit_info(), popup_user_passwd_dialog(), popup_worklist_editor(), real_activeunits_report_dialog_update(), real_city_dialog_popup(), real_info_city_report_dialog_update(), science_report_dialog_popup(), show_main_page(), spy_steal_popup_shared(), themespec_reread(), themespec_try_read(), tilespec_setup_city_gfx(), and ui_main().