5 * Copyright (C) 2005 Kevin Webb
6 * Copyright (C) 2006 Andrew Sayman
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 #include "../TextureLoader.h"
28 #include "callbacks.h"
29 #include "interface.h"
33 gui_data_save (GtkWidget
*widget
)
37 GtkEntry
*entPlayerName
;
38 const gchar
*tmp
= NULL
;
39 gchar player_name
[GC_PLAYER_NAME_LENGTH
];
44 // Get the current name in the name text box.
45 entPlayerName
= GTK_ENTRY(lookup_widget(GTK_WIDGET(widget
), "entPlayerName"));
47 tmp
= gtk_entry_get_text(entPlayerName
);
49 if (strlen(tmp
) == 0) {
50 gtk_entry_set_text(entPlayerName
, g_get_user_name());
53 g_strlcpy(player_name
, tmp
, 256);
57 // Get the currently selected resolution.
58 resolution
= (gint
) gtk_combo_box_get_active((GtkComboBox
*) lookup_widget(GTK_WIDGET(widget
), "cmbResolution"));
60 // Get the status of the quality combo box.
61 quality
= gtk_combo_box_get_active((GtkComboBox
*) lookup_widget(GTK_WIDGET(widget
), "cmbQuality"));
63 // Get the current AI difficulty setting.
64 ai_difficulty
= gtk_combo_box_get_active((GtkComboBox
*) lookup_widget(GTK_WIDGET(widget
), "cmbAI"));
66 // Generate the file name and write the data,
67 TextureLoader::buildLocalDataFileName(GC_GUI_FILE_NAME
, file_name
);
69 std::ofstream
file(file_name
);
71 std::cerr
<< "Unable to write gui data to file!\n";
75 file
<< player_name
<< std::endl
;
76 file
<< resolution
<< std::endl
;
77 file
<< quality
<< std::endl
;
78 file
<< ai_difficulty
<< std::endl
;
85 gui_data_read (GtkWidget
*widget
)
90 GtkEntry
*entPlayerName
;
91 gchar player_name
[GC_PLAYER_NAME_LENGTH
];
97 // Generate the name of the file and read the data.
98 TextureLoader::buildLocalDataFileName(GC_GUI_FILE_NAME
, file_name
);
100 std::ifstream
file(file_name
);
103 std::cerr
<< "Unable to find gui data file!\n";
109 file
.getline(buffer
, 256);
110 strcpy(player_name
, buffer
);
112 file
.getline(buffer
, 256);
113 resolution
= atoi(buffer
);
115 if (resolution
< 0 || resolution
> 4) {
119 file
.getline(buffer
, 256);
120 quality
= atoi(buffer
);
122 if (quality
< 0 || quality
> 2) {
126 file
.getline(buffer
, 256);
127 ai_difficulty
= atoi(buffer
);
129 if (ai_difficulty
< 0 || ai_difficulty
> 3) {
140 entPlayerName
= GTK_ENTRY(lookup_widget(GTK_WIDGET(widget
), "entPlayerName"));
142 gtk_entry_set_text (GTK_ENTRY (entPlayerName
), player_name
);
145 // Set the resolution.
146 gtk_combo_box_set_active((GtkComboBox
*) lookup_widget(GTK_WIDGET(widget
), "cmbResolution"), resolution
);
149 gtk_combo_box_set_active((GtkComboBox
*) lookup_widget(GTK_WIDGET(widget
), "cmbAI"), ai_difficulty
);
152 gtk_combo_box_set_active((GtkComboBox
*) lookup_widget(GTK_WIDGET(widget
), "cmbQuality"), quality
);