Freeciv-3.2: /fast/freeciv/nightly/S3_2/client/themes_common.c Source File

Freeciv-3.2

Loading...
Searching...
No Matches
themes_common.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 2005 The Freeciv Team
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12***********************************************************************/
13#ifdef HAVE_CONFIG_H
14#include <fc_config.h>
15#endif
16
17#include <unistd.h>
18#include <string.h>
19#include <sys/stat.h>
20
21/* utility */
22#include "log.h"
23#include "mem.h"
24#include "shared.h"
25#include "string_vector.h"
26#include "support.h"
27
28/* client/include */
29#include "themes_g.h"
30
31/* client */
32#include "themes_common.h"
33
34/***************************************************************************
35 A theme is a portion of client data, which for following reasons should
36 be separated from a tileset:
37 - Theme is not only graphic related
38 - Theme can be changed independently from tileset
39 - Theme implementation is gui specific and most themes can not be shared
40 between different guis.
41 Theme is recognized by its name.
42
43 Theme is stored in a directory called like the theme. The directory contains
44 some data files. Each gui defines its own format in the
45 get_useable_themes_in_directory() function.
46****************************************************************************/
47
48/* A directory containing a list of usable themes */
49 struct theme_directory {
50 /* Path on the filesystem */
51 char *path;
52 /* Array of theme names */
53 char **themes;
54 /* Themes array length */
55 int num_themes;
56};
57
58/* List of all directories with themes */
59 static int num_directories;
60 struct theme_directory *directories;
61
62/************************************************************************/
65 void init_themes(void)
66{
67 int i;
68
69 /* get GUI-specific theme directories */
70 char **gui_directories =
71 get_gui_specific_themes_directories(&num_directories);
72
73 directories =
74 fc_malloc(sizeof(struct theme_directory) * num_directories);
75
76 for (i = 0; i < num_directories; i++) {
77 directories[i].path = gui_directories[i];
78
79 /* get useable themes in this directory */
80 directories[i].themes =
81 get_useable_themes_in_directory(directories[i].path,
82 &(directories[i].num_themes));
83 }
84 free(gui_directories);
85}
86
87/************************************************************************/
90 const struct strvec *get_themes_list(const struct option *poption)
91{
92 static struct strvec *themes_list = NULL;
93
94 if (NULL == themes_list) {
95 int i, j, k;
96
97 themes_list = strvec_new();
98 for (i = 0; i < num_directories; i++) {
99 for (j = 0; j < directories[i].num_themes; j++) {
100 for (k = 0; k < strvec_size(themes_list); k++) {
101 if (strcmp(strvec_get(themes_list, k),
102 directories[i].themes[j]) == 0) {
103 break;
104 }
105 }
106 if (k == strvec_size(themes_list)) {
107 strvec_append(themes_list, directories[i].themes[j]);
108 }
109 }
110 }
111 }
112
113 return themes_list;
114}
115
116/************************************************************************/
120 bool load_theme(const char *theme_name)
121{
122 int i, j;
123
124 for (i = 0; i < num_directories; i++) {
125 for (j = 0; j < directories[i].num_themes; j++) {
126 if (strcmp(theme_name, directories[i].themes[j]) == 0) {
127 gui_load_theme(directories[i].path, directories[i].themes[j]);
128 return TRUE;
129 }
130 }
131 }
132 return FALSE;
133}
134
135/************************************************************************/
138 void theme_reread_callback(struct option *poption)
139{
140 const char *theme_name = option_str_get(poption);
141
142 fc_assert_ret(NULL != theme_name && theme_name[0] != '\0');
143 load_theme(theme_name);
144}
incite_cost
char * incite_cost
Definition comments.c:74
load_theme
static bool load_theme
Definition theme_dlg.c:30
get_gui_specific_themes_directories
char ** get_gui_specific_themes_directories(int *count)
Definition themes.c:104
gui_load_theme
void gui_load_theme(const char *directory, const char *theme_name)
Definition themes.c:45
log.h
fc_assert_ret
#define fc_assert_ret(condition)
Definition log.h:191
mem.h
fc_malloc
#define fc_malloc(sz)
Definition mem.h:34
option_str_get
const char * option_str_get(const struct option *poption)
Definition options.c:892
shared.h
strvec_append
void strvec_append(struct strvec *psv, const char *string)
Definition string_vector.c:278
strvec_get
const char * strvec_get(const struct strvec *psv, size_t svindex)
Definition string_vector.c:388
strvec_new
struct strvec * strvec_new(void)
Definition string_vector.c:58
strvec_size
size_t strvec_size(const struct strvec *psv)
Definition string_vector.c:343
string_vector.h
option
Definition options.c:478
strvec
Definition string_vector.c:29
theme_directory
Definition themes_common.c:49
theme_directory::themes
char ** themes
Definition themes_common.c:53
theme_directory::path
char * path
Definition themes_common.c:51
theme_directory::num_themes
int num_themes
Definition themes_common.c:55
support.h
TRUE
#define TRUE
Definition support.h:46
FALSE
#define FALSE
Definition support.h:47
theme_reread_callback
void theme_reread_callback(struct option *poption)
Definition themes_common.c:138
directories
struct theme_directory * directories
Definition themes_common.c:60
num_directories
static int num_directories
Definition themes_common.c:59
get_themes_list
const struct strvec * get_themes_list(const struct option *poption)
Definition themes_common.c:90
init_themes
void init_themes(void)
Definition themes_common.c:65
themes_common.h
themes_g.h
get_useable_themes_in_directory
get_useable_themes_in_directory
Definition themes_g.h:22