summaryrefslogtreecommitdiff
path: root/src/screen_setting.c
diff options
context:
space:
mode:
authororoborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e>2008-03-08 20:19:05 +0000
committeroroborus <oroborus@0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e>2008-03-08 20:19:05 +0000
commitda85e88878251f6a980fef95bd47109169a3cf7c (patch)
tree83b8b61c4afad0f6ccbb7940176a03f3ad4d2dc5 /src/screen_setting.c
parentf8bc51b580a5b9a8445f38b614a87209c074143a (diff)
- hra si vytvara domovskt adresar
- moznost ulozit konfiguraciu - lasserove streli boli lepsie posunute git-svn-id: http://opensvn.csie.org/tuxanci_ng@12 0ee4d065-81f0-4d1e-b06c-ff20ad07cc3e
Diffstat (limited to 'src/screen_setting.c')
-rw-r--r--src/screen_setting.c98
1 files changed, 98 insertions, 0 deletions
diff --git a/src/screen_setting.c b/src/screen_setting.c
index 6d8248d..9c4675c 100644
--- a/src/screen_setting.c
+++ b/src/screen_setting.c
@@ -10,8 +10,11 @@
#include "sound.h"
#include "screen_mainMenu.h"
#include "list.h"
+#include "homeDirector.h"
#include "screen_setting.h"
#include "tux.h"
+#include "textFile.h"
+#include "configFile.h"
#include "widget_label.h"
#include "widget_button.h"
@@ -51,6 +54,8 @@ static widget_textfield_t *textfield_count_cound;
static widget_textfield_t *textfield_name_player1;
static widget_textfield_t *textfield_name_player2;
+static textFile_t *configFile;
+
void startScreenSetting()
{
playMusic("menu", MUSIC_GROUP_BASE);
@@ -154,6 +159,92 @@ static void eventWidget(void *p)
}
}
+static void initSettingFile()
+{
+ char path[STR_PATH_SIZE];
+ char val[STR_SIZE];
+
+ sprintf(path, "%s/tuxanci-ng.conf", getHomeDirector());
+
+ configFile = loadTextFile(path);
+
+ if( configFile == NULL )
+ {
+ fprintf(stderr, "Don't load %s\n", path);
+ fprintf(stderr, "I create %s\n", path);
+
+ configFile = newTextFile(path);
+ }
+
+ if( configFile == NULL )
+ {
+ fprintf(stderr, "Don't create %s\n", path);
+ return;
+ }
+
+ loadValueFromConfigFile(configFile, "COUNT_ROUND", val, STR_SIZE, "15");
+ strcpy(textfield_count_cound->text, val);
+ loadValueFromConfigFile(configFile, "NAME_PLAYER_RIGHT", val, STR_SIZE, "name1");
+ strcpy(textfield_name_player1->text, val);
+ loadValueFromConfigFile(configFile, "NAME_PLAYER_LEFT", val, STR_SIZE, "name2");
+ strcpy(textfield_name_player2->text, val);
+
+ loadValueFromConfigFile(configFile, "GUN_DUAL_SIMPLE", val, STR_SIZE, "YES");
+ check[GUN_DUAL_SIMPLE]->status = isYesOrNO(val);
+ loadValueFromConfigFile(configFile, "GUN_TOMMY", val, STR_SIZE, "YES");
+ check[GUN_TOMMY]->status = isYesOrNO(val);
+ loadValueFromConfigFile(configFile, "GUN_LASSER", val, STR_SIZE, "YES");
+ check[GUN_LASSER]->status = isYesOrNO(val);
+ loadValueFromConfigFile(configFile, "GUN_MINE", val, STR_SIZE, "YES");
+ check[GUN_MINE]->status = isYesOrNO(val);
+ loadValueFromConfigFile(configFile, "GUN_BOMBBALL", val, STR_SIZE, "YES");
+ check[GUN_BOMBBALL]->status = isYesOrNO(val);
+
+ loadValueFromConfigFile(configFile, "BONUS_SPEED", val, STR_SIZE, "YES");
+ check[BONUS_SPEED]->status = isYesOrNO(val);
+ loadValueFromConfigFile(configFile, "BONUS_SHOT", val, STR_SIZE, "YES");
+ check[BONUS_SHOT]->status = isYesOrNO(val);
+ loadValueFromConfigFile(configFile, "BONUS_TELEPORT", val, STR_SIZE, "YES");
+ check[BONUS_TELEPORT]->status = isYesOrNO(val);
+ loadValueFromConfigFile(configFile, "BONUS_GHOST", val, STR_SIZE, "YES");
+ check[BONUS_GHOST]->status = isYesOrNO(val);
+ loadValueFromConfigFile(configFile, "BONUS_4X", val, STR_SIZE, "YES");
+ check[BONUS_4X]->status = isYesOrNO(val);
+ loadValueFromConfigFile(configFile, "BONUS_HIDDEN", val, STR_SIZE, "YES");
+ check[BONUS_HIDDEN]->status = isYesOrNO(val);
+
+ loadValueFromConfigFile(configFile, "MUSIC", val, STR_SIZE, "YES");
+ check_music->status = isYesOrNO(val);
+
+ loadValueFromConfigFile(configFile, "SOUND", val, STR_SIZE, "YES");
+ check_sound->status = isYesOrNO(val);
+}
+
+static void saveAndDestroyConfigFile()
+{
+ setValueInConfigFile(configFile, "COUNT_ROUND", textfield_count_cound->text );
+ setValueInConfigFile(configFile, "NAME_PLAYER_RIGHT", textfield_name_player1->text );
+ setValueInConfigFile(configFile, "NAME_PLAYER_LEFT", textfield_name_player2->text );
+
+ setValueInConfigFile(configFile, "GUN_DUAL_SIMPLE", getYesOrNo(check[GUN_DUAL_SIMPLE]->status) );
+ setValueInConfigFile(configFile, "GUN_TOMMY", getYesOrNo(check[GUN_TOMMY]->status) );
+ setValueInConfigFile(configFile, "GUN_LASSER", getYesOrNo(check[GUN_LASSER]->status) );
+ setValueInConfigFile(configFile, "GUN_MINE", getYesOrNo(check[GUN_MINE]->status) );
+ setValueInConfigFile(configFile, "GUN_BOMBBALL", getYesOrNo(check[GUN_BOMBBALL]->status) );
+ setValueInConfigFile(configFile, "BONUS_SPEED", getYesOrNo(check[BONUS_SPEED]->status) );
+ setValueInConfigFile(configFile, "BONUS_SHOT", getYesOrNo(check[BONUS_SHOT]->status) );
+ setValueInConfigFile(configFile, "BONUS_TELEPORT", getYesOrNo(check[BONUS_TELEPORT]->status) );
+ setValueInConfigFile(configFile, "BONUS_GHOST", getYesOrNo(check[BONUS_GHOST]->status) );
+ setValueInConfigFile(configFile, "BONUS_4X", getYesOrNo(check[BONUS_4X]->status) );
+ setValueInConfigFile(configFile, "BONUS_HIDDEN", getYesOrNo(check[BONUS_HIDDEN]->status) );
+
+ setValueInConfigFile(configFile, "MUSIC", getYesOrNo(check_music->status) );
+ setValueInConfigFile(configFile, "SOUND", getYesOrNo(check_sound->status) );
+
+ saveTextFile(configFile);
+ destroyTextFile(configFile);
+}
+
void initScreenSetting()
{
SDL_Surface *image;
@@ -237,6 +328,11 @@ void initScreenSetting()
registerScreen( newScreen("setting", startScreenSetting, eventScreenSetting,
drawScreenSetting, stopScreenSetting) );
+
+ initSettingFile();
+
+ eventWidget(check_music);
+ eventWidget(check_sound);
}
void getSettingNameRight(char *s)
@@ -286,6 +382,8 @@ void quitScreenSetting()
{
int i;
+ saveAndDestroyConfigFile();
+
destroyWidgetImage(image_backgorund);
destroyWidgetLabel(label_count_round);