mirror of https://github.com/tstellar/bygfoot.git
Country selection convenience stuff.
This commit is contained in:
parent
8965fe9455
commit
27b02de8b4
85
src/file.c
85
src/file.c
|
@ -517,9 +517,16 @@ file_get_country_files(void)
|
|||
|
||||
elem = elem->next;
|
||||
}
|
||||
free_gchar_array(&country_files);
|
||||
|
||||
return country_files_full_path;
|
||||
free_gchar_array(&country_files);
|
||||
country_files = g_ptr_array_new();
|
||||
|
||||
for(i = country_files_full_path->len - 1; i >= 0; i--)
|
||||
g_ptr_array_add(country_files, g_strdup(g_ptr_array_index(country_files_full_path, i)));
|
||||
|
||||
free_gchar_array(&country_files_full_path);
|
||||
|
||||
return country_files;
|
||||
}
|
||||
|
||||
/** Read the file until the next line that's not a comment or
|
||||
|
@ -935,3 +942,77 @@ file_get_bygfoot_dir(gchar *dir)
|
|||
|
||||
g_free(pwd);
|
||||
}
|
||||
|
||||
/** Store text information in a text file in the saves directory.
|
||||
*/
|
||||
void
|
||||
file_store_text_in_saves(const gchar *filename, const gchar *text)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
printf("file_store_text_in_saves\n");
|
||||
#endif
|
||||
|
||||
gchar buf[SMALL];
|
||||
const gchar *home = g_get_home_dir();
|
||||
FILE *fil = NULL;
|
||||
|
||||
if(os_is_unix)
|
||||
sprintf(buf, "%s%s%s%ssaves%s%s", home, G_DIR_SEPARATOR_S,
|
||||
HOMEDIRNAME, G_DIR_SEPARATOR_S, G_DIR_SEPARATOR_S,
|
||||
filename);
|
||||
else
|
||||
{
|
||||
gchar *pwd = g_get_current_dir();
|
||||
sprintf(buf, "%s%ssaves%s%s", pwd, G_DIR_SEPARATOR_S,
|
||||
G_DIR_SEPARATOR_S, filename);
|
||||
g_free(pwd);
|
||||
}
|
||||
|
||||
if(!file_my_fopen(buf, "w", &fil, FALSE))
|
||||
{
|
||||
g_warning("file_store_text_in_saves: failed to store '%s' in file '%s'\n", text, buf);
|
||||
return;
|
||||
}
|
||||
|
||||
fprintf(fil, "%s", text);
|
||||
|
||||
fclose(fil);
|
||||
}
|
||||
|
||||
/** Load the text stored in the file in the saves directory. */
|
||||
gchar*
|
||||
file_load_text_from_saves(const gchar *filename)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
printf("file_load_text_from_saves\n");
|
||||
#endif
|
||||
|
||||
gchar buf[SMALL];
|
||||
const gchar *home = g_get_home_dir();
|
||||
FILE *fil = NULL;
|
||||
gint i = 0, c;
|
||||
|
||||
if(os_is_unix)
|
||||
sprintf(buf, "%s%s%s%ssaves%s%s", home, G_DIR_SEPARATOR_S,
|
||||
HOMEDIRNAME, G_DIR_SEPARATOR_S, G_DIR_SEPARATOR_S,
|
||||
filename);
|
||||
else
|
||||
{
|
||||
gchar *pwd = g_get_current_dir();
|
||||
sprintf(buf, "%s%ssaves%s%s", pwd, G_DIR_SEPARATOR_S,
|
||||
G_DIR_SEPARATOR_S, filename);
|
||||
g_free(pwd);
|
||||
}
|
||||
|
||||
fil = fopen(buf, "r");
|
||||
if(fil == NULL)
|
||||
return NULL;
|
||||
|
||||
while ((c = (gchar)fgetc(fil)) != EOF)
|
||||
buf[i++] = (gchar)c;
|
||||
buf[i] = 0;
|
||||
|
||||
fclose(fil);
|
||||
|
||||
return g_strdup(buf);
|
||||
}
|
||||
|
|
|
@ -109,4 +109,10 @@ file_get_bygfoot_dir(gchar *dir);
|
|||
void
|
||||
file_load_hints_file(void);
|
||||
|
||||
gchar*
|
||||
file_load_text_from_saves(const gchar *filename);
|
||||
|
||||
void
|
||||
file_store_text_in_saves(const gchar *filename, const gchar *text);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -123,60 +123,6 @@ language_get_code_index(const gchar *code)
|
|||
return return_value;
|
||||
}
|
||||
|
||||
/** Compare country file names based on a preferred one (which
|
||||
should get moved to the start). */
|
||||
gint
|
||||
language_compare_country_files(gconstpointer a, gconstpointer b, gpointer data)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
printf("language_compare_country_files\n");
|
||||
#endif
|
||||
|
||||
gint i, j;
|
||||
const gchar *prefdef = (const gchar*)data;
|
||||
const gchar *def1 = *(const gchar**)a;
|
||||
const gchar *def2 = *(const gchar**)b;
|
||||
gint len1 = strlen(def1),
|
||||
len2 = strlen(def2), lenmin = MIN(len1, len2);
|
||||
gchar alphabet[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k',
|
||||
'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
|
||||
gint return_value = 0;
|
||||
|
||||
if(strcmp(def1, def2) == 0)
|
||||
return_value = 0;
|
||||
else if(prefdef != NULL && strcmp(prefdef, def1) == 0)
|
||||
return_value = -1;
|
||||
else if(prefdef != NULL && strcmp(prefdef, def2) == 0)
|
||||
return_value = 1;
|
||||
else
|
||||
{
|
||||
for(i=0;i<lenmin;i++)
|
||||
if(def1[i] != def2[i])
|
||||
break;
|
||||
|
||||
if(i == lenmin)
|
||||
return_value = (len2 < len1);
|
||||
else
|
||||
{
|
||||
for(j=0;j<26;j++)
|
||||
if(def1[i] == alphabet[j] ||
|
||||
def2[i] == alphabet[j])
|
||||
break;
|
||||
|
||||
if(j == 26)
|
||||
{
|
||||
g_warning("language_compare_country_files: chars %c and %c not comparable",
|
||||
def1[i], def2[i]);
|
||||
return_value = 0;
|
||||
}
|
||||
else
|
||||
return_value = (def1[i] == alphabet[j]) ? -1 : 1;
|
||||
}
|
||||
}
|
||||
|
||||
return return_value;
|
||||
}
|
||||
|
||||
/** Put the country matching the local language to the
|
||||
beginning of the array if possible. */
|
||||
void
|
||||
|
@ -200,27 +146,23 @@ language_pick_country(GPtrArray *country_files)
|
|||
if(lang != NULL)
|
||||
for(i=0;i<codes->len;i++)
|
||||
{
|
||||
if(((g_str_has_prefix(lang, "en") &&
|
||||
strcmp((gchar*)g_ptr_array_index(codes, i), "C") == 0) ||
|
||||
if(((g_str_has_prefix(lang, "en") && strcmp((gchar*)g_ptr_array_index(codes, i), "C") == 0) ||
|
||||
g_str_has_prefix(lang, (gchar*)g_ptr_array_index(codes, i))) &&
|
||||
strcmp((gchar*)g_ptr_array_index(defs, i), "NONE") != 0)
|
||||
for(j=0;j<country_files->len;j++)
|
||||
if(strcmp((gchar*)g_ptr_array_index(country_files, j),
|
||||
(gchar*)g_ptr_array_index(defs, i)) == 0)
|
||||
{
|
||||
for(j=0;j<country_files->len;j++)
|
||||
if(g_str_has_suffix((gchar*)g_ptr_array_index(country_files, j),
|
||||
(gchar*)g_ptr_array_index(defs, i)))
|
||||
{
|
||||
prefdef = g_ptr_array_index(country_files, j);
|
||||
g_ptr_array_remove_index(country_files, j);
|
||||
g_ptr_array_add(country_files, prefdef);
|
||||
break;
|
||||
}
|
||||
|
||||
if(prefdef != NULL)
|
||||
break;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
g_ptr_array_sort_with_data(
|
||||
country_files,
|
||||
(GCompareDataFunc)language_compare_country_files,
|
||||
prefdef);
|
||||
|
||||
free_gchar_array(&codes);
|
||||
free_gchar_array(&defs);
|
||||
}
|
||||
|
|
|
@ -39,9 +39,6 @@ language_get_code_index(const gchar *code);
|
|||
void
|
||||
language_set(gint index);
|
||||
|
||||
gint
|
||||
language_compare_country_files(gconstpointer a, gconstpointer b, gpointer data);
|
||||
|
||||
void
|
||||
language_pick_country(GPtrArray *country_files);
|
||||
|
||||
|
|
|
@ -178,7 +178,7 @@ load_save_save_game(const gchar *filename)
|
|||
gui_show_progress(1, _("Done."),
|
||||
PIC_TYPE_SAVE);
|
||||
|
||||
load_save_last_save_set(fullname->str);
|
||||
file_store_text_in_saves("last_save", fullname->str);
|
||||
|
||||
g_free(prefix);
|
||||
g_string_free(fullname, TRUE);
|
||||
|
@ -214,7 +214,7 @@ load_save_load_game(const gchar* filename, gboolean create_main_window)
|
|||
g_free(prefix);
|
||||
g_free(fullname);
|
||||
|
||||
basename = load_save_last_save_get();
|
||||
basename = file_load_text_from_saves("last_save");
|
||||
|
||||
if(basename != NULL)
|
||||
{
|
||||
|
@ -343,7 +343,7 @@ load_save_load_game(const gchar* filename, gboolean create_main_window)
|
|||
|
||||
misc_string_assign(&save_file, fullname);
|
||||
|
||||
load_save_last_save_set(fullname);
|
||||
file_store_text_in_saves("last_save", fullname);
|
||||
|
||||
gui_show_progress(-1, "",
|
||||
PIC_TYPE_LOAD);
|
||||
|
@ -369,76 +369,6 @@ load_save_load_game(const gchar* filename, gboolean create_main_window)
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
/** Store the name of the last savegame in the users home dir. */
|
||||
void
|
||||
load_save_last_save_set(const gchar *filename)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
printf("load_save_last_save_set\n");
|
||||
#endif
|
||||
|
||||
gchar buf[SMALL];
|
||||
const gchar *home = g_get_home_dir();
|
||||
FILE *fil = NULL;
|
||||
|
||||
if(os_is_unix)
|
||||
sprintf(buf, "%s%s%s%ssaves%slast_save", home, G_DIR_SEPARATOR_S,
|
||||
HOMEDIRNAME, G_DIR_SEPARATOR_S, G_DIR_SEPARATOR_S);
|
||||
else
|
||||
{
|
||||
gchar *pwd = g_get_current_dir();
|
||||
sprintf(buf, "%s%ssaves%slast_save", pwd, G_DIR_SEPARATOR_S,
|
||||
G_DIR_SEPARATOR_S);
|
||||
g_free(pwd);
|
||||
}
|
||||
|
||||
if(!file_my_fopen(buf, "w", &fil, FALSE))
|
||||
return;
|
||||
|
||||
fprintf(fil, "%s", filename);
|
||||
|
||||
fclose(fil);
|
||||
}
|
||||
|
||||
/** Return the filename of the last savegame. */
|
||||
gchar*
|
||||
load_save_last_save_get(void)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
printf("load_save_last_save_get\n");
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("load_save_last_save_get\n");
|
||||
#endif
|
||||
|
||||
gchar buf[SMALL];
|
||||
const gchar *home = g_get_home_dir();
|
||||
FILE *fil = NULL;
|
||||
gint i = 0, c;
|
||||
|
||||
if(os_is_unix)
|
||||
sprintf(buf, "%s%s%s%ssaves%slast_save", home, G_DIR_SEPARATOR_S,
|
||||
HOMEDIRNAME, G_DIR_SEPARATOR_S, G_DIR_SEPARATOR_S);
|
||||
else
|
||||
{
|
||||
gchar *pwd = g_get_current_dir();
|
||||
sprintf(buf, "%s%ssaves%slast_save", pwd, G_DIR_SEPARATOR_S,
|
||||
G_DIR_SEPARATOR_S);
|
||||
g_free(pwd);
|
||||
}
|
||||
|
||||
if(!file_my_fopen(buf, "r", &fil, FALSE))
|
||||
return NULL;
|
||||
|
||||
while ((c = (gchar)fgetc(fil)) != EOF)
|
||||
buf[i++] = (gchar)c;
|
||||
buf[i] = 0;
|
||||
|
||||
fclose(fil);
|
||||
|
||||
return g_strdup(buf);
|
||||
}
|
||||
|
||||
/** Write an autosave. */
|
||||
void
|
||||
|
|
|
@ -34,12 +34,6 @@ load_save_save_game(const gchar* filename);
|
|||
gboolean
|
||||
load_save_load_game(const gchar* filename, gboolean create_main_window);
|
||||
|
||||
void
|
||||
load_save_last_save_set(const gchar *filename);
|
||||
|
||||
gchar*
|
||||
load_save_last_save_get(void);
|
||||
|
||||
void
|
||||
load_save_autosave(void);
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
|
||||
#include "callbacks.h"
|
||||
#include "debug.h"
|
||||
#include "file.h"
|
||||
#include "finance.h"
|
||||
#include "free.h"
|
||||
#include "game.h"
|
||||
|
@ -98,6 +99,7 @@ misc_callback_start_game(void)
|
|||
|
||||
start_new_game();
|
||||
window_destroy(&window.startup);
|
||||
file_store_text_in_saves("last_country", country.sid);
|
||||
|
||||
if(!opt_int("int_opt_calodds"))
|
||||
{
|
||||
|
|
10
src/window.c
10
src/window.c
|
@ -309,6 +309,7 @@ window_show_startup(void)
|
|||
GPtrArray *country_files = NULL;
|
||||
GtkTreeModel *model = NULL;
|
||||
GtkCellRenderer *renderer = NULL;
|
||||
gchar *last_country = file_load_text_from_saves("last_country");
|
||||
|
||||
country_files = file_get_country_files();
|
||||
|
||||
|
@ -336,7 +337,14 @@ window_show_startup(void)
|
|||
|
||||
g_object_unref(model);
|
||||
|
||||
gtk_combo_box_set_active(GTK_COMBO_BOX(combo_country), 0);
|
||||
if(last_country != NULL)
|
||||
{
|
||||
misc_callback_show_team_list(combo_country, last_country);
|
||||
g_free(last_country);
|
||||
}
|
||||
else
|
||||
misc_callback_show_team_list(combo_country, (const gchar*)g_ptr_array_index(country_files, country_files->len - 1));
|
||||
//gtk_combo_box_set_active(GTK_COMBO_BOX(combo_country), country_index);
|
||||
|
||||
free_gchar_array(&country_files);
|
||||
}
|
||||
|
|
|
@ -770,7 +770,7 @@ float_name_random_list_prob 20000
|
|||
string_language_names English Deutsch Français Spanish Nederlands Polski Svenska Danish Romanian Bulgarian Chinese Italian
|
||||
string_language_codes C de fr es nl pl sv da ro bg zh it
|
||||
string_language_symbols flag_england.png flag_germany.png flag_france.png flag_spain.png flag_netherlands.png flag_poland.png flag_sweden.png flag_dk.png flag_romania.png flag_bulgaria.png flag_china.png flag_italy.png
|
||||
string_language_defs country_england.xml country_germany.xml country_france.xml country_spain.xml country_netherlands.xml country_poland.xml country_sweden.xml NONE country_romania.xml country_bulgaria.xml NONE country_italy.xml
|
||||
string_language_defs country_england.xml country_germany.xml country_france.xml country_spain.xml country_netherlands.xml country_poland.xml country_sweden.xml country_denmark.xml country_romania.xml country_bulgaria.xml NONE country_italy.xml
|
||||
|
||||
# lower and upper limits of which percentage
|
||||
# of the player wages a sponsor pays; the actual
|
||||
|
|
Loading…
Reference in New Issue