~ubuntu-branches/ubuntu/natty/freeciv/natty-proposed

« back to all changes in this revision

Viewing changes to client/gui-sdl/themespec.c

  • Committer: Bazaar Package Importer
  • Author(s): Clint Adams, Karl Goetz, Clint Adams
  • Date: 2010-02-23 22:09:02 UTC
  • mfrom: (7.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20100223220902-s3spqi1x4e190y0t
Tags: 2.2.0-1
[ Karl Goetz ]
* Remove civserver files in /etc/ggzd/ (Closes: 523772, 517787)
* Adding ${misc:Depends} to all binary packages (lintian warnings)

[ Clint Adams ]
* New upstream version.
  - Drop data_dsc_use_bindir.diff (binary pathnames have changed).

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
 
39
39
/* client */
40
40
#include "citydlg_common.h"
41
 
#include "civclient.h"          /* for client_state() */
 
41
#include "client_main.h"                /* for client_state() */
42
42
 
43
43
/* gui-sdl */
44
44
#include "dialogs.h"
48
48
 
49
49
#include "themespec.h"
50
50
 
 
51
#define THEMESPEC_CAPSTR "+themespec3 duplicates_ok"
 
52
/*
 
53
 * Themespec capabilities acceptable to this program:
 
54
 *
 
55
 * +themespec3     -  basic format; required
 
56
 *
 
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")
 
60
 */
 
61
 
 
62
#define SPEC_CAPSTR "+spec3"
 
63
/*
 
64
 * Individual spec file capabilities acceptable to this program:
 
65
 * +spec3          -  basic format, required
 
66
 */
 
67
 
51
68
#define THEMESPEC_SUFFIX ".themespec"
52
69
 
53
70
#if 0
122
139
 
123
140
struct theme *theme;
124
141
 
125
 
#define THEMESPEC_CAPSTR "+themespec3 duplicates_ok"
126
 
/*
127
 
 * Themespec capabilities acceptable to this program:
128
 
 *
129
 
 * +themespec3     -  basic format; required
130
 
 *
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")
134
 
 */
135
 
 
136
 
#define SPEC_CAPSTR "+spec3"
137
 
/*
138
 
 * Individual spec file capabilities acceptable to this program:
139
 
 * +spec3          -  basic format, required
140
 
 */
141
 
 
142
142
 
143
143
/****************************************************************************
144
144
  Return the name of the given theme.
246
246
                                        const char *us_capstr,
247
247
                                        const char *filename)
248
248
{
 
249
  int log_level = LOG_DEBUG;
 
250
 
249
251
  char *file_capstr = secfile_lookup_str(file, "%s.options", which);
250
252
  
251
253
  if (!has_capabilities(us_capstr, file_capstr)) {
252
 
    freelog(LOG_DEBUG, _("%s file appears incompatible:\n"
253
 
                         "file: \"%s\"\n"
254
 
                         "file options: %s\n"
255
 
                         "supported options: %s"),
256
 
            which, filename, file_capstr, us_capstr);
 
254
    freelog(log_level, "\"%s\": %s file appears incompatible:",
 
255
            filename, which);
 
256
    freelog(log_level, "  datafile options: %s", file_capstr);
 
257
    freelog(log_level, "  supported options: %s", us_capstr);
257
258
    return FALSE;
258
259
  }
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"
262
 
                         "file: \"%s\"\n"
263
 
                         "file options: %s\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:",
 
263
            filename, which);
 
264
    freelog(log_level, "  datafile options: %s", file_capstr);
 
265
    freelog(log_level, "  supported options: %s", us_capstr);
266
266
    return FALSE;
267
267
  }
268
268
 
291
291
    theme_color_system_free(t->color_system);
292
292
    t->color_system = NULL;
293
293
  }
294
 
  
295
294
}
296
295
 
297
296
/**************************************************************************
339
338
      exit(EXIT_FAILURE);
340
339
    }
341
340
 
342
 
    freelog(LOG_NORMAL, _("Trying \"%s\" theme."), theme->name);
 
341
    freelog(LOG_VERBOSE, "Trying theme \"%s\".", theme->name);
343
342
  }
344
 
/*  sz_strlcpy(default_theme_name, theme_get_name(theme));*/
 
343
/*  sz_strlcpy(gui_sdl_default_theme_name, theme_get_name(theme));*/
345
344
}
346
345
 
347
346
/**********************************************************************
366
365
  sz_strlcpy(theme_name, name);
367
366
  sz_strlcpy(old_name, theme->name);
368
367
 
369
 
  freelog(LOG_NORMAL, "Loading theme %s.", theme_name);
 
368
  freelog(LOG_NORMAL, _("Loading theme \"%s\"."), theme_name);
370
369
 
371
370
  /* Step 0:  Record old data.
372
371
   *
390
389
      die("Failed to re-read the currently loaded theme.");
391
390
    }
392
391
  }
393
 
/*  sz_strlcpy(default_theme_name, theme->name);*/
 
392
/*  sz_strlcpy(gui_sdl_default_theme_name, theme->name);*/
394
393
  theme_load_sprites(theme);
395
394
 
396
395
  /* Step 3: Setup
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;
429
428
}
430
429
 
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)
436
 
{
437
 
  assert(option->p_string_value && *option->p_string_value != '\0');
438
 
  themespec_reread(option->p_string_value);
439
 
}
440
 
 
441
 
/**************************************************************************
442
431
  Loads the given graphics file (found in the data path) into a newly
443
432
  allocated sprite.
444
433
**************************************************************************/
454
443
 
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);
459
448
      if (s) {
460
449
        return s;
462
451
    }
463
452
  }
464
453
 
465
 
  freelog(LOG_VERBOSE, "Could not load gfx file %s.", gfx_filename);
 
454
  freelog(LOG_ERROR, "Could not load gfx file \"%s\".", gfx_filename);
466
455
  return NULL;
467
456
}
468
457
 
497
486
  sf->big_sprite = load_gfx_file(gfx_filename);
498
487
 
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\".",
501
490
            sf->file_name);
502
491
    exit(EXIT_FAILURE);
503
492
  }
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]);
587
576
          }
588
577
        }
589
578
      } else {
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]);
629
618
        }
630
619
      }
631
620
    } else {
664
653
    }
665
654
  }
666
655
 
667
 
  freelog(LOG_FATAL, _("Couldn't find a supported gfx file extension for %s"),
 
656
  freelog(LOG_FATAL, "Couldn't find a supported gfx file extension for \"%s\".",
668
657
         gfx_filename);
669
658
  exit(EXIT_FAILURE);
670
659
  return NULL;
689
678
 
690
679
  fname = themespec_fullname(theme_name);
691
680
  if (!fname) {
 
681
    freelog(LOG_ERROR, "Can't find theme \"%s\".", theme_name); 
692
682
    theme_free(t);
693
683
    return NULL;
694
684
  }
695
 
  freelog(LOG_VERBOSE, "themespec file is %s", fname);
 
685
  freelog(LOG_VERBOSE, "themespec file is \"%s\".", fname);
696
686
 
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);
700
690
    FC_FREE(fname);
701
691
    theme_free(t);
768
758
    sf->big_sprite = NULL;
769
759
    dname = datafilename(spec_filenames[i]);
770
760
    if (!dname) {
 
761
      freelog(LOG_ERROR, "Can't find spec file \"%s\".", spec_filenames[i]);
771
762
      section_file_free(file);
772
763
      FC_FREE(fname);
773
764
      theme_free(t);
786
777
  section_file_check_unused(file, fname);
787
778
  
788
779
  section_file_free(file);
789
 
  freelog(LOG_VERBOSE, "finished reading %s", fname);
 
780
  freelog(LOG_VERBOSE, "finished reading \"%s\".", fname);
790
781
  FC_FREE(fname);
791
782
 
792
783
  return t;
816
807
    if (ss->file) {
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);
822
813
      }
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);
833
824
        return NULL;
834
825
      }
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;
867
858
  }
872
863
  do {                                                            \
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);                       \
876
867
    }                                                             \
877
868
  } while(FALSE)
878
869
 
884
875
      t->sprites.field = load_sprite(t, alt);                               \
885
876
    }                                                                       \
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);\
888
879
    }                                                                       \
889
880
  } while(FALSE)
890
881
 
894
885
 
895
886
#define SET_SPRITE_ALT_OPT(field, tag, alt)                                 \
896
887
  do {                                                                      \
897
 
    t->sprites.field = theme_lookup_sprite_tag_alt(t, tag, alt, FALSE,      \
898
 
                                             "sprite", #field);             \
 
888
    t->sprites.field = theme_lookup_sprite_tag_alt(t, LOG_VERBOSE, tag, alt,\
 
889
                                                   "sprite", #field);       \
899
890
  } while (FALSE)
900
891
 
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,
949
 
                                            const char *name)
 
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)
950
940
{
951
941
  struct sprite *sp;
952
942
  
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);
956
946
  }
957
947
 
958
948
  sp = load_sprite(t, tag);
961
951
  sp = load_sprite(t, alt);
962
952
  if (sp) {
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);
966
956
    return sp;
967
957
  }
968
958
 
969
 
  freelog(required ? LOG_FATAL : LOG_VERBOSE,
970
 
          _("Don't have graphics tags %s or %s for %s %s"),
 
959
  freelog(loglevel,
 
960
          "Don't have graphics tags \"%s\" or \"%s\" for %s \"%s\".",
971
961
          tag, alt, what, name);
972
 
  if (required) {
 
962
  if (LOG_FATAL >= loglevel) {
973
963
    exit(EXIT_FAILURE);
974
964
  }
975
965
  return NULL;
1016
1006
{
1017
1007
  int i;
1018
1008
 
1019
 
  freelog(LOG_DEBUG, "theme_free_sprites");
 
1009
  freelog(LOG_DEBUG, "theme_free_sprites()");
1020
1010
 
1021
1011
  unload_all_sprites(t);
1022
1012