49
49
#include "themespec.h"
51
#define THEMESPEC_CAPSTR "+themespec3 duplicates_ok"
53
* Themespec capabilities acceptable to this program:
55
* +themespec3 - basic format; required
57
* duplicates_ok - we can handle existence of duplicate tags
58
* (lattermost tag which appears is used; themes which
59
* have duplicates should specify "+duplicates_ok")
62
#define SPEC_CAPSTR "+spec3"
64
* Individual spec file capabilities acceptable to this program:
65
* +spec3 - basic format, required
51
68
#define THEMESPEC_SUFFIX ".themespec"
123
140
struct theme *theme;
125
#define THEMESPEC_CAPSTR "+themespec3 duplicates_ok"
127
* Themespec capabilities acceptable to this program:
129
* +themespec3 - basic format; required
131
* duplicates_ok - we can handle existence of duplicate tags
132
* (lattermost tag which appears is used; themes which
133
* have duplicates should specify "+duplicates_ok")
136
#define SPEC_CAPSTR "+spec3"
138
* Individual spec file capabilities acceptable to this program:
139
* +spec3 - basic format, required
143
143
/****************************************************************************
144
144
Return the name of the given theme.
246
246
const char *us_capstr,
247
247
const char *filename)
249
int log_level = LOG_DEBUG;
249
251
char *file_capstr = secfile_lookup_str(file, "%s.options", which);
251
253
if (!has_capabilities(us_capstr, file_capstr)) {
252
freelog(LOG_DEBUG, _("%s file appears incompatible:\n"
255
"supported options: %s"),
256
which, filename, file_capstr, us_capstr);
254
freelog(log_level, "\"%s\": %s file appears incompatible:",
256
freelog(log_level, " datafile options: %s", file_capstr);
257
freelog(log_level, " supported options: %s", us_capstr);
259
260
if (!has_capabilities(file_capstr, us_capstr)) {
260
freelog(LOG_DEBUG, _("%s file claims required option(s)"
261
" which we don't support:\n"
264
"supported options: %s"),
265
which, filename, file_capstr, us_capstr);
261
freelog(log_level, "\"%s\": %s file requires option(s)"
262
" that client doesn't support:",
264
freelog(log_level, " datafile options: %s", file_capstr);
265
freelog(log_level, " supported options: %s", us_capstr);
339
338
exit(EXIT_FAILURE);
342
freelog(LOG_NORMAL, _("Trying \"%s\" theme."), theme->name);
341
freelog(LOG_VERBOSE, "Trying theme \"%s\".", theme->name);
344
/* sz_strlcpy(default_theme_name, theme_get_name(theme));*/
343
/* sz_strlcpy(gui_sdl_default_theme_name, theme_get_name(theme));*/
347
346
/**********************************************************************
366
365
sz_strlcpy(theme_name, name);
367
366
sz_strlcpy(old_name, theme->name);
369
freelog(LOG_NORMAL, "Loading theme %s.", theme_name);
368
freelog(LOG_NORMAL, _("Loading theme \"%s\"."), theme_name);
371
370
/* Step 0: Record old data.
390
389
die("Failed to re-read the currently loaded theme.");
393
/* sz_strlcpy(default_theme_name, theme->name);*/
392
/* sz_strlcpy(gui_sdl_default_theme_name, theme->name);*/
394
393
theme_load_sprites(theme);
422
421
/* theme_changed();*/
423
422
can_slide = FALSE;
424
423
center_tile_mapcanvas(center_tile);
425
/* update_map_cavnas_visible forces a full redraw. Otherwise with fast
424
/* update_map_canvas_visible forces a full redraw. Otherwise with fast
426
425
* drawing we might not get one. Of course this is slower. */
427
426
update_map_canvas_visible();
428
427
can_slide = TRUE;
431
430
/**************************************************************************
432
This is merely a wrapper for themespec_reread (above) for use in
433
options.c and the client local options dialog.
434
**************************************************************************/
435
void themespec_reread_callback(struct client_option *option)
437
assert(option->p_string_value && *option->p_string_value != '\0');
438
themespec_reread(option->p_string_value);
441
/**************************************************************************
442
431
Loads the given graphics file (found in the data path) into a newly
443
432
allocated sprite.
444
433
**************************************************************************/
455
444
sprintf(full_name, "%s.%s", gfx_filename, gfx_fileext);
456
445
if ((real_full_name = datafilename(full_name))) {
457
freelog(LOG_DEBUG, "trying to load gfx file %s", real_full_name);
446
freelog(LOG_DEBUG, "trying to load gfx file \"%s\".", real_full_name);
458
447
s = load_gfxfile(real_full_name);
497
486
sf->big_sprite = load_gfx_file(gfx_filename);
499
488
if (!sf->big_sprite) {
500
freelog(LOG_FATAL, _("Couldn't load gfx file for the spec file %s"),
489
freelog(LOG_FATAL, "Could not load gfx file for the spec file \"%s\".",
502
491
exit(EXIT_FAILURE);
583
572
if (!duplicates_ok) {
584
573
for (k = 0; k < num_tags; k++) {
585
574
if (!hash_insert(t->sprite_hash, mystrdup(tags[k]), ss)) {
586
freelog(LOG_ERROR, "warning: already have a sprite for %s", tags[k]);
575
freelog(LOG_ERROR, "warning: already have a sprite for \"%s\".", tags[k]);
625
614
if (!duplicates_ok) {
626
615
for (k = 0; k < num_tags; k++) {
627
616
if (!hash_insert(t->sprite_hash, mystrdup(tags[k]), ss)) {
628
freelog(LOG_ERROR, "warning: already have a sprite for %s", tags[k]);
617
freelog(LOG_ERROR, "warning: already have a sprite for \"%s\".", tags[k]);
690
679
fname = themespec_fullname(theme_name);
681
freelog(LOG_ERROR, "Can't find theme \"%s\".", theme_name);
695
freelog(LOG_VERBOSE, "themespec file is %s", fname);
685
freelog(LOG_VERBOSE, "themespec file is \"%s\".", fname);
697
687
if (!section_file_load(file, fname)) {
698
freelog(LOG_ERROR, _("Could not open \"%s\"."), fname);
688
freelog(LOG_ERROR, "Could not open \"%s\".", fname);
699
689
section_file_free(file);
786
777
section_file_check_unused(file, fname);
788
779
section_file_free(file);
789
freelog(LOG_VERBOSE, "finished reading %s", fname);
780
freelog(LOG_VERBOSE, "finished reading \"%s\".", fname);
817
808
ss->sprite = load_gfx_file(ss->file);
818
809
if (!ss->sprite) {
819
freelog(LOG_FATAL, _("Couldn't load gfx file %s for sprite %s"),
810
freelog(LOG_FATAL, "Couldn't load gfx file \"%s\" for sprite '%s'.",
820
811
ss->file, tag_name);
821
812
exit(EXIT_FAILURE);
828
819
if (ss->x < 0 || ss->x + ss->width > sf_w
829
820
|| ss->y < 0 || ss->y + ss->height > sf_h) {
830
821
freelog(LOG_ERROR,
831
"Sprite '%s' in file '%s' isn't within the image!",
822
"Sprite '%s' in file \"%s\" isn't within the image!",
832
823
tag_name, ss->sf->file_name);
861
852
if (ss->ref_count == 0) {
862
853
/* Nobody's using the sprite anymore, so we should free it. We know
863
854
* where to find it if we need it again. */
864
freelog(LOG_DEBUG, "freeing sprite '%s'", tag_name);
855
freelog(LOG_DEBUG, "freeing sprite '%s'.", tag_name);
865
856
free_sprite(ss->sprite);
866
857
ss->sprite = NULL;
873
864
t->sprites.field = load_sprite(t, tag); \
874
865
if (!t->sprites.field) { \
875
die("Sprite tag %s missing.", tag); \
866
die("Sprite tag '%s' missing.", tag); \
884
875
t->sprites.field = load_sprite(t, alt); \
886
877
if (!t->sprites.field) { \
887
die("Sprite tag %s and alternate %s are both missing.", tag, alt); \
878
die("Sprite tag '%s' and alternate '%s' are both missing.", tag, alt);\
895
886
#define SET_SPRITE_ALT_OPT(field, tag, alt) \
897
t->sprites.field = theme_lookup_sprite_tag_alt(t, tag, alt, FALSE, \
888
t->sprites.field = theme_lookup_sprite_tag_alt(t, LOG_VERBOSE, tag, alt,\
901
892
/**********************************************************************
943
934
Lookup sprite to match tag, or else to match alt if don't find,
944
935
or else return NULL, and emit log message.
945
936
***********************************************************************/
946
struct sprite* theme_lookup_sprite_tag_alt(struct theme *t,
947
const char *tag, const char *alt,
948
bool required, const char *what,
937
struct sprite* theme_lookup_sprite_tag_alt(struct theme *t, int loglevel,
938
const char *tag, const char *alt,
939
const char *what, const char *name)
951
941
struct sprite *sp;
953
943
/* (should get sprite_hash before connection) */
954
944
if (!t->sprite_hash) {
955
die("attempt to lookup for %s %s before sprite_hash setup", what, name);
945
die("attempt to lookup for %s \"%s\" before sprite_hash setup", what, name);
958
948
sp = load_sprite(t, tag);
961
951
sp = load_sprite(t, alt);
963
953
freelog(LOG_VERBOSE,
964
"Using alternate graphic %s (instead of %s) for %s %s",
954
"Using alternate graphic \"%s\" (instead of \"%s\") for %s \"%s\".",
965
955
alt, tag, what, name);
969
freelog(required ? LOG_FATAL : LOG_VERBOSE,
970
_("Don't have graphics tags %s or %s for %s %s"),
960
"Don't have graphics tags \"%s\" or \"%s\" for %s \"%s\".",
971
961
tag, alt, what, name);
962
if (LOG_FATAL >= loglevel) {
973
963
exit(EXIT_FAILURE);