diff options
| author | Dusan Durech <dusan.d@Centrum.sk> | 2009-08-19 21:04:42 +0200 |
|---|---|---|
| committer | Dusan Durech <dusan.d@Centrum.sk> | 2009-08-19 21:04:42 +0200 |
| commit | 56f11df16e2949cf1cd29ed9e0fa43424e2181c2 (patch) | |
| tree | a8a3a5e569c9640d6969f440785636998be0ab9a /src | |
| parent | 7e4da11ff95f2867f8032ebb0279e5698053a7eb (diff) | |
behaves use params and save and load net setting game
Diffstat (limited to 'src')
| -rw-r--r-- | src/client/config.c | 39 | ||||
| -rw-r--r-- | src/client/config.h | 6 | ||||
| -rw-r--r-- | src/screen/choiceArena.c | 7 | ||||
| -rw-r--r-- | src/screen/gameType.c | 39 | ||||
| -rw-r--r-- | src/screen/setting.c | 6 |
5 files changed, 82 insertions, 15 deletions
diff --git a/src/client/config.c b/src/client/config.c index 1be1f1a..be95fb0 100644 --- a/src/client/config.c +++ b/src/client/config.c @@ -46,9 +46,15 @@ static config_t config_list[] = { .key=CFG_BONUS_TELEPORT, .var="BONUS_TELEPORT", .param="--bonus-teleport", .type=CONFIG_TYPE_INT, .value_int=1 }, { .key=CFG_BONUS_GHOST, .var="BONUS_GHOST", .param="--bonus-ghost", .type=CONFIG_TYPE_INT, .value_int=1 }, { .key=CFG_BONUS_4X, .var="BONUS_4X", .param="--bonus-4x", .type=CONFIG_TYPE_INT, .value_int=1 }, - { .key=CFG_BONUS_HIDDEN, .var="BONUS_HIDDEN", .param="--bonus-hidden", .type=CONFIG_TYPE_INT, .value_int=1 } + { .key=CFG_BONUS_HIDDEN, .var="BONUS_HIDDEN", .param="--bonus-hidden", .type=CONFIG_TYPE_INT, .value_int=1 }, + + { .key=CFG_GAME_TYPE, .var="GAME_TYPE", .param="--game-type", .type=CONFIG_TYPE_STR, .value_str="none" }, + { .key=CFG_NET_IP, .var="NET_IP", .param="--ip", .type=CONFIG_TYPE_STR, .value_str="127.0.0.1" }, + { .key=CFG_NET_PORT, .var="NET_PORT", .param="--port", .type=CONFIG_TYPE_STR, .value_str="6800" } }; +static textFile_t *config_file; + static config_t* find_config(int key) { int i; @@ -62,11 +68,34 @@ static config_t* find_config(int key) return NULL; } -static textFile_t *config_file; +static void check_param() +{ + int i; + + for (i = 0; i < CONFIG_LIST_COUNT; i++) { + char *str; + + str = getParam(config_list[i].param); + + if (str != NULL) { + if (config_list[i].type == CONFIG_TYPE_INT) { + config_list[i].value_int = atoi(str); + } else { + if (config_list[i].value_str != NULL) { + free(config_list[i].value_str); + } + + config_list[i].value_str = strdup(str); + } + } + } +} int config_init() { config_load(); + check_param(); + return 0; } @@ -126,7 +155,6 @@ void config_save() } text_file_save(config_file); - text_file_destroy(config_file); } int config_get_int_value(int key) @@ -184,5 +212,10 @@ void config_set_str_value(int key, char *str) int config_quit() { config_save(); + + if (config_file != NULL) { + text_file_destroy(config_file); + } + return 0; } diff --git a/src/client/config.h b/src/client/config.h index c56c537..ae84a76 100644 --- a/src/client/config.h +++ b/src/client/config.h @@ -24,7 +24,11 @@ #define CFG_BONUS_4X 18 #define CFG_BONUS_HIDDEN 19 -#define CONFIG_LIST_COUNT 19 +#define CFG_GAME_TYPE 20 +#define CFG_NET_IP 21 +#define CFG_NET_PORT 22 + +#define CONFIG_LIST_COUNT 22 extern int config_init(); extern void config_load(); diff --git a/src/screen/choiceArena.c b/src/screen/choiceArena.c index ea9079f..76e021f 100644 --- a/src/screen/choiceArena.c +++ b/src/screen/choiceArena.c @@ -9,6 +9,7 @@ #include "screen.h" #include "image.h" #include "hotKey.h" +#include "config.h" #ifndef NO_SOUND #include "music.h" @@ -242,10 +243,16 @@ void choice_arena_init() screen_register(screen_new("chiceArena", screen_startChoiceArena, choice_arena_event, choice_arena_draw, stopScreenChoiceArena)); + + choice_arena_set(arena_file_get_file_format_net_name(config_get_str_value(CFG_ARENA))); } void choice_arena_quit() { + if (choice_arena_get() != NULL) { + config_set_str_value(CFG_ARENA, arena_file_get_net_name(choice_arena_get())); + } + wid_image_destroy(image_backgorund); button_destroy(button_play); diff --git a/src/screen/gameType.c b/src/screen/gameType.c index 4493a95..c593c4c 100644 --- a/src/screen/gameType.c +++ b/src/screen/gameType.c @@ -13,6 +13,7 @@ #include "screen.h" #include "image.h" #include "hotKey.h" +#include "config.h" #ifndef NO_SOUND #include "music.h" @@ -93,10 +94,12 @@ void screen_startGameType() music_play("menu", MUSIC_GROUP_BASE); #endif +/* choiceGroup_set_status(check_none, TRUE); choiceGroup_set_status(check_server, FALSE); choiceGroup_set_status(check_client, FALSE); choiceGroup_set_status(check_load_session, FALSE); +*/ loadSession(selectSession); @@ -233,12 +236,14 @@ void game_type_init() check_client = choice_group_new(100, 250, FALSE, listChoiceGroup, eventWidget); check_load_session = choice_group_new(100, 300, FALSE, listChoiceGroup, eventWidget); - if (isParamFlag("--server")) { + if (strcmp(config_get_str_value(CFG_GAME_TYPE), "server") == 0) { choiceGroup_set_status(check_server, TRUE); - } else if (isParamFlag("--client")) { + } else if (strcmp(config_get_str_value(CFG_GAME_TYPE), "client") == 0) { choiceGroup_set_status(check_client, TRUE); - } else { + } else if (strcmp(config_get_str_value(CFG_GAME_TYPE), "none") == 0) { choiceGroup_set_status(check_none, TRUE); + } else { + choiceGroup_set_status(check_load_session, TRUE); } label_none = label_new(_("Local game"), 130, 145, WIDGET_LABEL_LEFT); @@ -250,11 +255,11 @@ void game_type_init() label_port = label_new(_("Port"), 300, 245, WIDGET_LABEL_LEFT); label_session = label_new(_("Load saved game:"), 300, 145, WIDGET_LABEL_LEFT); - textfield_ip = text_field_new(getParamElse("--ip", "127.0.0.1"), + textfield_ip = text_field_new(config_get_str_value(CFG_NET_IP), WIDGET_TEXTFIELD_FILTER_IP_OR_DOMAIN, 300, 180); - textfield_port = text_field_new(getParamElse("--port", "6800"), + textfield_port = text_field_new(config_get_str_value(CFG_NET_PORT), WIDGET_TEXTFIELD_FILTER_NUM, 300, 280); selectSession = select_new(300, 185, eventWidget); @@ -356,8 +361,32 @@ int public_server_get_settingProto() return -1; } +static void save_config() +{ + if (choice_group_get_status(check_none) == TRUE) { + config_set_str_value(CFG_GAME_TYPE, "none"); + } + + if (choice_group_get_status(check_server) == TRUE) { + config_set_str_value(CFG_GAME_TYPE, "server"); + } + + if (choice_group_get_status(check_client) == TRUE) { + config_set_str_value(CFG_GAME_TYPE, "client"); + } + + if (choice_group_get_status(check_load_session) == TRUE) { + config_set_str_value(CFG_GAME_TYPE, "session"); + } + + config_set_str_value(CFG_NET_IP, text_field_get_text(textfield_ip)); + config_set_str_value(CFG_NET_PORT, text_field_get_text(textfield_port)); +} + void game_type_quit() { + save_config(); + wid_image_destroy(image_backgorund); label_destroy(label_none); diff --git a/src/screen/setting.c b/src/screen/setting.c index ffe8e92..2645dac 100644 --- a/src/screen/setting.c +++ b/src/screen/setting.c @@ -242,8 +242,6 @@ static void initSettingFile() check_set_status(check_music, config_get_int_value(CFG_MUSIC)); check_set_status(check_sound, config_get_int_value(CFG_SOUND)); #endif - - choice_arena_set(arena_file_get_file_format_net_name(config_get_str_value(CFG_ARENA))); } static void saveAndDestroyConfigFile() @@ -271,10 +269,6 @@ static void saveAndDestroyConfigFile() config_set_int_value(CFG_MUSIC, check_get_status(check_music)); config_set_int_value(CFG_SOUND, check_get_status(check_sound)); #endif - - if (choice_arena_get() != NULL) { - config_set_str_value(CFG_ARENA, arena_file_get_net_name(choice_arena_get())); - } } void setting_init() |